#!/bin/sh
buildopt="$1"

export CC=g++
export IDLOUT=`pwd`/../SMACidl/idlout
export LIBINSTALL=/usr/local/lib
export LINK=g++
export OMNIDIR=/usr/local
export SMACFRM=`pwd`/../SMACFramework

export CFLAGS0="-I$SMACFRM -I$OMNIDIR/include -I$OMNIDIR/include/COS -D__OMNIORB4__ -fexceptions -Wall -Wno-unused -Werror -D__linux__ -D__OSVERSION__=2 -O2 -g"
export CFLAGS1="-I$IDLOUT $CFLAGS0"
export LFLAGS0="-lboost_date_time-mt -lboost_serialization-mt -lboost_thread-mt -lCOS4 -lomniORB4 -lCOSDynamic4 -lomniDynamic4 -lomnithread"
export LFLAGS1="-lLqrSMACInterfaces $LFLAGS0"
export LFLAGS2="-lLqrSMACFramework $LFLAGS1"

export SHARED_LIBS="/usr/local/lib/libLqrSMACFramework.so.1.0.1 /usr/local/lib/libLqrSMACInterfaces.so.1.0.1"

for builddir in SMACidl SMACFramework EventManager EventManager/TestClient PayloadManager PayloadManager/TestClient
do
	echo "*"
	echo "*"
	
	if [ -z "$buildopt" ]; then
		echo "*** Building $builddir ***"
	else
		echo "*** Building $builddir ($buildopt) ***"
	fi
	
	echo "*"
	start_dir=`pwd`

	cd ../$builddir
	make \
CC="$CC" \
IDLOUT="$IDLOUT" \
LIBINSTALL="$LIBINSTALL" \
LINK="$LINK" \
OMNIDIR="$OMNIDIR" \
SMACFRM="$SMACFRM" \
CFLAGS0="$CFLAGS0" \
CFLAGS1="$CFLAGS1" \
LFLAGS0="$LFLAGS0" \
LFLAGS1="$LFLAGS1" \
LFLAGS2="$LFLAGS2" \
$buildopt
	exit_code="$?"
	
	cd "$start_dir"
	
	if [ "$exit_code" -ne 0 ]; then
		echo "*"
		echo "*"
		echo "*"
		echo "error: make exited with code $exit_code"
		exit $exit_code
	fi
done

exit
