Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 976
Pita Avatar asked Feb 17 '12 17:02

Pita


People also ask

How do I split a line in Makefile?

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.

How to split variables in Stata?

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.

How to add a new line in a makefile?

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.


2 Answers

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))
like image 189
Beta Avatar answered Sep 28 '22 21:09

Beta


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))
like image 30
Carl Norum Avatar answered Sep 28 '22 21:09

Carl Norum