#!/usr/bin/make -f

BUILDDIR = $(CURDIR)/cmake-build

%:
	dh $@ --buildsystem=cmake --parallel --builddirectory=$(BUILDDIR)

no_hardening_all_archs = mips mipsel

ifeq (,$(filter $(DEB_HOST_ARCH),$(no_hardening_all_archs)))
  export DEB_BUILD_MAINT_OPTIONS = hardening=+all
endif

DPKG_EXPORT_BUILDFLAGS = 1

export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

export LIBS := -lgl2ps -lGL -lGLU -lglut

include /usr/share/dpkg/buildflags.mk

# we need to set the CMAKE_BUILD_TYPE because it is set to "None" otherwise
override_dh_auto_configure:
	dh_auto_configure -- -DCMAKE_BUILD_TYPE=Release

override_dh_auto_build-indep:
#	$(MAKE) --directory=$(BUILDDIR) traas
	./tools/build/buildPyDoc.py -p docs/pydoc -c
	#Clean some unneeded files and fix permissions
	find ./tools -name '*.pyc' -print0 | xargs -0 rm -f
	rm -rf ./tools/contributed/traas/license.txt
	rm -rf ./tools/contributed/traci4matlab/license.txt
	rm -rf ./tools/game/sounds/license.txt

override_dh_auto_test:
	sed -i '/traas/d' ./docs/examples/runAll.py
	dh_auto_test

override_dh_auto_build-arch:
	dh_auto_build -a
	$(MAKE) --directory=$(BUILDDIR) man

override_dh_auto_install:
	dh_auto_install
	find . -type d -name "__pycache__" -delete

# By default, dh_compress compresses files that Debian policy mandates
# should be compressed. Examples and tutorials are more user-friendly
# if they remain uncompressed.
override_dh_compress:
	dh_compress --exclude=examples --exclude=tutorial
