makefile etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
makefile etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

13 Nisan 2020 Pazartesi

makefile ve Variable Expansion

Giriş
$(Varible) şeklinde kullanılır. Açıklaması şöyle.
I'm assuming that you've seen $(CC) in a Makefile where it serves as an expansion of the variable CC, which normally holds the name of the C compiler. The $(...) syntax for variable expansions in Makefiles is used whenever a variable with a multi-character name is expanded,...

12 Mart 2019 Salı

makefile ve wildcard

Örnek
Elimizde şöyle bir kod olsun.
%.foo: %.bar
    cp $< $@

test: *.foo
    echo *.foo
Uzantısı *.foo veya *.bar olan dosyaları bul ve komutu çalıştır anlamına gelir. $< ile bulunan dosyalar temsil edilir. $@ ile target temsil edilir. Çıktı olarak şunu alırız. Ancak bu istediğimiz şey değildir. Amacımız b.bar dosyasını b.foo haline getirmek.
cp b.bar *.foo
echo *.foo
*.foo
Açıklaması şöyle.
There is no *.foo file to begin with. So what make does is look for how to make *.foo literaly and the first rule does this. Make expands $< to the first pre-requisite (*.bar, which happens to be b.bar in this case). Make then runs the shell command cp b.bar *.foo. Since there is no *.foo, shell expands it to cp b.bar *.foo literally. That's how you get a *.foo file.
Şöyle yaparız. wildcard ile b.bar dosyası bulunur. pathsubst ile b.foo haline getirilir.
%.foo: %.bar
    cp $< $@

foos = $(patsubst %.bar,%.foo,$(wildcard *.bar))

test: $(foos)
    echo $(foos)
Açıklaması şöyle.
$(wildcard *.bar) expands to all the files ending in .bar, the patsubst call replaces .bar with .foo, and all the targets are then processed as you’d expect.

17 Ekim 2017 Salı

makefile ve target

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