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 ln
, rm
, mv
, and
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
example, BISONFLAGS
. (The name CFLAGS
is an exception to
this rule, but we keep it because it is standard.) Use CPPFLAGS
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 ld
.
If there are C compiler options that must be used for proper
compilation of certain files, do not include them in CFLAGS
.
Users expect to be able to specify CFLAGS
freely themselves.
Instead, arrange to pass the necessary options to the C compiler
independently of 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.
Put CFLAGS
last in the compilation command, after other variables
containing compiler options, so the user can use CFLAGS
to
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_PROGRAM
and 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.