#! /usr/bin/make -f

# Uncomment this to turn on verbose mode. 
export DH_VERBOSE=1
 
# This is the debhelper compatability version to use.
export DH_COMPAT=3

# set the cflags to what debian requires
OTHERCFLAGS := -O2 -Wall
#OTHERCFLAGS := -ggdb3

patch: patch-stamp
patch-stamp:
	dh_testdir
 
	# Add here commands to patch the source..
	for i in `ls -1 debian/patches/*` ; \
        do \
        echo "--- $$i ---" ; patch -p1 < $$i ; \
        done
 
	touch patch-stamp
 
unpatch:
	dh_testdir
 
	# Add here commands to reverse patchs to the source.
	if [ -f patch-stamp ] ; then \
        for i in `ls -1 debian/patches/* | sort -r` ; \
        do \
        echo "--- $$i ---" ; patch -R -p1 < $$i ; \
        done ; \
        fi \
 
	if [ -f patch-stamp ] ; then \
        rm patch-stamp ; \
        fi

build: patch-stamp build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE) OTHERCFLAGS="$(OTHERCFLAGS)"
	> $@

	# we need to give the manpage a proper name
	cp man_page.txt debian/tidy.1

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

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

	# remove the manpage we created
	rm -f debian/tidy.1

	# reverse patchs we applied this has to happen after make clean
	-$(MAKE) -s -f debian/rules unpatch

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/tidy.
	#$(MAKE) install PREFIX=$(CURDIR)/debian/tidy

	install -m 755 tidy \
	debian/tidy/usr/bin
	install -m 644 debian/tidy.conf \
	debian/tidy/etc

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
#       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
#	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#       dh_makeshlibs
	dh_installdeb
#       dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
#       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
#	dh_link
	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 patch unpatch
