; CC — the name of the compiler. ; DEBUG — the debugging flag. This is
-g in both g++ and cxx. The purpose
of the flag is to include debugging
information into the executable, so
that you can use utilities like gdb to
debug the code. ; LFLAGS — the flags used in linking.
As it turns out, you don’t need any
special flags for linking. The option
listed is -Wall, which tells the compiler
to print all warnings. But, that’s fine.
We can use that. ; CFLAGS — the flags used in compil-
ing and creating object files. This
includes both -Wall and -c. The -c
option is needed to create object
files—that is, .o files.
COMMON VARIABLES FOR C++ PROGRAMMING
existed prior to calling make will exist
within make as variables and, thus, are
invoked the same way as variables. You
can specify a variable from the command line as well. Simply add it to the
end of your make command, and it will
be used within the make execution.
If, at some point, you need to alter
the data stored in a variable temporarily, there is a very simple way to
substitute in this new data without
overwriting the variable. It’s done
using the following format:
$(VARNAME:find=replace)
where find is the substring you are trying to find, and replace is the string to
replace it with. So, for instance:
LETTERS = abcxyz xyzabc xyz print: echo $(LETTERS:xyz=def)
will produce the output abcdef xyzabc def.
Suffix Rules
In certain situations, you will find that
the rules for a certain file type are
identical except for the filename. For
instance, a lot of times in a C project,
you will see rules like this:
file.o: file.c cc -O -Wall file.c
because for every .c file, you need to
make the intermediate .o file, so that
the end binary then can be built.
Suffix rules are a way of minimizing
the amount of time you spend writing
out rules and the number of rules in
your makefile. In order to use suffix
rules, you need to tell make which file
suffixes are considered significant
(suffix rules won’t work unless the
WWW.LINUXJOURNAL.COM SEPTEMBER 2011 | 81