#!/usr/bin/make -f

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


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

ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  CROSS = --build $(DEB_HOST_GNU_TYPE)
else
  CROSS = --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif


configure: configure-stamp
configure-stamp:
	dh_testdir
ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	cp -f /usr/share/misc/config.sub config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	cp -f /usr/share/misc/config.guess config.guess
endif
	./configure $(CROSS) \
		--prefix=/usr \
		--bindir=/usr/games \
		--disable-scrollkeeper \
		CFLAGS="$(CFLAGS)" \
		LDFLAGS="-Wl,-z,defs -Wl,--as-needed"
	touch configure-stamp

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp: configure-stamp
	dh_testdir
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	[ ! -f Makefile ] || $(MAKE) distclean
	dh_clean config.sub config.guess

install: build
	dh_testdir
	dh_testroot
	dh_prep
	$(MAKE) install DESTDIR=$(CURDIR)/debian/hitori

binary: binary-arch binary-indep

binary-arch: install
	dh_testdir
	dh_testroot
	dh_install
	dh_installchangelogs ChangeLog
# Take care to install the old changelogs as well...
	install ChangeLog.pre-0-2-2 debian/hitori/usr/share/doc/hitori/changelog.pre-0-2-2
	install help/ChangeLog.pre-0-2-2 debian/hitori/usr/share/doc/hitori/changelog.help.pre-0-2-2
	dh_installdocs
	dh_installman
	dh_installmenu
	dh_icons
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-indep:
# Nothing to do.


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