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

if [ -r src/$1.cc ]; then
    file=src/$1.cc
else
    if [ -r online/src/$1.cc ]; then
	file=online/src/$1.cc
    else
	if [ -r daquser/src/$1.cc ]; then
	    file=daquser/src/$1.cc
	else
	    if [ -r records/src/$1.cc ]; then
		file=records/src/$1.cc
	    else
		file=usbdaq/tests/src/$1.cpp
	    fi
	fi
    fi
fi

echo "Online: Building bin/$1 from $file"

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

g++ -Wall \
    -D CALICE_DAQ_ICC \
    -D CALICE_DAQ_TIME=`date +%s`\
    \
    -I- \
    -I inc \
    -I src \
    $CALICE_ONLINE_INC \
    $CALICE_DAQUSER_INC \
    $CALICE_RECORDS_INC \
    \
    -I usbdaq/interface \
    -I usbdaq/include \
    -I libusb \
    \
    `$ROOTSYS/bin/root-config --new --cflags --glibs` \
    \
    -L usbdaq/lib -lCALICEMAPS1 \
    -L libusb/lib -lusb \
    \
    -lpthread \
    \
    -o bin/$1 $file
