ICL_PC=icl-7.8.0-debug

if [ ! "$1" ] ; then
    echo "$1 is the compilation target e.g. test for compiling test.cpp" ;
    exit -1 ;
fi

if [ "$1" = "--help" ] ; then
    echo "icl-make applies the following command:" ;
    echo 'g++ $CXXFLAGS $(pkg-config --cflags ${ICL_PC}) -I. -o ARG_1 ARG_1.[cpp|cc|cxx] $LDFLAGS $(pkg-config --libs ${ICL_PC})' ;
    exit 0 ;
fi

if [ "`pkg-config --exists ${ICL_PC} && echo yes || echo no`" == "no" ] ; then
    echo "${ICL_PC}.pc could not be found in your PKG_CONFIG_PATH" ;
    exit -1 ;
fi

SRC=
if [ -e $1.cpp ] ; then
   SRC=$1.cpp ;
elif [ -e $1.cxx ] ; then
   SRC=$1.cxx ;
elif [ -e $1.cc ] ; then
   SRC=$1.cc ;
else
   echo unable to find source file $1.cpp or $1.cxx or $1.cc
   exit -1;
fi

LDFLAGS="$LDFLAGS $(pkg-config --libs ${ICL_PC} | sed 's|-Wl,-rpath\\|-Wl,-rpath|g')"
CXXFLAGS="$CXXFLAGS $(pkg-config --cflags ${ICL_PC}) -I."
g++ $CXXFLAGS -o $1 $SRC $LDFLAGS