views:

95

answers:

2

I was planning something like:

URLS=www.host.com/file1.tar.gz www.host2.com/file2.tar.gz
$(somefunc $URLS): #somefunc produces downloads/file1.tar.gz downloads/file2.tar.gz
   mkdir -P downloads
   wget whatever # I can't get the real url here because the targets don't contain the full url anymore

myproject: $(somefunc URLS)
   #Files should already be in downloads/ here

The problem I have is that if I convert URLS with somefunc I lose the urls, if I don't I can't use it as a target to avoid being downloaded when it is already there.

Any ideas?

A: 

At this point, I don't think you can do it directly with make. But here's a solution if you are willing to use some scripting:

$(URLS):
    @for url in ${URLS}; do \                                               
        if [ ! -e $$(somefunc $${url}) ]; then \
            echo wget $${url}; \
            wget $${url}; \
        fi \
    done
R Samuel Klatchko
But that will download all URLS each time one target is missing. I was thinking in a Makefile solution rather than relying in wget downloading several URLS at the same time.
Yogur
@Yogur - okay, I've completely revamped my solution.
R Samuel Klatchko
A: 

If somefunc only modifies the path, not the actual filename, and there are no duplicates, you could try searching $(URLS) for the original filename.

Maybe something like this? (untested)

$(somefunc $URLS): #somefunc produces downloads/file1.tar.gz downloads/file2.tar.gz
   mkdir -p $(dir $@)
   wget $(filter $(addprefix %/,$(notdir $@)),$(URLS)) -O $@
  • $(notdir $@) evaluates to file1.tar.gz for one of the targets.
  • $(addprefix %/,file1.tar.gz) evaluates to %/file1.tar.gz
  • $(filter %/file1.tar.gz,www.host.com/file1.tar.gz www.host2.com/file2.tar.gz) evaluates to www.host.com/file1.tar.gz.

(Presumably you want an http:// on there too?)

bk1e