help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how can I do this in gmake?


From: Maxim Yegorushkin
Subject: Re: how can I do this in gmake?
Date: Tue, 11 Jul 2006 19:40:40 +0100
User-agent: Thunderbird 1.5.0.4 (X11/20060614)

ma wrote:

I am writing a make file that will be used on several development. in each
development, there are a huge amount of file that needed to be built but
only a small part of them is changing and others are  not changing. I put
all of these files into a library. The idea is that when the user run make
file for the first time, it will create all of the source files and then
create library and copy somewhere in the system. On any other call to this
make file (maybe from some other directory that doesn't have  *.obj files
related to library in it), it checks if the lib exist, use it and if not
create it.

This may help you:

address@hidden tmp]$ cat Makefile
all :

libmy_obj := a.o b.o
lib/libmy.a : $(libmy_obj) | lib

foo_obj := foo.o
bin/foo : $(foo_obj) lib/libmy.a | bin
bin/foo : LDFLAGS += -Llib -lmy

bar_obj := bar.o
bin/bar : $(bar_obj) lib/libmy.a | bin
bin/bar : LDFLAGS += -Llib -lmy

bin/% :
        $(CC) -o $@ $($(@F)_obj) $(LDFLAGS)

lib/% :
        ar r $@ $($(@F)_obj)

.PHONY : all clean

all : lib/libmy.a bin/foo bin/bar

lib bin :
        mkdir -p $@

clean :
        rm -rf *.{c,o} lib bin

# create dummy source files
a.c b.c :
        touch $@
%.c :
        echo "int main() {}" > $@

address@hidden tmp]$ make
touch a.c
cc    -c -o a.o a.c
touch b.c
cc    -c -o b.o b.c
mkdir -p lib
ar r lib/libmy.a
ar: creating lib/libmy.a
echo "int main() {}" > foo.c
cc    -c -o foo.o foo.c
mkdir -p bin
cc -o bin/foo foo.o -Llib -lmy
echo "int main() {}" > bar.c
cc    -c -o bar.o bar.c
cc -o bin/bar bar.o -Llib -lmy
rm bar.c foo.c
address@hidden tmp]$ make bin/foo
make: `bin/foo' is up to date.
address@hidden tmp]$ rm lib/libmy.a
address@hidden tmp]$ make bin/foo
ar r lib/libmy.a
ar: creating lib/libmy.a
cc -o bin/foo foo.o -Llib -lmy





reply via email to

[Prev in Thread] Current Thread [Next in Thread]