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

# 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 ($(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

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

CFLAGS += -Wall -g

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

config.status: configure
	dh_testdir
	./configure  --localstatedir=/var $(CROSS) \
	--prefix=/usr CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" \
	LDFLAGS="$(LDFLAGS) -Wl,-z,defs -Wl,--as-needed"

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp: config.status
	dh_testdir
	$(MAKE)
	xsltproc --nonet /usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl debian/drivel.xml
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f debian/drivel.1 drivel.1 drivel.prj acsite.m4 drivel.pws
	rm -f config.status HACKING autogen.sh README.transifex
	chmod 644 po/*.po
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	# use DESTDIR here instead, then split out a data or common package.
	GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL=yes \
		$(MAKE) install prefix=/usr DESTDIR=$(CURDIR)/debian/tmp/ \
		sysconfdir=$(PREFIX)/etc UPDATE_MIME_DATABASE=:

# Build architecture-independent files here.
binary-indep: build install


# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installexamples
	dh_installmenu
	dh_installmime
	dh_installman drivel.1
	dh_install
	dh_icons
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_gconf
	dh_installdeb
	dh_shlibdeps -pdrivel
	dh_gencontrol -pdrivel
	dh_md5sums
	dh_builddeb -pdrivel

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