#!/usr/bin/make -f

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

BUILD_DATE=$(shell LC_ALL=C date -u "+%d %B %Y" -d "@$(SOURCE_DATE_EPOCH)")

MANPAGES := $(wildcard $(CURDIR)/*.*.xml)

%:
	dh $@

override_dh_auto_build:
	# Create man page from DocBook XML
	for x in $(MANPAGES) ; do \
	    docbook2x-man --string-param header-3="$(BUILD_DATE)" $$x ; \
	done

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	python3 -m flake8

	shellcheck *.sh
endif

execute_after_dh_auto_install:
	install -d $(CURDIR)/debian/josm-installer/usr/bin
	install -m 755 $(CURDIR)/josm $(CURDIR)/debian/josm-installer/usr/bin/josm
	install -m 755 $(CURDIR)/josm-installer.py $(CURDIR)/debian/josm-installer/usr/bin/josm-installer

	install -d $(CURDIR)/debian/josm-installer/lib/systemd/system
	install -m 644 $(CURDIR)/josm-installer.service $(CURDIR)/debian/josm-installer/lib/systemd/system/josm-installer.service
	install -m 644 $(CURDIR)/josm-installer.timer $(CURDIR)/debian/josm-installer/lib/systemd/system/josm-installer.timer

	install -d $(CURDIR)/debian/josm-installer/usr/share/josm
	install -m 644 $(CURDIR)/placeholder $(CURDIR)/debian/josm-installer/usr/share/josm/.placeholder

	install -d $(CURDIR)/debian/josm-installer/etc/default
	install -m 644 $(CURDIR)/linux/tested/etc/default/josm $(CURDIR)/debian/josm-installer/etc/default/josm

	for size in 512x512 256x256 192x192 128x128 96x96 80x80 72x72 64x64 48x48 42x42 40x40 36x36 32x32 24x24 22x22 16x16 8x8; do \
		install -d $(CURDIR)/debian/josm-installer/usr/share/icons/hicolor/$${size}/apps ; \
		install -m 644 $(CURDIR)/linux/tested/usr/share/icons/hicolor/$${size}/apps/org.openstreetmap.josm.png $(CURDIR)/debian/josm-installer/usr/share/icons/hicolor/$${size}/apps/org.openstreetmap.josm.png ; \
	done
	install -d $(CURDIR)/debian/josm-installer/usr/share/icons/hicolor/scalable/apps
	install -m 644 $(CURDIR)/linux/tested/usr/share/icons/hicolor/scalable/apps/org.openstreetmap.josm.svg $(CURDIR)/debian/josm-installer/usr/share/icons/hicolor/scalable/apps/org.openstreetmap.josm.svg

	install -m 644 $(CURDIR)/linux/tested/usr/share/pixmaps/org.openstreetmap.josm.png $(CURDIR)/debian/josm-installer/usr/share/pixmaps/org.openstreetmap.josm.png
	install -m 644 $(CURDIR)/linux/tested/usr/share/applications/org.openstreetmap.josm.desktop $(CURDIR)/debian/josm-installer/usr/share/applications/org.openstreetmap.josm.desktop
	install -m 644 $(CURDIR)/linux/tested/usr/share/metainfo/org.openstreetmap.josm.appdata.xml $(CURDIR)/debian/josm-installer/usr/share/metainfo/org.openstreetmap.josm.appdata.xml

	install -d $(CURDIR)/debian/josm-installer/usr/share/mime/packages
	install -m 644 $(CURDIR)/linux/tested/usr/share/mime/packages/josm.xml $(CURDIR)/debian/josm-installer/usr/share/mime/packages
