Article Title: System Compilation: How to pass parameters to the Make command. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
During system compilation, we generally only need to simply input make for execution. But sometimes, we still need to let the make command bring some parameters to the makefile script.
For example, you need to define a macro DEBUG in the code to enable the debugging switch. The Code is as follows:
int main() { int i=9; #ifdef DEBUG i=1; #else i=0; #endif printf("i=%d\n", i); return 0; }
|
Generally, this macro definition can be implemented by directly modifying the source code, but this is obviously not a good solution. Another method is to modify it through makefile, for example:
CFLAGS=-g -Wall -DDEBUG object=myprogall:$objectmyprog:a.c gcc ${CFLAGS} a.c -o ${object}
|
If you do not want to modify the makefile, you can pass the parameters to the make command. Therefore, modify the makefile as follows:
CFLAGS=CFLAGCFLAGS+=-g -Wall -DDEBUG object=myprogall:$objectmyprog:a.c gcc ${CFLAGS} a.c -o ${object}
|
To open the DEBUG macro, enter the make command as follows:
[ychq@ICM3-2 net]$ make CFLAG=-DDEBUG gcc -g -Wall -DDEBUG a.c a.c: In function `main': a.c:9: warning: implicit declaration of function `printf' [ychq@ICM3-2 net]$
|
We can find that the DEBUG macro has been passed in correctly.
Furthermore, we can pass different parameters to make so that make can compile different modules.