I encounter the following sed command in make's manual.
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g'
And it has the following effect (this is an example in the manual):
main.o : main.c defs.h
# is turned into:
main.o main.d : main.c defs.h
In my understanding, '\($*\)\.o' is intended to match the file name filename.o, but I do not understand how '\($*\)' achieve this. I know $ is special at the end of a line in a regular expression, but this does not apply here.
So what does '\($*\)' mean here?
The full code:
%.d: %.c
@set -e; rm -f $@; \
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$