#! /usr/bin/make -f

dh := --with sodeps

include /usr/share/pkg-kde-tools/qt-kde-team/2/debian-qt-kde.mk

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

#Always use Ruby 1.8.x
RUBY_SITEARCH := $(shell ruby1.8 -rrbconfig -e 'puts Config::CONFIG["sitearch"]')
CMAKE_FLAGS := \
  -DRUBY_EXECUTABLE=/usr/bin/ruby1.8 \
  -DCUSTOM_RUBY_SITE_LIB_DIR=/usr/lib/ruby/1.8/ \
  -DCUSTOM_RUBY_SITE_ARCH_DIR=/usr/lib/ruby/1.8/$(RUBY_SITEARCH) \
  $(NULL)

override_dh_install:
	$(overridden_command) --list-missing

override_dh_strip:
	$(overridden_command) --dbg-package=ruby-qt4-dbg

override_dh_auto_configure:
	$(overridden_command) -- $(CMAKE_FLAGS)

override_dh_compress:
	$(overridden_command) -X.rb -X.ui -X.mng -X.xbel

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

override_dh_makeshlibs:
	$(overridden_command) -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:
	$(overridden_command)
	rm -f debian/shlibs.local
