Help making object file archives
Peter Wyngaard
wyngaard at wayne
Wed Jun 12 22:12:06 AEST 1991
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 at ircam.fr
More information about the Comp.unix.questions
mailing list