home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
InfoMagic Source Code 1993 July
/
THE_SOURCE_CODE_CD_ROM.iso
/
gnu
/
make-3.67
/
make.info-1
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
Macintosh to JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
GNU Info File
|
1993-05-16
|
49.2 KB
|
1,087 lines
This is Info file make.info, produced by Makeinfo-1.54 from the input
file make.texinfo.
This file documents the GNU Make utility, which determines
automatically which pieces of a large program need to be recompiled,
and issues the commands to recompile them.
This is Edition 0.42, last updated 14 May 1993, of `The GNU Make
Manual', for `make', Version 3.66 Beta.
Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software
Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided also
that the section entitled "GNU General Public License" is included
exactly as in the original, and provided that the entire resulting
derived work is distributed under the terms of a permission notice
identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that the text of the translations of the section
entitled "GNU General Public License" must be approved for accuracy by
the Foundation.
File: make.info, Node: Top, Next: Copying, Prev: (dir), Up: (dir)
Make
****
The GNU `make' utility automatically determines which pieces of a
large program need to be recompiled, and issues the commands to
recompile them.
This is Edition 0.42 of the `GNU Make Manual', last updated 14 May
1993 for `make' Version 3.66 Beta.
This manual describes `make' and contains the following chapters:
* Menu:
* Copying::
* Overview:: Overview of `make'.
* Introduction:: An introduction to `make'.
* Makefiles:: Makefiles tell `make' what to do.
* Rules:: Rules describe when a file must be remade.
* Commands:: Commands say how to remake a file.
* Using Variables:: You can use variables to avoid repetition.
* Conditionals:: Use or ignore parts of the makefile based
on the values of variables.
* Functions:: Many powerful ways to manipulate text.
* make Invocation: Running. How to invoke `make' on the command line.
* Implicit Rules:: Use implicit rules to treat many files alike,
based on their file names.
* Archives:: How `make' can update library archives.
* Features:: Features GNU `make' has over other `make's.
* Missing:: What GNU `make' lacks from other `make's.
* Makefile Conventions:: Conventions for makefiles in GNU programs.
* Quick Reference:: A quick reference for experienced users.
* Complex Makefile:: A real example of a straightforward,
but nontrivial, makefile.
* Concept Index:: Index of Concepts
* Name Index:: Index of Functions, Variables, & Directives
-- The Detailed Node Listing --
Overview of `make'
* Preparing:: Preparing and Running Make
* Reading:: On Reading this Text
* Bugs:: Problems and Bugs
An Introduction to Makefiles
* Rule Introduction:: What a rule looks like.
* Simple Makefile:: A Simple Makefile
* How Make Works:: How `make' Processes This Makefile
* Variables Simplify:: Variables Make Makefiles Simpler
* make Deduces:: Letting `make' Deduce the Commands
* Combine By Dependency:: Another Style of Makefile
* Cleanup:: Rules for Cleaning the Directory
Writing Makefiles
* Makefile Contents:: What makefiles contain.
* Makefile Names:: How to name your makefile.
* Include:: How one makefile can use another makefile.
* MAKEFILES Variable:: The environment can specify extra makefiles.
* Remaking Makefiles:: How makefiles get remade.
* Overriding Makefiles:: How to override part of one makefile
with another makefile.
Writing Rules
* Rule Example:: An example explained.
* Rule Syntax:: General syntax explained.
* Wildcards:: Using wildcard characters such as `*'.
* Directory Search:: Searching other directories for source files.
* Phony Targets:: Using a target that is not a real file's name.
* Force Targets:: You can use a target without commands
or dependencies to mark other
targets as phony.
* Empty Targets:: When only the date matters and the
files are empty.
* Special Targets:: Targets with special built-in meanings.
* Multiple Targets:: When to make use of several targets in a rule.
* Multiple Rules:: How to use several rules with the same target.
* Static Pattern:: Static pattern rules apply to multiple targets
and can vary the dependencies according to
the target name.
* Double-Colon:: How to use a special kind of rule to allow
several independent rules for one target.
* Automatic Dependencies:: How to automatically generate rules giving
dependencies from the source files themselves.
Using Wildcard Characters in File Names
* Wildcard Examples:: Several examples
* Wildcard Pitfall:: Problems to avoid.
* Wildcard Function:: How to cause wildcard expansion where
it does not normally take place.
Searching Directories for Dependencies
* General Search:: Specifying a search path that applies
to every dependency.
* Selective Search:: Specifying a search path
for a specified class of names.
* Commands/Search:: How to write shell commands that work together
with search paths.
* Implicit/Search:: How search paths affect implicit rules.
* Libraries/Search:: Directory search for link libraries.
Static Pattern Rules
* Static Usage:: The syntax of static pattern rules.
* Static versus Implicit:: When are they better than implicit rules?
Writing the Commands in Rules
* Echoing:: How to control when commands are echoed.
* Execution:: How commands are executed.
* Parallel:: How commands can be executed in parallel.
* Errors:: What happens after a command execution error.
* Interrupts:: What happens when a command is interrupted.
* Recursion:: Invoking `make' from makefiles.
* Sequences:: Defining canned sequences of commands.
* Empty Commands:: Defining useful, do-nothing commands.
Recursive Use of `make'
* MAKE Variable:: The special effects of using `$(MAKE)'.
* Variables/Recursion:: How to communicate variables to a sub-`make'.
* Options/Recursion:: How to communicate options to a sub-`make'.
* -w Option:: How the `-w' or `--print-directory' option
helps debug use of recursive `make' commands.
How to Use Variables
* Reference:: How to use the value of a variable.
* Flavors:: Variables come in two flavors.
* Advanced:: Advanced features for referencing a variable.
* Values:: All the ways variables get their values.
* Setting:: How to set a variable in the makefile.
* Appending:: How to append more text to the old value
of a variable.
* Override Directive:: How to set a variable in the makefile even if
the user has set it with a command argument.
* Defining:: An alternate way to set a variable
to a verbatim string.
* Environment:: Variable values can come from the environment.
Advanced Features for Reference to Variables
* Substitution Refs:: Referencing a variable with
substitutions on the value.
* Computed Names:: Computing the name of the variable to refer to.
Conditional Parts of Makefiles
* Conditional Example:: Example of a conditional
* Conditional Syntax:: The syntax of conditionals.
* Testing Flags:: Conditionals that test flags.
Functions for Transforming Text
* Syntax of Functions:: How to write a function call.
* Text Functions:: General-purpose text manipulation functions.
* Filename Functions:: Functions for manipulating file names.
* Foreach Function:: Repeat some text with controlled variation.
* Origin Function:: Find where a variable got its value.
* Shell Function:: Substitute the output of a shell command.
How to Run `make'
* Makefile Arguments:: How to specify which makefile to use.
* Goals:: How to use goal arguments to specify which
parts of the makefile to use.
* Instead of Execution:: How to use mode flags to specify what
kind of thing to do with the commands
in the makefile other than simply
execute them.
* Avoiding Compilation:: How to avoid recompiling certain files.
* Overriding:: How to override a variable to specify
an alternate compiler and other things.
* Testing:: How to proceed past some errors, to
test compilation.
* Options Summary:: Summary of Options
Using Implicit Rules
* Using Implicit:: How to use an existing implicit rule
to get the commands for updating a file.
* Catalogue of Rules:: A list of built-in implicit rules.
* Implicit Variables:: How to change what predefined rules do.
* Chained Rules:: How to use a chain of implicit rules.
* Pattern Rules:: How to define new implicit rules.
* Last Resort:: How to defining commands for rules
which cannot find any.
* Suffix Rules:: The old-fashioned style of implicit rule.
* Search Algorithm:: The precise algorithm for applying
implicit rules.
Defining and Redefining Pattern Rules
* Pattern Intro:: An introduction to pattern rules.
* Pattern Examples:: Examples of pattern rules.
* Automatic:: How to use automatic variables in the
commands of implicit rules.
* Pattern Match:: How patterns match.
* Match-Anything Rules:: Precautions you should take prior to
defining rules that can match any
target file whatever.
* Canceling Rules:: How to override or cancel built-in rules.
Using `make' to Update Archive Files
* Archive Members:: Archive members as targets.
* Archive Update:: The implicit rule for archive member targets.
* Archive Suffix Rules:: You can write a special kind of suffix rule
for updating archives.
Implicit Rule for Archive Member Targets
* Archive Symbols:: How to update archive symbol directories.
File: make.info, Node: Copying, Next: Overview, Prev: Top, Up: Top
GNU GENERAL PUBLIC LICENSE
**************************
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
========
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it in
new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software,
and (2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
1. This License applies to any program or other work which contains a
notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program",
below, refers to any such program or work, and a "work based on
the Program" means either the Program or any derivative work under
copyright law: that is to say, a work containing the Program or a
portion of it, either verbatim or with modifications and/or
translated into another language. (Hereinafter, translation is
included without limitation in the term "modification".) Each
licensee is addressed as "you".
Activities other than copying, distribution and modification are
not covered by this License; they are outside its scope. The act
of running the Program is not restricted, and the output from the
Program is covered only if its contents constitute a work based on
the Program (independent of having been made by running the
Program). Whether that is true depends on what the Program does.
2. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any
warranty; and give any other recipients of the Program a copy of
this License along with the Program.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange
for a fee.
3. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a. You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b. You must cause any work that you distribute or publish, that
in whole or in part contains or is derived from the Program
or any part thereof, to be licensed as a whole at no charge
to all third parties under the terms of this License.
c. If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display
an announcement including an appropriate copyright notice and
a notice that there is no warranty (or else, saying that you
provide a warranty) and that users may redistribute the
program under these conditions, and telling the user how to
view a copy of this License. (Exception: if the Program
itself is interactive but does not normally print such an
announcement, your work based on the Program is not required
to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the
Program, and can be reasonably considered independent and separate
works in themselves, then this License, and its terms, do not
apply to those sections when you distribute them as separate
works. But when you distribute the same sections as part of a
whole which is a work based on the Program, the distribution of
the whole must be on the terms of this License, whose permissions
for other licensees extend to the entire whole, and thus to each
and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or
contest your rights to work written entirely by you; rather, the
intent is to exercise the right to control the distribution of
derivative or collective works based on the Program.
In addition, mere aggregation of another work not based on the
Program with the Program (or with a work based on the Program) on
a volume of a storage or distribution medium does not bring the
other work under the scope of this License.
4. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms
of Sections 1 and 2 above provided that you also do one of the
following:
a. Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Sections 1 and 2 above on a medium customarily used for
software interchange; or,
b. Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange; or,
c. Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with
such an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete
source code means all the source code for all modules it contains,
plus any associated interface definition files, plus the scripts
used to control compilation and installation of the executable.
However, as a special exception, the source code distributed need
not include anything that is normally distributed (in either
source or binary form) with the major components (compiler,
kernel, and so on) of the operating system on which the executable
runs, unless that component itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
5. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this
License. However, parties who have received copies, or rights,
from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
6. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify
or distribute the Program or its derivative works. These actions
are prohibited by law if you do not accept this License.
Therefore, by modifying or distributing the Program (or any work
based on the Program), you indicate your acceptance of this
License to do so, and all its terms and conditions for copying,
distributing or modifying the Program or works based on it.
7. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program
subject to these terms and conditions. You may not impose any
further restrictions on the recipients' exercise of the rights
granted herein. You are not responsible for enforcing compliance
by third parties to this License.
8. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent
issues), conditions are imposed on you (whether by court order,
agreement or otherwise) that contradict the conditions of this
License, they do not excuse you from the conditions of this
License. If you cannot distribute so as to satisfy simultaneously
your obligations under this License and any other pertinent
obligations, then as a consequence you may not distribute the
Program at all. For example, if a patent license would not permit
royalty-free redistribution of the Program by all those who
receive copies directly or indirectly through you, then the only
way you could satisfy both it and this License would be to refrain
entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable
under any particular circumstance, the balance of the section is
intended to apply and the section as a whole is intended to apply
in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of
any such claims; this section has the sole purpose of protecting
the integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is
willing to distribute software through any other system and a
licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed
to be a consequence of the rest of this License.
9. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces,
the original copyright holder who places the Program under this
License may add an explicit geographical distribution limitation
excluding those countries, so that distribution is permitted only
in or among countries not thus excluded. In such case, this
License incorporates the limitation as if written in the body of
this License.
10. The Free Software Foundation may publish revised and/or new
versions of the General Public License from time to time. Such
new versions will be similar in spirit to the present version, but
may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies a version number of this License which applies
to it and "any later version", you have the option of following
the terms and conditions either of that version or of any later
version published by the Free Software Foundation. If the Program
does not specify a version number of this License, you may choose
any version ever published by the Free Software Foundation.
11. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the
author to ask for permission. For software which is copyrighted
by the Free Software Foundation, write to the Free Software
Foundation; we sometimes make exceptions for this. Our decision
will be guided by the two goals of preserving the free status of
all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
12. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
SERVICING, REPAIR OR CORRECTION.
13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
=============================================
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
ONE LINE TO GIVE THE PROGRAM'S NAME AND AN IDEA OF WHAT IT DOES.
Copyright (C) 19YY NAME OF AUTHOR
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper
mail.
If the program is interactive, make it output a short notice like
this when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
type `show w'. This is free software, and you are welcome
to redistribute it under certain conditions; type `show c'
for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or
your school, if any, to sign a "copyright disclaimer" for the program,
if necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright
interest in the program `Gnomovision'
(which makes passes at compilers) written
by James Hacker.
SIGNATURE OF TY COON, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your
program into proprietary programs. If your program is a subroutine
library, you may consider it more useful to permit linking proprietary
applications with the library. If this is what you want to do, use the
GNU Library General Public License instead of this License.
File: make.info, Node: Overview, Next: Introduction, Prev: Copying, Up: Top
Overview of `make'
******************
The `make' utility automatically determines which pieces of a large
program need to be recompiled, and issues commands to recompile them.
This manual describes GNU `make', which was implemented by Richard
Stallman and Roland McGrath. GNU `make' conforms to section 6.2 of
`IEEE Standard 1003.2-1992' (POSIX.2).
Our examples show C programs, since they are most common, but you
can use `make' with any programming language whose compiler can be run
with a shell command. Indeed, `make' is not limited to programs. You
can use it to describe any task where some files must be updated
automatically from others whenever the others change.
* Menu:
* Preparing:: Preparing and Running Make
* Reading:: On Reading this Text
* Bugs:: Problems and Bugs
File: make.info, Node: Preparing, Next: Reading, Up: Overview
Preparing and Running Make
==========================
To prepare to use `make', you must write a file called the
"makefile" that describes the relationships among files in your program
and provides commands for updating each file. In a program, typically,
the executable file is updated from object files, which are in turn
made by compiling source files.
Once a suitable makefile exists, each time you change some source
files, this simple shell command:
make
suffices to perform all necessary recompilations. The `make' program
uses the makefile data base and the last-modification times of the
files to decide which of the files need to be updated. For each of
those files, it issues the commands recorded in the data base.
You can provide command line arguments to `make' to control which
files should be recompiled, or how. *Note How to Run `make': Running.
File: make.info, Node: Reading, Next: Bugs, Prev: Preparing, Up: Overview
How to Read This Manual
=======================
If you are new to `make', or are looking for a general introduction,
read the first few sections of each chapter, skipping the later
sections. In each chapter, the first few sections contain introductory
or general information and the later sections contain specialized or
technical information. The exception is the second chapter, *Note An
Introduction to Makefiles: Introduction, all of which is introductory.
If you are familiar with other `make' programs, see *Note Features
of GNU `make': Features, which lists the enhancements GNU `make' has,
and *Note Incompatibilities and Missing Features: Missing, which
explains the few things GNU `make' lacks that others have.
For a quick summary, see *Note Options Summary::, *Note Quick
Reference::, and *Note Special Targets::.
File: make.info, Node: Bugs, Prev: Reading, Up: Overview
Problems and Bugs
=================
If you have problems with GNU `make' or think you've found a bug,
please report it to the developers; we cannot promise to do anything but
we might well want to fix it.
Before reporting a bug, make sure you've actually found a real bug.
Carefully reread the documentation and see if it really says you can do
what you're trying to do. If it's not clear whether you should be able
to do something or not, report that too; it's a bug in the
documentation!
Before reporting a bug or trying to fix it yourself, try to isolate
it to the smallest possible makefile that reproduces the problem. Then
send us the makefile and the exact results `make' gave you. Also say
what you expected to occur; this will help us decide whether the
problem was really in the documentation.
Once you've got a precise problem, please send electronic mail either
through the Internet or via UUCP:
Internet address:
bug-gnu-utils@prep.ai.mit.edu
UUCP path:
mit-eddie!prep.ai.mit.edu!bug-gnu-utils
Please include the version number of `make' you are using. You can get
this information with the command `make --version'. Be sure also to
include the type of machine and operating system you are using. If
possible, include the contents of the file `config.h' that is generated
by the configuration process.
Non-bug suggestions are always welcome as well. If you have
questions about things that are unclear in the documentation or are
just obscure features, contact Roland McGrath; he will try to help you
out, although he may not have time to fix the problem.
You can send electronic mail to Roland McGrath either through the
Internet or via UUCP:
Internet address:
roland@prep.ai.mit.edu
UUCP path:
mit-eddie!prep.ai.mit.edu!roland
File: make.info, Node: Introduction, Next: Makefiles, Prev: Overview, Up: Top
An Introduction to Makefiles
****************************
You need a file called a "makefile" to tell `make' what to do. Most
often, the makefile tells `make' how to compile and link a program.
In this chapter, we will discuss a simple makefile that describes
how to compile and link a text editor which consists of eight C source
files and three header files. The makefile can also tell `make' how to
run miscellaneous commands when explicitly asked (for example, to remove
certain files as a clean-up operation). To see a more complex example
of a makefile, see *Note Complex Makefile::.
When `make' recompiles the editor, each changed C source file must
be recompiled. If a header file has changed, each C source file that
includes the header file must be recompiled to be safe. Each
compilation produces an object file corresponding to the source file.
Finally, if any source file has been recompiled, all the object files,
whether newly made or saved from previous compilations, must be linked
together to produce the new executable editor.
* Menu:
* Rule Introduction:: What a rule looks like.
* Simple Makefile:: A Simple Makefile
* How Make Works:: How `make' Processes This Makefile
* Variables Simplify:: Variables Make Makefiles Simpler
* make Deduces:: Letting `make' Deduce the Commands
* Combine By Dependency:: Another Style of Makefile
* Cleanup:: Rules for Cleaning the Directory
File: make.info, Node: Rule Introduction, Next: Simple Makefile, Up: Introduction
What a Rule Looks Like
======================
A simple makefile consists of "rules" with the following shape:
TARGET ... : DEPENDENCIES ...
COMMAND
...
...
A "target" is usually the name of a file that is generated by a
program; examples of targets are executable or object files. A target
can also be the name of an action to carry out, such as `clean' (*note
Phony Targets::.).
A "dependency" is a file that is used as input to create the target.
A target often depends on several files.
A "command" is an action that `make' carries out. A rule may have
more than one command, each on its own line. *Please note:* you need
to put a tab character at the beginning of every command line! This is
an obscurity that catches the unwary.
Usually a command is in a rule with dependencies and serves to
create a target file if any of the dependencies change. However, the
rule that specifies commands for the target need not have dependencies.
For example, the rule containing the delete command associated with the
target `clean' does not have dependencies.
A "rule", then, explains how and when to remake certain files which
are the targets of the particular rule. `make' carries out the
commands on the dependencies to create or update the target. A rule
can also explain how and when to carry out an action. *Note Writing
Rules: Rules.
A makefile may contain other text besides rules, but a simple
makefile need only contain rules. Rules may look somewhat more
complicated than shown in this template, but all fit the pattern more
or less.
File: make.info, Node: Simple Makefile, Next: How Make Works, Prev: Rule Introduction, Up: Introduction
A Simple Makefile
=================
Here is a straightforward makefile that describes the way an
executable file called `edit' depends on eight object files which, in
turn, depend on eight C source and three header files.
In this example, all the C files include `defs.h', but only those
defining editing commands include `command.h', and only low level files
that change the editor buffer include `buffer.h'.
edit : main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
cc -o edit main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
main.o : main.c defs.h
cc -c main.c
kbd.o : kbd.c defs.h command.h
cc -c kbd.c
command.o : command.c defs.h command.h
cc -c command.c
display.o : display.c defs.h buffer.h
cc -c display.c
insert.o : insert.c defs.h buffer.h
cc -c insert.c
search.o : search.c defs.h buffer.h
cc -c search.c
files.o : files.c defs.h buffer.h command.h
cc -c files.c
utils.o : utils.c defs.h
cc -c utils.c
clean :
rm edit main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
We split each long line into two lines using backslash-newline; this is
like using one long line, but is easier to read.
To use this makefile to create the executable file called `edit',
type:
make
To use this makefile to delete the executable file and all the object
files from the directory, type:
make clean
In the example makefile, the targets include the executable file
`edit', and the object files `main.o' and `kbd.o'. The dependencies
are files such as `main.c' and `defs.h'. In fact, each `.o' file is
both a target and a dependency. Commands include `cc -c main.c' and
`cc -c kbd.c'.
When a target is a file, it needs to be recompiled or relinked if any
of its dependencies change. In addition, any dependencies that are
themselves automatically generated should be updated first. In this
example, `edit' depends on each of the eight object files; the object
file `main.o' depends on the source file `main.c' and on the header
file `defs.h'.
A shell command follows each line that contains a target and
dependencies. These shell commands say how to update the target file.
A tab character must come at the beginning of every command line to
distinguish commands lines from other lines in the makefile. (Bear in
mind that `make' does not know anything about how the commands work.
It is up to you to supply commands that will update the target file
properly. All `make' does is execute the commands in the rule you have
specified when the target file needs to be updated.)
The target `clean' is not a file, but merely the name of an action.
Since you normally do not want to carry out the actions in this rule,
`clean' is not a dependency of any other rule. Consequently, `make'
never does anything with it unless you tell it specifically. Note that
this rule not only is not a dependency, it also does not have any
dependencies, so the only purpose of the rule is to run the specified
commands. Targets that do not refer to files but are just actions are
called "phony targets". *Note Phony Targets::, for information about
this kind of target. *Note Errors in Commands: Errors, to see how to
cause `make' to ignore errors from `rm' or any other command.
File: make.info, Node: How Make Works, Next: Variables Simplify, Prev: Simple Makefile, Up: Introduction
How `make' Processes a Makefile
===============================
By default, `make' starts with the first rule (not counting rules
whose target names start with `.'). This is called the "default goal".
("Goals" are the targets that `make' strives ultimately to update.
*Note Arguments to Specify the Goals: Goals.)
In the simple example of the previous section, the default goal is to
update the executable program `edit'; therefore, we put that rule first.
Thus, when you give the command:
make
`make' reads the makefile in the current directory and begins by
processing the first rule. In the example, this rule is for relinking
`edit'; but before `make' can fully process this rule, it must process
the rules for the files that `edit' depends on, which in this case are
the object files. Each of these files is processed according to its
own rule. These rules say to update each `.o' file by compiling its
source file. The recompilation must be done if the source file, or any
of the header files named as dependencies, is more recent than the
object file, or if the object file does not exist.
The other rules are processed because their targets appear as
dependencies of the goal. If some other rule is not depended on by the
goal (or anything it depends on, etc.), that rule is not processed,
unless you tell `make' to do so (with a command such as `make clean').
Before recompiling an object file, `make' considers updating its
dependencies, the source file and header files. This makefile does not
specify anything to be done for them--the `.c' and `.h' files are not
the targets of any rules--so `make' does nothing for these files. But
`make' would update automatically generated C programs, such as those
made by Bison or Yacc, by their own rules at this time.
After recompiling whichever object files need it, `make' decides
whether to relink `edit'. This must be done if the file `edit' does
not exist, or if any of the object files are newer than it. If an
object file was just recompiled, it is now newer than `edit', so `edit'
is relinked.
Thus, if we change the file `insert.c' and run `make', `make' will
compile that file to update `insert.o', and then link `edit'. If we
change the file `command.h' and run `make', `make' will recompile the
object files `kbd.o', `command.o' and `files.o' and then link the file
`edit'.
File: make.info, Node: Variables Simplify, Next: make Deduces, Prev: How Make Works, Up: Introduction
Variables Make Makefiles Simpler
================================
In our example, we had to list all the object files twice in the
rule for `edit' (repeated here):
edit : main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
cc -o edit main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
Such duplication is error-prone; if a new object file is added to the
system, we might add it to one list and forget the other. We can
eliminate the risk and simplify the makefile by using a variable.
"Variables" allow a text string to be defined once and substituted in
multiple places later (*note How to Use Variables: Using Variables.).
It is standard practice for every makefile to have a variable named
`objects', `OBJECTS', `objs', `OBJS', `obj', or `OBJ' which is a list
of all object file names. We would define such a variable `objects'
with a line like this in the makefile:
objects = main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
Then, each place we want to put a list of the object file names, we can
substitute the variable's value by writing `$(objects)' (*note How to
Use Variables: Using Variables.).
Here is how the complete simple makefile looks when you use a
variable for the object files:
objects = main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
edit : $(objects)
cc -o edit $(objects)
main.o : main.c defs.h
cc -c main.c
kbd.o : kbd.c defs.h command.h
cc -c kbd.c
command.o : command.c defs.h command.h
cc -c command.c
display.o : display.c defs.h buffer.h
cc -c display.c
insert.o : insert.c defs.h buffer.h
cc -c insert.c
search.o : search.c defs.h buffer.h
cc -c search.c
files.o : files.c defs.h buffer.h command.h
cc -c files.c
utils.o : utils.c defs.h
cc -c utils.c
clean :
rm edit $(objects)
File: make.info, Node: make Deduces, Next: Combine By Dependency, Prev: Variables Simplify, Up: Introduction
Letting `make' Deduce the Commands
==================================
It is not necessary to spell out the commands for compiling the
individual C source files, because `make' can figure them out: it has an
"implicit rule" for updating a `.o' file from a correspondingly named
`.c' file using a `cc -c' command. For example, it will use the
command `cc -c main.c -o main.o' to compile `main.c' into `main.o'. We
can therefore omit the commands from the rules for the object files.
*Note Using Implicit Rules: Implicit Rules.
When a `.c' file is used automatically in this way, it is also
automatically added to the list of dependencies. We can therefore omit
the `.c' files from the dependencies, provided we omit the commands.
Here is the entire example, with both of these changes, and a
variable `objects' as suggested above:
objects = main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
edit : $(objects)
cc -o edit $(objects)
main.o : defs.h
kbd.o : defs.h command.h
command.o : defs.h command.h
display.o : defs.h buffer.h
insert.o : defs.h buffer.h
search.o : defs.h buffer.h
files.o : defs.h buffer.h command.h
utils.o : defs.h
.PHONY : clean
clean :
-rm edit $(objects)
This is how we would write the makefile in actual practice. (The
complications associated with `clean' are described elsewhere. See
*Note Phony Targets::, and *Note Errors in Commands: Errors.)
Because implicit rules are so convenient, they are important. You
will see them used frequently.
File: make.info, Node: Combine By Dependency, Next: Cleanup, Prev: make Deduces, Up: Introduction
Another Style of Makefile
=========================
When the objects of a makefile are created only by implicit rules, an
alternative style of makefile is possible. In this style of makefile,
you group entries by their dependencies instead of by their targets.
Here is what one looks like:
objects = main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
edit : $(objects)
cc -o edit $(objects)
$(objects) : defs.h
kbd.o command.o files.o : command.h
display.o insert.o search.o files.o : buffer.h
Here `defs.h' is given as a dependency of all the object files;
`command.h' and `buffer.h' are dependencies of the specific object
files listed for them.
Whether this is better is a matter of taste: it is more compact, but
some people dislike it because they find it clearer to put all the
information about each target in one place.