make: Options/Recursion

1 
1 5.7.3 Communicating Options to a Sub-'make'
1 -------------------------------------------
1 
1 Flags such as '-s' and '-k' are passed automatically to the sub-'make'
1 through the variable 'MAKEFLAGS'.  This variable is set up automatically
1 by 'make' to contain the flag letters that 'make' received.  Thus, if
1 you do 'make -ks' then 'MAKEFLAGS' gets the value 'ks'.
1 
1    As a consequence, every sub-'make' gets a value for 'MAKEFLAGS' in
1 its environment.  In response, it takes the flags from that value and
11 processes them as if they had been given as arguments.  ⇒Summary of
 Options Options Summary.
1 
1    Likewise variables defined on the command line are passed to the
1 sub-'make' through 'MAKEFLAGS'.  Words in the value of 'MAKEFLAGS' that
1 contain '=', 'make' treats as variable definitions just as if they
1 appeared on the command line.  ⇒Overriding Variables Overriding.
1 
1    The options '-C', '-f', '-o', and '-W' are not put into 'MAKEFLAGS';
1 these options are not passed down.
1 
11    The '-j' option is a special case (⇒Parallel Execution
 Parallel.).  If you set it to some numeric value 'N' and your operating
1 system supports it (most any UNIX system will; others typically won't),
1 the parent 'make' and all the sub-'make's will communicate to ensure
1 that there are only 'N' jobs running at the same time between them all.
11 Note that any job that is marked recursive (⇒Instead of Executing
 Recipes Instead of Execution.) doesn't count against the total jobs
1 (otherwise we could get 'N' sub-'make's running and have no slots left
1 over for any real work!)
1 
1    If your operating system doesn't support the above communication,
1 then no '-j' is added to 'MAKEFLAGS', so that sub-'make's run in
1 non-parallel mode.  If the '-j' option were passed down to sub-'make's
1 you would get many more jobs running in parallel than you asked for.  If
1 you give '-j' with no numeric argument, meaning to run as many jobs as
1 possible in parallel, this is passed down, since multiple infinities are
1 no more than one.
1 
1    If you do not want to pass the other flags down, you must change the
1 value of 'MAKEFLAGS', like this:
1 
1      subsystem:
1              cd subdir && $(MAKE) MAKEFLAGS=
1 
1    The command line variable definitions really appear in the variable
1 'MAKEOVERRIDES', and 'MAKEFLAGS' contains a reference to this variable.
1 If you do want to pass flags down normally, but don't want to pass down
1 the command line variable definitions, you can reset 'MAKEOVERRIDES' to
1 empty, like this:
1 
1      MAKEOVERRIDES =
1 
1 This is not usually useful to do.  However, some systems have a small
1 fixed limit on the size of the environment, and putting so much
1 information into the value of 'MAKEFLAGS' can exceed it.  If you see the
1 error message 'Arg list too long', this may be the problem.  (For strict
1 compliance with POSIX.2, changing 'MAKEOVERRIDES' does not affect
1 'MAKEFLAGS' if the special target '.POSIX' appears in the makefile.  You
1 probably do not care about this.)
1 
1    A similar variable 'MFLAGS' exists also, for historical
1 compatibility.  It has the same value as 'MAKEFLAGS' except that it does
1 not contain the command line variable definitions, and it always begins
1 with a hyphen unless it is empty ('MAKEFLAGS' begins with a hyphen only
1 when it begins with an option that has no single-letter version, such as
1 '--warn-undefined-variables').  'MFLAGS' was traditionally used
1 explicitly in the recursive 'make' command, like this:
1 
1      subsystem:
1              cd subdir && $(MAKE) $(MFLAGS)
1 
1 but now 'MAKEFLAGS' makes this usage redundant.  If you want your
1 makefiles to be compatible with old 'make' programs, use this technique;
1 it will work fine with more modern 'make' versions too.
1 
1    The 'MAKEFLAGS' variable can also be useful if you want to have
11 certain options, such as '-k' (⇒Summary of Options Options
 Summary.), set each time you run 'make'.  You simply put a value for
1 'MAKEFLAGS' in your environment.  You can also set 'MAKEFLAGS' in a
1 makefile, to specify additional flags that should also be in effect for
1 that makefile.  (Note that you cannot use 'MFLAGS' this way.  That
1 variable is set only for compatibility; 'make' does not interpret a
1 value you set for it in any way.)
1 
1    When 'make' interprets the value of 'MAKEFLAGS' (either from the
1 environment or from a makefile), it first prepends a hyphen if the value
1 does not already begin with one.  Then it chops the value into words
1 separated by blanks, and parses these words as if they were options
1 given on the command line (except that '-C', '-f', '-h', '-o', '-W', and
1 their long-named versions are ignored; and there is no error for an
1 invalid option).
1 
1    If you do put 'MAKEFLAGS' in your environment, you should be sure not
1 to include any options that will drastically affect the actions of
1 'make' and undermine the purpose of makefiles and of 'make' itself.  For
1 instance, the '-t', '-n', and '-q' options, if put in one of these
1 variables, could have disastrous consequences and would certainly have
1 at least surprising and probably annoying effects.
1 
1    If you'd like to run other implementations of 'make' in addition to
1 GNU 'make', and hence do not want to add GNU 'make'-specific flags to
1 the 'MAKEFLAGS' variable, you can add them to the 'GNUMAKEFLAGS'
1 variable instead.  This variable is parsed just before 'MAKEFLAGS', in
1 the same way as 'MAKEFLAGS'.  When 'make' constructs 'MAKEFLAGS' to pass
1 to a recursive 'make' it will include all flags, even those taken from
1 'GNUMAKEFLAGS'.  As a result, after parsing 'GNUMAKEFLAGS' GNU 'make'
1 sets this variable to the empty string to avoid duplicating flags during
1 recursion.
1 
1    It's best to use 'GNUMAKEFLAGS' only with flags which won't
1 materially change the behavior of your makefiles.  If your makefiles
1 require GNU make anyway then simply use 'MAKEFLAGS'.  Flags such as
1 '--no-print-directory' or '--output-sync' may be appropriate for
1 'GNUMAKEFLAGS'.
1