#!/usr/bin/make -f
# -*- makefile -*-
# debian/rules for libpaper

export DH_COMPAT=3

export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
confflags := --build $(DEB_HOST_GNU_TYPE)
else
confflags := --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif

package	:= $(firstword $(shell dh_listpackages))
prefix	:= $(PWD)/debian/$(package)/usr
share	:= $(prefix)/share

version	:= $(shell dpkg-parsechangelog | \
			sed -ne 's/^Version: *\([0-9]\+:\)*//p')

get_misc_file   = test -f /usr/share/misc/$(1) && cp /usr/share/misc/$(1) $(1)
update_config_sub       := $(call get_misc_file,config.sub)
update_config_guess     := $(call get_misc_file,config.guess)

tag:
	cvs -Q status | grep File: | grep -qv Up-to-date && exit 1 || exit 0
	cvs tag -F $(subst .,_,debian_version_$(version))
ifeq ($(findstring -,$(version)),)
	cvs tag -F $(subst .,_,upstream_version_$(version))
endif

config:	config-stamp
config-stamp:
	dh_testdir
	./configure $(confflags) \
		--prefix=/usr

# Patch the generated libtool to avoid passing -rpath when linking,
# and to explicitly link libraries against the libraries they depend
# on. (thanks Richard Braakman <dark@xs4all.nl>)

	sed < libtool > libtool-2 \
		-e 's/^\(hardcode_libdir_flag_spec\).*$$/\1=" -D__LIBTOOL_IS_A_FOOL__ "/' \
		-e '/^archive_cmds="/s/"$$/ \\$$deplibs"/'
	mv libtool-2 libtool
	chmod 755 libtool
	touch $@

build:	config build-stamp
build-stamp:
	$(MAKE)
	touch $@

clean:	checkroot
	rm -f *-stamp
	-$(MAKE) distclean
	-$(update_config_sub)
	-$(update_config_guess)
	dh_clean

binary-indep:	checkroot build

binary-arch:	checkroot build
	dh_clean
	dh_installdirs

	$(MAKE) install \
		prefix=$(prefix) \
		mandir=$(share)/man \
		infodir=$(share)/info
	dh_movefiles --source=debian/$(package) -plibpaperg-dev

	dh_installchangelogs
	dh_installdocs
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdebconf
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch

.PHONY:	binary binary-indep binary-arch clean checkroot build config tag
