[comp.unix.wizards] Makefiles for library maintenance

pack@acdpyr.ucar.edu (Dan Packman) (12/10/88)

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.

PS: This problem seems to exist in the vms make clone mms.
Dan Packman     NCAR                         INTERNET: pack@acdpyr.UCAR.EDU
(303) 497-1427  P.O. Box 3000                   CSNET: pack@ncar.CSNET
                Boulder, CO  80307       DECNET  SPAN: 9.367::PACK

leo@philmds.UUCP (Leo de Wit) (12/19/88)

In article <1108@ncar.ucar.edu> pack@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.

andrew@alice.UUCP (Andrew Hume) (12/20/88)

another hack for maintaining libraries if you have to use something
broken like make (try make -t 'lib.a(c.o)') that i learnt from bruce ellis:

always keep all your .o's around (that's the space tradeoff) and after you make
any new ones, do a
	rm lib.a; ar q lib.a $(OBJ); optional ranlib lib.a
this form of ar runs real quick as it just adds to end.