#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright 2017 Jonas Smedegaard <dr@jones.dk>
# Description: Main Debian packaging script for Astroid
#
# 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/>.

# resolve if release is experimental
include /usr/share/dpkg/pkg-info.mk
EXP_RELEASE = $(filter experimental% UNRELEASED,$(DEB_DISTRIBUTION))

include /usr/share/cdbs/1/class/scons.mk
include /usr/share/cdbs/1/rules/debhelper.mk

pkg = astroid

dev-deps = gtkmm-3.0 glibmm-2.4 gmime-3.0 webkitgtk-3.0 vte-2.91 sass girepository1.0 peas notmuch
boost-deps = filesystem system program-options log thread date-time test
bdeps = $(patsubst %,$(comma) lib%-dev,$(dev-deps))
bdeps +=, $(patsubst %,$(comma) libboost-%-dev,$(boost-deps))
deps-test = python3-gi
deps-test-recommend = notmuch

# TODO: Identify and list more XEmbed-supportive editors
recommends = xdg-utils, vim-gtk3 | emacs25, gnupg (>= 2)

CDBS_BUILD_DEPENDS +=, $(bdeps), $(deps-test), $(deps-test-recommend)
CDBS_BUILD_DEPENDS +=, scons, pkg-config
CDBS_RECOMMENDS_$(pkg) = $(recommends), $(deps-test-recommend)

DEB_BUILD_PARALLEL = 1

DEB_SCONS_OPTIONS += --verbose
DEB_SCONS_OPTIONS += --prefix=/usr
DEB_SCONS_OPTIONS += --release=$(DEB_VERSION)
DEB_SCONS_OPTIONS += --enable-debug=yes

# use virtual X11 and UTF-8 in testsuite
# ignore testuite failure when targeting experimental
CDBS_BUILD_DEPENDS +=, xvfb, xauth
DEB_SCONS_CHECK_TARGET = test$(if $(EXP_RELEASE), || true)
common-post-build-impl:: DEB_SCONS_ENVVARS := LOCALE=C.UTF-8 xvfb-run -a $(DEB_SCONS_ENVVARS)

# TODO: teach SConstruct about destdir different from prefix
#DEB_SCONS_INSTALL_OPTIONS = --prefix=$(cdbs_curdestdir)/usr
DEB_SCONS_INSTALL_TARGET =

DEB_INSTALL_DOCS_ALL += README.md
DEB_INSTALL_EXAMPLES_$(pkg) += examples/poll.sh

clean::
	find -type f -name '*.pyc' -delete
	rm -f src/build_config.hh
