Michael C. Lehn
Michael C. Lehn

Reputation: 3194

gnu make Archive Members as Targets

I have a problem with GNU make when using Archive Members as Targets. The problem is that on some machines (e.g. running MacOS, Solaris) it works fine, i.e. builds the library and the next make gives Nothing to be done for 'all'.

But not on the Linux boxes there make always rebuild everything. On all machines I am using GNU Make.

Here the example with one source file foo.c and the Makefile

foo.c

void foo() {}

Makefile

all: libfoo.a

libfoo.a(%.o) : %.o
        $(AR) cr $@ $^

libfoo.a: libfoo.a(foo.o)
        ranlib libfoo.a

Can anyone confirm that? (or tell me what obvious stupid mistake I have done ...?)

Run on Solaris

theon$ make
gcc    -c -o foo.o foo.c
ar cr libfoo foo.o
ranlib libfoo
rm foo.o
theon$ make
make: Nothing to be done for 'all'.

Run on Linux

acker$ make
gcc    -c -o foo.o foo.c
ar cr libfoo foo.o
ranlib libfoo
rm foo.o
acker$ make
gcc    -c -o foo.o foo.c
ar cr libfoo foo.o
ranlib libfoo
rm foo.o

Upvotes: 1

Views: 179

Answers (1)

MadScientist
MadScientist

Reputation: 101021

Most likely it's not you, it's that your GNU/Linux distribution is stupid and has set "deterministic mode" as the default behavior of ar. This is a configure-time option for the ar program, to determine whether it defaults to "deterministic" or "non-deterministic" (the historical and correct default behavior for ar). Some distributions made the ridiculous decision to set this configuration option in their version of ar, and change the default behavior.

This breaks make (and any other tool that needs to know the timestamps of objects).

If this is the problem, you can change your invocation of ar to add the U option to turn deterministic mode off again:

ARFLAGS = crU

Unfortunately it's likely that the ar commands on non-GNU systems won't understand this option so you'll need to find a way to add it only for the ones using GNU binutils.

You should also feel free to complain to your GNU/Linux distribution about this.

Upvotes: 2

Related Questions