How can you define macro as an argument?

I want to define a C macro by passing it as the make argument, which is invoked from the command line.

Reference Information. I want the #define ENABLE_OPT 1 directive to be included in my C source code when I select a specific build option. Thus, I want this to be done using the make command line instead of modifying the source code or makefile.

How can this be achieved? I found that make -DENABLE_OPT=1 -f Makefile throws errors that are "E", "N", etc. Invalid arguments.

+5
source share
1 answer

You can use --eval , which will evaluate the line as a makefile statement:

 make --eval="FLAGS+= -D ENABLE_OPT=1" 

The make FLAGS variable is then used as a compiler argument to compile the code.

+4
source

All Articles