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.)

danglingpointer
  • 4,708
  • 3
  • 24
  • 42
woky
  • 4,686
  • 9
  • 36
  • 44

1 Answers1

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"...

HardcoreHenry
  • 5,909
  • 2
  • 19
  • 44