#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

# shared library versions, option 1
source = $(shell grep "^Source: " debian/control|head -1|sed 's/Source: \(.*\)/\1/g')

version = $(shell grep "^$(source) " debian/changelog|head -1 |sed 's/.*(\(.*\)\-[^\-]*).*/\1/g')

major=0

# Work around past library brokenness
ifeq ($(version),1.7)
ifeq ($(DEB_HOST_ARCH),m68k)
version = 1.7-4
endif
endif

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
cflags = -O0 -Wall -g
else
cflags = -O2 -Wall -g
endif

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
install = install
else
install = install-strip
endif


configure: configure-stamp
configure-stamp:
	dh_testdir
	# Fix it so that automake doesn't run
	cp -a $(CURDIR)/configure.in $(CURDIR)/configure.ac
	# Add here commands to configure the package.
	./configure --prefix=/usr --mandir=/usr/share/man --enable-shared
	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	$(MAKE) CFLAGS="$(cflags)"

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp config.log

	# Add here commands to clean up after the build process.
	-$(MAKE) distclean

	dh_clean
	rm -rf $(CURDIR)/tmp
	rm -rf $(CURDIR)/configure.ac

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp $(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

	dh_install --list-missing
#	dh_installdebconf	
	dh_installdocs
	dh_installexamples
#	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
	dh_installman
#	dh_installinfo
#	dh_undocumented
	dh_installchangelogs CHANGES
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs -V "libpopt0 (>= $(version))"
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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