home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / MAKE-INF.ZIP / make.INF (.txt)
OS/2 Help File  |  1993-05-04  |  202KB  |  6,589 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. Title page ΓòÉΓòÉΓòÉ
  3.  
  4.                                     GNU Make
  5.  
  6.                       A Program for Directing Recompilation
  7.  
  8.                     Edition 0.41, for make Version 3.64 Beta.
  9.  
  10.                                    April 1993
  11.  
  12.                     by Richard M. Stallman and Roland McGrath
  13.  
  14. Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software Foundation, Inc. 
  15.  
  16. Published by the Free Software Foundation 
  17. 675 Massachusetts Avenue, 
  18. Cambridge, MA 02139 USA 
  19. Printed copies are available for $20 each. 
  20.  
  21. Permission is granted to make and distribute verbatim copies of this manual 
  22. provided the copyright notice and this permission notice are preserved on all 
  23. copies. 
  24.  
  25. Permission is granted to copy and distribute modified versions of this manual 
  26. under the conditions for verbatim copying, provided also that the section 
  27. entitled ``GNU General Public License'' is included exactly as in the original, 
  28. and provided that the entire resulting derived work is distributed under the 
  29. terms of a permission notice identical to this one. 
  30.  
  31. Permission is granted to copy and distribute translations of this manual into 
  32. another language, under the above conditions for modified versions, except that 
  33. the text of the translation of the section entitled ``GNU General Public 
  34. License'' must be approved for accuracy by the Foundation. 
  35.  
  36. Cover art by Etienne Suvasa. 
  37.  
  38.  
  39. ΓòÉΓòÉΓòÉ 2. Top node: "Make" ΓòÉΓòÉΓòÉ
  40.  
  41. The GNU make utility automatically determines which pieces of a large program 
  42. need to be recompiled, and issues the commands to recompile them. 
  43.  
  44. This is Edition 0.41 of the GNU Make Manual, last updated 16 April 1993 for 
  45. make Version 3.64 Beta. 
  46.  
  47. This manual describes make and contains the following chapters: 
  48.  
  49.  
  50. ΓòÉΓòÉΓòÉ 3. GNU GENERAL PUBLIC LICENSE ΓòÉΓòÉΓòÉ
  51.  
  52.                               Version 2, June 1991
  53.  
  54. Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  55. 675 Mass Ave, Cambridge, MA 02139, USA
  56.  
  57. Everyone is permitted to copy and distribute verbatim copies
  58. of this license document, but changing it is not allowed.
  59.  
  60.  
  61. ΓòÉΓòÉΓòÉ 3.1. Preamble ΓòÉΓòÉΓòÉ
  62.  
  63.  The licenses for most software are designed to take away your freedom to share 
  64. and change it.  By contrast, the GNU General Public License is intended to 
  65. guarantee your freedom to share and change free software---to make sure the 
  66. software is free for all its users.  This General Public License applies to 
  67. most of the Free Software Foundation's software and to any other program whose 
  68. authors commit to using it.  (Some other Free Software Foundation software is 
  69. covered by the GNU Library General Public License instead.)  You can apply it 
  70. to your programs, too. 
  71.  
  72.  When we speak of free software, we are referring to freedom, not price.  Our 
  73. General Public Licenses are designed to make sure that you have the freedom to 
  74. distribute copies of free software (and charge for this service if you wish), 
  75. that you receive source code or can get it if you want it, that you can change 
  76. the software or use pieces of it in new free programs; and that you know you 
  77. can do these things. 
  78.  
  79.  To protect your rights, we need to make restrictions that forbid anyone to 
  80. deny you these rights or to ask you to surrender the rights. These restrictions 
  81. translate to certain responsibilities for you if you distribute copies of the 
  82. software, or if you modify it. 
  83.  
  84.  For example, if you distribute copies of such a program, whether gratis or for 
  85. a fee, you must give the recipients all the rights that you have.  You must 
  86. make sure that they, too, receive or can get the source code.  And you must 
  87. show them these terms so they know their rights. 
  88.  
  89.  We protect your rights with two steps: (1) copyright the software, and (2) 
  90. offer you this license which gives you legal permission to copy, distribute 
  91. and/or modify the software. 
  92.  
  93.  Also, for each author's protection and ours, we want to make certain that 
  94. everyone understands that there is no warranty for this free software.  If the 
  95. software is modified by someone else and passed on, we want its recipients to 
  96. know that what they have is not the original, so that any problems introduced 
  97. by others will not reflect on the original authors' reputations. 
  98.  
  99.  Finally, any free program is threatened constantly by software patents.  We 
  100. wish to avoid the danger that redistributors of a free program will 
  101. individually obtain patent licenses, in effect making the program proprietary. 
  102. To prevent this, we have made it clear that any patent must be licensed for 
  103. everyone's free use or not licensed at all. 
  104.  
  105.  The precise terms and conditions for copying, distribution and modification 
  106. follow. 
  107.  
  108.          TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  109.  
  110.  1. This License applies to any program or other work which contains a notice 
  111.     placed by the copyright holder saying it may be distributed under the terms 
  112.     of this General Public License.  The ``Program'', below, refers to any such 
  113.     program or work, and a ``work based on the Program'' means either the 
  114.     Program or any derivative work under copyright law: that is to say, a work 
  115.     containing the Program or a portion of it, either verbatim or with 
  116.     modifications and/or translated into another language.  (Hereinafter, 
  117.     translation is included without limitation in the term ``modification''.) 
  118.     Each licensee is addressed as ``you''. 
  119.  
  120.     Activities other than copying, distribution and modification are not 
  121.     covered by this License; they are outside its scope.  The act of running 
  122.     the Program is not restricted, and the output from the Program is covered 
  123.     only if its contents constitute a work based on the Program (independent of 
  124.     having been made by running the Program). Whether that is true depends on 
  125.     what the Program does. 
  126.  
  127.  2. You may copy and distribute verbatim copies of the Program's source code as 
  128.     you receive it, in any medium, provided that you conspicuously and 
  129.     appropriately publish on each copy an appropriate copyright notice and 
  130.     disclaimer of warranty; keep intact all the notices that refer to this 
  131.     License and to the absence of any warranty; and give any other recipients 
  132.     of the Program a copy of this License along with the Program. 
  133.  
  134.     You may charge a fee for the physical act of transferring a copy, and you 
  135.     may at your option offer warranty protection in exchange for a fee. 
  136.  
  137.  3. You may modify your copy or copies of the Program or any portion of it, 
  138.     thus forming a work based on the Program, and copy and distribute such 
  139.     modifications or work under the terms of Section 1 above, provided that you 
  140.     also meet all of these conditions: 
  141.  
  142.     a. You must cause the modified files to carry prominent notices stating 
  143.        that you changed the files and the date of any change. 
  144.  
  145.     b. You must cause any work that you distribute or publish, that in whole or 
  146.        in part contains or is derived from the Program or any part thereof, to 
  147.        be licensed as a whole at no charge to all third parties under the terms 
  148.        of this License. 
  149.  
  150.     c. If the modified program normally reads commands interactively when run, 
  151.        you must cause it, when started running for such interactive use in the 
  152.        most ordinary way, to print or display an announcement including an 
  153.        appropriate copyright notice and a notice that there is no warranty (or 
  154.        else, saying that you provide a warranty) and that users may 
  155.        redistribute the program under these conditions, and telling the user 
  156.        how to view a copy of this License.  (Exception: if the Program itself 
  157.        is interactive but does not normally print such an announcement, your 
  158.        work based on the Program is not required to print an announcement.) 
  159.  
  160.     These requirements apply to the modified work as a whole.  If identifiable 
  161.     sections of that work are not derived from the Program, and can be 
  162.     reasonably considered independent and separate works in themselves, then 
  163.     this License, and its terms, do not apply to those sections when you 
  164.     distribute them as separate works.  But when you distribute the same 
  165.     sections as part of a whole which is a work based on the Program, the 
  166.     distribution of the whole must be on the terms of this License, whose 
  167.     permissions for other licensees extend to the entire whole, and thus to 
  168.     each and every part regardless of who wrote it. 
  169.  
  170.     Thus, it is not the intent of this section to claim rights or contest your 
  171.     rights to work written entirely by you; rather, the intent is to exercise 
  172.     the right to control the distribution of derivative or collective works 
  173.     based on the Program. 
  174.  
  175.     In addition, mere aggregation of another work not based on the Program with 
  176.     the Program (or with a work based on the Program) on a volume of a storage 
  177.     or distribution medium does not bring the other work under the scope of 
  178.     this License. 
  179.  
  180.  4. You may copy and distribute the Program (or a work based on it, under 
  181.     Section 2) in object code or executable form under the terms of Sections 1 
  182.     and 2 above provided that you also do one of the following: 
  183.  
  184.     a. Accompany it with the complete corresponding machine-readable source 
  185.        code, which must be distributed under the terms of Sections 1 and 2 
  186.        above on a medium customarily used for software interchange; or, 
  187.  
  188.     b. Accompany it with a written offer, valid for at least three years, to 
  189.        give any third party, for a charge no more than your cost of physically 
  190.        performing source distribution, a complete machine-readable copy of the 
  191.        corresponding source code, to be distributed under the terms of Sections 
  192.        1 and 2 above on a medium customarily used for software interchange; or, 
  193.  
  194.     c. Accompany it with the information you received as to the offer to 
  195.        distribute corresponding source code.  (This alternative is allowed only 
  196.        for noncommercial distribution and only if you received the program in 
  197.        object code or executable form with such an offer, in accord with 
  198.        Subsection b above.) 
  199.  
  200.     The source code for a work means the preferred form of the work for making 
  201.     modifications to it.  For an executable work, complete source code means 
  202.     all the source code for all modules it contains, plus any associated 
  203.     interface definition files, plus the scripts used to control compilation 
  204.     and installation of the executable.  However, as a special exception, the 
  205.     source code distributed need not include anything that is normally 
  206.     distributed (in either source or binary form) with the major components 
  207.     (compiler, kernel, and so on) of the operating system on which the 
  208.     executable runs, unless that component itself accompanies the executable. 
  209.  
  210.     If distribution of executable or object code is made by offering access to 
  211.     copy from a designated place, then offering equivalent access to copy the 
  212.     source code from the same place counts as distribution of the source code, 
  213.     even though third parties are not compelled to copy the source along with 
  214.     the object code. 
  215.  
  216.  5. You may not copy, modify, sublicense, or distribute the Program except as 
  217.     expressly provided under this License.  Any attempt otherwise to copy, 
  218.     modify, sublicense or distribute the Program is void, and will 
  219.     automatically terminate your rights under this License. However, parties 
  220.     who have received copies, or rights, from you under this License will not 
  221.     have their licenses terminated so long as such parties remain in full 
  222.     compliance. 
  223.  
  224.  6. You are not required to accept this License, since you have not signed it. 
  225.     However, nothing else grants you permission to modify or distribute the 
  226.     Program or its derivative works.  These actions are prohibited by law if 
  227.     you do not accept this License.  Therefore, by modifying or distributing 
  228.     the Program (or any work based on the Program), you indicate your 
  229.     acceptance of this License to do so, and all its terms and conditions for 
  230.     copying, distributing or modifying the Program or works based on it. 
  231.  
  232.  7. Each time you redistribute the Program (or any work based on the Program), 
  233.     the recipient automatically receives a license from the original licensor 
  234.     to copy, distribute or modify the Program subject to these terms and 
  235.     conditions.  You may not impose any further restrictions on the recipients' 
  236.     exercise of the rights granted herein. You are not responsible for 
  237.     enforcing compliance by third parties to this License. 
  238.  
  239.  8. If, as a consequence of a court judgment or allegation of patent 
  240.     infringement or for any other reason (not limited to patent issues), 
  241.     conditions are imposed on you (whether by court order, agreement or 
  242.     otherwise) that contradict the conditions of this License, they do not 
  243.     excuse you from the conditions of this License.  If you cannot distribute 
  244.     so as to satisfy simultaneously your obligations under this License and any 
  245.     other pertinent obligations, then as a consequence you may not distribute 
  246.     the Program at all.  For example, if a patent license would not permit 
  247.     royalty-free redistribution of the Program by all those who receive copies 
  248.     directly or indirectly through you, then the only way you could satisfy 
  249.     both it and this License would be to refrain entirely from distribution of 
  250.     the Program. 
  251.  
  252.     If any portion of this section is held invalid or unenforceable under any 
  253.     particular circumstance, the balance of the section is intended to apply 
  254.     and the section as a whole is intended to apply in other circumstances. 
  255.  
  256.     It is not the purpose of this section to induce you to infringe any patents 
  257.     or other property right claims or to contest validity of any such claims; 
  258.     this section has the sole purpose of protecting the integrity of the free 
  259.     software distribution system, which is implemented by public license 
  260.     practices.  Many people have made generous contributions to the wide range 
  261.     of software distributed through that system in reliance on consistent 
  262.     application of that system; it is up to the author/donor to decide if he or 
  263.     she is willing to distribute software through any other system and a 
  264.     licensee cannot impose that choice. 
  265.  
  266.     This section is intended to make thoroughly clear what is believed to be a 
  267.     consequence of the rest of this License. 
  268.  
  269.  9. If the distribution and/or use of the Program is restricted in certain 
  270.     countries either by patents or by copyrighted interfaces, the original 
  271.     copyright holder who places the Program under this License may add an 
  272.     explicit geographical distribution limitation excluding those countries, so 
  273.     that distribution is permitted only in or among countries not thus 
  274.     excluded.  In such case, this License incorporates the limitation as if 
  275.     written in the body of this License. 
  276.  
  277. 10. The Free Software Foundation may publish revised and/or new versions of the 
  278.     General Public License from time to time.  Such new versions will be 
  279.     similar in spirit to the present version, but may differ in detail to 
  280.     address new problems or concerns. 
  281.  
  282.     Each version is given a distinguishing version number.  If the Program 
  283.     specifies a version number of this License which applies to it and ``any 
  284.     later version'', you have the option of following the terms and conditions 
  285.     either of that version or of any later version published by the Free 
  286.     Software Foundation.  If the Program does not specify a version number of 
  287.     this License, you may choose any version ever published by the Free 
  288.     Software Foundation. 
  289.  
  290. 11. If you wish to incorporate parts of the Program into other free programs 
  291.     whose distribution conditions are different, write to the author to ask for 
  292.     permission.  For software which is copyrighted by the Free Software 
  293.     Foundation, write to the Free Software Foundation; we sometimes make 
  294.     exceptions for this.  Our decision will be guided by the two goals of 
  295.     preserving the free status of all derivatives of our free software and of 
  296.     promoting the sharing and reuse of software generally. 
  297.  
  298.                                      NO WARRANTY
  299.  
  300. 12. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR 
  301.     THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN 
  302.     OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 
  303.     PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER 
  304.     EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
  305.     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK 
  306.     AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE 
  307.     PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 
  308.     REPAIR OR CORRECTION. 
  309.  
  310. 13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL 
  311.     ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE 
  312.     THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 
  313.     GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 
  314.     USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 
  315.     DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 
  316.     PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 
  317.     EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 
  318.     SUCH DAMAGES. 
  319.  
  320.                            END OF TERMS AND CONDITIONS
  321.  
  322.  
  323. ΓòÉΓòÉΓòÉ 3.2. How to Apply These Terms to Your New Programs ΓòÉΓòÉΓòÉ
  324.  
  325.  If you develop a new program, and you want it to be of the greatest possible 
  326. use to the public, the best way to achieve this is to make it free software 
  327. which everyone can redistribute and change under these terms. 
  328.  
  329.  To do so, attach the following notices to the program.  It is safest to attach 
  330. them to the start of each source file to most effectively convey the exclusion 
  331. of warranty; and each file should have at least the ``copyright'' line and a 
  332. pointer to where the full notice is found. 
  333.  
  334. one line to give the program's name and an idea of what it does.
  335. Copyright (C) 19yy  name of author
  336.  
  337. This program is free software; you can redistribute it and/or
  338. modify it under the terms of the GNU General Public License
  339. as published by the Free Software Foundation; either version 2
  340. of the License, or (at your option) any later version.
  341.  
  342. This program is distributed in the hope that it will be useful,
  343. but WITHOUT ANY WARRANTY; without even the implied warranty of
  344. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  345. GNU General Public License for more details.
  346.  
  347. You should have received a copy of the GNU General Public License
  348. along with this program; if not, write to the Free Software
  349. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  350.  
  351. Also add information on how to contact you by electronic and paper mail. 
  352.  
  353. If the program is interactive, make it output a short notice like this when it 
  354. starts in an interactive mode: 
  355.  
  356. Gnomovision version 69, Copyright (C) 19yy name of author
  357. Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
  358. type `show w'.  This is free software, and you are welcome
  359. to redistribute it under certain conditions; type `show c'
  360. for details.
  361.  
  362. The hypothetical commands `show w' and `show c' should show the appropriate 
  363. parts of the General Public License.  Of course, the commands you use may be 
  364. called something other than `show w' and `show c'; they could even be 
  365. mouse-clicks or menu items---whatever suits your program. 
  366.  
  367. You should also get your employer (if you work as a programmer) or your school, 
  368. if any, to sign a ``copyright disclaimer'' for the program, if necessary.  Here 
  369. is a sample; alter the names: 
  370.  
  371. Yoyodyne, Inc., hereby disclaims all copyright
  372. interest in the program `Gnomovision'
  373. (which makes passes at compilers) written
  374. by James Hacker.
  375.  
  376. signature of Ty Coon, 1 April 1989
  377. Ty Coon, President of Vice
  378.  
  379. This General Public License does not permit incorporating your program into 
  380. proprietary programs.  If your program is a subroutine library, you may 
  381. consider it more useful to permit linking proprietary applications with the 
  382. library.  If this is what you want to do, use the GNU Library General Public 
  383. License instead of this License. 
  384.  
  385.  
  386. ΓòÉΓòÉΓòÉ 4. Overview of make ΓòÉΓòÉΓòÉ
  387.  
  388. The make utility automatically determines which pieces of a large program need 
  389. to be recompiled, and issues commands to recompile them. This manual describes 
  390. GNU make, which was implemented by Richard Stallman and Roland McGrath.  GNU 
  391. make conforms to section 6.2 of IEEE Standard 1003.2-1992 (POSIX.2). 
  392.  
  393. Our examples show C programs, since they are most common, but you can use make 
  394. with any programming language whose compiler can be run with a shell command. 
  395. Indeed, make is not limited to programs.  You can use it to describe any task 
  396. where some files must be updated automatically from others whenever the others 
  397. change. 
  398.  
  399.  
  400. ΓòÉΓòÉΓòÉ 4.1. Preparing and Running Make ΓòÉΓòÉΓòÉ
  401.  
  402. To prepare to use make, you must write a file called the makefile that 
  403. describes the relationships among files in your program and provides commands 
  404. for updating each file. In a program, typically, the executable file is updated 
  405. from object files, which are in turn made by compiling source files. 
  406.  
  407. Once a suitable makefile exists, each time you change some source files, this 
  408. simple shell command: 
  409.  
  410. make
  411.  
  412. suffices to perform all necessary recompilations.  The make program uses the 
  413. makefile data base and the last-modification times of the files to decide which 
  414. of the files need to be updated.  For each of those files, it issues the 
  415. commands recorded in the data base. 
  416.  
  417. You can provide command line arguments to make to control which files should be 
  418. recompiled, or how. See How to Run make. 
  419.  
  420.  
  421. ΓòÉΓòÉΓòÉ 4.2. How to Read This Manual ΓòÉΓòÉΓòÉ
  422.  
  423. If you are new to make, or are looking for a general introduction, read the 
  424. first few sections of each chapter, skipping the later sections.  In each 
  425. chapter, the first few sections contain introductory or general information and 
  426. the later sections contain specialized or technical information. The exception 
  427. is the second chapter, An Introduction to Makefiles, all of which is 
  428. introductory. 
  429.  
  430. If you are familiar with other make programs, see Features of GNU make, which 
  431. lists the enhancements GNU make has, and Incompatibilities and Missing 
  432. Features, which explains the few things GNU make lacks that others have. 
  433.  
  434. For a quick summary, see Options Summary, Quick Reference, and Special Targets. 
  435.  
  436.  
  437. ΓòÉΓòÉΓòÉ 4.3. Problems and Bugs ΓòÉΓòÉΓòÉ
  438.  
  439. If you have problems with GNU make or think you've found a bug, please report 
  440. it to the developers; we cannot promise to do anything but we might well want 
  441. to fix it. 
  442.  
  443. Before reporting a bug, make sure you've actually found a real bug. Carefully 
  444. reread the documentation and see if it really says you can do what you're 
  445. trying to do.  If it's not clear whether you should be able to do something or 
  446. not, report that too; it's a bug in the documentation! 
  447.  
  448. Before reporting a bug or trying to fix it yourself, try to isolate it to the 
  449. smallest possible makefile that reproduces the problem.  Then send us the 
  450. makefile and the exact results make gave you.  Also say what you expected to 
  451. occur; this will help us decide whether the problem was really in the 
  452. documentation. 
  453.  
  454. Once you've got a precise problem, please send electronic mail either through 
  455. the Internet or via UUCP: 
  456.  
  457. Internet address:
  458.     bug-gnu-utils@prep.ai.mit.edu
  459.  
  460. UUCP path:
  461.     mit-eddie!prep.ai.mit.edu!bug-gnu-utils
  462.  
  463. Please include the version number of make you are using.  You can get this 
  464. information with the command `make --version -f /dev/null'. Be sure also to 
  465. include the type of machine and operating system you are using.  If possible, 
  466. include the contents of the file `config.h' that is generated by the 
  467. configuration process. 
  468.  
  469. Non-bug suggestions are always welcome as well.  If you have questions about 
  470. things that are unclear in the documentation or are just obscure features, 
  471. contact Roland McGrath; he will try to help you out, although he may not have 
  472. time to fix the problem. 
  473.  
  474. You can send electronic mail to Roland McGrath either through the Internet or 
  475. via UUCP: 
  476.  
  477. Internet address:
  478.     roland@prep.ai.mit.edu
  479.  
  480. UUCP path:
  481.     mit-eddie!prep.ai.mit.edu!roland
  482.  
  483.  
  484. ΓòÉΓòÉΓòÉ 5. An Introduction to Makefiles ΓòÉΓòÉΓòÉ
  485.  
  486. You need a file called a makefile to tell make what to do. Most often, the 
  487. makefile tells make how to compile and link a program. 
  488.  
  489. In this chapter, we will discuss a simple makefile that describes how to 
  490. compile and link a text editor which consists of eight C source files and three 
  491. header files.  The makefile can also tell make how to run miscellaneous 
  492. commands when explicitly asked (for example, to remove certain files as a 
  493. clean-up operation).  To see a more complex example of a makefile, see Complex 
  494. Makefile. 
  495.  
  496. When make recompiles the editor, each changed C source file must be recompiled. 
  497. If a header file has changed, each C source file that includes the header file 
  498. must be recompiled to be safe.  Each compilation produces an object file 
  499. corresponding to the source file. Finally, if any source file has been 
  500. recompiled, all the object files, whether newly made or saved from previous 
  501. compilations, must be linked together to produce the new executable editor. 
  502.  
  503.  
  504. ΓòÉΓòÉΓòÉ 5.1. What a Rule Looks Like ΓòÉΓòÉΓòÉ
  505.  
  506. A simple makefile consists of ``rules'' with the following shape: 
  507.  
  508. target ... : dependencies ...
  509.         command
  510.         ...
  511.         ...
  512.  
  513. A target is usually the name of a file that is generated by a program; examples 
  514. of targets are executable or object files.  A target can also be the name of an 
  515. action to carry out, such as `clean' (see Phony Targets). 
  516.  
  517. A dependency is a file that is used as input to create the target.  A target 
  518. often depends on several files. 
  519.  
  520. A command is an action that make carries out. A rule may have more than one 
  521. command, each on its own line. *Please note:* you need to put a tab character 
  522. at the beginning of every command line!  This is an obscurity that catches the 
  523. unwary. 
  524.  
  525. Usually a command is in a rule with dependencies and serves to create a target 
  526. file if any of the dependencies change.  However, the rule that specifies 
  527. commands for the target need not have dependencies.  For example, the rule 
  528. containing the delete command associated with the target `clean' does not have 
  529. dependencies. 
  530.  
  531. A rule, then, explains how and when to remake certain files which are the 
  532. targets of the particular rule.  make carries out the commands on the 
  533. dependencies to create or update the target.  A rule can also explain how and 
  534. when to carry out an action. See Writing Rules. 
  535.  
  536. A makefile may contain other text besides rules, but a simple makefile need 
  537. only contain rules.  Rules may look somewhat more complicated than shown in 
  538. this template, but all fit the pattern more or less. 
  539.  
  540.  
  541. ΓòÉΓòÉΓòÉ 5.2. A Simple Makefile ΓòÉΓòÉΓòÉ
  542.  
  543. Here is a straightforward makefile that describes the way an executable file 
  544. called edit depends on eight object files which, in turn, depend on eight C 
  545. source and three header files. 
  546.  
  547. In this example, all the C files include `defs.h', but only those defining 
  548. editing commands include `command.h', and only low level files that change the 
  549. editor buffer include `buffer.h'. 
  550.  
  551. edit : main.o kbd.o command.o display.o \
  552.        insert.o search.o files.o utils.o
  553.         cc -o edit main.o kbd.o command.o display.o \
  554.                    insert.o search.o files.o utils.o
  555.  
  556. main.o : main.c defs.h
  557.         cc -c main.c
  558. kbd.o : kbd.c defs.h command.h
  559.         cc -c kbd.c
  560. command.o : command.c defs.h command.h
  561.         cc -c command.c
  562. display.o : display.c defs.h buffer.h
  563.         cc -c display.c
  564. insert.o : insert.c defs.h buffer.h
  565.         cc -c insert.c
  566. search.o : search.c defs.h buffer.h
  567.         cc -c search.c
  568. files.o : files.c defs.h buffer.h command.h
  569.         cc -c files.c
  570. utils.o : utils.c defs.h
  571.         cc -c utils.c
  572. clean :
  573.         rm edit main.o kbd.o command.o display.o \
  574.            insert.o search.o files.o utils.o
  575.  
  576. We split each long line into two lines using backslash-newline; this is like 
  577. using one long line, but is easier to read. 
  578.  
  579. To use this makefile to create the executable file called `edit', type: 
  580.  
  581. make
  582.  
  583. To use this makefile to delete the executable file and all the object files 
  584. from the directory, type: 
  585.  
  586. make clean
  587.  
  588. In the example makefile, the targets include the executable file `edit', and 
  589. the object files `main.o' and `kbd.o'.  The dependencies are files such as 
  590. `main.c' and `defs.h'. In fact, each `.o' file is both a target and a 
  591. dependency. Commands include `cc -c main.c' and `cc -c kbd.c'. 
  592.  
  593. When a target is a file, it needs to be recompiled or relinked if any of its 
  594. dependencies change.  In addition, any dependencies that are themselves 
  595. automatically generated should be updated first.  In this example, `edit' 
  596. depends on each of the eight object files; the object file `main.o' depends on 
  597. the source file `main.c' and on the header file `defs.h'. 
  598.  
  599. A shell command follows each line that contains a target and dependencies. 
  600. These shell commands say how to update the target file. A tab character must 
  601. come at the beginning of every command line to distinguish commands lines from 
  602. other lines in the makefile.  (Bear in mind that make does not know anything 
  603. about how the commands work.  It is up to you to supply commands that will 
  604. update the target file properly.  All make does is execute the commands in the 
  605. rule you have specified when the target file needs to be updated.) 
  606.  
  607. The target `clean' is not a file, but merely the name of an action.  Since you 
  608. normally do not want to carry out the actions in this rule, `clean' is not a 
  609. dependency of any other rule. Consequently, make never does anything with it 
  610. unless you tell it specifically.  Note that this rule not only is not a 
  611. dependency, it also does not have any dependencies, so the only purpose of the 
  612. rule is to run the specified commands.  Targets that do not refer to files but 
  613. are just actions are called phony targets. See Phony Targets, for information 
  614. about this kind of target. See Errors in Commands, to see how to cause make to 
  615. ignore errors from rm or any other command. 
  616.  
  617.  
  618. ΓòÉΓòÉΓòÉ 5.3. How make Processes a Makefile ΓòÉΓòÉΓòÉ
  619.  
  620. By default, make starts with the first rule (not counting rules whose target 
  621. names start with `.').  This is called the default goal.  (Goals are the 
  622. targets that make strives ultimately to update. See Arguments to Specify the 
  623. Goals.) 
  624.  
  625. In the simple example of the previous section, the default goal is to update 
  626. the executable program `edit'; therefore, we put that rule first. 
  627.  
  628. Thus, when you give the command: 
  629.  
  630. make
  631.  
  632. make reads the makefile in the current directory and begins by processing the 
  633. first rule.  In the example, this rule is for relinking `edit'; but before make 
  634. can fully process this rule, it must process the rules for the files that 
  635. `edit' depends on, which in this case are the object files.  Each of these 
  636. files is processed according to its own rule.  These rules say to update each 
  637. `.o' file by compiling its source file.  The recompilation must be done if the 
  638. source file, or any of the header files named as dependencies, is more recent 
  639. than the object file, or if the object file does not exist. 
  640.  
  641. The other rules are processed because their targets appear as dependencies of 
  642. the goal.  If some other rule is not depended on by the goal (or anything it 
  643. depends on, etc.), that rule is not processed, unless you tell make to do so 
  644. (with a command such as make clean). 
  645.  
  646. Before recompiling an object file, make considers updating its dependencies, 
  647. the source file and header files.  This makefile does not specify anything to 
  648. be done for them---the `.c' and `.h' files are not the targets of any 
  649. rules---so make does nothing for these files.  But make would update 
  650. automatically generated C programs, such as those made by Bison or Yacc, by 
  651. their own rules at this time. 
  652.  
  653. After recompiling whichever object files need it, make decides whether to 
  654. relink `edit'.  This must be done if the file `edit' does not exist, or if any 
  655. of the object files are newer than it.  If an object file was just recompiled, 
  656. it is now newer than `edit', so `edit' is relinked. 
  657.  
  658. Thus, if we change the file `insert.c' and run make, make will compile that 
  659. file to update `insert.o', and then link `edit'.  If we change the file 
  660. `command.h' and run make, make will recompile the object files `kbd.o', 
  661. `command.o' and `files.o' and then link the file `edit'. 
  662.  
  663.  
  664. ΓòÉΓòÉΓòÉ 5.4. Variables Make Makefiles Simpler ΓòÉΓòÉΓòÉ
  665.  
  666. In our example, we had to list all the object files twice in the rule for 
  667. `edit' (repeated here): 
  668.  
  669. edit : main.o kbd.o command.o display.o \
  670.               insert.o search.o files.o utils.o
  671.         cc -o edit main.o kbd.o command.o display.o \
  672.                    insert.o search.o files.o utils.o
  673.  
  674. Such duplication is error-prone; if a new object file is added to the system, 
  675. we might add it to one list and forget the other.  We can eliminate the risk 
  676. and simplify the makefile by using a variable.  Variables allow a text string 
  677. to be defined once and substituted in multiple places later (see How to Use 
  678. Variables). 
  679.  
  680. It is standard practice for every makefile to have a variable named objects, 
  681. OBJECTS, objs, OBJS, obj, or OBJ which is a list of all object file names.  We 
  682. would define such a variable objects with a line like this in the makefile: 
  683.  
  684. objects = main.o kbd.o command.o display.o \
  685.           insert.o search.o files.o utils.o
  686.  
  687. Then, each place we want to put a list of the object file names, we can 
  688. substitute the variable's value by writing `$(objects)' (see How to Use 
  689. Variables). 
  690.  
  691. Here is how the complete simple makefile looks when you use a variable for the 
  692. object files: 
  693.  
  694. objects = main.o kbd.o command.o display.o \
  695.           insert.o search.o files.o utils.o
  696.  
  697. edit : $(objects)
  698.         cc -o edit $(objects)
  699. main.o : main.c defs.h
  700.         cc -c main.c
  701. kbd.o : kbd.c defs.h command.h
  702.         cc -c kbd.c
  703. command.o : command.c defs.h command.h
  704.         cc -c command.c
  705. display.o : display.c defs.h buffer.h
  706.         cc -c display.c
  707. insert.o : insert.c defs.h buffer.h
  708.         cc -c insert.c
  709. search.o : search.c defs.h buffer.h
  710.         cc -c search.c
  711. files.o : files.c defs.h buffer.h command.h
  712.         cc -c files.c
  713. utils.o : utils.c defs.h
  714.         cc -c utils.c
  715. clean :
  716.         rm edit $(objects)
  717.  
  718.  
  719. ΓòÉΓòÉΓòÉ 5.5. Letting make Deduce the Commands ΓòÉΓòÉΓòÉ
  720.  
  721. It is not necessary to spell out the commands for compiling the individual C 
  722. source files, because make can figure them out: it has an implicit rule for 
  723. updating a `.o' file from a correspondingly named `.c' file using a `cc -c' 
  724. command.  For example, it will use the command `cc -c main.c -o main.o' to 
  725. compile `main.c' into `main.o'.  We can therefore omit the commands from the 
  726. rules for the object files.  See Using Implicit Rules. 
  727.  
  728. When a `.c' file is used automatically in this way, it is also automatically 
  729. added to the list of dependencies.  We can therefore omit the `.c' files from 
  730. the dependencies, provided we omit the commands. 
  731.  
  732. Here is the entire example, with both of these changes, and a variable objects 
  733. as suggested above: 
  734.  
  735. objects = main.o kbd.o command.o display.o \
  736.           insert.o search.o files.o utils.o
  737.  
  738. edit : $(objects)
  739.         cc -o edit $(objects)
  740.  
  741. main.o : defs.h
  742. kbd.o : defs.h command.h
  743. command.o : defs.h command.h
  744. display.o : defs.h buffer.h
  745. insert.o : defs.h buffer.h
  746. search.o : defs.h buffer.h
  747. files.o : defs.h buffer.h command.h
  748. utils.o : defs.h
  749.  
  750. .PHONY : clean
  751. clean :
  752.         -rm edit $(objects)
  753.  
  754. This is how we would write the makefile in actual practice.  (The complications 
  755. associated with `clean' are described elsewhere. See Phony Targets, and Errors 
  756. in Commands.) 
  757.  
  758. Because implicit rules are so convenient, they are important.  You will see 
  759. them used frequently. 
  760.  
  761.  
  762. ΓòÉΓòÉΓòÉ 5.6. Another Style of Makefile ΓòÉΓòÉΓòÉ
  763.  
  764. When the objects of a makefile are created only by implicit rules, an 
  765. alternative style of makefile is possible.  In this style of makefile, you 
  766. group entries by their dependencies instead of by their targets. Here is what 
  767. one looks like: 
  768.  
  769. objects = main.o kbd.o command.o display.o \
  770.           insert.o search.o files.o utils.o
  771.  
  772. edit : $(objects)
  773.         cc -o edit $(objects)
  774.  
  775. $(objects) : defs.h
  776. kbd.o command.o files.o : command.h
  777. display.o insert.o search.o files.o : buffer.h
  778.  
  779. Here `defs.h' is given as a dependency of all the object files; `command.h' and 
  780. `buffer.h' are dependencies of the specific object files listed for them. 
  781.  
  782. Whether this is better is a matter of taste: it is more compact, but some 
  783. people dislike it because they find it clearer to put all the information about 
  784. each target in one place. 
  785.  
  786.  
  787. ΓòÉΓòÉΓòÉ 5.7. Rules for Cleaning the Directory ΓòÉΓòÉΓòÉ
  788.  
  789. Compiling a program is not the only thing you might want to write rules for. 
  790. Makefiles commonly tell how to do a few other things besides compiling a 
  791. program: for example, how to delete all the object files and executables so 
  792. that the directory is `clean'. 
  793.  
  794. Here is how we could write a make rule for cleaning our example editor: 
  795.  
  796. clean:
  797.         rm edit $(objects)
  798.  
  799. In practice, we might want to write the rule in a somewhat more complicated 
  800. manner to handle unanticipated situations.  We would do this: 
  801.  
  802. .PHONY : clean
  803. clean :
  804.         -rm edit $(objects)
  805.  
  806. This prevents make from getting confused by an actual file called `clean' and 
  807. causes it to continue in spite of errors from rm.  (See Phony Targets, and 
  808. Errors in Commands.) 
  809.  
  810. A rule such as this should not be placed at the beginning of the makefile, 
  811. because we do not want it to run by default!  Thus, in the example makefile, we 
  812. want the rule for edit, which recompiles the editor, to remain the default 
  813. goal. 
  814.  
  815. Since clean is not a dependency of edit, this rule will not run at all if we 
  816. give the command `make' with no arguments.  In order to make the rule run, we 
  817. have to type `make clean'. See How to Run make. 
  818.  
  819.  
  820. ΓòÉΓòÉΓòÉ 6. Writing Makefiles ΓòÉΓòÉΓòÉ
  821.  
  822. The information that tells make how to recompile a system comes from reading a 
  823. data base called the makefile. 
  824.  
  825.  
  826. ΓòÉΓòÉΓòÉ 6.1. What Makefiles Contain ΓòÉΓòÉΓòÉ
  827.  
  828. Makefiles contain five kinds of things: explicit rules, implicit rules, 
  829. variable definitions, directives, and comments.  Rules, variables, and 
  830. directives are described at length in later chapters. 
  831.  
  832. o An explicit rule says when and how to remake one or more files, called the 
  833.   rule's targets.  It lists the other files that the targets depend on, and may 
  834.   also give commands to use to create or update the targets.  See Writing 
  835.   Rules. 
  836.  
  837. o An implicit rule says when and how to remake a class of files based on their 
  838.   names.  It describes how a target may depend on a file with a name similar to 
  839.   the target and gives commands to create or update such a target.  See Using 
  840.   Implicit Rules. 
  841.  
  842. o A variable definition is a line that specifies a text string value for a 
  843.   variable that can be substituted into the text later.  The simple makefile 
  844.   example shows a variable definition for objects as a list of all object files 
  845.   ( see Variables Make Makefiles Simpler). 
  846.  
  847. o A directive is a command for make to do something special while reading the 
  848.   makefile.  These include: 
  849.  
  850.    - Reading another makefile (see Including Other Makefiles). 
  851.  
  852.    - Deciding (based on the values of variables) whether to use or ignore a 
  853.      part of the makefile (see Conditional Parts of Makefiles). 
  854.  
  855.    - Defining a variable from a verbatim string containing multiple lines (see 
  856.      Defining Variables Verbatim). 
  857.  
  858. o `#' in a line of a makefile starts a comment.  It and the rest of the line 
  859.   are ignored, except that a trailing backslash not escaped by another 
  860.   backslash will continue the comment across multiple lines. Comments may 
  861.   appear on any of the lines in the makefile, except within a define directive, 
  862.   and perhaps within commands (where the shell decides what is a comment).  A 
  863.   line containing just a comment (with perhaps spaces before it) is effectively 
  864.   blank, and is ignored. 
  865.  
  866.  
  867. ΓòÉΓòÉΓòÉ 6.2. What Name to Give Your Makefile ΓòÉΓòÉΓòÉ
  868.  
  869. By default, when make looks for the makefile, it tries the following names, in 
  870. order: `GNUmakefile', `makefile' and `Makefile'. 
  871.  
  872. Normally you should call your makefile either `makefile' or `Makefile'.  (We 
  873. recommend `Makefile' because it appears prominently near the beginning of a 
  874. directory listing, right near other important files such as `README'.)  The 
  875. first name checked, `GNUmakefile', is not recommended for most makefiles.  You 
  876. should use this name if you have a makefile that is specific to GNU make, and 
  877. will not be understood by other versions of make.  Other make programs look for 
  878. `makefile' and `Makefile', but not `GNUmakefile'. 
  879.  
  880. If make finds none of these names, it does not use any makefile. Then you must 
  881. specify a goal with a command argument, and make will attempt to figure out how 
  882. to remake it using only its built-in implicit rules.  See Using Implicit Rules. 
  883.  
  884. If you want to use a nonstandard name for your makefile, you can specify the 
  885. makefile name with the `-f' or `--file' option.  The arguments `-f name' or 
  886. `--file name' tell make to read the file name as the makefile.  If you use more 
  887. than one `-f' or `--file' option, you can specify several makefiles.  All the 
  888. makefiles are effectively concatenated in the order specified.  The default 
  889. makefile names `GNUmakefile', `makefile' and `Makefile' are not checked 
  890. automatically if you specify `-f' or `--file'. 
  891.  
  892.  
  893. ΓòÉΓòÉΓòÉ 6.3. Including Other Makefiles ΓòÉΓòÉΓòÉ
  894.  
  895. The include directive tells make to suspend reading the current makefile and 
  896. read one or more other makefiles before continuing. The directive is a line in 
  897. the makefile that looks like this: 
  898.  
  899. include filenames...
  900.  
  901. filenames can contain shell file name patterns. 
  902.  
  903. Extra spaces are allowed and ignored at the beginning of the line, but a tab is 
  904. not allowed.  (If the line begins with a tab, it will be considered a command 
  905. line.)  Whitespace is required between include and the file names, and between 
  906. file names; extra whitespace is ignored there and at the end of the directive. 
  907. A comment starting with `#' is allowed at the end of the line.  If the file 
  908. names contain any variable or function references, they are expanded.  See How 
  909. to Use Variables. 
  910.  
  911. For example, if you have three `.mk' files, `a.mk', `b.mk', and `c.mk', and 
  912. $(bar) expands to bish bash, then the following expression 
  913.  
  914. include foo *.mk $(bar)
  915.  
  916. is equivalent to 
  917.  
  918. include foo a.mk b.mk c.mk bish bash
  919.  
  920. When make processes an include directive, it suspends reading of the containing 
  921. makefile and reads from each listed file in turn.  When that is finished, make 
  922. resumes reading the makefile in which the directive appears. 
  923.  
  924. One occasion for using include directives is when several programs, handled by 
  925. individual makefiles in various directories, need to use a common set of 
  926. variable definitions (see Setting Variables) or pattern rules (see Defining and 
  927. Redefining Pattern Rules). 
  928.  
  929. Another such occasion is when you want to generate dependencies from source 
  930. files automatically; the dependencies can be put in a file that is included by 
  931. the main makefile.  This practice is generally cleaner than that of somehow 
  932. appending the dependencies to the end of the main makefile as has been 
  933. traditionally done with other versions of make.  See Automatic Dependencies. 
  934.  
  935. If the specified name does not start with a slash, and the file is not found in 
  936. the current directory, several other directories are searched. First, any 
  937. directories you have specified with the `-I' or `--include-dir' option are 
  938. searched (see Summary of Options). Then the following directories (if they 
  939. exist) are searched, in this order: `prefix/include' (normally 
  940. `/usr/local/include') `/usr/gnu/include', `/usr/local/include', `/usr/include'. 
  941.  
  942. If an included makefile cannot be found in any of these directories, a warning 
  943. message is generated, but it is not an immediately fatal error; processing of 
  944. the makefile containing the include continues. Once it has finished reading 
  945. makefiles, make will try to remake any that are out of date or don't exist. See 
  946. How Makefiles Are Remade. Only after it has tried to find a way to remake a 
  947. makefile and failed, will make diagnose the missing makefile as a fatal error. 
  948.  
  949.  
  950. ΓòÉΓòÉΓòÉ 6.4. The Variable MAKEFILES ΓòÉΓòÉΓòÉ
  951.  
  952. If the environment variable MAKEFILES is defined, make considers its value as a 
  953. list of names (separated by whitespace) of additional makefiles to be read 
  954. before the others.  This works much like the include directive: various 
  955. directories are searched for those files (see Including Other Makefiles).  In 
  956. addition, the default goal is never taken from one of these makefiles and it is 
  957. not an error if the files listed in MAKEFILES are not found. 
  958.  
  959. The main use of MAKEFILES is in communication between recursive invocations of 
  960. make ( see Recursive Use of make).  It usually is not desirable to set the 
  961. environment variable before a top-level invocation of make, because it is 
  962. usually better not to mess with a makefile from outside.  However, if you are 
  963. running make without a specific makefile, a makefile in MAKEFILES can do useful 
  964. things to help the built-in implicit rules work better, such as defining search 
  965. paths (see Directory Search). 
  966.  
  967. Some users are tempted to set MAKEFILES in the environment automatically on 
  968. login, and program makefiles to expect this to be done. This is a very bad 
  969. idea, because such makefiles will fail to work if run by anyone else.  It is 
  970. much better to write explicit include directives in the makefiles.  See 
  971. Including Other Makefiles. 
  972.  
  973.  
  974. ΓòÉΓòÉΓòÉ 6.5. How Makefiles Are Remade ΓòÉΓòÉΓòÉ
  975.  
  976. Sometimes makefiles can be remade from other files, such as RCS or SCCS files. 
  977. If a makefile can be remade from other files, you probably want make to get an 
  978. up-to-date version of the makefile to read in. 
  979.  
  980. To this end, after reading in all makefiles, make will consider each as a goal 
  981. target and attempt to update it.  If a makefile has a rule which says how to 
  982. update it (found either in that very makefile or in another one) or if an 
  983. implicit rule applies to it ( see Using Implicit Rules), it will be updated if 
  984. necessary.  After all makefiles have been checked, if any have actually been 
  985. changed, make starts with a clean slate and reads all the makefiles over again. 
  986. (It will also attempt to update each of them over again, but normally this will 
  987. not change them again, since they are already up to date.) 
  988.  
  989. If the makefiles specify a double-colon rule to remake a file with commands but 
  990. no dependencies, that file will always be remade (see Double-Colon).  In the 
  991. case of makefiles, a makefile that has a double-colon rule with commands but no 
  992. dependencies will be remade every time make is run, and then again after make 
  993. starts over and reads the makefiles in again.  This would cause an infinite 
  994. loop: make would constantly remake the makefile, and never do anything else. 
  995. So, to avoid this, make will *not* attempt to remake makefiles which are 
  996. specified as double-colon targets but have no dependencies. 
  997.  
  998. If you do not specify any makefiles to be read with `-f' or `--file' options, 
  999. make will try the default makefile names; see What Name to Give Your Makefile. 
  1000. Unlike makefiles explicitly requested with `-f' or `--file' options, make is 
  1001. not certain that these makefiles should exist.  However, if a default makefile 
  1002. does not exist but can be created by running make rules, you probably want the 
  1003. rules to be run so that the makefile can be used. 
  1004.  
  1005. Therefore, if none of the default makefiles exists, make will try to make each 
  1006. of them in the same order in which they are searched for (see What Name to Give 
  1007. Your Makefile) until it succeeds in making one, or it runs out of names to try. 
  1008. Note that it is not an error if make cannot find or make any makefile; a 
  1009. makefile is not always necessary. 
  1010.  
  1011. When you use the `-t' or `--touch' option (see Instead of Executing the 
  1012. Commands), you would not want to use an out-of-date makefile to decide which 
  1013. targets to touch.  So the `-t' option has no effect on updating makefiles; they 
  1014. are really updated even if `-t' is specified. Likewise, `-q' (or `--question') 
  1015. and `-n' (or `--just-print') do not prevent updating of makefiles, because an 
  1016. out-of-date makefile would result in the wrong output for other targets. Thus, 
  1017. `make -f mfile -n foo' will update `mfile', read it in, and then print the 
  1018. commands to update `foo' and its dependencies without running them.  The 
  1019. commands printed for `foo' will be those specified in the updated contents of 
  1020. `mfile'. 
  1021.  
  1022. However, on occasion you might actually wish to prevent updating of even the 
  1023. makefiles.  You can do this by specifying the makefiles as goals in the command 
  1024. line as well as specifying them as makefiles.  When the makefile name is 
  1025. specified explicitly as a goal, the options `-t' and so on do apply to them. 
  1026.  
  1027. Thus, `make -f mfile -n mfile foo' would read the makefile `mfile', print the 
  1028. commands needed to update it without actually running them, and then print the 
  1029. commands needed to update `foo' without running them.  The commands for `foo' 
  1030. will be those specified by the existing contents of `mfile'. 
  1031.  
  1032.  
  1033. ΓòÉΓòÉΓòÉ 6.6. Overriding Part of Another Makefile ΓòÉΓòÉΓòÉ
  1034.  
  1035. Sometimes it is useful to have a makefile that is mostly just like another 
  1036. makefile.  You can often use the `include' directive to include one in the 
  1037. other, and add more targets or variable definitions. However, if the two 
  1038. makefiles give different commands for the same target, make will not let you 
  1039. just do this.  But there is another way. 
  1040.  
  1041. In the containing makefile (the one that wants to include the other), you can 
  1042. use the .DEFAULT special target to say that to remake any target that cannot be 
  1043. made from the information in the containing makefile, make should look in 
  1044. another makefile. See Defining Last-Resort Default Rules, for more information 
  1045. on .DEFAULT. 
  1046.  
  1047. For example, if you have a makefile called `Makefile' that says how to make the 
  1048. target `foo' (and other targets), you can write a makefile called `GNUmakefile' 
  1049. that contains: 
  1050.  
  1051. foo:
  1052.         frobnicate > foo
  1053.  
  1054. .DEFAULT:
  1055.         @$(MAKE) -f Makefile $@
  1056.  
  1057. If you say `make foo', make will find `GNUmakefile', read it, and see that to 
  1058. make `foo', it needs to run the command `frobnicate > foo'.  If you say `make 
  1059. bar', make will find no way to make `bar' in `GNUmakefile', so it will use the 
  1060. commands from .DEFAULT: `make -f Makefile bar'.  If `Makefile' provides a rule 
  1061. for updating `bar', make will apply the rule.  And likewise for any other 
  1062. target that `GNUmakefile' does not say how to make. 
  1063.  
  1064.  
  1065. ΓòÉΓòÉΓòÉ 7. Writing Rules ΓòÉΓòÉΓòÉ
  1066.  
  1067. A rule appears in the makefile and says when and how to remake certain files, 
  1068. called the rule's targets (most often only one per rule). It lists the other 
  1069. files that are the dependencies of the target, and commands to use to create or 
  1070. update the target. 
  1071.  
  1072. The order of rules is not significant, except for determining the default goal: 
  1073. the target for make to consider, if you do not otherwise specify one.  The 
  1074. default goal is the target of the first rule in the first makefile.  If the 
  1075. first rule has multiple targets, only the first target is taken as the default. 
  1076. There are two exceptions: a target starting with a period is not a default 
  1077. unless it contains one or more slashes, `/', as well; and, a target that 
  1078. defines a pattern rule has no effect on the default goal. (See Defining and 
  1079. Redefining Pattern Rules.) 
  1080.  
  1081. Therefore, we usually write the makefile so that the first rule is the one for 
  1082. compiling the entire program or all the programs described by the makefile 
  1083. (often with a target called `all'). See Arguments to Specify the Goals. 
  1084.  
  1085.  
  1086. ΓòÉΓòÉΓòÉ 7.1. Rule Example ΓòÉΓòÉΓòÉ
  1087.  
  1088. Here is an example of a rule: 
  1089.  
  1090. foo.o : foo.c defs.h       # module for twiddling the frobs
  1091.         cc -c -g foo.c
  1092.  
  1093. Its target is `foo.o' and its dependencies are `foo.c' and `defs.h'.  It has 
  1094. one command, which is `cc -c -g foo.c'. The command line starts with a tab to 
  1095. identify it as a command. 
  1096.  
  1097. This rule says two things: 
  1098.  
  1099. o How to decide whether `foo.o' is out of date: it is out of date if it does 
  1100.   not exist, or if either `foo.c' or `defs.h' is more recent than it. 
  1101.  
  1102. o How to update the file `foo.o': by running cc as stated. The command does not 
  1103.   explicitly mention `defs.h', but we presume that `foo.c' includes it, and 
  1104.   that that is why `defs.h' was added to the dependencies. 
  1105.  
  1106.  
  1107. ΓòÉΓòÉΓòÉ 7.2. Rule Syntax ΓòÉΓòÉΓòÉ
  1108.  
  1109. In general, a rule looks like this: 
  1110.  
  1111. targets : dependencies
  1112.         command
  1113.         ...
  1114.  
  1115. or like this: 
  1116.  
  1117. targets : dependencies ; command
  1118.         command
  1119.         ...
  1120.  
  1121. The targets are file names, separated by spaces.  Wildcard characters may be 
  1122. used ( see Using Wildcard Characters in File Names) and a name of the form 
  1123. `a(m)' represents member m in archive file a (see Archive Members as Targets). 
  1124. Usually there is only one target per rule, but occasionally there is a reason 
  1125. to have more (see Multiple Targets in a Rule). 
  1126.  
  1127. The command lines start with a tab character.  The first command may appear on 
  1128. the line after the dependencies, with a tab character, or may appear on the 
  1129. same line, with a semicolon.  Either way, the effect is the same.  See Writing 
  1130. the Commands in Rules. 
  1131.  
  1132. Because dollar signs are used to start variable references, if you really want 
  1133. a dollar sign in a rule you must write two of them, `$$' (see How to Use 
  1134. Variables). You may split a long line by inserting a backslash followed by a 
  1135. newline, but this is not required, as make places no limit on the length of a 
  1136. line in a makefile. 
  1137.  
  1138. A rule tells make two things: when the targets are out of date, and how to 
  1139. update them when necessary. 
  1140.  
  1141. The criterion for being out of date is specified in terms of the dependencies, 
  1142. which consist of file names separated by spaces. (Wildcards and archive members 
  1143. (see Archives) are allowed here too.) A target is out of date if it does not 
  1144. exist or if it is older than any of the dependencies (by comparison of 
  1145. last-modification times).  The idea is that the contents of the target file are 
  1146. computed based on information in the dependencies, so if any of the 
  1147. dependencies changes, the contents of the existing target file are no longer 
  1148. necessarily valid. 
  1149.  
  1150. How to update is specified by commands.  These are lines to be executed by the 
  1151. shell (normally `sh'), but with some extra features (see Writing the Commands 
  1152. in Rules). 
  1153.  
  1154.  
  1155. ΓòÉΓòÉΓòÉ 7.3. Using Wildcard Characters in File Names ΓòÉΓòÉΓòÉ
  1156.  
  1157. A single file name can specify many files using wildcard characters. The 
  1158. wildcard characters in make are `*', `?' and `[...]', the same as in the Bourne 
  1159. shell.  For example, `*.c' specifies a list of all the files (in the working 
  1160. directory) whose names end in `.c'. 
  1161.  
  1162. The character `~' at the beginning of a file name also has special 
  1163. significance.  If alone, or followed by a slash, it represents your home 
  1164. directory.  For example `~/bin' expands to `/home/you/bin'. If the `~' is 
  1165. followed by a word, the string represents the home directory of the user named 
  1166. by that word.  For example `~john/bin' expands to `/home/john/bin'. 
  1167.  
  1168. Wildcard expansion happens automatically in targets, in dependencies, and in 
  1169. commands (where the shell does the expansion).  In other contexts, wildcard 
  1170. expansion happens only if you request it explicitly with the wildcard function. 
  1171.  
  1172. The special significance of a wildcard character can be turned off by preceding 
  1173. it with a backslash.  Thus, `foo\*bar' would refer to a specific file whose 
  1174. name consists of `foo', an asterisk, and `bar'. 
  1175.  
  1176.  
  1177. ΓòÉΓòÉΓòÉ 7.3.1. Wildcard Examples ΓòÉΓòÉΓòÉ
  1178.  
  1179. Wildcards can be used in the commands of a rule, where they are expanded by the 
  1180. shell.  For example, here is a rule to delete all the object files: 
  1181.  
  1182. clean:
  1183.         rm -f *.o
  1184.  
  1185. Wildcards are also useful in the dependencies of a rule.  With the following 
  1186. rule in the makefile, `make print' will print all the `.c' files that have 
  1187. changed since the last time you printed them: 
  1188.  
  1189. print: *.c
  1190.         lpr -p $?
  1191.         touch print
  1192.  
  1193. This rule uses `print' as an empty target file; see Empty Target Files to 
  1194. Record Events.  (The automatic variable `$?' is used to print only those files 
  1195. that have changed; see Automatic Variables.) 
  1196.  
  1197. Wildcard expansion does not happen when you define a variable.  Thus, if you 
  1198. write this: 
  1199.  
  1200. objects = *.o
  1201.  
  1202. then the value of the variable objects is the actual string `*.o'.  However, if 
  1203. you use the value of objects in a target, dependency or command, wildcard 
  1204. expansion will take place at that time. To set objects to the expansion, 
  1205. instead use: 
  1206.  
  1207. objects := $(wildcard *.o)
  1208.  
  1209. See Wildcard Function. 
  1210.  
  1211.  
  1212. ΓòÉΓòÉΓòÉ 7.3.2. Pitfalls of Using Wildcards ΓòÉΓòÉΓòÉ
  1213.  
  1214. Now here is an example of a naive way of using wildcard expansion, that does 
  1215. not do what you would intend.  Suppose you would like to say that the 
  1216. executable file `foo' is made from all the object files in the directory, and 
  1217. you write this: 
  1218.  
  1219. objects = *.o
  1220.  
  1221. foo : $(objects)
  1222.         cc -o foo $(CFLAGS) $(objects)
  1223.  
  1224. The value of objects is the actual string `*.o'.  Wildcard expansion happens in 
  1225. the rule for `foo', so that each existing `.o' file becomes a dependency of 
  1226. `foo' and will be recompiled if necessary. 
  1227.  
  1228. But what if you delete all the `.o' files?  Then `*.o' will expand into 
  1229. nothing.  The target `foo' will have no dependencies and would be remade by 
  1230. linking no object files.  This is not what you want! 
  1231.  
  1232. Actually it is possible to obtain the desired result with wildcard expansion, 
  1233. but you need more sophisticated techniques, including the wildcard function and 
  1234. string substitution. See The Function wildcard. 
  1235.  
  1236.  
  1237. ΓòÉΓòÉΓòÉ 7.3.3. The Function wildcard ΓòÉΓòÉΓòÉ
  1238.  
  1239. Wildcard expansion happens automatically in rules.  But wildcard expansion does 
  1240. not normally take place when a variable is set, or inside the arguments of a 
  1241. function.  If you want to do wildcard expansion in such places, you need to use 
  1242. the wildcard function, like this: 
  1243.  
  1244. $(wildcard pattern)
  1245.  
  1246. This string, used anywhere in a makefile, is replaced by a space-separated list 
  1247. of names of existing files that match the pattern pattern. 
  1248.  
  1249. One use of the wildcard function is to get a list of all the C source files in 
  1250. a directory, like this: 
  1251.  
  1252. $(wildcard *.c)
  1253.  
  1254. We can change the list of C source files into a list of object files by 
  1255. replacing the `.o' suffix with `.c' in the result, like this: 
  1256.  
  1257. $(patsubst %.c,%.o,$(wildcard *.c))
  1258.  
  1259. (Here we have used another function, patsubst. See Functions for String 
  1260. Substitution and Analysis.) 
  1261.  
  1262. Thus, a makefile to compile all C source files in the directory and then link 
  1263. them together could be written as follows: 
  1264.  
  1265. objects := $(patsubst %.c,%.o,$(wildcard *.c))
  1266.  
  1267. foo : $(objects)
  1268.         cc -o foo $(objects)
  1269.  
  1270. (This takes advantage of the implicit rule for compiling C programs, so there 
  1271. is no need to write explicit rules for compiling the files. See The Two Flavors 
  1272. of Variables, for an explanation of `:=', which is a variant of `='.) 
  1273.  
  1274.  
  1275. ΓòÉΓòÉΓòÉ 7.4. Searching Directories for Dependencies ΓòÉΓòÉΓòÉ
  1276.  
  1277. For large systems, it is often desirable to put sources in a separate directory 
  1278. from the binaries.  The directory search features of make facilitate this by 
  1279. searching several directories automatically to find a dependency.  When you 
  1280. redistribute the files among directories, you do not need to change the 
  1281. individual rules, just the search paths. 
  1282.  
  1283.  
  1284. ΓòÉΓòÉΓòÉ 7.4.1. VPATH: Search Path for All Dependencies ΓòÉΓòÉΓòÉ
  1285.  
  1286. The value of the make variable VPATH specifies a list of directories that make 
  1287. should search.  Most often, the directories are expected to contain dependency 
  1288. files that are not in the current directory; however, VPATH specifies a search 
  1289. list that make applies for all files, including files which are targets of 
  1290. rules. 
  1291.  
  1292. Thus, if a file that is listed as a target or dependency does not exist in the 
  1293. current directory, make searches the directories listed in VPATH for a file 
  1294. with that name.  If a file is found in one of them, that file becomes the 
  1295. dependency.  Rules may then specify the names of source files in the 
  1296. dependencies as if they all existed in the current directory. See Writing Shell 
  1297. Commands with Directory Search. 
  1298.  
  1299. In the VPATH variable, directory names are separated by colons. The order in 
  1300. which directories are listed is the order followed by make in its search. 
  1301.  
  1302. For example, 
  1303.  
  1304. VPATH = src:../headers
  1305.  
  1306. specifies a path containing two directories, `src' and `../headers', which make 
  1307. searches in that order. 
  1308.  
  1309. With this value of VPATH, the following rule, 
  1310.  
  1311. foo.o : foo.c
  1312.  
  1313. is interpreted as if it were written like this: 
  1314.  
  1315. foo.o : src/foo.c
  1316.  
  1317. assuming the file `foo.c' does not exist in the current directory but is found 
  1318. in the directory `src'. 
  1319.  
  1320.  
  1321. ΓòÉΓòÉΓòÉ 7.4.2. The vpath Directive ΓòÉΓòÉΓòÉ
  1322.  
  1323. Similar to the VPATH variable but more selective is the vpath directive (note 
  1324. lower case), which allows you to specify a search path for a particular class 
  1325. of file names, those that match a particular pattern.  Thus you can supply 
  1326. certain search directories for one class of file names and other directories 
  1327. (or none) for other file names. 
  1328.  
  1329. There are three forms of the vpath directive: 
  1330.  
  1331. vpath pattern directories 
  1332.           Specify the search path directories for file names that match 
  1333.           pattern. 
  1334.  
  1335.           The search path, directories, is a colon-separated list of 
  1336.           directories to be searched, just like the search path used in the 
  1337.           VPATH variable. 
  1338.  
  1339. vpath pattern 
  1340.           Clear out the search path associated with pattern. 
  1341.  
  1342. vpath 
  1343.           Clear all search paths previously specified with vpath directives. 
  1344.  
  1345. A vpath pattern is a string containing a `%' character.  The string must match 
  1346. the file name of a dependency that is being searched for, the `%' character 
  1347. matching any sequence of zero or more characters (as in pattern rules; see 
  1348. Defining and Redefining Pattern Rules).  For example, %.h matches files that 
  1349. end in .h.  (If there is no `%', the pattern must match the dependency exactly, 
  1350. which is not useful very often.) 
  1351.  
  1352. `%' characters in a vpath directive's pattern can be quoted with preceding 
  1353. backslashes (`\').  Backslashes that would otherwise quote `%' characters can 
  1354. be quoted with more backslashes. Backslashes that quote `%' characters or other 
  1355. backslashes are removed from the pattern before it is compared to file names. 
  1356. Backslashes that are not in danger of quoting `%' characters go unmolested. 
  1357.  
  1358. When a dependency fails to exist in the current directory, if the pattern in a 
  1359. vpath directive matches the name of the dependency file, then the directories 
  1360. in that directive are searched just like (and before) the directories in the 
  1361. VPATH variable. 
  1362.  
  1363. For example, 
  1364.  
  1365. vpath %.h ../headers
  1366.  
  1367. tells make to look for any dependency whose name ends in `.h' in the directory 
  1368. `../headers' if the file is not found in the current directory. 
  1369.  
  1370. If several vpath patterns match the dependency file's name, then make processes 
  1371. each matching vpath directive one by one, searching all the directories 
  1372. mentioned in each directive.  make handles multiple vpath directives in the 
  1373. order in which they appear in the makefile; multiple directives with the same 
  1374. pattern are independent of each other. 
  1375.  
  1376. Thus, 
  1377.  
  1378. vpath %.c foo
  1379. vpath %   blish
  1380. vpath %.c bar
  1381.  
  1382. will look for a file ending in `.c' in `foo', then `blish', then `bar', while 
  1383.  
  1384. vpath %.c foo:bar
  1385. vpath %   blish
  1386.  
  1387. will look for a file ending in `.c' in `foo', then `bar', then `blish'. 
  1388.  
  1389.  
  1390. ΓòÉΓòÉΓòÉ 7.4.3. Writing Shell Commands with Directory Search ΓòÉΓòÉΓòÉ
  1391.  
  1392. When a dependency is found in another directory through directory search, this 
  1393. cannot change the commands of the rule; they will execute as written. 
  1394. Therefore, you must write the commands with care so that they will look for the 
  1395. dependency in the directory where make finds it. 
  1396.  
  1397. This is done with the automatic variables such as `$^' (see Automatic 
  1398. Variables). For instance, the value of `$^' is a list of all the dependencies 
  1399. of the rule, including the names of the directories in which they were found, 
  1400. and the value of `$@' is the target.  Thus: 
  1401.  
  1402. foo.o : foo.c
  1403.         cc -c $(CFLAGS) $^ -o $@
  1404.  
  1405. (The variable CFLAGS exists so you can specify flags for C compilation by 
  1406. implicit rules; we use it here for consistency so it will affect all C 
  1407. compilations uniformly; see Variables Used by Implicit Rules.) 
  1408.  
  1409. Often the dependencies include header files as well, which you do not want to 
  1410. mention in the commands.  The automatic variable `$<' is just the first 
  1411. dependency: 
  1412.  
  1413. VPATH = src:../headers
  1414. foo.o : foo.c defs.h hack.h
  1415.         cc -c $(CFLAGS) $< -o $@
  1416.  
  1417.  
  1418. ΓòÉΓòÉΓòÉ 7.4.4. Directory Search and Implicit Rules ΓòÉΓòÉΓòÉ
  1419.  
  1420. The search through the directories specified in VPATH or with vpath also 
  1421. happens during consideration of implicit rules (see Using Implicit Rules). 
  1422.  
  1423. For example, when a file `foo.o' has no explicit rule, make considers implicit 
  1424. rules such as to compile `foo.c' if that file exists.  If such a file is 
  1425. lacking in the current directory, the appropriate directories are searched for 
  1426. it.  If `foo.c' exists (or is mentioned in the makefile) in any of the 
  1427. directories, the implicit rule for C compilation is applied. 
  1428.  
  1429. The commands of implicit rules normally use automatic variables as a matter of 
  1430. necessity; consequently they will use the file names found by directory search 
  1431. with no extra effort. 
  1432.  
  1433.  
  1434. ΓòÉΓòÉΓòÉ 7.4.5. Directory Search for Link Libraries ΓòÉΓòÉΓòÉ
  1435.  
  1436. Directory search applies in a special way to libraries used with the linker. 
  1437. This special feature comes into play when you write a dependency whose name is 
  1438. of the form `-lname'.  (You can tell something strange is going on here because 
  1439. the dependency is normally the name of a file, and the file name of the library 
  1440. looks like `libname.a', not like `-lname'.) 
  1441.  
  1442. When a dependency's name has the form `-lname', make handles it specially by 
  1443. searching for the file `libname.a' in the current directory, in directories 
  1444. specified by matching vpath search paths and the VPATH search path, and then in 
  1445. the directories `/lib', `/usr/lib', and `prefix/lib' (normally 
  1446. `/usr/local/lib'). 
  1447.  
  1448. For example, 
  1449.  
  1450. foo : foo.c -lcurses
  1451.         cc $^ -o $@
  1452.  
  1453. would cause the command `cc foo.c /usr/lib/libcurses.a -o foo' to be executed 
  1454. when `foo' is older than `foo.c' or than `/usr/lib/libcurses.a'. 
  1455.  
  1456.  
  1457. ΓòÉΓòÉΓòÉ 7.5. Phony Targets ΓòÉΓòÉΓòÉ
  1458.  
  1459. A phony target is one that is not really the name of a file.  It is just a name 
  1460. for some commands to be executed when you make an explicit request. There are 
  1461. two reasons to use a phony target: to avoid a conflict with a file of the same 
  1462. name, and to improve performance. 
  1463.  
  1464. If you write a rule whose commands will not create the target file, the 
  1465. commands will be executed every time the target comes up for remaking. Here is 
  1466. an example: 
  1467.  
  1468. clean:
  1469.         rm *.o temp
  1470.  
  1471. Because the rm command does not create a file named `clean', probably no such 
  1472. file will ever exist.  Therefore, the rm command will be executed every time 
  1473. you say `make clean'. 
  1474.  
  1475. The phony target will cease to work if anything ever does create a file named 
  1476. `clean' in this directory.  Since it has no dependencies, the file `clean' 
  1477. would inevitably be considered up to date, and its commands would not be 
  1478. executed.  To avoid this problem, you can explicitly declare the target to be 
  1479. phony, using the special target .PHONY (see Special Built-in Target Names) as 
  1480. follows: 
  1481.  
  1482. .PHONY : clean
  1483.  
  1484. Once this is done, `make clean' will run the commands regardless of whether 
  1485. there is a file named `clean'. 
  1486.  
  1487. Since it knows that phony targets do not name actual files that could be remade 
  1488. from other files, make skips the implicit rule search for phony targets (see 
  1489. Implicit Rules).  This is why declaring a target phony is good for performance, 
  1490. even if you are not worried about the actual file existing. 
  1491.  
  1492. Thus, you first write the line that states that clean is a phony target, then 
  1493. you write the rule, like this: 
  1494.  
  1495. .PHONY: clean
  1496. clean:
  1497.         rm *.o temp
  1498.  
  1499. A phony target should not be a dependency of a real target file; if it is, its 
  1500. commands are run every time make goes to update that file.  As long as a phony 
  1501. target is never a dependency of a real target, the phony target commands will 
  1502. be executed only when the phony target is a specified goal ( see Arguments to 
  1503. Specify the Goals). 
  1504.  
  1505. Phony targets can have dependencies.  When one directory contains multiple 
  1506. programs, it is most convenient to describe all of the programs in one makefile 
  1507. `./Makefile'.  Since the target remade by default will be the first one in the 
  1508. makefile, it is common to make this a phony target named `all' and give it, as 
  1509. dependencies, all the individual programs.  For example: 
  1510.  
  1511. all : prog1 prog2 prog3
  1512. .PHONY : all
  1513.  
  1514. prog1 : prog1.o utils.o
  1515.         cc -o prog1 prog1.o utils.o
  1516.  
  1517. prog2 : prog2.o
  1518.         cc -o prog2 prog2.o
  1519.  
  1520. prog3 : prog3.o sort.o utils.o
  1521.         cc -o prog3 prog3.o sort.o utils.o
  1522.  
  1523. Now you can say just `make' to remake all three programs, or specify as 
  1524. arguments the ones to remake (as in `make prog1 prog3'). 
  1525.  
  1526. When one phony target is a dependency of another, it serves as a subroutine of 
  1527. the other.  For example, here `make cleanall' will delete the object files, the 
  1528. difference files, and the file `program': 
  1529.  
  1530. .PHONY: cleanall cleanobj cleandiff
  1531.  
  1532. cleanall : cleanobj cleandiff
  1533.         rm program
  1534.  
  1535. cleanobj :
  1536.         rm *.o
  1537.  
  1538. cleandiff :
  1539.         rm *.diff
  1540.  
  1541.  
  1542. ΓòÉΓòÉΓòÉ 7.6. Rules without Commands or Dependencies ΓòÉΓòÉΓòÉ
  1543.  
  1544. If a rule has no dependencies or commands, and the target of the rule is a 
  1545. nonexistent file, then make imagines this target to have been updated whenever 
  1546. its rule is run.  This implies that all targets depending on this one will 
  1547. always have their commands run. 
  1548.  
  1549. An example will illustrate this: 
  1550.  
  1551. clean: FORCE
  1552.         rm $(objects)
  1553. FORCE:
  1554.  
  1555. Here the target `FORCE' satisfies the special conditions, so the target `clean' 
  1556. that depends on it is forced to run its commands. There is nothing special 
  1557. about the name `FORCE', but that is one name commonly used this way. 
  1558.  
  1559. As you can see, using `FORCE' this way has the same results as using `.PHONY: 
  1560. clean'. 
  1561.  
  1562. Using `.PHONY' is more explicit and more efficient.  However, other versions of 
  1563. make do not support `.PHONY'; thus `FORCE' appears in many makefiles.  See 
  1564. Phony Targets. 
  1565.  
  1566.  
  1567. ΓòÉΓòÉΓòÉ 7.7. Empty Target Files to Record Events ΓòÉΓòÉΓòÉ
  1568.  
  1569. The empty target is a variant of the phony target; it is used to hold commands 
  1570. for an action that you request explicitly from time to time. Unlike a phony 
  1571. target, this target file can really exist; but the file's contents do not 
  1572. matter, and usually are empty. 
  1573.  
  1574. The purpose of the empty target file is to record, with its last-modification 
  1575. time, when the rule's commands were last executed.  It does so because one of 
  1576. the commands is a touch command to update the target file. 
  1577.  
  1578. The empty target file must have some dependencies.  When you ask to remake the 
  1579. empty target, the commands are executed if any dependency is more recent than 
  1580. the target; in other words, if a dependency has changed since the last time you 
  1581. remade the target.  Here is an example: 
  1582.  
  1583. print: foo.c bar.c
  1584.         lpr -p $?
  1585.         touch print
  1586.  
  1587. With this rule, `make print' will execute the lpr command if either source file 
  1588. has changed since the last `make print'.  The automatic variable `$?' is used 
  1589. to print only those files that have changed (see Automatic Variables). 
  1590.  
  1591.  
  1592. ΓòÉΓòÉΓòÉ 7.8. Special Built-in Target Names ΓòÉΓòÉΓòÉ
  1593.  
  1594. Certain names have special meanings if they appear as targets. 
  1595.  
  1596. .PHONY 
  1597.           The dependencies of the special target .PHONY are considered to be 
  1598.           phony targets.  When it is time to consider such a target, make will 
  1599.           run its commands unconditionally, regardless of whether a file with 
  1600.           that name exists or what its last-modification time is.  See Phony 
  1601.           Targets. 
  1602.  
  1603. .SUFFIXES 
  1604.           The dependencies of the special target .SUFFIXES are the list of 
  1605.           suffixes to be used in checking for suffix rules. See Old-Fashioned 
  1606.           Suffix Rules. 
  1607.  
  1608. .DEFAULT 
  1609.           The commands specified for .DEFAULT are used for any target for which 
  1610.           no rules are found (either explicit rules or implicit rules). See 
  1611.           Last Resort.  If .DEFAULT commands are specified, every file 
  1612.           mentioned as a dependency, but not as a target in a rule, will have 
  1613.           these commands executed on its behalf. See Implicit Rule Search 
  1614.           Algorithm. 
  1615.  
  1616. .PRECIOUS 
  1617.           The targets which .PRECIOUS depends on are given the following 
  1618.           special treatment: if make is killed or interrupted during the 
  1619.           execution of their commands, the target is not deleted. See 
  1620.           Interrupting or Killing make. Also, if the target is an intermediate 
  1621.           file, it will not be deleted after it is no longer needed, as is 
  1622.           normally done. See Chains of Implicit Rules. 
  1623.  
  1624.           You can also list the target pattern of an implicit rule (such as 
  1625.           `%.o') as a dependency file of the special target .PRECIOUS to 
  1626.           preserve intermediate files whose target patterns match that file's 
  1627.           name. 
  1628.  
  1629. .IGNORE 
  1630.           Simply by being mentioned as a target, .IGNORE says to ignore errors 
  1631.           in execution of commands.  The dependencies and commands for .IGNORE 
  1632.           are not meaningful. 
  1633.  
  1634.           `.IGNORE' exists for historical compatibility.  Since .IGNORE affects 
  1635.           every command in the makefile, it is not very useful; we recommend 
  1636.           you use the more selective ways to ignore errors in specific 
  1637.           commands.  See Errors in Commands. 
  1638.  
  1639. .SILENT 
  1640.           Simply by being mentioned as a target, .SILENT says not to print 
  1641.           commands before executing them.  The dependencies and commands for 
  1642.           .SILENT are not meaningful. 
  1643.  
  1644.           `.SILENT' exists for historical compatibility.  We recommend you use 
  1645.           the more selective ways to silence specific commands. See Command 
  1646.           Echoing.  If you want to silence all commands for a particular run of 
  1647.           make, use the `-s' or `--silent' option (see Options Summary). 
  1648.  
  1649. .EXPORT_ALL_VARIABLES 
  1650.           Simply by being mentioned as a target, this tells make to export all 
  1651.           variables to child processes by default. See Communicating Variables 
  1652.           to a Sub-make. 
  1653.  
  1654. Any defined implicit rule suffix also counts as a special target if it appears 
  1655. as a target, and so does the concatenation of two suffixes, such as `.c.o'. 
  1656. These targets are suffix rules, an obsolete way of defining implicit rules (but 
  1657. a way still widely used).  In principle, any target name could be special in 
  1658. this way if you break it in two and add both pieces to the suffix list.  In 
  1659. practice, suffixes normally begin with `.', so these special target names also 
  1660. begin with `.'. See Old-Fashioned Suffix Rules. 
  1661.  
  1662.  
  1663. ΓòÉΓòÉΓòÉ 7.9. Multiple Targets in a Rule ΓòÉΓòÉΓòÉ
  1664.  
  1665. A rule with multiple targets is equivalent to writing many rules, each with one 
  1666. target, and all identical aside from that.  The same commands apply to all the 
  1667. targets, but their effects may vary because you can substitute the actual 
  1668. target name into the command using `$@'.  The rule contributes the same 
  1669. dependencies to all the targets also. 
  1670.  
  1671. This is useful in two cases. 
  1672.  
  1673. o You want just dependencies, no commands.  For example: 
  1674.  
  1675.     kbd.o command.o files.o: command.h
  1676.  
  1677.   gives an additional dependency to each of the three object files mentioned. 
  1678.  
  1679. o Similar commands work for all the targets.  The commands do not need to be 
  1680.   absolutely identical, since the automatic variable `$@' can be used to 
  1681.   substitute the particular target to be remade into the commands (see 
  1682.   Automatic Variables).  For example: 
  1683.  
  1684.     bigoutput littleoutput : text.g
  1685.             generate text.g -$(subst output,,$@) > $@
  1686.  
  1687.   is equivalent to 
  1688.  
  1689.     bigoutput : text.g
  1690.             generate text.g -big > bigoutput
  1691.     littleoutput : text.g
  1692.             generate text.g -little > littleoutput
  1693.  
  1694.   Here we assume the hypothetical program generate makes two types of output, 
  1695.   one if given `-big' and one if given `-little'. See Functions for String 
  1696.   Substitution and Analysis, for an explanation of the subst function. 
  1697.  
  1698. Suppose you would like to vary the dependencies according to the target, much 
  1699. as the variable `$@' allows you to vary the commands. You cannot do this with 
  1700. multiple targets in an ordinary rule, but you can do it with a static pattern 
  1701. rule. See Static Pattern Rules. 
  1702.  
  1703.  
  1704. ΓòÉΓòÉΓòÉ 7.10. Multiple Rules for One Target ΓòÉΓòÉΓòÉ
  1705.  
  1706. One file can be the target of several rules.  All the dependencies mentioned in 
  1707. all the rules are merged into one list of dependencies for the target.  If the 
  1708. target is older than any dependency from any rule, the commands are executed. 
  1709.  
  1710. There can only be one set of commands to be executed for a file. If more than 
  1711. one rule gives commands for the same file, make uses the last set given and 
  1712. prints an error message. (As a special case, if the file's name begins with a 
  1713. dot, no error message is printed.  This odd behavior is only for compatibility 
  1714. with other implementations of make.) There is no reason to write your makefiles 
  1715. this way; that is why make gives you an error message. 
  1716.  
  1717. An extra rule with just dependencies can be used to give a few extra 
  1718. dependencies to many files at once.  For example, one usually has a variable 
  1719. named objects containing a list of all the compiler output files in the system 
  1720. being made.  An easy way to say that all of them must be recompiled if 
  1721. `config.h' changes is to write the following: 
  1722.  
  1723. objects = foo.o bar.o
  1724. foo.o : defs.h
  1725. bar.o : defs.h test.h
  1726. $(objects) : config.h
  1727.  
  1728. This could be inserted or taken out without changing the rules that really 
  1729. specify how to make the object files, making it a convenient form to use if you 
  1730. wish to add the additional dependency intermittently. 
  1731.  
  1732. Another wrinkle is that the additional dependencies could be specified with a 
  1733. variable that you set with a command argument to make (see Overriding 
  1734. Variables).  For example, 
  1735.  
  1736. extradeps=
  1737. $(objects) : $(extradeps)
  1738.  
  1739. means that the command `make extradeps=foo.h' will consider `foo.h' as a 
  1740. dependency of each object file, but plain `make' will not. 
  1741.  
  1742. If none of the explicit rules for a target has commands, then make searches for 
  1743. an applicable implicit rule to find some commands see Using Implicit Rules). 
  1744.  
  1745.  
  1746. ΓòÉΓòÉΓòÉ 7.11. Static Pattern Rules ΓòÉΓòÉΓòÉ
  1747.  
  1748. Static pattern rules are rules which specify multiple targets and construct the 
  1749. dependency names for each target based on the target name. They are more 
  1750. general than ordinary rules with multiple targets because the targets do not 
  1751. have to have identical dependencies.  Their dependencies must be analogous, but 
  1752. not necessarily identical. 
  1753.  
  1754.  
  1755. ΓòÉΓòÉΓòÉ 7.11.1. Syntax of Static Pattern Rules ΓòÉΓòÉΓòÉ
  1756.  
  1757. Here is the syntax of a static pattern rule: 
  1758.  
  1759. targets ...: target-pattern: dep-patterns ...
  1760.         commands
  1761.         ...
  1762.  
  1763. The targets list specifies the targets that the rule applies to. The targets 
  1764. can contain wildcard characters, just like the targets of ordinary rules ( see 
  1765. Using Wildcard Characters in File Names). 
  1766.  
  1767. The target-pattern and dep-patterns say how to compute the dependencies of each 
  1768. target.  Each target is matched against the target-pattern to extract a part of 
  1769. the target name, called the stem.  This stem is substituted into each of the 
  1770. dep-patterns to make the dependency names (one from each dep-pattern). 
  1771.  
  1772. Each pattern normally contains the character `%' just once.  When the 
  1773. target-pattern matches a target, the `%' can match any part of the target name; 
  1774. this part is called the stem.  The rest of the pattern must match exactly.  For 
  1775. example, the target `foo.o' matches the pattern `%.o', with `foo' as the stem. 
  1776. The targets `foo.c' and `foo.out' do not match that pattern. 
  1777.  
  1778. The dependency names for each target are made by substituting the stem for the 
  1779. `%' in each dependency pattern.  For example, if one dependency pattern is 
  1780. `%.c', then substitution of the stem `foo' gives the dependency name `foo.c'. 
  1781. It is legitimate to write a dependency pattern that does not contain `%'; then 
  1782. this dependency is the same for all targets. 
  1783.  
  1784. `%' characters in pattern rules can be quoted with preceding backslashes (`\'). 
  1785. Backslashes that would otherwise quote `%' characters can be quoted with more 
  1786. backslashes.  Backslashes that quote `%' characters or other backslashes are 
  1787. removed from the pattern before it is compared to file names or has a stem 
  1788. substituted into it. Backslashes that are not in danger of quoting `%' 
  1789. characters go unmolested.  For example, the pattern `the\%weird\\%pattern\\' 
  1790. has `the%weird\' preceding the operative `%' character, and `pattern\\' 
  1791. following it.  The final two backslashes are left alone because they cannot 
  1792. affect any `%' character. 
  1793.  
  1794. Here is an example, which compiles each of `foo.o' and `bar.o' from the 
  1795. corresponding `.c' file: 
  1796.  
  1797. objects = foo.o bar.o
  1798.  
  1799. $(objects): %.o: %.c
  1800.         $(CC) -c $(CFLAGS) $< -o $@
  1801.  
  1802. Here `$<' is the automatic variable that holds the name of the dependency and 
  1803. `$@' is the automatic variable that holds the name of the target; see Automatic 
  1804. Variables. 
  1805.  
  1806. Each target specified must match the target pattern; a warning is issued for 
  1807. each target that does not.  If you have a list of files, only some of which 
  1808. will match the pattern, you can use the filter function to remove nonmatching 
  1809. file names (see Functions for String Substitution and Analysis): 
  1810.  
  1811. files = foo.elc bar.o lose.o
  1812.  
  1813. $(filter %.o,$(files)): %.o: %.c
  1814.         $(CC) -c $(CFLAGS) $< -o $@
  1815. $(filter %.elc,$(files)): %.elc: %.el
  1816.         emacs -f batch-byte-compile $<
  1817.  
  1818. Here the result of `$(filter %.o,$(files))' is `bar.o lose.o', and the first 
  1819. static pattern rule causes each of these object files to be updated by 
  1820. compiling the corresponding C source file.  The result of `$(filter 
  1821. %.elc,$(files))' is `foo.elc', so that file is made from `foo.el'. 
  1822.  
  1823. Another example shows how to use $* in static pattern rules: 
  1824.  
  1825. bigoutput littleoutput : %output : text.g
  1826.         generate text.g -$* > $@
  1827.  
  1828. When the generate command is run, $* will expand to the stem, either `big' or 
  1829. `little'. 
  1830.  
  1831.  
  1832. ΓòÉΓòÉΓòÉ 7.11.2. Static Pattern Rules versus Implicit Rules ΓòÉΓòÉΓòÉ
  1833.  
  1834. A static pattern rule has much in common with an implicit rule defined as a 
  1835. pattern rule (see Defining and Redefining Pattern Rules). Both have a pattern 
  1836. for the target and patterns for constructing the names of dependencies.  The 
  1837. difference is in how make decides when the rule applies. 
  1838.  
  1839. An implicit rule can apply to any target that matches its pattern, but it does 
  1840. apply only when the target has no commands otherwise specified, and only when 
  1841. the dependencies can be found.  If more than one implicit rule appears 
  1842. applicable, only one applies; the choice depends on the order of rules. 
  1843.  
  1844. By contrast, a static pattern rule applies to the precise list of targets that 
  1845. you specify in the rule.  It cannot apply to any other target and it invariably 
  1846. does apply to each of the targets specified.  If two conflicting rules apply, 
  1847. and both have commands, that's an error. 
  1848.  
  1849. The static pattern rule can be better than an implicit rule for these reasons: 
  1850.  
  1851. o You may wish to override the usual implicit rule for a few files whose names 
  1852.   cannot be categorized syntactically but can be given in an explicit list. 
  1853.  
  1854. o If you cannot be sure of the precise contents of the directories you are 
  1855.   using, you may not be sure which other irrelevant files might lead make to 
  1856.   use the wrong implicit rule.  The choice might depend on the order in which 
  1857.   the implicit rule search is done. With static pattern rules, there is no 
  1858.   uncertainty: each rule applies to precisely the targets specified. 
  1859.  
  1860.  
  1861. ΓòÉΓòÉΓòÉ 7.12. Double-Colon Rules ΓòÉΓòÉΓòÉ
  1862.  
  1863. Double-colon rules are rules written with `::' instead of `:' after the target 
  1864. names.  They are handled differently from ordinary rules when the same target 
  1865. appears in more than one rule. 
  1866.  
  1867. When a target appears in multiple rules, all the rules must be the same type: 
  1868. all ordinary, or all double-colon.  If they are double-colon, each of them is 
  1869. independent of the others.  Each double-colon rule's commands are executed if 
  1870. the target is older than any dependencies of that rule.  This can result in 
  1871. executing none, any, or all of the double-colon rules. 
  1872.  
  1873. Double-colon rules with the same target are in fact completely separate from 
  1874. one another.  Each double-colon rule is processed individually, just as rules 
  1875. with different targets are processed. 
  1876.  
  1877. The double-colon rules for a target are executed in the order they appear in 
  1878. the makefile.  However, the cases where double-colon rules really make sense 
  1879. are those where the order of executing the commands would not matter. 
  1880.  
  1881. Double-colon rules are somewhat obscure and not often very useful; they provide 
  1882. a mechanism for cases in which the method used to update a target differs 
  1883. depending on which dependency files caused the update, and such cases are rare. 
  1884.  
  1885. Each double-colon rule should specify commands; if it does not, an implicit 
  1886. rule will be used if one applies. See Using Implicit Rules. 
  1887.  
  1888.  
  1889. ΓòÉΓòÉΓòÉ 7.13. Generating Dependencies Automatically ΓòÉΓòÉΓòÉ
  1890.  
  1891. In the makefile for a program, many of the rules you need to write often say 
  1892. only that some object file depends on some header file.  For example, if 
  1893. `main.c' uses `defs.h' via an #include, you would write: 
  1894.  
  1895. main.o: defs.h
  1896.  
  1897. You need this rule so that make knows that it must remake `main.o' whenever 
  1898. `defs.h' changes.  You can see that for a large program you would have to write 
  1899. dozens of such rules in your makefile.  And, you must always be very careful to 
  1900. update the makefile every time you add or remove an #include. 
  1901.  
  1902. To avoid this hassle, most modern C compilers can write these rules for you, by 
  1903. looking at the #include lines in the source files. Usually this is done with 
  1904. the `-M' option to the compiler. For example, the command: 
  1905.  
  1906. cc -M main.c
  1907.  
  1908. generates the output: 
  1909.  
  1910. main.o : main.c defs.h
  1911.  
  1912. Thus you no longer have to write all those rules yourself. The compiler will do 
  1913. it for you. 
  1914.  
  1915. With old make programs, it was traditional practice to use this compiler 
  1916. feature to generate dependencies on demand with a command like `make depend'. 
  1917. That command would create a file `depend' containing all the 
  1918. automatically-generated dependencies; then the makefile could use include to 
  1919. read them in (see Include). 
  1920.  
  1921. In GNU make, the feature of remaking makefiles makes this practice 
  1922. obsolete---you need never tell make explicitly to regenerate the dependencies, 
  1923. because it always regenerates any makefile that is out of date.  See Remaking 
  1924. Makefiles. 
  1925.  
  1926. The practice we recommend for automatic dependency generation is to have one 
  1927. makefile corresponding to each source file.  For each source file `name.c' 
  1928. there is a makefile `name.d' which lists what files the object file `name.o' 
  1929. depends on.  That way only the source files that have changed need to be 
  1930. rescanned to produce the new dependencies. 
  1931.  
  1932. Here is the pattern rule to generate a file of dependencies (i.e., a makefile) 
  1933. called `name.d' from a C source file called `name.c': 
  1934.  
  1935. %.d: %.c
  1936.         $(CC) -M $(CPPFLAGS) $< | sed 's/$*.o/& $@/g' > $@
  1937.  
  1938. See Pattern Rules, for information on defining pattern rules. The purpose of 
  1939. the sed command is to translate (for example): 
  1940.  
  1941. main.o : main.c defs.h
  1942.  
  1943. into: 
  1944.  
  1945. main.o main.d : main.c defs.h
  1946.  
  1947. This makes each `.d' file depend on all the source and header files that the 
  1948. corresponding `.o' file depends on.  make then knows it must regenerate the 
  1949. dependencies whenever any of the source or header files changes. 
  1950.  
  1951. Once you've defined the rule to remake the `.d' files, you then use the include 
  1952. directive to read them all in. See Include.  For example: 
  1953.  
  1954. sources = foo.c bar.c
  1955.  
  1956. include $(sources:.c=.d)
  1957.  
  1958. (This example uses a substitution variable reference to translate the list of 
  1959. source files `foo.c bar.c' into a list of dependency makefiles, `foo.d bar.d'. 
  1960. See Substitution Refs, for full information on substitution references.)  Since 
  1961. the `.d' files are makefiles like any others, make will remake them as 
  1962. necessary with no further work from you.  See Remaking Makefiles. 
  1963.  
  1964.  
  1965. ΓòÉΓòÉΓòÉ 8. Writing the Commands in Rules ΓòÉΓòÉΓòÉ
  1966.  
  1967. The commands of a rule consist of shell command lines to be executed one by 
  1968. one.  Each command line must start with a tab, except that the first command 
  1969. line may be attached to the target-and-dependencies line with a semicolon in 
  1970. between.  Blank lines and lines of just comments may appear among the command 
  1971. lines; they are ignored. 
  1972.  
  1973. Users use many different shell programs, but commands in makefiles are always 
  1974. interpreted by `/bin/sh' unless the makefile specifies otherwise.  See Command 
  1975. Execution. 
  1976.  
  1977. The shell that is in use determines whether comments can be written on command 
  1978. lines, and what syntax they use.  When the shell is `/bin/sh', a `#' starts a 
  1979. comment that extends to the end of the line.  The `#' does not have to be at 
  1980. the beginning of a line. Text on a line before a `#' is not part of the 
  1981. comment. 
  1982.  
  1983.  
  1984. ΓòÉΓòÉΓòÉ 8.1. Command Echoing ΓòÉΓòÉΓòÉ
  1985.  
  1986. Normally make prints each command line before it is executed. We call this 
  1987. echoing because it gives the appearance that you are typing the commands 
  1988. yourself. 
  1989.  
  1990. When a line starts with `@', the echoing of that line is suppressed. The `@' is 
  1991. discarded before the command is passed to the shell. Typically you would use 
  1992. this for a command whose only effect is to print something, such as an echo 
  1993. command to indicate progress through the makefile: 
  1994.  
  1995. @echo About to make distribution files
  1996.  
  1997. When make is given the flag `-n' or `--just-print', echoing is all that 
  1998. happens, no execution. See Summary of Options.  In this case and only this 
  1999. case, even the commands starting with `@' are printed.  This flag is useful for 
  2000. finding out which commands make thinks are necessary without actually doing 
  2001. them. 
  2002.  
  2003. The `-s' or `--silent' flag to make prevents all echoing, as if all commands 
  2004. started with `@'.  A rule in the makefile for the special target .SILENT has 
  2005. the same effect (see Special Built-in Target Names). .SILENT is essentially 
  2006. obsolete since `@' is more flexible. 
  2007.  
  2008.  
  2009. ΓòÉΓòÉΓòÉ 8.2. Command Execution ΓòÉΓòÉΓòÉ
  2010.  
  2011. When it is time to execute commands to update a target, they are executed by 
  2012. making a new subshell for each line.  (In practice, make may take shortcuts 
  2013. that do not affect the results.) 
  2014.  
  2015. *Please note:* this implies that shell commands such as cd that set variables 
  2016. local to each process will not affect the following command lines.  If you want 
  2017. to use cd to affect the next command, put the two on a single line with a 
  2018. semicolon between them.  Then make will consider them a single command and pass 
  2019. them, together, to a shell which will execute them in sequence.  For example: 
  2020.  
  2021. foo : bar/lose
  2022.         cd bar; gobble lose > ../foo
  2023.  
  2024. If you would like to split a single shell command into multiple lines of text, 
  2025. you must use a backslash at the end of all but the last subline. Such a 
  2026. sequence of lines is combined into a single line, by deleting the 
  2027. backslash-newline sequences, before passing it to the shell.  Thus, the 
  2028. following is equivalent to the preceding example: 
  2029.  
  2030. foo : bar/lose
  2031.         cd bar;  \
  2032.         gobble lose > ../foo
  2033.  
  2034. The program used as the shell is taken from the variable SHELL. By default, the 
  2035. program `/bin/sh' is used. 
  2036.  
  2037. Unlike most variables, the variable SHELL is never set from the environment. 
  2038. This is because the SHELL environment variable is used to specify your personal 
  2039. choice of shell program for interactive use.  It would be very bad for personal 
  2040. choices like this to affect the functioning of makefiles. See Variables from 
  2041. the Environment. 
  2042.  
  2043.  
  2044. ΓòÉΓòÉΓòÉ 8.3. Parallel Execution ΓòÉΓòÉΓòÉ
  2045.  
  2046. GNU make knows how to execute several commands at once. Normally, make will 
  2047. execute only one command at a time, waiting for it to finish before executing 
  2048. the next.  However, the `-j' or `--jobs' option tells make to execute many 
  2049. commands simultaneously. 
  2050.  
  2051. If the `-j' option is followed by an integer, this is the number of commands to 
  2052. execute at once; this is called the number of job slots. If there is nothing 
  2053. looking like an integer after the `-j' option, there is no limit on the number 
  2054. of job slots.  The default number of job slots is one, which means serial 
  2055. execution (one thing at a time). 
  2056.  
  2057. One unpleasant consequence of running several commands simultaneously is that 
  2058. output from all of the commands comes when the commands send it, so messages 
  2059. from different commands may be interspersed. 
  2060.  
  2061. Another problem is that two processes cannot both take input from the same 
  2062. device; so to make sure that only one command tries to take input from the 
  2063. terminal at once, make will invalidate the standard input streams of all but 
  2064. one running command.  This means that attempting to read from standard input 
  2065. will usually be a fatal error (a `Broken pipe' signal) for most child processes 
  2066. if there are several. 
  2067.  
  2068. It is unpredictable which command will have a valid standard input stream 
  2069. (which will come from the terminal, or wherever you redirect the standard input 
  2070. of make).  The first command run will always get it first, and the first 
  2071. command started after that one finishes will get it next, and so on. 
  2072.  
  2073. We will change how this aspect of make works if we find a better alternative. 
  2074. In the mean time, you should not rely on any command using standard input at 
  2075. all if you are using the parallel execution feature; but if you are not using 
  2076. this feature, then standard input works normally in all commands. 
  2077.  
  2078. If a command fails (is killed by a signal or exits with a nonzero status), and 
  2079. errors are not ignored for that command (see Errors in Commands), the remaining 
  2080. command lines to remake the same target will not be run. If a command fails and 
  2081. the `-k' or `--keep-going' option was not given (see Summary of Options), make 
  2082. aborts execution.  If make terminates for any reason (including a signal) with 
  2083. child processes running, it waits for them to finish before actually exiting. 
  2084.  
  2085. When the system is heavily loaded, you will probably want to run fewer jobs 
  2086. than when it is lightly loaded.  You can use the `-l' option to tell make to 
  2087. limit the number of jobs to run at once, based on the load average.  The `-l' 
  2088. or `--max-load' option is followed by a floating-point number.  For example, 
  2089.  
  2090. -l 2.5
  2091.  
  2092. will not let make start more than one job if the load average is above 2.5. 
  2093. The `-l' option with no following number removes the load limit, if one was 
  2094. given with a previous `-l' option. 
  2095.  
  2096. More precisely, when make goes to start up a job, and it already has at least 
  2097. one job running, it checks the current load average; if it is not lower than 
  2098. the limit given with `-l', make waits until the load average goes below that 
  2099. limit, or until all the other jobs finish. 
  2100.  
  2101. By default, there is no load limit. 
  2102.  
  2103.  
  2104. ΓòÉΓòÉΓòÉ 8.4. Errors in Commands ΓòÉΓòÉΓòÉ
  2105.  
  2106. After each shell command returns, make looks at its exit status. If the command 
  2107. completed successfully, the next command line is executed in a new shell; after 
  2108. the last command line is finished, the rule is finished. 
  2109.  
  2110. If there is an error (the exit status is nonzero), make gives up on the current 
  2111. rule, and perhaps on all rules. 
  2112.  
  2113. Sometimes the failure of a certain command does not indicate a problem. For 
  2114. example, you may use the mkdir command to ensure that a directory exists.  If 
  2115. the directory already exists, mkdir will report an error, but you probably want 
  2116. make to continue regardless. 
  2117.  
  2118. To ignore errors in a command line, write a `-' at the beginning of the line's 
  2119. text (after the initial tab).  The `-' is discarded before the command is 
  2120. passed to the shell for execution. 
  2121.  
  2122. For example, 
  2123.  
  2124. clean:
  2125.         -rm -f *.o
  2126.  
  2127. This causes rm to continue even if it is unable to remove a file. 
  2128.  
  2129. When you run make with the `-i' or `--ignore-errors' flag, errors are ignored 
  2130. in all commands of all rules.  A rule in the makefile for the special target 
  2131. .IGNORE has the same effect.  These ways of ignoring errors are obsolete 
  2132. because `-' is more flexible. 
  2133.  
  2134. When errors are to be ignored, because of either a `-' or the `-i' flag, make 
  2135. treats an error return just like success, except that it prints out a message 
  2136. that tells you the status code the command exited with, and says that the error 
  2137. has been ignored. 
  2138.  
  2139. When an error happens that make has not been told to ignore, it implies that 
  2140. the current target cannot be correctly remade, and neither can any other that 
  2141. depends on it either directly or indirectly.  No further commands will be 
  2142. executed for these targets, since their preconditions have not been achieved. 
  2143.  
  2144. Normally make gives up immediately in this circumstance, returning a nonzero 
  2145. status.  However, if the `-k' or `--keep-going' flag is specified, make 
  2146. continues to consider the other dependencies of the pending targets, remaking 
  2147. them if necessary, before it gives up and returns nonzero status. For example, 
  2148. after an error in compiling one object file, `make -k' will continue compiling 
  2149. other object files even though it already knows that linking them will be 
  2150. impossible.  See Summary of Options. 
  2151.  
  2152. The usual behavior assumes that your purpose is to get the specified targets up 
  2153. to date; once make learns that this is impossible, it might as well report the 
  2154. failure immediately.  The `-k' option says that the real purpose is to test as 
  2155. many of the changes made in the program as possible, perhaps to find several 
  2156. independent problems so that you can correct them all before the next attempt 
  2157. to compile.  This is why Emacs' compile command passes the `-k' flag by 
  2158. default. 
  2159.  
  2160.  
  2161. ΓòÉΓòÉΓòÉ 8.5. Interrupting or Killing make ΓòÉΓòÉΓòÉ
  2162.  
  2163. If make gets a fatal signal while a command is executing, it may delete the 
  2164. target file that the command was supposed to update.  This is done if the 
  2165. target file's last-modification time has changed since make first checked it. 
  2166.  
  2167. The purpose of deleting the target is to make sure that it is remade from 
  2168. scratch when make is next run.  Why is this?  Suppose you type Ctrl-c while a 
  2169. compiler is running, and it has begun to write an object file `foo.o'.  The 
  2170. Ctrl-c kills the compiler, resulting in an incomplete file whose 
  2171. last-modification time is newer than the source file `foo.c'.  But make also 
  2172. receives the Ctrl-c signal and deletes this incomplete file.  If make did not 
  2173. do this, the next invocation of make would think that `foo.o' did not require 
  2174. updating---resulting in a strange error message from the linker when it tries 
  2175. to link an object file half of which is missing. 
  2176.  
  2177. You can prevent the deletion of a target file in this way by making the special 
  2178. target .PRECIOUS depend on it.  Before remaking a target, make checks to see 
  2179. whether it appears on the dependencies of .PRECIOUS, and thereby decides 
  2180. whether the target should be deleted if a signal happens.  Some reasons why you 
  2181. might do this are that the target is updated in some atomic fashion, or exists 
  2182. only to record a modification-time (its contents do not matter), or must exist 
  2183. at all times to prevent other sorts of trouble. 
  2184.  
  2185.  
  2186. ΓòÉΓòÉΓòÉ 8.6. Recursive Use of make ΓòÉΓòÉΓòÉ
  2187.  
  2188. Recursive use of make means using make as a command in a makefile.  This 
  2189. technique is useful when you want separate makefiles for various subsystems 
  2190. that compose a larger system.  For example, suppose you have a subdirectory 
  2191. `subdir' which has its own makefile, and you would like the containing 
  2192. directory's makefile to run make on the subdirectory.  You can do it by writing 
  2193. this: 
  2194.  
  2195. subsystem:
  2196.         cd subdir; $(MAKE)
  2197.  
  2198. or, equivalently, this (see Summary of Options): 
  2199.  
  2200. subsystem:
  2201.         $(MAKE) -C subdir
  2202.  
  2203. You can write recursive make commands just by copying this example, but there 
  2204. are many things to know about how they work and why, and about how the sub-make 
  2205. relates to the top-level make. 
  2206.  
  2207.  
  2208. ΓòÉΓòÉΓòÉ 8.6.1. How the MAKE Variable Works ΓòÉΓòÉΓòÉ
  2209.  
  2210. Recursive make commands should always use the variable MAKE, not the explicit 
  2211. command name `make', as shown here: 
  2212.  
  2213. subsystem:
  2214.         cd subdir; $(MAKE)
  2215.  
  2216. The value of this variable is the file name with which make was invoked.  If 
  2217. this file name was `/bin/make', then the command executed is `cd subdir; 
  2218. /bin/make'.  If you use a special version of make to run the top-level 
  2219. makefile, the same special version will be executed for recursive invocations. 
  2220.  
  2221. Also, any arguments that define variable values are added to MAKE, so the 
  2222. sub-make gets them too.  Thus, if you do `make CFLAGS=-O', so that all C 
  2223. compilations will be optimized, the sub-make is run with `cd subdir; /bin/make 
  2224. CFLAGS=-O'. 
  2225.  
  2226. The MAKE variable actually just refers to two other variables which contain 
  2227. these special values.  In fact, MAKE is always defined as `$(MAKE_COMMAND) 
  2228. $(MAKEOVERRIDES)'.  The variable MAKE_COMMAND is the file name with which make 
  2229. was invoked (such as `/bin/make', above).  The variable MAKEOVERRIDES contains 
  2230. definitions for the variables defined on the command line; in the above 
  2231. example, its value is `CFLAGS=-O'.  If you do not want these variable 
  2232. definitions done in all recursive make invocations, you can redefine the 
  2233. MAKEOVERRIDES variable to remove them.  You do this in any of the normal ways 
  2234. for defining variables: in a makefile (see Setting Variables); on the command 
  2235. line with an argument like `MAKEOVERRIDES=' (see Overriding Variables); or with 
  2236. an environment variable (see Variables from the Environment). 
  2237.  
  2238. As a special feature, using the variable MAKE in the commands of a rule alters 
  2239. the effects of the `-t' (`--touch'), `-n' (`--just-print'), or `-q' 
  2240. (`--question') option. Using the MAKE variable has the same effect as using a 
  2241. `+' character at the beginning of the command line. See Instead of Executing 
  2242. the Commands. 
  2243.  
  2244. Consider the command `make -t' in the above example.  (The `-t' option marks 
  2245. targets as up to date without actually running any commands; see Instead of 
  2246. Execution.)  Following the usual definition of `-t', a `make -t' command in the 
  2247. example would create a file named `subsystem' and do nothing else.  What you 
  2248. really want it to do is run `cd subdir; make -t'; but that would require 
  2249. executing the command, and `-t' says not to execute commands. 
  2250.  
  2251. The special feature makes this do what you want: whenever a command line of a 
  2252. rule contains the variable MAKE, the flags `-t', `-n' and `-q' do not apply to 
  2253. that line.  Command lines containing MAKE are executed normally despite the 
  2254. presence of a flag that causes most commands not to be run.  The usual 
  2255. MAKEFLAGS mechanism passes the flags to the sub-make ( see Communicating 
  2256. Options to a Sub-make), so your request to touch the files, or print the 
  2257. commands, is propagated to the subsystem. 
  2258.  
  2259.  
  2260. ΓòÉΓòÉΓòÉ 8.6.2. Communicating Variables to a Sub-make ΓòÉΓòÉΓòÉ
  2261.  
  2262. Variable values of the top-level make can be passed to the sub-make through the 
  2263. environment by explicit request.  These variables are defined in the sub-make 
  2264. as defaults, but do not override what is specified in the sub-make's makefile 
  2265. unless you use the `-e' switch (see Summary of Options). 
  2266.  
  2267. To pass down, or export, a variable, make adds the variable and its value to 
  2268. the environment for running each command.  The sub-make, in turn, uses the 
  2269. environment to initialize its table of variable values. See Variables from the 
  2270. Environment. 
  2271.  
  2272. Except by explicit request, make exports a variable only if it is either 
  2273. defined in the environment initially or set on the command line, and if its 
  2274. name consists only of letters, numbers, and underscores. Some shells cannot 
  2275. cope with environment variable names consisting of characters other than 
  2276. letters, numbers, and underscores. 
  2277.  
  2278. The special variables SHELL and MAKEFLAGS are always exported. MAKEFILES is 
  2279. exported if you set it to anything. 
  2280.  
  2281. Variables are not normally passed down if they were created by default by make 
  2282. ( see Variables Used by Implicit Rules).  The sub-make will define these for 
  2283. itself. 
  2284.  
  2285. If you want to export specific variables to a sub-make, use the export 
  2286. directive, like this: 
  2287.  
  2288. export variable ...
  2289.  
  2290. If you want to prevent a variable from being exported, use the unexport 
  2291. directive, like this: 
  2292.  
  2293. unexport variable ...
  2294.  
  2295. As a convenience, you can define a variable and export it at the same time by 
  2296. doing: 
  2297.  
  2298. export variable = value
  2299.  
  2300. has the same result as: 
  2301.  
  2302. variable = value
  2303. export variable
  2304.  
  2305. and 
  2306.  
  2307. export variable := value
  2308.  
  2309. has the same result as: 
  2310.  
  2311. variable := value
  2312. export variable
  2313.  
  2314. Likewise, 
  2315.  
  2316. export variable += value
  2317.  
  2318. is just like: 
  2319.  
  2320. variable += value
  2321. export variable
  2322.  
  2323. See Appending More Text to Variables. 
  2324.  
  2325. You may notice that the export and unexport directives work in make in the same 
  2326. way they work in the shell, sh. 
  2327.  
  2328. If you want all variables to be exported by default, you can use export by 
  2329. itself: 
  2330.  
  2331. export
  2332.  
  2333. This tells make that variables which are not explicitly mentioned in an export 
  2334. or unexport directive should be exported. Any variable given in an unexport 
  2335. directive will still not be exported.  If you use export by itself to export 
  2336. variables by default, variables whose names contain characters other than 
  2337. alphanumerics and underscores will not be exported unless specifically 
  2338. mentioned in an export directive. 
  2339.  
  2340. The behavior elicited by an export directive by itself was the default in older 
  2341. versions of GNU make.  If your makefiles depend on this behavior and you want 
  2342. to be compatible with old versions of make, you can write a rule for the 
  2343. special target .EXPORT_ALL_VARIABLES instead of using the export directive. 
  2344. This will be ignored by old makes, while the export directive will cause a 
  2345. syntax error. 
  2346.  
  2347. Likewise, you can use unexport by itself to tell make not to export variables 
  2348. by default.  Since this is the default behavior, you would only need to do this 
  2349. if export had been used by itself earlier (in an included makefile, perhaps). 
  2350. You *cannot* use export and unexport by themselves to have variables exported 
  2351. for some commands and not for others.  The last export or unexport directive 
  2352. that appears by itself determines the behavior for the entire run of make. 
  2353.  
  2354. As a special feature, the variable MAKELEVEL is changed when it is passed down 
  2355. from level to level.  This variable's value is a string which is the depth of 
  2356. the level as a decimal number.  The value is `0' for the top-level make; `1' 
  2357. for a sub-make, `2' for a sub-sub-make, and so on.  The incrementation happens 
  2358. when make sets up the environment for a command. 
  2359.  
  2360. The main use of MAKELEVEL is to test it in a conditional directive (see 
  2361. Conditional Parts of Makefiles); this way you can write a makefile that behaves 
  2362. one way if run recursively and another way if run directly by you. 
  2363.  
  2364. You can use the variable MAKEFILES to cause all sub-make commands to use 
  2365. additional makefiles.  The value of MAKEFILES is a whitespace-separated list of 
  2366. file names.  This variable, if defined in the outer-level makefile, is passed 
  2367. down through the environment; then it serves as a list of extra makefiles for 
  2368. the sub-make to read before the usual or specified ones. See The Variable 
  2369. MAKEFILES. 
  2370.  
  2371.  
  2372. ΓòÉΓòÉΓòÉ 8.6.3. Communicating Options to a Sub-make ΓòÉΓòÉΓòÉ
  2373.  
  2374. Flags such as `-s' and `-k' are passed automatically to the sub-make through 
  2375. the variable MAKEFLAGS.  This variable is set up automatically by make to 
  2376. contain the flag letters that make received.  Thus, if you do `make -ks' then 
  2377. MAKEFLAGS gets the value `ks'. 
  2378.  
  2379. As a consequence, every sub-make gets a value for MAKEFLAGS in its environment. 
  2380. In response, it takes the flags from that value and processes them as if they 
  2381. had been given as arguments. See Summary of Options. 
  2382.  
  2383. The options `-C', `-f', `-I', `-o', and `-W' are not put into MAKEFLAGS; these 
  2384. options are not passed down. 
  2385.  
  2386. The `-j' option is a special case (see Parallel Execution).  If you set it to 
  2387. some numeric value, `-j 1' is always put into MAKEFLAGS instead of the value 
  2388. you specified.  This is because if the `-j' option were passed down to 
  2389. sub-makes, you would get many more jobs running in parallel than you asked for. 
  2390. If you give `-j' with no numeric argument, meaning to run as many jobs as 
  2391. possible in parallel, this is passed down, since multiple infinities are no 
  2392. more than one. 
  2393.  
  2394. If you do not want to pass the other flags down, you must change the value of 
  2395. MAKEFLAGS, like this: 
  2396.  
  2397. MAKEFLAGS=
  2398. subsystem:
  2399.         cd subdir; $(MAKE)
  2400.  
  2401. or like this: 
  2402.  
  2403. subsystem:
  2404.         cd subdir; $(MAKE) MAKEFLAGS=
  2405.  
  2406. A similar variable MFLAGS exists also, for historical compatibility. It has the 
  2407. same value as MAKEFLAGS except that a hyphen is added at the beginning if it is 
  2408. not empty.  MFLAGS was traditionally used explicitly in the recursive make 
  2409. command, like this: 
  2410.  
  2411. subsystem:
  2412.         cd subdir; $(MAKE) $(MFLAGS)
  2413.  
  2414. but now MAKEFLAGS makes this usage redundant. 
  2415.  
  2416. The MAKEFLAGS and MFLAGS variables can also be useful if you want to have 
  2417. certain options, such as `-k' (see Summary of Options) set each time you run 
  2418. make.  Just put `MAKEFLAGS=k' or `MFLAGS=-k' in your environment.  These 
  2419. variables may also be set in makefiles, so a makefile can specify additional 
  2420. flags that should also be in effect for that makefile. 
  2421.  
  2422. If you do put MAKEFLAGS or MFLAGS in your environment, you should be sure not 
  2423. to include any options that will drastically affect the actions of make and 
  2424. undermine the purpose of makefiles and of make itself.  For instance, the `-t', 
  2425. `-n', and `-q' options, if put in one of these variables, could have disastrous 
  2426. consequences and would certainly have at least surprising and probably annoying 
  2427. effects. 
  2428.  
  2429.  
  2430. ΓòÉΓòÉΓòÉ 8.6.4. The --print-directory Option ΓòÉΓòÉΓòÉ
  2431.  
  2432. If you use several levels of recursive make invocations, the `-w' or 
  2433. `--print-directory' option can make the output a lot easier to understand by 
  2434. showing each directory as make starts processing it and as make finishes 
  2435. processing it.  For example, if `make -w' is run in the directory 
  2436. `/u/gnu/make', make will print a line of the form: 
  2437.  
  2438. make: Entering directory `/u/gnu/make'.
  2439.  
  2440. before doing anything else, and a line of the form: 
  2441.  
  2442. make: Leaving directory `/u/gnu/make'.
  2443.  
  2444. when processing is completed. 
  2445.  
  2446. Normally, you do not need to specify this option because `make' does it for 
  2447. you: `-w' is turned on automatically when you use the `-C' option, and in 
  2448. sub-makes.  make will not automatically turn on `-w' if you also use `-s', 
  2449. which says to be silent, or if you use `--no-print-directory' to explicitly 
  2450. disable it. 
  2451.  
  2452.  
  2453. ΓòÉΓòÉΓòÉ 8.7. Defining Canned Command Sequences ΓòÉΓòÉΓòÉ
  2454.  
  2455. When the same sequence of commands is useful in making various targets, you can 
  2456. define it as a canned sequence with the define directive, and refer to the 
  2457. canned sequence from the rules for those targets.  The canned sequence is 
  2458. actually a variable, so the name must not conflict with other variable names. 
  2459.  
  2460. Here is an example of defining a canned sequence of commands: 
  2461.  
  2462. define run-yacc
  2463. yacc $(firstword $^)
  2464. mv y.tab.c $@
  2465. endef
  2466.  
  2467. Here run-yacc is the name of the variable being defined; endef marks the end of 
  2468. the definition; the lines in between are the commands.  The define directive 
  2469. does not expand variable references and function calls in the canned sequence; 
  2470. the `$' characters, parentheses, variable names, and so on, all become part of 
  2471. the value of the variable you are defining. See Defining Variables Verbatim, 
  2472. for a complete explanation of define. 
  2473.  
  2474. The first command in this example runs Yacc on the first dependency of 
  2475. whichever rule uses the canned sequence.  The output file from Yacc is always 
  2476. named `y.tab.c'.  The second command moves the output to the rule's target file 
  2477. name. 
  2478.  
  2479. To use the canned sequence, substitute the variable into the commands of a 
  2480. rule.  You can substitute it like any other variable (see Basics of Variable 
  2481. References). Because variables defined by define are recursively expanded 
  2482. variables, all the variable references you wrote inside the define are expanded 
  2483. now.  For example: 
  2484.  
  2485. foo.c : foo.y
  2486.         $(run-yacc)
  2487.  
  2488. `foo.y' will be substituted for the variable `$^' when it occurs in run-yacc's 
  2489. value, and `foo.c' for `$@'. 
  2490.  
  2491. This is a realistic example, but this particular one is not needed in practice 
  2492. because make has an implicit rule to figure out these commands based on the 
  2493. file names involved (see Using Implicit Rules). 
  2494.  
  2495. In command execution, each line of a canned sequence is treated just as if the 
  2496. line appeared on its own in the rule, preceded by a tab.  In particular, make 
  2497. invokes a separate subshell for each line.  You can use the special prefix 
  2498. characters that affect command lines (`@', `-', and `+') on each line of a 
  2499. canned sequence. See Writing the Commands in Rules. For example, using this 
  2500. canned sequence: 
  2501.  
  2502. define frobnicate
  2503. @echo "frobnicating target $@"
  2504. frob-step-1 $< -o $@-step-1
  2505. frob-step-2 $@-step-1 -o $@
  2506. endef
  2507.  
  2508. make will not echo the first line, the echo command. But it will echo the 
  2509. following two command lines. 
  2510.  
  2511. On the other hand, prefix characters on the command line that refers to a 
  2512. canned sequence apply to every line in the sequence.  So the rule: 
  2513.  
  2514. frob.out: frob.in
  2515.         @$(frobnicate)
  2516.  
  2517. does not echo any commands. (See Command Echoing, for a full explanation of 
  2518. `@'.) 
  2519.  
  2520.  
  2521. ΓòÉΓòÉΓòÉ 8.8. Using Empty Commands ΓòÉΓòÉΓòÉ
  2522.  
  2523. It is sometimes useful to define commands which do nothing.  This is done 
  2524. simply by giving a command that consists of nothing but whitespace.  For 
  2525. example: 
  2526.  
  2527. target: ;
  2528.  
  2529. defines an empty command string for `target'.  You could also use a line 
  2530. beginning with a tab character to define an empty command string, but this 
  2531. would be confusing because such a line looks empty. 
  2532.  
  2533. You may be wondering why you would want to define a command string that does 
  2534. nothing.  The only reason this is useful is to prevent a target from getting 
  2535. implicit commands (from implicit rules or the .DEFAULT special target; see 
  2536. Implicit Rules and see Defining Last-Resort Default Rules). 
  2537.  
  2538. You may be inclined to define empty command strings for targets that are not 
  2539. actual files, but only exist so that their dependencies can be remade. 
  2540. However, this is not the best way to do that, because the dependencies may not 
  2541. be remade properly if the target file actually does exist. See Phony Targets, 
  2542. for a better way to do this. 
  2543.  
  2544.  
  2545. ΓòÉΓòÉΓòÉ 9. How to Use Variables ΓòÉΓòÉΓòÉ
  2546.  
  2547. A variable is a name defined in a makefile to represent a string of text, 
  2548. called the variable's value.  These values are substituted by explicit request 
  2549. into targets, dependencies, commands, and other parts of the makefile.  (In 
  2550. some other versions of make, variables are called macros.) 
  2551.  
  2552. Variables and functions in all parts of a makefile are expanded when read, 
  2553. except for the shell commands in rules, the right-hand sides of variable 
  2554. definitions using `=', and the bodies of variable definitions using the define 
  2555. directive. 
  2556.  
  2557. Variables can represent lists of file names, options to pass to compilers, 
  2558. programs to run, directories to look in for source files, directories to write 
  2559. output in, or anything else you can imagine. 
  2560.  
  2561. A variable name may be any sequence of characters not containing `:', `#', `=', 
  2562. or leading or trailing whitespace.  However, variable names containing 
  2563. characters other than letters, numbers, and underscores should be avoided, as 
  2564. they may be given special meanings in the future, and with some shells they 
  2565. cannot be passed through the environment to a sub-make (see Communicating 
  2566. Variables to a Sub-make). 
  2567.  
  2568. It is traditional to use upper case letters in variable names, but we recommend 
  2569. using lower case letters for variable names that serve internal purposes in the 
  2570. makefile, and reserving upper case for parameters that control implicit rules 
  2571. or for parameters that the user should override with command options (see 
  2572. Overriding Variables). 
  2573.  
  2574.  
  2575. ΓòÉΓòÉΓòÉ 9.1. Basics of Variable References ΓòÉΓòÉΓòÉ
  2576.  
  2577. To substitute a variable's value, write a dollar sign followed by the name of 
  2578. the variable in parentheses or braces: either `$(foo)' or `${foo}' is a valid 
  2579. reference to the variable foo.  This special significance of `$' is why you 
  2580. must write `$$' to have the effect of a single dollar sign in a file name or 
  2581. command. 
  2582.  
  2583. Variable references can be used in any context: targets, dependencies, 
  2584. commands, most directives, and new variable values.  Here is an example of a 
  2585. common case, where a variable holds the names of all the object files in a 
  2586. program: 
  2587.  
  2588. objects = program.o foo.o utils.o
  2589. program : $(objects)
  2590.         cc -o program $(objects)
  2591.  
  2592. $(objects) : defs.h
  2593.  
  2594. Variable references work by strict textual substitution.  Thus, the rule 
  2595.  
  2596. foo = c
  2597. prog.o : prog.$(foo)
  2598.         $(foo)$(foo) -$(foo) prog.$(foo)
  2599.  
  2600. could be used to compile a C program `prog.c'.  Since spaces before the 
  2601. variable value are ignored in variable assignments, the value of foo is 
  2602. precisely `c'.  (Don't actually write your makefiles this way!) 
  2603.  
  2604. A dollar sign followed by a character other than a dollar sign, 
  2605. open-parenthesis or open-brace treats that single character as the variable 
  2606. name.  Thus, you could reference the variable x with `$x'.  However, this 
  2607. practice is strongly discouraged, except in the case of the automatic variables 
  2608. (see Automatic Variables). 
  2609.  
  2610.  
  2611. ΓòÉΓòÉΓòÉ 9.2. The Two Flavors of Variables ΓòÉΓòÉΓòÉ
  2612.  
  2613. There are two ways that a variable in GNU make can have a value; we call them 
  2614. the two flavors of variables.  The two flavors are distinguished in how they 
  2615. are defined and in what they do when expanded. 
  2616.  
  2617. The first flavor of variable is a recursively expanded variable. Variables of 
  2618. this sort are defined by lines using `=' (see Setting Variables) or by the 
  2619. define directive (see Defining Variables Verbatim).  The value you specify is 
  2620. installed verbatim; if it contains references to other variables, these 
  2621. references are expanded whenever this variable is substituted (in the course of 
  2622. expanding some other string).  When this happens, it is called recursive 
  2623. expansion. 
  2624.  
  2625. For example, 
  2626.  
  2627. foo = $(bar)
  2628. bar = $(ugh)
  2629. ugh = Huh?
  2630.  
  2631. all:;echo $(foo)
  2632.  
  2633. will echo `Huh?': `$(foo)' expands to `$(bar)' which expands to `$(ugh)' which 
  2634. finally expands to `Huh?'. 
  2635.  
  2636. This flavor of variable is the only sort supported by other versions of make. 
  2637. It has its advantages and its disadvantages.  An advantage (most would say) is 
  2638. that: 
  2639.  
  2640. CFLAGS = $(include_dirs) -O
  2641. include_dirs = -Ifoo -Ibar
  2642.  
  2643. will do what was intended: when `CFLAGS' is expanded in a command, it will 
  2644. expand to `-Ifoo -Ibar -O'.  A major disadvantage is that you cannot append 
  2645. something on the end of a variable, as in 
  2646.  
  2647. CFLAGS = $(CFLAGS) -O
  2648.  
  2649. because it will cause an infinite loop in the variable expansion. (Actually 
  2650. make detects the infinite loop and reports an error.) 
  2651.  
  2652. Another disadvantage is that any functions (see Functions for Transforming 
  2653. Text) referenced in the definition will be executed every time the variable is 
  2654. expanded.  This makes make run slower; worse, it causes the wildcard and shell 
  2655. functions to give unpredictable results because you cannot easily control when 
  2656. they are called, or even how many times. 
  2657.  
  2658. To avoid all the problems and inconveniences of recursively expanded variables, 
  2659. there is another flavor: simply expanded variables. 
  2660.  
  2661. Simply expanded variables are defined by lines using `:=' (see Setting 
  2662. Variables). The value of a simply expanded variable is scanned once and for 
  2663. all, expanding any references to other variables and functions, when the 
  2664. variable is defined.  The actual value of the simply expanded variable is the 
  2665. result of expanding the text that you write. It does not contain any references 
  2666. to other variables; it contains their values as of the time this variable was 
  2667. defined.  Therefore, 
  2668.  
  2669. x := foo
  2670. y := $(x) bar
  2671. x := later
  2672.  
  2673. is equivalent to 
  2674.  
  2675. y := foo bar
  2676. x := later
  2677.  
  2678. When a simply expanded variable is referenced, its value is substituted 
  2679. verbatim. 
  2680.  
  2681. Here is a somewhat more complicated example, illustrating the use of `:=' in 
  2682. conjunction with the shell function. (See The shell Function.)  This example 
  2683. also shows use of the variable MAKELEVEL, which is changed when it is passed 
  2684. down from level to level. ( See Communicating Variables to a Sub-make, for 
  2685. information about MAKELEVEL.) 
  2686.  
  2687. ifeq (0,${MAKELEVEL})
  2688. cur-dir   := $(shell pwd)
  2689. whoami    := $(shell whoami)
  2690. host-type := $(shell arch)
  2691. MAKE := ${MAKE} host-type=${host-type} whoami=${whoami}
  2692. endif
  2693.  
  2694. An advantage of this use of `:=' is that a typical `descend into a directory' 
  2695. command then looks like this: 
  2696.  
  2697. ${subdirs}:
  2698.       ${MAKE} cur-dir=${cur-dir}/$@ -C $@ all
  2699.  
  2700. Simply expanded variables generally make complicated makefile programming more 
  2701. predictable because they work like variables in most programming languages. 
  2702. They allow you to redefine a variable using its own value (or its value 
  2703. processed in some way by one of the expansion functions) and to use the 
  2704. expansion functions much more efficiently (see Functions for Transforming 
  2705. Text). 
  2706.  
  2707. You can also use them to introduce controlled leading or trailing spaces into 
  2708. variable values.  Such spaces are discarded from your input before substitution 
  2709. of variable references and function calls; this means you can include leading 
  2710. or trailing spaces in a variable value by protecting them with variable 
  2711. references, like this: 
  2712.  
  2713. nullstring :=
  2714. space := $(nullstring) $(nullstring)
  2715.  
  2716. Here the value of the variable space is precisely one space. 
  2717.  
  2718.  
  2719. ΓòÉΓòÉΓòÉ 9.3. Advanced Features for Reference to Variables ΓòÉΓòÉΓòÉ
  2720.  
  2721. This section describes some advanced features you can use to reference 
  2722. variables in more flexible ways. 
  2723.  
  2724.  
  2725. ΓòÉΓòÉΓòÉ 9.3.1. Substitution References ΓòÉΓòÉΓòÉ
  2726.  
  2727. A substitution reference substitutes the value of a variable with alterations 
  2728. that you specify.  It has the form `$(var:a=b)' (or `${var:a=b}') and its 
  2729. meaning is to take the value of the variable var, replace every a at the end of 
  2730. a word with b in that value, and substitute the resulting string. 
  2731.  
  2732. When we say ``at the end of a word'', we mean that a must appear either 
  2733. followed by whitespace or at the end of the value in order to be replaced; 
  2734. other occurrences of a in the value are unaltered.  For example: 
  2735.  
  2736. foo := a.o b.o c.o
  2737. bar := $(foo:.o=.c)
  2738.  
  2739. sets `bar' to `a.c b.c c.c'.  See Setting Variables. 
  2740.  
  2741. A substitution reference is actually an abbreviation for use of the patsubst 
  2742. expansion function (see Functions for String Substitution and Analysis).  We 
  2743. provide substitution references as well as patsubst for compatibility with 
  2744. other implementations of make. 
  2745.  
  2746. Another type of substitution reference lets you use the full power of the 
  2747. patsubst function.  It has the same form `$(var:a=b)' described above, except 
  2748. that now a must contain a single `%' character.  This case is equivalent to 
  2749. `$(patsubst a,b,$(var))'. See Functions for String Substitution and Analysis, 
  2750. for a description of the patsubst function. 
  2751.  
  2752. For example:
  2753.  
  2754. foo := a.o b.o c.o
  2755. bar := $(foo:%.o=%.c)
  2756.  
  2757. sets `bar' to `a.c b.c c.c'. 
  2758.  
  2759.  
  2760. ΓòÉΓòÉΓòÉ 9.3.2. Computed Variable Names ΓòÉΓòÉΓòÉ
  2761.  
  2762. Computed variable names are a complicated concept needed only for sophisticated 
  2763. makefile programming.  For most purposes you need not consider them, except to 
  2764. know that making a variable with a dollar sign in its name might have strange 
  2765. results.  However, if you are the type that wants to understand everything, or 
  2766. you are actually interested in what they do, read on. 
  2767.  
  2768. Variables may be referenced inside the name of a variable.  This is called a 
  2769. computed variable name or a nested variable reference.  For example, 
  2770.  
  2771. x = y
  2772. y = z
  2773. a := $($(x))
  2774.  
  2775. defines a as `z': the `$(x)' inside `$($(x))' expands to `y', so `$($(x))' 
  2776. expands to `$(y)' which in turn expands to `z'.  Here the name of the variable 
  2777. to reference is not stated explicitly; it is computed by expansion of `$(x)'. 
  2778. The reference `$(x)' here is nested within the outer variable reference. 
  2779.  
  2780. The previous example shows two levels of nesting, but any number of levels is 
  2781. possible.  For example, here are three levels: 
  2782.  
  2783. x = y
  2784. y = z
  2785. z = u
  2786. a := $($($(x)))
  2787.  
  2788. Here the innermost `$(x)' expands to `y', so `$($(x))' expands to `$(y)' which 
  2789. in turn expands to `z'; now we have `$(z)', which becomes `u'. 
  2790.  
  2791. References to recursively-expanded variables within a variable name are 
  2792. reexpanded in the usual fashion.  For example: 
  2793.  
  2794. x = $(y)
  2795. y = z
  2796. z = Hello
  2797. a := $($(x))
  2798.  
  2799. defines a as `Hello': `$($(x))' becomes `$($(y))' which becomes `$(z)' which 
  2800. becomes `Hello'. 
  2801.  
  2802. Nested variable references can also contain modified references and function 
  2803. invocations (see Functions for Transforming Text), just like any other 
  2804. reference. For example, using the subst function (see Functions for String 
  2805. Substitution and Analysis): 
  2806.  
  2807. x = variable1
  2808. variable2 := Hello
  2809. y = $(subst 1,2,$(x))
  2810. z = y
  2811. a := $($($(z)))
  2812.  
  2813. eventually defines a as `Hello'.  It is doubtful that anyone would ever want to 
  2814. write a nested reference as convoluted as this one, but it works: `$($($(z)))' 
  2815. expands to `$($(y))' which becomes `$($(subst 1,2,$(x)))'.  This gets the value 
  2816. `variable1' from x and changes it by substitution to `variable2', so that the 
  2817. entire string becomes `$(variable2)', a simple variable reference whose value 
  2818. is `Hello'. 
  2819.  
  2820. A computed variable name need not consist entirely of a single variable 
  2821. reference.  It can contain several variable references, as well as some 
  2822. invariant text.  For example, 
  2823.  
  2824. a_dirs := dira dirb
  2825. 1_dirs := dir1 dir2
  2826.  
  2827. a_files := filea fileb
  2828. 1_files := file1 file2
  2829.  
  2830. ifeq "$(use_a)" "yes"
  2831. a1 := a
  2832. else
  2833. a1 := 1
  2834. endif
  2835.  
  2836. ifeq "$(use_dirs)" "yes"
  2837. df := dirs
  2838. else
  2839. df := files
  2840. endif
  2841.  
  2842. dirs := $($(a1)_$(df))
  2843.  
  2844. will give dirs the same value as a_dirs, 1_dirs, a_files or 1_files depending 
  2845. on the settings of use_a and use_dirs. 
  2846.  
  2847. Computed variable names can also be used in substitution references: 
  2848.  
  2849. a_objects := a.o b.o c.o
  2850. 1_objects := 1.o 2.o 3.o
  2851.  
  2852. sources := $($(a1)_objects:.o=.c)
  2853.  
  2854. defines sources as either `a.c b.c c.c' or `1.c 2.c 3.c', depending on the 
  2855. value of a1. 
  2856.  
  2857. The only restriction on this sort of use of nested variable references is that 
  2858. they cannot specify part of the name of a function to be called. This is 
  2859. because the test for a recognized function name is done before the expansion of 
  2860. nested references.  For example, 
  2861.  
  2862. ifdef do_sort
  2863. func := sort
  2864. else
  2865. func := strip
  2866. endif
  2867.  
  2868. bar := a d b g q c
  2869.  
  2870. foo := $($(func) $(bar))
  2871.  
  2872. attempts to give `foo' the value of the variable `sort a d b g q c' or `strip a 
  2873. d b g q c', rather than giving `a d b g q c' as the argument to either the sort 
  2874. or the strip function. This restriction could be removed in the future if that 
  2875. change is shown to be a good idea. 
  2876.  
  2877. You can also use computed variable names in the left-hand side of a variable 
  2878. assignment, or in a define directive, as in: 
  2879.  
  2880. dir = foo
  2881. $(dir)_sources := $(wildcard $(dir)/*.c)
  2882. define $(dir)_print
  2883. lpr $($(dir)_sources)
  2884. endef
  2885.  
  2886. This example defines the variables `dir', `foo_sources', and `foo_print'. 
  2887.  
  2888. Note that nested variable references are quite different from recursively 
  2889. expanded variables (see The Two Flavors of Variables), though both are used 
  2890. together in complex ways when doing makefile programming. 
  2891.  
  2892.  
  2893. ΓòÉΓòÉΓòÉ 9.4. How Variables Get Their Values ΓòÉΓòÉΓòÉ
  2894.  
  2895. Variables can get values in several different ways: 
  2896.  
  2897. o You can specify an overriding value when you run make. See Overriding 
  2898.   Variables. 
  2899.  
  2900. o You can specify a value in the makefile, either with an assignment (see 
  2901.   Setting Variables) or with a verbatim definition (see Defining Variables 
  2902.   Verbatim). 
  2903.  
  2904. o Variables in the environment become make variables. See Variables from the 
  2905.   Environment. 
  2906.  
  2907. o Several automatic variables are given new values for each rule. Each of these 
  2908.   has a single conventional use. See Automatic Variables. 
  2909.  
  2910. o Several variables have constant initial values. See Variables Used by 
  2911.   Implicit Rules. 
  2912.  
  2913.  
  2914. ΓòÉΓòÉΓòÉ 9.5. Setting Variables ΓòÉΓòÉΓòÉ
  2915.  
  2916. To set a variable from the makefile, write a line starting with the variable 
  2917. name followed by `=' or `:='.  Whatever follows the `=' or `:=' on the line 
  2918. becomes the value.  For example, 
  2919.  
  2920. objects = main.o foo.o bar.o utils.o
  2921.  
  2922. defines a variable named objects.  Whitespace around the variable name and 
  2923. immediately after the `=' is ignored. 
  2924.  
  2925. Variables defined with `=' are recursively expanded variables. Variables 
  2926. defined with `:=' are simply expanded variables; these definitions can contain 
  2927. variable references which will be expanded before the definition is made.  See 
  2928. The Two Flavors of Variables. 
  2929.  
  2930. The variable name may contain function and variable references, which are 
  2931. expanded when the line is read to find the actual variable name to use. 
  2932.  
  2933. There is no limit on the length of the value of a variable except the amount of 
  2934. swapping space on the computer.  When a variable definition is long, it is a 
  2935. good idea to break it into several lines by inserting backslash-newline at 
  2936. convenient places in the definition.  This will not affect the functioning of 
  2937. make, but it will make the makefile easier to read. 
  2938.  
  2939. Most variable names are considered to have the empty string as a value if you 
  2940. have never set them.  Several variables have built-in initial values that are 
  2941. not empty, but you can set them in the usual ways (see Variables Used by 
  2942. Implicit Rules). Several special variables are set automatically to a new value 
  2943. for each rule; these are called the automatic variables (see Automatic 
  2944. Variables). 
  2945.  
  2946.  
  2947. ΓòÉΓòÉΓòÉ 9.6. Appending More Text to Variables ΓòÉΓòÉΓòÉ
  2948.  
  2949. Often it is useful to add more text to the value of a variable already defined. 
  2950. You do this with a line containing `+=', like this: 
  2951.  
  2952. objects += another.o
  2953.  
  2954. This takes the value of the variable objects, and adds the text `another.o' to 
  2955. it (preceded by a single space).  Thus: 
  2956.  
  2957. objects = main.o foo.o bar.o utils.o
  2958. objects += another.o
  2959.  
  2960. sets objects to `main.o foo.o bar.o utils.o another.o'. 
  2961.  
  2962. Using `+=' is similar to: 
  2963.  
  2964. objects = main.o foo.o bar.o utils.o
  2965. objects := $(objects) another.o
  2966.  
  2967. but differs in ways that become important when you use more complex values. 
  2968.  
  2969. When the variable in question has not been defined before, `+=' acts just like 
  2970. normal `=': it defines a recursively-expanded variable.  However, when there is 
  2971. a previous definition, exactly what `+=' does depends on what flavor of 
  2972. variable you defined originally.  See The Two Flavors of Variables, for an 
  2973. explanation of the two flavors of variables. 
  2974.  
  2975. When you add to a variable's value with `+=', make acts essentially as if you 
  2976. had included the extra text in the initial definition of the variable.  If you 
  2977. defined it first with `:=', making it a simply-expanded variable, `+=' adds to 
  2978. that simply-expanded definition, and expands the new text before appending it 
  2979. to the old value just as `:=' does (see Setting Variables, for a full 
  2980. explanation of `:='). In fact, 
  2981.  
  2982. variable := value
  2983. variable += more
  2984.  
  2985. is exactly equivalent to: 
  2986.  
  2987. variable := value
  2988. variable := $(variable) more
  2989.  
  2990. On the other hand, when you use `+=' with a variable that you defined first to 
  2991. be recursively-expanded using plain `=', make does something a bit different. 
  2992. Recall that when you define a recursively-expanded variable, make does not 
  2993. expand the value you set for variable and function references immediately. 
  2994. Instead it stores the text verbatim, and saves these variable and function 
  2995. references to be expanded later, when you refer to the new variable ( see The 
  2996. Two Flavors of Variables).  When you use `+=' on a recursively-expanded 
  2997. variable, it is this unexpanded text to which make appends the new text you 
  2998. specify. 
  2999.  
  3000. variable = value
  3001. variable += more
  3002.  
  3003. is roughly equivalent to: 
  3004.  
  3005. temp = value
  3006. variable = $(temp) more
  3007.  
  3008. except that of course it never defines a variable called temp. The importance 
  3009. of this comes when the variable's old value contains variable references.  Take 
  3010. this common example: 
  3011.  
  3012. CFLAGS = $(includes) -O
  3013. ...
  3014. CFLAGS += -pg # enable profiling
  3015.  
  3016. The first line defines the CFLAGS variable with a reference to another 
  3017. variable, includes.  (CFLAGS is used by the rules for C compilation; see 
  3018. Catalogue of Implicit Rules.) Using `=' for the definition makes CFLAGS a 
  3019. recursively-expanded variable, meaning `$(includes) -O' is not expanded when 
  3020. make processes the definition of CFLAGS.  Thus, includes need not be defined 
  3021. yet for its value to take effect.  It only has to be defined before any 
  3022. reference to CFLAGS.  If we tried to append to the value of CFLAGS without 
  3023. using `+=', we might do it like this: 
  3024.  
  3025. CFLAGS := $(CFLAGS) -pg # enable profiling
  3026.  
  3027. This is close, but not quite what we want.  Using `:=' redefines CFLAGS as a 
  3028. simply-expanded variable; this means make expands the text `$(CFLAGS) -pg' 
  3029. before setting the variable.  If includes is not yet defined, we get `-O -pg', 
  3030. and a later definition of includes will have no effect.  Conversely, by using 
  3031. `+=' we set CFLAGS to the unexpanded value `$(includes) -O -pg'.  Thus we 
  3032. preserve the reference to includes, so if that variable gets defined at any 
  3033. later point, a reference like `$(CFLAGS)' still uses its value. 
  3034.  
  3035.  
  3036. ΓòÉΓòÉΓòÉ 9.7. The override Directive ΓòÉΓòÉΓòÉ
  3037.  
  3038. If a variable has been set with a command argument (see Overriding Variables), 
  3039. then ordinary assignments in the makefile are ignored.  If you want to set the 
  3040. variable in the makefile even though it was set with a command argument, you 
  3041. can use an override directive, which is a line that looks like this: 
  3042.  
  3043. override variable = value
  3044.  
  3045. or 
  3046.  
  3047. override variable := value
  3048.  
  3049. To append more text to a variable defined on the command line, use: 
  3050.  
  3051. override variable += more text
  3052.  
  3053. See Appending More Text to Variables. 
  3054.  
  3055. The override directive was not invented for escalation in the war between 
  3056. makefiles and command arguments.  It was invented so you can alter and add to 
  3057. values that the user specifies with command arguments. 
  3058.  
  3059. For example, suppose you always want the `-g' switch when you run the C 
  3060. compiler, but you would like to allow the user to specify the other switches 
  3061. with a command argument just as usual.  You could use this override directive: 
  3062.  
  3063. override CFLAGS += -g
  3064.  
  3065. You can also use override directives with define directives. This is done as 
  3066. you might expect: 
  3067.  
  3068. override define foo
  3069. bar
  3070. endef
  3071.  
  3072. See Defining Variables Verbatim. 
  3073.  
  3074.  
  3075. ΓòÉΓòÉΓòÉ 9.8. Defining Variables Verbatim ΓòÉΓòÉΓòÉ
  3076.  
  3077. Another way to set the value of a variable is to use the define directive. 
  3078. This directive has an unusual syntax which allows newline characters to be 
  3079. included in the value, which is convenient for defining canned sequences of 
  3080. commands (see Defining Canned Command Sequences). 
  3081.  
  3082. The define directive is followed on the same line by the name of the variable 
  3083. and nothing more.  The value to give the variable appears on the following 
  3084. lines.  The end of the value is marked by a line containing just the word 
  3085. endef.  Aside from this difference in syntax, define works just like `=': it 
  3086. creates a recursively-expanded variable (see The Two Flavors of Variables). The 
  3087. variable name may contain function and variable references, which are expanded 
  3088. when the directive is read to find the actual variable name to use. 
  3089.  
  3090. define two-lines
  3091. echo foo
  3092. echo $(bar)
  3093. endef
  3094.  
  3095. The value in an ordinary assignment cannot contain a newline; but the newlines 
  3096. that separate the lines of the value in a define become part of the variable's 
  3097. value (except for the final newline which precedes the endef and is not 
  3098. considered part of the value). 
  3099.  
  3100. The previous example is functionally equivalent to this: 
  3101.  
  3102. two-lines = echo foo; echo $(bar)
  3103.  
  3104. since two commands separated by semicolon behave much like two separate shell 
  3105. commands.  However, note that using two separate lines means make will invoke 
  3106. the shell twice, running an independent subshell for each line.  See Command 
  3107. Execution. 
  3108.  
  3109. If you want variable definitions made with define to take precedence over 
  3110. command-line variable definitions, you can use the override directive together 
  3111. with define: 
  3112.  
  3113. override define two-lines
  3114. foo
  3115. $(bar)
  3116. endef
  3117.  
  3118. See The override Directive. 
  3119.  
  3120.  
  3121. ΓòÉΓòÉΓòÉ 9.9. Variables from the Environment ΓòÉΓòÉΓòÉ
  3122.  
  3123. Variables in make can come from the environment in which make is run.  Every 
  3124. environment variable that make sees when it starts up is transformed into a 
  3125. make variable with the same name and value.  But an explicit assignment in the 
  3126. makefile, or with a command argument, overrides the environment.  (If the `-e' 
  3127. flag is specified, then values from the environment override assignments in the 
  3128. makefile. See Summary of Options. But this is not recommended practice.) 
  3129.  
  3130. Thus, by setting the variable CFLAGS in your environment, you can cause all C 
  3131. compilations in most makefiles to use the compiler switches you prefer.  This 
  3132. is safe for variables with standard or conventional meanings because you know 
  3133. that no makefile will use them for other things.  (But this is not totally 
  3134. reliable; some makefiles set CFLAGS explicitly and therefore are not affected 
  3135. by the value in the environment.) 
  3136.  
  3137. When make is invoked recursively, variables defined in the outer invocation can 
  3138. be passed to inner invocations through the environment (see Recursive Use of 
  3139. make).  By default, only variables that came from the environment or the 
  3140. command line are passed to recursive invocations.  You can use the export 
  3141. directive to pass other variables. See Communicating Variables to a Sub-make, 
  3142. for full details. 
  3143.  
  3144. Other use of variables from the environment is not recommended.  It is not wise 
  3145. for makefiles to depend for their functioning on environment variables set up 
  3146. outside their control, since this would cause different users to get different 
  3147. results from the same makefile.  This is against the whole purpose of most 
  3148. makefiles. 
  3149.  
  3150. Such problems would be especially likely with the variable SHELL, which is 
  3151. normally present in the environment to specify the user's choice of interactive 
  3152. shell.  It would be very undesirable for this choice to affect make.  So make 
  3153. ignores the environment value of SHELL. 
  3154.  
  3155.  
  3156. ΓòÉΓòÉΓòÉ 10. Conditional Parts of Makefiles ΓòÉΓòÉΓòÉ
  3157.  
  3158. A conditional causes part of a makefile to be obeyed or ignored depending on 
  3159. the values of variables.  Conditionals can compare the value of one variable to 
  3160. another, or the value of a variable to a constant string.  Conditionals control 
  3161. what make actually ``sees'' in the makefile, so they cannot be used to control 
  3162. shell commands at the time of execution. 
  3163.  
  3164.  
  3165. ΓòÉΓòÉΓòÉ 10.1. Example of a Conditional ΓòÉΓòÉΓòÉ
  3166.  
  3167. The following example of a conditional tells make to use one set of libraries 
  3168. if the CC variable is `gcc', and a different set of libraries otherwise.  It 
  3169. works by controlling which of two command lines will be used as the command for 
  3170. a rule.  The result is that `CC=gcc' as an argument to make changes not only 
  3171. which compiler is used but also which libraries are linked. 
  3172.  
  3173. libs_for_gcc = -lgnu
  3174. normal_libs =
  3175.  
  3176. foo: $(objects)
  3177. ifeq ($(CC),gcc)
  3178.         $(CC) -o foo $(objects) $(libs_for_gcc)
  3179. else
  3180.         $(CC) -o foo $(objects) $(normal_libs)
  3181. endif
  3182.  
  3183. This conditional uses three directives: one ifeq, one else and one endif. 
  3184.  
  3185. The ifeq directive begins the conditional, and specifies the condition.  It 
  3186. contains two arguments, separated by a comma and surrounded by parentheses. 
  3187. Variable substitution is performed on both arguments and then they are 
  3188. compared.  The lines of the makefile following the ifeq are obeyed if the two 
  3189. arguments match; otherwise they are ignored. 
  3190.  
  3191. The else directive causes the following lines to be obeyed if the previous 
  3192. conditional failed.  In the example above, this means that the second 
  3193. alternative linking command is used whenever the first alternative is not used. 
  3194. It is optional to have an else in a conditional. 
  3195.  
  3196. The endif directive ends the conditional.  Every conditional must end with an 
  3197. endif.  Unconditional makefile text follows. 
  3198.  
  3199. As this example illustrates, conditionals work at the textual level: the lines 
  3200. of the conditional are treated as part of the makefile, or ignored, according 
  3201. to the condition.  This is why the larger syntactic units of the makefile, such 
  3202. as rules, may cross the beginning or the end of the conditional. 
  3203.  
  3204. When the variable CC has the value `gcc', the above example has this effect: 
  3205.  
  3206. foo: $(objects)
  3207.         $(CC) -o foo $(objects) $(libs_for_gcc)
  3208.  
  3209. When the variable CC has any other value, the effect is this: 
  3210.  
  3211. foo: $(objects)
  3212.         $(CC) -o foo $(objects) $(normal_libs)
  3213.  
  3214. Equivalent results can be obtained in another way by conditionalizing a 
  3215. variable assignment and then using the variable unconditionally: 
  3216.  
  3217. libs_for_gcc = -lgnu
  3218. normal_libs =
  3219.  
  3220. ifeq ($(CC),gcc)
  3221.   libs=$(libs_for_gcc)
  3222. else
  3223.   libs=$(normal_libs)
  3224. endif
  3225.  
  3226. foo: $(objects)
  3227.         $(CC) -o foo $(objects) $(libs)
  3228.  
  3229.  
  3230. ΓòÉΓòÉΓòÉ 10.2. Syntax of Conditionals ΓòÉΓòÉΓòÉ
  3231.  
  3232. The syntax of a simple conditional with no else is as follows: 
  3233.  
  3234. conditional-directive
  3235. text-if-true
  3236. endif
  3237.  
  3238. The text-if-true may be any lines of text, to be considered as part of the 
  3239. makefile if the condition is true.  If the condition is false, no text is used 
  3240. instead. 
  3241.  
  3242. The syntax of a complex conditional is as follows: 
  3243.  
  3244. conditional-directive
  3245. text-if-true
  3246. else
  3247. text-if-false
  3248. endif
  3249.  
  3250. If the condition is true, text-if-true is used; otherwise, text-if-false is 
  3251. used instead.  The text-if-false can be any number of lines of text. 
  3252.  
  3253. The syntax of the conditional-directive is the same whether the conditional is 
  3254. simple or complex.  There are four different directives that test different 
  3255. conditions.  Here is a table of them: 
  3256.  
  3257. ifeq (arg1, arg2) 
  3258. ifeq 'arg1' 'arg2' 
  3259. ifeq "arg1" "arg2" 
  3260. ifeq "arg1" 'arg2' 
  3261. ifeq 'arg1' "arg2" 
  3262.           Expand all variable references in arg1 and arg2 and compare them.  If 
  3263.           they are identical, the text-if-true is effective; otherwise, the 
  3264.           text-if-false, if any, is effective. 
  3265.  
  3266.           Often you want to test if a variable has a non-empty value.  When the 
  3267.           value results from complex expansions of variables and functions, 
  3268.           expansions you would consider empty may actually contain whitespace 
  3269.           characters and thus are not seen as empty.  However, you can use the 
  3270.           strip function (see Text Functions) to avoid interpreting whitespace 
  3271.           as a non-empty value.  For example: 
  3272.  
  3273.                     ifeq ($(strip $(foo)),)
  3274.                     text-if-empty
  3275.                     endif
  3276.  
  3277.           will evaluate text-if-empty even if the expansion of $(foo) contains 
  3278.           whitespace characters. 
  3279.  
  3280. ifneq (arg1, arg2) 
  3281. ifneq 'arg1' 'arg2' 
  3282. ifneq "arg1" "arg2" 
  3283. ifneq "arg1" 'arg2' 
  3284. ifneq 'arg1' "arg2" 
  3285.           Expand all variable references in arg1 and arg2 and compare them.  If 
  3286.           they are different, the text-if-true is effective; otherwise, the 
  3287.           text-if-false, if any, is effective. 
  3288.  
  3289. ifdef variable-name 
  3290.           If the variable variable-name has a non-empty value, the text-if-true 
  3291.           is effective; otherwise, the text-if-false, if any, is effective. 
  3292.           Variables that have never been defined have an empty value. 
  3293.  
  3294.           Note that ifdef only tests whether a variable has a value.  It does 
  3295.           not expand the variable to see if that value is nonempty. 
  3296.           Consequently, tests using ifdef return true for all definitions 
  3297.           except those like foo =.  To test for an empty value, use ifeq 
  3298.           ($(foo),).  For example, 
  3299.  
  3300.                     bar =
  3301.                     foo = $(bar)
  3302.                     ifdef foo
  3303.                     frobozz = yes
  3304.                     else
  3305.                     frobozz = no
  3306.                     endif
  3307.  
  3308.           sets `frobozz' to `yes', while: 
  3309.  
  3310.                     foo =
  3311.                     ifdef foo
  3312.                     frobozz = yes
  3313.                     else
  3314.                     frobozz = no
  3315.                     endif
  3316.  
  3317.           sets `frobozz' to `no'. 
  3318.  
  3319. ifndef variable-name 
  3320.           If the variable variable-name has an empty value, the text-if-true is 
  3321.           effective; otherwise, the text-if-false, if any, is effective. 
  3322.  
  3323. Extra spaces are allowed and ignored at the beginning of the conditional 
  3324. directive line, but a tab is not allowed.  (If the line begins with a tab, it 
  3325. will be considered a command for a rule.)  Aside from this, extra spaces or 
  3326. tabs may be inserted with no effect anywhere except within the directive name 
  3327. or within an argument.  A comment starting with `#' may appear at the end of 
  3328. the line. 
  3329.  
  3330. The other two directives that play a part in a conditional are else and endif. 
  3331. Each of these directives is written as one word, with no arguments.  Extra 
  3332. spaces are allowed and ignored at the beginning of the line, and spaces or tabs 
  3333. at the end.  A comment starting with `#' may appear at the end of the line. 
  3334.  
  3335. Conditionals affect which lines of the makefile make uses.  If the condition is 
  3336. true, make reads the lines of the text-if-true as part of the makefile; if the 
  3337. condition is false, make ignores those lines completely.  It follows that 
  3338. syntactic units of the makefile, such as rules, may safely be split across the 
  3339. beginning or the end of the conditional. 
  3340.  
  3341. make evaluates conditionals when it reads a makefile. Consequently, you cannot 
  3342. use automatic variables in the tests of conditionals because they are not 
  3343. defined until commands are run (see Automatic Variables). 
  3344.  
  3345. To prevent intolerable confusion, it is not permitted to start a conditional in 
  3346. one makefile and end it in another.  However, you may write an include 
  3347. directive within a conditional, provided you do not attempt to terminate the 
  3348. conditional inside the included file. 
  3349.  
  3350.  
  3351. ΓòÉΓòÉΓòÉ 10.3. Conditionals that Test Flags ΓòÉΓòÉΓòÉ
  3352.  
  3353. You can write a conditional that tests make command flags such as `-t' by using 
  3354. the variable MAKEFLAGS together with the findstring function (see Functions for 
  3355. String Substitution and Analysis). This is useful when touch is not enough to 
  3356. make a file appear up to date. 
  3357.  
  3358. The findstring function determines whether one string appears as a substring of 
  3359. another.  If you want to test for the `-t' flag, use `t' as the first string 
  3360. and the value of MAKEFLAGS as the other. 
  3361.  
  3362. For example, here is how to arrange to use `ranlib -t' to finish marking an 
  3363. archive file up to date: 
  3364.  
  3365. archive.a: ...
  3366. ifneq (,$(findstring t,$(MAKEFLAGS)))
  3367.         +touch archive.a
  3368.         +ranlib -t archive.a
  3369. else
  3370.         ranlib archive.a
  3371. endif
  3372.  
  3373. The `+' prefix marks those command lines as ``recursive'' so that they will be 
  3374. executed despite use of the `-t' flag. See Recursive Use of make. 
  3375.  
  3376.  
  3377. ΓòÉΓòÉΓòÉ 11. Functions for Transforming Text ΓòÉΓòÉΓòÉ
  3378.  
  3379. Functions allow you to do text processing in the makefile to compute the files 
  3380. to operate on or the commands to use.  You use a function in a function call, 
  3381. where you give the name of the function and some text (the arguments) for the 
  3382. function to operate on.  The result of the function's processing is substituted 
  3383. into the makefile at the point of the call, just as a variable might be 
  3384. substituted. 
  3385.  
  3386.  
  3387. ΓòÉΓòÉΓòÉ 11.1. Function Call Syntax ΓòÉΓòÉΓòÉ
  3388.  
  3389. A function call resembles a variable reference.  It looks like this: 
  3390.  
  3391. $(function arguments)
  3392.  
  3393. or like this: 
  3394.  
  3395. ${function arguments}
  3396.  
  3397. Here function is a function name; one of a short list of names that are part of 
  3398. make.  There is no provision for defining new functions. 
  3399.  
  3400. The arguments are the arguments of the function.  They are separated from the 
  3401. function name by one or more spaces or tabs, and if there is more than one 
  3402. argument, then they are separated by commas. Such whitespace and commas are not 
  3403. part of an argument's value.  The delimiters which you use to surround the 
  3404. function call, whether parentheses or braces, can appear in an argument only in 
  3405. matching pairs; the other kind of delimiters may appear singly.  If the 
  3406. arguments themselves contain other function calls or variable references, it is 
  3407. wisest to use the same kind of delimiters for all the references; write 
  3408. `$(subst a,b,$(x))', not `$(subst a,b,${x})'.  This is because it is clearer, 
  3409. and because only one type of delimiter is matched to find the end of the 
  3410. reference. 
  3411.  
  3412. The text written for each argument is processed by substitution of variables 
  3413. and function calls to produce the argument value, which is the text on which 
  3414. the function acts.  The substitution is done in the order in which the 
  3415. arguments appear. 
  3416.  
  3417. Commas and unmatched parentheses or braces cannot appear in the text of an 
  3418. argument as written; leading spaces cannot appear in the text of the first 
  3419. argument as written.  These characters can be put into the argument value by 
  3420. variable substitution.  First define variables comma and space whose values are 
  3421. isolated comma and space characters, then substitute these variables where such 
  3422. characters are wanted, like this: 
  3423.  
  3424. comma:= ,
  3425. empty:=
  3426. space:= $(empty) $(empty)
  3427. foo:= a b c
  3428. bar:= $(subst $(space),$(comma),$(foo))
  3429. # bar is now `a,b,c'.
  3430.  
  3431. Here the subst function replaces each space with a comma, through the value of 
  3432. foo, and substitutes the result. 
  3433.  
  3434.  
  3435. ΓòÉΓòÉΓòÉ 11.2. Functions for String Substitution and Analysis ΓòÉΓòÉΓòÉ
  3436.  
  3437. Here are some functions that operate on strings: 
  3438.  
  3439. $(subst from,to,text) 
  3440.           Performs a textual replacement on the text text: each occurrence of 
  3441.           from is replaced by to.  The result is substituted for the function 
  3442.           call.  For example, 
  3443.  
  3444.                     $(subst ee,EE,feet on the street)
  3445.  
  3446.           substitutes the string `fEEt on the strEEt'. 
  3447.  
  3448. $(patsubst pattern,replacement,text) 
  3449.           Finds whitespace-separated words in text that match pattern and 
  3450.           replaces them with replacement.  Here pattern may contain a `%' which 
  3451.           acts as a wildcard, matching any number of any characters within a 
  3452.           word.  If replacement also contains a `%', the `%' is replaced by the 
  3453.           text that matched the `%' in pattern. 
  3454.  
  3455.           `%' characters in patsubst function invocations can be quoted with 
  3456.           preceding backslashes (`\').  Backslashes that would otherwise quote 
  3457.           `%' characters can be quoted with more backslashes. Backslashes that 
  3458.           quote `%' characters or other backslashes are removed from the 
  3459.           pattern before it is compared file names or has a stem substituted 
  3460.           into it.  Backslashes that are not in danger of quoting `%' 
  3461.           characters go unmolested.  For example, the pattern 
  3462.           `the\%weird\\%pattern\\' has `the%weird\' preceding the operative `%' 
  3463.           character, and `pattern\\' following it.  The final two backslashes 
  3464.           are left alone because they cannot affect any `%' character. 
  3465.  
  3466.           Whitespace between words is folded into single space characters; 
  3467.           leading and trailing whitespace is discarded. 
  3468.  
  3469.           For example, 
  3470.  
  3471.                     $(patsubst %.c,%.o,x.c.c bar.c)
  3472.  
  3473.           produces the value `x.c.o bar.o'. 
  3474.  
  3475.           Substitution references ( see Substitution References) are a simpler 
  3476.           way to get the effect of the patsubst function: 
  3477.  
  3478.                     $(var:pattern=replacement)
  3479.  
  3480.           is equivalent to 
  3481.  
  3482.                     $(patsubst pattern,replacement,$(var))
  3483.  
  3484.           The second shorthand simplifies one of the most common uses of 
  3485.           patsubst: replacing the suffix at the end of file names. 
  3486.  
  3487.                     $(var:suffix=replacement)
  3488.  
  3489.           is equivalent to 
  3490.  
  3491.                     $(patsubst %suffix,%replacement,$(var))
  3492.  
  3493.           For example, you might have a list of object files: 
  3494.  
  3495.                     objects = foo.o bar.o baz.o
  3496.  
  3497.           To get the list of corresponding source files, you could simply 
  3498.           write: 
  3499.  
  3500.                     $(objects:.o=.c)
  3501.  
  3502.           instead of using the general form: 
  3503.  
  3504.                     $(patsubst %.o,%.c,$(objects))
  3505.  
  3506. $(strip string) 
  3507.           Removes leading and trailing whitespace from string and replaces each 
  3508.           internal sequence of one or more whitespace characters with a single 
  3509.           space.  Thus, `$(strip a b  c )' results in `a b c'. 
  3510.  
  3511.           The function strip can be very useful when used in conjunction with 
  3512.           conditionals.  When comparing something with the null string `""' 
  3513.           using ifeq or ifneq, you usually want a string of just whitespace to 
  3514.           match the null string (see Conditionals). 
  3515.  
  3516.           Thus, the following may fail to have the desired results: 
  3517.  
  3518.                     .PHONY: all
  3519.                     ifneq   "$(needs_made)" ""
  3520.                     all: $(needs_made)
  3521.                     else
  3522.                     all:;@echo 'Nothing to make!'
  3523.                     endif
  3524.  
  3525.           Replacing the variable reference `$(needs_made)' with the function 
  3526.           call `$(strip $(needs_made))' in the ifneq directive would make it 
  3527.           more robust. 
  3528.  
  3529. $(findstring find,in) 
  3530.           Searches in for an occurrence of find.  If it occurs, the value is 
  3531.           find; otherwise, the value is empty.  You can use this function in a 
  3532.           conditional to test for the presence of a specific substring in a 
  3533.           given string.  Thus, the two examples, 
  3534.  
  3535.                     $(findstring a,a b c)
  3536.                     $(findstring a,b c)
  3537.  
  3538.           produce the values `a' and `' (the empty string), respectively.  See 
  3539.           Testing Flags, for a practical application of findstring. 
  3540.  
  3541. $(filter pattern...,text) 
  3542.           Removes all whitespace-separated words in text that do not match any 
  3543.           of the pattern words, returning only matching words.  The patterns 
  3544.           are written using `%', just like the patterns used in the patsubst 
  3545.           function above. 
  3546.  
  3547.           The filter function can be used to separate out different types of 
  3548.           strings (such as file names) in a variable.  For example: 
  3549.  
  3550.                     sources := foo.c bar.c baz.s ugh.h
  3551.                     foo: $(sources)
  3552.                             cc $(filter %.c %.s,$(sources)) -o foo
  3553.  
  3554.           says that `foo' depends of `foo.c', `bar.c', `baz.s' and `ugh.h' but 
  3555.           only `foo.c', `bar.c' and `baz.s' should be specified in the command 
  3556.           to the compiler. 
  3557.  
  3558. $(filter-out pattern...,text) 
  3559.           Removes all whitespace-separated words in text that do match the 
  3560.           pattern words, returning only the words that do not match.  This is 
  3561.           the exact opposite of the filter function. 
  3562.  
  3563.           For example, given: 
  3564.  
  3565.                     objects=main1.o foo.o main2.o bar.o
  3566.                     mains=main1.o main2.o
  3567.  
  3568.           the following generates a list which contains all the object files 
  3569.           not in `mains': 
  3570.  
  3571.                     $(filter-out $(mains),$(objects))
  3572.  
  3573. $(sort list) 
  3574.           Sorts the words of list in lexical order, removing duplicate words. 
  3575.           The output is a list of words separated by single spaces. Thus, 
  3576.  
  3577.                     $(sort foo bar lose)
  3578.  
  3579.           returns the value `bar foo lose'. 
  3580.  
  3581.           Incidentally, since sort removes duplicate words, you can use it for 
  3582.           this purpose even if you don't care about the sort order. 
  3583.  
  3584. Here is a realistic example of the use of subst and patsubst.  Suppose that a 
  3585. makefile uses the VPATH variable to specify a list of directories that make 
  3586. should search for dependency files (see VPATH Search Path for All 
  3587. Dependencies). This example shows how to tell the C compiler to search for 
  3588. header files in the same list of directories. 
  3589.  
  3590. The value of VPATH is a list of directories separated by colons, such as 
  3591. `src:../headers'.  First, the subst function is used to change the colons to 
  3592. spaces: 
  3593.  
  3594. $(subst :, ,$(VPATH))
  3595.  
  3596. This produces `src ../headers'.  Then patsubst is used to turn each directory 
  3597. name into a `-I' flag.  These can be added to the value of the variable CFLAGS, 
  3598. which is passed automatically to the C compiler, like this: 
  3599.  
  3600. override CFLAGS += $(patsubst %,-I%,$(subst :, ,$(VPATH)))
  3601.  
  3602. The effect is to append the text `-Isrc -I../headers' to the previously given 
  3603. value of CFLAGS.  The override directive is used so that the new value is 
  3604. assigned even if the previous value of CFLAGS was specified with a command 
  3605. argument ( see The override Directive). 
  3606.  
  3607.  
  3608. ΓòÉΓòÉΓòÉ 11.3. Functions for File Names ΓòÉΓòÉΓòÉ
  3609.  
  3610. Several of the built-in expansion functions relate specifically to taking apart 
  3611. file names or lists of file names. 
  3612.  
  3613. Each of the following functions performs a specific transformation on a file 
  3614. name.  The argument of the function is regarded as a series of file names, 
  3615. separated by whitespace.  (Leading and trailing whitespace is ignored.)  Each 
  3616. file name in the series is transformed in the same way and the results are 
  3617. concatenated with single spaces between them. 
  3618.  
  3619. $(dir names...) 
  3620.           Extracts the directory-part of each file name in names.  The 
  3621.           directory-part of the file name is everything up through (and 
  3622.           including) the last slash in it.  If the file name contains no slash, 
  3623.           the directory part is the string `./'.  For example, 
  3624.  
  3625.                     $(dir src/foo.c hacks)
  3626.  
  3627.           produces the result `src/ ./'. 
  3628.  
  3629. $(notdir names...) 
  3630.           Extracts all but the directory-part of each file name in names. If 
  3631.           the file name contains no slash, it is left unchanged.  Otherwise, 
  3632.           everything through the last slash is removed from it. 
  3633.  
  3634.           A file name that ends with a slash becomes an empty string.  This is 
  3635.           unfortunate, because it means that the result does not always have 
  3636.           the same number of whitespace-separated file names as the argument 
  3637.           had; but we do not see any other valid alternative. 
  3638.  
  3639.           For example, 
  3640.  
  3641.                     $(notdir src/foo.c hacks)
  3642.  
  3643.           produces the result `foo.c hacks'. 
  3644.  
  3645. $(suffix names...) 
  3646.           Extracts the suffix of each file name in names.  If the file name 
  3647.           contains a period, the suffix is everything starting with the last 
  3648.           period.  Otherwise, the suffix is the empty string.  This frequently 
  3649.           means that the result will be empty when names is not, and if names 
  3650.           contains multiple file names, the result may contain fewer file 
  3651.           names. 
  3652.  
  3653.           For example, 
  3654.  
  3655.                     $(suffix src/foo.c hacks)
  3656.  
  3657.           produces the result `.c'. 
  3658.  
  3659. $(basename names...) 
  3660.           Extracts all but the suffix of each file name in names.  If the file 
  3661.           name contains a period, the basename is everything starting up to 
  3662.           (and not including) the last period.  Otherwise, the basename is the 
  3663.           entire file name.  For example, 
  3664.  
  3665.                     $(basename src/foo.c hacks)
  3666.  
  3667.           produces the result `src/foo hacks'. 
  3668.  
  3669. $(addsuffix suffix,names...) 
  3670.           The argument names is regarded as a series of names, separated by 
  3671.           whitespace; suffix is used as a unit.  The value of suffix is 
  3672.           appended to the end of each individual name and the resulting larger 
  3673.           names are concatenated with single spaces between them.  For example, 
  3674.  
  3675.                     $(addsuffix .c,foo bar)
  3676.  
  3677.           produces the result `foo.c bar.c'. 
  3678.  
  3679. $(addprefix prefix,names...) 
  3680.           The argument names is regarded as a series of names, separated by 
  3681.           whitespace; prefix is used as a unit.  The value of prefix is 
  3682.           prepended to the front of each individual name and the resulting 
  3683.           larger names are concatenated with single spaces between them.  For 
  3684.           example, 
  3685.  
  3686.                     $(addprefix src/,foo bar)
  3687.  
  3688.           produces the result `src/foo src/bar'. 
  3689.  
  3690. $(join list1,list2) 
  3691.           Concatenates the two arguments word by word: the two first words (one 
  3692.           from each argument) concatenated form the first word of the result, 
  3693.           the two second words form the second word of the result, and so on. 
  3694.           So the nth word of the result comes from the nth word of each 
  3695.           argument.  If one argument has more words that the other, the extra 
  3696.           words are copied unchanged into the result. 
  3697.  
  3698.           For example, `$(join a b,.c .o)' produces `a.c b.o'. 
  3699.  
  3700.           Whitespace between the words in the lists is not preserved; it is 
  3701.           replaced with a single space. 
  3702.  
  3703.           This function can merge the results of the dir and notdir functions, 
  3704.           to produce the original list of files which was given to those two 
  3705.           functions. 
  3706.  
  3707. $(word n,text) 
  3708.           Returns the nth word of text.  The legitimate values of n start from 
  3709.           1.  If n is bigger than the number of words in text, the value is 
  3710.           empty.  For example, 
  3711.  
  3712.                     $(word 2, foo bar baz)
  3713.  
  3714.           returns `bar'. 
  3715.  
  3716. $(words text) 
  3717.           Returns the number of words in text. Thus, the last word of text is 
  3718.           $(word $(words text),text). 
  3719.  
  3720. $(firstword names...) 
  3721.           The argument names is regarded as a series of names, separated by 
  3722.           whitespace.  The value is the first name in the series.  The rest of 
  3723.           the names are ignored. 
  3724.  
  3725.           For example, 
  3726.  
  3727.                     $(firstword foo bar)
  3728.  
  3729.           produces the result `foo'.  Although $(firstword text) is the same as 
  3730.           $(word 1,text), the firstword function is retained for its 
  3731.           simplicity. 
  3732.  
  3733. $(wildcard pattern) 
  3734.           The argument pattern is a file name pattern, typically containing 
  3735.           wildcard characters (as in shell file name patterns).  The result of 
  3736.           wildcard is a space-separated list of the names of existing files 
  3737.           that match the pattern. See Using Wildcard Characters in File Names. 
  3738.  
  3739.  
  3740. ΓòÉΓòÉΓòÉ 11.4. The foreach Function ΓòÉΓòÉΓòÉ
  3741.  
  3742. The foreach function is very different from other functions.  It causes one 
  3743. piece of text to be used repeatedly, each time with a different substitution 
  3744. performed on it.  It resembles the for command in the shell sh and the foreach 
  3745. command in the C-shell csh. 
  3746.  
  3747. The syntax of the foreach function is: 
  3748.  
  3749. $(foreach var,list,text)
  3750.  
  3751. The first two arguments, var and list, are expanded before anything else is 
  3752. done; note that the last argument, text, is *not* expanded at the same time. 
  3753. Then for each word of the expanded value of list, the variable named by the 
  3754. expanded value of var is set to that word, and text is expanded.  Presumably 
  3755. text contains references to that variable, so its expansion will be different 
  3756. each time. 
  3757.  
  3758. The result is that text is expanded as many times as there are 
  3759. whitespace-separated words in list.  The multiple expansions of text are 
  3760. concatenated, with spaces between them, to make the result of foreach. 
  3761.  
  3762. This simple example sets the variable `files' to the list of all files in the 
  3763. directories in the list `dirs': 
  3764.  
  3765. dirs := a b c d
  3766. files := $(foreach dir,$(dirs),$(wildcard $(dir)/*))
  3767.  
  3768. Here text is `$(wildcard $(dir)/*)'.  The first repetition finds the value `a' 
  3769. for dir, so it produces the same result as `$(wildcard a/*)'; the second 
  3770. repetition produces the result of `$(wildcard b/*)'; and the third, that of 
  3771. `$(wildcard c/*)'. 
  3772.  
  3773. This example has the same result (except for setting `dirs') as the following 
  3774. example: 
  3775.  
  3776. files := $(wildcard a/* b/* c/* d/*)
  3777.  
  3778. When text is complicated, you can improve readability by giving it a name, with 
  3779. an additional variable: 
  3780.  
  3781. find_files = $(wildcard $(dir)/*)
  3782. dirs := a b c d
  3783. files := $(foreach dir,$(dirs),$(find_files))
  3784.  
  3785. Here we use the variable find_files this way.  We use plain `=' to define a 
  3786. recursively-expanding variable, so that its value contains an actual function 
  3787. call to be reexpanded under the control of foreach; a simply-expanded variable 
  3788. would not do, since wildcard would be called only once at the time of defining 
  3789. find_files. 
  3790.  
  3791. The foreach function has no permanent effect on the variable var; its value and 
  3792. flavor after the foreach function call are the same as they were beforehand. 
  3793. The other values which are taken from list are in effect only temporarily, 
  3794. during the execution of foreach.  The variable var is a simply-expanded 
  3795. variable during the execution of foreach.  If var was undefined before the 
  3796. foreach function call, it is undefined after the call. See The Two Flavors of 
  3797. Variables. 
  3798.  
  3799. You must take care when using complex variable expressions that result in 
  3800. variable names because many strange things are valid variable names, but are 
  3801. probably not what you intended.  For example, 
  3802.  
  3803. files := $(foreach Es escrito en espanol!,b c ch,$(find_files))
  3804.  
  3805. might be useful if the value of find_files references the variable whose name 
  3806. is `Es escrito en espanol!' (es un nombre bastante largo, no?), but it is more 
  3807. likely to be a mistake. 
  3808.  
  3809.  
  3810. ΓòÉΓòÉΓòÉ 11.5. The origin Function ΓòÉΓòÉΓòÉ
  3811.  
  3812. The origin function is unlike most other functions in that it does not operate 
  3813. on the values of variables; it tells you something about a variable. 
  3814. Specifically, it tells you where it came from. 
  3815.  
  3816. The syntax of the origin function is: 
  3817.  
  3818. $(origin variable)
  3819.  
  3820. Note that variable is the name of a variable to inquire about; not a reference 
  3821. to that variable.  Therefore you would not normally use a `$' or parentheses 
  3822. when writing it.  (You can, however, use a variable reference in the name if 
  3823. you want the name not to be a constant.) 
  3824.  
  3825. The result of this function is a string telling you how the variable variable 
  3826. was defined: 
  3827.  
  3828. `undefined' 
  3829.           if variable was never defined. 
  3830.  
  3831. `default' 
  3832.           if variable has a default definition, as is usual with CC and so on. 
  3833.           See Variables Used by Implicit Rules. Note that if you have redefined 
  3834.           a default variable, the origin function will return the origin of the 
  3835.           later definition. 
  3836.  
  3837. `environment' 
  3838.           if variable was defined as an environment variable and the `-e' 
  3839.           option is not turned on (see Summary of Options). 
  3840.  
  3841. `environment override' 
  3842.           if variable was defined as an environment variable and the `-e' 
  3843.           option is turned on ( see Summary of Options). 
  3844.  
  3845. `file' 
  3846.           if variable was defined in a makefile. 
  3847.  
  3848. `command line' 
  3849.           if variable was defined on the command line. 
  3850.  
  3851. `override' 
  3852.           if variable was defined with an override directive in a makefile (see 
  3853.           The override Directive). 
  3854.  
  3855. `automatic' 
  3856.           if variable is an automatic variable defined for the execution of the 
  3857.           commands for each rule (see Automatic Variables). 
  3858.  
  3859. This information is primarily useful (other than for your curiosity) to 
  3860. determine if you want to believe the value of a variable.  For example, suppose 
  3861. you have a makefile `foo' that includes another makefile `bar'.  You want a 
  3862. variable bletch to be defined in `bar' if you run the command `make -f bar', 
  3863. even if the environment contains a definition of bletch.  However, if `foo' 
  3864. defined bletch before including `bar', you do not want to override that 
  3865. definition.  This could be done by using an override directive in `foo', giving 
  3866. that definition precedence over the later definition in `bar'; unfortunately, 
  3867. the override directive would also override any command line definitions.  So, 
  3868. `bar' could include: 
  3869.  
  3870. ifdef bletch
  3871. ifeq "$(origin bletch)" "environment"
  3872. bletch = barf, gag, etc.
  3873. endif
  3874. endif
  3875.  
  3876. If bletch has been defined from the environment, this will redefine it. 
  3877.  
  3878. If you want to override a previous definition of bletch if it came from the 
  3879. environment, even under `-e', you could instead write: 
  3880.  
  3881. ifneq "$(findstring environment,$(origin bletch))" ""
  3882. bletch = barf, gag, etc.
  3883. endif
  3884.  
  3885. Here the redefinition takes place if `$(origin bletch)' returns either 
  3886. `environment' or `environment override'. See Functions for String Substitution 
  3887. and Analysis. 
  3888.  
  3889.  
  3890. ΓòÉΓòÉΓòÉ 11.6. The shell Function ΓòÉΓòÉΓòÉ
  3891.  
  3892. The shell function is unlike any other function except the wildcard function 
  3893. (see The Function wildcard) in that it communicates with the world outside of 
  3894. make. 
  3895.  
  3896. The shell function performs the same function that backquotes (``') perform in 
  3897. most shells: it does command expansion.  This means that it takes an argument 
  3898. that is a shell command and returns the output of the command.  The only 
  3899. processing make does on the result, before substituting it into the surrounding 
  3900. text, is to convert newlines to spaces. 
  3901.  
  3902. The commands run by calls to the shell function are run when the function calls 
  3903. are expanded.  In most cases, this is when the makefile is read in.  The 
  3904. exception is that function calls in the commands of the rules are expanded when 
  3905. the commands are run, and this applies to shell function calls like all others. 
  3906.  
  3907. Here are some examples of the use of the shell function: 
  3908.  
  3909. contents := $(shell cat foo)
  3910.  
  3911. sets contents to the contents of the file `foo', with a space (rather than a 
  3912. newline) separating each line. 
  3913.  
  3914. files := $(shell echo *.c)
  3915.  
  3916. sets files to the expansion of `*.c'.  Unless make is using a very strange 
  3917. shell, this has the same result as `$(wildcard *.c)'. 
  3918.  
  3919.  
  3920. ΓòÉΓòÉΓòÉ 12. How to Run make ΓòÉΓòÉΓòÉ
  3921.  
  3922. A makefile that says how to recompile a program can be used in more than one 
  3923. way.  The simplest use is to recompile every file that is out of date. 
  3924. Usually, makefiles are written so that if you run make with no arguments, it 
  3925. does just that. 
  3926.  
  3927. But you might want to update only some of the files; you might want to use a 
  3928. different compiler or different compiler options; you might want just to find 
  3929. out which files are out of date without changing them. 
  3930.  
  3931. By giving arguments when you run make, you can do any of these things and many 
  3932. others. 
  3933.  
  3934.  
  3935. ΓòÉΓòÉΓòÉ 12.1. Arguments to Specify the Makefile ΓòÉΓòÉΓòÉ
  3936.  
  3937. The way to specify the name of the makefile is with the `-f' or `--file' option 
  3938. (`--makefile' also works).  For example, `-f altmake' says to use the file 
  3939. `altmake' as the makefile. 
  3940.  
  3941. If you use the `-f' flag several times and follow each `-f' with an argument, 
  3942. all the specified files are used jointly as makefiles. 
  3943.  
  3944. If you do not use the `-f' or `--file' flag, the default is to try 
  3945. `GNUmakefile', `makefile', and `Makefile', in that order, and use the first of 
  3946. these three which exists or can be made (see Writing Makefiles). 
  3947.  
  3948.  
  3949. ΓòÉΓòÉΓòÉ 12.2. Arguments to Specify the Goals ΓòÉΓòÉΓòÉ
  3950.  
  3951. The goals are the targets that make should strive ultimately to update.  Other 
  3952. targets are updated as well if they appear as dependencies of goals, or 
  3953. dependencies of dependencies of goals, etc. 
  3954.  
  3955. By default, the goal is the first target in the makefile (not counting targets 
  3956. that start with a period).  Therefore, makefiles are usually written so that 
  3957. the first target is for compiling the entire program or programs they describe. 
  3958.  
  3959. You can specify a different goal or goals with arguments to make. Use the name 
  3960. of the goal as an argument.  If you specify several goals, make processes each 
  3961. of them in turn, in the order you name them. 
  3962.  
  3963. Any target in the makefile may be specified as a goal (unless it starts with 
  3964. `-' or contains an `=', in which case it will be parsed as a switch or variable 
  3965. definition, respectively).  Even targets not in the makefile may be specified, 
  3966. if make can find implicit rules that say how to make them. 
  3967.  
  3968. One use of specifying a goal is if you want to compile only a part of the 
  3969. program, or only one of several programs.  Specify as a goal each file that you 
  3970. wish to remake.  For example, consider a directory containing several programs, 
  3971. with a makefile that starts like this: 
  3972.  
  3973. .PHONY: all
  3974. all: size nm ld ar as
  3975.  
  3976. If you are working on the program size, you might want to say `make size' so 
  3977. that only the files of that program are recompiled. 
  3978.  
  3979. Another use of specifying a goal is to make files that are not normally made. 
  3980. For example, there may be a file of debugging output, or a version of the 
  3981. program that is compiled specially for testing, which has a rule in the 
  3982. makefile but is not a dependency of the default goal. 
  3983.  
  3984. Another use of specifying a goal is to run the commands associated with a phony 
  3985. target (see Phony Targets) or empty target ( see Empty Target Files to Record 
  3986. Events).  Many makefiles contain a phony target named `clean' which deletes 
  3987. everything except source files.  Naturally, this is done only if you request it 
  3988. explicitly with `make clean'.  Here is a list of typical phony and empty target 
  3989. names: 
  3990.  
  3991. `all' 
  3992.           Make all the top-level targets the makefile knows about. 
  3993.  
  3994. `clean' 
  3995.           Delete all files that are normally created by running make. 
  3996.  
  3997. `mostlyclean' 
  3998.           Like `clean', but may refrain from deleting a few files that people 
  3999.           normally don't want to recompile.  For example, the `mostlyclean' 
  4000.           target for GCC does not delete `libgcc.a', because recompiling it is 
  4001.           rarely necessary and takes a lot of time. 
  4002.  
  4003. `distclean' 
  4004. `realclean' 
  4005. `clobber' 
  4006.           Any of these three might be defined to delete everything that would 
  4007.           not be part of a standard distribution.  For example, this would 
  4008.           delete configuration files or links that you would normally create as 
  4009.           preparation for compilation, even if the makefile itself cannot 
  4010.           create these files. 
  4011.  
  4012. `install' 
  4013.           Copy the executable file into a directory that users typically search 
  4014.           for commands; copy any auxiliary files that the executable uses into 
  4015.           the directories where it will look for them. 
  4016.  
  4017. `print' 
  4018.           Print listings of the source files that have changed. 
  4019.  
  4020. `tar' 
  4021.           Create a tar file of the source files. 
  4022.  
  4023. `shar' 
  4024.           Create a shell archive (shar file) of the source files. 
  4025.  
  4026. `dist' 
  4027.           Create a distribution file of the source files.  This might be a tar 
  4028.           file, or a shar file, or a compressed version of one of the above, or 
  4029.           even more than one of the above. 
  4030.  
  4031. `TAGS' 
  4032.           Update a tags table for this program. 
  4033.  
  4034. `check' 
  4035. `test' 
  4036.           Perform self tests on the program this makefile builds. 
  4037.  
  4038.  
  4039. ΓòÉΓòÉΓòÉ 12.3. Instead of Executing the Commands ΓòÉΓòÉΓòÉ
  4040.  
  4041. The makefile tells make how to tell whether a target is up to date, and how to 
  4042. update each target.  But updating the targets is not always what you want. 
  4043. Certain options specify other activities for make. 
  4044.  
  4045. `-n' 
  4046. `--just-print' 
  4047. `--dry-run' 
  4048. `--recon' 
  4049.           ``No-op''.  The activity is to print what commands would be used to 
  4050.           make the targets up to date, but not actually execute them. 
  4051.  
  4052. `-t' 
  4053. `--touch' 
  4054.           ``Touch''.  The activity is to mark the targets as up to date without 
  4055.           actually changing them.  In other words, make pretends to compile the 
  4056.           targets but does not really change their contents. 
  4057.  
  4058. `-q' 
  4059. `--question' 
  4060.           ``Question''.  The activity is to find out silently whether the 
  4061.           targets are up to date already; but execute no commands in either 
  4062.           case.  In other words, neither compilation nor output will occur. 
  4063.  
  4064. `-W' 
  4065. `--what-if' 
  4066. `--assume-new' 
  4067. `--new-file' 
  4068.           ``What if''.  Each `-W' flag is followed by a file name.  The given 
  4069.           files' modification times are recorded by make as being the present 
  4070.           time, although the actual modification times remain the same. You can 
  4071.           use the `-W' flag in conjunction with the `-n' flag to see what would 
  4072.           happen if you were to modify specific files. 
  4073.  
  4074. With the `-n' flag, make prints the commands that it would normally execute but 
  4075. does not execute them. 
  4076.  
  4077. With the `-t' flag, make ignores the commands in the rules and uses (in effect) 
  4078. the command touch for each target that needs to be remade.  The touch command 
  4079. is also printed, unless `-s' or .SILENT is used.  For speed, make does not 
  4080. actually invoke the program touch.  It does the work directly. 
  4081.  
  4082. With the `-q' flag, make prints nothing and executes no commands, but the exit 
  4083. status code it returns is zero if and only if the targets to be considered are 
  4084. already up to date. 
  4085.  
  4086. It is an error to use more than one of these three flags in the same invocation 
  4087. of make. 
  4088.  
  4089. The `-n', `-t', and `-q' options do not affect command lines that begin with 
  4090. `+' characters or contain the strings `$(MAKE)' or `${MAKE}'.  Note that only 
  4091. the line containing the `+' character or the strings `$(MAKE)' or `${MAKE}' is 
  4092. run regardless of these options.  Other lines in the same rule are not run 
  4093. unless they too begin with `+' or contain `$(MAKE)' or `${MAKE}' (See How the 
  4094. MAKE Variable Works.) 
  4095.  
  4096. The `-W' flag provides two features: 
  4097.  
  4098. o If you also use the `-n' or `-q' flag, you can see what make would do if you 
  4099.   were to modify some files. 
  4100.  
  4101. o Without the `-n' or `-q' flag, when make is actually executing commands, the 
  4102.   `-W' flag can direct make to act as if some files had been modified, without 
  4103.   actually modifying the files. 
  4104.  
  4105. Note that the options `-p' and `-v' allow you to obtain other information about 
  4106. make or about the makefiles in use (see Summary of Options). 
  4107.  
  4108.  
  4109. ΓòÉΓòÉΓòÉ 12.4. Avoiding Recompilation of Some Files ΓòÉΓòÉΓòÉ
  4110.  
  4111. Sometimes you may have changed a source file but you do not want to recompile 
  4112. all the files that depend on it.  For example, suppose you add a macro or a 
  4113. declaration to a header file that many other files depend on. Being 
  4114. conservative, make assumes that any change in the header file requires 
  4115. recompilation of all dependent files, but you know that they do not need to be 
  4116. recompiled and you would rather not waste the time waiting for them to compile. 
  4117.  
  4118. If you anticipate the problem before changing the header file, you can use the 
  4119. `-t' flag.  This flag tells make not to run the commands in the rules, but 
  4120. rather to mark the target up to date by changing its last-modification date. 
  4121. You would follow this procedure: 
  4122.  
  4123.  1. Use the command `make' to recompile the source files that really need 
  4124.     recompilation. 
  4125.  
  4126.  2. Make the changes in the header files. 
  4127.  
  4128.  3. Use the command `make -t' to mark all the object files as up to date.  The 
  4129.     next time you run make, the changes in the header files will not cause any 
  4130.     recompilation. 
  4131.  
  4132. If you have already changed the header file at a time when some files do need 
  4133. recompilation, it is too late to do this.  Instead, you can use the `-o file' 
  4134. flag, which marks a specified file as ``old'' (see Summary of Options).  This 
  4135. means that the file itself will not be remade, and nothing else will be remade 
  4136. on its account.  Follow this procedure: 
  4137.  
  4138.  1. Recompile the source files that need compilation for reasons independent of 
  4139.     the particular header file, with `make -o headerfile'. If several header 
  4140.     files are involved, use a separate `-o' option for each header file. 
  4141.  
  4142.  2. Touch all the object files with `make -t'. 
  4143.  
  4144.  
  4145. ΓòÉΓòÉΓòÉ 12.5. Overriding Variables ΓòÉΓòÉΓòÉ
  4146.  
  4147. An argument that contains `=' specifies the value of a variable: `v=x' sets the 
  4148. value of the variable v to x. If you specify a value in this way, all ordinary 
  4149. assignments of the same variable in the makefile are ignored; we say they have 
  4150. been overridden by the command line argument. 
  4151.  
  4152. The most common way to use this facility is to pass extra flags to compilers. 
  4153. For example, in a properly written makefile, the variable CFLAGS is included in 
  4154. each command that runs the C compiler, so a file `foo.c' would be compiled 
  4155. something like this: 
  4156.  
  4157. cc -c $(CFLAGS) foo.c
  4158.  
  4159. Thus, whatever value you set for CFLAGS affects each compilation that occurs. 
  4160. The makefile probably specifies the usual value for CFLAGS, like this: 
  4161.  
  4162. CFLAGS=-g
  4163.  
  4164. Each time you run make, you can override this value if you wish.  For example, 
  4165. if you say `make CFLAGS='-g -O'', each C compilation will be done with `cc -c 
  4166. -g -O'.  (This illustrates how you can use quoting in the shell to enclose 
  4167. spaces and other special characters in the value of a variable when you 
  4168. override it.) 
  4169.  
  4170. The variable CFLAGS is only one of many standard variables that exist just so 
  4171. that you can change them this way. See Variables Used by Implicit Rules, for a 
  4172. complete list. 
  4173.  
  4174. You can also program the makefile to look at additional variables of your own, 
  4175. giving the user the ability to control other aspects of how the makefile works 
  4176. by changing the variables. 
  4177.  
  4178. When you override a variable with a command argument, you can define either a 
  4179. recursively-expanded variable or a simply-expanded variable.  The examples 
  4180. shown above make a recursively-expanded variable; to make a simply-expanded 
  4181. variable, write `:=' instead of `='.  But, unless you want to include a 
  4182. variable reference or function call in the value that you specify, it makes no 
  4183. difference which kind of variable you create. 
  4184.  
  4185. There is one way that the makefile can change a variable that you have 
  4186. overridden.  This is to use the override directive, which is a line that looks 
  4187. like this: `override variable = value' (see The override Directive). 
  4188.  
  4189.  
  4190. ΓòÉΓòÉΓòÉ 12.6. Testing the Compilation of a Program ΓòÉΓòÉΓòÉ
  4191.  
  4192. Normally, when an error happens in executing a shell command, make gives up 
  4193. immediately, returning a nonzero status.  No further commands are executed for 
  4194. any target.  The error implies that the goal cannot be correctly remade, and 
  4195. make reports this as soon as it knows. 
  4196.  
  4197. When you are compiling a program that you have just changed, this is not what 
  4198. you want.  Instead, you would rather that make try compiling every file that 
  4199. can be tried, to show you as many compilation errors as possible. 
  4200.  
  4201. On these occasions, you should use the `-k' or `--keep-going' flag.  This tells 
  4202. make to continue to consider the other dependencies of the pending targets, 
  4203. remaking them if necessary, before it gives up and returns nonzero status.  For 
  4204. example, after an error in compiling one object file, `make -k' will continue 
  4205. compiling other object files even though it already knows that linking them 
  4206. will be impossible.  In addition to continuing after failed shell commands, 
  4207. `make -k' will continue as much as possible after discovering that it does not 
  4208. know how to make a target or dependency file.  This will always cause an error 
  4209. message, but without `-k', it is a fatal error ( see Summary of Options). 
  4210.  
  4211. The usual behavior of make assumes that your purpose is to get the goals up to 
  4212. date; once make learns that this is impossible, it might as well report the 
  4213. failure immediately.  The `-k' flag says that the real purpose is to test as 
  4214. much as possible of the changes made in the program, perhaps to find several 
  4215. independent problems so that you can correct them all before the next attempt 
  4216. to compile.  This is why Emacs' M-x compile command passes the `-k' flag by 
  4217. default. 
  4218.  
  4219.  
  4220. ΓòÉΓòÉΓòÉ 12.7. Summary of Options ΓòÉΓòÉΓòÉ
  4221.  
  4222. Here is a table of all the options make understands: 
  4223.  
  4224. `-b' 
  4225. `-m' 
  4226.           These options are ignored for compatibility with other versions of 
  4227.           make. 
  4228.  
  4229. `-C dir' 
  4230. `--directory dir' 
  4231.           Change to directory dir before reading the makefiles.  If multiple 
  4232.           `-C' options are specified, each is interpreted relative to the 
  4233.           previous one: `-C / -C etc' is equivalent to `-C /etc'. This is 
  4234.           typically used with recursive invocations of make (see Recursive Use 
  4235.           of make). 
  4236.  
  4237. `-d' 
  4238. `--debug' 
  4239.           Print debugging information in addition to normal processing.  The 
  4240.           debugging information says which files are being considered for 
  4241.           remaking, which file-times are being compared and with what results, 
  4242.           which files actually need to be remade, which implicit rules are 
  4243.           considered and which are applied---everything interesting about how 
  4244.           make decides what to do. 
  4245.  
  4246. `-e' 
  4247. `--environment-overrides' 
  4248.           Give variables taken from the environment precedence over variables 
  4249.           from makefiles. See Variables from the Environment. 
  4250.  
  4251. `-f file' 
  4252. `--file file' 
  4253. `--makefile file' 
  4254.           Read the file named file as a makefile. See Writing Makefiles. 
  4255.  
  4256. `-h' 
  4257. `--help' 
  4258.           Remind you of the options that make understands and then exit. 
  4259.  
  4260. `-i' 
  4261. `--ignore-errors' 
  4262.           Ignore all errors in commands executed to remake files. See Errors in 
  4263.           Commands. 
  4264.  
  4265. `-I dir' 
  4266. `--include-dir dir' 
  4267.           Specifies a directory dir to search for included makefiles. See 
  4268.           Including Other Makefiles.  If several `-I' options are used to 
  4269.           specify several directories, the directories are searched in the 
  4270.           order specified. 
  4271.  
  4272. `-j [jobs]' 
  4273. `--jobs [jobs]' 
  4274.           Specifies the number of jobs (commands) to run simultaneously.  With 
  4275.           no argument, make runs as many jobs simultaneously as possible.  If 
  4276.           there is more than one `-j' option, the last one is effective. See 
  4277.           Parallel Execution, for more information on how commands are run. 
  4278.  
  4279. `-k' 
  4280. `--keep-going' 
  4281.           Continue as much as possible after an error.  While the target that 
  4282.           failed, and those that depend on it, cannot be remade, the other 
  4283.           dependencies of these targets can be processed all the same. See 
  4284.           Testing the Compilation of a Program. 
  4285.  
  4286. `-l [load]' 
  4287. `--load-average [load]' 
  4288. `--max-load [load]' 
  4289.           Specifies that no new jobs (commands) should be started if there are 
  4290.           others jobs running and the load average is at least load (a 
  4291.           floating-point number).  With no argument, removes a previous load 
  4292.           limit.  See Parallel Execution. 
  4293.  
  4294. `-n' 
  4295. `--just-print' 
  4296. `--dry-run' 
  4297. `--recon' 
  4298.           Print the commands that would be executed, but do not execute them. 
  4299.           See Instead of Executing the Commands. 
  4300.  
  4301. `-o file' 
  4302. `--old-file file' 
  4303. `--assume-old file' 
  4304.           Do not remake the file file even if it is older than its 
  4305.           dependencies, and do not remake anything on account of changes in 
  4306.           file.  Essentially the file is treated as very old and its rules are 
  4307.           ignored. See Avoiding Recompilation of Some Files. 
  4308.  
  4309. `-p' 
  4310. `--print-data-base' 
  4311.           Print the data base (rules and variable values) that results from 
  4312.           reading the makefiles; then execute as usual or as otherwise 
  4313.           specified.  This also prints the version information given by the 
  4314.           `-v' switch (see below).  To print the data base without trying to 
  4315.           remake any files, use `make -p -f /dev/null'. 
  4316.  
  4317. `-q' 
  4318. `--question' 
  4319.           ``Question mode''.  Do not run any commands, or print anything; just 
  4320.           return an exit status that is zero if the specified targets are 
  4321.           already up to date, nonzero otherwise. See Instead of Executing the 
  4322.           Commands. 
  4323.  
  4324. `-r' 
  4325. `--no-builtin-rules' 
  4326.           Eliminate use of the built-in implicit rules ( see Using Implicit 
  4327.           Rules).  You can still define your own by writing pattern rules ( see 
  4328.           Defining and Redefining Pattern Rules).  The `-r' option also clears 
  4329.           out the default list of suffixes for suffix rules ( see Old-Fashioned 
  4330.           Suffix Rules).  But you can still define your own suffixes with a 
  4331.           rule for .SUFFIXES, and then define your own suffix rules. 
  4332.  
  4333. `-s' 
  4334. `--silent' 
  4335. `--quiet' 
  4336.           Silent operation; do not print the commands as they are executed. See 
  4337.           Command Echoing. 
  4338.  
  4339. `-S' 
  4340. `--no-keep-going' 
  4341. `--stop' 
  4342.           Cancel the effect of the `-k' option.  This is never necessary except 
  4343.           in a recursive make where `-k' might be inherited from the top-level 
  4344.           make via MAKEFLAGS (see Recursive Use of make) or if you set `-k' in 
  4345.           MAKEFLAGS in your environment. 
  4346.  
  4347. `-t' 
  4348. `--touch' 
  4349.           Touch files (mark them up to date without really changing them) 
  4350.           instead of running their commands.  This is used to pretend that the 
  4351.           commands were done, in order to fool future invocations of make.  See 
  4352.           Instead of Executing the Commands. 
  4353.  
  4354. `-v' 
  4355. `--version' 
  4356.           Print the version of the make program plus a copyright, a list of 
  4357.           authors, and a notice that there is no warranty.  After this 
  4358.           information is printed, continue processing normally.  To get this 
  4359.           information without doing anything else, use `make --version -f 
  4360.           /dev/null'. 
  4361.  
  4362. `-w' 
  4363. `--print-directory' 
  4364.           Print a message containing the working directory both before and 
  4365.           after executing the makefile.  This may be useful for tracking down 
  4366.           errors from complicated nests of recursive make commands. See 
  4367.           Recursive Use of make.  (In practice, you rarely need to specify this 
  4368.           option since `make' does it for you; see The `--print-directory' 
  4369.           Option.) 
  4370.           `--no-print-directory' Disable printing of the working directory 
  4371.           under -w. This option is useful when -w is turned on automatically, 
  4372.           but you do not want to see the extra messages. See The 
  4373.           `--print-directory' Option. 
  4374.  
  4375. `-W file' 
  4376. `--what-if file' 
  4377. `--new-file file' 
  4378. `--assume-new file' 
  4379.           Pretend that the target file has just been modified.  When used with 
  4380.           the `-n' flag, this shows you what would happen if you were to modify 
  4381.           that file.  Without `-n', it is almost the same as running a touch 
  4382.           command on the given file before running make, except that the 
  4383.           modification time is changed only in the imagination of make. See 
  4384.           Instead of Executing the Commands. 
  4385.  
  4386.  
  4387. ΓòÉΓòÉΓòÉ 13. Using Implicit Rules ΓòÉΓòÉΓòÉ
  4388.  
  4389. Certain standard ways of remaking target files are used very often.  For 
  4390. example, one customary way to make an object file is from a C source file using 
  4391. the C compiler, cc. 
  4392.  
  4393. Implicit rules tell make how to use customary techniques so that you do not 
  4394. have to specify them in detail when you want to use them.  For example, there 
  4395. is an implicit rule for C compilation.  File names determine which implicit 
  4396. rules are run.  For example, C compilation typically takes a `.c' file and 
  4397. makes a `.o' file. So make applies the implicit rule for C compilation when it 
  4398. sees this combination of file name endings. 
  4399.  
  4400. A chain of implicit rules can apply in sequence; for example, make will remake 
  4401. a `.o' file from a `.y' file by way of a `.c' file. 
  4402.  
  4403. The built-in implicit rules use several variables in their commands so that, by 
  4404. changing the values of the variables, you can change the way the implicit rule 
  4405. works.  For example, the variable CFLAGS controls the flags given to the C 
  4406. compiler by the implicit rule for C compilation. 
  4407.  
  4408. You can define your own implicit rules by writing pattern rules. 
  4409.  
  4410. Suffix rules are a more limited way to define implicit rules. Pattern rules are 
  4411. more general and clearer, but suffix rules are retained for compatibility. 
  4412.  
  4413.  
  4414. ΓòÉΓòÉΓòÉ 13.1. Using Implicit Rules ΓòÉΓòÉΓòÉ
  4415.  
  4416. To allow make to find a customary method for updating a target file, all you 
  4417. have to do is refrain from specifying commands yourself.  Either write a rule 
  4418. with no command lines, or don't write a rule at all.  Then make will figure out 
  4419. which implicit rule to use based on which kind of source file exists or can be 
  4420. made. 
  4421.  
  4422. For example, suppose the makefile looks like this: 
  4423.  
  4424. foo : foo.o bar.o
  4425.         cc -o foo foo.o bar.o $(CFLAGS) $(LDFLAGS)
  4426.  
  4427. Because you mention `foo.o' but do not give a rule for it, make will 
  4428. automatically look for an implicit rule that tells how to update it. This 
  4429. happens whether or not the file `foo.o' currently exists. 
  4430.  
  4431. If an implicit rule is found, it can supply both commands and one or more 
  4432. dependencies (the source files).  You would want to write a rule for `foo.o' 
  4433. with no command lines if you need to specify additional dependencies, such as 
  4434. header files, that the implicit rule cannot supply. 
  4435.  
  4436. Each implicit rule has a target pattern and dependency patterns.  There may be 
  4437. many implicit rules with the same target pattern.  For example, numerous rules 
  4438. make `.o' files: one, from a `.c' file with the C compiler; another, from a 
  4439. `.p' file with the Pascal compiler; and so on.  The rule that actually applies 
  4440. is the one whose dependencies exist or can be made. So, if you have a file 
  4441. `foo.c', make will run the C compiler; otherwise, if you have a file `foo.p', 
  4442. make will run the Pascal compiler; and so on. 
  4443.  
  4444. Of course, when you write the makefile, you know which implicit rule you want 
  4445. make to use, and you know it will choose that one because you know which 
  4446. possible dependency files are supposed to exist. See Catalogue of Implicit 
  4447. Rules, for a catalogue of all the predefined implicit rules. 
  4448.  
  4449. Above, we said an implicit rule applies if the required dependencies ``exist or 
  4450. can be made''.  A file ``can be made'' if it is mentioned explicitly in the 
  4451. makefile as a target or a dependency, or if an implicit rule can be recursively 
  4452. found for how to make it.  When an implicit dependency is the result of another 
  4453. implicit rule, we say that chaining is occurring. See Chains of Implicit Rules. 
  4454.  
  4455. In general, make searches for an implicit rule for each target, and for each 
  4456. double-colon rule, that has no commands.  A file that is mentioned only as a 
  4457. dependency is considered a target whose rule specifies nothing, so implicit 
  4458. rule search happens for it.  See Implicit Rule Search Algorithm, for the 
  4459. details of how the search is done. 
  4460.  
  4461. Note that explicit dependencies do not influence implicit rule search. For 
  4462. example, consider this explicit rule: 
  4463.  
  4464. foo.o: foo.p
  4465.  
  4466. The dependency on `foo.p' does not necessarily mean that make will remake 
  4467. `foo.o' according to the implicit rule to make an object file, a `.o' file, 
  4468. from a Pascal source file, a `.p' file.  For example, if `foo.c' also exists, 
  4469. the implicit rule to make an object file from a C source file is used instead, 
  4470. because it appears before the Pascal rule in the list of predefined implicit 
  4471. rules ( see Catalogue of Implicit Rules). 
  4472.  
  4473. If you do not want an implicit rule to be used for a target that has no 
  4474. commands, you can give that target empty commands by writing a semicolon (see 
  4475. Defining Empty Commands). 
  4476.  
  4477.  
  4478. ΓòÉΓòÉΓòÉ 13.2. Catalogue of Implicit Rules ΓòÉΓòÉΓòÉ
  4479.  
  4480. Here is a catalogue of predefined implicit rules which are always available 
  4481. unless the makefile explicitly overrides or cancels them. See Canceling 
  4482. Implicit Rules, for information on canceling or overriding an implicit rule. 
  4483. The `-r' or `--no-builtin-rules' option cancels all predefined rules. 
  4484.  
  4485. Not all of these rules will always be defined, even when the `-r' option is not 
  4486. given.  Many of the predefined implicit rules are implemented in make as suffix 
  4487. rules, so which ones will be defined depends on the suffix list (the list of 
  4488. dependencies of the special target .SUFFIXES).  The default suffix list is: 
  4489. .out, .a, .ln, .o, .c, .cc, .C, .p, .f, .F, .r, .y, .l, .s, .S, .mod, .sym, 
  4490. .def, .h, .info, .dvi, .tex, .texinfo, .texi, .txinfo, .cweb, .web, .sh, .elc, 
  4491. .el.  All of the implicit rules described below whose dependencies have one of 
  4492. these suffixes are actually suffix rules.  If you modify the suffix list, the 
  4493. only predefined suffix rules in effect will be those named by one or two of the 
  4494. suffixes that are on the list you specify; rules whose suffixes fail to be on 
  4495. the list are disabled.  See Old-Fashioned Suffix Rules, for full details on 
  4496. suffix rules. 
  4497.  
  4498. Compiling C programs 
  4499.           `n.o' is made automatically from `n.c' with a command of the form 
  4500.           `$(CC) -c $(CPPFLAGS) $(CFLAGS)'. 
  4501.  
  4502. Compiling C++ programs 
  4503.           `n.o' is made automatically from `n.cc' or `n.C' with a command of 
  4504.           the form `$(CXX) -c $(CPPFLAGS) $(CXXFLAGS)'.  We encourage you to 
  4505.           use the suffix `.cc' for C++ source files instead of `.C'. 
  4506.  
  4507. Compiling Pascal programs 
  4508.           `n.o' is made automatically from `n.p' with the command `$(PC) -c 
  4509.           $(PFLAGS)'. 
  4510.  
  4511. Compiling Fortran and Ratfor programs 
  4512.           `n.o' is made automatically from `n.r', `n.F' or `n.f' by running the 
  4513.           Fortran compiler.  The precise command used is as follows: 
  4514.  
  4515.    `.f' 
  4516.              `$(FC) -c $(FFLAGS)'. 
  4517.  
  4518.    `.F' 
  4519.              `$(FC) -c $(FFLAGS) $(CPPFLAGS)'. 
  4520.  
  4521.    `.r' 
  4522.              `$(FC) -c $(FFLAGS) $(RFLAGS)'. 
  4523.  
  4524. Preprocessing Fortran and Ratfor programs 
  4525.           `n.f' is made automatically from `n.r' or `n.F'.  This rule runs just 
  4526.           the preprocessor to convert a Ratfor or preprocessable Fortran 
  4527.           program into a strict Fortran program.  The precise command used is 
  4528.           as follows: 
  4529.  
  4530.    `.F' 
  4531.              `$(FC) -F $(CPPFLAGS) $(FFLAGS)'. 
  4532.  
  4533.    `.r' 
  4534.              `$(FC) -F $(FFLAGS) $(RFLAGS)'. 
  4535.  
  4536. Compiling Modula-2 programs 
  4537.           `n.sym' is made from `n.def' with a command of the form `$(M2C) 
  4538.           $(M2FLAGS) $(DEFFLAGS)'.  `n.o' is made from `n.mod'; the form is: 
  4539.           `$(M2C) $(M2FLAGS) $(MODFLAGS)'. 
  4540.  
  4541. Assembling and preprocessing assembler programs 
  4542.           `n.o' is made automatically from `n.s' by running the assembler, as. 
  4543.           The precise command is `$(AS) $(ASFLAGS)'. 
  4544.  
  4545.           `n.s' is made automatically from `n.S' by running the C preprocessor, 
  4546.           cpp.  The precise command is `$(CPP) $(CPPFLAGS)'. 
  4547.  
  4548. Linking a single object file 
  4549.           `n' is made automatically from `n.o' by running the linker ld via the 
  4550.           C compiler.  The precise command used is `$(CC) $(LDFLAGS) n.o 
  4551.           $(LOADLIBES)'. 
  4552.  
  4553.           This rule does the right thing for a simple program with only one 
  4554.           source file.  It will also do the right thing if there are multiple 
  4555.           object files (presumably coming from various other source files), one 
  4556.           of which has a name matching that of the executable file.  Thus, 
  4557.  
  4558.                     x: y.o z.o
  4559.  
  4560.           when `x.c', `y.c' and `z.c' all exist will execute: 
  4561.  
  4562.                     cc -c x.c -o x.o
  4563.                     cc -c y.c -o y.o
  4564.                     cc -c z.c -o z.o
  4565.                     cc x.o y.o z.o -o x
  4566.                     rm -f x.o
  4567.                     rm -f y.o
  4568.                     rm -f z.o
  4569.  
  4570.           In more complicated cases, such as when there is no object file whose 
  4571.           name derives from the executable file name, you must write an 
  4572.           explicit command for linking. 
  4573.  
  4574.           Each kind of file automatically made into `.o' object files will be 
  4575.           automatically linked by using the compiler (`$(CC)', `$(FC)' or 
  4576.           `$(PC)'; the C compiler `$(CC)' is used to assemble `.s' files) 
  4577.           without the `-c' option.  This could be done by using the `.o' object 
  4578.           files as intermediates, but it is faster to do the compiling and 
  4579.           linking in one step, so that's how it's done. 
  4580.  
  4581. Yacc for C programs 
  4582.           `n.c' is made automatically from `n.y' by running Yacc with the 
  4583.           command `$(YACC) $(YFLAGS)'. 
  4584.  
  4585. Lex for C programs 
  4586.           `n.c' is made automatically from `n.l' by by running Lex.  The actual 
  4587.           command is `$(LEX) $(LFLAGS)'. 
  4588.  
  4589. Lex for Ratfor programs 
  4590.           `n.r' is made automatically from `n.l' by by running Lex.  The actual 
  4591.           command is `$(LEX) $(LFLAGS)'. 
  4592.  
  4593.           The convention of using the same suffix `.l' for all Lex files 
  4594.           regardless of whether they produce C code or Ratfor code makes it 
  4595.           impossible for make to determine automatically which of the two 
  4596.           languages you are using in any particular case.  If make is called 
  4597.           upon to remake an object file from a `.l' file, it must guess which 
  4598.           compiler to use.  It will guess the C compiler, because that is more 
  4599.           common.  If you are using Ratfor, make sure make knows this by 
  4600.           mentioning `n.r' in the makefile.  Or, if you are using Ratfor 
  4601.           exclusively, with no C files, remove `.c' from the list of implicit 
  4602.           rule suffixes with: 
  4603.  
  4604.                     .SUFFIXES:
  4605.                     .SUFFIXES: .o .r .f .l ...
  4606.  
  4607. Making Lint Libraries from C, Yacc, or Lex programs 
  4608.           `n.ln' is made from `n.c' with a command of the form `$(LINT) 
  4609.           $(LINTFLAGS) $(CPPFLAGS) -i'. The same command is used on the C code 
  4610.           produced from `n.y' or `n.l'. 
  4611.  
  4612. TeX and Web 
  4613.           `n.dvi' is made from `n.tex' with the command `$(TEX)'.  `n.tex' is 
  4614.           made from `n.web' with `$(WEAVE)', or from `n.cweb' with `$(CWEAVE)'. 
  4615.           `n.p' is made from `n.web' with `$(TANGLE)' and `n.c' is made from 
  4616.           `n.cweb' with `$(CTANGLE)'. 
  4617.  
  4618. Texinfo and Info 
  4619.           `n.dvi' is made from `n.texinfo', `n.texi', or `n.txinfo', with the 
  4620.           `$(TEXI2DVI)' command. `n.info' is made from `n.texinfo', `n.texi', 
  4621.           or `n.txinfo', with the `$(MAKEINFO)' command. 
  4622.  
  4623. RCS 
  4624.           Any file `n' is extracted if necessary from an RCS file named either 
  4625.           `n,v' or `RCS/n,v'.  The precise command used is `$(CO) $(COFLAGS)'. 
  4626.           `n' will not be extracted from RCS if it already exists, even if the 
  4627.           RCS file is newer.  The rules for RCS are terminal (see 
  4628.           Match-Anything Pattern Rules), so RCS files cannot be generated from 
  4629.           another source; they must actually exist. 
  4630.  
  4631. SCCS 
  4632.           Any file `n' is extracted if necessary from an SCCS file named either 
  4633.           `s.n' or `SCCS/s.n'.  The precise command used is `$(GET) $(GFLAGS)'. 
  4634.           The rules for SCCS are terminal (see Match-Anything Pattern Rules), 
  4635.           so SCCS files cannot be generated from another source; they must 
  4636.           actually exist. 
  4637.  
  4638.           For the benefit of SCCS, a file `n' is copied from `n.sh' and made 
  4639.           executable (by everyone).  This is for shell scripts that are checked 
  4640.           into SCCS.  Since RCS preserves the execution permission of a file, 
  4641.           you do not need to use this feature with RCS. 
  4642.  
  4643.           We recommend that you avoid using of SCCS.  RCS is widely held to be 
  4644.           superior, and is also free.  By choosing free software in place of 
  4645.           comparable (or inferior) proprietary software, you support the free 
  4646.           software movement. 
  4647.  
  4648. Usually, you want to change only the variables listed in the table above, which 
  4649. are documented in the following section. 
  4650.  
  4651. However, the commands in built-in implicit rules actually use variables such as 
  4652. COMPILE.c, LINK.p, and PREPROCESS.S, whose values contain the commands listed 
  4653. above. 
  4654.  
  4655. make follows the convention that the rule to compile a `.x' source file uses 
  4656. the variable COMPILE.x. Similarly, the rule to produce an executable from a 
  4657. `.x' file uses LINK.x; and the rule to preprocess a `.x' file uses 
  4658. PREPROCESS.x. 
  4659.  
  4660. Every rule that produces an object file uses the variable OUTPUT_OPTION.  make 
  4661. defines this variable either to contain `-o $@', or to be empty, depending on a 
  4662. compile-time option.  You need the `-o' option to ensure that the output goes 
  4663. into the right file when the source file is in a different directory, as when 
  4664. using VPATH (see Directory Search).  However, compilers on some systems do not 
  4665. accept a `-o' switch for object files.  If you use such a system, and use 
  4666. VPATH, some compilations will put their output in the wrong place. A possible 
  4667. workaround for this problem is to give OUTPUT_OPTION the value `; mv $*.o $@'. 
  4668.  
  4669.  
  4670. ΓòÉΓòÉΓòÉ 13.3. Variables Used by Implicit Rules ΓòÉΓòÉΓòÉ
  4671.  
  4672. The commands in built-in implicit rules make liberal use of certain predefined 
  4673. variables.  You can alter these variables in the makefile, with arguments to 
  4674. make, or in the environment to alter how the implicit rules work without 
  4675. redefining the rules themselves. 
  4676.  
  4677. For example, the command used to compile a C source file actually says `$(CC) 
  4678. -c $(CFLAGS) $(CPPFLAGS)'.  The default values of the variables used are `cc' 
  4679. and nothing, resulting in the command `cc -c'.  By redefining `CC' to `ncc', 
  4680. you could cause `ncc' to be used for all C compilations performed by the 
  4681. implicit rule.  By redefining `CFLAGS' to be `-g', you could pass the `-g' 
  4682. option to each compilation.  All implicit rules that do C compilation use 
  4683. `$(CC)' to get the program name for the compiler and all include `$(CFLAGS)' 
  4684. among the arguments given to the compiler. 
  4685.  
  4686. The variables used in implicit rules fall into two classes: those that are 
  4687. names of programs (like CC) and those that contain arguments for the programs 
  4688. (like CFLAGS).  (The ``name of a program'' may also contain some command 
  4689. arguments, but it must start with an actual executable program name.)  If a 
  4690. variable value contains more than one argument, separate them with spaces. 
  4691.  
  4692. Here is a table of variables used as names of programs in built-in rules: 
  4693.  
  4694. AR 
  4695.           Archive-maintaining program; default `ar'. 
  4696.  
  4697. AS 
  4698.           Program for doing assembly; default `as'. 
  4699.  
  4700. CC 
  4701.           Program for compiling C programs; default `cc'. 
  4702.  
  4703. CXX 
  4704.           Program for compiling C++ programs; default `g++'. 
  4705.  
  4706. CO 
  4707.           Program for extracting a file from RCS; default `co'. 
  4708.  
  4709. CPP 
  4710.           Program for running the C preprocessor, with results to standard 
  4711.           output; default `$(CC) -E'. 
  4712.  
  4713. FC 
  4714.           Program for compiling or preprocessing Fortran and Ratfor programs; 
  4715.           default `f77'. 
  4716.  
  4717. GET 
  4718.           Program for extracting a file from SCCS; default `get'. 
  4719.  
  4720. LEX 
  4721.           Program to use to turn Lex grammars into C programs or Ratfor 
  4722.           programs; default `lex'. 
  4723.  
  4724. PC 
  4725.           Program for compiling Pascal programs; default `pc'. 
  4726.  
  4727. YACC 
  4728.           Program to use to turn Yacc grammars into C programs; default `yacc'. 
  4729.  
  4730. YACCR 
  4731.           Program to use to turn Yacc grammars into Ratfor programs; default 
  4732.           `yacc -r'. 
  4733.  
  4734. MAKEINFO 
  4735.           Program to convert a Texinfo source file into an Info file; default 
  4736.           `makeinfo'. 
  4737.  
  4738. TEX 
  4739.           Program to make TeX dvi files from TeX source; default `tex'. 
  4740.  
  4741. TEXI2DVI 
  4742.           Program to make TeX dvi files from Texinfo source; default 
  4743.           `texi2dvi'. 
  4744.  
  4745. WEAVE 
  4746.           Program to translate Web into TeX; default `weave'. 
  4747.  
  4748. CWEAVE 
  4749.           Program to translate C Web into TeX; default `cweave'. 
  4750.  
  4751. TANGLE 
  4752.           Program to translate Web into Pascal; default `tangle'. 
  4753.  
  4754. CTANGLE 
  4755.           Program to translate C Web into C; default `ctangle'. 
  4756.  
  4757. RM 
  4758.           Command to remove a file; default `rm -f'. 
  4759.  
  4760. Here is a table of variables whose values are additional arguments for the 
  4761. programs above.  The default values for all of these is the empty string, 
  4762. unless otherwise noted. 
  4763.  
  4764. ARFLAGS 
  4765.           Flags to give the archive-maintaining program; default `rv'. 
  4766.  
  4767. ASFLAGS 
  4768.           Extra flags to give to the assembler (when explicitly invoked on a 
  4769.           `.s' or `.S' file). 
  4770.  
  4771. CFLAGS 
  4772.           Extra flags to give to the C compiler. 
  4773.  
  4774. CXXFLAGS 
  4775.           Extra flags to give to the C++ compiler. 
  4776.  
  4777. COFLAGS 
  4778.           Extra flags to give to the RCS co program. 
  4779.  
  4780. CPPFLAGS 
  4781.           Extra flags to give to the C preprocessor and programs that use it 
  4782.           (the C and Fortran compilers). 
  4783.  
  4784. FFLAGS 
  4785.           Extra flags to give to the Fortran compiler. 
  4786.  
  4787. GFLAGS 
  4788.           Extra flags to give to the SCCS get program. 
  4789.  
  4790. LDFLAGS 
  4791.           Extra flags to give to compilers when they are supposed to invoke the 
  4792.           linker, `ld'. 
  4793.  
  4794. LFLAGS 
  4795.           Extra flags to give to Lex. 
  4796.  
  4797. PFLAGS 
  4798.           Extra flags to give to the Pascal compiler. 
  4799.  
  4800. RFLAGS 
  4801.           Extra flags to give to the Fortran compiler for Ratfor programs. 
  4802.  
  4803. YFLAGS 
  4804.           Extra flags to give to Yacc. 
  4805.  
  4806.  
  4807. ΓòÉΓòÉΓòÉ 13.4. Chains of Implicit Rules ΓòÉΓòÉΓòÉ
  4808.  
  4809. Sometimes a file can be made by a sequence of implicit rules.  For example, a 
  4810. file `n.o' could be made from `n.y' by running first Yacc and then cc.  Such a 
  4811. sequence is called a chain. 
  4812.  
  4813. If the file `n.c' exists, or is mentioned in the makefile, no special searching 
  4814. is required: make finds that the object file can be made by C compilation from 
  4815. `n.c'; later on, when considering how to make `n.c', the rule for running Yacc 
  4816. is used.  Ultimately both `n.c' and `n.o' are updated. 
  4817.  
  4818. However, even if `n.c' does not exist and is not mentioned, make knows how to 
  4819. envision it as the missing link between `n.o' and `n.y'!  In this case, `n.c' 
  4820. is called an intermediate file.  Once make has decided to use the intermediate 
  4821. file, it is entered in the data base as if it had been mentioned in the 
  4822. makefile, along with the implicit rule that says how to create it. 
  4823.  
  4824. Intermediate files are remade using their rules just like all other files.  The 
  4825. difference is that the intermediate file is deleted when make is finished. 
  4826. Therefore, the intermediate file which did not exist before make also does not 
  4827. exist after make.  The deletion is reported to you by printing a `rm -f' 
  4828. command that shows what make is doing.  (You can list the target pattern of an 
  4829. implicit rule (such as `%.o') as a dependency of the special target .PRECIOUS 
  4830. to preserve intermediate files made by implicit rules whose target patterns 
  4831. match that file's name; see Interrupts.) 
  4832.  
  4833. A chain can involve more than two implicit rules.  For example, it is possible 
  4834. to make a file `foo' from `RCS/foo.y,v' by running RCS, Yacc and cc.  Then both 
  4835. `foo.y' and `foo.c' are intermediate files that are deleted at the end. 
  4836.  
  4837. No single implicit rule can appear more than once in a chain.  This means that 
  4838. make will not even consider such a ridiculous thing as making `foo' from 
  4839. `foo.o.o' by running the linker twice.  This constraint has the added benefit 
  4840. of preventing any infinite loop in the search for an implicit rule chain. 
  4841.  
  4842. There are some special implicit rules to optimize certain cases that would 
  4843. otherwise by handled by rule chains.  For example, making `foo' from `foo.c' 
  4844. could be handled by compiling and linking with separate chained rules, using 
  4845. `foo.o' as an intermediate file.  But what actually happens is that a special 
  4846. rule for this case does the compilation and linking with a single cc command. 
  4847. The optimized rule is used in preference to the step-by-step chain because it 
  4848. comes earlier in the ordering of rules. 
  4849.  
  4850.  
  4851. ΓòÉΓòÉΓòÉ 13.5. Defining and Redefining Pattern Rules ΓòÉΓòÉΓòÉ
  4852.  
  4853. You define an implicit rule by writing a pattern rule.  A pattern rule looks 
  4854. like an ordinary rule, except that its target contains the character `%' 
  4855. (exactly one of them).  The target is considered a pattern for matching file 
  4856. names; the `%' can match any nonempty substring, while other characters match 
  4857. only themselves.  The dependencies likewise use `%' to show how their names 
  4858. relate to the target name. 
  4859.  
  4860. Thus, a pattern rule `%.o : %.c' says how to make any file `stem.o' from 
  4861. another file `stem.c'. 
  4862.  
  4863. Note that expansion using `%' in pattern rules occurs *after* any variable or 
  4864. function expansions, which take place when the makefile is read. See How to Use 
  4865. Variables, and Functions for Transforming Text. 
  4866.  
  4867.  
  4868. ΓòÉΓòÉΓòÉ 13.5.1. Introduction to Pattern Rules ΓòÉΓòÉΓòÉ
  4869.  
  4870. A pattern rule contains the character `%' (exactly one of them) in the target; 
  4871. otherwise, it looks exactly like an ordinary rule.  The target is a pattern for 
  4872. matching file names; the `%' matches any nonempty substring, while other 
  4873. characters match only themselves. 
  4874.  
  4875. For example, `%.c' as a pattern matches any file name that ends in `.c'. 
  4876. `s.%.c' as a pattern matches any file name that starts with `s.', ends in `.c' 
  4877. and is at least five characters long. (There must be at least one character to 
  4878. match the `%'.)  The substring that the `%' matches is called the stem. 
  4879.  
  4880. `%' in a dependency of a pattern rule stands for the same stem that was matched 
  4881. by the `%' in the target.  In order for the pattern rule to apply, its target 
  4882. pattern must match the file name under consideration, and its dependency 
  4883. patterns must name files that exist or can be made.  These files become 
  4884. dependencies of the target. 
  4885.  
  4886. Thus, a rule of the form 
  4887.  
  4888. %.o : %.c ; command...
  4889.  
  4890. specifies how to make a file `n.o', with another file `n.c' as its dependency, 
  4891. provided that `n.c' exists or can be made. 
  4892.  
  4893. There may also be dependencies that do not use `%'; such a dependency attaches 
  4894. to every file made by this pattern rule.  These unvarying dependencies are 
  4895. useful occasionally. 
  4896.  
  4897. A pattern rule need not have any dependencies that contain `%', or in fact any 
  4898. dependencies at all.  Such a rule is effectively a general wildcard.  It 
  4899. provides a way to make any file that matches the target pattern.  See Last 
  4900. Resort. 
  4901.  
  4902. Pattern rules may have more than one target.  Unlike normal rules, this does 
  4903. not act as many different rules with the same dependencies and commands.  If a 
  4904. pattern rule has multiple targets, make knows that the rule's commands are 
  4905. responsible for making all of the targets.  The commands are executed only once 
  4906. to make all the targets.  When searching for a pattern rule to match a target, 
  4907. the target patterns of a rule other than the one that matches the target in 
  4908. need of a rule are incidental: make worries only about giving commands and 
  4909. dependencies to the file presently in question.  However, when this file's 
  4910. commands are run, the other targets are marked as having been updated 
  4911. themselves. 
  4912.  
  4913. The order in which pattern rules appear in the makefile is important since this 
  4914. is the order in which they are considered. Of equally applicable rules, only 
  4915. the first one found is used.  The rules you write take precedence over those 
  4916. that are built in.  Note however, that a rule whose dependencies actually exist 
  4917. or are mentioned always takes priority over a rule with dependencies that must 
  4918. be made by chaining other implicit rules. 
  4919.  
  4920.  
  4921. ΓòÉΓòÉΓòÉ 13.5.2. Pattern Rule Examples ΓòÉΓòÉΓòÉ
  4922.  
  4923. Here are some examples of pattern rules actually predefined in make.  First, 
  4924. the rule that compiles `.c' files into `.o' files: 
  4925.  
  4926. %.o : %.c
  4927.         $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
  4928.  
  4929. defines a rule that can make any file `x.o' from `x.c'.  The command uses the 
  4930. automatic variables `$@' and `$<' to substitute the names of the target file 
  4931. and the source file in each case where the rule applies (see Automatic 
  4932. Variables). 
  4933.  
  4934. Here is a second built-in rule: 
  4935.  
  4936. % :: RCS/%,v
  4937.         $(CO) $(COFLAGS) $<
  4938.  
  4939. defines a rule that can make any file `x' whatsoever from a corresponding file 
  4940. `x,v' in the subdirectory `RCS'.  Since the target is `%', this rule will apply 
  4941. to any file whatever, provided the appropriate dependency file exists.  The 
  4942. double colon makes the rule terminal, which means that its dependency may not 
  4943. be an intermediate file (see Match-Anything Pattern Rules). 
  4944.  
  4945. This pattern rule has two targets: 
  4946.  
  4947. %.tab.c %.tab.h: %.y
  4948.         bison -d $<
  4949.  
  4950. This tells make that the command `bison -d x.y' will make both `x.tab.c' and 
  4951. `x.tab.h'.  If the file `foo' depends on the files `parse.tab.o' and `scan.o' 
  4952. and the file `scan.o' depends on the file `parse.tab.h', when `parse.y' is 
  4953. changed, the command `bison -d parse.y' will be executed only once, and the 
  4954. dependencies of both `parse.tab.o' and `scan.o' will be satisfied.  (Presumably 
  4955. the file `parse.tab.o' will be recompiled from `parse.tab.c' and the file 
  4956. `scan.o' from `scan.c', while `foo' is linked from `parse.tab.o', `scan.o', and 
  4957. its other dependencies, and it will execute happily ever after.) 
  4958.  
  4959.  
  4960. ΓòÉΓòÉΓòÉ 13.5.3. Automatic Variables ΓòÉΓòÉΓòÉ
  4961.  
  4962. Suppose you are writing a pattern rule to compile a `.c' file into a `.o' file: 
  4963. how do you write the `cc' command so that it operates on the right source file 
  4964. name?  You cannot write the name in the command, because the name is different 
  4965. each time the implicit rule is applied. 
  4966.  
  4967. What you do is use a special feature of make, the automatic variables.  These 
  4968. variables have values computed afresh for each rule that is executed, based on 
  4969. the target and dependencies of the rule.  In this example, you would use `$@' 
  4970. for the object file name and `$<' for the source file name. 
  4971.  
  4972. Here is a table of automatic variables: 
  4973.  
  4974. $@ 
  4975.           The file name of the target of the rule.  If the target is an archive 
  4976.           member, then `$@' is the name of the archive file.  In a pattern rule 
  4977.           that has multiple targets ( see Introduction to Pattern Rules), `$@' 
  4978.           is the name of whichever target caused the rule's commands to be run. 
  4979.  
  4980. $% 
  4981.           The target member name, when the target is an archive member. See 
  4982.           Archives.  For example, if the target is `foo.a(bar.o)' then `$%' is 
  4983.           `bar.o' and `$@' is `foo.a'.  `$%' is empty when the target is not an 
  4984.           archive member. 
  4985.  
  4986. $< 
  4987.           The name of the first dependency.  If the target got its commands 
  4988.           from an implicit rule, this will be the first dependency added by the 
  4989.           implicit rule (see Implicit Rules). 
  4990.  
  4991. $? 
  4992.           The names of all the dependencies that are newer than the target, 
  4993.           with spaces between them.  For dependencies which are archive 
  4994.           members, only the member named is used (see Archives). 
  4995.  
  4996. $^ 
  4997.           The names of all the dependencies, with spaces between them.  For 
  4998.           dependencies which are archive members, only the member named is used 
  4999.           (see Archives). 
  5000.  
  5001. $* 
  5002.           The stem with which an implicit rule matches ( see How Patterns 
  5003.           Match).  If the target is `dir/a.foo.b' and the target pattern is 
  5004.           `a.%.b' then the stem is `dir/foo'.  The stem is useful for 
  5005.           constructing names of related files. 
  5006.  
  5007.           In a static pattern rule, the stem is part of the file name that 
  5008.           matched the `%' in the target pattern. 
  5009.  
  5010.           In an explicit rule, there is no stem; so `$*' cannot be determined 
  5011.           in that way.  Instead, if the target name ends with a recognized 
  5012.           suffix (see Old-Fashioned Suffix Rules), `$*' is set to the target 
  5013.           name minus the suffix.  For example, if the target name is `foo.c', 
  5014.           then `$*' is set to `foo', since `.c' is a suffix.  GNU make does 
  5015.           this bizarre thing only for compatibility with other implementations 
  5016.           of make.  You should generally never use `$*' except in implicit 
  5017.           rules or static pattern rules. 
  5018.  
  5019.           If the target name in an explicit rule does not end with a recognized 
  5020.           suffix, `$*' is set to the empty string for that rule. 
  5021.  
  5022. `$?' is useful even in explicit rules when you wish to operate on only the 
  5023. dependencies that have changed.  For example, suppose that an archive named 
  5024. `lib' is supposed to contain copies of several object files. This rule copies 
  5025. just the changed object files into the archive: 
  5026.  
  5027. lib: foo.o bar.o lose.o win.o
  5028.         ar r lib $?
  5029.  
  5030. Of the variables listed above, four have values that are single file names, and 
  5031. two have values that are lists of file names.  These six have variants that get 
  5032. just the file's directory name or just the file name within the directory.  The 
  5033. variant variables' names are formed by appending `D' or `F', respectively. 
  5034. These variants are semi-obsolete in GNU make since the functions dir and notdir 
  5035. can be used to get an equivalent effect ( see Functions for File Names).  Here 
  5036. is a table of the variants: 
  5037.  
  5038. `$(@D)' 
  5039.           The directory part of the file name of the target.  If the value of 
  5040.           `$@' is `dir/foo.o' then `$(@D)' is `dir/'. This value is `./' if 
  5041.           `$@' does not contain a slash. `$(@D)' is equivalent to `$(dir $@)'. 
  5042.  
  5043. `$(@F)' 
  5044.           The file-within-directory part of the file name of the target.  If 
  5045.           the value of `$@' is `dir/foo.o' then `$(@F)' is `foo.o'.  `$(@F)' is 
  5046.           equivalent to `$(notdir $@)'. 
  5047.  
  5048. `$(*D)' 
  5049. `$(*F)' 
  5050.           The directory part and the file-within-directory part of the stem; 
  5051.           `dir/' and `foo' in this example. 
  5052.  
  5053. `$(%D)' 
  5054. `$(%F)' 
  5055.           The directory part and the file-within-directory part of the target 
  5056.           archive member name.  This makes sense only for archive member 
  5057.           targets of the form `archive(member)' and is useful only when member 
  5058.           may contain a directory name.  ( See Archive Members as Targets.) 
  5059.  
  5060. `$(<D)' 
  5061. `$(<F)' 
  5062.           The directory part and the file-within-directory part of the first 
  5063.           dependency. 
  5064.  
  5065. `$(^D)' 
  5066. `$(^F)' 
  5067.           Lists of the directory parts and the file-within-directory parts of 
  5068.           all dependencies. 
  5069.  
  5070. `$(?D)' 
  5071. `$(?F)' 
  5072.           Lists of the directory parts and the file-within-directory parts of 
  5073.           all dependencies that are newer than the target. 
  5074.  
  5075. Note that we use a special stylistic convention when we talk about these 
  5076. automatic variables; we write ``the value of `$<''', rather than ``the variable 
  5077. <'' as we would write for ordinary variables such as objects and CFLAGS.  We 
  5078. think this convention looks more natural in this special case.  Please do not 
  5079. assume it has a deep significance; `$<' refers to the variable named < just as 
  5080. `$(CFLAGS)' refers to the variable named CFLAGS. You could just as well use 
  5081. `$(<)' in place of `$<'. 
  5082.  
  5083.  
  5084. ΓòÉΓòÉΓòÉ 13.5.4. How Patterns Match ΓòÉΓòÉΓòÉ
  5085.  
  5086. A target pattern is composed of a `%' between a prefix and a suffix, either or 
  5087. both of which may be empty.  The pattern matches a file name only if the file 
  5088. name starts with the prefix and ends with the suffix, without overlap.  The 
  5089. text between the prefix and the suffix is called the stem.  Thus, when the 
  5090. pattern `%.o' matches the file name `test.o', the stem is `test'.  The pattern 
  5091. rule dependencies are turned into actual file names by substituting the stem 
  5092. for the character `%'.  Thus, if in the same example one of the dependencies is 
  5093. written as `%.c', it expands to `test.c'. 
  5094.  
  5095. When the target pattern does not contain a slash (and it usually does not), 
  5096. directory names in the file names are removed from the file name before it is 
  5097. compared with the target prefix and suffix.  After the comparison of the file 
  5098. name to the target pattern, the directory names, along with the slash that ends 
  5099. them, are added on to the dependency file names generated from the pattern 
  5100. rule's dependency patterns and the file name. The directories are ignored only 
  5101. for the purpose of finding an implicit rule to use, not in the application of 
  5102. that rule.  Thus, `e%t' matches the file name `src/eat', with `src/a' as the 
  5103. stem.  When dependencies are turned into file names, the directories from the 
  5104. stem are added at the front, while the rest of the stem is substituted for the 
  5105. `%'.  The stem `src/a' with a dependency pattern `c%r' gives the file name 
  5106. `src/car'. 
  5107.  
  5108.  
  5109. ΓòÉΓòÉΓòÉ 13.5.5. Match-Anything Pattern Rules ΓòÉΓòÉΓòÉ
  5110.  
  5111. When a pattern rule's target is just `%', it matches any file name whatever. 
  5112. We call these rules match-anything rules.  They are very useful, but it can 
  5113. take a lot of time for make to think about them, because it must consider every 
  5114. such rule for each file name listed either as a target or as a dependency. 
  5115.  
  5116. Suppose the makefile mentions `foo.c'.  For this target, make would have to 
  5117. consider making it by linking an object file `foo.c.o', or by C 
  5118. compilation-and-linking in one step from `foo.c.c', or by Pascal 
  5119. compilation-and-linking from `foo.c.p', and many other possibilities. 
  5120.  
  5121. We know these possibilities are ridiculous since `foo.c' is a C source file, 
  5122. not an executable.  If make did consider these possibilities, it would 
  5123. ultimately reject them, because files such as `foo.c.o' and `foo.c.p' would not 
  5124. exist.  But these possibilities are so numerous that make would run very slowly 
  5125. if it had to consider them. 
  5126.  
  5127. To gain speed, we have put various constraints on the way make considers 
  5128. match-anything rules.  There are two different constraints that can be applied, 
  5129. and each time you define a match-anything rule you must choose one or the other 
  5130. for that rule. 
  5131.  
  5132. One choice is to mark the match-anything rule as terminal by defining it with a 
  5133. double colon.  When a rule is terminal, it does not apply unless its 
  5134. dependencies actually exist.  Dependencies that could be made with other 
  5135. implicit rules are not good enough.  In other words, no further chaining is 
  5136. allowed beyond a terminal rule. 
  5137.  
  5138. For example, the built-in implicit rules for extracting sources from RCS and 
  5139. SCCS files are terminal; as a result, if the file `foo.c,v' does not exist, 
  5140. make will not even consider trying to make it as an intermediate file from 
  5141. `foo.c,v.o' or from `RCS/SCCS/s.foo.c,v'. RCS and SCCS files are generally 
  5142. ultimate source files, which should not be remade from any other files; 
  5143. therefore, make can save time by not looking for ways to remake them. 
  5144.  
  5145. If you do not mark the match-anything rule as terminal, then it is nonterminal. 
  5146. A nonterminal match-anything rule cannot apply to a file name that indicates a 
  5147. specific type of data.  A file name indicates a specific type of data if some 
  5148. non-match-anything implicit rule target matches it. 
  5149.  
  5150. For example, the file name `foo.c' matches the target for the pattern rule `%.c 
  5151. : %.y' (the rule to run Yacc).  Regardless of whether this rule is actually 
  5152. applicable (which happens only if there is a file `foo.y'), the fact that its 
  5153. target matches is enough to prevent consideration of any nonterminal 
  5154. match-anything rules for the file `foo.c'.  Thus, make will not even consider 
  5155. trying to make `foo.c' as an executable file from `foo.c.o', `foo.c.c', 
  5156. `foo.c.p', etc. 
  5157.  
  5158. The motivation for this constraint is that nonterminal match-anything rules are 
  5159. used for making files containing specific types of data (such as executable 
  5160. files) and a file name with a recognized suffix indicates some other specific 
  5161. type of data (such as a C source file). 
  5162.  
  5163. Special built-in dummy pattern rules are provided solely to recognize certain 
  5164. file names so that nonterminal match-anything rules will not be considered. 
  5165. These dummy rules have no dependencies and no commands, and they are ignored 
  5166. for all other purposes.  For example, the built-in implicit rule 
  5167.  
  5168. %.p :
  5169.  
  5170. exists to make sure that Pascal source files such as `foo.p' match a specific 
  5171. target pattern and thereby prevent time from being wasted looking for `foo.p.o' 
  5172. or `foo.p.c'. 
  5173.  
  5174. Dummy pattern rules such as the one for `%.p' are made for every suffix listed 
  5175. as valid for use in suffix rules (see Old-Fashioned Suffix Rules). 
  5176.  
  5177.  
  5178. ΓòÉΓòÉΓòÉ 13.5.6. Canceling Implicit Rules ΓòÉΓòÉΓòÉ
  5179.  
  5180. You can override a built-in implicit rule (or one you have defined yourself) by 
  5181. defining a new pattern rule with the same target and dependencies, but 
  5182. different commands.  When the new rule is defined, the built-in one is 
  5183. replaced.  The new rule's position in the sequence of implicit rules is 
  5184. determined by where you write the new rule. 
  5185.  
  5186. You can cancel a built-in implicit rule by defining a pattern rule with the 
  5187. same target and dependencies, but no commands.  For example, the following 
  5188. would cancel the rule that runs the assembler: 
  5189.  
  5190. %.o : %.s
  5191.  
  5192.  
  5193. ΓòÉΓòÉΓòÉ 13.6. Defining Last-Resort Default Rules ΓòÉΓòÉΓòÉ
  5194.  
  5195. You can define a last-resort implicit rule by writing a terminal match-anything 
  5196. pattern rule with no dependencies ( see Match-Anything Rules).  This is just 
  5197. like any other pattern rule; the only thing special about it is that it will 
  5198. match any target.  So such a rule's commands are used for all targets and 
  5199. dependencies that have no commands of their own and for which no other implicit 
  5200. rule applies. 
  5201.  
  5202. For example, when testing a makefile, you might not care if the source files 
  5203. contain real data, only that they exist.  Then you might do this: 
  5204.  
  5205. %::
  5206.         touch $@
  5207.  
  5208. to cause all the source files needed (as dependencies) to be created 
  5209. automatically. 
  5210.  
  5211. You can instead define commands to be used for targets for which there are no 
  5212. rules at all, even ones which don't specify commands.  You do this by writing a 
  5213. rule for the target .DEFAULT.  Such a rule's commands are used for all 
  5214. dependencies which do not appear as targets in any explicit rule, and for which 
  5215. no implicit rule applies.  Naturally, there is no .DEFAULT rule unless you 
  5216. write one. 
  5217.  
  5218. If you use .DEFAULT with no commands or dependencies: 
  5219.  
  5220. .DEFAULT:
  5221.  
  5222. the commands previously stored for .DEFAULT are cleared. Then make acts as if 
  5223. you had never defined .DEFAULT at all. 
  5224.  
  5225. If you do not want a target to get the commands from a match-anything pattern 
  5226. rule or .DEFAULT, but you also do not want any commands to be run for the 
  5227. target, you can give it empty commands ( see Defining Empty Commands). 
  5228.  
  5229. You can use a last-resort rule to override part of another makefile. See 
  5230. Overriding Part of Another Makefile. 
  5231.  
  5232.  
  5233. ΓòÉΓòÉΓòÉ 13.7. Old-Fashioned Suffix Rules ΓòÉΓòÉΓòÉ
  5234.  
  5235. Suffix rules are the old-fashioned way of defining implicit rules for make. 
  5236. Suffix rules are obsolete because pattern rules are more general and clearer. 
  5237. They are supported in GNU make for compatibility with old makefiles.  They come 
  5238. in two kinds: double-suffix and single-suffix. 
  5239.  
  5240. A double-suffix rule is defined by a pair of suffixes: the target suffix and 
  5241. the source suffix.  It matches any file whose name ends with the target suffix. 
  5242. The corresponding implicit dependency is made by replacing the target suffix 
  5243. with the source suffix in the file name.  A two-suffix rule whose target and 
  5244. source suffixes are `.o' and `.c' is equivalent to the pattern rule `%.o : 
  5245. %.c'. 
  5246.  
  5247. A single-suffix rule is defined by a single suffix, which is the source suffix. 
  5248. It matches any file name, and the corresponding implicit dependency name is 
  5249. made by appending the source suffix.  A single-suffix rule whose source suffix 
  5250. is `.c' is equivalent to the pattern rule `% : %.c'. 
  5251.  
  5252. Suffix rule definitions are recognized by comparing each rule's target against 
  5253. a defined list of known suffixes.  When make sees a rule whose target is a 
  5254. known suffix, this rule is considered a single-suffix rule.  When make sees a 
  5255. rule whose target is two known suffixes concatenated, this rule is taken as a 
  5256. double-suffix rule. 
  5257.  
  5258. For example, `.c' and `.o' are both on the default list of known suffixes. 
  5259. Therefore, if you define a rule whose target is `.c.o', make takes it to be a 
  5260. double-suffix rule with source suffix `.c' and target suffix `.o'.  Here is the 
  5261. old-fashioned way to define the rule for compiling a C source file: 
  5262.  
  5263. .c.o:
  5264.         $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
  5265.  
  5266. Suffix rules cannot have any dependencies of their own.  If they have any, they 
  5267. are treated as normal files with funny names, not as suffix rules. Thus, the 
  5268. rule: 
  5269.  
  5270. .c.o: foo.h
  5271.         $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
  5272.  
  5273. tells how to make the file `.c.o' from the dependency file `foo.h', and is not 
  5274. at all like the pattern rule: 
  5275.  
  5276. %.o: %.c foo.h
  5277.         $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
  5278.  
  5279. which tells how to make `.o' files from `.c' files, and makes all `.o' files 
  5280. using this pattern rule also depend on `foo.h'. 
  5281.  
  5282. Suffix rules with no commands are also meaningless.  They do not remove 
  5283. previous rules as do pattern rules with no commands ( see Canceling Implicit 
  5284. Rules).  They simply enter the suffix or pair of suffixes concatenated as a 
  5285. target in the data base. 
  5286.  
  5287. The known suffixes are simply the names of the dependencies of the special 
  5288. target .SUFFIXES.  You can add your own suffixes by writing a rule for 
  5289. .SUFFIXES that adds more dependencies, as in: 
  5290.  
  5291. .SUFFIXES: .hack .win
  5292.  
  5293. which adds `.hack' and `.win' to the end of the list of suffixes. 
  5294.  
  5295. If you wish to eliminate the default known suffixes instead of just adding to 
  5296. them, write a rule for .SUFFIXES with no dependencies.  By special 
  5297. dispensation, this eliminates all existing dependencies of .SUFFIXES.  You can 
  5298. then write another rule to add the suffixes you want.  For example, 
  5299.  
  5300. .SUFFIXES:            # Delete the default suffixes
  5301. .SUFFIXES: .c .o .h   # Define our suffix list
  5302.  
  5303. The `-r' or `--no-builtin-rules' flag causes the default list of suffixes to be 
  5304. empty. 
  5305.  
  5306. The variable SUFFIXES is defined to the default list of suffixes before make 
  5307. reads any makefiles.  You can change the list of suffixes with a rule for the 
  5308. special target .SUFFIXES, but that does not alter this variable. 
  5309.  
  5310.  
  5311. ΓòÉΓòÉΓòÉ 13.8. Implicit Rule Search Algorithm ΓòÉΓòÉΓòÉ
  5312.  
  5313. Here is the procedure make uses for searching for an implicit rule for a target 
  5314. t.  This procedure is followed for each double-colon rule with no commands, for 
  5315. each target of ordinary rules none of which have commands, and for each 
  5316. dependency that is not the target of any rule.  It is also followed recursively 
  5317. for dependencies that come from implicit rules, in the search for a chain of 
  5318. rules. 
  5319.  
  5320. Suffix rules are not mentioned in this algorithm because suffix rules are 
  5321. converted to equivalent pattern rules once the makefiles have been read in. 
  5322.  
  5323. For an archive member target of the form `archive(member)', the following 
  5324. algorithm is run twice, first using `(member)' as the target t, and second 
  5325. using the entire target if the first run found no rule. 
  5326.  
  5327.  1. Split t into a directory part, called d, and the rest, called n.  For 
  5328.     example, if t is `src/foo.o', then d is `src/' and n is `foo.o'. 
  5329.  
  5330.  2. Make a list of all the pattern rules one of whose targets matches t or n. 
  5331.     If the target pattern contains a slash, it is matched against t; otherwise, 
  5332.     against n. 
  5333.  
  5334.  3. If any rule in that list is not a match-anything rule, then remove all 
  5335.     nonterminal match-anything rules from the list. 
  5336.  
  5337.  4. Remove from the list all rules with no commands. 
  5338.  
  5339.  5. For each pattern rule in the list: 
  5340.  
  5341.     a. Find the stem s, which is the nonempty part of t or n matched by the `%' 
  5342.        in the target pattern. 
  5343.  
  5344.     b. Compute the dependency names by substituting s for `%'; if the target 
  5345.        pattern does not contain a slash, append d to the front of each 
  5346.        dependency name. 
  5347.  
  5348.     c. Test whether all the dependencies exist or ought to exist.  (If a file 
  5349.        name is mentioned in the makefile as a target or as an explicit 
  5350.        dependency, then we say it ought to exist.) 
  5351.  
  5352.        If all dependencies exist or ought to exist, or there are no 
  5353.        dependencies, then this rule applies. 
  5354.  
  5355.  6. If no pattern rule has been found so far, try harder. For each pattern rule 
  5356.     in the list: 
  5357.  
  5358.     a. If the rule is terminal, ignore it and go on to the next rule. 
  5359.  
  5360.     b. Compute the dependency names as before. 
  5361.  
  5362.     c. Test whether all the dependencies exist or ought to exist. 
  5363.  
  5364.     d. For each dependency that does not exist, follow this algorithm 
  5365.        recursively to see if the dependency can be made by an implicit rule. 
  5366.  
  5367.     e. If all dependencies exist, ought to exist, or can be made by implicit 
  5368.        rules, then this rule applies. 
  5369.  
  5370.  7. If no implicit rule applies, the rule for .DEFAULT, if any, applies.  In 
  5371.     that case, give t the same commands that .DEFAULT has.  Otherwise, there 
  5372.     are no commands for t. 
  5373.  
  5374. Once a rule that applies has been found, for each target pattern of the rule 
  5375. other than the one that matched t or n, the `%' in the pattern is replaced with 
  5376. s and the resultant file name is stored until the commands to remake the target 
  5377. file t are executed.  After these commands are executed, each of these stored 
  5378. file names are entered into the data base and marked as having been updated and 
  5379. having the same update status as the file t. 
  5380.  
  5381. When the commands of a pattern rule are executed for t, the automatic variables 
  5382. are set corresponding to the target and dependencies. See Automatic Variables. 
  5383.  
  5384.  
  5385. ΓòÉΓòÉΓòÉ 14. Using make to Update Archive Files ΓòÉΓòÉΓòÉ
  5386.  
  5387. Archive files are files containing named subfiles called members; they are 
  5388. maintained with the program ar and their main use is as subroutine libraries 
  5389. for linking. 
  5390.  
  5391.  
  5392. ΓòÉΓòÉΓòÉ 14.1. Archive Members as Targets ΓòÉΓòÉΓòÉ
  5393.  
  5394. An individual member of an archive file can be used as a target or dependency 
  5395. in make.  The archive file must already exist, but the member need not exist. 
  5396. You specify the member named member in archive file archive as follows: 
  5397.  
  5398. archive(member)
  5399.  
  5400. This construct is available only in targets and dependencies, not in commands! 
  5401. Most programs that you might use in commands do not support this syntax and 
  5402. cannot act directly on archive members.  Only ar and other programs 
  5403. specifically designed to operate on archives can do so. Therefore, valid 
  5404. commands to update an archive member target probably must use ar.  For example, 
  5405. this rule says to create a member `hack.o' in archive `foolib' by copying the 
  5406. file `hack.o': 
  5407.  
  5408. foolib(hack.o) : hack.o
  5409.         ar r foolib hack.o
  5410.  
  5411. In fact, nearly all archive member targets are updated in just this way and 
  5412. there is an implicit rule to do it for you. 
  5413.  
  5414.  
  5415. ΓòÉΓòÉΓòÉ 14.2. Implicit Rule for Archive Member Targets ΓòÉΓòÉΓòÉ
  5416.  
  5417. Recall that a target that looks like `a(m)' stands for the member named m in 
  5418. the archive file a. 
  5419.  
  5420. When make looks for an implicit rule for such a target, as a special feature it 
  5421. considers implicit rules that match `(m)', as well as those that match the 
  5422. actual target `a(m)'. 
  5423.  
  5424. This causes one special rule whose target is `(%)' to match.  This rule updates 
  5425. the target `a(m)' by copying the file m into the archive.  For example, it will 
  5426. update the archive member target `foo.a(bar.o)' by copying the file `bar.o' 
  5427. into the archive `foo.a' as a member named `bar.o'. 
  5428.  
  5429. When this rule is chained with others, the result is very powerful. Thus, `make 
  5430. "foo.a(bar.o)"' (the quotes are needed to protect the `(' and `)' from being 
  5431. interpreted specially by the shell) in the presence of a file `bar.c' is enough 
  5432. to cause the following commands to be run, even without a makefile: 
  5433.  
  5434. cc -c bar.c -o bar.o
  5435. ar r foo.a bar.o
  5436. rm -f bar.o
  5437.  
  5438. Here make has envisioned the file `bar.o' as an intermediate file.  See Chains 
  5439. of Implicit Rules. 
  5440.  
  5441. Implicit rules such as this one are written using the automatic variable `$%'. 
  5442. See Automatic Variables. 
  5443.  
  5444. An archive member name in an archive cannot contain a directory name, but it 
  5445. may be useful in a makefile to pretend that it does.  If you write an archive 
  5446. member target `foo.a(dir/file.o)', make will perform automatic updating with 
  5447. this command: 
  5448.  
  5449. ar r foo.a dir/file.o
  5450.  
  5451. which has the effect of copying the file `dir/foo.o' into a member named 
  5452. `foo.o'.  In connection with such usage, the automatic variables %D and %F may 
  5453. be useful. 
  5454.  
  5455.  
  5456. ΓòÉΓòÉΓòÉ 14.2.1. Updating Archive Symbol Directories ΓòÉΓòÉΓòÉ
  5457.  
  5458. An archive file that is used as a library usually contains a special member 
  5459. named `__.SYMDEF' that contains a directory of the external symbol names 
  5460. defined by all the other members.  After you update any other members, you need 
  5461. to update `__.SYMDEF' so that it will summarize the other members properly. 
  5462. This is done by running the ranlib program: 
  5463.  
  5464. ranlib archivefile
  5465.  
  5466. Normally you would put this command in the rule for the archive file, and make 
  5467. all the members of the archive file dependencies of that rule. For example, 
  5468.  
  5469. libfoo.a: libfoo.a(x.o) libfoo.a(y.o) ...
  5470.         ranlib libfoo.a
  5471.  
  5472. The effect of this is to update archive members `x.o', `y.o', etc., and then 
  5473. update the symbol directory member `__.SYMDEF' by running ranlib.  The rules 
  5474. for updating the members are not shown here; most likely you can omit them and 
  5475. use the implicit rule which copies files into the archive, as described in the 
  5476. preceding section. 
  5477.  
  5478. This is not necessary when using the GNU ar program, which updates the 
  5479. `__.SYMDEF' member automatically. 
  5480.  
  5481.  
  5482. ΓòÉΓòÉΓòÉ 14.3. Suffix Rules for Archive Files ΓòÉΓòÉΓòÉ
  5483.  
  5484. You can write a special kind of suffix rule for dealing with archive files. 
  5485. See Suffix Rules, for a full explanation of suffix rules. Archive suffix rules 
  5486. are obsolete in GNU make, because pattern rules for archives are a more general 
  5487. mechanism ( see Archive Update).  But they are retained for compatibility with 
  5488. other makes. 
  5489.  
  5490. To write a suffix rule for archives, you simply write a suffix rule using the 
  5491. target suffix `.a' (the usual suffix for archive files). For example, here is 
  5492. the old-fashioned suffix rule to update a library archive from C source files: 
  5493.  
  5494. .c.a:
  5495.         $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $*.o
  5496.         $(AR) r $@ $*.o
  5497.         $(RM) $*.o
  5498.  
  5499. This works just as if you had written the pattern rule: 
  5500.  
  5501. (%.o): %.c
  5502.         $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $*.o
  5503.         $(AR) r $@ $*.o
  5504.         $(RM) $*.o
  5505.  
  5506. In fact, this is just what make does when it sees a suffix rule with `.a' as 
  5507. the target suffix.  Any double-suffix rule `.x.a' is converted to a pattern 
  5508. rule with the target pattern `(%.o)' and a dependency pattern of `%.x'. 
  5509.  
  5510.  
  5511. ΓòÉΓòÉΓòÉ 15. Features of GNU make ΓòÉΓòÉΓòÉ
  5512.  
  5513. Here is a summary of the features of GNU make, for comparison with and credit 
  5514. to other versions of make.  We consider the features of make in 4.2 BSD systems 
  5515. as a baseline.  If you are concerned with writing portable makefiles, you 
  5516. should use only the features of make not listed here or in Missing. 
  5517.  
  5518. Many features come from the version of make in System V. 
  5519.  
  5520. o The VPATH variable and its special meaning. See Searching Directories for 
  5521.   Dependencies. This feature exists in System V make, but is undocumented. It 
  5522.   is documented in 4.3 BSD make (which says it mimics System V's VPATH 
  5523.   feature). 
  5524.  
  5525. o Included makefiles.  See Including Other Makefiles. Allowing multiple files 
  5526.   to be included with a single directive is a GNU extension. 
  5527.  
  5528. o Variables are read from and communicated via the environment. See Variables 
  5529.   from the Environment. 
  5530.  
  5531. o Options passed through the variable MAKEFLAGS to recursive invocations of 
  5532.   make. See Communicating Options to a Sub-make. 
  5533.  
  5534. o The automatic variable $% is set to the member name in an archive reference. 
  5535.   See Automatic Variables. 
  5536.  
  5537. o The automatic variables $@, $*, $<, $%, and $? have corresponding forms like 
  5538.   $(@F) and $(@D).  We have generalized this to $^ as an obvious extension. 
  5539.   See Automatic Variables. 
  5540.  
  5541. o Substitution variable references. See Basics of Variable References. 
  5542.  
  5543. o The command-line options `-b' and `-m', accepted and ignored.  In System V 
  5544.   make, these options actually do something. 
  5545.  
  5546. o Execution of recursive commands to run make via the variable MAKE even if 
  5547.   `-n', `-q' or `-t' is specified. See Recursive Use of make. 
  5548.  
  5549. o Support for suffix `.a' in suffix rules. See Archive Suffix Rules.  This 
  5550.   feature is obsolete in GNU make, because the general feature of rule chaining 
  5551.   ( see Chains of Implicit Rules) allows one pattern rule for installing 
  5552.   members in an archive (see Archive Update) to be sufficient. 
  5553.  
  5554. o The arrangement of lines and backslash-newline combinations in commands is 
  5555.   retained when the commands are printed, so they appear as they do in the 
  5556.   makefile, except for the stripping of initial whitespace. 
  5557.  
  5558. The following features were inspired by various other versions of make.  In 
  5559. some cases it is unclear exactly which versions inspired which others. 
  5560.  
  5561. o Pattern rules using `%'. This has been implemented in several versions of 
  5562.   make. We're not sure who invented it first, but it's been spread around a 
  5563.   bit. See Defining and Redefining Pattern Rules. 
  5564.  
  5565. o Rule chaining and implicit intermediate files. This was implemented by Stu 
  5566.   Feldman in his version of make for AT&T Eighth Edition Research Unix, and 
  5567.   later by Andrew Hume of AT&T Bell Labs in his mk program (where he terms it 
  5568.   ``transitive closure'').  We do not really know if we got this from either of 
  5569.   them or thought it up ourselves at the same time.  See Chains of Implicit 
  5570.   Rules. 
  5571.  
  5572. o The automatic variable $^ containing a list of all dependencies of the 
  5573.   current target.  We did not invent this, but we have no idea who did. See 
  5574.   Automatic Variables. 
  5575.  
  5576. o The ``what if'' flag (`-W' in GNU make) was (as far as we know) invented by 
  5577.   Andrew Hume in mk. See Instead of Executing the Commands. 
  5578.  
  5579. o The concept of doing several things at once (parallelism) exists in many 
  5580.   incarnations of make and similar programs, though not in the System V or BSD 
  5581.   implementations.  See Command Execution. 
  5582.  
  5583. o Modified variable references using pattern substitution come from SunOS 4.0. 
  5584.   See Basics of Variable References. This functionality was provided in GNU 
  5585.   make by the patsubst function before the alternate syntax was implemented for 
  5586.   compatibility with SunOS 4.0.  It is not altogether clear who inspired whom, 
  5587.   since GNU make had patsubst before SunOS 4.0 was released. 
  5588.  
  5589. o The special significance of `+' characters preceding command lines (see 
  5590.   Instead of Executing the Commands) is mandated by draft 11.2 of IEEE Std 
  5591.   1003.2 (POSIX). 
  5592.  
  5593. o The `+=' syntax to append to the value of a variable comes from SunOS 4.0 
  5594.   make.  See Appending More Text to Variables. 
  5595.  
  5596. The remaining features are inventions new in GNU make: 
  5597.  
  5598. o Use the `-v' or `--version' option to print version and copyright 
  5599.   information. 
  5600.  
  5601. o Use the `-h' or `--help' option to summarize the options to make. 
  5602.  
  5603. o Simply-expand variables.  See The Two Flavors of Variables. 
  5604.  
  5605. o Pass command-line variable assignments automatically through the variable 
  5606.   MAKE to recursive make invocations. See Recursive Use of make. 
  5607.  
  5608. o Use the `-C' or `--directory' command option to change directory.  See 
  5609.   Summary of Options. 
  5610.  
  5611. o Make verbatim variable definitions with define. See Defining Variables 
  5612.   Verbatim. 
  5613.  
  5614. o Declare phony targets with the special target .PHONY. 
  5615.  
  5616.   Andrew Hume of AT&T Bell Labs implemented a similar feature with a different 
  5617.   syntax in his mk program.  This seems to be a case of parallel discovery. 
  5618.   See Phony Targets. 
  5619.  
  5620. o Manipulate text by calling functions. See Functions for Transforming Text. 
  5621.  
  5622. o Use the `-o' or `--old-file' option to pretend a file's modification-time is 
  5623.   old. See Avoiding Recompilation of Some Files. 
  5624.  
  5625. o Conditional execution. 
  5626.  
  5627.   This feature has been implemented numerous times in various versions of make; 
  5628.   it seems a natural extension derived from the features of the C preprocessor 
  5629.   and similar macro languages and is not a revolutionary concept.  See 
  5630.   Conditional Parts of Makefiles. 
  5631.  
  5632. o Specify the included makefile search path. See Including Other Makefiles. 
  5633.  
  5634. o Specify extra makefiles to read. See The Variable MAKEFILES. 
  5635.  
  5636. o Strip leading sequences of `./' from file names, so that `./file' and `file' 
  5637.   are considered to be the same file. 
  5638.  
  5639. o Use a special search method for library dependencies written in the form 
  5640.   `-lname'. See Directory Search for Link Libraries. 
  5641.  
  5642. o Allow suffixes for suffix rules (see Old-Fashioned Suffix Rules) to contain 
  5643.   any characters.  In other version of make, they must begin with `.' and not 
  5644.   contain any `/' characters. 
  5645.  
  5646. o Keep track of the current level of make recursion using the variable 
  5647.   MAKELEVEL.  See Recursive Use of make. 
  5648.  
  5649. o Specify static pattern rules.  See Static Pattern Rules. 
  5650.  
  5651. o Provide selective vpath search. See Searching Directories for Dependencies. 
  5652.  
  5653. o Provide computed variable references. See Basics of Variable References. 
  5654.  
  5655. o Update makefiles.  See How Makefiles Are Remade. System V make has a very, 
  5656.   very limited form of this functionality in that it will check out SCCS files 
  5657.   for makefiles. 
  5658.  
  5659. o Various new built-in implicit rules. See Catalogue of Implicit Rules. 
  5660.  
  5661.  
  5662. ΓòÉΓòÉΓòÉ 16. Incompatibilities and Missing Features ΓòÉΓòÉΓòÉ
  5663.  
  5664. The make programs in various other systems support a few features that are not 
  5665. implemented in GNU make.  Draft 11.2 of the POSIX.2 standard which specifies 
  5666. make does not require any of these features. 
  5667.  
  5668. o A target of the form `file((entry))' stands for a member of archive file 
  5669.   file.  The member is chosen, not by name, but by being an object file which 
  5670.   defines the linker symbol entry. 
  5671.  
  5672.   This feature was not put into GNU make because of the nonmodularity of 
  5673.   putting knowledge into make of the internal format of archive file symbol 
  5674.   tables. See Updating Archive Symbol Directories. 
  5675.  
  5676. o Suffixes (used in suffix rules) that end with the character `~' have a 
  5677.   special meaning to System V make; they refer to the SCCS file that 
  5678.   corresponds to the file one would get without the `~'.  For example, the 
  5679.   suffix rule `.c~.o' would make the file `n.o' file from the SCCS file 
  5680.   `s.n.c'.  For complete coverage, a whole series of such suffix rules is 
  5681.   required. See Old-Fashioned Suffix Rules. 
  5682.  
  5683.   In GNU make, this entire series of cases is handled by two pattern rules for 
  5684.   extraction from SCCS, in combination with the general feature of rule 
  5685.   chaining. See Chains of Implicit Rules. 
  5686.  
  5687. o In System V make, the string `$$@' has the strange meaning that, in the 
  5688.   dependencies of a rule with multiple targets, it stands for the particular 
  5689.   target that is being processed. 
  5690.  
  5691.   This is not defined in GNU make because `$$' should always stand for an 
  5692.   ordinary `$'. 
  5693.  
  5694.   It is possible to get this functionality through the use of static pattern 
  5695.   rules (see Static Pattern Rules). The System V make rule: 
  5696.  
  5697.     $(targets): $$@.o lib.a
  5698.  
  5699.   can be replaced with the GNU make static pattern rule: 
  5700.  
  5701.     $(targets): %: %.o lib.a
  5702.  
  5703. o In System V and 4.3 BSD make, files found by VPATH search (see Searching 
  5704.   Directories for Dependencies) have their names changed inside command 
  5705.   strings.  We feel it is much cleaner to always use automatic variables and 
  5706.   thus make this feature obsolete. 
  5707.  
  5708. o In some Unix makes, implicit rule search (see Using Implicit Rules) is 
  5709.   apparently done for all targets, not just those without commands.  This means 
  5710.   you can do: 
  5711.  
  5712.     foo.o:
  5713.             cc -c foo.c
  5714.  
  5715.   and Unix make will intuit that `foo.o' depends on `foo.c'. 
  5716.  
  5717.   We feel that such usage is broken.  The dependency properties of make are 
  5718.   well-defined (for GNU make, at least), and doing such a thing simply does not 
  5719.   fit the model. 
  5720.  
  5721. o GNU make does not include any built-in implicit rules for compiling or 
  5722.   preprocessing EFL programs.  If we hear of anyone who is using EFL, we will 
  5723.   gladly add them. 
  5724.  
  5725. o It appears that in SVR4 make, a suffix rule can be specified with no 
  5726.   commands, and it is treated as if it had empty commands (see Empty Commands). 
  5727.   For example: 
  5728.  
  5729.     .c.a:
  5730.  
  5731.   will override the built-in `.c.a' suffix rule. 
  5732.  
  5733.   We feel that it is cleaner for a rule without commands to always simply add 
  5734.   to the dependency list for the target.  The above example can be easily 
  5735.   rewritten to get the desired behavior in GNU make: 
  5736.  
  5737.     .c.a: ;
  5738.  
  5739.  
  5740. ΓòÉΓòÉΓòÉ 17. Makefile Conventions ΓòÉΓòÉΓòÉ
  5741.  
  5742. This chapter describes conventions for writing the Makefiles for GNU programs. 
  5743.  
  5744.  
  5745. ΓòÉΓòÉΓòÉ 17.1. General Conventions for Makefiles ΓòÉΓòÉΓòÉ
  5746.  
  5747. Every Makefile should contain this line: 
  5748.  
  5749. SHELL = /bin/sh
  5750.  
  5751. to avoid trouble on systems where the SHELL variable might be inherited from 
  5752. the environment.  (This is never a problem with GNU make.) 
  5753.  
  5754. Don't assume that `.' is in the path for command execution.  When you need to 
  5755. run programs that are a part of your package during the make, please make sure 
  5756. that it uses `./' if the program is built as part of the make or `$(srcdir)/' 
  5757. if the file is an unchanging part of the source code.  Without one of these 
  5758. prefixes, the current search path is used. 
  5759.  
  5760. The distinction between `./' and `$(srcdir)/' is important when using the 
  5761. `--srcdir' option to `configure'.  A rule of the form: 
  5762.  
  5763. foo.1 : foo.man sedscript
  5764.         sed -e sedscript foo.man > foo.1
  5765.  
  5766. will fail when the current directory is not the source directory, because 
  5767. `foo.man' and `sedscript' are not in the current directory. 
  5768.  
  5769. When using GNU make, relying on `VPATH' to find the source file will work in 
  5770. the case where there is a single dependency file, since the `make' automatic 
  5771. variable `$<' will represent the source file wherever it is.  (Many versions of 
  5772. make set `$<' only in implicit rules.)  A makefile target like 
  5773.  
  5774. foo.o : bar.c
  5775.         $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
  5776.  
  5777. should instead be written as 
  5778.  
  5779. foo.o : bar.c
  5780.         $(CC) $(CFLAGS) $< -o $@
  5781.  
  5782. in order to allow `VPATH' to work correctly.  When the target has multiple 
  5783. dependencies, using an explicit `$(srcdir)' is the easiest way to make the rule 
  5784. work well.  For example, the target above for `foo.1' is best written as: 
  5785.  
  5786. foo.1 : foo.man sedscript
  5787.         sed -s $(srcdir)/sedscript $(srcdir)/foo.man > foo.1
  5788.  
  5789.  
  5790. ΓòÉΓòÉΓòÉ 17.2. Utilities in Makefiles ΓòÉΓòÉΓòÉ
  5791.  
  5792. Write the Makefile commands (and any shell scripts, such as configure) to run 
  5793. in sh, not in csh.  Don't use any special features of ksh or bash. 
  5794.  
  5795. The configure script and the Makefile rules for building and installation 
  5796. should not use any utilities directly except these: 
  5797.  
  5798. cat cmp cp echo egrep expr grep
  5799. ln mkdir mv pwd rm rmdir sed test touch
  5800.  
  5801. Stick to the generally supported options for these programs.  For example, 
  5802. don't use `mkdir -p', convenient as it may be, because most systems don't 
  5803. support it. 
  5804.  
  5805. The Makefile rules for building and installation can also use compilers and 
  5806. related programs, but should do so via make variables so that the user can 
  5807. substitute alternatives.  Here are some of the programs we mean: 
  5808.  
  5809. ar bison cc flex install ld lex
  5810. make makeinfo ranlib texi2dvi yacc
  5811.  
  5812. When you use ranlib, you should test whether it exists, and run it only if it 
  5813. exists, so that the distribution will work on systems that don't have ranlib. 
  5814.  
  5815. If you use symbolic links, you should implement a fallback for systems that 
  5816. don't have symbolic links. 
  5817.  
  5818. It is ok to use other utilities in Makefile portions (or scripts) intended only 
  5819. for particular systems where you know those utilities to exist. 
  5820.  
  5821.  
  5822. ΓòÉΓòÉΓòÉ 17.3. Standard Targets for Users ΓòÉΓòÉΓòÉ
  5823.  
  5824. All GNU programs should have the following targets in their Makefiles: 
  5825.  
  5826. `all' 
  5827.           Compile the entire program.  This should be the default target.  This 
  5828.           target need not rebuild any documentation files; info files should 
  5829.           normally be included in the distribution, and DVI files should be 
  5830.           made only when explicitly asked for. 
  5831.  
  5832. `install' 
  5833.           Compile the program and copy the executables, libraries, and so on to 
  5834.           the file names where they should reside for actual use.  If there is 
  5835.           a simple test to verify that a program is properly installed then run 
  5836.           that test. 
  5837.  
  5838.           Use `-' before any command for installing a man page, so that make 
  5839.           will ignore any errors.  This is in case there are systems that don't 
  5840.           have the Unix man page documentation system installed. 
  5841.  
  5842.           In the future, when we have a standard way of installing info files, 
  5843.           `install' targets will be the proper place to do so. 
  5844.  
  5845. `uninstall' 
  5846.           Delete all the installed files that the `install' target would create 
  5847.           (but not the noninstalled files such as `make all' would create). 
  5848.  
  5849. `clean' 
  5850.           Delete all files from the current directory that are normally created 
  5851.           by building the program.  Don't delete the files that record the 
  5852.           configuration.  Also preserve files that could be made by building, 
  5853.           but normally aren't because the distribution comes with them. 
  5854.  
  5855.           Delete `.dvi' files here if they are not part of the distribution. 
  5856.  
  5857. `distclean' 
  5858.           Delete all files from the current directory that are created by 
  5859.           configuring or building the program.  If you have unpacked the source 
  5860.           and built the program without creating any other files, `make 
  5861.           distclean' should leave only the files that were in the distribution. 
  5862.  
  5863. `mostlyclean' 
  5864.           Like `clean', but may refrain from deleting a few files that people 
  5865.           normally don't want to recompile.  For example, the `mostlyclean' 
  5866.           target for GCC does not delete `libgcc.a', because recompiling it is 
  5867.           rarely necessary and takes a lot of time. 
  5868.  
  5869. `realclean' 
  5870.           Delete everything from the current directory that can be 
  5871.           reconstructed with this Makefile.  This typically includes everything 
  5872.           deleted by distclean, plus more: C source files produced by Bison, 
  5873.           tags tables, info files, and so on. 
  5874.  
  5875.           One exception, however: `make realclean' should not delete 
  5876.           `configure' even if `configure' can be remade using a rule in the 
  5877.           Makefile.  More generally, `make realclean' should not delete 
  5878.           anything that needs to exist in order to run `configure' and then 
  5879.           begin to build the program. 
  5880.  
  5881. `TAGS' 
  5882.           Update a tags table for this program. 
  5883.  
  5884. `info' 
  5885.           Generate any info files needed.  The best way to write the rules is 
  5886.           as follows: 
  5887.  
  5888.                     info:  foo.info
  5889.  
  5890.                     foo.info: $(srcdir)/foo.texi $(srcdir)/chap1.texi $(srcdir)/chap2.texi
  5891.                             $(MAKEINFO) $(srcdir)/foo.texi
  5892.  
  5893.           You must define the variable MAKEINFO in the Makefile. It should run 
  5894.           the Makeinfo program, which is part of the Texinfo2 distribution. 
  5895.  
  5896. `dvi' 
  5897.           Generate DVI files for all TeXinfo documentation. For example: 
  5898.  
  5899.                     dvi: foo.dvi
  5900.  
  5901.                     foo.dvi: $(srcdir)/foo.texi $(srcdir)/chap1.texi $(srcdir)/chap2.texi
  5902.                             $(TEXI2DVI) $(srcdir)/foo.texi
  5903.  
  5904.           You must define the variable TEXI2DVI in the Makefile.  It should run 
  5905.           the program texi2dvi, which is part of the Texinfo2 distribution. 
  5906.           Alternatively, write just the dependencies, and allow GNU Make to 
  5907.           provide the command. 
  5908.  
  5909. `dist' 
  5910.           Create a distribution tar file for this program.  The tar file should 
  5911.           be set up so that the file names in the tar file start with a 
  5912.           subdirectory name which is the name of the package it is a 
  5913.           distribution for.  This name can include the version number. 
  5914.  
  5915.           For example, the distribution tar file of GCC version 1.40 unpacks 
  5916.           into a subdirectory named `gcc-1.40'. 
  5917.  
  5918.           The easiest way to do this is to create a subdirectory appropriately 
  5919.           named, use ln or cp to install the proper files in it, and then tar 
  5920.           that subdirectory. 
  5921.  
  5922.           The dist target should explicitly depend on all non-source files that 
  5923.           are in the distribution, to make sure they are up to date in the 
  5924.           distribution. See Making Releases. 
  5925.  
  5926. `check' 
  5927.           Perform self-tests (if any).  The user must build the program before 
  5928.           running the tests, but need not install the program; you should write 
  5929.           the self-tests so that they work when the program is built but not 
  5930.           installed. 
  5931.  
  5932.  The following target is suggested as a conventional name, for programs in 
  5933. which it is useful. 
  5934.  
  5935. installcheck 
  5936.           Perform installation tests (if any).  The user must build and install 
  5937.           the program before running the tests.  You should not assume that 
  5938.           `$(bindir)' is in the search path. 
  5939.  
  5940.  
  5941. ΓòÉΓòÉΓòÉ 17.4. Variables for Specifying Commands ΓòÉΓòÉΓòÉ
  5942.  
  5943. Makefiles should provide variables for overriding certain commands, options, 
  5944. and so on. 
  5945.  
  5946. In particular, you should run most utility programs via variables. Thus, if you 
  5947. use Bison, have a variable named BISON whose default value is set with `BISON = 
  5948. bison', and refer to it with $(BISON) whenever you need to use Bison. 
  5949.  
  5950. File management utilities such as ln, rm, mv, and so on, need not be referred 
  5951. to through variables in this way, since users don't need to replace them with 
  5952. other programs. 
  5953.  
  5954. Each program-name variable should come with an options variable that is used to 
  5955. supply options to the program.  Append `FLAGS' to the program-name variable 
  5956. name to get the options variable name---for example, BISONFLAGS.  (The name 
  5957. CFLAGS is an exception to this rule, but we keep it because it is standard.) 
  5958. Use CPPFLAGS in any compilation command that runs the preprocessor, and use 
  5959. LDFLAGS in any compilation command that does linking as well as in any direct 
  5960. use of ld. 
  5961.  
  5962. If there are C compiler options that must be used for proper compilation of 
  5963. certain files, do not include them in CFLAGS. Users expect to be able to 
  5964. specify CFLAGS freely themselves. Instead, arrange to pass the necessary 
  5965. options to the C compiler independently of CFLAGS, by writing them explicitly 
  5966. in the compilation commands or by defining an implicit rule, like this: 
  5967.  
  5968. CFLAGS = -g
  5969. ALL_CFLAGS = -I. $(CFLAGS)
  5970. .c.o:
  5971.         $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
  5972.  
  5973. Do include the `-g' option in CFLAGS, because that is not required for proper 
  5974. compilation.  You can consider it a default that is only recommended.  If the 
  5975. package is set up so that it is compiled with GCC by default, then you might as 
  5976. well include `-O' in the default value of CFLAGS as well. 
  5977.  
  5978. Put CFLAGS last in the compilation command, after other variables containing 
  5979. compiler options, so the user can use CFLAGS to override the others. 
  5980.  
  5981. Every Makefile should define the variable INSTALL, which is the basic command 
  5982. for installing a file into the system. 
  5983.  
  5984. Every Makefile should also define variables INSTALL_PROGRAM and INSTALL_DATA. 
  5985. (The default for each of these should be $(INSTALL).)  Then it should use those 
  5986. variables as the commands for actual installation, for executables and 
  5987. nonexecutables respectively.  Use these variables as follows: 
  5988.  
  5989. $(INSTALL_PROGRAM) foo $(bindir)/foo
  5990. $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
  5991.  
  5992. Always use a file name, not a directory name, as the second argument of the 
  5993. installation commands.  Use a separate command for each file to be installed. 
  5994.  
  5995.  
  5996. ΓòÉΓòÉΓòÉ 17.5. Variables for Installation Directories ΓòÉΓòÉΓòÉ
  5997.  
  5998. Installation directories should always be named by variables, so it is easy to 
  5999. install in a nonstandard place.  The standard names for these variables are: 
  6000.  
  6001. `prefix' 
  6002.           A prefix used in constructing the default values of the variables 
  6003.           listed below.  The default value of prefix should be `/usr/local' (at 
  6004.           least for now). 
  6005.  
  6006. `exec_prefix' 
  6007.           A prefix used in constructing the default values of the some of the 
  6008.           variables listed below.  The default value of exec_prefix should be 
  6009.           $(prefix). 
  6010.  
  6011.           Generally, $(exec_prefix) is used for directories that contain 
  6012.           machine-specific files (such as executables and subroutine 
  6013.           libraries), while $(prefix) is used directly for other directories. 
  6014.  
  6015. `bindir' 
  6016.           The directory for installing executable programs that users can run. 
  6017.           This should normally be `/usr/local/bin', but write it as 
  6018.           `$(exec_prefix)/bin'. 
  6019.  
  6020. `libdir' 
  6021.           The directory for installing executable files to be run by the 
  6022.           program rather than by users.  Object files and libraries of object 
  6023.           code should also go in this directory.  The idea is that this 
  6024.           directory is used for files that pertain to a specific machine 
  6025.           architecture, but need not be in the path for commands.  The value of 
  6026.           libdir should normally be `/usr/local/lib', but write it as 
  6027.           `$(exec_prefix)/lib'. 
  6028.  
  6029. `datadir' 
  6030.           The directory for installing read-only data files which the programs 
  6031.           refer to while they run.  This directory is used for files which are 
  6032.           independent of the type of machine being used.  This should normally 
  6033.           be `/usr/local/lib', but write it as `$(prefix)/lib'. 
  6034.  
  6035. `statedir' 
  6036.           The directory for installing data files which the programs modify 
  6037.           while they run.  These files should be independent of the type of 
  6038.           machine being used, and it should be possible to share them among 
  6039.           machines at a network installation.  This should normally be 
  6040.           `/usr/local/lib', but write it as `$(prefix)/lib'. 
  6041.  
  6042. `includedir' 
  6043.           The directory for installing header files to be included by user 
  6044.           programs with the C `#include' preprocessor directive.  This should 
  6045.           normally be `/usr/local/include', but write it as 
  6046.           `$(prefix)/include'. 
  6047.  
  6048.           Most compilers other than GCC do not look for header files in 
  6049.           `/usr/local/include'.  So installing the header files this way is 
  6050.           only useful with GCC.  Sometimes this is not a problem because some 
  6051.           libraries are only really intended to work with GCC.  But some 
  6052.           libraries are intended to work with other compilers.  They should 
  6053.           install their header files in two places, one specified by includedir 
  6054.           and one specified by oldincludedir. 
  6055.  
  6056. `oldincludedir' 
  6057.           The directory for installing `#include' header files for use with 
  6058.           compilers other than GCC.  This should normally be `/usr/include'. 
  6059.  
  6060.           The Makefile commands should check whether the value of oldincludedir 
  6061.           is empty.  If it is, they should not try to use it; they should 
  6062.           cancel the second installation of the header files. 
  6063.  
  6064.           A package should not replace an existing header in this directory 
  6065.           unless the header came from the same package.  Thus, if your Foo 
  6066.           package provides a header file `foo.h', then it should install the 
  6067.           header file in the oldincludedir directory if either (1) there is no 
  6068.           `foo.h' there or (2) the `foo.h' that exists came from the Foo 
  6069.           package. 
  6070.  
  6071.           The way to tell whether `foo.h' came from the Foo package is to put a 
  6072.           magic string in the file---part of a comment---and grep for that 
  6073.           string. 
  6074.  
  6075. `mandir' 
  6076.           The directory for installing the man pages (if any) for this package. 
  6077.           It should include the suffix for the proper section of the 
  6078.           manual---usually `1' for a utility. 
  6079.  
  6080. `man1dir' 
  6081.           The directory for installing section 1 man pages. 
  6082.  
  6083. `man2dir' 
  6084.           The directory for installing section 2 man pages. 
  6085.  
  6086. `...' 
  6087.           Use these names instead of `mandir' if the package needs to install 
  6088.           man pages in more than one section of the manual. 
  6089.  
  6090.           *Don't make the primary documentation for any GNU software be a man 
  6091.           page.  Write a manual in Texinfo instead.  Man pages are just for the 
  6092.           sake of people running GNU software on Unix, which is a secondary 
  6093.           application only.* 
  6094.  
  6095. `manext' 
  6096.           The file name extension for the installed man page.  This should 
  6097.           contain a period followed by the appropriate digit. 
  6098.  
  6099. `infodir' 
  6100.           The directory for installing the info files for this package.  By 
  6101.           default, it should be `/usr/local/info', but it should be written as 
  6102.           `$(prefix)/info'. 
  6103.  
  6104. `srcdir' 
  6105.           The directory for the sources being compiled.  The value of this 
  6106.           variable is normally inserted by the configure shell script. 
  6107.  
  6108. For example: 
  6109.  
  6110. # Common prefix for installation directories.
  6111. # NOTE: This directory must exist when you start the install.
  6112. prefix = /usr/local
  6113. exec_prefix = $(prefix)
  6114. # Where to put the executable for the command `gcc'.
  6115. bindir = $(exec_prefix)/bin
  6116. # Where to put the directories used by the compiler.
  6117. libdir = $(exec_prefix)/lib
  6118. # Where to put the Info files.
  6119. infodir = $(prefix)/info
  6120.  
  6121. If your program installs a large number of files into one of the standard 
  6122. user-specified directories, it might be useful to group them into a 
  6123. subdirectory particular to that program.  If you do this, you should write the 
  6124. install rule to create these subdirectories. 
  6125.  
  6126. Do not expect the user to include the subdirectory name in the value of any of 
  6127. the variables listed above.  The idea of having a uniform set of variable names 
  6128. for installation directories is to enable the user to specify the exact same 
  6129. values for several different GNU packages.  In order for this to be useful, all 
  6130. the packages must be designed so that they will work sensibly when the user 
  6131. does so. 
  6132.  
  6133.  
  6134. ΓòÉΓòÉΓòÉ 18. Quick Reference ΓòÉΓòÉΓòÉ
  6135.  
  6136. This appendix summarizes the directives, text manipulation functions, and 
  6137. special variables which GNU make understands. See Special Targets, Catalogue of 
  6138. Implicit Rules, and Summary of Options. for other summaries. 
  6139.  
  6140. Here is a summary of the directives GNU make recognizes: 
  6141.  
  6142. define variable 
  6143. endef 
  6144.           Define a multi-line, recursively-expanded variable. 
  6145.           See Sequences. 
  6146.  
  6147. ifdef variable 
  6148. ifndef variable 
  6149. ifeq (a,b) 
  6150. ifeq "a" "b" 
  6151. ifeq 'a' 'b' 
  6152. ifneq (a,b) 
  6153. ifneq "a" "b" 
  6154. ifneq 'a' 'b' 
  6155. else 
  6156. endif 
  6157.           Conditionally evaluate part of the makefile. 
  6158.           See Conditionals. 
  6159.  
  6160. include file 
  6161.           Include another makefile. 
  6162.           See Including Other Makefiles. 
  6163.  
  6164. override variable = value 
  6165. override variable := value 
  6166. override variable += value 
  6167. override define variable 
  6168. endef 
  6169.           Define a variable, overriding any previous definition, even one from 
  6170.           the command line. 
  6171.           See The override Directive. 
  6172.  
  6173. export 
  6174.           Tell make to export all variables to child processes by default. 
  6175.           See Communicating Variables to a Sub-make. 
  6176.  
  6177. export variable 
  6178. export variable = value 
  6179. export variable := value 
  6180. export variable += value 
  6181. unexport variable 
  6182.           Tell make whether or not to export a particular variable to child 
  6183.           processes. 
  6184.           See Communicating Variables to a Sub-make. 
  6185.  
  6186. vpath pattern path 
  6187.           Specify a search path for files matching a `%' pattern. 
  6188.           See The vpath Directive. 
  6189.  
  6190. vpath pattern 
  6191.           Remove all search paths previously specified for pattern. 
  6192.  
  6193. vpath 
  6194.           Remove all search paths previously specified in any vpath directive. 
  6195.  
  6196. Here is a summary of the text manipulation functions (see Functions): 
  6197.  
  6198. $(subst from,to,text) 
  6199.           Replace from with to in text. 
  6200.           See Functions for String Substitution and Analysis. 
  6201.  
  6202. $(patsubst pattern,replacement,text) 
  6203.           Replace words matching pattern with replacement in text. 
  6204.           See Functions for String Substitution and Analysis. 
  6205.  
  6206. $(strip string) 
  6207.           Remove excess whitespace characters from string. 
  6208.           See Functions for String Substitution and Analysis. 
  6209.  
  6210. $(findstring find,text) 
  6211.           Locate find in text. 
  6212.           See Functions for String Substitution and Analysis. 
  6213.  
  6214. $(filter pattern...,text) 
  6215.           Select words in text that match one of the pattern words. 
  6216.           See Functions for String Substitution and Analysis. 
  6217.  
  6218. $(filter-out pattern...,text) 
  6219.           Select words in text that do not match any of the pattern words. 
  6220.           See Functions for String Substitution and Analysis. 
  6221.  
  6222. $(sort list) 
  6223.           Sort the words in list lexicographically, removing duplicates. 
  6224.           See Functions for String Substitution and Analysis. 
  6225.  
  6226. $(dir names...) 
  6227.           Extract the directory part of each file name. 
  6228.           See Functions for File Names. 
  6229.  
  6230. $(notdir names...) 
  6231.           Extract the non-directory part of each file name. 
  6232.           See Functions for File Names. 
  6233.  
  6234. $(suffix names...) 
  6235.           Extract the suffix (the last `.' and following characters) of each 
  6236.           file name. 
  6237.           See Functions for File Names. 
  6238.  
  6239. $(basename names...) 
  6240.           Extract the base name (name without suffix) of each file name. 
  6241.           See Functions for File Names. 
  6242.  
  6243. $(addsuffix suffix,names...) 
  6244.           Append suffix to each word in names. 
  6245.           See Functions for File Names. 
  6246.  
  6247. $(addprefix prefix,names...) 
  6248.           Prepend prefix to each word in names. 
  6249.           See Functions for File Names. 
  6250.  
  6251. $(join list1,list2) 
  6252.           Join two parallel lists of words. 
  6253.           See Functions for File Names. 
  6254.  
  6255. $(word n,text) 
  6256.           Extract the nth word (one-origin) of text. 
  6257.           See Functions for File Names. 
  6258.  
  6259. $(words text) 
  6260.           Count the number of words in text. 
  6261.           See Functions for File Names. 
  6262.  
  6263. $(firstword names...) 
  6264.           Extract the first word of names. 
  6265.           See Functions for File Names. 
  6266.  
  6267. $(wildcard pattern...) 
  6268.           Find file names matching a shell file name pattern (not a `%' 
  6269.           pattern). 
  6270.           See The Function wildcard. 
  6271.  
  6272. $(shell command) 
  6273.           Execute a shell command and return its output. 
  6274.           See The shell Function. 
  6275.  
  6276. $(origin variable) 
  6277.           Return a string describing how the make variable variable was 
  6278.           defined. 
  6279.           See The origin Function. 
  6280.  
  6281. $(foreach var,words,text) 
  6282.           Evaluate text with var bound to each word in words, and concatenate 
  6283.           the results. 
  6284.           See The foreach Function. 
  6285.  
  6286. Here is a summary of the automatic variables. See Automatic Variables, for full 
  6287. information. 
  6288.  
  6289. $@ 
  6290.           The file name of the target. 
  6291.  
  6292. $% 
  6293.           The target member name, when the target is an archive member. 
  6294.  
  6295. $< 
  6296.           The name of the first dependency. 
  6297.  
  6298. $? 
  6299.           The names of all the dependencies that are newer than the target, 
  6300.           with spaces between them. For dependencies which are archive members, 
  6301.           only the member named is used (see Archives). 
  6302.  
  6303. $^ 
  6304.           The names of all the dependencies, with spaces between them.  For 
  6305.           dependencies which are archive members, only the member named is used 
  6306.           (see Archives). 
  6307.  
  6308. $* 
  6309.           The stem with which an implicit rule matches (see How Patterns 
  6310.           Match). 
  6311.  
  6312. $(@D) 
  6313. $(@F) 
  6314.           The directory part and the file-within-directory part of $@. 
  6315.  
  6316. $(*D) 
  6317. $(*F) 
  6318.           The directory part and the file-within-directory part of $*. 
  6319.  
  6320. $(%D) 
  6321. $(%F) 
  6322.           The directory part and the file-within-directory part of $%. 
  6323.  
  6324. $(<D) 
  6325. $(<F) 
  6326.           The directory part and the file-within-directory part of $<. 
  6327.  
  6328. $(^D) 
  6329. $(^F) 
  6330.           The directory part and the file-within-directory part of $^. 
  6331.  
  6332. $(?D) 
  6333. $(?F) 
  6334.           The directory part and the file-within-directory part of $?. 
  6335.  
  6336. These variables are used specially by GNU make: 
  6337.  
  6338. MAKEFILES 
  6339.           Makefiles to be read on every invocation of make. 
  6340.           See The Variable MAKEFILES. 
  6341.  
  6342. VPATH 
  6343.           Directory search path for files not found in the current directory. 
  6344.           See VPATH Search Path for All Dependencies. 
  6345.  
  6346. SHELL 
  6347.           The name of the system default command interpreter, usually 
  6348.           `/bin/sh'. You can set SHELL in the makefile to change the shell used 
  6349.           to run commands.  See Command Execution. 
  6350.  
  6351. MAKE 
  6352.           The name with which make was invoked. Using this variable in commands 
  6353.           has special meaning. See How the MAKE Variable Works. 
  6354.  
  6355. MAKELEVEL 
  6356.           The number of levels of recursion (sub-makes). 
  6357.           See Variables/Recursion. 
  6358.  
  6359. MAKEFLAGS 
  6360. MFLAGS 
  6361.           The flags given to make.  You can set this in the environment or a 
  6362.           makefile to set flags. 
  6363.           See Communicating Options to a Sub-make. 
  6364.  
  6365. SUFFIXES 
  6366.           The default list of suffixes before make reads any makefiles. 
  6367.  
  6368.  
  6369. ΓòÉΓòÉΓòÉ 19. Complex Makefile Example ΓòÉΓòÉΓòÉ
  6370.  
  6371. Here is the makefile for the GNU tar program.  This is a moderately complex 
  6372. makefile. 
  6373.  
  6374. Because it is the first target, the default goal is `all'.  An interesting 
  6375. feature of this makefile is that `testpad.h' is a source file automatically 
  6376. created by the testpad program, itself compiled from `testpad.c'. 
  6377.  
  6378. If you type `make' or `make all', then make creates the `tar' executable, the 
  6379. `rmt' daemon that provides remote tape access, and the `tar.info' Info file. 
  6380.  
  6381. If you type `make install', then make not only creates `tar', `rmt', and 
  6382. `tar.info', but also installs them. 
  6383.  
  6384. If you type `make clean', then make removes the `.o' files, and the `tar', 
  6385. `rmt', `testpad', `testpad.h', and `core' files. 
  6386.  
  6387. If you type `make distclean', then make not only removes the same files as does 
  6388. `make clean' but also the `TAGS', `Makefile', and `config.status' files. 
  6389. (Although it is not evident, this makefile (and `config.status') is generated 
  6390. by the user with the configure program, which is provided in the tar 
  6391. distribution, but is not shown here.) 
  6392.  
  6393. If you type `make realclean', then make removes the same files as does `make 
  6394. distclean' and also removes the Info files generated from `tar.texinfo'. 
  6395.  
  6396. In addition, there are targets shar and dist that create distribution kits. 
  6397.  
  6398. # Generated automatically from Makefile.in by configure.
  6399. # Un*x Makefile for GNU tar program.
  6400. # Copyright (C) 1991 Free Software Foundation, Inc.
  6401.  
  6402. # This program is free software; you can redistribute
  6403. # it and/or modify it under the terms of the GNU
  6404. # General Public License ...
  6405. ...
  6406. ...
  6407.  
  6408. SHELL = /bin/sh
  6409.  
  6410. #### Start of system configuration section. ####
  6411.  
  6412. srcdir = .
  6413.  
  6414. # If you use gcc, you should either run the
  6415. # fixincludes script that comes with it or else use
  6416. # gcc with the -traditional option.  Otherwise ioctl
  6417. # calls will be compiled incorrectly on some systems.
  6418. CC = gcc -O
  6419. YACC = bison -y
  6420. INSTALL = /usr/local/bin/install -c
  6421. INSTALLDATA = /usr/local/bin/install -c -m 644
  6422.  
  6423. # Things you might add to DEFS:
  6424. # -DSTDC_HEADERS        If you have ANSI C headers and
  6425. #                       libraries.
  6426. # -DPOSIX               If you have POSIX.1 headers and
  6427. #                       libraries.
  6428. # -DBSD42               If you have sys/dir.h (unless
  6429. #                       you use -DPOSIX), sys/file.h,
  6430. #                       and st_blocks in `struct stat'.
  6431. # -DUSG                 If you have System V/ANSI C
  6432. #                       string and memory functions
  6433. #                       and headers, sys/sysmacros.h,
  6434. #                       fcntl.h, getcwd, no valloc,
  6435. #                       and ndir.h (unless
  6436. #                       you use -DDIRENT).
  6437. # -DNO_MEMORY_H         If USG or STDC_HEADERS but do not
  6438. #                       include memory.h.
  6439. # -DDIRENT              If USG and you have dirent.h
  6440. #                       instead of ndir.h.
  6441. # -DSIGTYPE=int         If your signal handlers
  6442. #                       return int, not void.
  6443. # -DNO_MTIO             If you lack sys/mtio.h
  6444. #                       (magtape ioctls).
  6445. # -DNO_REMOTE           If you do not have a remote shell
  6446. #                       or rexec.
  6447. # -DUSE_REXEC           To use rexec for remote tape
  6448. #                       operations instead of
  6449. #                       forking rsh or remsh.
  6450. # -DVPRINTF_MISSING     If you lack vprintf function
  6451. #                       (but have _doprnt).
  6452. # -DDOPRNT_MISSING      If you lack _doprnt function.
  6453. #                       Also need to define
  6454. #                       -DVPRINTF_MISSING.
  6455. # -DFTIME_MISSING       If you lack ftime system call.
  6456. # -DSTRSTR_MISSING      If you lack strstr function.
  6457. # -DVALLOC_MISSING      If you lack valloc function.
  6458. # -DMKDIR_MISSING       If you lack mkdir and
  6459. #                       rmdir system calls.
  6460. # -DRENAME_MISSING      If you lack rename system call.
  6461. # -DFTRUNCATE_MISSING   If you lack frtruncate
  6462. #                       system call.
  6463. # -DV7                  On Version 7 Unix (not
  6464. #                       tested in a long time).
  6465. # -DEMUL_OPEN3          If you lack a 3-argument version
  6466. #                       of open, and want to emulate it
  6467. #                       with system calls you do have.
  6468. # -DNO_OPEN3            If you lack the 3-argument open
  6469. #                       and want to disable the tar -k
  6470. #                       option instead of emulating open.
  6471. # -DXENIX               If you have sys/inode.h
  6472. #                       and need it 94 to be included.
  6473.  
  6474. DEFS =  -DSIGTYPE=int -DDIRENT -DSTRSTR_MISSING \
  6475.         -DVPRINTF_MISSING -DBSD42
  6476. # Set this to rtapelib.o unless you defined NO_REMOTE,
  6477. # in which case make it empty.
  6478. RTAPELIB = rtapelib.o
  6479. LIBS =
  6480. DEF_AR_FILE = /dev/rmt8
  6481. DEFBLOCKING = 20
  6482.  
  6483. CDEBUG = -g
  6484. CFLAGS = $(CDEBUG) -I. -I$(srcdir) $(DEFS) \
  6485.         -DDEF_AR_FILE=\"$(DEF_AR_FILE)\" \
  6486.         -DDEFBLOCKING=$(DEFBLOCKING)
  6487. LDFLAGS = -g
  6488.  
  6489. prefix = /usr/local
  6490. # Prefix for each installed program,
  6491. # normally empty or `g'.
  6492. binprefix =
  6493.  
  6494. # The directory to install tar in.
  6495. bindir = $(prefix)/bin
  6496.  
  6497. # The directory to install the info files in.
  6498. infodir = $(prefix)/info
  6499.  
  6500. #### End of system configuration section. ####
  6501.  
  6502. SRC1 =  tar.c create.c extract.c buffer.c \
  6503.         getoldopt.c update.c gnu.c mangle.c
  6504. SRC2 =  version.c list.c names.c diffarch.c \
  6505.         port.c wildmat.c getopt.c
  6506. SRC3 =  getopt1.c regex.c getdate.y
  6507. SRCS =  $(SRC1) $(SRC2) $(SRC3)
  6508. OBJ1 =  tar.o create.o extract.o buffer.o \
  6509.         getoldopt.o update.o gnu.o mangle.o
  6510. OBJ2 =  version.o list.o names.o diffarch.o \
  6511.         port.o wildmat.o getopt.o
  6512. OBJ3 =  getopt1.o regex.o getdate.o $(RTAPELIB)
  6513. OBJS =  $(OBJ1) $(OBJ2) $(OBJ3)
  6514. AUX =   README COPYING ChangeLog Makefile.in  \
  6515.         makefile.pc configure configure.in \
  6516.         tar.texinfo tar.info* texinfo.tex \
  6517.         tar.h port.h open3.h getopt.h regex.h \
  6518.         rmt.h rmt.c rtapelib.c alloca.c \
  6519.         msd_dir.h msd_dir.c tcexparg.c \
  6520.         level-0 level-1 backup-specs testpad.c
  6521.  
  6522. all:    tar rmt tar.info
  6523.  
  6524. tar:    $(OBJS)
  6525.         $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
  6526.  
  6527. rmt:    rmt.c
  6528.         $(CC) $(CFLAGS) $(LDFLAGS) -o $@ rmt.c
  6529.  
  6530. tar.info: tar.texinfo
  6531.         makeinfo tar.texinfo
  6532.  
  6533. install: all
  6534.         $(INSTALL) tar $(bindir)/$(binprefix)tar
  6535.         -test ! -f rmt || $(INSTALL) rmt /etc/rmt
  6536.         $(INSTALLDATA) $(srcdir)/tar.info* $(infodir)
  6537.  
  6538. $(OBJS): tar.h port.h testpad.h
  6539. regex.o buffer.o tar.o: regex.h
  6540. # getdate.y has 8 shift/reduce conflicts.
  6541.  
  6542. testpad.h: testpad
  6543.         ./testpad
  6544.  
  6545. testpad: testpad.o
  6546.         $(CC) -o $@ testpad.o
  6547.  
  6548. TAGS:   $(SRCS)
  6549.         etags $(SRCS)
  6550.  
  6551. clean:
  6552.         rm -f *.o tar rmt testpad testpad.h core
  6553.  
  6554. distclean: clean
  6555.         rm -f TAGS Makefile config.status
  6556.  
  6557. realclean: distclean
  6558.         rm -f tar.info*
  6559.  
  6560. shar: $(SRCS) $(AUX)
  6561.         shar $(SRCS) $(AUX) | compress \
  6562.           > tar-`sed -e '/version_string/!d' \
  6563.                      -e 's/[^0-9.]*\([0-9.]*\).*/\1/' \
  6564.                      -e q
  6565.                      version.c`.shar.Z
  6566.  
  6567. dist: $(SRCS) $(AUX)
  6568.         echo tar-`sed \
  6569.              -e '/version_string/!d' \
  6570.              -e 's/[^0-9.]*\([0-9.]*\).*/\1/' \
  6571.              -e q
  6572.              version.c` > .fname
  6573.         -rm -rf `cat .fname`
  6574.         mkdir `cat .fname`
  6575.         ln $(SRCS) $(AUX) `cat .fname`
  6576.         -rm -rf `cat .fname` .fname
  6577.         tar chZf `cat .fname`.tar.Z `cat .fname`
  6578.  
  6579. tar.zoo: $(SRCS) $(AUX)
  6580.         -rm -rf tmp.dir
  6581.         -mkdir tmp.dir
  6582.         -rm tar.zoo
  6583.         for X in $(SRCS) $(AUX) ; do \
  6584.             echo $$X ; \
  6585.             sed 's/$$/^M/' $$X \
  6586.             > tmp.dir/$$X ; done
  6587.         cd tmp.dir ; zoo aM ../tar.zoo *
  6588.         -rm -rf tmp.dir
  6589.