#!/usr/bin/make -f
#-*- makefile -*-
# Made with the aid of dh_make, by Craig Small
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# Some lines taken from debmake, by Christoph Lameter.

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

include /usr/share/dpatch/dpatch.make

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

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

# FOR AUTOCONF 2.52 AND NEWER ONLY
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

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
    confflags+="--enable-debug"
endif

build: patch-stamp build-stamp
build-stamp:
	dh_testdir
	
	# Make sure we use the latest autotools helpers.
	if test -f config.sub; then \
	        mv -f config.sub config.sub.debsave; \
	fi
	if test -f config.guess; then \
	        mv -f config.guess config.guess.debsave; \
	fi
	ln -sf /usr/share/misc/config.sub .
	ln -sf /usr/share/misc/config.guess .
											
	./configure --prefix=/usr CFLAGS=-Wall
	# Add here commands to compile the package.
	$(MAKE)
#	Disabled because xmlto doesn't translate umlauts into escape sequences as groff
#	need, see bug #328690
#	# Create German manpages at build time, so we need only .xml in .diff.gz 
#	-xmlto -o debian/ man debian/gif2png.de.xml
#	-mv -f debian/gif2png.1 debian/gif2png.de.1 
#	-xmlto -o debian/ man debian/web2png.de.xml
#	-mv -f debian/web2png.1 debian/web2png.de.1 

	touch build-stamp

clean: unpatch
	dh_testdir
	dh_testroot
	-$(MAKE) distclean
	-rm -f build-stamp install-stamp config.log config.status stamp-h1
	-rm -f Makefile config.h gif2png gif2png.spec
#		web2png.1 debian/gif2png.de.1 debian/web2png.de.1

	# Add here commands to clean up after the build process.
	-find . -type d -name .deps | xargs -r rm -r
	
	if test -L config.sub; then \
	        rm -f config.sub; \
	        if test -e config.sub.debsave; then \
			mv -f config.sub.debsave config.sub; \
	        fi; \
	fi
	if test -L config.guess; then \
	        rm -f config.guess; \
	        if test -e config.guess.debsave; then \
	                mv -f config.guess.debsave config.guess; \
	        fi; \
	fi

	dh_clean

install: install-stamp
install-stamp: build-stamp
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/gif2png.
	$(MAKE) install prefix=`pwd`/debian/gif2png/usr
	mv -f debian/gif2png/usr/man debian/gif2png/usr/share

	touch install-stamp

# 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_installdocs
	dh_installman
	dh_installchangelogs
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

source diff:                                                                  
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

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