Remove item from Makefile variable?

I have a makefile that includes several other makefiles, which in turn all add to a variable like this:

VAR := Something SomethingElse VAR += SomeOtherThing (...) 

Now I want to remove SomethingElse from the VAR variable. What am I doing instead of (...) for this?

I am using GNU Make, and GNU Make a specific solution will be fine.

+56
variables makefile gnu-make
Sep 13 '11 at 12:55
source share
2 answers

You can use the filter-out text function if you use GNU Make.

 OTHERVAR := $(filter-out SomethingElse,$(VAR)) 
+78
Sep 13 '11 at 13:01
source share

At the top of the correct answer above:

 VAR = bla1 bla2 bla3 bla4 bla5 TMPVAR := $(VAR) VAR = $(filter-out bla3, $(TMPVAR)) all: @echo "VAR is: $(VAR)" 

Exit:
VAR: bla1 bla2 bla4 bla5

Note that this interrupts all β€œrecursion” when performing filtering, but this may not matter in your case.

+3
Oct 12 '16 at 8:06
source share



All Articles