#!/usr/bin/make -f

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

CFLAGS = -O2 -Wall
LDFLAGS = -Wl,--as-needed

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

configure: configure-stamp
configure-stamp:
	dh_testdir
	LDFLAGS="$(LDFLAGS)" CFLAGS="$(CFLAGS)" ./configure \
		--build=$(DEB_BUILD_GNU_TYPE) --host=$(DEB_HOST_GNU_TYPE) \
		--prefix=/usr --mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--with-gconf-schema-file-dir=/usr/share/gconf/schemas
	touch $@

build: build-stamp
build-stamp: configure
	dh_testdir
	$(MAKE)
	touch $@

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

install: build
	dh_testdir
	dh_testroot
	dh_prep
	$(MAKE) GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL=1 \
		DESTDIR=$(CURDIR)/debian/tmp install
	dh_install --fail-missing

binary-indep: install

binary-arch: install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installexamples mssh_clusters.conf
	dh_installdocs
	dh_installman
	dh_gconf
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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