gcc -M -MM -MQ -MF -MT -MD

Posted suonikeyinsu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gcc -M -MM -MQ -MF -MT -MD相关的知识,希望对你有一定的参考价值。

静态模式规则对一个较大工程的管理非常有用。它可以对整个工程的同一类文件的重建规则进行一次定义,而实现对整个工程中此类文件指定相同的重建规则。比如,可
以用来描述整个工程中所有的.o 文件的依赖规则和编译命令。通常的做法是将生成同一类目标的模式定义在一个 make.rules 的文件中。在工程各个模块的 Makefile 中包含
此文件。

gcc 

-M: output a rule suitable for make describing the dependencies of the main source file.The preprocessor outputs one make rule containing the object file name for that source file, a colon, and the names of all the included files, including those coming from -include or -imacros command line options.

Unless specified explicitly (with -MT or -MQ), the object file name consists of the name of the source file with any suffix replaced
with object file suffix and with any leading directory parts removed. If there are many included files then the rule is split into
several lines using \\-newline. The rule has no commands.

 

-MM: Like -M but do not mention header files that are found in system header directories, nor header files that are included, directly or
indirectly, from such a header.

This implies that the choice of angle brackets or double quotes in an #include directive does not in itself determine whether that
header will appear in -MM dependency output. This is a slight change in semantics from GCC versions 3.0 and earlier.

 

-MF file
When used with -M or -MM, specifies a file to write the dependencies to. If no -MF switch is given the preprocessor sends the rules to
the same place it would have sent preprocessed output.

When used with the driver options -MD or -MMD, -MF overrides the default dependency output file.

 

-MT target
Change the target of the rule emitted by dependency generation. By default CPP takes the name of the main input file, deletes any
directory components and any file suffix such as .c, and appends the platform\'s usual object suffix. The result is the target.

An -MT option will set the target to be exactly the string you specify. If you want multiple targets, you can specify them as a single
argument to -MT, or use multiple -MT options.

For example, -MT \'$(objpfx)foo.o\' might give

    $(objpfx)foo.o: foo.c

 

 

-MQ target
Same as -MT, but it quotes any characters which are special to Make. -MQ \'$(objpfx)foo.o\' gives

  $$(objpfx)foo.o: foo.c

The default target is automatically quoted, as if it were given with -MQ.

 

 

-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 takes the name of the input file, removes any directory
components and suffix, 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 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 process.

 

以上是关于gcc -M -MM -MQ -MF -MT -MD的主要内容,如果未能解决你的问题,请参考以下文章

Mac OSX 上的 GCC——多个版本的 gcc

mingw和gcc的关系?mingw具有gcc的全部核心编译功能吗

gcc 和 g++/gcc-c++ 有啥区别?

ubuntu系统下怎么安装gcc编译器

GCC:在 GCC 版本之间伪装

arm gcc 内嵌汇编,gcc该是啥选项呢