#!/usr/bin/make -f
#export DH_VERBOSE = 1


export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export DEB_CXXFLAGS_MAINT_APPEND = -Wall -pedantic -O3
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

include /usr/share/dpkg/architecture.mk

ifeq ($(DEB_HOST_ARCH),ia64)
  # gcc o3 segfault on ia64
  # It's just annoying, not a sign I'll care about ia64
  export DEB_CXXFLAGS_MAINT_APPEND = -Wall -pedantic
endif


%:
	dh $@

build-indep:
	# pass

override_dh_clean-indep:
	dh_clean -i
	$(RM) DDNet*.png
	$(RM) -r datasrc/*.pyc datasrc/__pycache__

override_dh_auto_configure-arch:
	dh_auto_configure -a -- \
		-DMYSQL=ON -DWEBSOCKETS=ON -DPREFER_BUNDLED_LIBS=OFF -DAUTOUPDATE=OFF \
		-DTESTRUNNER_ARGS=--gtest_filter=-Jobs.LookupHost

override_dh_auto_build-arch:
	dh_auto_build -a

override_dh_auto_test-arch:
	+cd obj-$(DEB_BUILD_GNU_TYPE) && make run_tests

override_dh_auto_install-arch:
	cd obj-$(DEB_BUILD_GNU_TYPE) && DESTDIR=$(CURDIR)/debian/tmp cmake -DCOMPONENT=portable -P cmake_install.cmake

override_dh_auto_install-indep:

override_dh_install-indep:
	dh_install -i
	for f in languages/license.txt; do \
		rm -r "debian/ddnet-data/usr/share/games/ddnet/data/$$f"; \
	done
	for exe in DDNet; do \
		icns2png -x other/icons/$${exe}.icns; \
		for px in 16 32 48 128 256 512; do \
			size=$${px}x$${px}; \
			fn=$${exe}_$${size}x32.png; \
			if [ -f $${fn} ]; then \
				dir=debian/ddnet-data/usr/share/icons/hicolor/$${size}/apps/; \
				mkdir -p $${dir}; \
				mv $${fn} $${dir}/$${exe}.png; \
			fi; \
		done; \
	done
