GNU Make允许指定“仅限顺序”的目标: (详情请点击链接)。
有没有办法让微软NMAKE执行相当的操作?
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执行相当的操作?