#!/usr/bin/make -f
CC = gcc
CFLAGS = -g -Wall
export DH_VERBOSE=1

package = testrunner-lite

ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
  CFLAGS += -O2
endif

DEB_HOST_ARCH      ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
VERSION    ?= $(shell head  -1 debian/changelog | cut -d ' ' -f 2 | sed 's/[\(\)]//g')
CFLAGS += -DVERSIONSTR="$(VERSION)"
confflags += --build=$(DEB_BUILD_GNU_TYPE) --host=$(DEB_HOST_GNU_TYPE)

build: build-stamp
build-stamp:
	dh_testdir
	libtoolize --copy --force && aclocal  && autoheader && automake --add-missing --foreign && autoconf
	touch build-stamp 
	./configure --prefix=/usr  $(confflags)
	$(MAKE) CFLAGS="$(CFLAGS)"  || exit 1 
	$(MAKE) html || exit 1 
	touch NEWS 
	touch ChangeLog
	touch build-stamp

clean: 
	dh_clean
	rm -f build-stamp
	[ ! -f Makefile ] || $(MAKE) distclean 

install: build
	dh_clean
	dh_installdirs 
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp 
#	$(MAKE) install-html-local DESTDIR=$(CURDIR)/debian/tmp

binary-indep: install

binary-arch: install
	dh_testroot -Aai	
	dh_installdocs -a NEWS
	dh_installchangelogs -a ChangeLog
	dh_installdirs -Aai
	dh_install -Aai --sourcedir=debian/tmp
	dh_strip  -Aai
	dh_makeshlibs -Aai
	dh_compress -Aai
	dh_fixperms -Aai
	dh_installdeb -Aai
	dh_shlibdeps -Aai
	dh_gencontrol -Aai
	dh_builddeb -Aai

binary: binary-indep binary-arch
.PHONY: binary binary-arch binary-indep clean checkroot
