一. 用戶空間
???? 因為實際上進行預處理的只是Gcc工具,而make工具只是一個解決依賴關系的工具。所以問題就簡化成如何通過make向gcc傳遞參數。???? 通過簡單的例子來說明:
hello.c
- #include <stdio.h>
- void main(void) {
- #ifdef DEBUG
- ???? printf("you ask for debug!\n");
- #endif
- ???? printf("we must say goodbye\n");
- ???? return;
- }
- ifeq ($(DEBUG),y)
- CFLAGS := $(CFLAGS) -DDEBUG
- endif
- hello: hello.c
- $(CC) $(CFLAGS) $< -o $@
- [ville@localhost test]$ ls
- hello.c Makefile
- [ville@localhost test]$ make
- cc hello.c -o hello
- [ville@localhost test]$ ./hello
- we must say goodbye
- [ville@localhost test]$ rm hello
- [ville@localhost test]$ ls
- hello.c Makefile
- [ville@localhost test]$ make DEBUG:=y
- cc -DDEBUG hello.c -o hello
- [ville@localhost test]$ ./hello
- you ask for debug!
- we must say goodbye
- [ville@localhost test]$