Chopping off the last directory in a Makefile variable

Hi everybody,

I have a Makefile where I need to use an environment variable that I set, MYBUILDPATH. The variable can be different depending on the computer, but it always ends with /myBuildRoot/data_tables. Sometimes the data_tables directory will have a slash after it, sometimes not, depending on the computer.

What I'm trying to do is get the location of the build root from this variable (with a slash on the end), so something like this:

MYBUILDPATH=/randomstuff/myBuildRoot/data_tables
MYBUILDROOT=/randomstuff/myBuildRoot/

I've tried calling the shell from the Makefile:

I've tried a lot of things, including:

MYBUILDROOT=$(shell ${$$MYBUILDPATH%/data_tables})

And using sed, but no luck.

Would anyone mind pointing me in the right direction to figure this out? I'd appreciate any help.

Thanks,
Zel2008

There are different ways to achive this.
Try this for one:

$ MYBUILDPATH=/randomstuff/myBuildRoot/data_tables
$ echo $MYBUILDPATH | sed 's~data_tables[/]*$~~'
/randomstuff/myBuildRoot/
$ MYBUILDPATH=/randomstuff/myBuildRoot/data_tables/
$ echo $MYBUILDPATH | sed 's~data_tables[/]*$~~'
/randomstuff/myBuildRoot/
1 Like

Thank you edidataguy, that works perfectly! :slight_smile: