0

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)
Community
  • 1
  • 1
Sto Flo
  • 1
  • 3
  • Looks like a duplicate of [How do you force a makefile to rebuild a target](https://stackoverflow.com/q/816370/96588). – l0b0 Mar 26 '16 at 19:11
  • Another method is to just combine the two rules: `fetch data/www.example.org:` – user657267 Mar 28 '16 at 00:04

0 Answers0