help-make
[Top][All Lists]
Advanced

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

Variably determined prerequisites


From: NightStrike
Subject: Variably determined prerequisites
Date: Wed, 1 Apr 2020 16:03:35 -0400

Hi list!

I am trying to use a pattern rule to pick which variable gets added to
a target's prereq list.  It's not working, so I'm curious if this is
even possible.  Ultimately, what I'd like to do is:

xx%: xx%.o $(extra%)
    echo $@ $^

extra1 += ex1

# The below output is fake, it doesn't actually work
$ make xx1
echo xx1 xx1.o ex1
xx1 xx1.o ex1


But instead, make looks for a variable with a literal percent sign in
it, $(extra%):

extra% = zzz

xx%: xx%.o $(extra%)
        echo $@ $^

$ make xx1
make: *** No rule to make target `xx1'.  Stop.


Ok, that's a confusing error message... there's no rule to make zzz,
not xx1, maybe a bug in make?  Fine... adding ".PHONY: zzz":

$ make xx1
echo xx1 xx1.o zzz
xx1 xx1.o zzz


Ok, so % signs don't work the way I want in a pattern rule.  Let's be
more explicit:

extra1 = ex1
extra2 =

xx1: $(extra1)
xx2: $(extra2)

xx%: xx%.o
    echo $@ $^

extra2 += ex2

$ make xx1
make: *** No rule to make target `ex1', needed by `xx1'.  Stop.
$ make xx2
echo xx2 xx2.o
xx2 xx2.o

So now xx1 is doing the right thing!  Great!  But only if extra1 is
defined prior to writing the rule, despite them being = instead of :=.
With extra2, the way I want it to be such that other files included
later can add on to it, the rule has already been scanned by make and
so the later appending to it doesn't help.

What am I missing?

Oh, I guess I should also say:
$ make --version
GNU Make 3.81

Although, a quick test with 4.0 shows the same thing not working.


So...  is there a way to do this?



reply via email to

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