#!/usr/bin/make -f
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifneq ($(DEB_BUILD_GNU_TYPE), powerpc-linux-gnu)
  $(error "this package needs to be built with a powerpc-linux-gnu toolchain")
endif

ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  CROSS_PREFIX := ""
else
  CROSS_PREFIX := "$(DEB_BUILD_GNU_TYPE)-"
endif

CFLAGS = -Wall -g

ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

build-arch:
	dh_testdir
	
	$(MAKE) CROSS_COMPILE="$(CROSS_PREFIX)" CFLAGS="$(CFLAGS)"

build-indep:

build: build-arch build-indep

clean:
	dh_testdir
	dh_testroot
	
	$(MAKE) clean CROSS_COMPILE="$(CROSS_PREFIX)"
	$(RM) ppc_rom.bin
	
	dh_clean

binary-arch: build-arch
	dh_testdir
	dh_testroot
	dh_prep
	
	dh_installdirs
	dh_installchangelogs Changelog
	dh_installdocs
	dh_install
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-indep: build-indep
# Nothing to do

binary: binary-indep binary-arch

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