From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: Using `make' to maintain libraries Date: Fri, 20 Jun 1997 19:31:30 +0000 Organization: Two pounds of chaos and a pinch of salt Lines: 60 Message-ID: <33AADA92.5888@cs.com> References: <199706201650 DOT JAA09741 AT adit DOT ap DOT net> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp102.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Nate Eldredge wrote: > > Does anyone know of a way to have `make' rebuild only the changed members of > a .a library? For example, I have a library libfoo.a containing func1.o, > func2.o ... func(n).o. Each .o member is built from a .c source. The easy > way is to do this: > --cut-- > OBJS = func1.o func2.o [...] func(n).o > > libfoo.a : libfoo.a($(OBJS)) > --cut-- > and let implicit rules handle the rest. This is described in the Archives > section of the docs. But what happens when I make is, if the library is not > up-to-date, every source file is recompiled, and every member re-inserted. > This can take a loooong time if `n' is large. > > So what I want is: > for (each source file newer than libfoo.a) do > compile source file > gcc -o funcx.o funcx.c > re-insert member > ar -r libfoo.a funcx.c > > How do I get `make' to do this? Is it even possible? There are two ways that I can think of. Method 1: OBJS = func1.o func2.o [...] func(n).o libfoo.a : $(OBJS) %.o : %.c $(CC) -c $(CFLAGS) $< $(AR) rs libfoo.a $@ This has the advantage of doing exactly what you want, but it would take a long time if several source files were updated. A faster way would be... Method 2: OBJS = func1.o func2.o [...] func(n).o libfoo.a : $(OBJS) $(AR) rs $@ $^ This compiles only the necessary library members and then rebuilds the entire library. I don't know why make isn't working right when you use the archive member format to specify dependencies. -- --------------------------------------------------------------------- | John M. Aldrich, aka Fighteer I | mailto:fighteer AT cs DOT com | | Descent 2: The Infinite Abyss - The greatest Internet game of all | | time just got better! This time, you're going all the way down...| ---------------------------------------------------------------------