# Makefile for StarRTS Bench - OpenWatcom wmake.
#
# Targets:
#   wmake             -- builds Win32 PE  -> dist/starrtsbench.exe (default)
#   wmake dos         -- builds 32-bit DOS (CauseWay) -> dist/starrts-dos.exe
#   wmake clean       -- removes built binaries and object files
#
# Or use the convenience wrappers:
#    macOS / Linux:    ./build.sh
#    Windows 9x / 11:  build.bat        (Win32 build)
#                      build-dos.bat    (DOS build, single-file CauseWay exe)
#
# The wrapper scripts create the dist/ directory and export WATCOM /
# PATH / INCLUDE before invoking wmake. They also pass BUILD_ID=<git-short-sha>
# so the binary self-identifies the source revision it was built from.
#
# Optional macros:
#   BUILD_ID                  -- short git hash, defaults to "dev"
#   STARRTS_HMAC_SECRET_HEX   -- official-build HMAC secret (64 hex chars).
#                                Local builds omit this and run as "unofficial".

EXE_NT   = dist/starrtsbench.exe
EXE_DOS  = dist/starrts-dos.exe

!ifndef BUILD_ID
BUILD_ID = dev
!endif

!ifdef STARRTS_HMAC_SECRET_HEX
SECRET_DEF = -dSTARRTS_HMAC_SECRET_TOKEN=$(STARRTS_HMAC_SECRET_HEX)
!else
SECRET_DEF =
!endif

# Win32 build pulls in the network/submission stack via STARRTS_NET.
# DOS build omits it (DOS networking is on the deferred list).
CFLAGS_NT  = -bt=nt  -5r -fp5 -ot -ox -zq -wx -dSTARRTS_NET -dSTARRTS_BUILD_ID_TOKEN=$(BUILD_ID) $(SECRET_DEF)
CFLAGS_DOS = -bt=dos -5r -fp5 -ot -ox -zq -wx -dSTARRTS_DOS  -dSTARRTS_BUILD_ID_TOKEN=$(BUILD_ID) $(SECRET_DEF)

LFLAGS_NT  = -l=nt
LFLAGS_DOS = -l=causeway

# Win32 link: wsock32.lib for Winsock 1.1 (used by src/net.c). 1.1 instead
# of Winsock 2 so the binary runs on stock Win95 too.
LIBS_NT    = wsock32.lib

SRCS = src/main.c     &
       src/timing.c   &
       src/cpuid.c    &
       src/host.c     &
       src/menu.c     &
       src/output.c   &
       src/k_path.c   &
       src/k_blit.c   &
       src/k_fixed.c  &
       src/k_fog.c    &
       src/score.c    &
       src/sha256.c   &
       src/hmac.c     &
       src/json.c     &
       src/secret.c   &
       src/submit.c   &
       src/net.c

all: $(EXE_NT) .SYMBOLIC

dos: $(EXE_DOS) .SYMBOLIC

$(EXE_NT): $(SRCS) src/bench.h Makefile
    wcl386 $(CFLAGS_NT) $(LFLAGS_NT) $(SRCS) -fe=$(EXE_NT) $(LIBS_NT)

# DOS build: -l=causeway selects OpenWatcom's CauseWay system and writes
# the runnable DOS extender .exe directly. Do not run wbind here; wbind is
# for OpenWatcom 32-bit extended Windows/Win386 programs and creates a Win16
# wrapper, which DOS reports as "This is a Windows 16-bit executable."
$(EXE_DOS): $(SRCS) src/bench.h Makefile
    wcl386 $(CFLAGS_DOS) $(LFLAGS_DOS) $(SRCS) -fe=$(EXE_DOS)

clean: .SYMBOLIC
    rm -f dist/*.exe dist/*.rex *.obj src/*.obj
