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

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

UPSTREAM_VERSION=$(shell dpkg-parsechangelog | sed -e '/^Version/!d' -e 's/^Version: //g' -e 's/-.*//g')
UPSTREAM_REVISION=$(shell echo $(UPSTREAM_VERSION) | sed -e 's/.*svn/-r/')
UPSTREAM_SVN=svn://openbios.org/openbios/trunk/openbios-devel
UPSTREAM_CHECKOUT=openbios-ppc-$(UPSTREAM_VERSION)

DEB_BUILD_ARCH_CPU ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH_CPU)

get-orig-source:
	svn export $(UPSTREAM_REVISION) $(UPSTREAM_SVN) $(UPSTREAM_CHECKOUT)
	rm -fr openbios-ppc-$(UPSTREAM_VERSION)/utils/iso
	tar -zcf ../openbios-ppc_$(UPSTREAM_VERSION).orig.tar.gz $(UPSTREAM_CHECKOUT)
	rm -rf $(UPSTREAM_CHECKOUT)

build: build-stamp
build-stamp:
	dh_testdir

ifneq ($(DEB_BUILD_ARCH_CPU),powerpc)
	@echo "This package must be built on a PowerPC machine"
	@false
endif

	# PowerPC build
	config/scripts/switch-arch builtin-ppc
	cd obj-ppc && $(MAKE) all
	
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -rf obj-*
	rm -f config.xml rules.xml
	rm -f *-stamp
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	mkdir -p $(CURDIR)/debian/openbios-ppc/usr/share/openbios
	install -m644 obj-ppc/openbios-qemu.elf $(CURDIR)/debian/openbios-ppc/usr/share/openbios/openbios-ppc


# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installchangelogs Documentation/ChangeLog.arch
	dh_lintian
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
