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.
As in normal makefile syntax, a single logical recipe line can be split into multiple physical lines in the makefile by placing a backslash before each newline. A sequence of lines like this is considered a single recipe line, and one instance of the shell will be invoked to run it.
Stata will split the variable by a separator. The default separator is a space character, however you can specify whichever separator you need to adequately split your variables. This command is very useful for splitting off some information that you want to keep in separate variables.
So, you can format your makefiles for readability by adding newlines into the middle of a statement: you do this by escaping the internal newlines with a backslash ( \ ) character.
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))
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With