I'm trying to make a rule that will generate files regarding their names but regardless of the directory.
I'm starting from this makefile (see a previous question of mine):
TARGETS:=$(patsubst %_tpl,%,$(wildcard *_tpl))
.PHONY: all
all: $(TARGETS)
.SECONDEXPANSION:
$(TARGETS): %: $$(wildcard %*_tpl)
./generate $@_tpl > $@
With this, I can do, for instance, make foo.xml
. It looks if a set of foo.xml*_tpl
files are there, consider them as prerequisites and call the generate
script to generate the target.
What I would like to do is, for example, make ../ressources/foo.xml
and have make use the rule to create foo.xml
but creating it in the ../ressources/
directory, without having to explicitely specify this directory in the makefile.
What I have tried for the moment is adding this to the Makefile:
../ressources/%: $(notdir %)
mv $< $@
Which works, but I would like to avoid creating the file in the current directory before moving it to the destination folder. I would also like not having to specify the possible destination folders in the makefile (but this is less important).
But first of all, does this make any sense? Or is what I want to do just conceptually wrong?
EDIT: Some precisions regarding the _tpl
files and the generate
script to avoid confusions:
Each target has a main template ($@_tpl
) that includes others ($@-part1_tpl
, $@-part2_tpl
...) and the generate
script only takes the main template as argument. The templates are written with Jinja2 (the subparts included with the {% include %}
jinja directive).
If you always want the targets in another directory, just say so.
TARGETS:=$(patsubst %_tpl,../resources/%,$(wildcard *_tpl))
.PHONY: all
all: $(TARGETS)
.SECONDEXPANSION:
$(TARGETS): ../resources/%: $$(wildcard %*_tpl)
./generate $@_tpl > $@
I'm not sure if you should have generate $^ >$@
instead; superficially, this would make more sense.
If there are multiple *_tpl
files for each target (i.e. there are more tpl
files than xml
files), the TARGETS
definition isn't really correct; but we don't have enough information to actually fix it.
On the other hand, if the target directory can change a lot, the sane way forward might be to cd
into the target directory and use make -f ../path/to/Makefile
-- just make sure your VPATH
is set up so that the source files can be found.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments