#!/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-sparc-$(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-sparc-$(UPSTREAM_VERSION)/utils/iso
	tar -zcf ../openbios-sparc_$(UPSTREAM_VERSION).orig.tar.gz $(UPSTREAM_CHECKOUT)
	rm -rf $(UPSTREAM_CHECKOUT)

build: build-arch build-indep

build-arch:
# We have nothing to do by default.

build-indep: build-indep-stamp
build-indep-stamp:
	dh_testdir

ifeq (,$(findstring $(DEB_BUILD_ARCH_CPU),sparc sparc64))
	@echo "This package must be built on a SPARC machine"
	@false
endif

	HOSTARCH=sparc64 config/scripts/switch-arch builtin-sparc32 builtin-sparc64
	cd obj-sparc32 && $(MAKE) all CC="gcc -m32" HOSTCC="gcc -m32" TARGET=""
	cd obj-sparc64 && $(MAKE) all CC="gcc -m64" HOSTCC="gcc -m64" TARGET=""

	touch build-indep-stamp

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

install: build-indep
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	mkdir -p $(CURDIR)/debian/openbios-sparc/usr/share/openbios
	install -m644 obj-sparc32/openbios-builtin.elf $(CURDIR)/debian/openbios-sparc/usr/share/openbios/openbios-sparc32
	install -m644 obj-sparc32/QEMU,tcx.bin $(CURDIR)/debian/openbios-sparc/usr/share/openbios/QEMU,tcx.bin
	install -m644 obj-sparc64/openbios-builtin.elf $(CURDIR)/debian/openbios-sparc/usr/share/openbios/openbios-sparc64


# Build architecture-independent files here.
binary-indep: build-indep 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 -- -Zxz

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

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