The Dude
The Dude

Reputation: 681

Remove Trailing Slash (/) in Makefile

So in a makefile, if you want to get the directory just above you, you can do:

UP_ONE_DIR := $(subst $(notdir $(CURDIR)),,$(CURDIR))

The problem is, it ends with an '/' ending slash. Is there a pattern to remove this slash from the UP_ONE_DIR variable?

Upvotes: 2

Views: 1022

Answers (1)

MadScientist
MadScientist

Reputation: 100956

It's not a great idea to use subst because it can match multiple identical strings, for example if your path was /foo/bar/foo/bar or whatever. You can use:

UP_ONE_DIR := $(patsubst %/,%,$(dir $(CURDIR)))

Upvotes: 3

Related Questions