Makefiles for library maintenance

Leo de Wit leo at philmds.UUCP
Mon Dec 19 22:04:08 AEST 1988


In article <1108 at ncar.ucar.edu> pack at acdpyr.ucar.edu (Dan Packman) writes:
|The documentation for make (both ATT and UCB) says one can reference a
|module in a library, that is a(b) means the element b in archive a.
|One would hope that updates on this module would be calculated from the
|date recorded in the archive a and not the date of the archive itself.
|My tests of this seem to indicate that the archive date in incorrectly
|used and not the element date.  I can, of course, extract all elements
|in the archive with the appropriate date before invoking make and then
|update the archive after exiting make via the following script:
|
|#! /bin/csh
|# Fool dumb makes to allow archive of object files
|ar xo *.a
|/bin/make $*
|ar r *.a *.o
|rm *.o
|
|One could generalize to multiple local archives, but I'd rather find a
|more elegant and faster solution within make (a newer version?).  For
|large modules, the vast numbers of object files are getting in my way.
|Do I have to redefine all suffixes?  Any help will be appreciated.

One remedy is to update the archive whenever an object file is created.
To achieve this, at least all suffix rules involving .o must be
adjusted, and also all explicit rules that create .o files. This may
not be what you want.

Another solution is to update a library only once, after all objects
used in it have been made:

	liba1.a : $(LIBA1_OBJECTS)
		$(AR) rv $@ $?    # only the 'more recent ones'.

or, if all objects are present in the current directory, and used in
liba1.a:

	liba1.a : *.o
		$(AR) rv $@ $?    # only the 'more recent ones'.

Alternatively, you can use the 'u' option of ar, that only updates the
objects that are younger than the corresponding modules in the library
(the archive timestamps are used):

	prog : main.o $(LIBA1_OBJECTS)
		$(AR) ru liba1.a $(LIBA1_OBJECTS)
		$(CC) $(CFLAGS) $(LDFLAGS) -o $@ main.o liba1.a

I hope this helps, or at least gives you some new ideas -

                                        Leo.



More information about the Comp.unix.wizards mailing list