As we know, use sed command can change string.
When we want to use it in Makefile, how to use it?
Let's write a Makefile as following:
LDFLAGS = -Txxhello.lds -Lhello
IOT_LDFLAGS = $(LDFLAGS) | sed 's/-T.*lds/-Talex.lds/g'
all:
@echo $(LDFLAGS)
@echo $(IOT_LDFLAGS)
now let's execute make:
Looks good, we got what we wanted.
However, when you plan to use $(IOT_LDFLAGS), you will find something different.
let's use echo instead of @echo in Makefile,here is the output:
Here we can see:
read line marks the $(LDFLAGS)
blue line marks the $(IOT_LDFLAGS)
@echo just show the result after echo executed. so $(IOT_LDFLAGS) is not '-Talex.lds -Lhello'.
The correct way is:
LDFLAGS = -Txxhello.lds -Lhello
#IOT_LDFLAGS = $(LDFLAGS) | sed 's/-T.*lds/-Talex.lds/g'
IOT_LDFLAGS = $(shell echo $(LDFLAGS) | sed 's/-T.*lds/-Talex.lds/g')
all:
echo $(LDFLAGS)
echo $(IOT_LDFLAGS)
use $(shell xxxxx) to execute sed and return the result to $(IOT_LDFLAGS).
here is make result:
Now the $(IOT_LDFLAGS) is '-Talex.lds -Lhello'