#!/usr/bin/make -f
#
# Copyright 2001,2002,2003,2007 by Stefan Hornburg (Racke) <racke@linuxia.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA  02111-1307  USA.

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

ifndef PERL
	PERL = /usr/bin/perl
endif

TMP =`pwd`/debian/tmp
archlib =`$(PERL) -MConfig -e 'print $$Config{installarchlib}'`
config =INSTALLDIRS=perl INSTALLMAN1DIR=$(TMP)/usr/share/man/man1 INSTALLMAN3DIR=$(TMP)/usr/share/man/man3 INSTALLPRIVLIB=$(TMP)/usr/lib/perl5 INSTALLARCHLIB=$(TMP)$(archlib) INSTALLBIN=$(TMP)/usr/bin INSTALLSCRIPT=$(TMP)/usr/bin

build: build-stamp
build-stamp:
	dh_testdir

# Add here commands to compile the package.
	$(PERL) Makefile.PL INSTALLDIRS=vendor
# For potato builds
	if ! grep ^install_vendor Makefile >/dev/null; then \
		$(MAKE) clean; \
		$(PERL) Makefile.PL $(config); \
	fi
	$(MAKE) OPTIMIZE="-O2 -g -Wall"

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

# Add here commands to clean up after the build process.
	$(PERL) Makefile.PL
	$(MAKE) distclean
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

# Add here commands to install the package into debian/tmp.
	$(MAKE) install DESTDIR=$(TMP); \
	mkdir -p $(TMP)/usr/share/debaux/cpan
	cp -p share/cpan/compat share/cpan/control share/cpan/debbuild share/cpan/rules $(TMP)/usr/share/debaux/cpan
#	dh_movefiles
	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_testversion
	dh_testdir
	dh_testroot
#	dh_installdebconf	
	dh_installdocs
	dh_installexamples
	dh_installmenu
#	dh_installemacsen
#	dh_installpam
#	dh_installinit
	dh_installcron
#	dh_installmanpages
	dh_installinfo
	dh_installchangelogs
	dh_install -i --sourcedir=debian/tmp
	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
