help-make
[Top][All Lists]
Advanced

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

Should this makefile really hang make?


From: Bryan Ischo
Subject: Should this makefile really hang make?
Date: Tue, 15 Nov 2011 13:30:27 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20111001 Thunderbird/7.0.1

I'm trying to use .SECONDEXPANSION to create pattern rules for which the prerequisites list is a function of the target. But things don't work exactly as I expect. Here is an example of a makefile that causes make to apparently enter an infinite loop:

.SECONDEXPANSION:
all: foo.a
%.a: $$(@:%.a=%.o)

I can't understand why make would go into an infinite loop with the above. Shouldn't it be using the pattern rule to generate this rule:

foo.a: $(@:%.a=%.o)

and then doing a second expansion of $(@:%.a=%.o) with $@ equal to foo.a?

And if so, wouldn't that result in a prerequisite of foo.o?

Here is another example:

.SUFFIXES:
.PRECIOUS: %.c %.o

all: foo.a

%.c:
    echo > $@

%.o: %.c
    gcc -o $@ -c $<

.SECONDEXPANSION:
%.a: $$(patsubst %.a,%.o,$$@)
    ar cr $@ $^

This makefile produces this output:

echo > %.c
gcc -o %.o -c %.c
ar cr foo.a %.o

So make is using the pattern rule for %.a when figuring out how to build foo.a, but in the substitution that it does to determine the prerequisites it is using % instead of foo. I don't get it.

Thanks,
Bryan




reply via email to

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