/usr/share/doc/make-doc/make.html/Implicit-Rules.html is in make-doc 4.1-2.
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 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 | <!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.73, last updated 15 January 2016,
of The GNU Make Manual, for GNU make version 4.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 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.0, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU make: Implicit Rules</title>
<meta name="description" content="GNU make: Implicit Rules">
<meta name="keywords" content="GNU make: Implicit Rules">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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="Archives.html#Archives" rel="next" title="Archives">
<link href="Running.html#Options-Summary" rel="prev" title="Options Summary">
<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.nocodebreak {white-space: nowrap}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: serif; 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="Implicit-Rules"></a>
<div class="header">
<p>
Next: <a href="Archives.html#Archives" accesskey="n" rel="next">Archives</a>, Previous: <a href="Running.html#Running" accesskey="p" rel="prev">Running</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="Using-Implicit-Rules"></a>
<h2 class="chapter">10 Using Implicit Rules</h2>
<a name="index-implicit-rule"></a>
<a name="index-rule_002c-implicit"></a>
<p>Certain standard ways of remaking target files are used very often. For
example, one customary way to make an object file is from a C source file
using the C compiler, <code>cc</code>.
</p>
<p><em>Implicit rules</em> tell <code>make</code> how to use customary techniques so
that you do not have to specify them in detail when you want to use
them. For example, there is an implicit rule for C compilation. File
names determine which implicit rules are run. For example, C
compilation typically takes a <samp>.c</samp> file and makes a <samp>.o</samp> file.
So <code>make</code> applies the implicit rule for C compilation when it sees
this combination of file name endings.
</p>
<p>A chain of implicit rules can apply in sequence; for example, <code>make</code>
will remake a <samp>.o</samp> file from a <samp>.y</samp> file by way of a <samp>.c</samp> file.
</p>
<p>The built-in implicit rules use several variables in their recipes so
that, by changing the values of the variables, you can change the way the
implicit rule works. For example, the variable <code>CFLAGS</code> controls the
flags given to the C compiler by the implicit rule for C compilation.
</p>
<p>You can define your own implicit rules by writing <em>pattern rules</em>.
</p>
<p><em>Suffix rules</em> are a more limited way to define implicit rules.
Pattern rules are more general and clearer, but suffix rules are
retained for compatibility.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Using-Implicit" accesskey="1">Using Implicit</a>:</td><td> </td><td align="left" valign="top">How to use an existing implicit rule
to get the recipes for updating a file.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Catalogue-of-Rules" accesskey="2">Catalogue of Rules</a>:</td><td> </td><td align="left" valign="top">A list of built-in rules.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Implicit-Variables" accesskey="3">Implicit Variables</a>:</td><td> </td><td align="left" valign="top">How to change what predefined rules do.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Chained-Rules" accesskey="4">Chained Rules</a>:</td><td> </td><td align="left" valign="top">How to use a chain of implicit rules.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Pattern-Rules" accesskey="5">Pattern Rules</a>:</td><td> </td><td align="left" valign="top">How to define new implicit rules.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Last-Resort" accesskey="6">Last Resort</a>:</td><td> </td><td align="left" valign="top">How to define a recipe for rules which
cannot find any.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Suffix-Rules" accesskey="7">Suffix Rules</a>:</td><td> </td><td align="left" valign="top">The old-fashioned style of implicit rule.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Implicit-Rule-Search" accesskey="8">Implicit Rule Search</a>:</td><td> </td><td align="left" valign="top">The precise algorithm for applying
implicit rules.
</td></tr>
</table>
<hr>
<a name="Using-Implicit"></a>
<div class="header">
<p>
Next: <a href="#Catalogue-of-Rules" accesskey="n" rel="next">Catalogue of Rules</a>, Previous: <a href="#Implicit-Rules" accesskey="p" rel="prev">Implicit Rules</a>, Up: <a href="#Implicit-Rules" accesskey="u" rel="up">Implicit Rules</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="Using-Implicit-Rules-1"></a>
<h3 class="section">10.1 Using Implicit Rules</h3>
<a name="index-implicit-rule_002c-how-to-use"></a>
<a name="index-rule_002c-implicit_002c-how-to-use"></a>
<p>To allow <code>make</code> to find a customary method for updating a target
file, all you have to do is refrain from specifying recipes yourself.
Either write a rule with no recipe, or don’t write a rule at all.
Then <code>make</code> will figure out which implicit rule to use based on
which kind of source file exists or can be made.
</p>
<p>For example, suppose the makefile looks like this:
</p>
<div class="example">
<pre class="example">foo : foo.o bar.o
cc -o foo foo.o bar.o $(CFLAGS) $(LDFLAGS)
</pre></div>
<p>Because you mention <samp>foo.o</samp> but do not give a rule for it, <code>make</code>
will automatically look for an implicit rule that tells how to update it.
This happens whether or not the file <samp>foo.o</samp> currently exists.
</p>
<p>If an implicit rule is found, it can supply both a recipe and one or
more prerequisites (the source files). You would want to write a rule
for <samp>foo.o</samp> with no recipe if you need to specify additional
prerequisites, such as header files, that the implicit rule cannot
supply.
</p>
<p>Each implicit rule has a target pattern and prerequisite patterns. There may
be many implicit rules with the same target pattern. For example, numerous
rules make ‘<samp>.o</samp>’ files: one, from a ‘<samp>.c</samp>’ file with the C compiler;
another, from a ‘<samp>.p</samp>’ file with the Pascal compiler; and so on. The rule
that actually applies is the one whose prerequisites exist or can be made.
So, if you have a file <samp>foo.c</samp>, <code>make</code> will run the C compiler;
otherwise, if you have a file <samp>foo.p</samp>, <code>make</code> will run the Pascal
compiler; and so on.
</p>
<p>Of course, when you write the makefile, you know which implicit rule you
want <code>make</code> to use, and you know it will choose that one because you
know which possible prerequisite files are supposed to exist.
See <a href="#Catalogue-of-Rules">Catalogue of Built-In Rules</a>,
for a catalogue of all the predefined implicit rules.
</p>
<p>Above, we said an implicit rule applies if the required prerequisites “exist
or can be made”. A file “can be made” if it is mentioned explicitly in
the makefile as a target or a prerequisite, or if an implicit rule can be
recursively found for how to make it. When an implicit prerequisite is the
result of another implicit rule, we say that <em>chaining</em> is occurring.
See <a href="#Chained-Rules">Chains of Implicit Rules</a>.
</p>
<p>In general, <code>make</code> searches for an implicit rule for each target, and
for each double-colon rule, that has no recipe. A file that is mentioned
only as a prerequisite is considered a target whose rule specifies nothing,
so implicit rule search happens for it. See <a href="#Implicit-Rule-Search">Implicit Rule Search Algorithm</a>, for the
details of how the search is done.
</p>
<p>Note that explicit prerequisites do not influence implicit rule search.
For example, consider this explicit rule:
</p>
<div class="example">
<pre class="example">foo.o: foo.p
</pre></div>
<p>The prerequisite on <samp>foo.p</samp> does not necessarily mean that
<code>make</code> will remake <samp>foo.o</samp> according to the implicit rule to
make an object file, a <samp>.o</samp> file, from a Pascal source file, a
<samp>.p</samp> file. For example, if <samp>foo.c</samp> also exists, the implicit
rule to make an object file from a C source file is used instead,
because it appears before the Pascal rule in the list of predefined
implicit rules (see <a href="#Catalogue-of-Rules">Catalogue of Built-In
Rules</a>).
</p>
<p>If you do not want an implicit rule to be used for a target that has no
recipe, you can give that target an empty recipe by writing a semicolon
(see <a href="Recipes.html#Empty-Recipes">Defining Empty Recipes</a>).
</p>
<hr>
<a name="Catalogue-of-Rules"></a>
<div class="header">
<p>
Next: <a href="#Implicit-Variables" accesskey="n" rel="next">Implicit Variables</a>, Previous: <a href="#Using-Implicit" accesskey="p" rel="prev">Using Implicit</a>, Up: <a href="#Implicit-Rules" accesskey="u" rel="up">Implicit Rules</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="Catalogue-of-Built_002dIn-Rules"></a>
<h3 class="section">10.2 Catalogue of Built-In Rules</h3>
<a name="index-implicit-rule_002c-predefined"></a>
<a name="index-rule_002c-implicit_002c-predefined"></a>
<p>Here is a catalogue of predefined implicit rules which are always
available unless the makefile explicitly overrides or cancels them.
See <a href="#Canceling-Rules">Canceling Implicit Rules</a>, for information on
canceling or overriding an implicit rule. The ‘<samp>-r</samp>’ or
‘<samp>--no-builtin-rules</samp>’ option cancels all predefined rules.
</p>
<p>This manual only documents the default rules available on POSIX-based
operating systems. Other operating systems, such as VMS, Windows,
OS/2, etc. may have different sets of default rules. To see the full
list of default rules and variables available in your version of GNU
<code>make</code>, run ‘<samp>make -p</samp>’ in a directory with no makefile.
</p>
<p>Not all of these rules will always be defined, even when the ‘<samp>-r</samp>’
option is not given. Many of the predefined implicit rules are
implemented in <code>make</code> as suffix rules, so which ones will be
defined depends on the <em>suffix list</em> (the list of prerequisites of
the special target <code>.SUFFIXES</code>). The default suffix list is:
<code>.out</code>, <code>.a</code>, <code>.ln</code>, <code>.o</code>, <code>.c</code>, <code>.cc</code>,
<code>.C</code>, <code>.cpp</code>, <code>.p</code>, <code>.f</code>, <code>.F</code>, <code>.m</code>,
<code>.r</code>, <code>.y</code>, <code>.l</code>, <code>.ym</code>, <code>.lm</code>, <code>.s</code>,
<code>.S</code>, <code>.mod</code>, <code>.sym</code>, <code>.def</code>, <code>.h</code>,
<code>.info</code>, <code>.dvi</code>, <code>.tex</code>, <code>.texinfo</code>, <code>.texi</code>,
<code>.txinfo</code>, <code>.w</code>, <code>.ch</code> <code>.web</code>, <code>.sh</code>,
<code>.elc</code>, <code>.el</code>. All of the implicit rules described below
whose prerequisites have one of these suffixes are actually suffix
rules. If you modify the suffix list, the only predefined suffix
rules in effect will be those named by one or two of the suffixes that
are on the list you specify; rules whose suffixes fail to be on the
list are disabled. See <a href="#Suffix-Rules">Old-Fashioned Suffix Rules</a>,
for full details on suffix rules.
</p>
<dl compact="compact">
<dt>Compiling C programs</dt>
<dd><a name="index-C_002c-rule-to-compile"></a>
<a name="index-cc"></a>
<a name="index-gcc"></a>
<a name="index-_002eo"></a>
<a name="index-_002ec"></a>
<p><samp><var>n</var>.o</samp> is made automatically from <samp><var>n</var>.c</samp> with
a recipe of the form ‘<samp>$(CC) $(CPPFLAGS) $(CFLAGS) -c</samp>’.
</p>
</dd>
<dt>Compiling C++ programs</dt>
<dd><a name="index-C_002b_002b_002c-rule-to-compile"></a>
<a name="index-g_002b_002b"></a>
<a name="index-_002ecc"></a>
<a name="index-_002ecpp"></a>
<a name="index-_002eC"></a>
<p><samp><var>n</var>.o</samp> is made automatically from <samp><var>n</var>.cc</samp>,
<samp><var>n</var>.cpp</samp>, or <samp><var>n</var>.C</samp> with a recipe of the form
‘<samp>$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c</samp>’. We encourage you to use the
suffix ‘<samp>.cc</samp>’ for C++ source files instead of ‘<samp>.C</samp>’.
</p>
</dd>
<dt>Compiling Pascal programs</dt>
<dd><a name="index-Pascal_002c-rule-to-compile"></a>
<a name="index-pc"></a>
<a name="index-_002ep"></a>
<p><samp><var>n</var>.o</samp> is made automatically from <samp><var>n</var>.p</samp>
with the recipe ‘<samp>$(PC) $(PFLAGS) -c</samp>’.
</p>
</dd>
<dt>Compiling Fortran and Ratfor programs</dt>
<dd><a name="index-Fortran_002c-rule-to-compile"></a>
<a name="index-Ratfor_002c-rule-to-compile"></a>
<a name="index-f77"></a>
<a name="index-_002ef"></a>
<a name="index-_002er"></a>
<a name="index-_002eF"></a>
<p><samp><var>n</var>.o</samp> is made automatically from <samp><var>n</var>.r</samp>,
<samp><var>n</var>.F</samp> or <samp><var>n</var>.f</samp> by running the
Fortran compiler. The precise recipe used is as follows:
</p>
<dl compact="compact">
<dt>‘<samp>.f</samp>’</dt>
<dd><p>‘<samp>$(FC) $(FFLAGS) -c</samp>’.
</p></dd>
<dt>‘<samp>.F</samp>’</dt>
<dd><p>‘<samp>$(FC) $(FFLAGS) $(CPPFLAGS) -c</samp>’.
</p></dd>
<dt>‘<samp>.r</samp>’</dt>
<dd><p>‘<samp>$(FC) $(FFLAGS) $(RFLAGS) -c</samp>’.
</p></dd>
</dl>
</dd>
<dt>Preprocessing Fortran and Ratfor programs</dt>
<dd><p><samp><var>n</var>.f</samp> is made automatically from <samp><var>n</var>.r</samp> or
<samp><var>n</var>.F</samp>. This rule runs just the preprocessor to convert a
Ratfor or preprocessable Fortran program into a strict Fortran
program. The precise recipe used is as follows:
</p>
<dl compact="compact">
<dt>‘<samp>.F</samp>’</dt>
<dd><p>‘<samp>$(FC) $(CPPFLAGS) $(FFLAGS) -F</samp>’.
</p></dd>
<dt>‘<samp>.r</samp>’</dt>
<dd><p>‘<samp>$(FC) $(FFLAGS) $(RFLAGS) -F</samp>’.
</p></dd>
</dl>
</dd>
<dt>Compiling Modula-2 programs</dt>
<dd><a name="index-Modula_002d2_002c-rule-to-compile"></a>
<a name="index-m2c"></a>
<a name="index-_002esym"></a>
<a name="index-_002edef"></a>
<a name="index-_002emod"></a>
<p><samp><var>n</var>.sym</samp> is made from <samp><var>n</var>.def</samp> with a recipe
of the form ‘<samp>$(M2C) $(M2FLAGS) $(DEFFLAGS)</samp>’. <samp><var>n</var>.o</samp>
is made from <samp><var>n</var>.mod</samp>; the form is:
‘<samp>$(M2C) $(M2FLAGS) $(MODFLAGS)</samp>’<!-- /@w -->.
</p>
</dd>
<dt>Assembling and preprocessing assembler programs</dt>
<dd><a name="index-assembly_002c-rule-to-compile"></a>
<a name="index-as"></a>
<a name="index-_002es"></a>
<p><samp><var>n</var>.o</samp> is made automatically from <samp><var>n</var>.s</samp> by
running the assembler, <code>as</code>. The precise recipe is
‘<samp>$(AS) $(ASFLAGS)</samp>’.
</p>
<a name="index-_002eS"></a>
<p><samp><var>n</var>.s</samp> is made automatically from <samp><var>n</var>.S</samp> by
running the C preprocessor, <code>cpp</code>. The precise recipe is
‘<samp>$(CPP) $(CPPFLAGS)</samp>’<!-- /@w -->.
</p>
</dd>
<dt>Linking a single object file</dt>
<dd><a name="index-linking_002c-predefined-rule-for"></a>
<a name="index-ld"></a>
<a name="index-_002eo-1"></a>
<p><samp><var>n</var></samp> is made automatically from <samp><var>n</var>.o</samp> by running
the linker (usually called <code>ld</code>) via the C compiler. The precise
recipe used is ‘<samp>$(CC) $(LDFLAGS) <var>n</var>.o $(LOADLIBES) $(LDLIBS)</samp>’<!-- /@w -->.
</p>
<p>This rule does the right thing for a simple program with only one
source file. It will also do the right thing if there are multiple
object files (presumably coming from various other source files), one
of which has a name matching that of the executable file. Thus,
</p>
<div class="example">
<pre class="example">x: y.o z.o
</pre></div>
<p>when <samp>x.c</samp>, <samp>y.c</samp> and <samp>z.c</samp> all exist will execute:
</p>
<div class="example">
<pre class="example">cc -c x.c -o x.o
cc -c y.c -o y.o
cc -c z.c -o z.o
cc x.o y.o z.o -o x
rm -f x.o
rm -f y.o
rm -f z.o
</pre></div>
<p>In more complicated cases, such as when there is no object file whose
name derives from the executable file name, you must write an explicit
recipe for linking.
</p>
<p>Each kind of file automatically made into ‘<samp>.o</samp>’ object files will
be automatically linked by using the compiler (‘<samp>$(CC)</samp>’,
‘<samp>$(FC)</samp>’ or ‘<samp>$(PC)</samp>’; the C compiler ‘<samp>$(CC)</samp>’ is used to
assemble ‘<samp>.s</samp>’ files) without the ‘<samp>-c</samp>’ option. This could be
done by using the ‘<samp>.o</samp>’ object files as intermediates, but it is
faster to do the compiling and linking in one step, so that’s how it’s
done.
</p>
</dd>
<dt>Yacc for C programs</dt>
<dd><a name="index-yacc-1"></a>
<a name="index-Yacc_002c-rule-to-run"></a>
<a name="index-_002ey"></a>
<p><samp><var>n</var>.c</samp> is made automatically from <samp><var>n</var>.y</samp> by
running Yacc with the recipe ‘<samp>$(YACC) $(YFLAGS)</samp>’.
</p>
</dd>
<dt>Lex for C programs</dt>
<dd><a name="index-lex"></a>
<a name="index-Lex_002c-rule-to-run"></a>
<a name="index-_002el"></a>
<p><samp><var>n</var>.c</samp> is made automatically from <samp><var>n</var>.l</samp> by
running Lex. The actual recipe is ‘<samp>$(LEX) $(LFLAGS)</samp>’.
</p>
</dd>
<dt>Lex for Ratfor programs</dt>
<dd><p><samp><var>n</var>.r</samp> is made automatically from <samp><var>n</var>.l</samp> by
running Lex. The actual recipe is ‘<samp>$(LEX) $(LFLAGS)</samp>’.
</p>
<p>The convention of using the same suffix ‘<samp>.l</samp>’ for all Lex files
regardless of whether they produce C code or Ratfor code makes it
impossible for <code>make</code> to determine automatically which of the two
languages you are using in any particular case. If <code>make</code> is
called upon to remake an object file from a ‘<samp>.l</samp>’ file, it must
guess which compiler to use. It will guess the C compiler, because
that is more common. If you are using Ratfor, make sure <code>make</code>
knows this by mentioning <samp><var>n</var>.r</samp> in the makefile. Or, if you
are using Ratfor exclusively, with no C files, remove ‘<samp>.c</samp>’ from
the list of implicit rule suffixes with:
</p>
<div class="example">
<pre class="example">.SUFFIXES:
.SUFFIXES: .o .r .f .l …
</pre></div>
</dd>
<dt>Making Lint Libraries from C, Yacc, or Lex programs</dt>
<dd><a name="index-lint"></a>
<a name="index-lint_002c-rule-to-run"></a>
<a name="index-_002eln"></a>
<p><samp><var>n</var>.ln</samp> is made from <samp><var>n</var>.c</samp> by running <code>lint</code>.
The precise recipe is ‘<samp>$(LINT) $(LINTFLAGS) $(CPPFLAGS) <span class="nolinebreak">-i</span></samp>’<!-- /@w -->.
The same recipe is used on the C code produced from
<samp><var>n</var>.y</samp> or <samp><var>n</var>.l</samp>.
</p>
</dd>
<dt>TeX and Web</dt>
<dd><a name="index-TeX_002c-rule-to-run"></a>
<a name="index-Web_002c-rule-to-run"></a>
<a name="index-tex"></a>
<a name="index-cweave"></a>
<a name="index-weave"></a>
<a name="index-tangle"></a>
<a name="index-ctangle"></a>
<a name="index-_002edvi"></a>
<a name="index-_002etex"></a>
<a name="index-_002eweb"></a>
<a name="index-_002ew"></a>
<a name="index-_002ech"></a>
<p><samp><var>n</var>.dvi</samp> is made from <samp><var>n</var>.tex</samp> with the recipe
‘<samp>$(TEX)</samp>’. <samp><var>n</var>.tex</samp> is made from <samp><var>n</var>.web</samp> with
‘<samp>$(WEAVE)</samp>’, or from <samp><var>n</var>.w</samp> (and from <samp><var>n</var>.ch</samp> if
it exists or can be made) with ‘<samp>$(CWEAVE)</samp>’. <samp><var>n</var>.p</samp> is
made from <samp><var>n</var>.web</samp> with ‘<samp>$(TANGLE)</samp>’ and <samp><var>n</var>.c</samp>
is made from <samp><var>n</var>.w</samp> (and from <samp><var>n</var>.ch</samp> if it exists
or can be made) with ‘<samp>$(CTANGLE)</samp>’.
</p>
</dd>
<dt>Texinfo and Info</dt>
<dd><a name="index-Texinfo_002c-rule-to-format"></a>
<a name="index-Info_002c-rule-to-format"></a>
<a name="index-texi2dvi"></a>
<a name="index-makeinfo"></a>
<a name="index-_002etexinfo"></a>
<a name="index-_002einfo"></a>
<a name="index-_002etexi"></a>
<a name="index-_002etxinfo"></a>
<p><samp><var>n</var>.dvi</samp> is made from <samp><var>n</var>.texinfo</samp>,
<samp><var>n</var>.texi</samp>, or <samp><var>n</var>.txinfo</samp>, with the recipe
‘<samp>$(TEXI2DVI) <span class="nolinebreak">$(TEXI2DVI_FLAGS)</span></samp>’<!-- /@w -->. <samp><var>n</var>.info</samp> is made from
<samp><var>n</var>.texinfo</samp>, <samp><var>n</var>.texi</samp>, or <samp><var>n</var>.txinfo</samp>, with
the recipe ‘<samp>$(MAKEINFO) <span class="nolinebreak">$(MAKEINFO_FLAGS)</span></samp>’<!-- /@w -->.
</p>
</dd>
<dt>RCS</dt>
<dd><a name="index-RCS_002c-rule-to-extract-from"></a>
<a name="index-co"></a>
<a name="index-_002cv-_0028RCS-file-extension_0029"></a>
<p>Any file <samp><var>n</var></samp> is extracted if necessary from an RCS file
named either <samp><var>n</var>,v</samp> or <samp>RCS/<var>n</var>,v</samp>. The precise
recipe used is ‘<samp>$(CO) $(COFLAGS)</samp>’<!-- /@w -->. <samp><var>n</var></samp> will not be
extracted from RCS if it already exists, even if the RCS file is
newer. The rules for RCS are terminal
(see <a href="#Match_002dAnything-Rules">Match-Anything Pattern Rules</a>),
so RCS files cannot be generated from another source; they must
actually exist.
</p>
</dd>
<dt>SCCS</dt>
<dd><a name="index-SCCS_002c-rule-to-extract-from"></a>
<a name="index-get"></a>
<a name="index-s_002e-_0028SCCS-file-prefix_0029"></a>
<p>Any file <samp><var>n</var></samp> is extracted if necessary from an SCCS file
named either <samp>s.<var>n</var></samp> or <samp>SCCS/s.<var>n</var></samp>. The precise
recipe used is ‘<samp>$(GET) $(GFLAGS)</samp>’<!-- /@w -->. The rules for SCCS are
terminal (see <a href="#Match_002dAnything-Rules">Match-Anything Pattern Rules</a>),
so SCCS files cannot be generated from another source; they must
actually exist.
</p>
<a name="index-_002esh"></a>
<p>For the benefit of SCCS, a file <samp><var>n</var></samp> is copied from
<samp><var>n</var>.sh</samp> and made executable (by everyone). This is for
shell scripts that are checked into SCCS. Since RCS preserves the
execution permission of a file, you do not need to use this feature
with RCS.
</p>
<p>We recommend that you avoid using of SCCS. RCS is widely held to be
superior, and is also free. By choosing free software in place of
comparable (or inferior) proprietary software, you support the free
software movement.
</p></dd>
</dl>
<p>Usually, you want to change only the variables listed in the table
above, which are documented in the following section.
</p>
<p>However, the recipes in built-in implicit rules actually use
variables such as <code>COMPILE.c</code>, <code>LINK.p</code>, and
<code>PREPROCESS.S</code>, whose values contain the recipes listed above.
</p>
<p><code>make</code> follows the convention that the rule to compile a
<samp>.<var>x</var></samp> source file uses the variable <code>COMPILE.<var>x</var></code>.
Similarly, the rule to produce an executable from a <samp>.<var>x</var></samp>
file uses <code>LINK.<var>x</var></code>; and the rule to preprocess a
<samp>.<var>x</var></samp> file uses <code>PREPROCESS.<var>x</var></code>.
</p>
<a name="index-OUTPUT_005fOPTION"></a>
<p>Every rule that produces an object file uses the variable
<code>OUTPUT_OPTION</code>. <code>make</code> defines this variable either to
contain ‘<samp>-o $@</samp>’, or to be empty, depending on a compile-time
option. You need the ‘<samp>-o</samp>’ option to ensure that the output goes
into the right file when the source file is in a different directory,
as when using <code>VPATH</code> (see <a href="Rules.html#Directory-Search">Directory Search</a>). However,
compilers on some systems do not accept a ‘<samp>-o</samp>’ switch for object
files. If you use such a system, and use <code>VPATH</code>, some
compilations will put their output in the wrong place.
A possible workaround for this problem is to give <code>OUTPUT_OPTION</code>
the value ‘<samp>; mv $*.o $@</samp>’<!-- /@w -->.
</p>
<hr>
<a name="Implicit-Variables"></a>
<div class="header">
<p>
Next: <a href="#Chained-Rules" accesskey="n" rel="next">Chained Rules</a>, Previous: <a href="#Catalogue-of-Rules" accesskey="p" rel="prev">Catalogue of Rules</a>, Up: <a href="#Implicit-Rules" accesskey="u" rel="up">Implicit Rules</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="Variables-Used-by-Implicit-Rules"></a>
<h3 class="section">10.3 Variables Used by Implicit Rules</h3>
<a name="index-flags-for-compilers"></a>
<p>The recipes in built-in implicit rules make liberal use of certain
predefined variables. You can alter the values of these variables in
the makefile, with arguments to <code>make</code>, or in the environment to
alter how the implicit rules work without redefining the rules
themselves. You can cancel all variables used by implicit rules with
the ‘<samp>-R</samp>’ or ‘<samp>--no-builtin-variables</samp>’ option.
</p>
<p>For example, the recipe used to compile a C source file actually says
‘<samp>$(CC) -c $(CFLAGS) $(CPPFLAGS)</samp>’. The default values of the variables
used are ‘<samp>cc</samp>’ and nothing, resulting in the command ‘<samp>cc -c</samp>’. By
redefining ‘<samp>CC</samp>’ to ‘<samp>ncc</samp>’, you could cause ‘<samp>ncc</samp>’ to be
used for all C compilations performed by the implicit rule. By redefining
‘<samp>CFLAGS</samp>’ to be ‘<samp>-g</samp>’, you could pass the ‘<samp>-g</samp>’ option to
each compilation. <em>All</em> implicit rules that do C compilation use
‘<samp>$(CC)</samp>’ to get the program name for the compiler and <em>all</em>
include ‘<samp>$(CFLAGS)</samp>’ among the arguments given to the compiler.
</p>
<p>The variables used in implicit rules fall into two classes: those that are
names of programs (like <code>CC</code>) and those that contain arguments for the
programs (like <code>CFLAGS</code>). (The “name of a program” may also contain
some command arguments, but it must start with an actual executable program
name.) If a variable value contains more than one argument, separate them
with spaces.
</p>
<p>The following tables describe of some of the more commonly-used predefined
variables. This list is not exhaustive, and the default values shown here may
not be what <code>make</code> selects for your environment. To see the
complete list of predefined variables for your instance of GNU <code>make</code> you
can run ‘<samp>make -p</samp>’ in a directory with no makefiles.
</p>
<p>Here is a table of some of the more common variables used as names of
programs in built-in rules:
</p>
<dl compact="compact">
<dt><code>AR</code></dt>
<dd><a name="index-AR"></a>
<p>Archive-maintaining program; default ‘<samp>ar</samp>’.
<a name="index-ar"></a>
</p>
</dd>
<dt><code>AS</code></dt>
<dd><a name="index-AS"></a>
<p>Program for compiling assembly files; default ‘<samp>as</samp>’.
<a name="index-as-1"></a>
</p>
</dd>
<dt><code>CC</code></dt>
<dd><a name="index-CC"></a>
<p>Program for compiling C programs; default ‘<samp>cc</samp>’.
<a name="index-cc-1"></a>
</p>
</dd>
<dt><code>CXX</code></dt>
<dd><a name="index-CXX"></a>
<p>Program for compiling C++ programs; default ‘<samp>g++</samp>’.
<a name="index-g_002b_002b-1"></a>
</p>
</dd>
<dt><code>CPP</code></dt>
<dd><a name="index-CPP"></a>
<p>Program for running the C preprocessor, with results to standard output;
default ‘<samp>$(CC) -E</samp>’.
</p>
</dd>
<dt><code>FC</code></dt>
<dd><a name="index-FC"></a>
<p>Program for compiling or preprocessing Fortran and Ratfor programs;
default ‘<samp>f77</samp>’.
<a name="index-f77-1"></a>
</p>
</dd>
<dt><code>M2C</code></dt>
<dd><a name="index-M2C"></a>
<p>Program to use to compile Modula-2 source code; default ‘<samp>m2c</samp>’.
<a name="index-m2c-1"></a>
</p>
</dd>
<dt><code>PC</code></dt>
<dd><a name="index-PC"></a>
<p>Program for compiling Pascal programs; default ‘<samp>pc</samp>’.
<a name="index-pc-1"></a>
</p>
</dd>
<dt><code>CO</code></dt>
<dd><a name="index-CO"></a>
<p>Program for extracting a file from RCS; default ‘<samp>co</samp>’.
<a name="index-co-1"></a>
</p>
</dd>
<dt><code>GET</code></dt>
<dd><a name="index-GET"></a>
<p>Program for extracting a file from SCCS; default ‘<samp>get</samp>’.
<a name="index-get-1"></a>
</p>
</dd>
<dt><code>LEX</code></dt>
<dd><a name="index-LEX"></a>
<p>Program to use to turn Lex grammars into source code; default ‘<samp>lex</samp>’.
<a name="index-lex-1"></a>
</p>
</dd>
<dt><code>YACC</code></dt>
<dd><a name="index-YACC"></a>
<p>Program to use to turn Yacc grammars into source code; default ‘<samp>yacc</samp>’.
<a name="index-yacc-2"></a>
</p>
</dd>
<dt><code>LINT</code></dt>
<dd><a name="index-LINT"></a>
<p>Program to use to run lint on source code; default ‘<samp>lint</samp>’.
<a name="index-lint-1"></a>
</p>
</dd>
<dt><code>MAKEINFO</code></dt>
<dd><a name="index-MAKEINFO"></a>
<p>Program to convert a Texinfo source file into an Info file; default
‘<samp>makeinfo</samp>’.
<a name="index-makeinfo-1"></a>
</p>
</dd>
<dt><code>TEX</code></dt>
<dd><a name="index-TEX"></a>
<p>Program to make TeX <small>DVI</small> files from TeX source;
default ‘<samp>tex</samp>’.
<a name="index-tex-1"></a>
</p>
</dd>
<dt><code>TEXI2DVI</code></dt>
<dd><a name="index-TEXI2DVI"></a>
<p>Program to make TeX <small>DVI</small> files from Texinfo source;
default ‘<samp>texi2dvi</samp>’.
<a name="index-texi2dvi-1"></a>
</p>
</dd>
<dt><code>WEAVE</code></dt>
<dd><a name="index-WEAVE"></a>
<p>Program to translate Web into TeX; default ‘<samp>weave</samp>’.
<a name="index-weave-1"></a>
</p>
</dd>
<dt><code>CWEAVE</code></dt>
<dd><a name="index-CWEAVE"></a>
<p>Program to translate C Web into TeX; default ‘<samp>cweave</samp>’.
<a name="index-cweave-1"></a>
</p>
</dd>
<dt><code>TANGLE</code></dt>
<dd><a name="index-TANGLE"></a>
<p>Program to translate Web into Pascal; default ‘<samp>tangle</samp>’.
<a name="index-tangle-1"></a>
</p>
</dd>
<dt><code>CTANGLE</code></dt>
<dd><a name="index-CTANGLE"></a>
<p>Program to translate C Web into C; default ‘<samp>ctangle</samp>’.
<a name="index-ctangle-1"></a>
</p>
</dd>
<dt><code>RM</code></dt>
<dd><a name="index-RM"></a>
<p>Command to remove a file; default ‘<samp>rm -f</samp>’.
<a name="index-rm"></a>
</p></dd>
</dl>
<p>Here is a table of variables whose values are additional arguments for the
programs above. The default values for all of these is the empty
string, unless otherwise noted.
</p>
<dl compact="compact">
<dt><code>ARFLAGS</code></dt>
<dd><a name="index-ARFLAGS"></a>
<p>Flags to give the archive-maintaining program; default ‘<samp>rv</samp>’.
</p>
</dd>
<dt><code>ASFLAGS</code></dt>
<dd><a name="index-ASFLAGS"></a>
<p>Extra flags to give to the assembler (when explicitly
invoked on a ‘<samp>.s</samp>’ or ‘<samp>.S</samp>’ file).
</p>
</dd>
<dt><code>CFLAGS</code></dt>
<dd><a name="index-CFLAGS"></a>
<p>Extra flags to give to the C compiler.
</p>
</dd>
<dt><code>CXXFLAGS</code></dt>
<dd><a name="index-CXXFLAGS"></a>
<p>Extra flags to give to the C++ compiler.
</p>
</dd>
<dt><code>COFLAGS</code></dt>
<dd><a name="index-COFLAGS"></a>
<p>Extra flags to give to the RCS <code>co</code> program.
</p>
</dd>
<dt><code>CPPFLAGS</code></dt>
<dd><a name="index-CPPFLAGS"></a>
<p>Extra flags to give to the C preprocessor and programs
that use it (the C and Fortran compilers).
</p>
</dd>
<dt><code>FFLAGS</code></dt>
<dd><a name="index-FFLAGS"></a>
<p>Extra flags to give to the Fortran compiler.
</p>
</dd>
<dt><code>GFLAGS</code></dt>
<dd><a name="index-GFLAGS"></a>
<p>Extra flags to give to the SCCS <code>get</code> program.
</p>
</dd>
<dt><code>LDFLAGS</code></dt>
<dd><a name="index-LDFLAGS"></a>
<p>Extra flags to give to compilers when they are supposed to invoke the linker,
‘<samp>ld</samp>’, such as <code>-L</code>. Libraries (<code>-lfoo</code>) should be
added to the <code>LDLIBS</code> variable instead.
</p>
</dd>
<dt><code>LDLIBS</code></dt>
<dd><a name="index-LDLIBS"></a>
<a name="index-LOADLIBES"></a>
<p>Library flags or names given to compilers when they are supposed to
invoke the linker, ‘<samp>ld</samp>’. <code>LOADLIBES</code> is a deprecated (but
still supported) alternative to <code>LDLIBS</code>. Non-library linker
flags, such as <code>-L</code>, should go in the <code>LDFLAGS</code> variable.
</p>
</dd>
<dt><code>LFLAGS</code></dt>
<dd><a name="index-LFLAGS"></a>
<p>Extra flags to give to Lex.
</p>
</dd>
<dt><code>YFLAGS</code></dt>
<dd><a name="index-YFLAGS"></a>
<p>Extra flags to give to Yacc.
</p>
</dd>
<dt><code>PFLAGS</code></dt>
<dd><a name="index-PFLAGS"></a>
<p>Extra flags to give to the Pascal compiler.
</p>
</dd>
<dt><code>RFLAGS</code></dt>
<dd><a name="index-RFLAGS"></a>
<p>Extra flags to give to the Fortran compiler for Ratfor programs.
</p>
</dd>
<dt><code>LINTFLAGS</code></dt>
<dd><a name="index-LINTFLAGS"></a>
<p>Extra flags to give to lint.
</p></dd>
</dl>
<hr>
<a name="Chained-Rules"></a>
<div class="header">
<p>
Next: <a href="#Pattern-Rules" accesskey="n" rel="next">Pattern Rules</a>, Previous: <a href="#Implicit-Variables" accesskey="p" rel="prev">Implicit Variables</a>, Up: <a href="#Implicit-Rules" accesskey="u" rel="up">Implicit Rules</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="Chains-of-Implicit-Rules"></a>
<h3 class="section">10.4 Chains of Implicit Rules</h3>
<a name="index-chains-of-rules"></a>
<a name="index-rule_002c-implicit_002c-chains-of"></a>
<p>Sometimes a file can be made by a sequence of implicit rules. For example,
a file <samp><var>n</var>.o</samp> could be made from <samp><var>n</var>.y</samp> by running
first Yacc and then <code>cc</code>. Such a sequence is called a <em>chain</em>.
</p>
<p>If the file <samp><var>n</var>.c</samp> exists, or is mentioned in the makefile, no
special searching is required: <code>make</code> finds that the object file can
be made by C compilation from <samp><var>n</var>.c</samp>; later on, when considering
how to make <samp><var>n</var>.c</samp>, the rule for running Yacc is
used. Ultimately both <samp><var>n</var>.c</samp> and <samp><var>n</var>.o</samp> are
updated.
</p>
<a name="index-intermediate-files"></a>
<a name="index-files_002c-intermediate"></a>
<p>However, even if <samp><var>n</var>.c</samp> does not exist and is not mentioned,
<code>make</code> knows how to envision it as the missing link between
<samp><var>n</var>.o</samp> and <samp><var>n</var>.y</samp>! In this case, <samp><var>n</var>.c</samp> is
called an <em>intermediate file</em>. Once <code>make</code> has decided to use the
intermediate file, it is entered in the data base as if it had been
mentioned in the makefile, along with the implicit rule that says how to
create it.
</p>
<p>Intermediate files are remade using their rules just like all other
files. But intermediate files are treated differently in two ways.
</p>
<p>The first difference is what happens if the intermediate file does not
exist. If an ordinary file <var>b</var> does not exist, and <code>make</code>
considers a target that depends on <var>b</var>, it invariably creates
<var>b</var> and then updates the target from <var>b</var>. But if <var>b</var> is an
intermediate file, then <code>make</code> can leave well enough alone. It
won’t bother updating <var>b</var>, or the ultimate target, unless some
prerequisite of <var>b</var> is newer than that target or there is some other
reason to update that target.
</p>
<p>The second difference is that if <code>make</code> <em>does</em> create <var>b</var>
in order to update something else, it deletes <var>b</var> later on after it
is no longer needed. Therefore, an intermediate file which did not
exist before <code>make</code> also does not exist after <code>make</code>.
<code>make</code> reports the deletion to you by printing a ‘<samp>rm -f</samp>’
command showing which file it is deleting.
</p>
<p>Ordinarily, a file cannot be intermediate if it is mentioned in the
makefile as a target or prerequisite. However, you can explicitly mark a
file as intermediate by listing it as a prerequisite of the special target
<code>.INTERMEDIATE</code>. This takes effect even if the file is mentioned
explicitly in some other way.
</p>
<a name="index-intermediate-files_002c-preserving"></a>
<a name="index-preserving-intermediate-files"></a>
<a name="index-secondary-files"></a>
<p>You can prevent automatic deletion of an intermediate file by marking it
as a <em>secondary</em> file. To do this, list it as a prerequisite of the
special target <code>.SECONDARY</code>. When a file is secondary, <code>make</code>
will not create the file merely because it does not already exist, but
<code>make</code> does not automatically delete the file. Marking a file as
secondary also marks it as intermediate.
</p>
<p>You can list the target pattern of an implicit rule (such as ‘<samp>%.o</samp>’)
as a prerequisite of the special target <code>.PRECIOUS</code> to preserve
intermediate files made by implicit rules whose target patterns match
that file’s name; see <a href="Recipes.html#Interrupts">Interrupts</a>.
<a name="index-preserving-with-_002ePRECIOUS-1"></a>
<a name="index-_002ePRECIOUS-intermediate-files"></a>
</p>
<p>A chain can involve more than two implicit rules. For example, it is
possible to make a file <samp>foo</samp> from <samp>RCS/foo.y,v</samp> by running RCS,
Yacc and <code>cc</code>. Then both <samp>foo.y</samp> and <samp>foo.c</samp> are
intermediate files that are deleted at the end.
</p>
<p>No single implicit rule can appear more than once in a chain. This means
that <code>make</code> will not even consider such a ridiculous thing as making
<samp>foo</samp> from <samp>foo.o.o</samp> by running the linker twice. This
constraint has the added benefit of preventing any infinite loop in the
search for an implicit rule chain.
</p>
<p>There are some special implicit rules to optimize certain cases that would
otherwise be handled by rule chains. For example, making <samp>foo</samp> from
<samp>foo.c</samp> could be handled by compiling and linking with separate
chained rules, using <samp>foo.o</samp> as an intermediate file. But what
actually happens is that a special rule for this case does the compilation
and linking with a single <code>cc</code> command. The optimized rule is used in
preference to the step-by-step chain because it comes earlier in the
ordering of rules.
</p>
<hr>
<a name="Pattern-Rules"></a>
<div class="header">
<p>
Next: <a href="#Last-Resort" accesskey="n" rel="next">Last Resort</a>, Previous: <a href="#Chained-Rules" accesskey="p" rel="prev">Chained Rules</a>, Up: <a href="#Implicit-Rules" accesskey="u" rel="up">Implicit Rules</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="Defining-and-Redefining-Pattern-Rules"></a>
<h3 class="section">10.5 Defining and Redefining Pattern Rules</h3>
<p>You define an implicit rule by writing a <em>pattern rule</em>. A pattern
rule looks like an ordinary rule, except that its target contains the
character ‘<samp>%</samp>’ (exactly one of them). The target is considered a
pattern for matching file names; the ‘<samp>%</samp>’ can match any nonempty
substring, while other characters match only themselves. The prerequisites
likewise use ‘<samp>%</samp>’ to show how their names relate to the target name.
</p>
<p>Thus, a pattern rule ‘<samp>%.o : %.c</samp>’ says how to make any file
<samp><var>stem</var>.o</samp> from another file <samp><var>stem</var>.c</samp>.
</p>
<p>Note that expansion using ‘<samp>%</samp>’ in pattern rules occurs
<strong>after</strong> any variable or function expansions, which take place
when the makefile is read. See <a href="Using-Variables.html#Using-Variables">How to Use
Variables</a>, and <a href="Functions.html#Functions">Functions for Transforming Text</a>.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Pattern-Intro" accesskey="1">Pattern Intro</a>:</td><td> </td><td align="left" valign="top">An introduction to pattern rules.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Pattern-Examples" accesskey="2">Pattern Examples</a>:</td><td> </td><td align="left" valign="top">Examples of pattern rules.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Automatic-Variables" accesskey="3">Automatic Variables</a>:</td><td> </td><td align="left" valign="top">How to use automatic variables in the
recipe of implicit rules.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Pattern-Match" accesskey="4">Pattern Match</a>:</td><td> </td><td align="left" valign="top">How patterns match.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Match_002dAnything-Rules" accesskey="5">Match-Anything Rules</a>:</td><td> </td><td align="left" valign="top">Precautions you should take prior to
defining rules that can match any
target file whatever.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Canceling-Rules" accesskey="6">Canceling Rules</a>:</td><td> </td><td align="left" valign="top">How to override or cancel built-in rules.
</td></tr>
</table>
<hr>
<a name="Pattern-Intro"></a>
<div class="header">
<p>
Next: <a href="#Pattern-Examples" accesskey="n" rel="next">Pattern Examples</a>, Previous: <a href="#Pattern-Rules" accesskey="p" rel="prev">Pattern Rules</a>, Up: <a href="#Pattern-Rules" accesskey="u" rel="up">Pattern Rules</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="Introduction-to-Pattern-Rules"></a>
<h4 class="subsection">10.5.1 Introduction to Pattern Rules</h4>
<a name="index-pattern-rule"></a>
<a name="index-rule_002c-pattern"></a>
<p>A pattern rule contains the character ‘<samp>%</samp>’ (exactly one of them)
in the target; otherwise, it looks exactly like an ordinary rule. The
target is a pattern for matching file names; the ‘<samp>%</samp>’ matches any
nonempty substring, while other characters match only themselves.
<a name="index-target-pattern_002c-implicit"></a>
<a name="index-_0025_002c-in-pattern-rules"></a>
</p>
<p>For example, ‘<samp>%.c</samp>’ as a pattern matches any file name that ends in
‘<samp>.c</samp>’. ‘<samp>s.%.c</samp>’ as a pattern matches any file name that starts
with ‘<samp>s.</samp>’, ends in ‘<samp>.c</samp>’ and is at least five characters long.
(There must be at least one character to match the ‘<samp>%</samp>’.) The substring
that the ‘<samp>%</samp>’ matches is called the <em>stem</em>.
</p>
<p>‘<samp>%</samp>’ in a prerequisite of a pattern rule stands for the same stem
that was matched by the ‘<samp>%</samp>’ in the target. In order for the
pattern rule to apply, its target pattern must match the file name
under consideration and all of its prerequisites (after pattern
substitution) must name files that exist or can be made. These files
become prerequisites of the target.
<a name="index-prerequisite-pattern_002c-implicit"></a>
</p>
<p>Thus, a rule of the form
</p>
<div class="example">
<pre class="example">%.o : %.c ; <var>recipe</var>…
</pre></div>
<p>specifies how to make a file <samp><var>n</var>.o</samp>, with another file
<samp><var>n</var>.c</samp> as its prerequisite, provided that <samp><var>n</var>.c</samp>
exists or can be made.
</p>
<p>There may also be prerequisites that do not use ‘<samp>%</samp>’; such a prerequisite
attaches to every file made by this pattern rule. These unvarying
prerequisites are useful occasionally.
</p>
<p>A pattern rule need not have any prerequisites that contain ‘<samp>%</samp>’, or
in fact any prerequisites at all. Such a rule is effectively a general
wildcard. It provides a way to make any file that matches the target
pattern. See <a href="#Last-Resort">Last Resort</a>.
</p>
<p>More than one pattern rule may match a target. In this case
<code>make</code> will choose the “best fit” rule. See <a href="#Pattern-Match">How Patterns Match</a>.
</p>
<p>Pattern rules may have more than one target. Unlike normal rules,
this does not act as many different rules with the same prerequisites
and recipe. If a pattern rule has multiple targets, <code>make</code> knows
that the rule’s recipe is responsible for making all of the targets.
The recipe is executed only once to make all the targets. When
searching for a pattern rule to match a target, the target patterns of
a rule other than the one that matches the target in need of a rule
are incidental: <code>make</code> worries only about giving a recipe and
prerequisites to the file presently in question. However, when this
file’s recipe is run, the other targets are marked as having been
updated themselves.
<a name="index-multiple-targets_002c-in-pattern-rule"></a>
<a name="index-target_002c-multiple-in-pattern-rule"></a>
</p>
<hr>
<a name="Pattern-Examples"></a>
<div class="header">
<p>
Next: <a href="#Automatic-Variables" accesskey="n" rel="next">Automatic Variables</a>, Previous: <a href="#Pattern-Intro" accesskey="p" rel="prev">Pattern Intro</a>, Up: <a href="#Pattern-Rules" accesskey="u" rel="up">Pattern Rules</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="Pattern-Rule-Examples"></a>
<h4 class="subsection">10.5.2 Pattern Rule Examples</h4>
<p>Here are some examples of pattern rules actually predefined in
<code>make</code>. First, the rule that compiles ‘<samp>.c</samp>’ files into ‘<samp>.o</samp>’
files:
</p>
<div class="example">
<pre class="example">%.o : %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
</pre></div>
<p>defines a rule that can make any file <samp><var>x</var>.o</samp> from
<samp><var>x</var>.c</samp>. The recipe uses the automatic variables ‘<samp>$@</samp>’ and
‘<samp>$<</samp>’ to substitute the names of the target file and the source file
in each case where the rule applies (see <a href="#Automatic-Variables">Automatic Variables</a>).
</p>
<p>Here is a second built-in rule:
</p>
<div class="example">
<pre class="example">% :: RCS/%,v
$(CO) $(COFLAGS) $<
</pre></div>
<p>defines a rule that can make any file <samp><var>x</var></samp> whatsoever from a
corresponding file <samp><var>x</var>,v</samp> in the sub-directory <samp>RCS</samp>. Since
the target is ‘<samp>%</samp>’, this rule will apply to any file whatever, provided
the appropriate prerequisite file exists. The double colon makes the rule
<em>terminal</em>, which means that its prerequisite may not be an intermediate
file (see <a href="#Match_002dAnything-Rules">Match-Anything Pattern Rules</a>).
</p>
<p>This pattern rule has two targets:
</p>
<div class="example">
<pre class="example">%.tab.c %.tab.h: %.y
bison -d $<
</pre></div>
<p>This tells <code>make</code> that the recipe ‘<samp>bison -d <var>x</var>.y</samp>’ will
make both <samp><var>x</var>.tab.c</samp> and <samp><var>x</var>.tab.h</samp>. If the file
<samp>foo</samp> depends on the files <samp>parse.tab.o</samp> and <samp>scan.o</samp>
and the file <samp>scan.o</samp> depends on the file <samp>parse.tab.h</samp>,
when <samp>parse.y</samp> is changed, the recipe ‘<samp>bison -d parse.y</samp>’
will be executed only once, and the prerequisites of both
<samp>parse.tab.o</samp> and <samp>scan.o</samp> will be satisfied. (Presumably
the file <samp>parse.tab.o</samp> will be recompiled from <samp>parse.tab.c</samp>
and the file <samp>scan.o</samp> from <samp>scan.c</samp>, while <samp>foo</samp> is
linked from <samp>parse.tab.o</samp>, <samp>scan.o</samp>, and its other
prerequisites, and it will execute happily ever after.)
</p>
<hr>
<a name="Automatic-Variables"></a>
<div class="header">
<p>
Next: <a href="#Pattern-Match" accesskey="n" rel="next">Pattern Match</a>, Previous: <a href="#Pattern-Examples" accesskey="p" rel="prev">Pattern Examples</a>, Up: <a href="#Pattern-Rules" accesskey="u" rel="up">Pattern Rules</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="Automatic-Variables-1"></a>
<h4 class="subsection">10.5.3 Automatic Variables</h4>
<a name="index-automatic-variables"></a>
<a name="index-variables_002c-automatic"></a>
<a name="index-variables_002c-and-implicit-rule"></a>
<p>Suppose you are writing a pattern rule to compile a ‘<samp>.c</samp>’ file into a
‘<samp>.o</samp>’ file: how do you write the ‘<samp>cc</samp>’ command so that it operates
on the right source file name? You cannot write the name in the recipe,
because the name is different each time the implicit rule is applied.
</p>
<p>What you do is use a special feature of <code>make</code>, the <em>automatic
variables</em>. These variables have values computed afresh for each rule that
is executed, based on the target and prerequisites of the rule. In this
example, you would use ‘<samp>$@</samp>’ for the object file name and ‘<samp>$<</samp>’
for the source file name.
</p>
<a name="index-automatic-variables-in-prerequisites"></a>
<a name="index-prerequisites_002c-and-automatic-variables"></a>
<p>It’s very important that you recognize the limited scope in which
automatic variable values are available: they only have values within
the recipe. In particular, you cannot use them anywhere
within the target list of a rule; they have no value there and will
expand to the empty string. Also, they cannot be accessed directly
within the prerequisite list of a rule. A common mistake is
attempting to use <code>$@</code> within the prerequisites list; this will
not work. However, there is a special feature of GNU <code>make</code>,
secondary expansion (see <a href="Makefiles.html#Secondary-Expansion">Secondary Expansion</a>), which will allow
automatic variable values to be used in prerequisite lists.
</p>
<p>Here is a table of automatic variables:
</p>
<dl compact="compact">
<dd><a name="index-_0024_0040"></a>
<a name="index-_0040-_0028automatic-variable_0029"></a>
</dd>
<dt><code>$@</code></dt>
<dd><p>The file name of the target of the rule. If the target is an archive
member, then ‘<samp>$@</samp>’ is the name of the archive file. In a pattern
rule that has multiple targets (see <a href="#Pattern-Intro">Introduction to
Pattern Rules</a>), ‘<samp>$@</samp>’ is the name of whichever target caused the
rule’s recipe to be run.
</p>
<a name="index-_0024_0025"></a>
<a name="index-_0025-_0028automatic-variable_0029"></a>
</dd>
<dt><code>$%</code></dt>
<dd><p>The target member name, when the target is an archive member.
See <a href="Archives.html#Archives">Archives</a>. For example, if the target is <samp>foo.a(bar.o)</samp> then
‘<samp>$%</samp>’ is <samp>bar.o</samp> and ‘<samp>$@</samp>’ is <samp>foo.a</samp>. ‘<samp>$%</samp>’ is
empty when the target is not an archive member.
</p>
<a name="index-_0024_003c"></a>
<a name="index-_003c-_0028automatic-variable_0029"></a>
</dd>
<dt><code>$<</code></dt>
<dd><p>The name of the first prerequisite. If the target got its recipe from
an implicit rule, this will be the first prerequisite added by the
implicit rule (see <a href="#Implicit-Rules">Implicit Rules</a>).
</p>
<a name="index-_0024_003f"></a>
<a name="index-_003f-_0028automatic-variable_0029"></a>
</dd>
<dt><code>$?</code></dt>
<dd><p>The names of all the prerequisites that are newer than the target, with
spaces between them. For prerequisites which are archive members, only
the named member is used (see <a href="Archives.html#Archives">Archives</a>).
<a name="index-prerequisites_002c-list-of-changed"></a>
<a name="index-list-of-changed-prerequisites"></a>
</p>
<a name="index-_0024_005e"></a>
<a name="index-_005e-_0028automatic-variable_0029"></a>
</dd>
<dt><code>$^</code></dt>
<dd><p>The names of all the prerequisites, with spaces between them. For
prerequisites which are archive members, only the named member is used
(see <a href="Archives.html#Archives">Archives</a>). A target has only one prerequisite on each other file
it depends on, no matter how many times each file is listed as a
prerequisite. So if you list a prerequisite more than once for a target,
the value of <code>$^</code> contains just one copy of the name. This list
does <strong>not</strong> contain any of the order-only prerequisites; for those
see the ‘<samp>$|</samp>’ variable, below.
<a name="index-prerequisites_002c-list-of-all"></a>
<a name="index-list-of-all-prerequisites"></a>
</p>
<a name="index-_0024_002b"></a>
<a name="index-_002b-_0028automatic-variable_0029"></a>
</dd>
<dt><code>$+</code></dt>
<dd><p>This is like ‘<samp>$^</samp>’, but prerequisites listed more than once are
duplicated in the order they were listed in the makefile. This is
primarily useful for use in linking commands where it is meaningful to
repeat library file names in a particular order.
</p>
<a name="index-_0024_007c"></a>
<a name="index-_007c-_0028automatic-variable_0029"></a>
</dd>
<dt><code>$|</code></dt>
<dd><p>The names of all the order-only prerequisites, with spaces between
them.
</p>
<a name="index-_0024_002a"></a>
<a name="index-_002a-_0028automatic-variable_0029"></a>
</dd>
<dt><code>$*</code></dt>
<dd><p>The stem with which an implicit rule matches (see <a href="#Pattern-Match">How
Patterns Match</a>). If the target is <samp>dir/a.foo.b</samp> and the target
pattern is <samp>a.%.b</samp> then the stem is <samp>dir/foo</samp>. The stem is
useful for constructing names of related files.
<a name="index-stem_002c-variable-for"></a>
</p>
<p>In a static pattern rule, the stem is part of the file name that matched
the ‘<samp>%</samp>’ in the target pattern.
</p>
<p>In an explicit rule, there is no stem; so ‘<samp>$*</samp>’ cannot be determined
in that way. Instead, if the target name ends with a recognized suffix
(see <a href="#Suffix-Rules">Old-Fashioned Suffix Rules</a>), ‘<samp>$*</samp>’ is set to
the target name minus the suffix. For example, if the target name is
‘<samp>foo.c</samp>’, then ‘<samp>$*</samp>’ is set to ‘<samp>foo</samp>’, since ‘<samp>.c</samp>’ is a
suffix. GNU <code>make</code> does this bizarre thing only for compatibility
with other implementations of <code>make</code>. You should generally avoid
using ‘<samp>$*</samp>’ except in implicit rules or static pattern rules.
</p>
<p>If the target name in an explicit rule does not end with a recognized
suffix, ‘<samp>$*</samp>’ is set to the empty string for that rule.
</p></dd>
</dl>
<p>‘<samp>$?</samp>’ is useful even in explicit rules when you wish to operate on only
the prerequisites that have changed. For example, suppose that an archive
named <samp>lib</samp> is supposed to contain copies of several object files.
This rule copies just the changed object files into the archive:
</p>
<div class="example">
<pre class="example">lib: foo.o bar.o lose.o win.o
ar r lib $?
</pre></div>
<p>Of the variables listed above, four have values that are single file
names, and three have values that are lists of file names. These seven
have variants that get just the file’s directory name or just the file
name within the directory. The variant variables’ names are formed by
appending ‘<samp>D</samp>’ or ‘<samp>F</samp>’, respectively. These variants are
semi-obsolete in GNU <code>make</code> since the functions <code>dir</code> and
<code>notdir</code> can be used to get a similar effect (see <a href="Functions.html#File-Name-Functions">Functions for File Names</a>). Note, however, that the
‘<samp>D</samp>’ variants all omit the trailing slash which always appears in
the output of the <code>dir</code> function. Here is a table of the variants:
</p>
<dl compact="compact">
<dd><a name="index-_0024_0028_0040D_0029"></a>
<a name="index-_0040D-_0028automatic-variable_0029"></a>
</dd>
<dt>‘<samp>$(@D)</samp>’</dt>
<dd><p>The directory part of the file name of the target, with the trailing
slash removed. If the value of ‘<samp>$@</samp>’ is <samp>dir/foo.o</samp> then
‘<samp>$(@D)</samp>’ is <samp>dir</samp>. This value is <samp>.</samp> if ‘<samp>$@</samp>’ does
not contain a slash.
</p>
<a name="index-_0024_0028_0040F_0029"></a>
<a name="index-_0040F-_0028automatic-variable_0029"></a>
</dd>
<dt>‘<samp>$(@F)</samp>’</dt>
<dd><p>The file-within-directory part of the file name of the target. If the
value of ‘<samp>$@</samp>’ is <samp>dir/foo.o</samp> then ‘<samp>$(@F)</samp>’ is
<samp>foo.o</samp>. ‘<samp>$(@F)</samp>’ is equivalent to ‘<samp>$(notdir $@)</samp>’.
</p>
<a name="index-_0024_0028_002aD_0029"></a>
<a name="index-_002aD-_0028automatic-variable_0029"></a>
</dd>
<dt>‘<samp>$(*D)</samp>’</dt>
<dd><a name="index-_0024_0028_002aF_0029"></a>
<a name="index-_002aF-_0028automatic-variable_0029"></a>
</dd>
<dt>‘<samp>$(*F)</samp>’</dt>
<dd><p>The directory part and the file-within-directory
part of the stem; <samp>dir</samp> and <samp>foo</samp> in this example.
</p>
<a name="index-_0024_0028_0025D_0029"></a>
<a name="index-_0025D-_0028automatic-variable_0029"></a>
</dd>
<dt>‘<samp>$(%D)</samp>’</dt>
<dd><a name="index-_0024_0028_0025F_0029"></a>
<a name="index-_0025F-_0028automatic-variable_0029"></a>
</dd>
<dt>‘<samp>$(%F)</samp>’</dt>
<dd><p>The directory part and the file-within-directory part of the target
archive member name. This makes sense only for archive member targets
of the form <samp><var>archive</var>(<var>member</var>)</samp> and is useful only when
<var>member</var> may contain a directory name. (See <a href="Archives.html#Archive-Members">Archive Members as Targets</a>.)
</p>
<a name="index-_0024_0028_003cD_0029"></a>
<a name="index-_003cD-_0028automatic-variable_0029"></a>
</dd>
<dt>‘<samp>$(<D)</samp>’</dt>
<dd><a name="index-_0024_0028_003cF_0029"></a>
<a name="index-_003cF-_0028automatic-variable_0029"></a>
</dd>
<dt>‘<samp>$(<F)</samp>’</dt>
<dd><p>The directory part and the file-within-directory
part of the first prerequisite.
</p>
<a name="index-_0024_0028_005eD_0029"></a>
<a name="index-_005eD-_0028automatic-variable_0029"></a>
</dd>
<dt>‘<samp>$(^D)</samp>’</dt>
<dd><a name="index-_0024_0028_005eF_0029"></a>
<a name="index-_005eF-_0028automatic-variable_0029"></a>
</dd>
<dt>‘<samp>$(^F)</samp>’</dt>
<dd><p>Lists of the directory parts and the file-within-directory
parts of all prerequisites.
</p>
<a name="index-_0024_0028_002bD_0029"></a>
<a name="index-_002bD-_0028automatic-variable_0029"></a>
</dd>
<dt>‘<samp>$(+D)</samp>’</dt>
<dd><a name="index-_0024_0028_002bF_0029"></a>
<a name="index-_002bF-_0028automatic-variable_0029"></a>
</dd>
<dt>‘<samp>$(+F)</samp>’</dt>
<dd><p>Lists of the directory parts and the file-within-directory
parts of all prerequisites, including multiple instances of duplicated
prerequisites.
</p>
<a name="index-_0024_0028_003fD_0029"></a>
<a name="index-_003fD-_0028automatic-variable_0029"></a>
</dd>
<dt>‘<samp>$(?D)</samp>’</dt>
<dd><a name="index-_0024_0028_003fF_0029"></a>
<a name="index-_003fF-_0028automatic-variable_0029"></a>
</dd>
<dt>‘<samp>$(?F)</samp>’</dt>
<dd><p>Lists of the directory parts and the file-within-directory parts of
all prerequisites that are newer than the target.
</p></dd>
</dl>
<p>Note that we use a special stylistic convention when we talk about these
automatic variables; we write “the value of ‘<samp>$<</samp>’”, rather than
“the variable <code><</code>”<!-- /@w --> as we would write for ordinary variables
such as <code>objects</code> and <code>CFLAGS</code>. We think this convention
looks more natural in this special case. Please do not assume it has a
deep significance; ‘<samp>$<</samp>’ refers to the variable named <code><</code> just
as ‘<samp>$(CFLAGS)</samp>’ refers to the variable named <code>CFLAGS</code>.
You could just as well use ‘<samp>$(<)</samp>’ in place of ‘<samp>$<</samp>’.
</p>
<hr>
<a name="Pattern-Match"></a>
<div class="header">
<p>
Next: <a href="#Match_002dAnything-Rules" accesskey="n" rel="next">Match-Anything Rules</a>, Previous: <a href="#Automatic-Variables" accesskey="p" rel="prev">Automatic Variables</a>, Up: <a href="#Pattern-Rules" accesskey="u" rel="up">Pattern Rules</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-Patterns-Match"></a>
<h4 class="subsection">10.5.4 How Patterns Match</h4>
<a name="index-stem-1"></a>
<p>A target pattern is composed of a ‘<samp>%</samp>’ between a prefix and a suffix,
either or both of which may be empty. The pattern matches a file name only
if the file name starts with the prefix and ends with the suffix, without
overlap. The text between the prefix and the suffix is called the
<em>stem</em>. Thus, when the pattern ‘<samp>%.o</samp>’ matches the file name
<samp>test.o</samp>, the stem is ‘<samp>test</samp>’. The pattern rule prerequisites are
turned into actual file names by substituting the stem for the character
‘<samp>%</samp>’. Thus, if in the same example one of the prerequisites is written
as ‘<samp>%.c</samp>’, it expands to ‘<samp>test.c</samp>’.
</p>
<p>When the target pattern does not contain a slash (and it usually does
not), directory names in the file names are removed from the file name
before it is compared with the target prefix and suffix. After the
comparison of the file name to the target pattern, the directory
names, along with the slash that ends them, are added on to the
prerequisite file names generated from the pattern rule’s prerequisite
patterns and the file name. The directories are ignored only for the
purpose of finding an implicit rule to use, not in the application of
that rule. Thus, ‘<samp>e%t</samp>’ matches the file name <samp>src/eat</samp>,
with ‘<samp>src/a</samp>’ as the stem. When prerequisites are turned into file
names, the directories from the stem are added at the front, while the
rest of the stem is substituted for the ‘<samp>%</samp>’. The stem
‘<samp>src/a</samp>’ with a prerequisite pattern ‘<samp>c%r</samp>’ gives the file name
<samp>src/car</samp>.
</p>
<a name="index-pattern-rules_002c-order-of"></a>
<a name="index-order-of-pattern-rules"></a>
<p>A pattern rule can be used to build a given file only if there is a
target pattern that matches the file name, <em>and</em> all
prerequisites in that rule either exist or can be built. The rules
you write take precedence over those that are built in. Note however,
that a rule whose prerequisites actually exist or are mentioned always
takes priority over a rule with prerequisites that must be made by
chaining other implicit rules.
</p>
<a name="index-stem_002c-shortest"></a>
<p>It is possible that more than one pattern rule will meet these
criteria. In that case, <code>make</code> will choose the rule with the
shortest stem (that is, the pattern that matches most specifically).
If more than one pattern rule has the shortest stem, <code>make</code> will
choose the first one found in the makefile.
</p>
<p>This algorithm results in more specific rules being preferred over
more generic ones; for example:
</p>
<div class="example">
<pre class="example">%.o: %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
%.o : %.f
$(COMPILE.F) $(OUTPUT_OPTION) $<
lib/%.o: lib/%.c
$(CC) -fPIC -c $(CFLAGS) $(CPPFLAGS) $< -o $@
</pre></div>
<p>Given these rules and asked to build <samp>bar.o</samp> where both
<samp>bar.c</samp> and <samp>bar.f</samp> exist, <code>make</code> will choose the first
rule and compile <samp>bar.c</samp> into <samp>bar.o</samp>. In the same
situation where <samp>bar.c</samp> does not exist, then <code>make</code> will
choose the second rule and compile <samp>bar.f</samp> into <samp>bar.o</samp>.
</p>
<p>If <code>make</code> is asked to build <samp>lib/bar.o</samp> and both
<samp>lib/bar.c</samp> and <samp>lib/bar.f</samp> exist, then the third rule will
be chosen since the stem for this rule (‘<samp>bar</samp>’) is shorter than
the stem for the first rule (‘<samp>lib/bar</samp>’). If <samp>lib/bar.c</samp>
does not exist then the third rule is not eligible and the second rule
will be used, even though the stem is longer.
</p>
<hr>
<a name="Match_002dAnything-Rules"></a>
<div class="header">
<p>
Next: <a href="#Canceling-Rules" accesskey="n" rel="next">Canceling Rules</a>, Previous: <a href="#Pattern-Match" accesskey="p" rel="prev">Pattern Match</a>, Up: <a href="#Pattern-Rules" accesskey="u" rel="up">Pattern Rules</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="Match_002dAnything-Pattern-Rules"></a>
<h4 class="subsection">10.5.5 Match-Anything Pattern Rules</h4>
<a name="index-match_002danything-rule"></a>
<a name="index-terminal-rule"></a>
<p>When a pattern rule’s target is just ‘<samp>%</samp>’, it matches any file name
whatever. We call these rules <em>match-anything</em> rules. They are very
useful, but it can take a lot of time for <code>make</code> to think about them,
because it must consider every such rule for each file name listed either
as a target or as a prerequisite.
</p>
<p>Suppose the makefile mentions <samp>foo.c</samp>. For this target, <code>make</code>
would have to consider making it by linking an object file <samp>foo.c.o</samp>,
or by C compilation-and-linking in one step from <samp>foo.c.c</samp>, or by
Pascal compilation-and-linking from <samp>foo.c.p</samp>, and many other
possibilities.
</p>
<p>We know these possibilities are ridiculous since <samp>foo.c</samp> is a C source
file, not an executable. If <code>make</code> did consider these possibilities,
it would ultimately reject them, because files such as <samp>foo.c.o</samp> and
<samp>foo.c.p</samp> would not exist. But these possibilities are so
numerous that <code>make</code> would run very slowly if it had to consider
them.
</p>
<p>To gain speed, we have put various constraints on the way <code>make</code>
considers match-anything rules. There are two different constraints that
can be applied, and each time you define a match-anything rule you must
choose one or the other for that rule.
</p>
<p>One choice is to mark the match-anything rule as <em>terminal</em> by defining
it with a double colon. When a rule is terminal, it does not apply unless
its prerequisites actually exist. Prerequisites that could be made with
other implicit rules are not good enough. In other words, no further
chaining is allowed beyond a terminal rule.
</p>
<p>For example, the built-in implicit rules for extracting sources from RCS
and SCCS files are terminal; as a result, if the file <samp>foo.c,v</samp> does
not exist, <code>make</code> will not even consider trying to make it as an
intermediate file from <samp>foo.c,v.o</samp> or from <samp>RCS/SCCS/s.foo.c,v</samp>.
RCS and SCCS files are generally ultimate source files, which should not be
remade from any other files; therefore, <code>make</code> can save time by not
looking for ways to remake them.
</p>
<p>If you do not mark the match-anything rule as terminal, then it is
non-terminal. A non-terminal match-anything rule cannot apply to a file name
that indicates a specific type of data. A file name indicates a specific
type of data if some non-match-anything implicit rule target matches it.
</p>
<p>For example, the file name <samp>foo.c</samp> matches the target for the pattern
rule ‘<samp>%.c : %.y</samp>’ (the rule to run Yacc). Regardless of whether this
rule is actually applicable (which happens only if there is a file
<samp>foo.y</samp>), the fact that its target matches is enough to prevent
consideration of any non-terminal match-anything rules for the file
<samp>foo.c</samp>. Thus, <code>make</code> will not even consider trying to make
<samp>foo.c</samp> as an executable file from <samp>foo.c.o</samp>, <samp>foo.c.c</samp>,
<samp>foo.c.p</samp>, etc.
</p>
<p>The motivation for this constraint is that non-terminal match-anything
rules are used for making files containing specific types of data (such as
executable files) and a file name with a recognized suffix indicates some
other specific type of data (such as a C source file).
</p>
<p>Special built-in dummy pattern rules are provided solely to recognize
certain file names so that non-terminal match-anything rules will not be
considered. These dummy rules have no prerequisites and no recipes, and
they are ignored for all other purposes. For example, the built-in
implicit rule
</p>
<div class="example">
<pre class="example">%.p :
</pre></div>
<p>exists to make sure that Pascal source files such as <samp>foo.p</samp> match a
specific target pattern and thereby prevent time from being wasted looking
for <samp>foo.p.o</samp> or <samp>foo.p.c</samp>.
</p>
<p>Dummy pattern rules such as the one for ‘<samp>%.p</samp>’ are made for every
suffix listed as valid for use in suffix rules (see <a href="#Suffix-Rules">Old-Fashioned Suffix Rules</a>).
</p>
<hr>
<a name="Canceling-Rules"></a>
<div class="header">
<p>
Previous: <a href="#Match_002dAnything-Rules" accesskey="p" rel="prev">Match-Anything Rules</a>, Up: <a href="#Pattern-Rules" accesskey="u" rel="up">Pattern Rules</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="Canceling-Implicit-Rules"></a>
<h4 class="subsection">10.5.6 Canceling Implicit Rules</h4>
<p>You can override a built-in implicit rule (or one you have defined
yourself) by defining a new pattern rule with the same target and
prerequisites, but a different recipe. When the new rule is defined, the
built-in one is replaced. The new rule’s position in the sequence of
implicit rules is determined by where you write the new rule.
</p>
<p>You can cancel a built-in implicit rule by defining a pattern rule with the
same target and prerequisites, but no recipe. For example, the following
would cancel the rule that runs the assembler:
</p>
<div class="example">
<pre class="example">%.o : %.s
</pre></div>
<hr>
<a name="Last-Resort"></a>
<div class="header">
<p>
Next: <a href="#Suffix-Rules" accesskey="n" rel="next">Suffix Rules</a>, Previous: <a href="#Pattern-Rules" accesskey="p" rel="prev">Pattern Rules</a>, Up: <a href="#Implicit-Rules" accesskey="u" rel="up">Implicit Rules</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="Defining-Last_002dResort-Default-Rules"></a>
<h3 class="section">10.6 Defining Last-Resort Default Rules</h3>
<a name="index-last_002dresort-default-rules"></a>
<a name="index-default-rules_002c-last_002dresort"></a>
<p>You can define a last-resort implicit rule by writing a terminal
match-anything pattern rule with no prerequisites (see <a href="#Match_002dAnything-Rules">Match-Anything Rules</a>). This is just like any other pattern rule; the only thing
special about it is that it will match any target. So such a rule’s
recipe is used for all targets and prerequisites that have no recipe
of their own and for which no other implicit rule applies.
</p>
<p>For example, when testing a makefile, you might not care if the source
files contain real data, only that they exist. Then you might do this:
</p>
<div class="example">
<pre class="example">%::
touch $@
</pre></div>
<p>to cause all the source files needed (as prerequisites) to be created
automatically.
</p>
<a name="index-_002eDEFAULT-1"></a>
<p>You can instead define a recipe to be used for targets for which there
are no rules at all, even ones which don’t specify recipes. You do
this by writing a rule for the target <code>.DEFAULT</code>. Such a rule’s
recipe is used for all prerequisites which do not appear as targets in
any explicit rule, and for which no implicit rule applies. Naturally,
there is no <code>.DEFAULT</code> rule unless you write one.
</p>
<p>If you use <code>.DEFAULT</code> with no recipe or prerequisites:
</p>
<div class="example">
<pre class="example">.DEFAULT:
</pre></div>
<p>the recipe previously stored for <code>.DEFAULT</code> is cleared. Then
<code>make</code> acts as if you had never defined <code>.DEFAULT</code> at all.
</p>
<p>If you do not want a target to get the recipe from a match-anything
pattern rule or <code>.DEFAULT</code>, but you also do not want any recipe
to be run for the target, you can give it an empty recipe
(see <a href="Recipes.html#Empty-Recipes">Defining Empty Recipes</a>).
</p>
<p>You can use a last-resort rule to override part of another makefile.
See <a href="Makefiles.html#Overriding-Makefiles">Overriding Part of Another Makefile</a>.
</p>
<hr>
<a name="Suffix-Rules"></a>
<div class="header">
<p>
Next: <a href="#Implicit-Rule-Search" accesskey="n" rel="next">Implicit Rule Search</a>, Previous: <a href="#Last-Resort" accesskey="p" rel="prev">Last Resort</a>, Up: <a href="#Implicit-Rules" accesskey="u" rel="up">Implicit Rules</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="Old_002dFashioned-Suffix-Rules"></a>
<h3 class="section">10.7 Old-Fashioned Suffix Rules</h3>
<a name="index-old_002dfashioned-suffix-rules"></a>
<a name="index-suffix-rule"></a>
<p><em>Suffix rules</em> are the old-fashioned way of defining implicit rules for
<code>make</code>. Suffix rules are obsolete because pattern rules are more
general and clearer. They are supported in GNU <code>make</code> for
compatibility with old makefiles. They come in two kinds:
<em>double-suffix</em> and <em>single-suffix</em>.
</p>
<p>A double-suffix rule is defined by a pair of suffixes: the target suffix
and the source suffix. It matches any file whose name ends with the
target suffix. The corresponding implicit prerequisite is made by
replacing the target suffix with the source suffix in the file name. A
two-suffix rule whose target and source suffixes are ‘<samp>.o</samp>’ and
‘<samp>.c</samp>’ is equivalent to the pattern rule ‘<samp>%.o : %.c</samp>’.
</p>
<p>A single-suffix rule is defined by a single suffix, which is the source
suffix. It matches any file name, and the corresponding implicit
prerequisite name is made by appending the source suffix. A single-suffix
rule whose source suffix is ‘<samp>.c</samp>’ is equivalent to the pattern rule
‘<samp>% : %.c</samp>’.
</p>
<p>Suffix rule definitions are recognized by comparing each rule’s target
against a defined list of known suffixes. When <code>make</code> sees a rule
whose target is a known suffix, this rule is considered a single-suffix
rule. When <code>make</code> sees a rule whose target is two known suffixes
concatenated, this rule is taken as a double-suffix rule.
</p>
<p>For example, ‘<samp>.c</samp>’ and ‘<samp>.o</samp>’ are both on the default list of
known suffixes. Therefore, if you define a rule whose target is
‘<samp>.c.o</samp>’, <code>make</code> takes it to be a double-suffix rule with source
suffix ‘<samp>.c</samp>’ and target suffix ‘<samp>.o</samp>’. Here is the old-fashioned
way to define the rule for compiling a C source file:
</p>
<div class="example">
<pre class="example">.c.o:
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
</pre></div>
<p>Suffix rules cannot have any prerequisites of their own. If they have any,
they are treated as normal files with funny names, not as suffix rules.
Thus, the rule:
</p>
<div class="example">
<pre class="example">.c.o: foo.h
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
</pre></div>
<p>tells how to make the file <samp>.c.o</samp> from the prerequisite file
<samp>foo.h</samp>, and is not at all like the pattern rule:
</p>
<div class="example">
<pre class="example">%.o: %.c foo.h
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
</pre></div>
<p>which tells how to make ‘<samp>.o</samp>’ files from ‘<samp>.c</samp>’ files, and makes all
‘<samp>.o</samp>’ files using this pattern rule also depend on <samp>foo.h</samp>.
</p>
<p>Suffix rules with no recipe are also meaningless. They do not remove
previous rules as do pattern rules with no recipe (see <a href="#Canceling-Rules">Canceling Implicit Rules</a>). They simply enter the suffix or
pair of suffixes concatenated as a target in the data base.
</p>
<a name="index-_002eSUFFIXES-1"></a>
<p>The known suffixes are simply the names of the prerequisites of the special
target <code>.SUFFIXES</code>. You can add your own suffixes by writing a rule
for <code>.SUFFIXES</code> that adds more prerequisites, as in:
</p>
<div class="example">
<pre class="example">.SUFFIXES: .hack .win
</pre></div>
<p>which adds ‘<samp>.hack</samp>’ and ‘<samp>.win</samp>’ to the end of the list of suffixes.
</p>
<p>If you wish to eliminate the default known suffixes instead of just adding
to them, write a rule for <code>.SUFFIXES</code> with no prerequisites. By
special dispensation, this eliminates all existing prerequisites of
<code>.SUFFIXES</code>. You can then write another rule to add the suffixes you
want. For example,
</p>
<div class="example">
<pre class="example">.SUFFIXES: # <span class="roman">Delete the default suffixes</span>
.SUFFIXES: .c .o .h # <span class="roman">Define our suffix list</span>
</pre></div>
<p>The ‘<samp>-r</samp>’ or ‘<samp>--no-builtin-rules</samp>’ flag causes the default
list of suffixes to be empty.
</p>
<a name="index-SUFFIXES"></a>
<p>The variable <code>SUFFIXES</code> is defined to the default list of suffixes
before <code>make</code> reads any makefiles. You can change the list of suffixes
with a rule for the special target <code>.SUFFIXES</code>, but that does not alter
this variable.
</p>
<hr>
<a name="Implicit-Rule-Search"></a>
<div class="header">
<p>
Previous: <a href="#Suffix-Rules" accesskey="p" rel="prev">Suffix Rules</a>, Up: <a href="#Implicit-Rules" accesskey="u" rel="up">Implicit Rules</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="Implicit-Rule-Search-Algorithm"></a>
<h3 class="section">10.8 Implicit Rule Search Algorithm</h3>
<a name="index-implicit-rule_002c-search-algorithm"></a>
<a name="index-search-algorithm_002c-implicit-rule"></a>
<p>Here is the procedure <code>make</code> uses for searching for an implicit rule
for a target <var>t</var>. This procedure is followed for each double-colon
rule with no recipe, for each target of ordinary rules none of which have
a recipe, and for each prerequisite that is not the target of any rule. It
is also followed recursively for prerequisites that come from implicit
rules, in the search for a chain of rules.
</p>
<p>Suffix rules are not mentioned in this algorithm because suffix rules are
converted to equivalent pattern rules once the makefiles have been read in.
</p>
<p>For an archive member target of the form
‘<samp><var>archive</var>(<var>member</var>)</samp>’, the following algorithm is run
twice, first using the entire target name <var>t</var>, and second using
‘<samp>(<var>member</var>)</samp>’ as the target <var>t</var> if the first run found no
rule.
</p>
<ol>
<li> Split <var>t</var> into a directory part, called <var>d</var>, and the rest,
called <var>n</var>. For example, if <var>t</var> is ‘<samp>src/foo.o</samp>’, then
<var>d</var> is ‘<samp>src/</samp>’ and <var>n</var> is ‘<samp>foo.o</samp>’.
</li><li> Make a list of all the pattern rules one of whose targets matches
<var>t</var> or <var>n</var>. If the target pattern contains a slash, it is
matched against <var>t</var>; otherwise, against <var>n</var>.
</li><li> If any rule in that list is <em>not</em> a match-anything rule, then
remove all non-terminal match-anything rules from the list.
</li><li> Remove from the list all rules with no recipe.
</li><li> For each pattern rule in the list:
<ol>
<li> Find the stem <var>s</var>, which is the nonempty part of <var>t</var> or <var>n</var>
matched by the ‘<samp>%</samp>’ in the target pattern.
</li><li> Compute the prerequisite names by substituting <var>s</var> for ‘<samp>%</samp>’; if
the target pattern does not contain a slash, append <var>d</var> to
the front of each prerequisite name.
</li><li> Test whether all the prerequisites exist or ought to exist. (If a
file name is mentioned in the makefile as a target or as an explicit
prerequisite, then we say it ought to exist.)
<p>If all prerequisites exist or ought to exist, or there are no prerequisites,
then this rule applies.
</p></li></ol>
</li><li> If no pattern rule has been found so far, try harder.
For each pattern rule in the list:
<ol>
<li> If the rule is terminal, ignore it and go on to the next rule.
</li><li> Compute the prerequisite names as before.
</li><li> Test whether all the prerequisites exist or ought to exist.
</li><li> For each prerequisite that does not exist, follow this algorithm
recursively to see if the prerequisite can be made by an implicit
rule.
</li><li> If all prerequisites exist, ought to exist, or can be
made by implicit rules, then this rule applies.
</li></ol>
</li><li> If no implicit rule applies, the rule for <code>.DEFAULT</code>, if any,
applies. In that case, give <var>t</var> the same recipe that
<code>.DEFAULT</code> has. Otherwise, there is no recipe for <var>t</var>.
</li></ol>
<p>Once a rule that applies has been found, for each target pattern of
the rule other than the one that matched <var>t</var> or <var>n</var>, the
‘<samp>%</samp>’ in the pattern is replaced with <var>s</var> and the resultant
file name is stored until the recipe to remake the target file <var>t</var>
is executed. After the recipe is executed, each of these stored file
names are entered into the data base and marked as having been updated
and having the same update status as the file <var>t</var>.
</p>
<p>When the recipe of a pattern rule is executed for <var>t</var>, the
automatic variables are set corresponding to the target and
prerequisites. See <a href="#Automatic-Variables">Automatic Variables</a>.
</p>
<hr>
<div class="header">
<p>
Previous: <a href="#Suffix-Rules" accesskey="p" rel="prev">Suffix Rules</a>, Up: <a href="#Implicit-Rules" accesskey="u" rel="up">Implicit Rules</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>
|