OBJS := a.o b.o c.o
rule : $(OBJS)
@echo $^
@echo $^.bc // @echo a.o.bc b.o.bc c.o.bc -> what I want to do
I want to add suffix after automatic variable $^
However, even though I use $^.bc, it shows
a.o b.o c.o.bc
not,
a.o.bc b.o.bc c.o.bc
Are there any ways to do this?
The automatic variable $^ is in your case a space-separated list of elements since it expands to a.o b.o c.o.
Therefore, echo $^.bc will result in a.o b.o c.o.bc instead of a.o.bc b.o.bc c.o.bc, because the suffix .bc is only appended to the last element of the list, i.e., c.o.
If you want to obtain a.o.bc b.o.bc c.o.bc, then what you want is to add the suffix .bc to every single element of that space-separated list, not just the last one.
GNU Make's addsuffix builtin function does work on lists:
OBJS := a.o b.o c.o
rule: $(OBJS)
@echo $^
@echo $(addsuffix .bc,$^)
Running make on the makefile above:
$ make
a.o b.o c.o
a.o.bc b.o.bc c.o.bc
produces the output you are looking for.
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