I'm using an implementation of non-recursive make similar to the one covered here: http://evbergen.home.xs4all.nl/nonrecursive-make.html
Here's an example of the problem.
The main Makefile
includes foo/Rules.mk
. foo/Rules.mk
contains the snippet:
# Here, d is bound to foo, the path to the current directory
$(d)/foo.zip: $(d)/bar
zip -r $@ $^
# This expands to the recipe: zip -r foo/foo.zip foo/bar
Unfortunately, this creates a zip archive containing foo/bar
, but I need it to contain bar
, that is, to make the archive relative to a given directory. cd
does not work.
# DOES NOT WORK
$(d)/foo.zip: d := $(d) # this makes the variable d work in the recipe
$(d)/foo.zip: $(d)/bar
cd $(d); zip -r $@ $^
# This expands to the recipe: cd foo; zip -r foo/foo.zip foo/bar
How can I make this work in the general case (d could be any path, the zip contains an arbitrary selection of files and subdirectories)?
I came up with the following hack, may the programming gods forgive me.