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))
      cp -f $< $(subst $(space),\ ,$@)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s