#!/usr/bin/make -f

#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)
CXXFLAGS = "-Wall -O2 -fno-exceptions -DDATA_DIR=\"\\\"/usr/share/games/adonthell\"\\\""
CFGDEBUG = ""
INSTALL = /usr/bin/install -c
INSTALL_PROGRAM = ${INSTALL} -p -o root -g root  -m 755

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CXXFLAGS += -g
	CFGDEBUG = "--enable-py-debug"
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

config.status: configure
	dh_testdir
	./configure --host=$(DEB_HOST_GNU_TYPE) \
                    --build=$(DEB_BUILD_GNU_TYPE) \
                    --prefix=/usr \
                    --mandir=\$${prefix}/share/man \
                    --bindir=\$${prefix}/games \
                    --datadir=\$${prefix}/share/games \
                    --with-py-libs="-Wl,-E -L/usr/lib/python2.2/config -lpython2.2 -ldl -lpthread -lutil" \
                    --with-py-cflags="-I/usr/include/python2.2" \
                    $(CFGDEBUG)


build: build-stamp

build-stamp:  config.status
	dh_testdir
	$(MAKE) CXXFLAGS=$(CXXFLAGS) INSTALL_PROGRAM="$(INSTALL_PROGRAM)"
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 

	-$(MAKE) distclean
#	-test -r /usr/share/misc/config.sub && \
#	  cp -f /usr/share/misc/config.sub config.sub
#	-test -r /usr/share/misc/config.guess && \
#	  cp -f /usr/share/misc/config.guess config.guess
	-rm -f `find . -name "*~"`
	-rm -f src/adonthell.pyc
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) install DESTDIR="$(CURDIR)/debian/adonthell" INSTALL_PROGRAM="$(INSTALL_PROGRAM)"


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

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installmenu
	dh_installman debian/adonthell.6
	dh_installchangelogs ChangeLog
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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