Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using makefile wildcard command for file names with spaces

Tags:

makefile

I have a makefile that I use to compress pictures:

src=$(wildcard Photos/*.jpg) $(wildcard Photos/*.JPG)
out=$(subst Photos,Compressed,$(src))

all : $(out)

clean:
    @rmdir -r Compressed

Compressed:
    @mkdir Compressed

Compressed/%.jpg: Photos/%.jpg Compressed
    @echo "Compressing $<"
    @convert "$<" -scale 20% "$@"

Compressed/%.JPG: Photos/%.JPG Compressed
    @echo "Compressing $<"
    @convert "$<" -scale 20% "$@"

However, when I have a picture with a space in its name, for example Piper PA-28-236 Dakota.JPG, I get this error:

make: *** No rule to make target `Compressed/Piper', needed by `all'.  Stop.

I think this is a problem in the wildcard command, but I'm not sure what to change to get it to work.

How can I modify my makefile to allow for spaces in file names?

like image 479
iBelieve Avatar asked Dec 20 '12 00:12

iBelieve


1 Answers

Generally having spaces in file names is a bad idea with make, but for your case this may work:

src=$(shell find Photos/ -iname '*.JPG' | sed 's/ /\\ /g')

out=$(subst Photos,Compressed,$(src))

all : $(out)

Compressed:
  @mkdir Compressed

Compressed/%: Photos/% Compressed
  @echo "Compressing $<"
  @convert "$<" -scale 20% "$@"
like image 68
perreal Avatar answered Oct 13 '22 07:10

perreal