The sed pattern will be processed by make first, so if the rule it applies to is trying to build foo.P , then $@ will be translated to foo.P and $* to foo . This means that the actual sed command will look something like this:
sed 's/\(foo\)\.o[ :]*/\1.o foo.P : /g' < foo.d > foo.P
\(foo\) exactly matches foo and sets up the first substitute for what matches (i.e. foo ) \. matches a literal period, and [ :]* matches any number of spaces and colons.
As you can see, replacing \1 bit redundant as the matched string is fixed. That would work too.
sed 's/foo\.o[ :]*/foo.o foo.P : /g' < foo.d > foo.P
which could be made from:
sed 's/$*\.o[ :]*/$*.o $@ : /g' < $*.d > $@
source share