#!/usr/bin/make -f

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

# This is the debhelper compatibility version to use.
# export DH_COMPAT=4
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

prefix=/usr
mandir=$(prefix)/share/man

arch=$(shell uname -m)
# check https://wiki.debian.org/Multiarch/Implementation#Dynamic_debian.2F.2A_files
libd=$(shell if [ -d $(prefix)/lib/$(arch)-linux-gnu ] ; then echo lib/$(arch)-linux-gnu; else echo lib;fi)
cp=/bin/cp
rm=/bin/rm

DESTDIR=$(CURDIR)/debian/lcd-daemon.tmp

build: build-stamp
build-stamp:
	dh_testdir
	#
	# run configure script
	#
	./configure $(shell dpkg-buildflags --export=cmdline) \
		--prefix=$(prefix) --libexecdir=$(prefix)/libexec \
		--mandir=$(mandir)

	$(MAKE) -s DESTDIR=$(DESTDIR)
	${rm} -rf $(DESTDIR)$(prefix)/$(libd)/*.la
	touch build-stamp

clean:
	rm -f build-stamp configure-stamp
	${rm} -rf $(DESTDIR) .deps
	dh_testdir
	dh_testroot
	dh_clean
	$(MAKE) clean || true; $(MAKE) distclean || true
	${rm} -f build-stamp

install: build
	dh_testdir
	dh_testroot
	dh_prep || dh_clean -k
	dh_installdirs
	$(MAKE) -s install DESTDIR=$(DESTDIR)

binary-indep: build install
	dh_testdir
	dh_testroot
	find $(DESTDIR)$(mandir) -name '*'.? -type f -exec gzip -q {} \;
	dh_install --sourcedir=$(DESTDIR) -plcd-daemon
	dh_installchangelogs
	dh_installcron
	dh_installdocs
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_makeshlibs -V
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here. 
binary-arch: build install

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
