help-make
[Top][All Lists]
Advanced

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

Possible to get prerequisite path with secondary expansion when VPATH is


From: Glen Huang
Subject: Possible to get prerequisite path with secondary expansion when VPATH is employed?
Date: Thu, 7 Apr 2022 14:12:17 +0800

Hi,

I’m trying to use make to render some files with VPATH employed:

Source files
```
foo/1.tpl
foo/1.data
bar/2.tpl
bar/2.data
baz/3
```

Makefile
```
.SECONDEXPANSION:
VPATH := foo bar baz
build/%: %.tpl $$(patsubst %.tpl,%.data,$$<)
        render --data $(word 2,$^) $< $@
build/%: %
        cp $< $@
```

I’d like for make to automatically list the corresponding data file as a 
prerequisite for the pattern rule, but apparently this doesn’t work, because 
$$< expands to an empty string.

I also tried this:

Makefile
```
.SECONDEXPANSION:
VPATH := foo bar
build/%: %.tpl
build/%: $$(patsubst %.tpl,%.data,$$<)
        render --data $(word 2,$^) $< $@
build/%: %
        cp $< $@
```

But since an implicit rule only applies when both the target and requisites are 
found, this also doesn’t work.

I read the official doc on topics about secondary expansion, VPATH and search 
algorithm, but couldn’t come up with a way to get the prerequisite path and 
turn it into another prerequisite. I’d be really grateful if anyone could shed 
some light.

Regards,
Glen


reply via email to

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