#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DH_COMPAT=3

tmp = $(shell pwd)/debian/tmp
SHELL=/bin/sh
 
ARCH = $(shell dpkg-architecture -qDEB_BUILD_ARCH)
ifeq ($(ARCH),alpha)
  COMPILER_FLAGS=CFLAGS="-O0 -mieee" CXXFLAGS="-O0 -mieee"
else
  COMPILER_FLAGS=CXX=g++ CC=gcc
endif

build: build-stamp

ifndef PERL
PERL=/usr/bin/perl
endif
 
-include debian/debiandirs

debian/debiandirs: admin/debianrules
	perl -w admin/debianrules echodirs > debian/debiandirs

build-stamp:
	dh_testdir
	if test ! -f configure; then \
	  $(MAKE) -f admin/Makefile.common ;\
	fi
	-chmod 755 configure
	$(COMPILER_FLAGS) \
	./configure $(configkde) --without-java
	$(MAKE)
	$(MAKE) -C dcoppython
	cp dcopperl/Makefile.PL debian/Makefile.back
	cp debian/Makefile.Debian.PL dcopperl/Makefile.PL
	(cd dcopperl ; $(PERL) Makefile.PL INSTALLDIRS=vendor ; \
		$(MAKE) OPTIMIZE="-O2 -g -Wall" )

	touch build-stamp

debian-clean:
	dh_testdir
	-rm -f build-stamp
	dh_clean

clean: debian-clean
	-rm -rf debian/debiandirs debian/tmp
	-cp debian/Makefile.back dcopperl/Makefile.PL
	if test -d CVS; then \
	  $(MAKE) -f admin/Makefile.common cvs-clean ;\
	fi
	-$(MAKE) distclean

binary-indep:	build
	dh_testdir
	dh_testroot


binary-arch:  build
	dh_testdir
	dh_testroot
	dh_clean
	dh_installdirs
	$(MAKE) DESTDIR=$(tmp)/ install
	$(MAKE) -C dcoppython DESTDIR=$(tmp)/ install
	$(MAKE) -C dcopperl PREFIX=$(tmp)/usr install
	dh_installdocs
	dh_installman
	install -d $(tmp)/usr/share/lintian/overrides
	cp debian/*.override $(tmp)/usr/share/lintian/overrides/
	for i in `ls debian/tmp/usr/share/lintian/overrides/`; do \
	  mv debian/tmp/usr/share/lintian/overrides/$$i debian/tmp/usr/share/lintian/overrides/`echo $$i | sed -e 's#.override##'`; \
	done
	dh_movefiles --sourcedir=debian/tmp
	dh_installchangelogs
	dh_strip
	dh_perl
	dh_compress -X.docbook -X.css -X-license -X.dcl -X.bz2
	dh_fixperms
	-chmod 755 debian/dcoppython/usr/lib/python2.1/qt.py
	dh_makeshlibs -V
	dh_installdeb
	dh_shlibdeps -l`pwd`/debian/libdcopc1/usr/lib:`pwd`/debian/libkdexparts1/usr/lib
	dh_gencontrol 
	dh_md5sums 
	dh_builddeb

# Below here is fairly generic really

binary:		binary-indep binary-arch

.PHONY: binary binary-arch clean
