#!/usr/bin/make -f

DEB_BUILDDIR = debian/build
DEB_MAKE_DESTDIRSKEL = $(CURDIR)/debian/install/@FLAVOR@
DEB_MAKE_FLAVORS = shared static udeb
DISABLE_UPDATE_UPLOADERS = 1

include /usr/share/cdbs/1/rules/autoreconf.mk
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/rules/utils.mk
include /usr/share/cdbs/1/class/gnome.mk
include /usr/share/gnome-pkg-tools/1/rules/uploaders.mk
include /usr/share/gnome-pkg-tools/1/rules/gnome-get-source.mk

GNOME_MODULE := pango

# Enable parallel build support
DEB_BUILD_PARALLEL = 1

# Ensure the build aborts when there are still references to undefined symbols
LDFLAGS += -Wl,-z,defs

# Make the linker work a bit harder so dynamic loading can be done faster
LDFLAGS += -Wl,-O1

APIVER := 1.0
SONAME := 0

# relative libdir
LIBDIR := usr/lib/$(DEB_HOST_MULTIARCH)
LIBDIR_UDEB := $(LIBDIR)

# package names
SHARED_PKG := libpango-$(APIVER)-$(SONAME)
UDEB_PKG := libpango$(APIVER)-udeb
DEV_PKG := libpango$(APIVER)-dev
DEBUG_PKG := libpango$(APIVER)-$(SONAME)-dbg
DOC_PKG := libpango$(APIVER)-doc

DEB_CONFIGURE_EXTRA_FLAGS = \
		--with-html-dir=\$${prefix}/share/doc/$(DOC_PKG)

DEB_CONFIGURE_FLAGS_shared = \
		--libdir=/$(LIBDIR) \
		--enable-installed-tests

DEB_CONFIGURE_FLAGS_static = \
		--libdir=/$(LIBDIR) \
		--disable-shared \
		--enable-static

DEB_CONFIGURE_FLAGS_udeb = \
		--libdir=/$(LIBDIR_UDEB) \
		--without-libthai \
		--disable-debug

# Get failing tests' stdout/err so we have some information when a build fails
export VERBOSE=1

DEB_MAKE_CHECK_TARGET = check
DEB_DH_STRIP_ARGS_DEFAULT = --dbg-package=libpango$(APIVER)-$(SONAME)-dbg
DEB_DH_STRIP_ARGS_$(UDEB_PKG) =
DEB_DH_MAKESHLIBS_ARGS_ALL += -V --add-udeb=$(UDEB_PKG) -- -c4

# macro computing the list of 'debian/<pkg>.*" files which have a corresponding
# ".in" file; pass the list of packages in $(1)
dh_subst_files = $(patsubst %.in,%,$(wildcard $(addprefix debian/, $(addsuffix *.in, $(1)))))

debian/%: debian/%.in
	dh_testdir
	sed \
		-e 's#@SONAME@#$(SONAME)#g' \
		-e 's#@APIVER@#$(APIVER)#g' \
		-e 's#@VERSION@#$(DEB_UPSTREAM_VERSION)#g' \
		-e 's#@LIBDIR@#$(LIBDIR)#g' \
		-e 's#@LIBDIR_UDEB@#$(LIBDIR_UDEB)#g' \
		-e 's#@GNOME_TEAM@#$(UPLOADERS)#g' \
		$@.in >$@

clean:: debian/control
	# gross kludge to force control generation with the %.in target
	touch debian/control.in
	# remove generated files
	rm -f $(call dh_subst_files,$(DEB_ALL_PACKAGES))
	rm -rf $(DEB_BUILDDIR) debian/install

build-indep: $(call dh_subst_files,$(DEB_INDEP_PACKAGES))
build-arch: $(call dh_subst_files,$(DEB_ARCH_PACKAGES))

common-build-arch::
	# hack to fix missing enumeration GTypes in GIR
	cd debian/build/shared/pango/ && rm pango-enum-types.* *.gir *.typelib && make

binary-install/$(DEV_PKG)::
	# verify that the .gir is built correctly
	grep -q 'glib:get-type="pango_wrap_mode_get_type"' debian/$(DEV_PKG)/usr/share/gir-1.0/Pango-1.0.gir

binary-install/pango1.0-tests:: DEB_DH_INSTALL_ARGS = --sourcedir=debian/install/shared
