home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
gnu
/
info
/
make.info-4
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-11-12
|
50KB
|
955 lines
This is Info file make.info, produced by Makeinfo-1.55 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.47, last updated 1 November 1994, of `The GNU Make
Manual', for `make', Version 3.72 Beta.
Copyright (C) 1988, '89, '90, '91, '92, '93, '94 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 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 this permission notice may be stated in a
translation approved by the Free Software Foundation.
File: make.info, Node: Override Directive, Next: Defining, Prev: Appending, Up: Using Variables
The `override' Directive
========================
If a variable has been set with a command argument (*note Overriding
Variables: Overriding.), then ordinary assignments in the makefile are
ignored. If you want to set the variable in the makefile even though
it was set with a command argument, you can use an `override'
directive, which is a line that looks like this:
override VARIABLE = VALUE
override VARIABLE := VALUE
To append more text to a variable defined on the command line, use:
override VARIABLE += MORE TEXT
*Note Appending More Text to Variables: Appending.
The `override' directive was not invented for escalation in the war
between makefiles and command arguments. It was invented so you can
alter and add to values that the user specifies with command arguments.
For example, suppose you always want the `-g' switch when you run the
C compiler, but you would like to allow the user to specify the other
switches with a command argument just as usual. You could use this
`override' directive:
override CFLAGS += -g
You can also use `override' directives with `define' directives.
This is done as you might expect:
override define foo
bar
endef
*Note Defining Variables Verbatim: Defining.
File: make.info, Node: Defining, Next: Environment, Prev: Override Directive, Up: Using Variables
Defining Variables Verbatim
===========================
Another way to set the value of a variable is to use the `define'
directive. This directive has an unusual syntax which allows newline
characters to be included in the value, which is convenient for defining
canned sequences of commands (*note Defining Canned Command Sequences:
Sequences.).
The `define' directive is followed on the same line by the name of
the variable and nothing more. The value to give the variable appears
on the following lines. The end of the value is marked by a line
containing just the word `endef'. Aside from this difference in
syntax, `define' works just like `=': it creates a recursively-expanded
variable (*note The Two Flavors of Variables: Flavors.). The variable
name may contain function and variable references, which are expanded
when the directive is read to find the actual variable name to use.
define two-lines
echo foo
echo $(bar)
endef
The value in an ordinary assignment cannot contain a newline; but the
newlines that separate the lines of the value in a `define' become part
of the variable's value (except for the final newline which precedes
the `endef' and is not considered part of the value).
The previous example is functionally equivalent to this:
two-lines = echo foo; echo $(bar)
since two commands separated by semicolon behave much like two separate
shell commands. However, note that using two separate lines means
`make' will invoke the shell twice, running an independent subshell for
each line. *Note Command Execution: Execution.
If you want variable definitions made with `define' to take
precedence over command-line variable definitions, you can use the
`override' directive together with `define':
override define two-lines
foo
$(bar)
endef
*Note The `override' Directive: Override Directive.
File: make.info, Node: Environment, Prev: Defining, Up: Using Variables
Variables from the Environment
==============================
Variables in `make' can come from the environment in which `make' is
run. Every environment variable that `make' sees when it starts up is
transformed into a `make' variable with the same name and value. But
an explicit assignment in the makefile, or with a command argument,
overrides the environment. (If the `-e' flag is specified, then values
from the environment override assignments in the makefile. *Note
Summary of Options: Options Summary. But this is not recommended
practice.)
Thus, by setting the variable `CFLAGS' in your environment, you can
cause all C compilations in most makefiles to use the compiler switches
you prefer. This is safe for variables with standard or conventional
meanings because you know that no makefile will use them for other
things. (But this is not totally reliable; some makefiles set `CFLAGS'
explicitly and therefore are not affected by the value in the
environment.)
When `make' is invoked recursively, variables defined in the outer
invocation can be passed to inner invocations through the environment
(*note Recursive Use of `make': Recursion.). By default, only
variables that came from the environment or the command line are passed
to recursive invocations. You can use the `export' directive to pass
other variables. *Note Communicating Variables to a Sub-`make':
Variables/Recursion, for full details.
Other use of variables from the environment is not recommended. It
is not wise for makefiles to depend for their functioning on
environment variables set up outside their control, since this would
cause different users to get different results from the same makefile.
This is against the whole purpose of most makefiles.
Such problems would be especially likely with the variable `SHELL',
which is normally present in the environment to specify the user's
choice of interactive shell. It would be very undesirable for this
choice to affect `make'. So `make' ignores the environment value of
`SHELL'.
File: make.info, Node: Conditionals, Next: Functions, Prev: Using Variables, Up: Top
Conditional Parts of Makefiles
******************************
A "conditional" causes part of a makefile to be obeyed or ignored
depending on the values of variables. Conditionals can compare the
value of one variable to another, or the value of a variable to a
constant string. Conditionals control what `make' actually "sees" in
the makefile, so they *cannot* be used to control shell commands at the
time of execution.
* Menu:
* Conditional Example:: Example of a conditional
* Conditional Syntax:: The syntax of conditionals.
* Testing Flags:: Conditionals that test flags.
File: make.info, Node: Conditional Example, Next: Conditional Syntax, Up: Conditionals
Example of a Conditional
========================
The following example of a conditional tells `make' to use one set
of libraries if the `CC' variable is `gcc', and a different set of
libraries otherwise. It works by controlling which of two command
lines will be used as the command for a rule. The result is that
`CC=gcc' as an argument to `make' changes not only which compiler is
used but also which libraries are linked.
libs_for_gcc = -lgnu
normal_libs =
foo: $(objects)
ifeq ($(CC),gcc)
$(CC) -o foo $(objects) $(libs_for_gcc)
else
$(CC) -o foo $(objects) $(normal_libs)
endif
This conditional uses three directives: one `ifeq', one `else' and
one `endif'.
The `ifeq' directive begins the conditional, and specifies the
conditi