I've got a Makefile that extracts a series of tarballs. Right now the rules are written like:
dirname:
tar zxvf file.tar.gz
and other targets that depend on the expanded tarball reference dirname
. But, it's kind of cluttery to define a rule like this for every tarball. So, I'm trying to use the eval
function to auto generate these rules. My attempt looks like this:
TARFILES = $(wildcard *.tar.gz *.tgz)
define extract_tmpl =
$(shell tar tf $(1) | head -1):
tar zxvf $(1)
endef
$(foreach file, $(TARFILES), $(eval $(call extract_tmpl, $(file))))
But it doesn't seem to work. I'm testing with this tarball (in the same dir):
$ ls Python-2.6.6.tgz
Python-2.6.6.tgz
$ tar tf Python-2.6.6.tgz | head -1
Python-2.6.6/
$ make Python-2.6.6/
make-3.79.1-p7: *** No rule to make target `Python-2.6.6/'. Stop.
It seems like it should work to me, but honestly I'm not even sure how I can see what it expands to. Anything obviously wrong here?