#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
CFLAGS:=$(shell dpkg-buildflags --get CFLAGS)
CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS)
LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS)

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DEB_HOST_GNU_TYPE=$(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE=$(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
CROSS= --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
else
CROSS= --build $(DEB_BUILD_GNU_TYPE)
endif

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -g
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

configure: configure-stamp
configure-stamp:
	dh_testdir
	$(RM) aclocal.m4 configure
	aclocal
	libtoolize -f
	automake --add-missing
	autoreconf -fs
	./configure --enable-gtk-doc --prefix=/usr --libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH) $(CROSS) \
		CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"
	touch configure-stamp

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp: configure-stamp
	dh_testdir
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	$(RM) doc/libgpewidget-scan.*
	$(RM) doc/libgpewidget.types
	$(RM) doc/*.txt patch-stamp
	$(RM) doc/xml/color-slider.xml doc/xml/colordialog.xml doc/xml/colorrenderer.xml doc/xml/dirbrowser.xml
	$(RM) doc/xml/errorbox.xml doc/xml/gpeclockface.xml doc/xml/gpedialog.xml doc/xml/gpehelp.xml doc/xml/gpeiconlistitem.xml
	$(RM) doc/xml/gpeiconlistview.xml doc/xml/gpetimesel.xml doc/xml/gpewindowlist.xml doc/xml/gtkdatecombo.xml
	$(RM) doc/xml/gtksimplemenu.xml doc/xml/infoprint.xml doc/xml/init.xml doc/xml/link-warning.xml doc/xml/pixmaps.xml 
	$(RM) doc/xml/popup.xml doc/xml/popup_menu.xml doc/xml/question.xml doc/xml/smallbox.xml doc/xml/spacing.xml 
	$(RM) doc/xml/stylus.xml doc/xml/translabel.xml doc/xml/tray.xml 
	$(RM) -r Makefile.in aclocal.m4 config.guess config.sub configure depcomp doc/Makefile.in install-sh ltmain.sh missing
	$(RM) -r doc/html INSTALL
	$(RM) doc/tmpl/color-slider.sgml doc/tmpl/colordialog.sgml \
	doc/tmpl/dirbrowser.sgml doc/tmpl/errorbox.sgml \
	doc/tmpl/gpeclockface.sgml doc/tmpl/gpehelp.sgml \
	doc/tmpl/gpeiconlistitem.sgml doc/tmpl/gpeiconlistview.sgml \
	doc/tmpl/gpetimesel.sgml doc/tmpl/gpewindowlist.sgml \
	doc/tmpl/gtkdatecombo.sgml doc/tmpl/gtksimplemenu.sgml \
	doc/tmpl/infoprint.sgml doc/tmpl/init.sgml \
	doc/tmpl/libgpewidget-unused.sgml doc/tmpl/pixmaps.sgml \
	doc/tmpl/popup.sgml doc/tmpl/popup_menu.sgml doc/tmpl/question.sgml \
	doc/tmpl/smallbox.sgml doc/tmpl/spacing.sgml doc/tmpl/stylus.sgml \
	doc/tmpl/translabel.sgml doc/tmpl/tray.sgml \
	doc/tmpl/colorrenderer.sgml doc/tmpl/gpedialog.sgml \
	doc/tmpl/link-warning.sgml doc/tmpl/picturebutton.sgml doc/tmpl/windows.sgml
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	$(MAKE) install PREFIX=/usr DESTDIR=$(CURDIR)/debian/tmp
	install -d debian/tmp/usr/share/doc/libgpewidget-doc/
	ln -s -T /usr/share/gtk-doc/html/libgpewidget/ debian/tmp/usr/share/doc/libgpewidget-doc/html

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_install
	dh_installdocs
	dh_installchangelogs ChangeLog
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_install
	dh_installdocs
	dh_installman
	dh_installchangelogs ChangeLog
	dh_link
	dh_strip --dbg-package=libgpewidget1-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
