#!/usr/bin/make -f

#export DH_VERBOSE=1
export GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL=1
export MONO_SHARED_DIR=$(CURDIR)

include /usr/share/dpatch/dpatch.make

CFLAGS ?= -O2 -Wall -g
LDFLAGS += -Wl,-z,defs -Wl,-O1 -Wl,--as-needed

API_VERSION = 2.24.0

UPVERSION = $(shell dpkg-parsechangelog | grep ^Vers | cut -d\  -f2 | sed 's,-.*,,')
NEXT_UPVERSION = $(shell perl -e '$$_=pop; s/(\d+)$$/$$1+1/e; print' $(UPVERSION))

autoreconf: autoreconf-stamp
autoreconf-stamp: patch-stamp
	touch $@

config: config-stamp
config-stamp: autoreconf-stamp
	dh_testdir
	CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" ./configure \
		--prefix=/usr \
		CSC=/usr/bin/gmcs
	touch $@

build-indep: build-indep-stamp
build-indep-stamp: config-stamp
	dh_testdir
	$(MAKE)
	touch $@

build-arch: build-arch-stamp
build-arch-stamp: config-stamp
	dh_testdir
	$(MAKE)
	touch $@

clean: unpatch
	dh_testdir
	dh_testroot

	rm -f autoreconf-stamp config-stamp build-indep-stamp build-arch-stamp
	[ ! -f Makefile ] || $(MAKE) distclean 



	dh_clean

install:
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp

binary-indep: build-indep install
	dh_testdir
	dh_testroot
	dh_installdirs -i
	dh_link -i
        # HACK: we must install arch dep and indep here!
        # dh_clideps needs the clilibs files of all packages
	dh_install
	install -m755 $(CURDIR)/debian/list-examples $(CURDIR)/debian/gnome-sharp2-examples/usr/bin/gnome-sharp2-examples-list
	dh_installchangelogs -i ChangeLog
	dh_installdocs -i
	dh_installcligac -i
	dh_compress -i
	dh_fixperms -i
	dh_clifixperms -i
	dh_installdeb -i
	# HACK: we must generate clilibs of arch:all and arch:any here!
	# else dh_clideps can't catch up inner source package dependencies
	dh_makeclilibs -m $(API_VERSION)
	dh_clideps -i -d
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

binary-arch: build-arch install
	dh_testdir
	dh_testroot
	dh_installdirs -a
	dh_link -a
        # HACK: we must install arch dep and indep here!
        # dh_clideps needs the clilibs files of all packages
	dh_install
	dh_installchangelogs -a ChangeLog
	dh_installdocs -a
	dh_installcligac -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_clifixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	# HACK: we must generate clilibs of arch:all and arch:any here!
	# else dh_clideps can't catch up inner source package dependencies
	dh_makeclilibs -m $(API_VERSION)
	dh_clideps -a -d
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

build: build-indep build-arch
binary: binary-indep binary-arch

.PHONY: autoreconf config build-indep build-arch clean install binary-indep binary-arch build binary patch
