/usr/share/doc/make-doc/make.html/Makefiles.html is in make-doc 4.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This file documents the GNU make utility, which determines
automatically which pieces of a large program need to be recompiled,
and issues the commands to recompile them.
This is Edition 0.74, last updated 21 May 2016,
of The GNU Make Manual, for GNU make version 4.2.1.
Copyright (C) 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 Free Software
Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with the Front-Cover Texts being "A GNU Manual,"
and with the Back-Cover Texts as in (a) below. A copy of the
license is included in the section entitled "GNU Free Documentation
License."
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom." -->
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Makefiles (GNU make)</title>
<meta name="description" content="Makefiles (GNU make)">
<meta name="keywords" content="Makefiles (GNU make)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="index.html#Top" rel="up" title="Top">
<link href="Rules.html#Rules" rel="next" title="Rules">
<link href="Introduction.html#Cleanup" rel="prev" title="Cleanup">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en">
<a name="Makefiles"></a>
<div class="header">
<p>
Next: <a href="Rules.html#Rules" accesskey="n" rel="next">Rules</a>, Previous: <a href="Introduction.html#Introduction" accesskey="p" rel="prev">Introduction</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Writing-Makefiles"></a>
<h2 class="chapter">3 Writing Makefiles</h2>
<a name="index-makefile_002c-how-to-write"></a>
<p>The information that tells <code>make</code> how to recompile a system comes from
reading a data base called the <em>makefile</em>.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Makefile-Contents" accesskey="1">Makefile Contents</a>:</td><td> </td><td align="left" valign="top">What makefiles contain.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Makefile-Names" accesskey="2">Makefile Names</a>:</td><td> </td><td align="left" valign="top">How to name your makefile.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Include" accesskey="3">Include</a>:</td><td> </td><td align="left" valign="top">How one makefile can use another makefile.
</td></tr>
<tr><td align="left" valign="top">• <a href="#MAKEFILES-Variable" accesskey="4">MAKEFILES Variable</a>:</td><td> </td><td align="left" valign="top">The environment can specify extra makefiles.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Remaking-Makefiles" accesskey="5">Remaking Makefiles</a>:</td><td> </td><td align="left" valign="top">How makefiles get remade.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Overriding-Makefiles" accesskey="6">Overriding Makefiles</a>:</td><td> </td><td align="left" valign="top">How to override part of one makefile
with another makefile.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Reading-Makefiles" accesskey="7">Reading Makefiles</a>:</td><td> </td><td align="left" valign="top">How makefiles are parsed.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Secondary-Expansion" accesskey="8">Secondary Expansion</a>:</td><td> </td><td align="left" valign="top">How and when secondary expansion is performed.
</td></tr>
</table>
<hr>
<a name="Makefile-Contents"></a>
<div class="header">
<p>
Next: <a href="#Makefile-Names" accesskey="n" rel="next">Makefile Names</a>, Previous: <a href="#Makefiles" accesskey="p" rel="prev">Makefiles</a>, Up: <a href="#Makefiles" accesskey="u" rel="up">Makefiles</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="What-Makefiles-Contain"></a>
<h3 class="section">3.1 What Makefiles Contain</h3>
<p>Makefiles contain five kinds of things: <em>explicit rules</em>,
<em>implicit rules</em>, <em>variable definitions</em>, <em>directives</em>,
and <em>comments</em>. Rules, variables, and directives are described at
length in later chapters.
</p>
<ul>
<li> <a name="index-rule_002c-explicit_002c-definition-of"></a>
<a name="index-explicit-rule_002c-definition-of"></a>
An <em>explicit rule</em> says when and how to remake one or more files,
called the rule’s <em>targets</em>. It lists the other files that the
targets depend on, called the <em>prerequisites</em> of the target, and
may also give a recipe to use to create or update the targets.
See <a href="Rules.html#Rules">Writing Rules</a>.
</li><li> <a name="index-rule_002c-implicit_002c-definition-of"></a>
<a name="index-implicit-rule_002c-definition-of"></a>
An <em>implicit rule</em> says when and how to remake a class of files
based on their names. It describes how a target may depend on a file
with a name similar to the target and gives a recipe to create or
update such a target. See <a href="Implicit-Rules.html#Implicit-Rules">Using Implicit Rules</a>.
</li><li> <a name="index-variable-definition"></a>
A <em>variable definition</em> is a line that specifies a text string
value for a variable that can be substituted into the text later. The
simple makefile example shows a variable definition for <code>objects</code>
as a list of all object files (see <a href="Introduction.html#Variables-Simplify">Variables
Make Makefiles Simpler</a>).
</li><li> <a name="index-directive"></a>
A <em>directive</em> is an instruction for <code>make</code> to do something
special while reading the makefile. These include:
<ul>
<li> Reading another makefile (see <a href="#Include">Including Other Makefiles</a>).
</li><li> Deciding (based on the values of variables) whether to use or
ignore a part of the makefile (see <a href="Conditionals.html#Conditionals">Conditional Parts of Makefiles</a>).
</li><li> Defining a variable from a verbatim string containing multiple lines
(see <a href="Using-Variables.html#Multi_002dLine">Defining Multi-Line Variables</a>).
</li></ul>
</li><li> <a name="index-comments_002c-in-makefile"></a>
<a name="index-_0023-_0028comments_0029_002c-in-makefile"></a>
‘<samp>#</samp>’ in a line of a makefile starts a <em>comment</em>. It and the
rest of the line are ignored, except that a trailing backslash not
escaped by another backslash will continue the comment across multiple
lines. A line containing just a comment (with perhaps spaces before
it) is effectively blank, and is ignored. If you want a literal
<code>#</code>, escape it with a backslash (e.g., <code>\#</code>). Comments may
appear on any line in the makefile, although they are treated
specially in certain situations.
<p>You cannot use comments within variable references or function calls:
any instance of <code>#</code> will be treated literally (rather than as the
start of a comment) inside a variable reference or function call.
</p>
<p>Comments within a recipe are passed to the shell, just as with any
other recipe text. The shell decides how to interpret it: whether or
not this is a comment is up to the shell.
</p>
<p>Within a <code>define</code> directive, comments are not ignored during the
definition of the variable, but rather kept intact in the value of the
variable. When the variable is expanded they will either be treated
as <code>make</code> comments or as recipe text, depending on the context in
which the variable is evaluated.
</p></li></ul>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Splitting-Lines" accesskey="1">Splitting Lines</a>:</td><td> </td><td align="left" valign="top">Splitting long lines in makefiles
</td></tr>
</table>
<hr>
<a name="Splitting-Lines"></a>
<div class="header">
<p>
Previous: <a href="#Makefile-Contents" accesskey="p" rel="prev">Makefile Contents</a>, Up: <a href="#Makefile-Contents" accesskey="u" rel="up">Makefile Contents</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Splitting-Long-Lines"></a>
<h4 class="subsection">3.1.1 Splitting Long Lines</h4>
<a name="index-splitting-long-lines"></a>
<a name="index-long-lines_002c-splitting"></a>
<a name="index-backslash-_0028_005c_0029_002c-to-quote-newlines"></a>
<p>Makefiles use a “line-based” syntax in which the newline character
is special and marks the end of a statement. GNU <code>make</code> has no
limit on the length of a statement line, up to the amount of memory in
your computer.
</p>
<p>However, it is difficult to read lines which are too long to display
without wrapping or scrolling. So, you can format your makefiles for
readability by adding newlines into the middle of a statement: you do
this by escaping the internal newlines with a backslash (<code>\</code>)
character. Where we need to make a distinction we will refer to
“physical lines” as a single line ending with a newline (regardless
of whether it is escaped) and a “logical line” being a complete
statement including all escaped newlines up to the first non-escaped
newline.
</p>
<p>The way in which backslash/newline combinations are handled depends on
whether the statement is a recipe line or a non-recipe line. Handling
of backslash/newline in a recipe line is discussed later
(see <a href="Recipes.html#Splitting-Recipe-Lines">Splitting Recipe Lines</a>).
</p>
<p>Outside of recipe lines, backslash/newlines are converted into a
single space character. Once that is done, all whitespace around the
backslash/newline is condensed into a single space: this includes all
whitespace preceding the backslash, all whitespace at the beginning of
the line after the backslash/newline, and any consecutive
backslash/newline combinations.
</p>
<p>If the <code>.POSIX</code> special target is defined then backslash/newline
handling is modified slightly to conform to POSIX.2: first, whitespace
preceding a backslash is not removed and second, consecutive
backslash/newlines are not condensed.
</p>
<hr>
<a name="Makefile-Names"></a>
<div class="header">
<p>
Next: <a href="#Include" accesskey="n" rel="next">Include</a>, Previous: <a href="#Makefile-Contents" accesskey="p" rel="prev">Makefile Contents</a>, Up: <a href="#Makefiles" accesskey="u" rel="up">Makefiles</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="What-Name-to-Give-Your-Makefile"></a>
<h3 class="section">3.2 What Name to Give Your Makefile</h3>
<a name="index-makefile-name"></a>
<a name="index-name-of-makefile"></a>
<a name="index-default-makefile-name"></a>
<a name="index-file-name-of-makefile"></a>
<p>By default, when <code>make</code> looks for the makefile, it tries the
following names, in order: <samp>GNUmakefile</samp>, <samp>makefile</samp>
and <samp>Makefile</samp>.
<a name="index-Makefile"></a>
<a name="index-GNUmakefile"></a>
<a name="index-makefile-1"></a>
</p>
<a name="index-README"></a>
<p>Normally you should call your makefile either <samp>makefile</samp> or
<samp>Makefile</samp>. (We recommend <samp>Makefile</samp> because it appears
prominently near the beginning of a directory listing, right near other
important files such as <samp>README</samp>.) The first name checked,
<samp>GNUmakefile</samp>, is not recommended for most makefiles. You should
use this name if you have a makefile that is specific to GNU
<code>make</code>, and will not be understood by other versions of
<code>make</code>. Other <code>make</code> programs look for <samp>makefile</samp> and
<samp>Makefile</samp>, but not <samp>GNUmakefile</samp>.
</p>
<p>If <code>make</code> finds none of these names, it does not use any makefile.
Then you must specify a goal with a command argument, and <code>make</code>
will attempt to figure out how to remake it using only its built-in
implicit rules. See <a href="Implicit-Rules.html#Implicit-Rules">Using Implicit Rules</a>.
</p>
<a name="index-_002df"></a>
<a name="index-_002d_002dfile"></a>
<a name="index-_002d_002dmakefile"></a>
<p>If you want to use a nonstandard name for your makefile, you can specify
the makefile name with the ‘<samp>-f</samp>’ or ‘<samp>--file</samp>’ option. The
arguments ‘<samp><span class="nolinebreak">-f</span> <var>name</var></samp>’<!-- /@w --> or ‘<samp><span class="nolinebreak">--file=</span><var>name</var></samp>’<!-- /@w --> tell
<code>make</code> to read the file <var>name</var> as the makefile. If you use
more than one ‘<samp>-f</samp>’ or ‘<samp>--file</samp>’ option, you can specify several
makefiles. All the makefiles are effectively concatenated in the order
specified. The default makefile names <samp>GNUmakefile</samp>,
<samp>makefile</samp> and <samp>Makefile</samp> are not checked automatically if you
specify ‘<samp>-f</samp>’ or ‘<samp>--file</samp>’.
<a name="index-specifying-makefile-name"></a>
<a name="index-makefile-name_002c-how-to-specify"></a>
<a name="index-name-of-makefile_002c-how-to-specify"></a>
<a name="index-file-name-of-makefile_002c-how-to-specify"></a>
</p>
<hr>
<a name="Include"></a>
<div class="header">
<p>
Next: <a href="#MAKEFILES-Variable" accesskey="n" rel="next">MAKEFILES Variable</a>, Previous: <a href="#Makefile-Names" accesskey="p" rel="prev">Makefile Names</a>, Up: <a href="#Makefiles" accesskey="u" rel="up">Makefiles</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Including-Other-Makefiles"></a>
<h3 class="section">3.3 Including Other Makefiles</h3>
<a name="index-including-other-makefiles"></a>
<a name="index-makefile_002c-including"></a>
<a name="index-include"></a>
<p>The <code>include</code> directive tells <code>make</code> to suspend reading the
current makefile and read one or more other makefiles before continuing.
The directive is a line in the makefile that looks like this:
</p>
<div class="example">
<pre class="example">include <var>filenames</var>…
</pre></div>
<p><var>filenames</var> can contain shell file name patterns. If
<var>filenames</var> is empty, nothing is included and no error is printed.
<a name="index-shell-file-name-pattern-_0028in-include_0029"></a>
<a name="index-shell-wildcards-_0028in-include_0029"></a>
<a name="index-wildcard_002c-in-include"></a>
</p>
<p>Extra spaces are allowed and ignored at the beginning of the line, but
the first character must not be a tab (or the value of
<code>.RECIPEPREFIX</code>)—if the line begins with a tab, it will be
considered a recipe line. Whitespace is required between
<code>include</code> and the file names, and between file names; extra
whitespace is ignored there and at the end of the directive. A
comment starting with ‘<samp>#</samp>’ is allowed at the end of the line. If
the file names contain any variable or function references, they are
expanded. See <a href="Using-Variables.html#Using-Variables">How to Use Variables</a>.
</p>
<p>For example, if you have three <samp>.mk</samp> files, <samp>a.mk</samp>,
<samp>b.mk</samp>, and <samp>c.mk</samp>, and <code>$(bar)</code> expands to
<code>bish bash</code>, then the following expression
</p>
<div class="example">
<pre class="example">include foo *.mk $(bar)
</pre></div>
<p>is equivalent to
</p>
<div class="example">
<pre class="example">include foo a.mk b.mk c.mk bish bash
</pre></div>
<p>When <code>make</code> processes an <code>include</code> directive, it suspends
reading of the containing makefile and reads from each listed file in
turn. When that is finished, <code>make</code> resumes reading the
makefile in which the directive appears.
</p>
<p>One occasion for using <code>include</code> directives is when several programs,
handled by individual makefiles in various directories, need to use a
common set of variable definitions
(see <a href="Using-Variables.html#Setting">Setting Variables</a>) or pattern rules
(see <a href="Implicit-Rules.html#Pattern-Rules">Defining and Redefining Pattern Rules</a>).
</p>
<p>Another such occasion is when you want to generate prerequisites from
source files automatically; the prerequisites can be put in a file that
is included by the main makefile. This practice is generally cleaner
than that of somehow appending the prerequisites to the end of the main
makefile as has been traditionally done with other versions of
<code>make</code>. See <a href="Rules.html#Automatic-Prerequisites">Automatic Prerequisites</a>.
<a name="index-prerequisites_002c-automatic-generation"></a>
<a name="index-automatic-generation-of-prerequisites"></a>
<a name="index-generating-prerequisites-automatically"></a>
</p>
<a name="index-_002dI"></a>
<a name="index-_002d_002dinclude_002ddir"></a>
<a name="index-included-makefiles_002c-default-directories"></a>
<a name="index-default-directories-for-included-makefiles"></a>
<a name="index-_002fusr_002fgnu_002finclude"></a>
<a name="index-_002fusr_002flocal_002finclude"></a>
<a name="index-_002fusr_002finclude"></a>
<p>If the specified name does not start with a slash, and the file is not
found in the current directory, several other directories are searched.
First, any directories you have specified with the ‘<samp>-I</samp>’ or
‘<samp>--include-dir</samp>’ option are searched
(see <a href="Running.html#Options-Summary">Summary of Options</a>).
Then the following directories (if they exist)
are searched, in this order:
<samp><var>prefix</var>/include</samp> (normally <samp>/usr/local/include</samp>
<a name="DOCF1" href="#FOOT1"><sup>1</sup></a>)
<samp>/usr/gnu/include</samp>,
<samp>/usr/local/include</samp>, <samp>/usr/include</samp>.
</p>
<p>If an included makefile cannot be found in any of these directories, a
warning message is generated, but it is not an immediately fatal error;
processing of the makefile containing the <code>include</code> continues.
Once it has finished reading makefiles, <code>make</code> will try to remake
any that are out of date or don’t exist.
See <a href="#Remaking-Makefiles">How Makefiles Are Remade</a>.
Only after it has tried to find a way to remake a makefile and failed,
will <code>make</code> diagnose the missing makefile as a fatal error.
</p>
<p>If you want <code>make</code> to simply ignore a makefile which does not exist
or cannot be remade, with no error message, use the <code><span class="nolinebreak">-include</span></code><!-- /@w -->
directive instead of <code>include</code>, like this:
</p>
<div class="example">
<pre class="example">-include <var>filenames</var>…
</pre></div>
<p>This acts like <code>include</code> in every way except that there is no
error (not even a warning) if any of the <var>filenames</var> (or any
prerequisites of any of the <var>filenames</var>) do not exist or cannot be
remade.
</p>
<p>For compatibility with some other <code>make</code> implementations,
<code>sinclude</code> is another name for <code><span class="nolinebreak">-include</span></code><!-- /@w -->.
</p>
<hr>
<a name="MAKEFILES-Variable"></a>
<div class="header">
<p>
Next: <a href="#Remaking-Makefiles" accesskey="n" rel="next">Remaking Makefiles</a>, Previous: <a href="#Include" accesskey="p" rel="prev">Include</a>, Up: <a href="#Makefiles" accesskey="u" rel="up">Makefiles</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="The-Variable-MAKEFILES"></a>
<h3 class="section">3.4 The Variable <code>MAKEFILES</code></h3>
<a name="index-makefile_002c-and-MAKEFILES-variable"></a>
<a name="index-including-_0028MAKEFILES-variable_0029"></a>
<a name="index-MAKEFILES"></a>
<p>If the environment variable <code>MAKEFILES</code> is defined, <code>make</code>
considers its value as a list of names (separated by whitespace) of
additional makefiles to be read before the others. This works much
like the <code>include</code> directive: various directories are searched
for those files (see <a href="#Include">Including Other Makefiles</a>). In
addition, the default goal is never taken from one of these makefiles
(or any makefile included by them) and it is not an error if the files
listed in <code>MAKEFILES</code> are not found.
</p>
<a name="index-recursion_002c-and-MAKEFILES-variable"></a>
<p>The main use of <code>MAKEFILES</code> is in communication between recursive
invocations of <code>make</code> (see <a href="Recipes.html#Recursion">Recursive Use of
<code>make</code></a>). It usually is not desirable to set the environment
variable before a top-level invocation of <code>make</code>, because it is
usually better not to mess with a makefile from outside. However, if
you are running <code>make</code> without a specific makefile, a makefile in
<code>MAKEFILES</code> can do useful things to help the built-in implicit
rules work better, such as defining search paths (see <a href="Rules.html#Directory-Search">Directory Search</a>).
</p>
<p>Some users are tempted to set <code>MAKEFILES</code> in the environment
automatically on login, and program makefiles to expect this to be done.
This is a very bad idea, because such makefiles will fail to work if run by
anyone else. It is much better to write explicit <code>include</code> directives
in the makefiles. See <a href="#Include">Including Other Makefiles</a>.
</p>
<hr>
<a name="Remaking-Makefiles"></a>
<div class="header">
<p>
Next: <a href="#Overriding-Makefiles" accesskey="n" rel="next">Overriding Makefiles</a>, Previous: <a href="#MAKEFILES-Variable" accesskey="p" rel="prev">MAKEFILES Variable</a>, Up: <a href="#Makefiles" accesskey="u" rel="up">Makefiles</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="How-Makefiles-Are-Remade"></a>
<h3 class="section">3.5 How Makefiles Are Remade</h3>
<a name="index-updating-makefiles"></a>
<a name="index-remaking-makefiles"></a>
<a name="index-makefile_002c-remaking-of"></a>
<p>Sometimes makefiles can be remade from other files, such as RCS or SCCS
files. If a makefile can be remade from other files, you probably want
<code>make</code> to get an up-to-date version of the makefile to read in.
</p>
<p>To this end, after reading in all makefiles, <code>make</code> will consider
each as a goal target and attempt to update it. If a makefile has a
rule which says how to update it (found either in that very makefile or
in another one) or if an implicit rule applies to it (see <a href="Implicit-Rules.html#Implicit-Rules">Using Implicit Rules</a>), it will be updated if necessary. After
all makefiles have been checked, if any have actually been changed,
<code>make</code> starts with a clean slate and reads all the makefiles over
again. (It will also attempt to update each of them over again, but
normally this will not change them again, since they are already up to
date.)
</p>
<p>If you know that one or more of your makefiles cannot be remade and
you want to keep <code>make</code> from performing an implicit rule search
on them, perhaps for efficiency reasons, you can use any normal method
of preventing implicit rule look-up to do so. For example, you can
write an explicit rule with the makefile as the target, and an empty
recipe (see <a href="Recipes.html#Empty-Recipes">Using Empty Recipes</a>).
</p>
<p>If the makefiles specify a double-colon rule to remake a file with
a recipe but no prerequisites, that file will always be remade
(see <a href="Rules.html#Double_002dColon">Double-Colon</a>). In the case of makefiles, a makefile that has a
double-colon rule with a recipe but no prerequisites will be remade every
time <code>make</code> is run, and then again after <code>make</code> starts over
and reads the makefiles in again. This would cause an infinite loop:
<code>make</code> would constantly remake the makefile, and never do anything
else. So, to avoid this, <code>make</code> will <strong>not</strong> attempt to
remake makefiles which are specified as targets of a double-colon rule
with a recipe but no prerequisites.
</p>
<p>If you do not specify any makefiles to be read with ‘<samp>-f</samp>’ or
‘<samp>--file</samp>’ options, <code>make</code> will try the default makefile names;
see <a href="#Makefile-Names">What Name to Give Your Makefile</a>. Unlike
makefiles explicitly requested with ‘<samp>-f</samp>’ or ‘<samp>--file</samp>’ options,
<code>make</code> is not certain that these makefiles should exist. However,
if a default makefile does not exist but can be created by running
<code>make</code> rules, you probably want the rules to be run so that the
makefile can be used.
</p>
<p>Therefore, if none of the default makefiles exists, <code>make</code> will try
to make each of them in the same order in which they are searched for
(see <a href="#Makefile-Names">What Name to Give Your Makefile</a>)
until it succeeds in making one, or it runs out of names to try. Note
that it is not an error if <code>make</code> cannot find or make any makefile;
a makefile is not always necessary.
</p>
<p>When you use the ‘<samp>-t</samp>’ or ‘<samp>--touch</samp>’ option
(see <a href="Running.html#Instead-of-Execution">Instead of Executing Recipes</a>),
you would not want to use an out-of-date makefile to decide which
targets to touch. So the ‘<samp>-t</samp>’ option has no effect on updating
makefiles; they are really updated even if ‘<samp>-t</samp>’ is specified.
Likewise, ‘<samp>-q</samp>’ (or ‘<samp>--question</samp>’) and ‘<samp>-n</samp>’ (or
‘<samp>--just-print</samp>’) do not prevent updating of makefiles, because an
out-of-date makefile would result in the wrong output for other targets.
Thus, ‘<samp>make -f mfile -n foo</samp>’ will update <samp>mfile</samp>, read it in,
and then print the recipe to update <samp>foo</samp> and its prerequisites
without running it. The recipe printed for <samp>foo</samp> will be the one
specified in the updated contents of <samp>mfile</samp>.
</p>
<p>However, on occasion you might actually wish to prevent updating of even
the makefiles. You can do this by specifying the makefiles as goals in
the command line as well as specifying them as makefiles. When the
makefile name is specified explicitly as a goal, the options ‘<samp>-t</samp>’
and so on do apply to them.
</p>
<p>Thus, ‘<samp>make -f mfile -n mfile foo</samp>’ would read the makefile
<samp>mfile</samp>, print the recipe needed to update it without actually
running it, and then print the recipe needed to update <samp>foo</samp>
without running that. The recipe for <samp>foo</samp> will be the one
specified by the existing contents of <samp>mfile</samp>.
</p>
<hr>
<a name="Overriding-Makefiles"></a>
<div class="header">
<p>
Next: <a href="#Reading-Makefiles" accesskey="n" rel="next">Reading Makefiles</a>, Previous: <a href="#Remaking-Makefiles" accesskey="p" rel="prev">Remaking Makefiles</a>, Up: <a href="#Makefiles" accesskey="u" rel="up">Makefiles</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Overriding-Part-of-Another-Makefile"></a>
<h3 class="section">3.6 Overriding Part of Another Makefile</h3>
<a name="index-overriding-makefiles"></a>
<a name="index-makefile_002c-overriding"></a>
<p>Sometimes it is useful to have a makefile that is mostly just like
another makefile. You can often use the ‘<samp>include</samp>’ directive to
include one in the other, and add more targets or variable definitions.
However, it is invalid for two makefiles to give different recipes for
the same target. But there is another way.
</p>
<a name="index-match_002danything-rule_002c-used-to-override"></a>
<p>In the containing makefile (the one that wants to include the other),
you can use a match-anything pattern rule to say that to remake any
target that cannot be made from the information in the containing
makefile, <code>make</code> should look in another makefile.
See <a href="Implicit-Rules.html#Pattern-Rules">Pattern Rules</a>, for more information on pattern rules.
</p>
<p>For example, if you have a makefile called <samp>Makefile</samp> that says how
to make the target ‘<samp>foo</samp>’ (and other targets), you can write a
makefile called <samp>GNUmakefile</samp> that contains:
</p>
<div class="example">
<pre class="example">foo:
frobnicate > foo
%: force
@$(MAKE) -f Makefile $@
force: ;
</pre></div>
<p>If you say ‘<samp>make foo</samp>’, <code>make</code> will find <samp>GNUmakefile</samp>,
read it, and see that to make <samp>foo</samp>, it needs to run the recipe
‘<samp>frobnicate > foo</samp>’. If you say ‘<samp>make bar</samp>’, <code>make</code> will
find no way to make <samp>bar</samp> in <samp>GNUmakefile</samp>, so it will use the
recipe from the pattern rule: ‘<samp>make -f Makefile bar</samp>’. If
<samp>Makefile</samp> provides a rule for updating <samp>bar</samp>, <code>make</code>
will apply the rule. And likewise for any other target that
<samp>GNUmakefile</samp> does not say how to make.
</p>
<p>The way this works is that the pattern rule has a pattern of just
‘<samp>%</samp>’, so it matches any target whatever. The rule specifies a
prerequisite <samp>force</samp>, to guarantee that the recipe will be run even
if the target file already exists. We give the <samp>force</samp> target an
empty recipe to prevent <code>make</code> from searching for an implicit rule to
build it—otherwise it would apply the same match-anything rule to
<samp>force</samp> itself and create a prerequisite loop!
</p>
<hr>
<a name="Reading-Makefiles"></a>
<div class="header">
<p>
Next: <a href="#Secondary-Expansion" accesskey="n" rel="next">Secondary Expansion</a>, Previous: <a href="#Overriding-Makefiles" accesskey="p" rel="prev">Overriding Makefiles</a>, Up: <a href="#Makefiles" accesskey="u" rel="up">Makefiles</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="How-make-Reads-a-Makefile"></a>
<h3 class="section">3.7 How <code>make</code> Reads a Makefile</h3>
<a name="index-reading-makefiles"></a>
<a name="index-makefile_002c-parsing"></a>
<p>GNU <code>make</code> does its work in two distinct phases. During the first
phase it reads all the makefiles, included makefiles, etc. and
internalizes all the variables and their values, implicit and explicit
rules, and constructs a dependency graph of all the targets and their
prerequisites. During the second phase, <code>make</code> uses these internal
structures to determine what targets will need to be rebuilt and to
invoke the rules necessary to do so.
</p>
<p>It’s important to understand this two-phase approach because it has a
direct impact on how variable and function expansion happens; this is
often a source of some confusion when writing makefiles. Here we will
present a summary of the phases in which expansion happens for different
constructs within the makefile. We say that expansion is
<em>immediate</em> if it happens during the first phase: in this case
<code>make</code> will expand any variables or functions in that section of a
construct as the makefile is parsed. We say that expansion is
<em>deferred</em> if expansion is not performed immediately. Expansion of
a deferred construct is not performed until either the construct appears
later in an immediate context, or until the second phase.
</p>
<p>You may not be familiar with some of these constructs yet. You can
reference this section as you become familiar with them, in later
chapters.
</p>
<a name="Variable-Assignment"></a>
<h4 class="subheading">Variable Assignment</h4>
<a name="index-_002b_003d_002c-expansion"></a>
<a name="index-_003d_002c-expansion"></a>
<a name="index-_003f_003d_002c-expansion"></a>
<a name="index-_002b_003d_002c-expansion-1"></a>
<a name="index-_0021_003d_002c-expansion"></a>
<a name="index-define_002c-expansion"></a>
<p>Variable definitions are parsed as follows:
</p>
<div class="example">
<pre class="example"><var>immediate</var> = <var>deferred</var>
<var>immediate</var> ?= <var>deferred</var>
<var>immediate</var> := <var>immediate</var>
<var>immediate</var> ::= <var>immediate</var>
<var>immediate</var> += <var>deferred</var> or <var>immediate</var>
<var>immediate</var> != <var>immediate</var>
define <var>immediate</var>
<var>deferred</var>
endef
define <var>immediate</var> =
<var>deferred</var>
endef
define <var>immediate</var> ?=
<var>deferred</var>
endef
define <var>immediate</var> :=
<var>immediate</var>
endef
define <var>immediate</var> ::=
<var>immediate</var>
endef
define <var>immediate</var> +=
<var>deferred</var> or <var>immediate</var>
endef
define <var>immediate</var> !=
<var>immediate</var>
endef
</pre></div>
<p>For the append operator, ‘<samp>+=</samp>’, the right-hand side is considered
immediate if the variable was previously set as a simple variable
(‘<samp>:=</samp>’ or ‘<samp>::=</samp>’), and deferred otherwise.
</p>
<p>For the shell assignment operator, ‘<samp>!=</samp>’, the right-hand side is
evaluated immediately and handed to the shell. The result is stored in the
variable named on the left, and that variable becomes a simple variable
(and will thus be re-evaluated on each reference).
</p>
<a name="Conditional-Directives"></a>
<h4 class="subheading">Conditional Directives</h4>
<a name="index-ifdef_002c-expansion"></a>
<a name="index-ifeq_002c-expansion"></a>
<a name="index-ifndef_002c-expansion"></a>
<a name="index-ifneq_002c-expansion"></a>
<p>Conditional directives are parsed immediately. This means, for
example, that automatic variables cannot be used in conditional
directives, as automatic variables are not set until the recipe for
that rule is invoked. If you need to use automatic variables in a
conditional directive you <em>must</em> move the condition into the
recipe and use shell conditional syntax instead.
</p>
<a name="Rule-Definition"></a>
<h4 class="subheading">Rule Definition</h4>
<a name="index-target_002c-expansion"></a>
<a name="index-prerequisite_002c-expansion"></a>
<a name="index-implicit-rule_002c-expansion"></a>
<a name="index-pattern-rule_002c-expansion"></a>
<a name="index-explicit-rule_002c-expansion"></a>
<p>A rule is always expanded the same way, regardless of the form:
</p>
<div class="example">
<pre class="example"><var>immediate</var> : <var>immediate</var> ; <var>deferred</var>
<var>deferred</var>
</pre></div>
<p>That is, the target and prerequisite sections are expanded immediately,
and the recipe used to construct the target is always deferred. This
general rule is true for explicit rules, pattern rules, suffix rules,
static pattern rules, and simple prerequisite definitions.
</p>
<hr>
<a name="Secondary-Expansion"></a>
<div class="header">
<p>
Previous: <a href="#Reading-Makefiles" accesskey="p" rel="prev">Reading Makefiles</a>, Up: <a href="#Makefiles" accesskey="u" rel="up">Makefiles</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Secondary-Expansion-1"></a>
<h3 class="section">3.8 Secondary Expansion</h3>
<a name="index-secondary-expansion"></a>
<a name="index-expansion_002c-secondary"></a>
<a name="index-_002eSECONDEXPANSION"></a>
<p>In the previous section we learned that GNU <code>make</code> works in two
distinct phases: a read-in phase and a target-update phase
(see <a href="#Reading-Makefiles">How <code>make</code> Reads a Makefile</a>). GNU
make also has the ability to enable a <em>second expansion</em> of the
prerequisites (only) for some or all targets defined in the makefile.
In order for this second expansion to occur, the special target
<code>.SECONDEXPANSION</code> must be defined before the first prerequisite
list that makes use of this feature.
</p>
<p>If that special target is defined then in between the two phases
mentioned above, right at the end of the read-in phase, all the
prerequisites of the targets defined after the special target are
expanded a <em>second time</em>. In most circumstances this secondary
expansion will have no effect, since all variable and function
references will have been expanded during the initial parsing of the
makefiles. In order to take advantage of the secondary expansion
phase of the parser, then, it’s necessary to <em>escape</em> the
variable or function reference in the makefile. In this case the
first expansion merely un-escapes the reference but doesn’t expand it,
and expansion is left to the secondary expansion phase. For example,
consider this makefile:
</p>
<div class="example">
<pre class="example">.SECONDEXPANSION:
ONEVAR = onefile
TWOVAR = twofile
myfile: $(ONEVAR) $$(TWOVAR)
</pre></div>
<p>After the first expansion phase the prerequisites list of the
<samp>myfile</samp> target will be <code>onefile</code> and <code>$(TWOVAR)</code>; the
first (unescaped) variable reference to <var>ONEVAR</var> is expanded,
while the second (escaped) variable reference is simply unescaped,
without being recognized as a variable reference. Now during the
secondary expansion the first word is expanded again but since it
contains no variable or function references it remains the value
<samp>onefile</samp>, while the second word is now a normal reference to the
variable <var>TWOVAR</var>, which is expanded to the value <samp>twofile</samp>.
The final result is that there are two prerequisites, <samp>onefile</samp>
and <samp>twofile</samp>.
</p>
<p>Obviously, this is not a very interesting case since the same result
could more easily have been achieved simply by having both variables
appear, unescaped, in the prerequisites list. One difference becomes
apparent if the variables are reset; consider this example:
</p>
<div class="example">
<pre class="example">.SECONDEXPANSION:
AVAR = top
onefile: $(AVAR)
twofile: $$(AVAR)
AVAR = bottom
</pre></div>
<p>Here the prerequisite of <samp>onefile</samp> will be expanded immediately,
and resolve to the value <samp>top</samp>, while the prerequisite of
<samp>twofile</samp> will not be full expanded until the secondary expansion
and yield a value of <samp>bottom</samp>.
</p>
<p>This is marginally more exciting, but the true power of this feature
only becomes apparent when you discover that secondary expansions
always take place within the scope of the automatic variables for that
target. This means that you can use variables such as <code>$@</code>,
<code>$*</code>, etc. during the second expansion and they will have their
expected values, just as in the recipe. All you have to do is defer
the expansion by escaping the <code>$</code>. Also, secondary expansion
occurs for both explicit and implicit (pattern) rules. Knowing this,
the possible uses for this feature increase dramatically. For
example:
</p>
<div class="example">
<pre class="example">.SECONDEXPANSION:
main_OBJS := main.o try.o test.o
lib_OBJS := lib.o api.o
main lib: $$($$@_OBJS)
</pre></div>
<p>Here, after the initial expansion the prerequisites of both the
<samp>main</samp> and <samp>lib</samp> targets will be <code>$($@_OBJS)</code>. During
the secondary expansion, the <code>$@</code> variable is set to the name of
the target and so the expansion for the <samp>main</samp> target will yield
<code>$(main_OBJS)</code>, or <code>main.o try.o test.o</code>, while the
secondary expansion for the <samp>lib</samp> target will yield
<code>$(lib_OBJS)</code>, or <code>lib.o api.o</code>.
</p>
<p>You can also mix in functions here, as long as they are properly escaped:
</p>
<div class="example">
<pre class="example">main_SRCS := main.c try.c test.c
lib_SRCS := lib.c api.c
.SECONDEXPANSION:
main lib: $$(patsubst %.c,%.o,$$($$@_SRCS))
</pre></div>
<p>This version allows users to specify source files rather than object
files, but gives the same resulting prerequisites list as the previous
example.
</p>
<p>Evaluation of automatic variables during the secondary expansion
phase, especially of the target name variable <code>$$@</code>, behaves
similarly to evaluation within recipes. However, there are some
subtle differences and “corner cases” which come into play for the
different types of rule definitions that <code>make</code> understands. The
subtleties of using the different automatic variables are described
below.
</p>
<a name="Secondary-Expansion-of-Explicit-Rules"></a>
<h4 class="subheading">Secondary Expansion of Explicit Rules</h4>
<a name="index-secondary-expansion-and-explicit-rules"></a>
<a name="index-explicit-rules_002c-secondary-expansion-of"></a>
<p>During the secondary expansion of explicit rules, <code>$$@</code> and
<code>$$%</code> evaluate, respectively, to the file name of the target and,
when the target is an archive member, the target member name. The
<code>$$<</code> variable evaluates to the first prerequisite in the first
rule for this target. <code>$$^</code> and <code>$$+</code> evaluate to the list
of all prerequisites of rules <em>that have already appeared</em> for
the same target (<code>$$+</code> with repetitions and <code>$$^</code>
without). The following example will help illustrate these behaviors:
</p>
<div class="example">
<pre class="example">.SECONDEXPANSION:
foo: foo.1 bar.1 $$< $$^ $$+ # line #1
foo: foo.2 bar.2 $$< $$^ $$+ # line #2
foo: foo.3 bar.3 $$< $$^ $$+ # line #3
</pre></div>
<p>In the first prerequisite list, all three variables (<code>$$<</code>,
<code>$$^</code>, and <code>$$+</code>) expand to the empty string. In the
second, they will have values <code>foo.1</code>, <code>foo.1 bar.1</code>, and
<code>foo.1 bar.1</code> respectively. In the third they will have values
<code>foo.1</code>, <code>foo.1 bar.1 foo.2 bar.2</code>, and <code>foo.1 bar.1
foo.2 bar.2 foo.1 foo.1 bar.1 foo.1 bar.1</code> respectively.
</p>
<p>Rules undergo secondary expansion in makefile order, except that
the rule with the recipe is always evaluated last.
</p>
<p>The variables <code>$$?</code> and <code>$$*</code> are not available and expand
to the empty string.
</p>
<a name="Secondary-Expansion-of-Static-Pattern-Rules"></a>
<h4 class="subheading">Secondary Expansion of Static Pattern Rules</h4>
<a name="index-secondary-expansion-and-static-pattern-rules"></a>
<a name="index-static-pattern-rules_002c-secondary-expansion-of"></a>
<p>Rules for secondary expansion of static pattern rules are identical to
those for explicit rules, above, with one exception: for static
pattern rules the <code>$$*</code> variable is set to the pattern stem. As
with explicit rules, <code>$$?</code> is not available and expands to the
empty string.
</p>
<a name="Secondary-Expansion-of-Implicit-Rules"></a>
<h4 class="subheading">Secondary Expansion of Implicit Rules</h4>
<a name="index-secondary-expansion-and-implicit-rules"></a>
<a name="index-implicit-rules_002c-secondary-expansion-of"></a>
<p>As <code>make</code> searches for an implicit rule, it substitutes the stem
and then performs secondary expansion for every rule with a matching
target pattern. The value of the automatic variables is derived in
the same fashion as for static pattern rules. As an example:
</p>
<div class="example">
<pre class="example">.SECONDEXPANSION:
foo: bar
foo foz: fo%: bo%
%oo: $$< $$^ $$+ $$*
</pre></div>
<p>When the implicit rule is tried for target <samp>foo</samp>, <code>$$<</code>
expands to <samp>bar</samp>, <code>$$^</code> expands to <samp>bar boo</samp>,
<code>$$+</code> also expands to <samp>bar boo</samp>, and <code>$$*</code> expands to
<samp>f</samp>.
</p>
<p>Note that the directory prefix (D), as described in <a href="Implicit-Rules.html#Implicit-Rule-Search">Implicit Rule Search Algorithm</a>, is appended (after
expansion) to all the patterns in the prerequisites list. As an
example:
</p>
<div class="example">
<pre class="example">.SECONDEXPANSION:
/tmp/foo.o:
%.o: $$(addsuffix /%.c,foo bar) foo.h
@echo $^
</pre></div>
<p>The prerequisite list printed, after the secondary expansion and
directory prefix reconstruction, will be <samp>/tmp/foo/foo.c
/tmp/bar/foo.c foo.h</samp>. If you are not interested in this
reconstruction, you can use <code>$$*</code> instead of <code>%</code> in the
prerequisites list.
</p>
<div class="footnote">
<hr>
<h4 class="footnotes-heading">Footnotes</h4>
<h3><a name="FOOT1" href="#DOCF1">(1)</a></h3>
<p>GNU Make compiled for MS-DOS and MS-Windows behaves as if
<var>prefix</var> has been defined to be the root of the DJGPP tree
hierarchy.</p>
</div>
<hr>
<div class="header">
<p>
Previous: <a href="#Reading-Makefiles" accesskey="p" rel="prev">Reading Makefiles</a>, Up: <a href="#Makefiles" accesskey="u" rel="up">Makefiles</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|