Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!sics.se!fuug!mcsun!corton!ircam!usenet From: wyngaard@wayne (Peter Wyngaard) Newsgroups: comp.unix.questions Subject: Help making object file archives Message-ID: <1991Jun12.121206.26970@ircam.fr> Date: 12 Jun 91 12:12:06 GMT Sender: usenet@ircam.fr (USENET News System) Organization: IRCAM Lines: 48 I have a library of routines spread out over many directories and I am trying to write the (gnu)makefiles for them. I don't like the built-in implicit rule for making an archive member from an object file because it does an 'ar' for each object file. This is VERY slow. I have played around a little and it seems as though there should be some way to trick gnumake into letting me do one 'ar' after all the '.c' files in a directory have been compiled. Here is about as close as I've come: LIB = anylib.a # # Get rid of gnumake's implicit rule for making archive members and replace # it with my own # (%) : % (%.o) : %.c $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $% $< # # Silly macros for extracting the object file name from a list of archive # elements # lpar = ( rpar = ) sp = $(empty) $(empty) object_files = $(filter %.o,$(subst $(lpar),$(sp),$(subst $(rpar),$(sp),$?))) $(LIB) : $(LIB)(file1.o) $(LIB)(file2.o) $(LIB)(file3.o) $(LIB)(file4.o) $(AR) $(ARFLAGS) $(LIB) $(object_files) $(RM) $(object_files) $(RANLIB) $(LIB) This doesn't work, however, because the object files aren't put into the archive by the '(%.o) : %.c' rule hence the '$(AR) - $(RM) - $(RANLIB)' sequence is never executed. I know this would be easy if I just kept copies of the object files in the source directories, but this takes up too much disk space. If you have any suggestions, please send them to me via email. Thanks in advance, Peter wyngaard@ircam.fr