bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make 3.81: erratic behavior with archive members


From: Philip Guenther
Subject: Re: Make 3.81: erratic behavior with archive members
Date: Wed, 21 Nov 2007 21:55:37 -0700

On Nov 21, 2007 6:48 PM, Stephen Macmanus
<address@hidden> wrote:
> I am using make 3.81 and encountering some unexplained behavior
> when adding object files to an archive using pattern rules.
...
> The build process successfully uses the implicit rules
> to compile the "(member.o)" file from the "member.c"
> file in the same directory and add it to the "$(LIB)"
> library file with the modified pattern rule. However,
> it does not consistently detect that the $(LIB) target
> must also be remade. As a result, the $(OUT) target is
> not always updated as required and the build fails at a
> later stage.
...
> The Makefile includes the following:
>
> # Redefine the implicit rule for archive members to save
> # the intermediate file elsewhere.
>
> (%): %
>          $(AR) $(ARFLAGS) $@ $<
>          $(MV) $< $(subst /,$(SLASH),$(OBJDIR))

IMHO, the ARCHIVE(MEMBER) capability of make should simply be avoided,
mainly because it isn't safe to use with the -j option.

In this case, I'm not sure what benefit the above rule provides, as
make won't know to used the saved copies.  If you just want to tell
make to not remove them then use
    .SECONDARY: $(OBJS)

instead of overriding the (%):% rule.


> $(LIB): $(LIB)($(OBJS)) ;

This looks unwise to me.  You're telling make that it doesn't need to
do anything when $(LIB) is older than any of the objects inside it.
That might seem to be impossible, but I can imagine it happening when
building on NFS-mounted filesystem when the clocks are synced.


> OUT = $(OUTDIR)/$(LIBRARY).out
> default :: $(OUT)
> $(OUT) : $(LIB) $(OUTDIR)
>          $(LD) -o $@ -r -whole-archive $(LIB)

Huh.  Why would you want both an archive version of a library _and_ a
single-object version?  If you only need the single-object form them
just build it directly with

$(OUT): $(OBJS) $(OUTDIR)
        $(LD) -o $@ -r $(OBJS)


and avoid the extra I/O and complexity of the archive.  If you really
do need both, then I would recommend dropping the ARCHIVE(MEMBER)
usage and simply have a direct rule for $(LIB), ala:

$(LIB): $(OBJS)
        $(RM) $@
        ${AR} cr $@ $(OBJS)

Yes, that rebuilds it completely when just a single object changes,
but that seems like a good trade off if it makes the build work
predictably.

(I.e., I agree that there appears to be a bug; fixing the bug is a
Good Thing, but getting your job done may be more important.)


Philip Guenther




reply via email to

[Prev in Thread] Current Thread [Next in Thread]