#!/usr/bin/make -f
# rules for building IJS
# Based on debhelper template by Joey Hess
# Copyright 2002-2004 Roger Leigh

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

# This is the debhelper compatibility version to use.
export DH_COMPAT=4

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE	?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE	?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)


ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -g
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

# Get upstream version, and define libgimpprint suffix
UPSTREAM_VERSION = $(shell dpkg-parsechangelog | grep ^Version | sed "s/.* //" | sed "s/-[^-]*$$//")
LIBRARY_VERSION = -$(UPSTREAM_VERSION)
#LIBRARY_VERSION = 1

configure: configure-stamp debian/control
configure-stamp:
	dh_testdir
	cd debian ; \
	for file in libijs.*; do \
	  ln -sf $$file `echo $$file | sed -e 's/libijs/libijs$(LIBRARY_VERSION)/'` ; \
	done
	mkdir debian/build; \
	cd debian/build; \
	../../configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info --enable-shared

	touch configure-stamp

build: build-stamp debian/control
build-stamp: configure-stamp
	dh_testdir

	cd debian/build; \
	$(MAKE)

	touch build-stamp

clean: debian/control
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	-$(MAKE) distclean
	-test -r /usr/share/misc/config.sub && \
	  cp -f /usr/share/misc/config.sub config.sub
	-test -r /usr/share/misc/config.guess && \
	  cp -f /usr/share/misc/config.guess config.guess

	rm -rf debian/build debian/install
	rm -rf $(CURDIR)/debian/libijs$(LIBRARY_VERSION)*
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	cd debian/build; \
	$(MAKE) DESTDIR=$(CURDIR)/debian/install install

	dh_install


# 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
#	rm $(CURDIR)/debian/libijs$(LIBRARY_VERSION)-dev/usr/bin/*example
#	mkdir -p $(CURDIR)/debian/libijs$(LIBRARY_VERSION)-dev/usr/share/doc/libijs$(LIBRARY_VERSION)-dev
#	cp ijs_spec.ps $(CURDIR)/debian/libijs$(LIBRARY_VERSION)-dev/usr/share/doc/libijs$(LIBRARY_VERSION)-dev
	dh_installdocs
	dh_installchangelogs
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps -l$(CURDIR)/debian/libijs-0.35/usr/lib
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Make sure debian/control is up-to-date.
debian/control: debian/changelog debian/control.in
	sed -e 's/#UPSTREAM_VERSION#/$(UPSTREAM_VERSION)/g' -e 's/#LIBRARY_VERSION#/$(LIBRARY_VERSION)/g' <debian/control.in >debian/control

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