Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"write error: stdout" when calling "make" from Makefile

Tags:

makefile

This is my Makefile:

SHELL=/bin/bash
.SHELLFLAGS = -e -o pipefail -c 

env:
    make -version | head -1

This is what I'm getting on Ubuntu 20.04.3:

make -version | head -1
GNU Make 4.2.1
make[1]: write error: stdout
make: *** [Makefile:4: env] Error 1

What's wrong?

like image 871
yegor256 Avatar asked Feb 17 '26 20:02

yegor256


1 Answers

I don't see this problem with GNU make 4.3, so I guess something was changed there to allow this to work.

To fix it you can try changing your rule to this:

env:
        make -version | cat | head -1

The error is because the head program closes its stdin when it's read the first line, then make complains because it fails to write to its stdout (because it was closed).

By introducing the cat here, the cat reads all the input from make without closing the pipe so make doesn't get any error.

PS. You should always, always use the variable $(MAKE) when invoking a sub-make, never the hardcoded make.

like image 130
MadScientist Avatar answered Feb 20 '26 13:02

MadScientist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!