#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.

#export DH_VERBOSE=1

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

packn = atari-fdisk
packu = atari-fdisk-udeb
packc = atari-fdisk-cross
tmpn = debian/tmp
tmpu = debian/$(packu)
tmpc = debian/$(packc)
docn = $(tmpn)/usr/share/doc/$(packn)
docc = $(tmpc)/usr/share/doc/$(packc)
mann = $(tmpn)/usr/share/man
manc = $(tmpc)/usr/share/man

build:
	$(checkdir)
	# override cross-compiling stuff in upstream Makefile
	make COMPILE_ARCH=m68k
	touch build

clean:
	$(checkdir)
	-rm -f build
	-make reallyclean
	-rm -f `find . -name "*~"`
	-rm -rf $(tmpn) $(tmpc) debian/files* core debian/substvars \
            debian/atari-fdisk-cross.substvars

binary-indep: 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: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	install -d $(tmpn)/sbin
	install -s -m 755 atari-fdisk $(tmpn)/sbin
	install -d $(tmpu)/sbin
	install -s -m 755 atari-fdisk $(tmpu)/sbin
	install -d $(tmpc)/usr/sbin
	install -s -m 755 atari-fdisk $(tmpc)/usr/sbin
	dh_installdocs -p$(packn) -p$(packc) README
	# install README also in cross package (not done by dh_installdocs)
	install -m 644 README $(docc)
	# debhelper doesn't see debian/atari-fdisk.8, so install it manually
	#dh_installmanpages
	install -d $(mann)/man8
	install -m 644 debian/atari-fdisk.8 $(mann)/man8
	install -d $(manc)/man8
	install -m 644 debian/atari-fdisk.8 $(manc)/man8
	dh_installchangelogs -p$(packn) -p$(packc) NEWS
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	# build native package only for m68k, cross package only for others
	set -e; if [ "$(BUILDARCH)" = "m68k" ]; then \
		rm -rf $(tmpu)/usr; \
		dh_gencontrol -p$(packn); \
		dh_gencontrol -p$(packu) -- -isp -fdebian/files~; \
	else \
		dh_gencontrol -p$(packc); \
	fi
	dh_md5sums -p$(packn) -p$(packc)
	set -e; if [ "$(BUILDARCH)" = "m68k" ]; then \
		dh_builddeb -p$(packn); \
		version=`dpkg-parsechangelog | grep ^Version: | cut -d ' ' -f 2`; \
		dpkg-distaddfile $(packu)_$${version}_$(BUILDARCH).udeb debian-installer standard; \
		dh_builddeb -p$(packu) --filename $(packu)_$${version}_$(BUILDARCH).udeb; \
	else \
		dh_builddeb -p$(packc); \
	fi

binary:		binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean
