Hi all:

I have written a makefile that accepts a directory path from outside like this:

make SOME_PATH=/my/path all

I keep forgetting that GNU Make does not support spaces inside filenames, so I wanted to check in the makefile that the given path has no spaces.

This is what I came up with:


# This defines a variable with a single space as its value.
SPACE := $(subst ,, )

PATH_TO_CHECK := /some/path

ifeq ($(SPACE),$(findstring $(SPACE),$(PATH_TO_CHECK)))
  $(error The file or directory path contains at least one space character)
else
  $(error The file or directory path does not contain any space characters)
endif


Is there a better way?

My makefile is actually accepting several paths from outside, so I wanted to 
wrap the code above in a macro like this:

define check_path_contains_no_spaces =
...
endef

But then I hit problems with 'ifeq' inside such a definition. I could 
work-around it by using eval like this:

  $(eval $(call check_path_contains_no_spaces,/some/path))

Is there a way to avoid going through $(eval) ? I tried turning the ifeq into $(if ...), but I couldn't find a way to do it reliably. Has anybody a suggestion in this area?

I would also like to check against all kinds of whitespace (like tabs). Is there a way to achieve that with GNU Make? Or do I have to shell out? If so, what would you suggest for this kind of work?

Thanks in advance,
  rdiez

Reply via email to