#!/bin/sh
#
# Very ugly picker for executables from a build.
#
# Problem is that /var/lib/pcp/testsuite/qa is populated from the
# packaging, but in a build context the qmc headers are defined in
# ../../src/libpcp_qmc/src but the qmc library and the standard
# PCP headers are not in ../../src they are out in the build area
# c/o Makepkgs
#

if [ -z "$PCP_DIR" ]
then
    . /etc/pcp.env
else
    . "$PCP_DIR"/etc/pcp.env
fi

# Don't bother if we're not building libraries that depend on Qt
#
if [ -f ../../src/include/builddefs ]
then
    eval `sed -n -e '/^ENABLE_QT[ 	]*=/s/[ 	]//gp' ../../src/include/builddefs`
    [ "$ENABLE_QT" = false ] && exit 0
elif [ -f $PCP_INC_DIR/builddefs ]
then
    eval `sed -n -e '/^ENABLE_QT[ 	]*=/s/[ 	]//gp' $PCP_INC_DIR/builddefs`
    [ "$ENABLE_QT" = false ] && exit 0
fi

builddir=''
for builddir in ../../build/deb/pcp-$PCP_VERSION/qa/qt $PCP_VAR_DIR/testsuite/qt ''
do
    [ -n "$builddir" -a -d "$builddir" ] && break
done

for x in qmc_*
do
    [ -x $x/$x ] && continue
    $PCP_ECHO_PROG $PCP_ECHO_N "Hunting for $x executable ... $PCP_ECHO_C"
    if [ -z "$builddir" ]
    then
	echo "no build dir, not found"
    elif [ -x $builddir/$x/$x ]
    then
	cp $builddir/$x/$x $x/$x
	echo OK
    else
	echo "not found"
    fi
done
