Is it possible to put the equivalent of #define VAR
(in a C program) into a makefile, so that one can control which part of the program should be compiled?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
Accordingly to
cc
manpage onlinux
Yes.
Most compilers support command line options for specifying #define's. For Visual C++, this is the /D option.
Edit your
Makefile
to showIf you are using default rules in the Makefile, this should work automatically. If you do not, and are invoking the C compiler explicitely, just make sure you are writing something along the lines of
Even more cute if the fact the
CFLAGS=...
above can be used on the command line rather than written in the Makefile (readman(1)
manual page); this allows for easy reconfiguration of your compilation parameters at last moment, but the parameters won't be kept.Best practices include using
CPPFLAGS
instead ofCFLAGS
, and using+=
instead of=
; however support for these features are not as universal as the above, and depend on your make system.