帅绝人寰 发表于 2010-06-19 11:25

一个GCC问题,-MMD的

一个project的Makefile中,有这么几行:9 .c.o:
10         $(CC) $(CFLAGS) -MMD -o $@ -c $<
11         @cp $*.d $*.P; \
12          sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$//' \
13            -e '/^$/ d' -e 's/$/ :/' < $*.d >> $*.P; \
14         rm -f $*.d
15
当$@是 AMD/MSR-K6时, gcc有时在当前目录产生MSR-K6.d文件,有时产生AMD/MSR-K6.d文件。 RHEL5/Fedora8是第一种情况,而有人说Fedora12、13是第二种情况。

这就导致第11行的cp命令没法写。如果指定cp的源文件是$*.d,则在F8、RHEL上出错; 如果指定$(*F).d,则在F12、F13上出错。


有没有办法,强制gcc产生AMD/MSR-K6.d?也就是说,即使指定了-o选项,也要gcc采用 输入文件的pathname、只是把*.c换成*.d?


man gcc这么说的:

       -MD -MD is equivalent to -M -MF file, except that -E is not implied.The driver determines file based on whether an -o
         option is given.If it is, the driver uses its argument but with a suffix of .d, otherwise it take the basename of the
         input file and applies a .d suffix.

         If -MD is used in conjunction with -E, any -o switch is understood to specify the dependency output file (but
         @pxref{dashMF,,-MF}), but if used without -E, each -o is understood to specify a target object file.

         Since -E is not implied, -MD can be used to generate a dependency output file as a side-effect of the compilation pro-
         cess.

       -MMD
         Like -MD except mention only user header files, not system header files.

EricFisher 发表于 2010-06-19 20:06

或者可以考虑在cp之前,加一条判断语句
页: [1]
查看完整版本: 一个GCC问题,-MMD的