GNU Make中的仅限顺序目标 - 对于Microsoft NMAKE呢?

3
GNU Make允许指定“仅限顺序”的目标: (详情请点击链接)

Occasionally [...] you have a situation where you want to impose a specific ordering on the rules to be invoked without forcing the target to be updated if one of those rules is executed. In that case, you want to define order-only prerequisites. Order-only prerequisites can be specified by placing a pipe symbol (|) in the prerequisites list: any prerequisites to the left of the pipe symbol are normal; any prerequisites to the right are order-only:

targets : normal-prerequisites | order-only-prerequisites

仅限于顺序的先决条件不包含在$^中; 您可以使用$|引用它们。

我发现这对于指定系统库作为链接的额外依赖项非常有用。

CXX      = cl
CXXFLAGS = /nologo /W4 /EHsc /MD
RC       = rc
RCFLAGS  = /nologo

# Link executables; $^ = all prerequisites; $| = order-only prerequisites
%.exe: %.obj %.res
    $(CXX) $(CXXFLAGS) /Fe$@ $^ $|

# Compile source files
%.obj: %.cpp
    $(CXX) $(CXXFLAGS) /c /Fo$@ $^

# Compile resource files
%.res: %.rc
    $(RC) $(RCFLAGS) /r /fo$@ $^

# System libraries needed for linking. Specify them as order-only prerequisites
# so their (no-op) rule being executed (due to their absence from the build
# directory) won't make the target appear out of date.
ErrorShow.exe:   | user32.lib
Singleton.exe:   | user32.lib advapi32.lib
ProcessInfo.exe: | user32.lib advapi32.lib gdi32.lib

# Set libraries as no-op targets to satisfy rule existence requirement.
advapi32.lib:
gdi32.lib:
user32.lib:

有没有办法让微软NMAKE执行相当的操作?
1个回答

1
很遗憾,Microsoft NMAKE没有类似GNU make中的仅限顺序前提条件,并且由于他们已经转向其他构建工具(如MSBuild),因此微软不太可能添加这样的功能。但是,Electric Cloud的高性能GNU make和NMAKE替代品ElectricAccelerator在NMAKE模式下支持仅限顺序前提条件。您可以试试这个。 (免责声明:我是ElectricAccelerator的架构师和首席开发人员)

谢谢Eric。当我提出那个问题时,我认为使用Visual Studio(在构建方面使用MSbuild)会隐藏很多东西,从而阻止我进行适当的学习...所以我转向了NMake,寻求简单性,但与GNU Make相比,NMake非常有限。同时,我现在只是使用Visual Studio... - Lumi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接