#!/bin/sh
# Time-stamp: <06/01/24 21:32:31 ptr>

configmak=../Makefiles/config.mak

# rm -f ${configmak}

# echo "# STLPORT_DIR := /export/home/windows/guest/STLlab/STLport" >> ${configmak}
# echo "# TARGET_PROC=x86" >> ${configmak}

write_option() {
  target=`echo $1 | sed -e 's/^[^=]*=//'`
  echo $2 := $target >> ${configmak}
}

print_help() {
  cat <<EOF
Configuration utility.

Usage:

  configure [options]

Available options:

  --target=<target>     Target platform (cross-compiling)

  --help                Print this help message and exit

  --with-stlport=<dir>  use STLport in catalog <dir>

  --with-mwcw=<dir>     Metrowerks CodeWarrior compiler catalog (useful for mw* compilers)
                        i.e. something like "c:/Program Files/Metrowerks/CodeWarrior"

  --with-nwsdk=<dir>    Use Novell NDK/SDK from this catalog (useful for *-*-netware target)
                        i.e. something like "c:/Novell/ndk/nwsdk"

  --no-cygwin           Specific cygwin distribution option. Use it to build STLport using
                        the cygwin tools but without dependency on the cygwin1.dll

  --with-extra-cxxflags=<options>
                        Pass extra options to C++ compiler

  --not-thread-safe     Per default STLport libraries are built in order to be usable in a multithreaded
                        context. If you don't need this you can ask for a not thread safe version with
                        this option.

  --with-boost=<dir>    Request use of boost support (www.boost.org). For the moment only the boost
                        type_traits library is used to get type information and to implement some
                        specific workaround not directly implemented by STLport. To use the same
                        support using STLport don't forget to define _STLP_USE_BOOST_SUPPORT in
                        stlport/stl/config/user_config.h file.

  --with-lib-motif=<motif>
                        Use this option to customize the generated library name. The motif will be used
                        in the last place before version information, separated by an underscore, ex:
                        stlportd_MOTIF.5.0.lib
                        stlportstld_static_MOTIF.5.1.lib

  --use-static-gcc      use static gcc libs instead of shared libgcc_s (useful for gcc compiler,
                        that was builded with --enable-shared [default]; if compiler was builded
                        with --disable-shared, static libraries will be used in any case)

  --clean               remove custom settings (file ${configmak})
                        and use default values

EOF
}

case $# in
  0)
    exit 0
    ;;
esac

case $1 in
  --help)
    print_help
    exit 0
    ;;
esac

rm -f ${configmak}

while :
do
  case $# in
    0)
      break
      ;;
  esac
  option=$1
  shift
  case $option in
    --clean)
      rm -f ${configmak}
      echo Configuration file removed.
      ;; 
    --target=*)
      write_option "$option" TARGET_OS
      ;;
    --with-stlport=*)
      write_option "$option" STLPORT_DIR
      ;;
    --with-extra-cxxflags=*)
      write_option "$option" EXTRA_CXXFLAGS
      ;;
    --with-nwsdk=*)
      write_option "$option" NWSDK_DIR
      ;;
    --with-mwcw=*)
      write_option "$option" MWCW_BASE
      ;;
    --no-cygwin)
      write_option "-mno-cygwin" OPT
      write_option -D_STLP_NO_CYGWIN DEFS
      echo "--no-cygwin: Don't forget to uncomment _STLP_NO_CYGWIN macro"
      echo "in stlport/stl/config/host.h to use such a configuration."
      ;;
    --not-thread-safe)
      write_option 1 STLP_BUILD_NO_THREAD
      ;;
    --with-boost=*)
      echo "Don't forget to define _STLP_USE_BOOST_SUPPORT in stlport/stl/config/user_config.h file"
      write_option "$option" STLP_BUILD_BOOST_PATH
      ;;
    --with-lib-motif=*)
      echo "Using $option in generated library names"
      write_option "$option" STLP_BUILD_LIB_MOTIF
      ;;
    --use-static-gcc)
      write_option "$option" USE_STATIC_LIBGCC
      ;;
  esac
done

