#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright 2008-2013, 2015-2017 Jonas Smedegaard
# <dr@jones.dk>
# Description: Main Debian packaging script for sugar-toolkit
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

DEB_BUILDDIR = build
include /usr/share/cdbs/1/class/python-autotools.mk
include /usr/share/cdbs/1/rules/debhelper.mk

CDBS_BUILD_DEPENDS +=, autoconf-archive
include /usr/share/cdbs/1/rules/autoreconf.mk

pkgbase = python-sugar-toolkit
pkgbranch = $(subst $(space),.,$(wordlist 1, 2,$(subst .,$(space),$(DEB_UPSTREAM_VERSION))))
pkg = $(pkgbase)

# Drop created dir if empty to please lintian
binary-post-install/$(pkg)::
	rmdir --ignore-fail-on-non-empty --parents $(DEB_DESTDIR)/usr/share/locale

# Strip hardcoded rpath
binary-strip/$(pkg)::
	find $(DEB_DESTDIR)/usr/lib -type f -name '*.so' -exec chrpath -d '{}' ';'

# Needed by upstream build process
bdeps = libglib2.0-dev, python-gtk2-dev, libsm-dev, libice-dev
bdeps +=, libasound2-dev | libasound-dev, gettext, intltool
bdeps +=, libxml-parser-perl

# Needed for our packaging
bdeps +=, chrpath

# Needed (always/often/seldom) at runtime
#  * dbus-session-bus (bus.get_object) used in sugar.*
#    + python-carquinyol-* (org.laptop.sugar.DataStore) used in
#      sugar.datastore.datastore
#    + python-jarabe (org.laptop.Journal and org.laptop.Shell) used in
#      sugar.activity.activity sugar.graphics.objectchooser and
#      sugar.activity.activityfactory
#    + sugar-presence-service (org.laptop.Telepathy) used in sugar.presence.*
#    + telepathy-mission-control-5 (org.freedesktop.Telepathy.*) used in
#      sugar.presence.connectionmanager and sugar.presence.presenceservice
#  * python-sugar (sugar.mime and sugar.dispatch) used in
#    sugar.datastore.datastore
#  * telepathy-* versioning follows http://wiki.sugarlabs.org/go/0.90/Notes
#  * shared-mime-info (update-mime-database) used in sugar.bundle.bundlebuilder
#  * unzip used in sugar.bundle.bundle
#  * git used in sugar.activity.bundlebuilder
#  TODO: Drop dbus-x11 fallback after stretch+1
python-depends = gtk2 dbus gobject cairo telepathy
python-depends += sugar hippocanvas gconf dateutil rsvg
depends = $(patsubst %,$(comma) python-%,$(python-depends))
recommends = sugar-presence-service, fonts-dejavu-core, unzip
recommends +=, default-dbus-session-bus | dbus-session-bus | dbus-x11
recommends +=, telepathy-mission-control-5, telepathy-salut
recommends +=, python-carquinyol, python-jarabe, shared-mime-info
suggests = git, fonts-dejavu-extra

CDBS_BUILD_DEPENDS +=, $(bdeps)
CDBS_DEPENDS_$(pkg) = $(depends)
CDBS_RECOMMENDS_$(pkg) = $(recommends)
CDBS_SUGGESTS_$(pkg) = $(suggests)

# Avoid .la files - see http://wiki.debian.org/ReleaseGoals/LAFileRemoval
binary-post-install/$(pkg)::
	find '$(cdbs_curdestdir)' -name '*.la' -delete

# Fix favor ISO 639-1 when differing from ISO 639-2
binary-post-install/$(pkg)::
	mv debian/$(cdbs_curpkg)/usr/share/locale/aym \
		debian/$(cdbs_curpkg)/usr/share/locale/ay
