#!/usr/bin/make -f
#
# Debian Makefile for OpenToken
# Copyright (c) 2009, 2010 Stephen Leake <stephen_leake@stephe-leake.org>
#
# 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 of the License, 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# To setup for building this package from a new upstream release:
# cd /home/Projects/opentoken
# mkdir opentoken-<upstream_version>-current
# cd opentoken-<upstream_version>-current
# cp ../opentoken.main/Build/opentoken-<upstream_version>.tar.gz opentoken_<upstream_version>.orig.tar.gz
# mtn -d ~/monotone-dbs/ada-france.db checkout --branch org.debian.libopentoken opentoken-<upstream_version>/debian
#
# To build this package in a chroot, from a new upstream release:
# schroot -d `cd ..; pwd` --chroot=unstable -- dpkg-buildpackage -uc -us -i"_MTN|\\.mtn-ignore"
#
# To run lintian:
# schroot -d `cd ..; pwd` --chroot=unstable -- make -f debian/rules lint
#
# To install the packages and run the tests:
# schroot --chroot=unstable -- ./test_installed.sh
#
# To review changes from previous version:
# schroot -d `cd ..; pwd` --chroot=unstable -- debdiff

.SUFFIXES=

# We use gnatmake, not make, for parallel builds.
.NOTPARALLEL:
CPUS := $(shell getconf _NPROCESSORS_ONLN)

# get soversions, aliversions from debian/control
soversion  := $(shell sed -n -e "s/^Package: libopentoken\([0123456789]\+\)$$/\1/p" debian/control)
aliversion := $(shell sed -n -e "s/^Package: libopentoken\(.\+\)-dev$$/\1/p" debian/control)

verify-versions :
	echo $(soversion)
	echo $(aliversion)

# Targets mandated by the Debian Policy

.PHONY: build binary binary-arch binary-indep clean

build: build-stamp

build-stamp:
	dh_testdir
	gnatmake -p -j$(CPUS) -Pdebian/opentoken_build -XLIBTYPE=static -Xsoversion=$(soversion)
	gnatmake -p -j$(CPUS) -Pdebian/opentoken_build -XLIBTYPE=dynamic -Xsoversion=$(soversion)
	touch $@

clean:
	dh_testdir
	dh_testroot
	dh_clean -a
	rm -f *-stamp

binary: binary-indep binary-arch

binary-indep:

# we don't use <package>.[dirs | docs | examples | ...], because they
# would all have to be renamed and edited when the soversion or
# aliversion change.
binary-arch: build libopentoken-so libopentoken-dev
	dh_shlibdeps -a
	dh_installdeb -a
	dh_installdocs -a
	dh_installchangelogs -a
	dh_compress -a
	dh_fixperms -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

libopentoken-so: package := libopentoken$(soversion)
libopentoken-so:
	dh_testdir
	dh_testroot
	dh_installdirs -p$(package) usr/lib
	dh_install -p$(package) debian/tmp/libopentoken.so.$(soversion) usr/lib
	dh_strip -p$(package) --dbg-package=libopentoken-dbg
	dh_makeshlibs -p$(package)

libopentoken-dev: source  := $(shell ls *.ad[sb] Language_Lexers/*.ad[sb])
libopentoken-dev: package := libopentoken$(aliversion)-dev
libopentoken-dev:
	dh_testdir
	dh_testroot
	dh_install -p$(package) debian/tmp/libopentoken-dynamic/*.ali usr/lib/ada/adalib/opentoken
	dh_install -p$(package) $(source) usr/share/ada/adainclude/opentoken
	dh_install -p$(package) debian/opentoken.gpr usr/share/ada/adainclude
	dh_install -p$(package) debian/tmp/libopentoken.a usr/lib
	dh_link -p$(package) usr/lib/libopentoken.so.$(soversion) usr/lib/libopentoken.so
	dh_installdocs -p$(package) Docs/*
	dh_installexamples -p$(package) Examples/*

lint:
	cd ..; lintian -i opentoken*.changes

# end of file
