#! /usr/bin/make -f

NULL=

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DPKG_GENSYMBOLS_CHECK_LEVEL = 4

# The advantages of -Wl,-Bsymbolic-functions are of limited value here, and
# they mean that the test suite's LD_PRELOAD tricks don't work properly.
export DEB_LDFLAGS_MAINT_STRIP := -Wl,-Bsymbolic-functions

%:
	dh $@ --buildsystem autoconf

PY3REQUESTED := $(shell py3versions -r)
PY3DEFAULT := $(shell py3versions -d)
# Run setup.py with the default python3 last so that the scripts use
# #!/usr/bin/python3 and not #!/usr/bin/python3.X.
PY3 := $(filter-out $(PY3DEFAULT),$(PY3REQUESTED)) python3

override_dh_autoreconf:
	dh_autoreconf -- ./autogen.sh

override_dh_auto_configure:
	dh_auto_configure -- \
		--with-python-interpreters='$(PY3)' \
		--with-systemdsystemunitdir=/usr/lib/systemd/system \
		--with-systemduserunitdir=/usr/lib/systemd/user \
		--with-default-root=/var/lib/clickpkg \
		$(NULL)

execute_before_dh_installdocs:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	$(MAKE) -C doc subst DEFAULT_ROOT=/var/lib/clickpkg
	$(MAKE) -C doc html man
endif

execute_after_dh_auto_clean:
	$(MAKE) -C doc subst-clean || true
	$(MAKE) -C doc clean || true

PYTHON_INSTALL_FLAGS := \
	--force --root=$(CURDIR)/debian/tmp \
	--no-compile -O0 --install-layout=deb

override_dh_auto_install:
	dh_auto_install -- PYTHON_INSTALL_FLAGS='$(PYTHON_INSTALL_FLAGS)'
	rm -f debian/tmp/usr/lib/*/click/*.la

override_dh_install:
	rm debian/tmp/usr/lib/*/libclick-0.4.la
	dh_install
	DH_AUTOSCRIPTDIR=debhelper debhelper/dh_click --name=click-desktop

get-orig-source:
	uscan --noconf --force-download --rename --download-current-version --destdir=..
