[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #47151] make: -q fails for recursive makes

From: Paul D. Smith
Subject: [bug #47151] make: -q fails for recursive makes
Date: Sun, 28 Feb 2016 21:35:14 +0000
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0

Follow-up Comment #1, bug #47151 (project make):

Well, this is kind of gross.

The reason for this is as follows: first, to know the result of "make -q" make
just needs to locate at least one target that will be rebuilt.  Once it finds
the first target that will be rebuilt, then it knows the exit code should be

So, you ask it to build "foo".  It sees that "foo" depends on "bar", so it
determines whether "bar" will be rebuilt.  Here's where it gets tricky: make
has special handling for recipe lines that contain "$(MAKE)", and those which
start with "+"; if you run "make -q" (or "make -n" etc.) then these lines will
actually be invoked anyway.  See the documentation section "How the 'MAKE'
Variable Works".

The idea is that in a recursive make environment if we want to know if any
target needs to be built we need to recursively invoke make to see if it will
build anything.

So, make is recursively invoked (with -q set) and we discover yes, we need to
build "baz", so the recursive invocation of make exits with a "1" exit code.

Unfortunately the parent make doesn't really understand that, and it just says
"oh, my target failed!" and so it then decides to exit with an exit code of
"2" because something failed.

Yuck.  I agree that this is probably a bug.  Make needs to understand that
it's invoking a recursive make with -q mode enabled, and if it exits with a
"1" then it should treat that as a "must make target" exit code and itself
exit with a "1", not a "2".  I've checked and this wrong behavior has existed
as far back as I have compiled versions of GNU make (3.74, released in 1995).

As for why it works if you put some other line before the recursive make: in
that case before make runs the recursive line it sees that there is some other
recipe line that must be invoked, which is not marked as a recursive make
invocation (it doesn't contain "$(MAKE)" and it doesn't start with "+").  So,
make immediately knows that this target will be updated and it can stop right
away without doing any recursive make, and exit with "1".

You may be confused because you think you added a make comment line, but you
didn't: remember that ANY line which is indented with a TAB character,
REGARDLESS of what it contains, is considered a recipe line.  So that is not
interpreted as a makefile comment, because it's indented with a TAB.  Instead
it's going to be expanded and passed to the shell.  If you remove the TAB
before the comment line, so it's considered a makefile comment, you'll get the
"old" behavior (exiting with error 2).


Reply to this item at:


  Message sent via/by Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]