#!/bin/ksh
# Was /bin/sh

if [ -r src/$1.cc ]; then
    dir=src
else
    if [ -r online/src/$1.cc ]; then
	dir=online/src
    else
	if [ -r daquser/src/$1.cc ]; then
	    dir=daquser/src
	else
	    dir=records/src
	fi
    fi
fi

echo "Building bin/$1 from $dir/$1.cc"

. records/bin/setRecordsInc
. daquser/bin/setDaquserInc
. online/bin/setOnlineInc

g++ -Wall \
    -D CALICE_DAQ_ICC \
    -D CALICE_DAQ_TIME=`date +%s`\
    -D_G_HAVE_BOOL -DLITTLE_ENDIAN__ -Dlinux -DBT1003 -DVXILINUX \
    \
    -I- \
    -I inc \
    -I src \
    $CALICE_ONLINE_INC \
    $CALICE_DAQUSER_INC \
    $CALICE_RECORDS_INC \
    \
    -I hal/generic/include \
    -I hal/utilities/include \
    -I hal/generic/include/linux \
    -I hal/busAdapter/include \
    -I hal/xcept/include \
    \
    -I sbs/include \
    \
    -Wl,-rpath hal/lib/linux/x86 \
    -L hal/lib/linux/x86 -lGenericHAL -lSBSLinuxX86BusAdapter -lHALUtilities -lxcept \
    \
    -L sbs/lib -lbtp \
    \
    `$ROOTSYS/bin/root-config --new --cflags --glibs` \
    \
    -lpthread \
    \
    -o bin/$1 $dir/$1.cc
