執行 make 時出現:
make: Nothing to be done for 'all'.
這不是錯誤,而是表示:
假設專案結構:
b/
├── main.c
├── main.o
├── Makefile
├── temp1/
│ ├── Makefile
│ └── temp1.c
└── temp2/
├── printhello21.c
├── printhello22.c
└── Makefile
頂層 Makefile 可能包含:
all: b
b: main.o temp1/temp1.o temp2/temp2.o
gcc -o b main.o temp1/temp1.o temp2/temp2.o
main.o: main.c
gcc -c main.c
temp1/temp1.o:
$(MAKE) -C temp1
temp2/temp2.o:
$(MAKE) -C temp2
首次執行 make 會編譯所有子目錄並產生 b。再次執行無任何檔案異動時,輸出:
[root@localhost b]# make
for i in temp1 temp2; do make -C $i; done
make[1]: Entering directory `/home/b/temp1'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory `/home/b/temp1'
make[1]: Entering directory `/home/b/temp2'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory `/home/b/temp2'
gcc -o b main.o temp1/temp1.o temp2/temp2.o
[root@localhost b]# ./b
hello_11
hello_12
hello_21
hello_22
make clean 清除中間檔(需 Makefile 定義 clean 目標)。touch *.c 更新原始碼時間戳記。make -B 或 make --always-make 強制重建所有目標。gcc -MMD 自動產生 .d 依賴檔並 include 進 Makefile。