Pita
Pita

Reputation: 1474

splitting a variable in a make file

I have a variable lets say x=tpm/tpm

in a makefile i want to be able to split x to halves.

in bash this would be something like ${x%/} and ${x#/}

but how do i do it in a makefile?

thanks in advance.

Upvotes: 8

Views: 13055

Answers (2)

Beta
Beta

Reputation: 99094

For a more general solution (e.g. if there are more than two parts, or if the separator isn't always '/') you can use this approach:

y = $(subst /, ,$(x))

half1 = $(word 1, $(y))
half2 = $(word 2, $(y))

Upvotes: 17

Carl Norum
Carl Norum

Reputation: 224944

If that's a pathname (or even if it's not and the separator is always /), you can use the dir and notdir functions.

half1 = $(dir $(x))
half2 = $(notdir $(x))

Upvotes: 5

Related Questions