Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove first two chars from string in makefile?

Tags:

makefile

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?

like image 553
Jon Avatar asked Sep 02 '25 02:09

Jon


1 Answers

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)
like image 139
Etan Reisner Avatar answered Sep 05 '25 00:09

Etan Reisner