1

I have following make rule:

$ ls files a b c $ cat Makefile files.7z: ./files/* 7z a $@ $? 

The rule will be executed as follows:

7z a files.7z files/a files/b files/c

7z treats paths beginning with ./ especially in that, it will include the file in the archive without the path. What would be the shortest way to replace the paths, to begin with, ./ in the $?? (Files names can have spaces.)

1 Answer 1

1

Makefile doesn't handle spaces very well at all (see here). The simplest thing is to make make fail if there are spaces and then it's easy:

check: @ ls ./files/* | grep -q " "; \ if [ $$? -ne 1 ]; then \ echo "WE DO NOT SUPPORT FILENAMES WITH SPACES"; \ exit 1; \ fi files.7z: ./files/* | check 7z a $@ $(addprefix ./,$^) 

Note: there are workarounds on the web for filenames with spaces, but they're overly complex, not very maintainable and will cost you a lot more headaches than telling your customers/coworkers "We don't support file names with spaces"...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.