#!/bin/sh
set -Ceu
cp -a $0-pkg "$AUTOPKGTEST_TMP/pkg"
cd "$AUTOPKGTEST_TMP/pkg"

DEB_BUILD_OPTIONS=noopt debian/rules binary

cd debian

DEB_ADA_SOURCE_DIR=usr/share/ada/adainclude
DEB_GNAT_PROJECT_DIR=usr/share/gpr

DEB_HOST_MULTIARCH=`dpkg-architecture -qDEB_HOST_MULTIARCH`
DEB_LIB_DIR=usr/lib/$DEB_HOST_MULTIARCH
DEB_ADA_LIB_INFO_DIR=$DEB_LIB_DIR/ada/adalib

DEB_GNAT_VERSION=`gnatmake --version | sed 's/.* \([0-9]\+\)\.[0-9.]\+$/\1/;q'`

echo 'Sources'
test -e libfoo3-dev/$DEB_ADA_SOURCE_DIR/foo/foo.adb
test -e libfoo3-dev/$DEB_ADA_SOURCE_DIR/foo/foo.ads

echo 'Static archive'
test -e libfoo3-dev/$DEB_LIB_DIR/libfoo.a

echo 'Project'
test -e libfoo3-dev/$DEB_GNAT_PROJECT_DIR/foo.gpr

echo 'ALI files'
test -e libfoo3-dev/$DEB_ADA_LIB_INFO_DIR/foo/foo.ali

echo 'debug-prefix-map'
status=0
grep fdebug-prefix-map= lib*-dev/$DEB_ADA_LIB_INFO_DIR/*/*.ali  || status=$?
test $status = 1

echo 'Shared library'
test -e libfoo5/$DEB_LIB_DIR/libfoo.so.5.0.0

echo 'Ldconfig link'
test -h libfoo5/$DEB_LIB_DIR/libfoo.so.5
test $(readlink -v libfoo5/$DEB_LIB_DIR/libfoo.so.5) = libfoo.so.5.0.0

echo 'Development symbolic link'
test -h libfoo3-dev/$DEB_LIB_DIR/libfoo.so
test $(readlink -v libfoo3-dev/$DEB_LIB_DIR/libfoo.so) = libfoo.so.5.0.0

echo 'ada:Depends'
grep "^Depends: gnat (<< [0-9]\+), gnat (>= $DEB_GNAT_VERSION), libfoo5 (= 1)\$" \
     libfoo3-dev/DEBIAN/control

echo 'OK'
