Skip to content

Instantly share code, notes, and snippets.

@billti
Created February 13, 2020 20:02
Show Gist options
  • Save billti/5ee2fb1659b9ee22220e002a0744f6e1 to your computer and use it in GitHub Desktop.
Save billti/5ee2fb1659b9ee22220e002a0744f6e1 to your computer and use it in GitHub Desktop.
nmake basics
# Set up the default build type. Build for release with: nmake build=release
!IF "$(BUILD)" == "RELEASE" || "$(build)" == "release"
_BUILD=release
!ELSE
_BUILD=debug
!ENDIF
BINDIR=bin\$(_BUILD)^\
!IF !EXIST("$(BINDIR)")
! IF [MKDIR $(BINDIR)] != 0
! ERROR Could not create the $(BINDIR) directory.
! ENDIF
!ENDIF
# Define the standard flags for compilation
CPPFLAGS=/Zi /EHsc /std:c++17 /permissive- /W3 /WX- /Fd$(BINDIR) /Fo$(BINDIR) /nologo
LNKFLAGS=/DEBUG /nologo
# Add on the build-type specific flags
!IF "$(_BUILD)" == "release"
CPPFLAGS=$(CPPFLAGS) /MD /O2 /Gy /Zc:inline /D "NDEBUG"
LNKFLAGS=$(LNKFLAGS) /OPT:REF,ICF
!ELSE
CPPFLAGS=$(CPPFLAGS) /MDd /RTC1 /JMC /D "_DEBUG"
LNKFLAGS=$(LNKFLAGS) /INCREMENTAL
!ENDIF
default: $(BINDIR)app.exe
@echo Build for $(_BUILD) completed
# Invoke the compiler if any dependencies are out of date
$(BINDIR)app.exe: src\test.cpp src\common.h
$(CPP) $(CPPFLAGS) src\test.cpp /link $(LNKFLAGS) /OUT:"$@"
clean:
-rmdir /s /q bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment