[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to detect spaces in paths
From: |
R. Diez |
Subject: |
How to detect spaces in paths |
Date: |
Wed, 15 Dec 2021 15:05:44 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 |
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
- How to detect spaces in paths,
R. Diez <=