#!/bin/sh -f

#
# File produced by the obuild tool version 1.0
# for the package snova with version v2r0p1.
#

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

#obuild_args="$*"

obuild_verbose=no
obuild_debug=no
obuild_set_x=no
obuild_erase_dir_bin=no
obuild_do_mains=yes
obuild_group=main

obuild_args=""
while test $# -ge 1 ; do
  case $1 in
    -h) 
        echo "Usage :"
        echo "  UNIX> sh/build [Options] [Target]"
        echo "Options :"
        echo "  -v : verbose."
        echo "  -g : build in debug mode."
        echo "  -i : install setup scripts."
        echo "  -bci : broadacst install setup scripts."
        echo "  -e : erase binary directory."
        echo "  -x : execute with set -x."
        echo "  -l : link only, do not (re)compile."
        echo "  -k : do not erase result of compilations (.o, .obj)."
        echo "  -nm : build the not-main components."
        echo "  -group group : build the given group of components."
        echo "Target :"
        echo "  If no option is specify and a ending"
        echo " string is given ; this string is given"
        echo " to a find command of the form :"
        echo '    find ./sh -name "*target*" -exec {} \;'
        echo " in order to execute selected scripts under"
        echo " the sh directory."
        echo "Examples :"
        echo "  UNIX> sh/build app"
        echo "  UNIX> sh/build -v _lib"
        echo "  UNIX> sh/build -v -g dll_"
        echo ""
        exit ;;
    -v) obuild_verbose=yes;obuild_args="${obuild_args} $1" ;;
    -g) obuild_debug=yes;obuild_args="${obuild_args} $1" ;;
    -i) ./sh/install; exit ;;
    -bci) if [ ! -e ./sh/broadcast_install ] ; then 
            echo "Nothing to do for this package." 
            exit
          fi
          ./sh/broadcast_install ${obuild_args}
          exit ;;
    -x) obuild_set_x=yes;obuild_args="${obuild_args} $1" ;;
    -l) obuild_args="${obuild_args} $1" ;;
    -k) obuild_args="${obuild_args} $1" ;;
    -e) obuild_erase_dir_bin=yes ;;
    -nm) obuild_do_mains=no ;;
    -group) shift
        if [ $# != 0 ] ; then
          obuild_group=$1 
        else         
          echo "give a group name after the -group option."
          exit 
        fi ;;
    -*) echo "unknwon option : $1" ; exit ;;
     *) if [ $# = 1 ] ; then
          find ./sh -name "*$1*" -exec {} ${obuild_args} \;
        else         
          echo "unknwon option : $1"
        fi
        exit ;;
  esac
  shift
done

if [ ${obuild_set_x} = yes ] ; then
  set -x
fi

if [ ${obuild_erase_dir_bin} = "yes" ] ; then
  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_snova_path=`dirname "${obuild_pwd}"`
  unset obuild_pwd
  /bin/rm -R -f "${obuild_snova_path}/${obuild_dir_bin}"
  exit  
fi

if [ "${obuild_group}" = main ] ; then
if [ "${obuild_do_mains}" = yes ] ; then
  if [ -e ./sh/build_lib_geomutils ] ; then
    ./sh/build_lib_geomutils ${obuild_args}
    obuild_status=$?;if [ ${obuild_status} != 0 ] ; then exit ${obuild_status};fi
  fi
fi
fi
if [ "${obuild_group}" = main ] ; then
if [ "${obuild_do_mains}" = yes ] ; then
  if [ -e ./sh/build_lib_sngeom ] ; then
    ./sh/build_lib_sngeom ${obuild_args}
    obuild_status=$?;if [ ${obuild_status} != 0 ] ; then exit ${obuild_status};fi
  fi
fi
fi
if [ "${obuild_group}" = main ] ; then
if [ "${obuild_do_mains}" = yes ] ; then
  if [ -e ./sh/build_lib_snvertex ] ; then
    ./sh/build_lib_snvertex ${obuild_args}
    obuild_status=$?;if [ ${obuild_status} != 0 ] ; then exit ${obuild_status};fi
  fi
fi
fi
if [ "${obuild_group}" = main ] ; then
if [ "${obuild_do_mains}" = yes ] ; then
  if [ -e ./sh/build_lib_snova ] ; then
    ./sh/build_lib_snova ${obuild_args}
    obuild_status=$?;if [ ${obuild_status} != 0 ] ; then exit ${obuild_status};fi
  fi
fi
fi

if [ "${obuild_group}" = main ] ; then
if [ "${obuild_do_mains}" = yes ] ; then
  if [ -e ./sh/build_app_prog_snova ] ; then
    ./sh/build_app_prog_snova ${obuild_args}
    obuild_status=$?;if [ ${obuild_status} != 0 ] ; then exit ${obuild_status};fi
  fi
fi
fi

if [ -e ./sh/install ] ; then
  ./sh/install
fi

