#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess. 

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

CXXFLAGS = -g -D_REENTRANT -Wl,-z,defs
export CXXFLAGS

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
    CXXFLAGS += -O0
else
    ifeq (m68k,$(DEB_HOST_ARCH))
        CXXFLAGS += -O0
    else ifeq (alpha,$(DEB_HOST_ARCH))
        CXXFLAGS += -O0
    else ifeq (sh4,$(DEB_HOST_ARCH))
        CXXFLAGS += -O2 -mieee
    else
        CXXFLAGS += -O2
    endif
endif

build: build-stamp
build-stamp:
	dh_testdir

	dh_autoreconf
	./configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
	$(MAKE)

	$(MAKE) check

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	[ ! -f Makefile ] || $(MAKE) distclean
	find src -name '*.o' | xargs rm -f
	rm -f config.log
	rm -rf lib

	dh_autoreconf_clean
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	$(MAKE) DESTDIR=`pwd`/debian/tmp \
		htmldir=/usr/share/doc/libcppunit-doc/html \
		install

	sed -i "/dependency_libs/ s/'.*'/''/" `find . -name '*.la'`

	# Runtime library package
	dh_install -plibcppunit-1.12-1 --autodest debian/tmp/usr/lib/lib*.so.*

	# Developer package
	dh_install -plibcppunit-dev --autodest debian/tmp/usr/bin/DllPlugInTester
	dh_install -plibcppunit-dev --autodest debian/tmp/usr/bin/cppunit-config

	dh_install -plibcppunit-dev --autodest debian/tmp/usr/lib/lib*.so
	dh_install -plibcppunit-dev usr/lib/lib*.so usr/lib
	dh_install -plibcppunit-dev --autodest debian/tmp/usr/lib/lib*.a
	dh_install -plibcppunit-dev --autodest debian/tmp/usr/lib/lib*.la
	dh_install -plibcppunit-dev --autodest debian/tmp/usr/lib/pkgconfig
	dh_install -plibcppunit-dev --autodest debian/tmp/usr/include

	dh_installman -plibcppunit-dev         debian/tmp/usr/share/man/man*/*
	dh_install -plibcppunit-dev --autodest debian/tmp/usr/share/aclocal

	# Documentation package
	$(MAKE) -C examples clean
	dh_install -plibcppunit-doc --autodest debian/tmp/usr/share/doc
	dh_installexamples -plibcppunit-doc examples/* debian/examples/*
	chmod 644 debian/libcppunit-doc/usr/share/doc/libcppunit-doc/examples/qt/run.bat
	find debian -name .cvsignore | xargs rm

# 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_installdocs
	dh_installmenu
	dh_installcron
	dh_installinfo
	dh_installchangelogs
	dh_link
	dh_strip
	dh_compress -XMakefile
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps -L libcppunit-1.12-1 -l debian/libcppunit-1.12-1/usr/lib
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
