#!/usr/bin/make -f
# PLEASE NOTE: when building a development version or a version where the minor
# library version changes or has changed but the major so version stays the 
# same, make sure to Build-Conflict on libgimpX.X, Where libgimpX.X contains
# a previous version of the same major version of the library. Otherwise,
# libtool will stupidly relink against the system version of the library
# when installing, and create a dependency on the old version of libgimp.
# TODO: maybe set LD_LIBRARY_PATH instead?

## WARNING: compiling without -O2 (DEB_BUILD_OPTIONS=noopt) may produce
## undesired effects, especially when scaling JPEG images

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/class/gnome.mk

LDFLAGS = -Wl,--as-needed
# explicitly set PYTHON to be the versioned python binary, since dh_python2
# will just end up depending on the pythonX.X package, and we don't want a
# version mismatch between the installed python binary and the private python
# modules.
DEB_CONFIGURE_EXTRA_FLAGS := --enable-python --enable-default-binary \
    --without-hal --enable-gtk-doc PYTHON=/usr/bin/`pyversions -d`
DEB_BUILDDIR := $(DEB_SRCDIR)/build

DEB_DH_SHLIBDEPS_ARGS_ALL := -Llibgimp2.0 -l$(CURDIR)/debian/libgimp2.0/usr/lib
# exclude this since we manually add the Recommends in debian/control
DEB_DH_SHLIBDEPS_ARGS_gimp := -Xlibcontroller-midi.so
DEB_DH_MAKESHLIBS_ARGS_gimp := -X/usr/lib/gimp/2.0/modules/

clean::
	rm -rf build

common-install-impl::
	# Remove compiled python files from the distribution, they're compiled
	# in postrm by dh_python2
	# TODO: is this still needed?
	find $(CURDIR)/debian/tmp -name "*.py[co]" -delete
	# Add translation domain to .desktop and .server files
	DOMAIN=$$(grep --max-count 1 '^GETTEXT_PACKAGE[[:space:]]*=' $(DEB_BUILDDIR)/po/Makefile | sed 's/^.*=[[:space:]]\([^[:space:]]\)/\1/'); \
	for d in $$(find debian/tmp -type f -name "*.desktop" ); do \
 		echo "Adding translation domain $$DOMAIN to $$d..."; \
 		echo "X-Ubuntu-Gettext-Domain=$$DOMAIN" >> $$d; \
	done;

	cd po; intltool-update -p
	cd po-libgimp; intltool-update -p
	cd po-plug-ins; intltool-update -p
	cd po-script-fu; intltool-update -p

	# Remove compiled python files from the distribution, they're compiled in
	# postrm by dh_python
	find $(CURDIR)/debian/tmp -name "*.py[co]" -exec rm '{}' ';'

	# Remove all libtool .la files
	find $(CURDIR)/debian/tmp/usr/lib -name "*.la" -delete

	dh_movefiles

binary-install/gimp::
	dh_python2 -pgimp /usr/lib/gimp/2.0/python
