Makefiles should provide variables for overriding certain commands, options, and so on.
In particular, you should run most utility programs via variables.
Thus, if you use Bison, have a variable named
BISON whose default
value is set with `BISON = bison', and refer to it with
$(BISON) whenever you need to use Bison.
File management utilities such as
so on, need not be referred to through variables in this way, since users
don't need to replace them with other programs.
Each program-name variable should come with an options variable that is
used to supply options to the program. Append `FLAGS' to the
program-name variable name to get the options variable name--for
BISONFLAGS. (The name
CFLAGS is an exception to
this rule, but we keep it because it is standard.) Use
in any compilation command that runs the preprocessor, and use
LDFLAGS in any compilation command that does linking as well as
in any direct use of
If there are C compiler options that must be used for proper
compilation of certain files, do not include them in
Users expect to be able to specify
CFLAGS freely themselves.
Instead, arrange to pass the necessary options to the C compiler
CFLAGS, by writing them explicitly in the
compilation commands or by defining an implicit rule, like this:
CFLAGS = -g ALL_CFLAGS = -I. $(CFLAGS) .c.o: $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
Do include the `-g' option in
CFLAGS, because that is not
required for proper compilation. You can consider it a default
that is only recommended. If the package is set up so that it is
compiled with GCC by default, then you might as well include `-O'
in the default value of
CFLAGS as well.
CFLAGS last in the compilation command, after other variables
containing compiler options, so the user can use
override the others.
Every Makefile should define the variable
INSTALL, which is the
basic command for installing a file into the system.
Every Makefile should also define the variables
INSTALL_DATA. (The default for each of these should be
$(INSTALL).) Then it should use those variables as the commands
for actual installation, for executables and nonexecutables
respectively. Use these variables as follows:
$(INSTALL_PROGRAM) foo $(bindir)/foo $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
Always use a file name, not a directory name, as the second argument of the installation commands. Use a separate command for each file to be installed.
Go to the first, previous, next, last section, table of contents.