Makefile

Makefile: whitespace in path

I hates whitespace in path. I wrote a Perl script which uses a resource file and several template files. So I created a makefile to copy them to user’s HOME directory. It looks like:

$(HOME)/a: a
      cp -f $< $@

Unfortunately, it doesn’t work when there are whitespaces in $(HOME) string, such as /abc/d e/. That happens on Cygwin default installation.

You can double-qoute path, but there are whitespaces in target and target can not be double-qouted. Finally, I find a workaround after diving into `make' info page for a long time. Here is the trick.

nullstring :=
space := $(nullstring) # a space at the end
QUOTED_HOME=$(subst $(space),\ ,$(HOME))
$(QUOTED_HOME)/a:a
      cp -f $< $(subst $(space),\ ,$@)

Standard

Leave a comment