#!/usr/bin/make -f

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

BUILD_FLAGS=

# Not using dpkg-architecture to keep in sync with tremulous's Makefile
Q3ARCH=$(shell uname -m | sed -e s/i.86/x86/ | sed -e s/alpha/axp/)
# We don't want tremulous to automatically optimize for i586 or i686!
ifeq ($(Q3ARCH),x86)
	BUILD_FLAGS="OPTIMIZE=-O3 -march=i486 -fomit-frame-pointer -ffast-math -funroll-loops -falign-loops=2 -falign-jumps=2 -falign-functions=2 -fstrength-reduce"
endif

BUILD_DIR=build/release-linux-$(Q3ARCH)

build clean binary-indep binary-arch binary install install-indep install-arch: %:
	dh $@

override_dh_auto_clean:
	rm -fr build

override_dh_auto_build:
	$(MAKE) $(BUILD_FLAGS)
	cp build/release-linux-$(Q3ARCH)/tremulous.$(Q3ARCH) build/release-linux-$(Q3ARCH)/tremulous
	cp build/release-linux-$(Q3ARCH)/tremded.$(Q3ARCH) build/release-linux-$(Q3ARCH)/tremded
	zip -9 debian/z-debian-tremulous-ui-fixes.pk3 ui/joinserver.menu

override_dh_compress:
	dh_compress -X.pdf

.PHONY: build clean binary-indep binary-arch binary install install-indep install-arch
