#! /usr/bin/make -f

pkgs_lib := $(filter-out %-dev %-dbg,$(filter lib%,$(shell dh_listpackages)))
current_version := $(shell dpkg-parsechangelog | sed -n 's/^Version: //p')


#RUBY_CONFIG_INCLUDE_DIR := $(shell ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyarchhdrdir"]')
RUBY_VENDORARCHDIR := $(shell ruby -rrbconfig -e 'puts RbConfig::CONFIG["vendorarchdir"]')
RUBY_VENDORLIBDIR := $(shell ruby -rrbconfig -e 'puts RbConfig::CONFIG["vendorlibdir"]')
CMAKE_FLAGS := \
  -DCUSTOM_RUBY_SITE_LIB_DIR=$(RUBY_VENDORLIBDIR) \
  -DCUSTOM_RUBY_SITE_ARCH_DIR=$(RUBY_VENDORARCHDIR) \
  $(NULL)

override_dh_install:
	dh_install --list-missing

override_dh_strip:
	dh_strip --dbg-package=ruby-qt4-dbg

override_dh_auto_configure:
	dh_auto_configure -- $(CMAKE_FLAGS)

override_dh_compress:
	dh_compress -X.rb -X.ui -X.mng -X.xbel

override_dh_installexamples:
	dh_installexamples
	tar cvzf $(CURDIR)/debian/ruby-qt4/usr/share/doc/ruby-qt4/examples.tar.gz examples

override_dh_makeshlibs:
	dh_makeshlibs -V
# Generate shlibs local files
	for pkg in $(pkgs_lib); do \
		if test -e debian/$${pkg}/DEBIAN/shlibs ; then \
			sed 's/>=[^)]*/= $(current_version)/' debian/$${pkg}/DEBIAN/shlibs >> debian/shlibs.local ;\
		fi \
	done

override_dh_auto_clean:
	dh_auto_clean
	rm -f debian/shlibs.local

#Build-Depend on pkg-kde-tools (>= 0.6.8) for the sodeps addon
%:
	dh $@ --parallel --with sodeps

