#!/bin/sh -f

#
# File produced by the obuild tool version 1.0
# for the package bhep with version v1r4p2.
#

#////////////////////////////////////////////////
# Usage :
#   UNIX> cd some_path/pack/version/obuild
# ( UNIX> chmod a+x sh/check_foreigns )
#   UNIX> sh/check_foreigns
#
#////////////////////////////////////////////////

# Binary directory is needed to create the obuild_plaform program.

if [  "${OBUILD_PLATFORM}" = "" ] ; then
  obuild_platform=`uname`
else
  obuild_platform=${OBUILD_PLATFORM}
fi

if [ "${obuild_platform}" = "" ] ; then
  echo "obuild_platform variable not defined."
  exit
fi

if [  "${OBUILD_DIR_BIN}" = "" ] ; then
  obuild_dir_bin=${obuild_platform}_obuild
else
  obuild_dir_bin=${OBUILD_DIR_BIN}
fi

if [ "${obuild_dir_bin}" = "" ] ; then
  echo "obuild_dir_bin variable not defined."
  exit
fi

obuild_pwd=`pwd`
obuild_bhep_path=`dirname "${obuild_pwd}"`
unset obuild_pwd

# Create the bin directory :
/bin/mkdir -p "${obuild_bhep_path}/${obuild_dir_bin}"

obuild_check_what=$1
if [ "${obuild_check_what}" = "" ] ; then
  echo "check_foreigns : no argument given"
  exit 1
fi

if [ ! -e "${obuild_bhep_path}/${obuild_dir_bin}/obuild_platform" ] ; then
  if [ ! -e "${obuild_bhep_path}/obuild/cpp/obuild_platform.cpp" ] ; then
    echo "Program source obuild_platform.cpp not found."
    exit
  fi
  if [ "${obuild_cxx_command}" = "" ] ; then 
    if [  "${OBUILD_CXX}" != "" ] ; then
      obuild_platform_compiler=${OBUILD_CXX}
    else
      obuild_platform_compiler=c++ 
    fi
  else
    obuild_platform_compiler=${obuild_cxx_command} 
  fi
  ${obuild_platform_compiler} -o "${obuild_bhep_path}/${obuild_dir_bin}/obuild_platform" "${obuild_bhep_path}/obuild/cpp/obuild_platform.cpp"
  unset obuild_platform_compiler
  if [ ! -e "${obuild_bhep_path}/${obuild_dir_bin}/obuild_platform" ] ; then
    echo "Program obuild_platform not found."
    exit
  fi
fi
obuild_platform_exe="${obuild_bhep_path}/${obuild_dir_bin}/obuild_platform"
if [ "${obuild_platform_exe}" = "" ] ; then
  echo "Variable obuild_platform_exe not defined."
  exit
fi
obuild_platform_result=`"${obuild_platform_exe}" ${obuild_platform} 'UNIX'`
if [ ${obuild_platform_result} = yes ] ; then
CLHEP_home="/usr/local/CLHEP/2.0.3.1"
fi
unset obuild_platform_result
if [ "${obuild_platform_exe}" = "" ] ; then
  echo "Variable obuild_platform_exe not defined."
  exit
fi
obuild_platform_result=`"${obuild_platform_exe}" ${obuild_platform} 'UNIX'`
if [ ${obuild_platform_result} = yes ] ; then
if [ "${obuild_check_what}" = "CLHEP" ] ; then
  if [ ! -d "${CLHEP_home}" ] ; then
    echo "WARNING : CLHEP not found under ${CLHEP_home}"
    exit 1
  fi
fi
fi
unset obuild_platform_result

