#! /bin/sh

usage='echo "Usage: ccp4_build [--help] [--libdir=DIR]" '

if ( eval test -d cctbx_build || eval mkdir cctbx_build ) ; then :
else
  eval echo "! No directory cctbx_build and can\'t create it."
  exit 1
fi

cctbxopts="--command_version_suffix=ccp4-6.0 --build=release"
for arg
do

    case $arg in

    -help | --help | -h | help)
      eval $usage; exit 0;;

    -libdir=* | --libdir=* | --libdi=* | --libd=* | --lib=* | --li=* | --l=*)
      libdir=`echo $arg | sed 's/[-a-z_]*=//'` ; break;;

    # all other arguments passed to cctbx build
    *)
      cctbxopts="$cctbxopts $arg" ;;

    esac

done

if ( eval test -z \"\$CCP4\" ) ; then
  echo "! Please set CCP4 environment, e.g. source ccp4.setup "
  exit 1
else true; fi

libdir=${libdir:-$CCP4_LIB}

echo "Changing directory to cctbx_build"
cd cctbx_build

echo "Running libtbx/configure.py"
python ../cctbx_sources/libtbx/configure.py $cctbxopts ccp4io=${CCP4} mmtbx

echo "Running setpaths.sh"
. ./setpaths.sh

echo "Building cctbx"
libtbx.scons .

# sunos 32 vs 64
# use of sunos compilers
# installation ??

