ma wrote:
"Maxim Yegorushkin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
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:
[EMAIL PROTECTED] 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() {}" > $@
[EMAIL PROTECTED] 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
[EMAIL PROTECTED] tmp]$ make bin/foo
make: `bin/foo' is up to date.
[EMAIL PROTECTED] tmp]$ rm lib/libmy.a
[EMAIL PROTECTED] tmp]$ make bin/foo
ar r lib/libmy.a
ar: creating lib/libmy.a
cc -o bin/foo foo.o -Llib -lmy
Thanks.
I belive the main trick that used here is
lib/libmy.a : $(libmy_obj) | lib
which 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 | bin
The 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
_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make