#!/usr/bin/make -f
# -*- makefile -*-

# Hardening.
export DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie,+fortify

CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
CFLAGS:=$(shell dpkg-buildflags --get CFLAGS)
CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS)
LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS) -Wl,--as-needed

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

.PHONY: override_dh_auto_clean		\
	override_dh_auto_configure	\
	override_dh_auto_build-indep	\
	override_dh_strip

override_dh_auto_clean:
	dh_auto_clean
	rm -f Doxyfile				\
	      src/Base/gettext.h 		\
	      src/BodyPlugin/gettext.h 		\
	      src/PoseSeqPlugin/gettext.h 	\
	      src/Util/Config.h
	rm -Rf html

override_dh_auto_configure:
	dh_auto_configure --				\
		-DINSTALL_SDK:BOOL=TRUE			\
		-DINSTALL_DEPENDENCIES:BOOL=TRUE	\
		-DCNOID_ENABLE_GETTEXT:BOOL=TRUE	\
		-DUSE_EXTERNAL_EIGEN:BOOL=TRUE		\
		-DUSE_EXTERNAL_YAML:BOOL=TRUE

override_dh_auto_build-indep:
	doxygen Doxyfile # Generate documentation.

override_dh_auto_install:
	dh_auto_install -- # Install files in prefix.
	# Install desktop file
	mkdir -p debian/choreonoid/usr/share/applications/
	install -m 644 ./debian/choreonoid.desktop \
	 debian/choreonoid/usr/share/applications/
	# Install icons.
	mkdir -p debian/choreonoid/usr/share/icons/hicolor/scalable/apps/
	install -m 644 ./src/Choreonoid/icon/choreonoid.svg \
	 debian/choreonoid/usr/share/icons/hicolor/scalable/apps/choreonoid.svg
	for s in 16 24 32 48 64 256; do \
	 mkdir -p "debian/choreonoid/usr/share/icons/hicolor/$$s""x$$s/apps/"; \
	 install -m 644 "./src/Choreonoid/icon/choreonoid$$s.png" \
	  "debian/choreonoid/usr/share/icons/hicolor/$$s""x$$s/apps/choreonoid.png"; \
	done

override_dh_strip:
	dh_strip -a --dbg-package=choreonoid-dbg

%:
	dh  $@ --parallel --with pkgkde-symbolshelper
