#!/usr/bin/make -f

install_dir=install -d -m 755
install_file=install -m 644
install_script=install -m 755
install_binary=install -m 755

PACKAGE = xloadimage
PKGDIR	= $(CURDIR)/debian/$(PACKAGE)

EXTRA_CFLAGS+=	-Wall -Wformat
# we are dealing with extremely old software here, give it a chance
EXTRA_CFLAGS+=	-fno-strict-aliasing -fwrapv

export DEB_BUILD_MAINT_OPTIONS	= hardening=+all optimize=-lto
export DEB_CFLAGS_MAINT_APPEND	= ${EXTRA_CFLAGS}

CHANGELOG = debian/upstream.changelog

override_dh_installchangelogs:
	dh_installchangelogs $(CHANGELOG)

override_dh_auto_configure:
	chmod 755 build-info configure
	dh_auto_configure

execute_before_dh_auto_clean:
	if grep -Fq 'configure-clean:: autoconfig' Makefile >/dev/null 2>&1; then \
		rm Makefile; \
	fi

override_dh_clean:
	rm -f build *.o xloadimage uufilter build.c config.log config.cache \
	       config.status config.h Makefile jpeg.conf tiff.conf
	rm -rf debian/tmp debian/files* debian/substvars debian/patched
	find . -name \*~ | xargs rm -vf
	dh_clean

override_dh_auto_install:
	$(install_binary) xloadimage $(PKGDIR)/usr/bin/
	ln -s xloadimage $(PKGDIR)/usr/bin/xsetbg
	ln -s xloadimage $(PKGDIR)/usr/bin/xview
	$(install_binary) uufilter $(PKGDIR)/usr/bin/

	$(install_file) xloadimagerc $(PKGDIR)/etc/X11/Xloadimage

	$(install_file) debian/mime $(PKGDIR)/usr/lib/mime/packages/xloadimage

	$(install_dir) $(PKGDIR)/usr/share/man/man1/
	$(install_file) xloadimage.man $(PKGDIR)/usr/share/man/man1/xloadimage.1x
	$(install_file) uufilter.man $(PKGDIR)/usr/share/man/man1/uufilter.1x
	ln -s xloadimage.1x.gz $(PKGDIR)/usr/share/man/man1/xsetbg.1x.gz
	ln -s xloadimage.1x.gz $(PKGDIR)/usr/share/man/man1/xview.1x.gz

%:
	dh $@

.PHONY: get-changelog
