#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DH_OPTIONS
export LDFLAGS=-Wl,--as-needed
export DPKG_EXPORT_BUILDFLAGS = 1
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

include /usr/share/dpkg/buildflags.mk

CFLAGS+=$(CPPFLAGS)
CXXFLAGS+=$(CPPFLAGS)

%:
	dh $@ --with autotools-dev

override_dh_auto_build:
	# Build the main game binaries
	make -C engine/hexen2 h2
	make -s -C engine/hexen2 clean
	make -C engine/hexen2 glh2
	make -s -C engine/hexen2 clean
	# Build the dedicated server
	make -C engine/hexen2/server
	# HexenWorld binaries
	make -C engine/hexenworld/server
	make -C engine/hexenworld/client hw
	make -s -C engine/hexenworld/client clean
	make -C engine/hexenworld/client glhw
	# HexenWorld master server
	make -C hw_utils/hwmaster
	# Build h2patch
	make -C h2patch
	# Launcher binaries
	#make -C launcher
	# Build the hcode compiler
	make -C utils/hcc

	# building the gamecode
	utils/hcc/hcc -q -src gamecode/hc/h2 -os
	utils/hcc/hcc -q -src gamecode/hc/h2 -os -name progs2.src
	utils/hcc/hcc -q -src gamecode/hc/hw -os -oi -on
	utils/hcc/hcc -q -src gamecode/hc/portals -os -oi -on


override_dh_installdocs:
	dh_installdocs --exclude=SrcNotes.txt --exclude=CHANGES

override_dh_auto_install:

override_dh_auto_clean:
	make -s -C engine/hexen2 distclean
	make -C engine/hexen2 clean
	make -C engine/hexen2/server clean
	rm -f engine/hexen2/server/h2ded
	make -s -C engine/hexenworld/client distclean
	make -s -C engine/hexenworld/server distclean
	#make -s -C launcher distclean
	rm -f gamecode/hc/h2/progs.dat
	rm -f gamecode/hc/h2/files.dat
	rm -f gamecode/hc/h2/progdefs.h
	rm -f gamecode/hc/hw/files.dat
	rm -f gamecode/hc/hw/progdefs.h
	rm -f gamecode/hc/portals/files.dat
	rm -f gamecode/hc/portals/progdefs.h
	rm -f gamecode/hc/h2/progs2.dat
	rm -f gamecode/hc/hw/hwprogs.dat
	rm -f gamecode/hc/portals/progs.dat
	make -s -C h2patch distclean
	make -s -C utils/hcc distclean
	make -s -C hw_utils/hwmaster distclean
	dh_auto_clean
	
