#!/usr/bin/make -f

export DH_VERBOSE = 1
export DEB_BUILD_MAINT_OPTIONS := hardening=+all
export DH_ALWAYS_EXCLUDE := COPYING:LICENSE
export LANG:=C

INSTALL_DIR=${CURDIR}/debian/lazbuild

override_dh_auto_build-indep:
	# Nothing to do here

override_dh_auto_build-arch:
	make FPC=/usr/bin/fpc OPT='@hardening -gl -gw -Crtoi' lazbuild

override_dh_auto_install-arch:
	# Fix permissions
	chmod a-x lcl/include/screen.inc
	chmod a+x components/aggpas/examples/build_find_compile/build*
	chmod a+x components/fpweb/images/make_fpweb_images_res.sh
	chmod a+x components/rtticontrols/fpdoc/*.sh

	# Remove extra license files
	-rm components/lazdebuggers/lazdebuggerfplldb/gpl*.txt
	-rm components/lazdebuggers/lazdebuggerlldb/gpl*.txt
	-rm components/lazreport/license.txt
	-rm lcl/interfaces/qt?/cbindings/COPYING.TXT

	# Remove empty folder
	-rmdir components/chmhelp/lhelp/lhelp.app/Contents/MacOS

	install -Dm755 lazbuild ${INSTALL_DIR}/usr/bin/lazbuild
	mkdir -p ${INSTALL_DIR}/usr/lib/lazarus

	# Only install folders needed for lazbuild
	cp -a lcl        ${INSTALL_DIR}/usr/lib/lazarus
	cp -a components ${INSTALL_DIR}/usr/lib/lazarus
	cp -a packager   ${INSTALL_DIR}/usr/lib/lazarus
	cp -a ide        ${INSTALL_DIR}/usr/lib/lazarus

%:
	dh $@
