#!/usr/bin/make -f
# -*- makefile-gmake -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
# This has to be exported to make some magic below work.
export DH_OPTIONS
RUBY_SITEARCH := $(shell ruby1.8 -rrbconfig -e 'puts Config::CONFIG["sitearch"]')
export RUBY_CFLAGS+=-I/usr/lib/ruby/vendor_ruby/1.8/$(RUBY_SITEARCH)

DEB_HOST_ARCH      ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

confflags := \
	--libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
	--with-ruby=/usr/bin/ruby1.8 \
	$(NULL)

confflags += $(shell dpkg-buildflags --export=configure)
export AM_LDFLAGS=$(shell dpkg-buildflags --get LDFLAGS)

%:
	dh  --with quilt $@

override_dh_auto_configure:
	for i in \
		lib/tomoe-enum-types.c \
		lib/tomoe-enum-types.h \
		doc/reference/version.xml \
		spec/miracle-linux/tomoe.spec \
		spec/turbo-linux/tomoe.spec \
		tomoe.pc \
	; do \
		[ ! -e $(CURDIR)/$$i.dh-orig ] || continue; \
		cp -f $(CURDIR)/$$i $(CURDIR)/$$i.dh-orig; \
	done
	dh_auto_configure -- $(confflags)

override_dh_auto_clean:
	dh_auto_clean
	rm -f intltool-extract intltool-merge intltool-update
	rm -f lib/stamp-tomoe-enum-types-c lib/stamp-tomoe-enum-types-h
	rm -f test/python/tomoe-test-xmldict.xml
	for i in \
		lib/tomoe-enum-types.c \
		lib/tomoe-enum-types.h \
		doc/reference/version.xml \
		spec/miracle-linux/tomoe.spec \
		spec/turbo-linux/tomoe.spec \
		tomoe.pc \
	; do \
		[ -e $(CURDIR)/$$i.dh-orig ] || continue; \
		mv -f $(CURDIR)/$$i.dh-orig $(CURDIR)/$$i; \
	done

override_dh_link:
	for pkg in \
		tomoe-doc \
		libtomoe-dev \
		libtomoe0 \
		python-tomoe \
		ruby-tomoe \
	; do \
		rm -rf $(CURDIR)/debian/$$pkg/usr/share/doc/$$pkg; \
		dh_link -p$$pkg \
			usr/share/doc/tomoe-common \
			usr/share/doc/$$pkg; \
	done
	dh_link
