makefile - 无法理解 ubuntu makefile 中 .suffixes 规则的使用

标签 makefile

我见过各种使用 .SUFFIXES 规则的 makefile。根据我的理解,这意味着,举一个简单的例子

第 1 步:

.SUFFIXES: .o .c .cpp .cc .cxx .C

#where $< indicates the source file and $@ represents the target file.
.cpp.o:
        $(CXX) -c $(INCPATH) -o "$@" "$<"

它将使用带有 CXX 编译器的源代码将目标文件编译为 .o 文件。

但在此之后我还看到了一些其他命令,例如

第二步:

all: Makefile $(TARGET)

第三步:

someobjectfile.o: dependencies

那么,如果我们可以使用 .SUFFIXES 规则来编译我的目标,那么为什么要使用 Step3。 如果这是一个愚蠢的问题,我深表歉意。

最佳答案

我首先指出后缀规则是 obsolete in GNU make

Suffix rules are the old-fashioned way of defining implicit rules for make. Suffix rules are obsolete because pattern rules are more general and clearer. They are supported in GNU make for compatibility with old makefiles.

(尽管由于遗留原因 .SUFFIXES 仍然控制哪些内置规则可用。)

也就是说,仅仅因为您告诉 make 可以从具有某些后缀的源编译 .o 文件,并不意味着除了单个源文件之外没有任何其他依赖项,例如以下是非常常见的

someobjectfile.o: someheader.h someotherheader.h

关于makefile - 无法理解 ubuntu makefile 中 .suffixes 规则的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38691264/

相关文章:

c - 为依赖扩展模式两次

c - 制定排除目标?

c++ - 如何链接到从源代码而不是系统库构建的 libusb?

c++ - 在我的用户定义的 makefile 中的 makefile 上使用 PETSc

c++ - Linux上适用于C++的任何更智能的编译系统

目录树中具有多个依赖项的 Makefile

makefile - “notdir”在 Makefile 中不起作用

makefile - 何时/如何指定配置/制作目标

c++ - C++ 的 Makefile,包含一个 .o 文件和一个 .CPP 文件

c++ - 如何在makefile中添加.c、.cc和.so文件来创建另一个.so?