#!/usr/bin/make -f
# (C) 2003 Marcelo E. Magallon <mmagallo@debian.org>
# (C) 2006-2011 Joost Yervante Damad <andete@debian.org>
# (C) 2012 Matteo F. Vescovi <mfv.debian@gmail.com>

export DH_VERBOSE
# export DH_NO_ACT
# export DH_OPTIONS

include /usr/share/dpkg/architecture.mk

DPKG_EXPORT_BUILDFLAGS = 1
DEB_CFLAGS_MAINT_APPEND = -Wall -g
include /usr/share/dpkg/buildflags.mk

# let dh_strip strip
export STRIP=true
export INSTALL=install --strip-program=true

configure: configure-stamp
configure-stamp:
	dh_testdir
	rm -f config/config.guess
	ln -sf /usr/share/misc/config.guess config/
	touch configure-stamp

build:

install: build-stamp
build-stamp: configure-stamp
	dh_testdir
	dh_testroot
	dh_prep
	dh_auto_build -- \
		GL_LDFLAGS=-lGL \
		GLU_LDFLAGS=-lGLU \
		GLUT_LDFLAGS=-lglut \
		LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH) \
		'LD=$$(CC)' \
		SYSTEM=$(firstword $(subst -, ,$(DEB_HOST_GNU_SYSTEM))) \
		'OPT=$(CFLAGS)'
	touch build-stamp
	dh_installdirs
	$(MAKE) install.all GLEW_DEST=$(CURDIR)/debian/tmp/usr LIBDIR=$(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)

clean:
	dh_testdir
	dh_testroot
	rm -f config/config.guess
	ln -sf /usr/share/misc/config.guess config/
	rm -f build-stamp build-stampmx configure-stamp
	$(MAKE) distclean
	rm -f config/config.guess
	dh_clean

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

build-arch: build
build-indep: build

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installchangelogs
	dh_install --sourcedir=debian/tmp
	dh_installman
	dh_link
	dh_strip --dbgsym-migration="libglew-dbg (<< 2.0.0-5)"
	dh_compress
	dh_fixperms
	dh_makeshlibs -V
	dh_installdeb
	dh_shlibdeps # -ldebian/tmp/usr/lib
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch

debian/%.1: debian/%.sgml
	docbook-to-man $< > $@

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