|
From: | Maxim Yegorushkin |
Subject: | Re: how can I do this in gmake? |
Date: | Thu, 13 Jul 2006 10:40:26 +0100 |
User-agent: | Thunderbird 1.5 (Windows/20051201) |
ma wrote:
"Maxim Yegorushkin" <address@hidden> wrote in message news:address@hiddenma wrote:I am writing a make file that will be used on several development. in eachdevelopment, 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 putall of these files into a library. The idea is that when the user run makefile for the first time, it will create all of the source files and thencreate library and copy somewhere in the system. On any other call to thismake 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 -lmyThanks. I belive the main trick that used here is lib/libmy.a : $(libmy_obj) | libwhich I think telling that if lib is uptodate, don't go for $(libmy_obj) prerequiatic else go and use that pre requistic. Am I wring?
bin/foo : $(foo_obj) lib/libmy.a | bin bin/bar : $(bar_obj) lib/libmy.a | binThe above two targets depend on lib/libmy.a. Whenever they are built lib/libmy.a will also be built if it's not up to date.
I'm bad explaining things in comparisons with the make's clear documentation. http://www.gnu.org/software/make/manual/make.html.gz#Rules
[Prev in Thread] | Current Thread | [Next in Thread] |