天天看點

MakeFIle [email protected],$^,$<

Makefile  [email protected], $^, $< 

[email protected]  表示目标檔案

$^  表示所有的依賴檔案

$<  表示第一個依賴檔案

$?  表示比目标還要新的依賴檔案清單

如一個目錄下有如下檔案:

$ ls

hello.c  hi.c  main.c  Makefile

按照 Makefile 規則規規矩矩的寫:

main: main.o hello.o hi.o

        gcc -o main main.o hello.o hi.o

main.o: main.c

        cc -c main.c

hello.o: hello.c

        cc -c hello.c

hi.o: hi.c

        cc -c hi.c

clean:

        rm *.o

        rm main

改為用上述符号進行替代:

main: main.o hello.o hi.o

        gcc -o [email protected] $^

main.o: main.c

        cc -c $<

hello.o: hello.c

        cc -c $<

hi.o: hi.c

        cc -c $<

clean:

        rm *.o

        rm main

[email protected]:~/makefile_test/semicolon/real$ make

cc -c main.c

cc -c hello.c

cc -c hi.c

gcc -o main main.o hello.o hi.o

[email protected]:~/makefile_test/semicolon/real$ ls

hello.c  hello.o  hi.c  hi.o  main  main.c  main.o  Makefile

繼續閱讀