dbotha
dbotha

Reputation: 1703

Makefile collect list of files in a new directory

I have a list of file paths in a variable. I'd like to copy each file in this list to a new location. The problem is that I'm very new to makefiles and I'm struggling to get anything working. My attempt has culminated at the following, although not working (and probably totally wrong) I hope it illustrates what I'm trying to do.

FILES = a/b/file c/d/file e/.../file etc...
copyfiles:
       for file in $(FILES); do \
           cp $$file newDir/$(notdir $$file);  \
       done

Upvotes: 2

Views: 4335

Answers (1)

Dan
Dan

Reputation: 12665

You could do

FILES = a/b/file c/d/file e/.../file etc...
copyfiles:
    cp $(FILES) newDir

I tried it, and it works.

Remember, globbing is done by the shell, not by the commands. cp takes a list of files as arguments, and copies all of them to the location specified by the last argument. When you type cp *.cpp all the cp program sees as its arguments are the files in the current directory that end in .cpp.

Upvotes: 5

Related Questions