Creating dependency file using rule

hi,
I am trying to create dependency files using this rule, and I am having trouble with the $@.$$$$

%.d: %.cpp
 $(CC) -MM $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

when I run the command, it generates the following:

$gcc  -MM foo.cpp > foo.d.$$
sed 's'\(foo\)\.o[ :],\1.o foo.d : ,g' <foo.d.$$> foo.d
rm -f foo.d.$$
/bin/sh: foo.d.4325: No such file or directory
make: *** [foo.d] Error 1

can anybody pls tell me how I can fix this foo.d.$$ problem

thx,
BA

The $$ in the gcc line, I believe, will be different from the one in the sed line, so your sed will be operating on a different file from the one generated by the gcc. Try storing $$ into another variable and then using that everywhere.

1 Like

thanks.
I'll try that and let you know if it works!

It looks like you're just using $@.$$$$ very briefly as a temporary file, whose name doesn't matter.
Why not use a different name that doesn't use dollar signs?

$@.TEMP

Or even the same filename for every rule, with no $s or @ at all, since it will be deleted before the next command begins.

BTW, I trust you are working on Makefile rules, though you never mentioned it. :slight_smile:

1 Like

yes indeed, I am working on a makefile - sorry for not having mentioned that earlier.
I actually replaced $@.$$$$ with $@.tmp and it did work, so you're right. but I was stuck upon understanding why it shouldn't work with the $'s.
It seems like what JerryHone mentioned regd. the sed and gcc having a different $$ value could be the problem - trying to play around with that.