Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU Make Convert Spaces to Colons

Given a colon-delimited list of paths, getting a space-delimited list with GNU Make is straightforward:

CPATHS := /usr/bin/foo:/usr/bin/baz:/usr/bin/baz SPATHS := $(subst :, ,$(CPATHS)) 

However, I couldn't find a nice way to go the opposite direction. The following hack does work (at least if sed is installed) but I'm pretty sure there will be a nicer way to solve this just using Make's internal functions.

SPATHS := /usr/bin/foo /usr/bin/baz /usr/bin/baz CPATHS := $(shell echo $(SPATHS) > tmp; sed 's/ \+/:/g' tmp; rm tmp) 
like image 912
5gon12eder Avatar asked May 13 '12 12:05

5gon12eder


People also ask

What is $@ in makefile?

The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.

What is Subst in makefile?

From the GNU make reference manual: $(subst from,to,text) Performs a textual replacement on the text text: each occurrence of from is replaced by to. The result is substituted for the function call. For example, $(subst ee,EE,feet on the street) substitutes the string 'fEEt on the strEEt'.

What is $( make in makefile?

And in your scenario, $MAKE is used in commands part (recipe) of makefile. It means whenever there is a change in dependency, make executes the command make --no-print-directory post-build in whichever directory you are on.

What is Makefile_list?

MAKEFILE_LIST. Contains the name of each makefile that is parsed by make , in the order in which it was parsed. The name is appended just before make begins to parse the makefile. Thus, if the first thing a makefile does is examine the last word in this variable, it will be the name of the current makefile.


1 Answers

The only tricky part here is to define a literal space:

space := $(subst ,, )  SPATHS := /usr/bin/foo /usr/bin/baz /usr/bin/baz CPATHS := $(subst $(space),:,$(SPATHS)) 
like image 51
Eldar Abusalimov Avatar answered Sep 28 '22 08:09

Eldar Abusalimov