#! /usr/bin/make -f
# Generated automatically from debian/packages
# by yada v0.9.9, of Tue, 07 Dec 1999
# Modified by Piotr Roszatycki <dexter@debian.org>, Mon,  1 Oct 2001 13:14:11 +0200

DEB_HOST_GNU_CPU    := $(shell dpkg-architecture -qDEB_HOST_GNU_CPU)
DEB_HOST_GNU_TYPE   := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_HOST_GNU_SYSTEM := $(shell dpkg-architecture -qDEB_HOST_GNU_SYSTEM)

DEB_BUILD_GNU_CPU    := $(shell dpkg-architecture -qDEB_BUILD_GNU_CPU)
DEB_BUILD_GNU_TYPE   := $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_BUILD_GNU_SYSTEM := $(shell dpkg-architecture -qDEB_BUILD_GNU_SYSTEM)

VERSION:=$(shell LC_ALL=C dpkg-parsechangelog | sed -ne 's/^Version: *\([^2]*\)/\1/p')

SHELL=/bin/bash

.PHONY: default
default:
	@echo "Specify a target:"; \
	echo " build              compile the package"; \
	echo " binary             make all binary packages"; \
	echo " binary-arch        make all architecture-dependent binary packages"; \
	echo " binary-indep       make all architecture-independent binary packages"; \
	echo " clean              clean up the source package"; \
	echo; \
	echo " depends            check build-time dependencies"; \
	echo " install-tree       compile the package and create the install trees"; \
	echo " clean-install-tree clean up only under debian/"; \
	echo

# Check build dependencies and conflicts

.PHONY: depends
depends: chmod-yada debian/depends-stamp
debian/depends-stamp:
	@echo 'Checking build conflicts and dependencies; just a minute...'
	@echo -n 'grep-dctrl...'; v=$$(grep-status -X -F Package 'grep-dctrl' | grep Version | head -1 | sed -e 's/^Version: //'); \
	if test ! "$$v"; then echo -n 'grep-dctrl (virtual package)...'; v=$$(grep-status -e -F Provides '(^grep-dctrl, |, grep-dctrl$$|^grep-dctrl$$)' | grep Version | head -1 | sed -e 's/^Version: //'); fi; \
	if test "$$v"; then \
	    exit 0; \
	fi; \
	echo 'Build depends on `grep-dctrl'\'' (any version), which is not satisfied' | fmt; exit 1
	@echo -n 'yada...'; v=$$(grep-status -X -F Package 'yada' | grep Version | head -1 | sed -e 's/^Version: //'); \
	if test ! "$$v"; then echo -n 'yada (virtual package)...'; v=$$(grep-status -e -F Provides '(^yada, |, yada$$|^yada$$)' | grep Version | head -1 | sed -e 's/^Version: //'); fi; \
	if test "$$v"; then \
	  if dpkg --compare-versions "$$v" '>=' '0.9.9'; then \
	    exit 0; \
	  fi; \
	fi; \
	echo 'Build depends on `yada'\'' (version >= 0.9.9), which is not satisfied' | fmt; exit 1
	@echo
	@echo 'Conflicts and dependencies all satisfied!'
	touch debian/depends-stamp

# Build the package and prepare the install tree

.PHONY: build-only build
build-only: debian/build-stamp
build: chmod-yada build-only

# Make sure these rules and the control file are up-to-date

.PHONY: rules control
rules: debian/rules
debian/rules: $(shell which yada) debian/packages
	$(shell which yada) rebuild rules

control: debian/control
debian/control: $(shell which yada) debian/packages
	$(shell which yada) rebuild control

debian/build-stamp: debian/depends-stamp
	@[ -f $(shell which yada) -a -f debian/rules ]
	@umask 022 \
	    && export PACKAGE="systune" \
	    && export VERSION="$(VERSION)" \
	    && export DEB_HOST_GNU_CPU="$(DEB_HOST_GNU_CPU)" \
	    && export DEB_HOST_GNU_TYPE="$(DEB_HOST_GNU_TYPE)" \
	    && export DEB_HOST_GNU_SYSTEM="$(DEB_HOST_GNU_SYSTEM)" \
	    && export DEB_BUILD_GNU_CPU="$(DEB_BUILD_GNU_CPU)" \
	    && export DEB_BUILD_GNU_TYPE="$(DEB_BUILD_GNU_TYPE)" \
	    && export DEB_BUILD_GNU_SYSTEM="$(DEB_BUILD_GNU_SYSTEM)" \
 && (\
	echo -E 'eval "yada () { perl $$(which yada) \"\$$@\"; }"; set -e; set -v';\
	echo -E 'make') | /bin/sh
	touch debian/build-stamp

.PHONY: install-tree
install-tree: chmod-yada install-tree-any
install-tree-any: \
	debian/tmp-systune/DEBIAN/control

debian/tmp-systune/DEBIAN/control: debian/build-stamp debian/control
	rm -rf debian/tmp-systune
	umask 022 && install -d debian/tmp-systune/DEBIAN
	install -d debian/tmp-systune/usr/share/doc/systune
	umask 022; $(shell which yada) generate copyright \
	                       >debian/tmp-systune/usr/share/doc/systune/copyright
	install -m 644 -p debian/changelog \
	                  debian/tmp-systune/usr/share/doc/systune/changelog
	@umask 022 \
	    && export PACKAGE="systune" \
	    && export ROOT="$$(pwd)/debian/tmp-systune" \
	    && export CONTROL="$$(pwd)/debian/tmp-systune/DEBIAN" \
	    && export VERSION="$(VERSION)" \
	    && export DEB_HOST_GNU_CPU="$(DEB_HOST_GNU_CPU)" \
	    && export DEB_HOST_GNU_TYPE="$(DEB_HOST_GNU_TYPE)" \
	    && export DEB_HOST_GNU_SYSTEM="$(DEB_HOST_GNU_SYSTEM)" \
	    && export DEB_BUILD_GNU_CPU="$(DEB_BUILD_GNU_CPU)" \
	    && export DEB_BUILD_GNU_TYPE="$(DEB_BUILD_GNU_TYPE)" \
	    && export DEB_BUILD_GNU_SYSTEM="$(DEB_BUILD_GNU_SYSTEM)" \
 && (\
	echo -E 'eval "yada () { perl $$(which yada) \"\$$@\"; }"; set -e; set -v';\
	echo -E 'yada install -script -into /usr/sbin systune';\
	echo -E 'yada install -script -into /usr/sbin systunedump';\
	echo -E 'yada install -doc -subdir examples systune.conf';\
	echo -E 'yada install -doc -subdir examples systune.dump';\
	echo -E 'yada install -man systune.8';\
	echo -E 'yada install -man systunedump.8';\
	echo -E 'ln -s changelog.gz $$ROOT/usr/share/doc/$$PACKAGE/changelog.Debian.gz') | /bin/sh
	$(shell which yada) compress systune
	$(shell which yada) generate maintscripts systune
	find debian/tmp-systune -type f -print \
	  | sed -n 's/^debian\/tmp-systune\(\/etc\/.*\)$$/\1/p' \
	    > debian/tmp-systune/DEBIAN/conffiles
	if test ! -s debian/tmp-systune/DEBIAN/conffiles; then rm -f debian/tmp-systune/DEBIAN/conffiles; fi
	$(shell which yada) rebuild control
	$(shell which yada) generate substvars systune
	umask 022 && dpkg-gencontrol -isp -psystune -Pdebian/tmp-systune

# Build package files

.PHONY: binary binary-arch binary-indep
binary: binary-arch binary-indep
binary-arch: chmod-yada binary-arch-any

.PHONY: binary-arch-any
binary-arch-any:
binary-indep: chmod-yada \
	binary-package-systune

.PHONY: binary-package-systune
binary-package-systune: check-root debian/tmp-systune/DEBIAN/control
	@[ -f $(shell which yada) -a -f debian/rules ]
	chown -R 0.0 debian/tmp-systune
	chmod -R u=rwX,go=rX debian/tmp-systune
	@umask 022 && export PACKAGE="systune" \
	    && export ROOT="$$(pwd)/debian/tmp-systune" \
	    && export CONTROL="$$(pwd)/debian/tmp-systune/DEBIAN" && (\
	echo -E 'eval "yada () { perl $$(which yada) \"\$$@\"; }"; set -e; set -v';\
	echo -E 'cat $$CONTROL/postinst \';\
	echo -E '    | awk '\''{ if( $$1 == "#systune.conf#" ) system("cat systune.conf"); else print }'\'' \';\
	echo -E '    | awk '\''{ if( $$1 == "#systune.dump#" ) system("cat systune.dump"); else print }'\'' \';\
	echo -E '    > $$CONTROL/postinst.tmp';\
	echo -E 'mv -f $$CONTROL/postinst.tmp $$CONTROL/postinst';\
	echo -E 'chmod 755 $$CONTROL/postinst') | /bin/sh
	@if [ -d debian/tmp-systune/usr/doc/systune ]; then \
	  echo "*** Yada warning: /usr/doc/systune should be /usr/share/doc/systune";\
	fi
	dpkg-deb --build debian/tmp-systune ..

.PHONY: check-root
check-root:
	@[ `id -u` = 0 ] || (echo "You must be root to do this!"; false)

.PHONY: chmod-yada
chmod-yada:
	@if [ -f debian/yada -a ! -x debian/yada ]; then \
	  chmod +x debian/yada; \
	fi

# Clean up afterwards

.PHONY: clean clean-install-tree clean-build
clean: chmod-yada clean-install-tree clean-build debian/control debian/rules

clean-build:
	@[ -f $(shell which yada) -a -f debian/rules ]
	rm -f debian/build-stamp debian/depends-stamp
	@umask 022 && (\
	echo -E 'eval "yada () { perl $$(which yada) \"\$$@\"; }"; set -e; set -v';\
	echo -E 'make clean || true') | /bin/sh

clean-install-tree: chmod-yada debian/rules
	@[ -f $(shell which yada) -a -f debian/rules ]
	rm -f debian/install-tree-stamp
	rm -rf debian/tmp* debian/files* debian/substvars
