Because of low reputation, I cannot comment the accepted answer.
I would like to mention the predefined variable CPPFLAGS
.
It might represent a better fit than CFLAGS
or CXXFLAGS
, since it is described by the GNU Make manual as:
Extra flags to give to the C preprocessor and programs that use it (the C and Fortran compilers).
CPPFLAGS
n.o
is made automatically from n.c
with a recipe of the form:
$(CC) $(CPPFLAGS) $(CFLAGS) -c
n.o
is made automatically from n.cc
, n.cpp
, or n.C
with a recipe of the form:
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c
One would use the command make CPPFLAGS=-Dvar=123
to define the desired macro.