我见过各种使用 .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 GNUmake
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/