#!/usr/bin/make -f
# $Id: rules,v 1.10 2003/10/13 13:22:26 absurd Exp $
#
# debian.rules file - for UAE, The Ubiquitous Amiga Emulator

export DH_VERBOSE=0

# all binaries
binaries=uae_readdisk uae

build: build-stamp

patch:
	# Apply patches
	#QUILT_PATCHES=debian/patches quilt push -a || test $$? == 2

uae:
	-make streifenfrei
	#	-make clean
	# there might be a stale config.cache, but no Makefile to do "streifenfrei"
	-rm -f config.cache

	# ./configure does not exit # 0 on error, so we need this overhead to be precise
	# with the svgalib warning, this hack got even worse ;)

	./configure --with-x --enable-sound --enable-threads 2>&1 | tee debian/configure.log
	@if ( grep --quiet "Configuration was successful" debian/configure.log || \
		grep --quiet "There were 1 warnings. That is usually harmless" debian/configure.log ) && \
		make ; \
			then	mv readdisk uae_readdisk &&\
						echo && \
						echo "Target $@ successfully build!" && \
						echo ;\
			else	echo && \
						echo "Configuration or building for target $@ failed for your system setup!" && \
						echo && \
						echo "Either" && \
						echo " 1. The source dependencies aren't met." &&\
						echo " 2. This is a bug for arch $(DEB_HOST_ARCH). Please report." &&\
						echo &&\
						exit 1 ;\
	fi

build-stamp: patch uae
	dh_testdir
	# at least one build run must have been succesful

	# Uncomment next line to DEBUG
	#	touch uae_readdisk

	[ -e uae_readdisk ]
	touch $@

clean: patch binary-clean
	dh_testdir
	-make streifenfrei
	#	-make clean
	-rm -f build-stamp ${binaries}

	# Support for autottools-dev update
	#cp -f /usr/share/misc/config.sub config.sub
	#cp -f /usr/share/misc/config.guess config.guess

	# Remove patches
	-QUILT_PATCHES=debian/patches quilt pop -a || test $$? == 2
	-rm -rf .pc

binary-indep: build
	dh_testdir
	dh_testroot

binary-arch: build
	dh_testdir
	dh_testroot

	# Install the binaries
	dh_installdirs usr/bin
	install ${binaries} debian/uae/usr/bin

	# Install Support Files (Amiga binaries && their sources)
	install -d debian/uae/usr/share/uae/
	tar czvf debian/uae/usr/share/uae/amiga.tar.gz amiga

	# Install Pixmaps
	install -d debian/uae/usr/share/pixmaps
	cp debian/uae-menu.xpm debian/uae.xpm debian/uae/usr/share/pixmaps


	dh_installexamples debian/uae-confwrap
	dh_installmenu

	# Install all man pages into uae
	dh_installman debian/man/uae_readdisk.1 debian/man/uae.1

	dh_installchangelogs src/ChangeLog

	dh_compress --all

	dh_strip --all
	dh_fixperms --all

	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-clean:
	dh_testdir
	dh_clean
	rm -f debian/configure.log

binary:	binary-clean binary-indep binary-arch

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

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