#!/usr/bin/make -f

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
CFLAGS+=$(CPPFLAGS)
CXXFLAGS+=$(CPPFLAGS)

DESTDIR = $(CURDIR)/debian/quakespasm

%:
	dh $@

ifeq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
maybe_debug = DEBUG=0
else
maybe_debug = DEBUG=1
endif

override_dh_auto_clean:
	make -C Quake clean
	rm -f Misc/qs_pak/quakespasm.pak

override_dh_auto_build:
	make -C Quake \
		$(maybe_debug) \
		STRIP=": do not strip:" \
		DO_USERDIRS=1 \
		USE_SDL2=1 \
		USE_CODEC_FLAC=1 \
		USE_CODEC_OPUS=1 \
		USE_CODEC_MIKMOD=1 \
		USE_CODEC_UMX=1
	make -C Misc/qs_pak

override_dh_auto_install:
	install -d $(DESTDIR)/usr/games
	install Quake/quakespasm $(DESTDIR)/usr/games
	install -d $(DESTDIR)/usr/share/games/quake
	install -m 644 Misc/qs_pak/quakespasm.pak $(DESTDIR)/usr/share/games/quake

override_dh_installchangelogs:
	dh_installchangelogs debian/upstream-changelog

override_dh_strip:
	dh_strip --dbg-package=quakespasm-dbg
