#!/usr/bin/make -f
#   -*- mode: makefile; -*-
# Sample debian.rules file - for GNU Hello (1.3).
# Copyright 1994,1995 by Ian Jackson.
# I hereby give you perpetual unlimited permission to copy,
# modify and relicense this file, provided that you do not remove
 # my name from the file itself.  (I assert my moral right of
# paternity under the Copyright, Designs and Patents Act 1988.)
# This file may have to be extensively modified
#
# Modified to be a prototype for debmake by Christoph Lameter <clameter@debian.org>

ARCH = $(shell dpkg --print-gnu-build-architecture)

BINARY-ARCH-TARGETS = binary-svgalib-dummyg1
ifeq ($(filter $(ARCH),i486 m68k),$(ARCH))
BUILDLIBC5=1
BINARY-ARCH-TARGETS += binary-svgalib-dummy1
endif

packg = svgalib-dummyg1
packc = svgalib-dummy1
tmpg = debian/tmp-libg
tmpc = debian/tmp-libcompat
docg = $(tmpg)/usr/share/doc/$(packg)
docc = $(tmpc)/usr/share/doc/$(packc)

build:
	$(checkdir)
	make
ifdef BUILDLIBC5
	test -d libc5-compat || mkdir libc5-compat
	cd libc5-compat; $(MAKE) CC=$(ARCH)-linuxlibc1-gcc -f ../Makefile SRCDIR=..
endif
	touch build

clean:
	$(checkdir)
	-rm -f build
	-make clean
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp* debian/files* core debian/substvars libc5-compat

binary-indep:	checkroot build
	$(checkdir)
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch: $(BINARY-ARCH-TARGETS)

binary-svgalib-dummyg1:	checkroot build
	$(checkdir)
	-rm -rf $(tmpg)
	install -d $(tmpg)/DEBIAN
	make install PREFIX=`pwd`/$(tmpg)
	install -m 644 debian/control $(tmpg)/DEBIAN
	install -m 644 debian/shlibs.glibc $(tmpg)/DEBIAN/shlibs
	install -m 755 debian/postinst.glibc $(tmpg)/DEBIAN/postinst
	install -m 755 debian/prerm.glibc $(tmpg)/DEBIAN/prerm
	install -d $(docg)
	install -m 644 debian/changelog $(docg)/changelog.Debian
	install -m 644 debian/README.debian $(docg)
	gzip -9f $(docg)/*
	install -m 644 debian/copyright $(docg)
	dpkg-shlibdeps $(tmpg)/usr/lib/lib*.so.*
	dpkg-gencontrol -p$(packg) -P$(tmpg)/
	chown -R root.root $(tmpg)
	chmod -R go=rX $(tmpg)
	dpkg --build $(tmpg) ..

binary-svgalib-dummy1:	checkroot build
	$(checkdir)
	-rm -rf $(tmpc)
	install -d $(tmpc)/DEBIAN
	cd libc5-compat; make -f ../Makefile install-libs PREFIX=`pwd`/../$(tmpc) LIBDIR=/usr/lib/libc5-compat SRCDIR=..
	rm -f $(tmpc)/usr/lib/libc5-compat/*.so
	install -m 644 debian/control $(tmpc)/DEBIAN
	install -m 644 debian/shlibs.compat $(tmpc)/DEBIAN/shlibs
	install -m 755 debian/postinst.compat $(tmpc)/DEBIAN/postinst
	install -m 755 debian/prerm.compat $(tmpc)/DEBIAN/prerm
	install -d $(docc)
	install -m 644 debian/changelog $(docc)/changelog.Debian
	install -m 644 debian/README.debian $(docc)
	gzip -9f $(docc)/*
	install -m 644 debian/copyright $(docc)
	dpkg-shlibdeps $(tmpc)/usr/lib/libc5-compat/lib*.so.*
	dpkg-gencontrol -p$(packc) -P$(tmpc)/
	chown -R root.root $(tmpc)
	chmod -R go=rX $(tmpc)
	dpkg --build $(tmpc) ..

define checkdir
	test -f debian/rules
endef

# Below here is fairly generic really

binary:		binary-indep binary-arch

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

checkroot:
	$(checkdir)
	test root = "`whoami`"

.PHONY: binary binary-arch binary-indep clean checkroot
