Take the 2-minute tour ×

I'd like to run my makefile without the -w flag turned on by the recursive make calls. The flag to do that is --no-print-directory on the make command line.

Is it possible to specify that flag within the makefile itself?

I plan to make this flag dependent on a VERBOSE mode, perhaps something like

$(if $(VERBOSE),,MAKEFLAGS += no-print-directory))

Thanks, Dan

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Yes, just appending --no-print-directory to MAKEFLAGS should be enough, but you have to do that with conditional directives, not with conditional functions:

ifndef VERBOSE
MAKEFLAGS += --no-print-directory
share|improve this answer
Please educate me, Why? –  dbbd Nov 17 '11 at 16:20
This is because variable assignment can't occur within an expansion which in turn is due to how Make parses makefiles. The only way to include variable assignment (or something else like rule definition) into an expandable code ($(if ...) in your question) is eval function. But particularly for your case a simple conditional directive is ok and also clearer than eval. –  Eldar Abusalimov Nov 17 '11 at 17:27
Oh, and of course you can embed a conditional function into the variable assignment like this: MAKEFLAGS += $(if $(value VERBOSE),,--no-print-directory). Here the assignment is performed unconditionally, but in case when VERBOSE is not defined or empty nothing is actually appended to the variable. –  Eldar Abusalimov Nov 17 '11 at 17:32
add comment

You can include the .SILENT: special target in the calling makefile. For example, here's your toplevel makefile:

    $(MAKE) -f sub.mk foo


and the submake makefile, sub.mk:

    @echo done

Note that .SILENT is considered obsolete, so it may not be around forever, and also note that including that in your makefile also has the effect of suppressing command echo, just as if you had put @ before every command in the makefile.

share|improve this answer
add comment

Your Answer


