make: Command Variables

1 
1 16.3 Variables for Specifying Commands
1 ======================================
1 
1 Makefiles should provide variables for overriding certain commands,
1 options, and so on.
1 
1    In particular, you should run most utility programs via variables.
1 Thus, if you use Bison, have a variable named 'BISON' whose default
1 value is set with 'BISON = bison', and refer to it with '$(BISON)'
1 whenever you need to use Bison.
1 
1    File management utilities such as 'ln', 'rm', 'mv', and so on, need
1 not be referred to through variables in this way, since users don't need
1 to replace them with other programs.
1 
1    Each program-name variable should come with an options variable that
1 is used to supply options to the program.  Append 'FLAGS' to the
1 program-name variable name to get the options variable name--for
1 example, 'BISONFLAGS'.  (The names 'CFLAGS' for the C compiler, 'YFLAGS'
1 for yacc, and 'LFLAGS' for lex, are exceptions to this rule, but we keep
1 them because they are standard.)  Use 'CPPFLAGS' in any compilation
1 command that runs the preprocessor, and use 'LDFLAGS' in any compilation
1 command that does linking as well as in any direct use of 'ld'.
1 
1    If there are C compiler options that _must_ be used for proper
1 compilation of certain files, do not include them in 'CFLAGS'.  Users
1 expect to be able to specify 'CFLAGS' freely themselves.  Instead,
1 arrange to pass the necessary options to the C compiler independently of
1 'CFLAGS', by writing them explicitly in the compilation commands or by
1 defining an implicit rule, like this:
1 
1      CFLAGS = -g
1      ALL_CFLAGS = -I. $(CFLAGS)
1      .c.o:
1              $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
1 
1    Do include the '-g' option in 'CFLAGS', because that is not
1 _required_ for proper compilation.  You can consider it a default that
1 is only recommended.  If the package is set up so that it is compiled
1 with GCC by default, then you might as well include '-O' in the default
1 value of 'CFLAGS' as well.
1 
1    Put 'CFLAGS' last in the compilation command, after other variables
1 containing compiler options, so the user can use 'CFLAGS' to override
1 the others.
1 
1    'CFLAGS' should be used in every invocation of the C compiler, both
1 those which do compilation and those which do linking.
1 
1    Every Makefile should define the variable 'INSTALL', which is the
1 basic command for installing a file into the system.
1 
1    Every Makefile should also define the variables 'INSTALL_PROGRAM' and
1 'INSTALL_DATA'.  (The default for 'INSTALL_PROGRAM' should be
1 '$(INSTALL)'; the default for 'INSTALL_DATA' should be '${INSTALL} -m
1 644'.)  Then it should use those variables as the commands for actual
1 installation, for executables and non-executables respectively.  Minimal
1 use of these variables is as follows:
1 
1      $(INSTALL_PROGRAM) foo $(bindir)/foo
1      $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
1 
1    However, it is preferable to support a 'DESTDIR' prefix on the target
1 files, as explained in the next section.
1 
1    It is acceptable, but not required, to install multiple files in one
1 command, with the final argument being a directory, as in:
1 
1      $(INSTALL_PROGRAM) foo bar baz $(bindir)
1