Reputation: 1705
How do I remove the first two characters from a string in a makefile?
On windows, suppose I have:
ROOT_DIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
Then later, I have:
WINTOOLS := $(ROOT_DIR)/../../wintools
GOWTOOLS := $(WINTOOLS))/Gow/bin
My GOWTOOLS variable has, for example: "L:/path/to/project/../../wintools/Gow/bin". Now, If I try to run a command from there, say:
$(GOWTOOLS)/sed -e xxxxx
I get the error message "'L:' is not recognized as an internal or external command, operable program or batch file."
If I manually enter the path minus the L:., it works fine. If I flip the slashes, it works fine.
How can I, in Makefile-ese, drop the drive specifier from the tools dir string?
Upvotes: 4
Views: 3659
Reputation: 80931
I can't think of a good way to drop two characters offhand but you can use the fact that :
isn't legal in a Windows file path/name and do something like:
GOWTOOLS := $(subst :, ,$(WINTOOLS))/Gow/bin)
GOWTOOLS := $(wordlist 2,$(words $(GOWTOOLS),$(GOWTOOLS))
But if If I flip the slashes, it works fine
is true then it might be simpler/safer to use (since neither /
nor \
are legal in path names either):
GOWTOOLS := $(subst /,\,$(WINTOOLS))/Gow/bin)
Upvotes: 3