splitting a variable in a make file
10,903
Solution 1
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))
Solution 2
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))
Author by
Pita
Updated on June 19, 2022Comments
-
Pita almost 2 years
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.