#!/usr/bin/make -f
# $Id: rules 1511 2011-02-07 19:58:27Z robert $
# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess.
#
# This version is for a multibinary package. It also allows you to build any
# of the binary packages independantly, via binary-<package> targets.

# 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

export DH_ALWAYS_EXCLUDE=CVS:.svn

DH_AUTO_OPTIONS := -v -Sautoconf --parallel
DESTDIR         := $(CURDIR)/debian/tmp
CFLAGS          := $(shell dpkg-buildflags --get CFLAGS)
LDFLAGS         := $(shell dpkg-buildflags --get LDFLAGS)


configure: configure-stamp
configure-stamp:
	dh_testdir

	dh_auto_configure $(DH_AUTO_OPTIONS) --         \
	            --enable-yesterday                  \
	            --disable-man-group                 \
	            --disable-compress-manpg            \
	            sa_lib_dir=/usr/lib/sysstat         \
	            sa_dir=/var/log/sysstat             \
	            conf_dir=/etc/sysstat               \
	            CFLAGS="$(CFLAGS)"                  \
	            LDFLAGS="$(LDFLAGS)"
	touch "$@"



build-arch: build-arch-stamp
build-arch-stamp: configure

	dh_auto_build $(DH_AUTO_OPTIONS)

	chmod a+x debian/debian-sa1

	touch "$@"



build-indep: build-indep-stamp
build-indep-stamp: configure

	dh_auto_build $(DH_AUTO_OPTIONS) -- contrib/isag/isag

	touch "$@"



clean:
	dh_testdir
	dh_testroot
	rm -f configure-stamp build-arch-stamp build-indep-stamp config.log

	[ ! -f Makefile ] || dh_auto_clean $(DH_AUTO_OPTIONS)

	dh_clean


install-common install-arch install-indep: DH_OPTIONS=
install-common:
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

install-arch: build-arch install-common

	dh_auto_install $(DH_AUTO_OPTIONS) --destdir="$(DESTDIR)"

	mkdir -p -m 755 $(DESTDIR)/usr/lib/sysstat
	mv $(DESTDIR)/usr/bin/sar $(DESTDIR)/usr/bin/sar.sysstat
	mv $(DESTDIR)/usr/share/man/man1/sar.1 $(DESTDIR)/usr/share/man/man1/sar.sysstat.1
	rm -rf $(DESTDIR)/usr/doc

	dh_installchangelogs -a CHANGES

install-indep: build-indep install-common

	$(MAKE) DESTDIR="$(DESTDIR)" install_isag

	dh_installchangelogs -i


# This single target is used to build all the packages, all at once, or
# one at a time. So keep in mind: any options passed to commands here will
# affect _all_ packages. Anything you want to only affect one package
# should be put in another target, such as the install target.
binary-common:
	dh_testdir
	dh_testroot
	dh_install
#	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_installmenu
	dh_installdebconf
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installcatalogs
#	dh_installpam
#	dh_installmime
	dh_installinit --no-start -- start 20 2 3 4 5 .
#	dh_installman
	dh_installcron
#	dh_installinfo
#	dh_undocumented

	sh debian/fix.sh `dh_listpackages`

	dh_lintian
	dh_strip
	dh_link
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_python
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb


# Build architecture independant packages using the common target.
binary-indep: build-indep install-indep
	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: build-arch install-arch
	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common

# Any other binary targets build just one binary package at a time.
binary-%: build install
	make -f debian/rules binary-common DH_OPTIONS=-p$*

binary: binary-indep binary-arch
build:  build-indep  build-arch

.PHONY: configure clean                                         \
	build-indep   build-arch   build                        \
	binary-indep  binary-arch  binary-common  binary        \
	indeall-indep install-arch install-common

.DEFAULT_GOAL := binary
