1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<h1 class="subsection">Disabling Parallel Execution</h1> <p>If a makefile completely and accurately defines the dependency relationships between all of its targets, then <code>make</code> will correctly build the goals regardless of whether parallel execution is enabled or not. This is the ideal way to write makefiles. </p> <p>However, sometimes some or all of the targets in a makefile cannot be executed in parallel and it’s not feasible to add the prerequisites needed to inform <code>make</code>. In that case the makefile can use various methods to disable parallel execution. </p> <p>If the <code>.NOTPARALLEL</code> special target with no prerequisites is specified anywhere then the entire instance of <code>make</code> will be run serially, regardless of the parallel setting. For example: </p> <div class="example"> <pre class="example">all: one two three
one two three: ; @sleep 1; echo $@
.NOTPARALLEL:
</pre>
</div> <p>Regardless of how <code>make</code> is invoked, the targets <samp>one</samp>, <samp>two</samp>, and <samp>three</samp> will be run serially. </p> <p>If the <code>.NOTPARALLEL</code> special target has prerequisites, then each of those prerequisites will be considered a target and all prerequisites of these targets will be run serially. Note that only when building this target will the prerequisites be run serially: if some other target lists the same prerequisites and is not in <code>.NOTPARALLEL</code> then these prerequisites may be run in parallel. For example: </p> <div class="example"> <pre class="example">all: base notparallel
base: one two three
notparallel: one two three
one two three: ; @sleep 1; echo $@
.NOTPARALLEL: notparallel
</pre>
</div> <p>Here ‘<samp>make -j base</samp>’ will run the targets <samp>one</samp>, <samp>two</samp>, and <samp>three</samp> in parallel, while ‘<samp>make -j notparallel</samp>’ will run them serially. If you run ‘<samp>make -j all</samp>’ then they <em>will</em> be run in parallel since <samp>base</samp> lists them as prerequisites and is not serialized. </p> <p>The <code>.NOTPARALLEL</code> target should not have commands. </p> <p>Finally you can control the serialization of specific prerequisites in a fine-grained way using the <code>.WAIT</code> special target. When this target appears in a prerequisite list and parallel execution is enabled, <code>make</code> will not build any of the prerequisites to the <em>right</em> of <code>.WAIT</code> until all prerequisites to the <em>left</em> of <code>.WAIT</code> have completed. For example: </p> <div class="example"> <pre class="example">all: one two .WAIT three
one two three: ; @sleep 1; echo $@
</pre>
</div> <p>If parallel execution is enabled, <code>make</code> will try to build <samp>one</samp> and <samp>two</samp> in parallel but will not try to build <samp>three</samp> until both are complete. </p> <p>As with targets provided to <code>.NOTPARALLEL</code>, <code>.WAIT</code> takes effect only when building the target in whose prerequisite list it appears. If the same prerequisites are present in other targets, without <code>.WAIT</code>, then they may still be run in parallel. Because of this, neither <code>.NOTPARALLEL</code> with targets nor <code>.WAIT</code> are as reliable for controlling parallel execution as defining a prerequisite relationship. However they are easy to use and may be sufficient in less complex situations. </p> <p>The <code>.WAIT</code> prerequisite will not be present in any of the automatic variables for the rule. </p> <p>You can create an actual target <code>.WAIT</code> in your makefile for portability but this is not required to use this feature. If a <code>.WAIT</code> target is created it should not have prerequisites or commands. </p> <p>The <code>.WAIT</code> feature is also implemented in other versions of <code>make</code> and it’s specified in the POSIX standard for <code>make</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/Parallel-Disable.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Parallel-Disable.html</a>
</p>
</div>
|