#!/usr/bin/make -f

export NXLIBDIR="/usr/lib/$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)/nx"

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

%:
	PREFIX=/usr NXLIBDIR=$(NXLIBDIR) dh ${@}

override_dh_auto_build:
	PREFIX=/usr NXLIBDIR=$(NXLIBDIR) PERL_INSTALLDIRS=vendor dh_auto_build --buildsystem=makefile

override_dh_auto_install:
	$(MAKE) -f Makefile build-arch
	PREFIX=/usr NXLIBDIR=$(NXLIBDIR) dh_auto_install

override_dh_install:

	# FIXME: the x2goagent.keyboard file is not required with nxagent (>= 3.5.99.17) anymore
	# In fact, this file should be removed upstream.
	rm -f debian/tmp/etc/x2go/x2goagent.keyboard

	dh_install

	# FIXME: upstream has some X2Go scripts in their tarball that are not executable
	# During binary-all builds, the below directory is non-existent, so ignoring
	# any sorts of failures here.
	-chmod a+x debian/x2goserver/usr/lib/x2go/*

	# on arch: all-only,source builds, the x2goserver-x2goagent.features file is non-present.
	# so let's handle this gracefully...
	if [ -e debian/x2goserver-x2goagent/usr/share/x2go/x2gofeature.d/x2goserver-x2goagent.features ]; then \
	    chmod 0755 debian/x2goserver-x2goagent/usr/share/x2go/x2gofeature.d/x2goserver-x2goagent.features; \
	fi


override_dh_missing:
	dh_missing --fail-missing

override_dh_auto_clean:
	rm -Rfv x2goserver/.build_html
	rm -Rfv x2goserver-extensions/.build_html
	rm -f MYMETA.yml
	PREFIX=/usr NXLIBDIR=$(NXLIBDIR) dh_auto_clean
	rm -fv Makefile.perl
	rm -fv Makefile.perl.old

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