# Legacy NMake build.
#
# CMake (CMakeLists.txt / CMakePresets.json) is the recommended way to build the
# 32-bit and 64-bit versions. This Makefile is kept for convenience and builds
# for the architecture of the Visual Studio command prompt it is run from.
#
# Run nmake from a Visual Studio 2017 "x86 Native Tools" or "x64 Native Tools"
# command prompt. The 64-bit executable is named wdxtest64.exe.

DEBUG=0

!IF $(DEBUG)
DBGOPT=-DDEBUG
!ENDIF

CCOPT=-nologo -W3 -O2 -Isrc -MD -D_CRT_SECURE_NO_WARNINGS $(DBGOPT)
CCO=-Fo
CLE=-Fe
CL=cl $(CCOPT)
CC=cl $(CCOPT) -c
LINKOPT=/NOLOGO
LINKO=/OUT:
LINK=link $(LINKOPT)
RC=rc /isrc
RCO=/fo

MAKEFILES=Makefile obj

!IF "$(VSCMD_ARG_TGT_ARCH)"=="x64"
TARGET=wdxtest64.exe
!ELSE
TARGET=wdxtest.exe
!ENDIF

WDXTVER=0.6


all : $(TARGET)

zips : $(MAKEFILES) all wdxtest-$(WDXTVER).zip

wdxtest-$(WDXTVER).zip : $(MAKEFILES) obj/zip.lst
	if exist $@ del $@
	zip $@ -rX9@ <obj/zip.lst

obj\zip.lst : $(MAKEFILES) File_Id.diz README.txt README_ru.txt $(TARGET) Makefile src/wdxtest.c src/contentplug.h
	@echo>$@ File_Id.diz
	@echo>>$@ README.txt
	@echo>>$@ README_ru.txt
	@echo>>$@ $(TARGET)
	@echo>>$@ Makefile
	@echo>>$@ src/wdxtest.c
	@echo>>$@ src/contentplug.h

clean :
	-del obj\*.* /q
	-del wdxtest.exe
	-del wdxtest64.exe
	-del wdxtest-$(WDXTVER).zip

obj :
	if not exist obj/nul mkdir obj

$(TARGET) : $(MAKEFILES) obj/wdxtest.obj
	$(LINK) $(LINKO)$@ obj/wdxtest.obj

obj/wdxtest.obj : $(MAKEFILES) src/contentplug.h src/wdxtest.c
	$(CC) $(CCO)$@ src/wdxtest.c
