2010年12月27日 星期一

Gnu make - implicit rule 概念

預設你在makefile內不編輯rule的話
gnu make會根據你所定義的target and prerequisites作自動編輯

source code download 

以此範例說明
解壓縮完
下make

nelsonchung@nelsonchung-aspireone:~/ebooks/gnumake/DoTest$ make
gcc -c main.c
gcc -c Eye.c
gcc -c Nose.c
gcc -c Ear.c
gcc -c Mouse.c
cc    -c -o Face.o Face.c
gcc main.o Eye.o Nose.o Ear.o Mouse.o -o main
nelsonchung@nelsonchung-aspireone:~/ebooks/gnumake/DoTest$

藍色部份


因為在makefile裡面沒有特地去寫rule

nelsonchung@nelsonchung-aspireone:~/ebooks/gnumake/DoTest$ cat makefile
all: main.o Eye.o Nose.o Ear.o Mouse.o Face.o
gcc main.o Eye.o Nose.o Ear.o Mouse.o -o main

main.o: main.c
gcc -c main.c
Eye.o: Eye.h
gcc -c Eye.c
Nose.o: Nose.h
gcc -c Nose.c
Ear.o: Ear.h
gcc -c Ear.c
Mouse.o: Mouse.h
gcc -c Mouse.c
Face.o: Face.c

clean:
rm main.o Eye.o Nose.o Ear.o Mouse.o Face.o main

所以gnu make會根據你現在要編譯的是.c, .cpp, .p or other files去啟動相對應的compiler


Reference:
Gnu make 文件第十章
10 Using Implicit Rules


透過Facebook分享

沒有留言: