#!/usr/bin/make -f
# $Id: rules 784 2012-01-17 09:28:07Z aqua $

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

# To resolve shlib dependencies at runtime, we need to take the annoying step
# of wrapping the executables in a shell script that can add a private library
# path to $LD_LIBRARY_PATH, then invoke the real binary from /usr/lib/quelcom/.
# This seemed the least odious of the available options.

build: build-stamp build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
	dh_testdir
	# stripping is disabled during the build so that it can
	# be done (or not) by dh_strip
	$(MAKE) PREFIX=/usr STRIP=/bin/true
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	$(MAKE) clean
	# Clean up the HTML docs
	rm -rf doc/quelcom doc/html
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	# binaries go to /usr/lib/quelcom for use by the wrapper
	$(MAKE) \
		PREFIX=$(CURDIR)/debian/quelcom/usr \
		INFODIR=$(CURDIR)/debian/quelcom/usr/share/info \
		BINDIR=$(CURDIR)/debian/quelcom/usr/lib/quelcom \
		LIBDIR=$(CURDIR)/debian/quelcom/usr/lib/quelcom \
		install
	# install the wrapper
	mkdir -p $(CURDIR)/debian/quelcom/usr/bin
	install debian/wrapper.sh $(CURDIR)/debian/quelcom/usr/bin/quelcom
	for e in "$(CURDIR)/debian/quelcom/usr/lib/quelcom/q"* ; do \
		ln -s quelcom $(CURDIR)/debian/quelcom/usr/bin/`basename "$$e"`;\
	done

	# move the generated HTML docs over so dh_installdocs can
	# be given a more suitable name later on
	mv doc/quelcom doc/html

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs README doc/html doc/quelcom.txt
	dh_installexamples
	dh_install
	dh_installinfo
	dh_installman debian/manpages/*
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	LD_LIBRARY_PATH="$(CURDIR)/debian/quelcom/usr/lib/quelcom" dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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