GNU Make allows to specify order-only targets:
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
Order-only prerequisites are not contained in $^
; you may refer to them using $|
.
I find this useful for specifying system libraries as additional dependencies for linking.
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:
Is there any way to have Microsoft NMAKE do the equivalent?