#!/usr/bin/make -f
# Generated automatically from debian/packages
# by yada v0.21, of Sun,  7 Sep 2003

DEB_HOST_ARCH        := $(shell dpkg-architecture -qDEB_HOST_ARCH)
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_ARCH       := $(shell dpkg-architecture -qDEB_BUILD_ARCH)
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 " build-arch         compile the architecture-dependent package"; \
	echo " build-indep        compile the architecture-independent 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 " clean-install-tree clean up only under debian/"; \
	echo

# Build the package and prepare the install tree

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

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

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

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

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

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

templates: debian/templates
debian/templates: $(shell which yada) debian/packages-tmp
	$(shell which yada) rebuild templates

debian/build-stamp: debian/build-arch-stamp debian/build-indep-stamp
	@[ -f $(shell which yada) -a -f debian/rules ]
	@umask 022 \
	  && export pwd="$$(pwd)" \
	  && export TMPROOT="$$(pwd)/debian/tmp" \
	  && export SOURCE="fakechroot" \
	  && 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 'aclocal-1.7';\
	echo -E 'autoheader';\
	echo -E 'libtoolize --copy';\
	echo -E 'automake-1.7 --add-missing --copy';\
	echo -E 'autoconf';\
	echo -E '( cd fake';\
	echo -E '   aclocal-1.7';\
	echo -E '   automake-1.7 --add-missing --copy';\
	echo -E '   autoconf';\
	echo -E ') || false';\
	echo -E 'CC=$${CC:-gcc}';\
	echo -E 'CFLAGS=$${CFLAGS:--Wall -pedantic -g}';\
	echo -E 'CXXFLAGS=$${CFLAGS:--Wall -pedantic -g}';\
	echo -E 'if [ "$${DEB_BUILD_OPTIONS#*noopt}" != "$$DEB_BUILD_OPTIONS" ]; then';\
	echo -E '    CFLAGS="$$CFLAGS -O0"';\
	echo -E '    CXXFLAGS="$$CXXFLAGS -O0"';\
	echo -E 'else';\
	echo -E '    CFLAGS="$$CFLAGS -O2"';\
	echo -E '    CXXFLAGS="$$CXXFLAGS -O2"';\
	echo -E 'fi';\
	echo -E 'install -d mkdir build-tree-lib build-tree-fake build-tree-lib64';\
	echo -E '( cd build-tree-lib && CC="$$CC" CFLAGS="$$CFLAGS" CXXFLAGS="$$CXXFLAGS" \';\
	echo -E '    ../configure --prefix=/usr --mandir=/usr/share/man --libdir=/usr/lib/libfakechroot ) || false';\
	echo -E '( cd build-tree-fake && CC="$$CC" CFLAGS="$$CFLAGS" CXXFLAGS="$$CXXFLAGS" \';\
	echo -E '    ../fake/configure --prefix=/usr --mandir=/usr/share/man ) || false';\
	echo -E '( cd build-tree-lib && make ) || false';\
	echo -E '( cd build-tree-fake && make ) || false';\
	echo -E 'if [ "$$DEB_HOST_GNU_TYPE" = "sparc-linux" ]; then';\
	echo -E '    ( cd build-tree-lib64 && CC="gcc -m64" CFLAGS="$$CFLAGS" CXXFLAGS="$$CXXFLAGS" \';\
	echo -E '        ../configure --prefix=/usr --mandir=/usr/share/man --build=sparc-linux --host=sparc64-linux ) || false';\
	echo -E '    ( cd build-tree-lib64 && make libfakechroot.la ) || false';\
	echo -E 'fi';\
	echo -E 'if [ "$$DEB_HOST_GNU_TYPE" = "s390-linux" ]; then';\
	echo -E '    ( cd build-tree-lib64 && CC="gcc-3.3 -m64" CFLAGS="$$CFLAGS" CXXFLAGS="$$CXXFLAGS" \';\
	echo -E '        ../configure --prefix=/usr --mandir=/usr/share/man --build=s390-linux --host=s390x-linux ) || false';\
	echo -E '    ( cd build-tree-lib64 && make libfakechroot.la ) || false';\
	echo -E 'fi') | /bin/sh
	touch debian/build-stamp

debian/build-arch-stamp:
	@[ -f $(shell which yada) -a -f debian/rules ]
	touch debian/build-arch-stamp

debian/build-indep-stamp:
	@[ -f $(shell which yada) -a -f debian/rules ]
	touch debian/build-indep-stamp

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

debian/tmp-fakechroot/DEBIAN/control: debian/build-stamp debian/control
	rm -rf debian/tmp-fakechroot
	umask 022 && install -d debian/tmp-fakechroot/DEBIAN
	install -d debian/tmp-fakechroot/usr/share/doc/fakechroot
	umask 022; $(shell which yada) generate copyright \
	  > debian/tmp-fakechroot/usr/share/doc/fakechroot/copyright
	install -m 644 -p debian/changelog \
	  debian/tmp-fakechroot/usr/share/doc/fakechroot/changelog
	@umask 022 \
	  && export pwd="$$(pwd)" \
	  && export ROOT="$$(pwd)/debian/tmp-fakechroot" \
	  && export TMPROOT="$$(pwd)/debian/tmp" \
	  && export CONTROL="$$(pwd)/debian/tmp-fakechroot/DEBIAN" \
	  && export PACKAGE="fakechroot" \
	  && export SOURCE="fakechroot" \
	  && 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 copy -into /usr/lib/libfakechroot build-tree-lib/.libs/*.so.*.*.* build-tree-lib/.libs/*.a';\
	echo -E 'chmod 644 $$ROOT/usr/lib/libfakechroot/*.so.*.*.*';\
	echo -E 'for f in build-tree-lib/.libs/*.so.*.*.*; do';\
	echo -E '    f=$$(basename $$f)';\
	echo -E '    yada symlink -lib -subdir libfakechroot -as $$(echo $$f | sed '\''s/\.[0-9]*\.[0-9]*$$//'\'') $$f';\
	echo -E '    yada symlink -lib -subdir libfakechroot -as $$(echo $$f | sed '\''s/\.[0-9]*\.[0-9]*\.[0-9]*$$//'\'') $$f';\
	echo -E 'done';\
	echo -E 'yada copy -into /usr/lib build-tree-fake/.libs/*.so.*.*.*';\
	echo -E 'chmod 4644 $$ROOT/usr/lib/*.so.*.*.*';\
	echo -E 'if [ "$$DEB_HOST_GNU_TYPE" = "sparc-linux" -o "$$DEB_HOST_GNU_TYPE" = "s390-linux" ]; then';\
	echo -E '    for f in build-tree-lib64/.libs/*.so.*.*.*; do';\
	echo -E '        f=$$(basename $$f)';\
	echo -E '        yada symlink -lib -into /usr/lib64/libfakechroot -as $$(echo $$f | sed '\''s/\.[0-9]*\.[0-9]*$$//'\'') $$f';\
	echo -E '        yada symlink -lib -into /usr/lib64/libfakechroot -as $$(echo $$f | sed '\''s/\.[0-9]*\.[0-9]*\.[0-9]*$$//'\'') $$f';\
	echo -E '    done';\
	echo -E '    chmod 4644 $$ROOT/usr/lib/*.so.*.*.*';\
	echo -E 'fi';\
	echo -E 'for f in build-tree-fake/.libs/*.so.*.*.*; do';\
	echo -E '    f=$$(basename $$f)';\
	echo -E '    yada symlink -lib -as $$(echo $$f | sed '\''s/\.[0-9]*\.[0-9]*$$//'\'') $$f';\
	echo -E '    yada symlink -lib -as $$(echo $$f | sed '\''s/\.[0-9]*\.[0-9]*\.[0-9]*$$//'\'') $$f';\
	echo -E 'done';\
	echo -E 'yada install -script -as fakechroot scripts/fakeroot';\
	echo -E 'yada install -man -as fakechroot.1 doc/fakeroot.1';\
	echo -E 'yada install -doc README.fakechroot doc/debootstrap.diff';\
	echo -E 'yada install -doc -subdir examples scripts/restoremode.sh scripts/savemode.sh scripts/ldd.fake') | /bin/sh
	@umask 022 \
	  && export pwd="$$(pwd)" \
	  && export ROOT="$$(pwd)/debian/tmp-fakechroot" \
	  && export TMPROOT="$$(pwd)/debian/tmp" \
	  && export CONTROL="$$(pwd)/debian/tmp-fakechroot/DEBIAN" \
	  && export PACKAGE="fakechroot" \
	  && export SOURCE="fakechroot" \
	  && export VERSION="$(VERSION)" && (\
	echo -E 'eval "yada () { perl $$(which yada) \"\$$@\"; }"; set -e; set -v';\
	echo -E 'yada perl';\
	echo -E 'yada python';\
	echo -E 'yada strip';\
	echo -E 'yada shlibdeps') | /bin/sh
	$(shell which yada) compress fakechroot
	$(shell which yada) generate maintscripts fakechroot
	find debian/tmp-fakechroot -type f -print \
	  | sed -n 's/^debian\/tmp-fakechroot\(\/etc\/.*\)$$/\1/p' \
	  > debian/tmp-fakechroot/DEBIAN/conffiles
	if test ! -s debian/tmp-fakechroot/DEBIAN/conffiles; then rm -f debian/tmp-fakechroot/DEBIAN/conffiles; fi
	$(shell which yada) rebuild control
	$(shell which yada) generate substvars fakechroot
	umask 022 && dpkg-gencontrol -isp -pfakechroot -Pdebian/tmp-fakechroot

# 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-package-fakechroot
binary-indep: chmod-yada

.PHONY: binary-package-fakechroot
binary-package-fakechroot: check-root debian/tmp-fakechroot/DEBIAN/control
	@[ -f $(shell which yada) -a -f debian/rules ]
	chown -R 0.0 debian/tmp-fakechroot
	chmod -R u=rwX,go=rX debian/tmp-fakechroot
	@if [ -d debian/tmp-fakechroot/usr/doc/fakechroot ]; then \
	  echo "*** Yada warning: /usr/doc/fakechroot should be /usr/share/doc/fakechroot";\
	fi
	dpkg-deb --build debian/tmp-fakechroot ..

.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

debian/packages-tmp: debian/packages 
	$(shell which yada) rebuild packages

## Clean up afterwards

.PHONY: clean clean-install-tree clean-build

clean: chmod-yada clean-install-tree clean-build debian/control debian/rules
	rm -f debian/packages-tmp debian/packages-tmp-new debian/packages-tmp-include

clean-build:
	@[ -f $(shell which yada) -a -f debian/rules ]
	rm -f debian/build-stamp debian/build-arch-stamp debian/build-indep-stamp
	@umask 022 \
	  && export pwd="$$(pwd)" \
	  && export TMPROOT="$$(pwd)/debian/tmp" \
	  && export SOURCE="fakechroot" \
	  && 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 'rm -rf build-tree-*';\
	echo -E 'rm -rf $$(cat .cvsignore)';\
	echo -E 'for i in $$(find -name .cvsignore); do';\
	echo -E '    ( cd $$(dirname $$i) && rm -rf $$(cat .cvsignore) )';\
	echo -E 'done') | /bin/sh
	$(shell which yada) unpatch
	rm -rf debian/tmp

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 debian/shlibs.local
