#!/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

# This is the debhelper compatability version to use.
export DH_COMPAT=3

pixmaps = $(CURDIR)/debian/keybled/usr/share/pixmaps
bindir = $(CURDIR)/debian/keybled/usr/bin
kdedocs = $(CURDIR)/debian/keybled/usr/share/doc/kde/HTML
overrides = $(CURDIR)/debian/keybled/usr/share/lintian/overrides

INSTALL_DIR = install -p -d -o root -g root -m 755
INSTALL_FILE = install -p -o root -g root -m 644

ARCH = $(shell dpkg-architecture -qDEB_BUILD_ARCH)
ifeq ($(ARCH),alpha)
  export CFLAGS=-O0 -mieee
  export CXXFLAGS=-O0 -mieee
endif

ifeq ($(ARCH),hppa)
  export CXXFLAGS=-ffunction-sections
endif

ifeq ($(ARCH),i386)
  # Uncomment the following 2 lines for i686 optimization
  # export CFLAGS=-O3 -march=i686 -ffast-math -finline-functions
  # export CXXFLAGS=-O3 -march=i686 -ffast-math -finline-functions
endif

build: build-stamp
	
-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
	./configure $(configkde)
	$(MAKE)
	touch build-stamp

clean: debian-clean
	dh_clean

debian-clean:
	dh_testdir
	-rm -f debian/debiandirs
	if test -d CVS; then \
	   make -f admin/Makefile.common cvs-clean ;\
	fi
	-rm -f *-stamp
	-$(MAKE) distclean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Install overrides.
	$(INSTALL_DIR) $(overrides)
	$(INSTALL_FILE) $(CURDIR)/debian/*.override $(overrides)
	for i in `ls $(overrides)/`; do \
	  mv $(overrides)/$$i \
	    $(overrides)/`echo $$i | sed -e 's#.override##'`; \
	done

	# Main install.
	$(MAKE) install DESTDIR=$(CURDIR)/debian/keybled

	# Generate HTML docs.
	for i in `find $(CURDIR)/debian/keybled -name "index.docbook"`; do \
	  pushd . > /dev/null; cd `dirname $$i`; meinproc `basename $$i`; \
	  popd > /dev/null; done

	# Make common links for docs.
	for p in `dh_listpackages`; do \
	  for i in `find $(kdedocs) -type d -name $$p`; do \
	    ln -f -n -s ../common $$i/common; done; done

	perl -w admin/debianrules cleanup
	
# 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_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 ChangeLog
	dh_link
	dh_strip
	dh_compress --exclude=.docbook
	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 configure
