#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/pkg-info.mk

# output every command that modifies files on the build system.
#DH_VERBOSE = 1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

CMAKE_ADDTIONAL_FLAGS ?=
ifneq ($(DEB_HOST_ARCH_CPU),amd64)
CMAKE_ADDITIONAL_FLAGS ?= -DUSE_INTRINSICS_SSE=OFF
endif

%:
	dh $@ --sourcedirectory=neo

# Upstream neo/CMakeLists.txt unconditionally appends -Werror=format-security
# and -Werror=format after CMAKE_CXX_FLAGS on the compiler command line. With
# GCC 15 that promotes the -Wformat-overflow=1 diagnostics of the legacy Doom
# classic code (sprintf into fixed-size buffers) into hard errors in
# doomclassic/doom/{hu_stuff,f_finale,wi_stuff}.cpp. CMAKE_CXX_FLAGS is placed
# before those -Werror flags, and the specific warning option wins there, so
# switching off that single warning class fixes the build without touching
# upstream sources; the format/format-security checks stay enabled.
override_dh_auto_configure:
	dh_auto_configure -- -G "Unix Makefiles" \
	 -DCMAKE_CXX_FLAGS="-Wno-format-overflow" \
	 -DSDL2=ON -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) \
	 -DUSE_SYSTEM_ZLIB=ON -DUSE_SYSTEM_LIBPNG=ON \
	 -DUSE_SYSTEM_LIBJPEG=ON -DUSE_SYSTEM_LIBGLEW=ON \
	 -DUSE_SYSTEM_IMGUI=ON -DUSE_SYSTEM_RAPIDJSON=ON \
	 -DCPU_TYPE=$(DEB_BUILD_ARCH_CPU) \
	 -DUSE_PRECOMPILED_HEADERS=OFF \
	 -DCPU_OPTIMIZATION="" \
	 $(CMAKE_ADDITIONAL_FLAGS)

override_dh_installchangelogs:
	# We won't have a ChangeLog if packaging from a released tarball.
	# In this case, use the RELEASE-NOTES.md
	dh_installchangelogs
	if [ ! -e ChangeLog ]; then \
	dh_installchangelogs -k RELEASE-NOTES.md ; \
	fi
