I have a makefile, which includes several other makefiles, which in turn all add to a variable like this:
VAR := Something SomethingElse VAR += SomeOtherThing (...)
Now I wish to remove SomethingElse
from the VAR
variable. What do I put in place of (...)
to do this?
I am using GNU Make, and a GNU Make specific solution will be fine.
Double dollar sign If you want a string to have a dollar sign, you can use $$ . This is how to use a shell variable in bash or sh . Note the differences between Makefile variables and Shell variables in this next example.
6.6 Appending More Text to Variables Often it is useful to add more text to the value of a variable already defined. You do this with a line containing ' += ', like this: objects += another.o.
$(strip string ) Removes leading and trailing whitespace from string and replaces each internal sequence of one or more whitespace characters with a single space. Thus, ' $(strip a b c ) ' results in ' a b c '. The function strip can be very useful when used in conjunction with conditionals.
How do I print a variable in a file? To use it, just set the list of variables to print on the command line, and include the debug target: $ make V="USERNAME SHELL" debug makefile:2: USERNAME = Owner makefile:2: SHELL = /bin/sh.exe make: debug is up to date.
You could use the filter-out
text function if you're using GNU Make.
OTHERVAR := $(filter-out SomethingElse,$(VAR))
On top of the correct answer above:
VAR = bla1 bla2 bla3 bla4 bla5 TMPVAR := $(VAR) VAR = $(filter-out bla3, $(TMPVAR)) all: @echo "VAR is: $(VAR)"
Output:
VAR is: bla1 bla2 bla4 bla5
Note that this breaks all "recursivity" when filter-out is executed, but that might not matter in your case.
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