#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# fix build problems on the hurd
ifeq ($(DEB_HOST_ARCH),hurd-i386)
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--no-as-needed -Wl,-lpthread -Wl,--as-needed -fPIC
endif

# get source date in seconds since 1970 and pass it to the build
SOURCE_DATE_EPOCH=$(shell date -d "$$(dpkg-parsechangelog --count 1 -SDate)" +%s)
export DEB_CPPFLAGS_MAINT_APPEND = -DDEBIAN_EPOCH=$(SOURCE_DATE_EPOCH)

# source date string instead of \today in gle-manual
# use only digits, locale month is not reproducible
DATE_FMT = %Y-%m-%d
SOURCE_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)"  2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)" 2>/dev/null || date -u "+$(DATE_FMT)")

%:
#	dh $@ --with autoreconf
	dh $@ --with autotools_dev
#	dh $@ --with autotools_dev,autoreconf

override_dh_auto_build:
	make
	echo $(SOURCE_DATE) > gle-refman/title/source_date.tex
	make doc

override_dh_auto_clean:
	[ ! -f Makefile ] || make distclean
# remove files which are updated by autoreconf:
	[ ! -f aclocal.m4 ] || rm aclocal.m4
	[ ! -f configure ] || rm configure
# remove source_date for manual:
	[ ! -f gle-refman/title/source_date.tex ] || rm  gle-refman/title/source_date.tex

override_dh_auto_configure:
	-autoreconf -vfi
	./configure --build $(DEB_HOST_GNU_TYPE) --docdir=/usr/share/doc/gle-graphics/ --with-rpath=no --with-scripts=no

override_dh_auto_install:
	dh_auto_install
	cp debian/qgle.1 debian/gle-graphics/usr/share/man/man1/
	cp debian/manip.1 debian/gle-graphics/usr/share/man/man1/
# do not ship helper that is only used during build
	[ ! -f debian/gle-graphics/usr/bin/glebtool ] || rm debian/gle-graphics/usr/bin/glebtool
