#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess. 
# $Id: rules 156 2011-10-23 12:02:34Z robert $

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

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
                     CFLAGS_ADD = -O0
else
                     CFLAGS_ADD = -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
                     INSTALL_ADD = -s
endif

CFLAGS=-Wall -g -DDEBIAN -D_FILE_OFFSET_BITS=64 $(CFLAGS_ADD)

ifeq (,$(DEB_BUILD_ARCH))
	DEB_BUILD_ARCH=$(shell dpkg-architecture -qDEB_BUILD_ARCH)
endif


build: build-stamp
build-stamp:
	dh_testdir

	./configure --prefix=/ \
		    --enable-history=simple \
		    --program-prefix="pd"


	$(MAKE) CFLAGS="$(CFLAGS)"
	touch "$@"

test: test-stamp
test-stamp: build-stamp
	$(MAKE) test
	touch "$@"

clean: 
	dh_testdir
	dh_testroot
	rm -f build-stamp test-stamp

	# Add here commands to clean up after the build process.
	if [ -f Makefile ]; then \
	  make realclean; \
	else \
	  make -f Makefile.in realclean; \
	fi

	rm -rf debian/_tmp_

	dh_clean

install: build-stamp test-stamp
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	# Add here commands to install the package into debian/<packagename>
	$(MAKE) CFLAGS="$(CFLAGS)" \
	        LDFLAGS="" INSTALL_PROGRAM='install -c $(INSTALL_ADD)' \
		prefix=$(CURDIR)/debian/$(shell dh_listpackages)/ \
		mandir='$$(prefix)/usr/share/man/man1' install

	mkdir -p -m755 debian/_tmp_
	cp -a ChangeLog.0 debian/_tmp_/changelog.0

# 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
	dh_installexamples
#	dh_install
	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installinfo
#	dh_undocumented
#	dh_installman

# ifneq (hurd,$(patsubst hurd-%,hurd,$(DEB_BUILD_ARCH)))
#	dh_link  bin/ksh usr/bin/ksh
#endif

	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	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 test
