#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# mingw does not know about the arm64 specific cflag branch-protection
# so strip it out of the build, so that the build doesn't fail.
export DEB_CFLAGS_MAINT_STRIP = -mbranch-protection=standard

ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes),yes)
	VENDOR_CONFIGURE_OPTIONS = --with-libssh2=included
endif
ifeq ($(shell dpkg-vendor --derives-from kali && echo yes),yes)
	VENDOR_CONFIGURE_OPTIONS = --with-libpcap=included
endif

%:
	dh $@ --with=python3

override_dh_auto_clean:
	dh_auto_clean
	dh_auto_clean --sourcedir=ndiff --buildsystem=pybuild
	rm -f nselib/data/jdwp-class/*.class nselib/data/psexec/nmap_service.ex*

override_dh_autoreconf:
	cp -r debian/libpcap .
	dh_autoreconf

override_dh_auto_configure:
	dh_auto_configure -- \
		--with-liblua=/usr \
		--with-liblinear \
		--without-zenmap \
		--without-ndiff \
		--enable-ipv6 \
		STRIP=/bin/true
	dh_auto_configure --sourcedir=ndiff --buildsystem=pybuild

override_dh_auto_build-indep:
	dh_auto_build
	dh_auto_build --sourcedir=ndiff --buildsystem=pybuild
	cd nselib/data/jdwp-class && /usr/lib/jvm/default-java/bin/javac *.java
	cd nselib/data/psexec && \
		i686-w64-mingw32-gcc ${CPPFLAGS} ${CFLAGS} -o nmap_service.exe nmap_service.c && \
		gzip -c -n9 nmap_service.exe | base64 | tac > nmap_service.ex_

override_dh_auto_test:
	dh_auto_test --sourcedir=ndiff --buildsystem=pybuild

override_dh_auto_install:
	dh_auto_install
	dh_auto_install --sourcedir=ndiff --buildsystem=pybuild
	mv debian/tmp/usr/share/man/pt_PT debian/tmp/usr/share/man/pt

override_dh_missing:
	dh_missing -X/usr/bin/uninstall_ -Xca-bundle.crt -X.pyc -Xnmap_service.exe --fail-missing

override_dh_install:
	dh_install -X/usr/bin/uninstall_ -Xca-bundle.crt -X.pyc -Xnmap_service.exe
