#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

#export DH_VERBOSE = 1


# See FEATURE AREAS in dpkg-buildflags(1).
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND := -Wl,--as-needed

ifeq ($(DEB_HOST_ARCH_OS),kfreebsd)
	confflags += --without-alsa
endif

# See ENVIRONMENT in dpkg-buildflags(1).
# Package maintainers to append CFLAGS.
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# Package maintainers to append LDFLAGS.
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


%:
	dh $@ --buildsystem=meson


# dh_make generated override targets.
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
#override_dh_auto_configure:
#	dh_auto_configure -- \
#	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

#override_dh_auto_configure:
#	./autogen.sh
#	dh_auto_configure -- \
#	--with-boost-libdir=/usr/lib/${DEB_HOST_MULTIARCH} \
#	--disable-update-checker $(confflags) \
#	LIBS=-lpthread

ifeq ($(DEB_HOST_ARCH_OS),kfreebsd)
	echo "#undef WITH_ALSA" >> acconf.h
endif

#	exit 1

override_dh_auto_install:
	dh_auto_install
	find debian/tmp/usr/share -type f -exec chmod a-x '{}' ';'

override_dh_auto_clean:
	-cp build/git_version.h debian/git_version.h.backup
	-cp build/version.sh debian/version.sh.backup

	[ ! -f Makefile.inc ] || dh_auto_clean

	-mv debian/git_version.h.backup build/git_version.h
	-mv debian/version.sh.backup build/version.sh
	-rm -f src/libresrc/default_config_platform.json

override_dh_clean:
	dh_clean packages/desktop/aegisub.desktop.template \
	desktop/aegisub.desktop.template \
	src/libresrc/bitmap.cpp src/libresrc/bitmap.h \
	src/libresrc/default_config.cpp src/libresrc/default_config.h \
	tools/osx-bundle.sed

#override_dh_installdocs:
#	dh_installdocs --link-doc=aegisub

override_dh_auto_test:

override_dh_builddeb:
	dh_builddeb -- -Zxz -z9