#!/usr/bin/make -f

include /usr/share/quilt/quilt.make

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

CFLAGS = -Wall -g

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

configure: configure-stamp
configure-stamp: $(QUILT_STAMPFN)
	dh_testdir
	autoreconf -i
	CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) \
		--build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr \
		--mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info
	touch $@

build: build-stamp
build-stamp: configure
	dh_testdir
	$(MAKE)
ifeq ($(DEB_HOST_GNU_TYPE), $(DEB_BUILD_GNU_TYPE))
	$(MAKE) check
endif
	touch $@

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f configure-stamp build-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	find $(CURDIR) -name "Makefile.in" | xargs rm -f
	rm -f config.sub config.guess configure
	rm -rf autom4te.cache config.h.in* aclocal.m4 ltmain.sh
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
	rm -f $(CURDIR)/debian/tmp/usr/lib/libglut.la

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_movefiles
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installexamples
	dh_install --fail-missing
	dh_installman
	dh_link
	dh_strip --dbg-package=freeglut3-dbg
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch

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