#!/bin/bash

#
# Tool for updating list of .in file for the SALOME project 
# and regenerating configure script
#
# Author : 
# Modified by : Alexander BORODIN (OCN) - autotools usage
# Date : 10/10/2002


ORIG_DIR=`pwd`
CONF_DIR=`echo $0 | sed -e "s,[^/]*$,,;s,/$,,;s,^$,.,"`

########################################################################
# Test if the KERNEL_ROOT_DIR is set correctly

if test ! -d "${KERNEL_ROOT_DIR}"; then
    echo "failed : KERNEL_ROOT_DIR variable is not correct !"
    exit
fi

HXX2SALOME_GENERIC_CLASS_NAME_WITH_GUI="yes"
for option
do
  case $option in
      -with-ihm | --with-ihm)
          HXX2SALOME_GENERIC_CLASS_NAME_WITH_GUI="yes"
          break;;
      -without-ihm | --without-ihm | -with-ihm=no | --with-ihm=no)
          HXX2SALOME_GENERIC_CLASS_NAME_WITH_GUI="no"
          break;;
  esac
done

########################################################################
# Test if the GUI_ROOT_DIR is set correctly

if test ${HXX2SALOME_GENERIC_CLASS_NAME_WITH_GUI} = yes; then
    if test ! -d "${GUI_ROOT_DIR}"; then
        echo "failed : GUI_ROOT_DIR variable is not correct !"
        exit
    fi
fi

########################################################################

# Update configure.ac script: to set HXX2SALOME_GENERIC_CLASS_NAME_WITH_GUI 
sed -e s/HXX2SALOME_GENERIC_CLASS_NAME_WITH_GUI=[a-z]*/HXX2SALOME_GENERIC_CLASS_NAME_WITH_GUI=${HXX2SALOME_GENERIC_CLASS_NAME_WITH_GUI}/g configure.ac > configure.tmp
mv configure.tmp configure.ac


# Test if the MED_ROOT_DIR is set correctly

if test ! -d "${MED_ROOT_DIR}"; then
    echo "failed : MED_ROOT_DIR variable is not correct !"
    exit
fi

cd ${CONF_DIR}
ABS_CONF_DIR=`pwd`

mkdir -p salome_adm/unix/config_files
cp -f ${KERNEL_ROOT_DIR}/salome_adm/unix/SALOMEconfig.h.in salome_adm/unix

# ____________________________________________________________________
# aclocal creates the aclocal.m4 file from the standard macro and the
# custom macro embedded in the directory salome_adm/unix/config_files
# and KERNEL config_files directory.
# output:
#   aclocal.m4
#   autom4te.cache (directory)
echo "====================================================== aclocal"

aclocal -I adm_local/unix/config_files \
        -I ${KERNEL_ROOT_DIR}/salome_adm/unix/config_files \
	-I ${GUI_ROOT_DIR}/adm_local/unix/config_files \
	-I ${MED_ROOT_DIR}/adm_local/unix/config_files   || exit 1

# ____________________________________________________________________
# libtoolize creates some configuration files (ltmain.sh,
# config.guess and config.sub). It only depends on the libtool
# version. The files are created in the directory specified with the
# AC_CONFIG_AUX_DIR(<mydir>) tag (see configure.ac).
# output:
#   salome_adm/unix/config_files/config.guess
#   salome_adm/unix/config_files/config.sub
#   salome_adm/unix/config_files/ltmain.sh
#echo "====================================================== libtoolize"

libtoolize --force --copy --automake || exit 1

# ____________________________________________________________________
# autoconf creates the configure script from the file configure.ac (or
# configure.in if configure.ac doesn't exist)
# output:
#   configure
echo "====================================================== autoconf"

autoconf

# ____________________________________________________________________
# automake creates some scripts used in building process
# (install-sh, missing, ...). It only depends on the automake
# version. The files are created in the directory specified with the
# AC_CONFIG_AUX_DIR(<mydir>) tag (see configure.ac). This step also
# creates the Makefile.in files from the Makefile.am files.
# output:
#   salome_adm/unix/config_files/compile
#   salome_adm/unix/config_files/depcomp
#   salome_adm/unix/config_files/install-sh
#   salome_adm/unix/config_files/missing
#   salome_adm/unix/config_files/py-compile
#   Makefile.in (from Makefile.am)
echo "====================================================== automake"

automake --copy --gnu --add-missing
