#!/usr/bin/make -f
#
# Debian Makefile for AUnit
# Copyright (c) 2009 Stephen Leake <stephen_leake@stephe-leake.org>
# Copyright (c) 2004, 2006 Ludovic Brenta <ludovic@ludovic-brenta.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 build this package in a chroot:
# 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)

# soversion changes when the library API changes
soversion := 3

# aliversion changes when any ali file changes
aliversion := 1

# 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/aunit_build -XLIBTYPE=static -Xsoversion=$(soversion)
	gnatmake -p -j$(CPUS) -Pdebian/aunit_build -XLIBTYPE=dynamic -Xsoversion=$(soversion)
	touch $@

clean:
	dh_testdir
	dh_testroot
	dh_clean -a
	rm -f *-stamp
	rm -f debian/substvars

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 libaunit-so libaunit-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

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

libaunit-dev: specs   := $(shell find aunit -name \*.ads)
libaunit-dev: bodies  := $(shell find aunit -name \*.adb)
libaunit-dev: package := libaunit$(aliversion)-dev
libaunit-dev:
	dh_testdir
	dh_testroot
	dh_installdirs -p$(package) usr/share/ada/adainclude/aunit usr/lib/ada/adalib/aunit usr/share/doc/$(package) /usr/lib
	dh_install -p$(package) debian/tmp/libaunit-dynamic/*.ali usr/lib/ada/adalib/aunit
	dh_install -p$(package) $(specs) $(bodies) usr/share/ada/adainclude/aunit
	dh_install -p$(package) debian/aunit.gpr usr/share/ada/adainclude
	dh_install -p$(package) debian/tmp/libaunit.a usr/lib
	dh_link -p$(package) usr/lib/libaunit.so.$(soversion) usr/lib/libaunit.so
	dh_installdocs -p$(package) AUnit.html
	dh_installexamples -p$(package) template/*

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

# end of file
