I have a directory where I download some data from somewhere on which I want to perform some operations by a script. When said directory does not yet exists, I want make
to automatically download the files, which I would also like to be able to initiate by running make fetch
. However, I don't want the download process to be started everytime I run make for the other target.
My attempt so far:
.PHONY: fetch
fetch: data/www.example.org
foo.dat: | data/www.example.org
somescript > foo.dat
data/www.example.org:
wget --mirror --prefix-directory=data http://www.example.org
This has almost the desired effects, except for when I run make fetch
it gives me:
$ make fetch
make: Nothing to be done for `fetch'.
I could, of course, simply copy the recipe of data/www.example.org
to fetch
, however as the recipe may get more complex in the future, I would like to avoid that kind of solution.
EDIT:
It seems kind of obvious in hindsight, but for some reason I didn't think of using variables. I think, my mind kept searching for some kind of "neater" way. But that does solve it for me, so thanks to l0b0 for pointing it out to me:
FETCH = wget --mirror --prefix-directory=data http://www.example.org
.PHONY: fetch
fetch:
$(FETCH)
foo.dat: | data/www.example.org
somescript > foo.dat
data/www.example.org:
$(FETCH)