#!/usr/bin/make -f
# Sample debian/rules that uses debhelper. 
# GNU copyright 1997 by Joey Hess.
#

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

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)

configure: config-stamp
config-stamp:
	ACLOCAL=aclocal-1.9 AUTOMAKE=automake-1.9 ./autogen.sh
	./configure --host=$(DEB_HOST_GNU_TYPE) --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-qt-includes=/usr/include/qt3 --with-kernel-support 
	touch config-stamp

build-arch: configure build-arch-stamp
build-arch-stamp: 
	# Add here commands to build the package
	DESTDIR=$(CURDIR)/debian/oprofile $(MAKE)
	touch build-arch-stamp

build-indep: build-indep-stamp
build-indep-stamp:
	dh_testdir
	touch build-indep-stamp

build: build-arch build-indep

OPROFILE_SUBDIRS = $(shell find * -type d -maxdepth 0 )
clean:
	dh_testdir
	dh_testroot
	-$(MAKE) clean
	-$(MAKE) distclean
	rm -f automake-stamp
	rm -f config-stamp build-arch-stamp build-indep-stamp 
	rm -f Makefile.modules.am Makefile.modules.in Makefile.modules
	rm -f configure.modules configure.modules.in
	rm -f debian/Makefile.modules 
	rm -f debian/oprofiled24 debian/oprofiled26
	rm -f config.status config.cache
	for ii in $(OPROFILE_SUBDIRS) ; \
	do \
		(cd $$ii && rm -rf .deps) || exit 1 ; \
	done
	-test -r /usr/share/misc/config.sub && \
	  cp -f /usr/share/misc/config.sub config.sub
	-test -r /usr/share/misc/config.guess && \
	  cp -f /usr/share/misc/config.guess config.guess
	find * -name '*.[oa]' | xargs rm -f
	rm -f libregex/regex_test libdb/db_test daemon/oprofiled
	rm -f dae/oprofiled
	rm -f utils/op_session utils/op_help
	rm -f pp/oprofpp pp/op_to_source pp/op_time pp/op_merge
	rm -f pp/opannotate pp/opgprof pp/opreport
	rm -f gui/oprof_start
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

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

	# Copy the driver source HOWTOs to the proper locations
	cp debian/oprofile-source.HOWTO-ia64 \
		debian/oprofile/usr/share/doc/oprofile/HOWTO-ia64
	cp debian/oprofile-source.HOWTO-i386 \
		debian/oprofile/usr/share/doc/oprofile/HOWTO-i386

	#-- clean up some of the mess from
	# an over-exuberant install command
	rm -f debian/oprofile/usr/share/mangled-name
	cp debian/oprofile/usr/share/man/man1/oprofile.1 \
	   debian/oprofile-gui/usr/share/man/man1/oprof_start.1
	dh_link usr/share/man/man1/oprofile.1 usr/share/man/man8/oprofiled.8

# Build architecture-independent files here.
# Pass -i to all debhelper commands in this target to reduce clutter.
binary-indep: build install

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir 
	dh_testroot 
	dh_installdocs 
	dh_installexamples 
	dh_installmenu 
	dh_installcron 
	dh_installman 
	dh_installinfo 
	dh_installdebconf 
	dh_installchangelogs ChangeLog 
	dh_install --sourcedir=debian/oprofile 
	#-- now that everything has been installed, clean up the
	#   original debian/oprofile directory
	rm -rf debian/oprofile/usr/bin
	rm -rf debian/oprofile/usr/share/man
	rm -rf debian/oprofile/usr/share/oprofile
	dh_strip 
	dh_link 
	dh_compress 
	dh_compress --sourcedir=debian/oprofile usr/share/doc/oprofile/ChangeLog
	dh_fixperms 
	dh_installdeb 
	dh_shlibdeps 
	dh_gencontrol 
	dh_md5sums 
	dh_builddeb 

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install  binary-modules kdist kdist_config kdist_image kdist_clean
