Reputation: 33
I have working makefile code which first finds all the files in the u
folder, then removes ./u/
and finally replaces the back extension of .c
to .o
. Is there a way to make this a one or two-liner instead? I feel that this code looks messy and could be improved.
UTILS=$(wildcard ./u/*.c)
TEMP=$(UTILS:./u/%=%)
OBJ=$(TEMP:.c=.o)
Upvotes: 0
Views: 1158
Reputation: 311655
You can't nest $(var:x=y)
style replacements, but you can nest the equivalent patsubst
function calls, so you could write this:
OBJ=$(patsubst %.c, %.o, $(patsubst ./u/%,%,$(wildcard ./u/*.c)))
Which you can simplify to:
OBJ=$(patsubst ./u/%.c,%.o,$(wildcard ./u/*.c))
But with that simplification in mind, you can do the same thing with the original version:
UTILS=$(wildcard ./u/*.c)
OBJ=$(UTILS:./u/%.c=%.o)
Which is maybe easier to read.
Upvotes: 1