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

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

debbuild=debian/build-deb
udebbuild=debian/build-udeb

DEB_HOST_ARCH=$(shell dpkg-architecture -qDEB_HOST_ARCH)
CONFFILE=/etc/cdebconf.conf

#package names
LIBDEBCONFDEV=libdebconfclient0-dev
LIBDEBCONF=libdebconfclient0

DEB_FRONTENDS=text newt gtk
UDEB_FRONTENDS=text newt gtk

SIZEOPTFLAG=-Os
SPEEDOPTFLAG=-O2
DEBUG_CONFIGURE_OPT=
ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -g
	SIZEOPTFLAG=
	SPEEDOPTFLAG=
	DEBUG_CONFIGURE_OPT=--with-debug=yes
endif

build: build-deb build-udeb

$(debbuild)/config.status:
	[ -d $(debbuild) ] || mkdir -p $(debbuild)
	cd $(debbuild); \
	CFLAGS="$(CFLAGS) $(SPEEDOPTFLAG)" \
	../../configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--without-rpath \
		--with-db="textdb rfc822db stack" \
		--with-frontend="$(DEB_FRONTENDS)" \
		--with-textwrap \
		--with-conffile=$(CONFFILE) \
		$(DEBUG_CONFIGURE_OPT)

build-deb: build-deb-stamp
build-deb-stamp: $(debbuild)/config.status
	dh_testdir
	$(MAKE) -C $(debbuild)
	touch $@

$(udebbuild)/config.status:
	[ -d $(udebbuild) ] || mkdir -p $(udebbuild)
	cd $(udebbuild); \
	CFLAGS="$(CFLAGS) $(SIZEOPTFLAG) -fomit-frame-pointer" \
	../../configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--enable-d-i \
		--without-rpath --with-db="rfc822db stack" \
		--with-frontend="$(UDEB_FRONTENDS)" \
		--with-default-frontend=newt \
		--with-syslog-logging \
		--with-textwrap \
		--with-conffile=$(CONFFILE) \
		$(DEBUG_CONFIGURE_OPT)

build-udeb: build-udeb-stamp
build-udeb-stamp: $(udebbuild)/config.status
	dh_testdir
	$(MAKE) -C $(udebbuild)
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f *-stamp
	-rm -rf $(debbuild) $(udebbuild)
	[ ! -f globalmakeflags ] || $(MAKE) -C src/test clean
	$(MAKE) distclean
	dh_clean

install: install-arch install-indep

install-arch: build
	dh_testdir
	dh_testroot
	dh_clean -k -a
	$(MAKE) -C $(debbuild) install DESTDIR=$(CURDIR)/debian/tmp/deb \
		TARGET=deb
	$(MAKE) -C $(udebbuild) install DESTDIR=$(CURDIR)/debian/tmp/udeb \
		TARGET=udeb
	dh_install -a --sourcedir=debian/tmp

install-indep:

# Build architecture-independent files here.
binary-indep: install-indep
	dh_testdir
	dh_testroot
	dh_installchangelogs -i
	dh_installdocs -i
	dh_installdebconf -i
	dh_installdirs -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: install-arch
	dh_testdir
	dh_testroot
	dh_installchangelogs -s
	dh_installdocs -s
	dh_installdebconf -s
	dh_installdirs -s
	dh_strip -s
	dh_compress -s
	dh_fixperms -s
	dh_makeshlibs -s --add-udeb=libdebconfclient0-udeb
	dh_installdeb -s
	dh_shlibdeps -s -Ncdebconf-gtk-udeb
	dh_shlibdeps -pcdebconf-gtk-udeb -l /usr/lib/libcairo-directfb/lib/
	dh_gencontrol -s
	dh_md5sums -s
	dh_builddeb -s

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