#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

# Enable verbose mode (optional)
export DH_VERBOSE=1
UPSTREAM_CLEAN := $(firstword $(subst +, ,$(DEB_VERSION_UPSTREAM)))
export UPSTREAM_CLEAN

%:
	dh $@ --buildsystem=gradle --with $(shell dh_addons strip-nondeterminism)

override_dh_auto_clean:
#	#$(MAKE) clean || true
	dh_auto_clean -- clean
	rm -rf .gradle build
	#rm -f debian/files

override_dh_auto_build:
	# Compile the rst source file into a traditional man page
	rst2man debian/ipscan.1.rst debian/ipscan.1
	#$(MAKE) linux64 || true
	dh_auto_build -- any

override_dh_install:
	# 1. Run the standard dh_install first for all your other files
	dh_install

	# 2. Sort out the application icon (rename and copy)
	mkdir -p debian/ipscan/usr/share/pixmaps/
	cp resources/images/icon128.png debian/ipscan/usr/share/pixmaps/net.azlib.ipscan.png
	
	# 3. Sort out the application desktop filename
	mkdir -p debian/ipscan/usr/share/applications/
	cp ext/deb-bundle/usr/share/applications/ipscan.desktop debian/ipscan/usr/share/applications/net.azlib.ipscan.desktop
	
	mkdir -p debian/ipscan/usr/share/metainfo/
	cp ext/deb-bundle/usr/share/metainfo/ipscan.appdata.xml debian/ipscan/usr/share/metainfo/net.azlib.ipscan.metainfo.xml
	
override_dh_auto_test:
	# Do nothing to skip tests
	
override_dh_missing:
	# 1. Run the standard missing-files check first
	dh_missing --fail-missing
	
	# Validate the AppStream metadata inside the build directory
	appstreamcli validate-tree --no-net --explain debian/ipscan/ || true
