Giriş
Sözdizimi olarak
şöyledir.
target: dependency1 dependency2 etc
command to build target
Bir başka gösterim ile
şöyledir.
target: dependencies
actions
target ismi ve komut çıktısı aynı olmalıdır.
Elimizde şöyle bir target
olsun.
program: client.o
gcc client.o -o Client
Bu kullanım şekli biraz tuhaf çünkü program target'ı program isimli bir dosya arar ve bulamaz. Çünkü komutun çıktısı Client isimli bir dosyadır. Dolayısıyla Client her seferinde baştan derlenir. Doğru kullanım
şöyledir.
Client: client.o
gcc client.o -o Client
target ve dependency
make programlama dilinden bağımsızdır denilse de alında C++ için bazı built-in kurallar vardır.
Örnek
Elimizde şöyle bir makefile
olsun. test target'ı test.o'ya bağlıdır. test.o target'ı ise test.c'ye bağlıdır. test.c değişince yeniden derkenir.
test: test.o
cc -o test test.o
test.o: test.c
cc -c test.c
clean:
rm test.o
Örnek
Mesela
all: main.o game.o zombie.o
g++ $(FLAGS) game.o main.o zombie.o -o main $(CXXFLAGS)
şeklindeki bir komut .o ile biten dependency'lerin aslında .cpp dosyası olduğunu bilir. Dolayısıyla g++ komutu sadece belirtilen cpp dosyası değişmiş ise çalışır.
Ancak c,cpp dosyaları .h dosyalarına bağımlıdırlar. Bu durumda bazı .c dosyaları için kullandıkları .h dosyalarını da belirtmek
gerekir:
all: main # all depends on the program
main: main.o foo.o # main depends on its objects
gcc main.o foo.o -o main # create the program by linking the object files
foo.o: foo.c foo.h # the foo object depends on its .c and .h files
# the main object implicitly depends on its .c file