summaryrefslogtreecommitdiff
path: root/devdocs/gnu_make/options_002frecursion.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/gnu_make/options_002frecursion.html')
-rw-r--r--devdocs/gnu_make/options_002frecursion.html14
1 files changed, 14 insertions, 0 deletions
diff --git a/devdocs/gnu_make/options_002frecursion.html b/devdocs/gnu_make/options_002frecursion.html
new file mode 100644
index 00000000..6322d3fc
--- /dev/null
+++ b/devdocs/gnu_make/options_002frecursion.html
@@ -0,0 +1,14 @@
+ <h1 class="subsection">Communicating Options to a Sub-make</h1> <p>Flags such as ‘<samp>-s</samp>’ and ‘<samp>-k</samp>’ are passed automatically to the sub-<code>make</code> through the variable <code>MAKEFLAGS</code>. This variable is set up automatically by <code>make</code> to contain the flag letters that <code>make</code> received. Thus, if you do ‘<samp>make <span class="nolinebreak">-ks</span></samp>’ then <code>MAKEFLAGS</code> gets the value ‘<samp>ks</samp>’. </p> <p>As a consequence, every sub-<code>make</code> gets a value for <code>MAKEFLAGS</code> in its environment. In response, it takes the flags from that value and processes them as if they had been given as arguments. See <a href="options-summary">Summary of Options</a>. </p> <p>The value of <code>MAKEFLAGS</code> is a possibly empty group of characters representing single-letter options that take no argument, followed by a space and any options that take arguments or which have long option names. If an option has both single-letter and long options, the single-letter option is always preferred. If there are no single-letter options on the command line, then the value of <code>MAKEFLAGS</code> starts with a space. </p> <p>Likewise variables defined on the command line are passed to the sub-<code>make</code> through <code>MAKEFLAGS</code>. Words in the value of <code>MAKEFLAGS</code> that contain ‘<samp>=</samp>’, <code>make</code> treats as variable definitions just as if they appeared on the command line. See <a href="overriding">Overriding Variables</a>. </p> <p>The options ‘<samp>-C</samp>’, ‘<samp>-f</samp>’, ‘<samp>-o</samp>’, and ‘<samp>-W</samp>’ are not put into <code>MAKEFLAGS</code>; these options are not passed down. </p> <p>The ‘<samp>-j</samp>’ option is a special case (see <a href="parallel">Parallel Execution</a>). If you set it to some numeric value ‘<samp>N</samp>’ and your operating system supports it (most any UNIX system will; others typically won’t), the parent <code>make</code> and all the sub-<code>make</code>s will communicate to ensure that there are only ‘<samp>N</samp>’ jobs running at the same time between them all. Note that any job that is marked recursive (see <a href="instead-of-execution">Instead of Executing Recipes</a>) doesn’t count against the total jobs (otherwise we could get ‘<samp>N</samp>’ sub-<code>make</code>s running and have no slots left over for any real work!) </p> <p>If your operating system doesn’t support the above communication, then no ‘<samp>-j</samp>’ is added to <code>MAKEFLAGS</code>, so that sub-<code>make</code>s run in non-parallel mode. If the ‘<samp><span class="nolinebreak">-j</span></samp>’ option were passed down to sub-<code>make</code>s you would get many more jobs running in parallel than you asked for. If you give ‘<samp>-j</samp>’ with no numeric argument, meaning to run as many jobs as possible in parallel, this is passed down, since multiple infinities are no more than one. </p> <p>If you do not want to pass the other flags down, you must change the value of <code>MAKEFLAGS</code>, for example like this: </p> <div class="example"> <pre class="example">subsystem:
+ cd subdir &amp;&amp; $(MAKE) MAKEFLAGS=
+</pre>
+</div> <p>The command line variable definitions really appear in the variable <code>MAKEOVERRIDES</code>, and <code>MAKEFLAGS</code> contains a reference to this variable. If you do want to pass flags down normally, but don’t want to pass down the command line variable definitions, you can reset <code>MAKEOVERRIDES</code> to empty, like this: </p> <div class="example"> <pre class="example">MAKEOVERRIDES =
+</pre>
+</div> <p> This is not usually useful to do. However, some systems have a small fixed limit on the size of the environment, and putting so much information into the value of <code>MAKEFLAGS</code> can exceed it. If you see the error message ‘<samp>Arg list too long</samp>’, this may be the problem. (For strict compliance with POSIX.2, changing <code>MAKEOVERRIDES</code> does not affect <code>MAKEFLAGS</code> if the special target ‘<samp>.POSIX</samp>’ appears in the makefile. You probably do not care about this.) </p> <p>A similar variable <code>MFLAGS</code> exists also, for historical compatibility. It has the same value as <code>MAKEFLAGS</code> except that it does not contain the command line variable definitions, and it always begins with a hyphen unless it is empty (<code>MAKEFLAGS</code> begins with a hyphen only when it begins with an option that has no single-letter version, such as ‘<samp>--warn-undefined-variables</samp>’). <code>MFLAGS</code> was traditionally used explicitly in the recursive <code>make</code> command, like this: </p> <div class="example"> <pre class="example">subsystem:
+ cd subdir &amp;&amp; $(MAKE) $(MFLAGS)
+</pre>
+</div> <p>but now <code>MAKEFLAGS</code> makes this usage redundant. If you want your makefiles to be compatible with old <code>make</code> programs, use this technique; it will work fine with more modern <code>make</code> versions too. </p> <p>The <code>MAKEFLAGS</code> variable can also be useful if you want to have certain options, such as ‘<samp>-k</samp>’ (see <a href="options-summary">Summary of Options</a>), set each time you run <code>make</code>. You simply put a value for <code>MAKEFLAGS</code> in your environment. You can also set <code>MAKEFLAGS</code> in a makefile, to specify additional flags that should also be in effect for that makefile. (Note that you cannot use <code>MFLAGS</code> this way. That variable is set only for compatibility; <code>make</code> does not interpret a value you set for it in any way.) </p> <p>When <code>make</code> interprets the value of <code>MAKEFLAGS</code> (either from the environment or from a makefile), it first prepends a hyphen if the value does not already begin with one. Then it chops the value into words separated by blanks, and parses these words as if they were options given on the command line (except that ‘<samp>-C</samp>’, ‘<samp>-f</samp>’, ‘<samp>-h</samp>’, ‘<samp>-o</samp>’, ‘<samp>-W</samp>’, and their long-named versions are ignored; and there is no error for an invalid option). </p> <p>If you do put <code>MAKEFLAGS</code> in your environment, you should be sure not to include any options that will drastically affect the actions of <code>make</code> and undermine the purpose of makefiles and of <code>make</code> itself. For instance, the ‘<samp>-t</samp>’, ‘<samp>-n</samp>’, and ‘<samp>-q</samp>’ options, if put in one of these variables, could have disastrous consequences and would certainly have at least surprising and probably annoying effects. </p> <p>If you’d like to run other implementations of <code>make</code> in addition to GNU <code>make</code>, and hence do not want to add GNU <code>make</code>-specific flags to the <code>MAKEFLAGS</code> variable, you can add them to the <code>GNUMAKEFLAGS</code> variable instead. This variable is parsed just before <code>MAKEFLAGS</code>, in the same way as <code>MAKEFLAGS</code>. When <code>make</code> constructs <code>MAKEFLAGS</code> to pass to a recursive <code>make</code> it will include all flags, even those taken from <code>GNUMAKEFLAGS</code>. As a result, after parsing <code>GNUMAKEFLAGS</code> GNU <code>make</code> sets this variable to the empty string to avoid duplicating flags during recursion. </p> <p>It’s best to use <code>GNUMAKEFLAGS</code> only with flags which won’t materially change the behavior of your makefiles. If your makefiles require GNU make anyway then simply use <code>MAKEFLAGS</code>. Flags such as ‘<samp>--no-print-directory</samp>’ or ‘<samp>--output-sync</samp>’ may be appropriate for <code>GNUMAKEFLAGS</code>. </p><div class="_attribution">
+ <p class="_attribution-p">
+ Copyright © 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Free Software Foundation, Inc. <br>Licensed under the GNU Free Documentation License.<br>
+ <a href="https://www.gnu.org/software/make/manual/html_node/Options_002fRecursion.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Options_002fRecursion.html</a>
+ </p>
+</div>