#!/usr/bin/make -f

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

# This is to mark that the public modules installed differ between
# Python version and they can't be shared
export DH_PYCENTRAL=nomove

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

# Get Python version information
PYDEF=$(shell pyversions -d)
PYVERS=$(shell pyversions -r)

configure: configure-stamp
configure-stamp:
	dh_testdir
	touch configure-stamp

build: configure-stamp build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
	dh_testdir
	set -e; \
	for python in $(PYVERS); do \
	  python=$$(echo $$python | sed "s/$(PYDEF)/python/"); \
	  $$python setup.py build --build-platlib=$(CURDIR)/build/lib; \
	done
	scripts/mkdoc.sh build/lib
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -rf doc/api/html/
	for python in $(PYVERS); do \
	  python=$$(echo $$python | sed "s/$(PYDEF)/python/"); \
	  $$python setup.py clean; \
	done
	rm -f build-stamp configure-stamp
	rm -rf build
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	set -e; \
	for python in $(PYVERS); do \
	  python=$$(echo $$python | sed "s/$(PYDEF)/python/"); \
	  $$python setup.py install --root=$(CURDIR)/debian/python-igraph --install-layout=deb; \
	done
	dh_installdocs -ppython-igraph-doc doc/api/html/*

# 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_installdebconf	
	dh_installdocs
	dh_installexamples
#	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
	dh_installman
	dh_installinfo
#	dh_installchangelogs ChangeLog
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_shlibdeps
#	dh_python
	dh_pycentral
	dh_gencontrol
	dh_installdeb
	dh_md5sums
	dh_builddeb

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