#!/usr/bin/make -f

NULL =

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

export LIBDIR = "/usr/lib/$(shell dpkg-architecture -qDEB_BUILD_MULTIARCH)"
export INCLUDEDIR = "/usr/include/$(shell dpkg-architecture -qDEB_BUILD_MULTIARCH)"

%:
	CONFIGURE="./configure --with-symbols --prefix=/usr --libdir=$(LIBDIR) --includedir=$(INCLUDEDIR)" dh $@ --with quilt

override_dh_auto_clean:
	rm -Rf nx-X11/.build-exports
	dh_auto_clean

override_dh_clean:
	rm -f nx*/configure
	dh_clean

override_dh_install:

	# remove static libs
	rm debian/tmp/usr/lib/$(DEB_BUILD_MULTIARCH)/libXcomp.a
	rm debian/tmp/usr/lib/$(DEB_BUILD_MULTIARCH)/libXcompshad.a

	# remove extras, GL, and other unneeded headers
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/GL/
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/extensions/XK*.h
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/extensions/*Xv*.h
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/extensions/XRes*.h
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/extensions/record*.h
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/extensions/bigreqstr.h
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/extensions/xcmiscstr.h
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/extensions/XIproto.h
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/extensions/xf86bigfproto.h
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/extensions/xf86bigfont.h
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/extensions/XI.h
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/extensions/dpms.h
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/extensions/security.h
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/extensions/sync.h
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/extensions/xtestext1.h
	rm -R debian/tmp/usr/include/$(DEB_BUILD_MULTIARCH)/nx-X11/Xtrans/

	dh_install --fail-missing

override_dh_auto_install:
	PREFIX=/usr dh_auto_install -Smakefile

override_dh_auto_build:

	PREFIX=/usr dh_auto_build --parallel -- CDEBUGFLAGS="$(CPPFLAGS) $(CFLAGS)" LOCAL_LDFLAGS="$(LDFLAGS)" SHLIBGLOBALSFLAGS='$(filter-out -pie,$(LDFLAGS))' SHLIBDIR="$(LIBDIR)"

override_dh_strip:
	dh_strip -plibnx-x11-6 --dbg-package=libnx-x11-6-dbg
	dh_strip -plibxcomp3 --dbg-package=libxcomp3-dbg
	dh_strip -plibxcompshad3 --dbg-package=libxcompshad3-dbg
	dh_strip -pnxagent --dbg-package=nxagent-dbg
	dh_strip -pnxproxy --dbg-package=nxproxy-dbg

override_dh_makeshlibs:
	dh_makeshlibs -n