#!/usr/bin/make -f

CFLAGS = -g -Wall
SHLD_FLAGS = -shared -Wl,--as-needed

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

include /usr/share/quilt/quilt.make

DESTDIR=$(CURDIR)/debian/tmp

configure: patch configure-stamp
configure-stamp:
	dh_testdir
	CFLAGS="$(CFLAGS)" ./configure --prefix=/usr
	touch configure-stamp

build: configure build-stamp
build-stamp:
	dh_testdir
	$(MAKE) all SHLD_FLAGS="$(SHLD_FLAGS)"
	touch build-stamp

clean: clean-patched unpatch
clean-patched:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -rf build
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(MAKE) install DESTDIR=$(DESTDIR)
	mv $(CURDIR)/debian/tmp/usr/bin/tdbbackup \
		$(CURDIR)/debian/tmp/usr/bin/tdbbackup.tdbtools
	mv $(CURDIR)/debian/tmp/usr/share/man/man8/tdbbackup.8 \
		$(CURDIR)/debian/tmp/usr/share/man/man8/tdbbackup.tdbtools.8
	dh_install --fail-missing --list-missing --sourcedir=$(DESTDIR)

binary-indep: 
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs 
	dh_installman
	dh_installchangelogs 
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs -V 'libtdb1 (>= 1.1.3~git2008122-1)' -- -c4
	dh_pycentral
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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