#! /bin/sh

# The following settings are determined by the configure script.

C_COMPILER="c++"
C_PREPROC="c++ -E"

FLAGS_OBJ="-O2 -I/usr/include   -Wno-unused -Wno-write-strings -Wdisabled-optimization -fwrapv -fno-strict-aliasing -fno-trapping-math -fno-math-errno -fschedule-insns2 -fmodulo-sched -freschedule-modulo-scheduled-loops -fomit-frame-pointer -fipa-ra -fmove-loop-invariants -fPIC -fno-common "
FLAGS_DYN="-L/usr/lib -Wl,-R/usr/lib -Wl,-R/usr/pkg/lib -O2 -I/usr/include   -Wno-unused -Wno-write-strings -Wdisabled-optimization -fwrapv -fno-strict-aliasing -fno-trapping-math -fno-math-errno -fschedule-insns2 -fmodulo-sched -freschedule-modulo-scheduled-loops -fomit-frame-pointer -fipa-ra -fmove-loop-invariants -fPIC -fno-common   -rdynamic -shared"
FLAGS_LIB="-L/usr/lib -Wl,-R/usr/lib -Wl,-R/usr/pkg/lib -O2 -I/usr/include    -rdynamic -shared -Wl,-soname,\$(LIBRARY)\$(LIB_MAJOR_VERSION_SUFFIX)"
FLAGS_EXE="-L/usr/lib -Wl,-R/usr/lib -Wl,-R/usr/pkg/lib -O2 -I/usr/include   -Wno-unused -Wno-write-strings -Wdisabled-optimization -fwrapv -fno-strict-aliasing -fno-trapping-math -fno-math-errno -fschedule-insns2 -fmodulo-sched -freschedule-modulo-scheduled-loops -fomit-frame-pointer -fipa-ra -fmove-loop-invariants -fPIC -fno-common    -Wno-unused -Wno-write-strings -Wdisabled-optimization -fwrapv -fno-strict-aliasing -fno-trapping-math -fno-math-errno -fschedule-insns2 -fmodulo-sched -freschedule-modulo-scheduled-loops -fomit-frame-pointer -fipa-ra -fmove-loop-invariants -fPIC -fno-common   -rdynamic"

FLAGS_OPT=" -O1 -fexpensive-optimizations -fno-gcse"
FLAGS_OPT_RTS=" -O3"

DEFS_OBJ=" -D___SINGLE_HOST "
DEFS_DYN=" -D___SINGLE_HOST -D___DYNAMIC"
DEFS_LIB=" -D___SINGLE_HOST "
DEFS_EXE=" -D___SINGLE_HOST "

BUILD_OBJ="\${C_COMPILER} \${FLAGS_OPT} \${FLAGS_OBJ} \${DEFS_OBJ} -I\"\${GAMBITDIR_INCLUDE}\" -c -o \${BUILD_OBJ_OUTPUT_FILENAME_PARAM} \${BUILD_OBJ_CC_OPTIONS_PARAM} \${BUILD_OBJ_INPUT_FILENAMES_PARAM}"
BUILD_DYN="\${C_COMPILER} \${FLAGS_OPT} \${FLAGS_DYN} \${DEFS_DYN} -I\"\${GAMBITDIR_INCLUDE}\" -o \${BUILD_DYN_OUTPUT_FILENAME_PARAM} \${BUILD_DYN_CC_OPTIONS_PARAM} \${BUILD_DYN_LD_OPTIONS_PRELUDE_PARAM} \${BUILD_DYN_INPUT_FILENAMES_PARAM} \${BUILD_DYN_LD_OPTIONS_PARAM}"
BUILD_LIB="echo BUILD_LIB not yet implemented"
BUILD_EXE="\${C_COMPILER} \${FLAGS_EXE} \${DEFS_EXE} -I\"\${GAMBITDIR_INCLUDE}\"  -o \${BUILD_EXE_OUTPUT_FILENAME_PARAM} \${BUILD_EXE_CC_OPTIONS_PARAM} \${BUILD_EXE_LD_OPTIONS_PRELUDE_PARAM} \${BUILD_EXE_INPUT_FILENAMES_PARAM} \"\${GAMBITDIR_LIB}/libgambit.so\" \${LIBS} \${BUILD_EXE_LD_OPTIONS_PARAM}"

DEFS=""
LIBS="-lutil "
GAMBITLIB="gambit"
GAMBITGSCLIB="gambitgsc"
GAMBITGSILIB="gambitgsi"
LIB_PREFIX="lib"
LIB_EXTENSION=".so"
OBJ_EXTENSION=".o"
EXE_EXTENSION=""
BAT_EXTENSION=""

case "$1" in

  "obj")

    if test "${GAMBUILD_VERBOSE}" != ""; then
      echo "${C_COMPILER} ${FLAGS_OPT} ${FLAGS_OBJ} ${DEFS_OBJ} -I\"${GAMBITDIR_INCLUDE}\" -c -o ${BUILD_OBJ_OUTPUT_FILENAME_PARAM} ${BUILD_OBJ_CC_OPTIONS_PARAM} ${BUILD_OBJ_INPUT_FILENAMES_PARAM}"
    fi

    ${C_COMPILER} ${FLAGS_OPT} ${FLAGS_OBJ} ${DEFS_OBJ} -I"${GAMBITDIR_INCLUDE}" -c -o ${BUILD_OBJ_OUTPUT_FILENAME_PARAM} ${BUILD_OBJ_CC_OPTIONS_PARAM} ${BUILD_OBJ_INPUT_FILENAMES_PARAM}
    ;;

  "dyn")

    if test "${GAMBUILD_VERBOSE}" != ""; then
      echo "${C_COMPILER} ${FLAGS_OPT} ${FLAGS_DYN} ${DEFS_DYN} -I\"${GAMBITDIR_INCLUDE}\" -o ${BUILD_DYN_OUTPUT_FILENAME_PARAM} ${BUILD_DYN_CC_OPTIONS_PARAM} ${BUILD_DYN_LD_OPTIONS_PRELUDE_PARAM} ${BUILD_DYN_INPUT_FILENAMES_PARAM} ${BUILD_DYN_LD_OPTIONS_PARAM}"
    fi

    ${C_COMPILER} ${FLAGS_OPT} ${FLAGS_DYN} ${DEFS_DYN} -I"${GAMBITDIR_INCLUDE}" -o ${BUILD_DYN_OUTPUT_FILENAME_PARAM} ${BUILD_DYN_CC_OPTIONS_PARAM} ${BUILD_DYN_LD_OPTIONS_PRELUDE_PARAM} ${BUILD_DYN_INPUT_FILENAMES_PARAM} ${BUILD_DYN_LD_OPTIONS_PARAM}
    ;;

  "lib")

    if test "${GAMBUILD_VERBOSE}" != ""; then
      echo "echo BUILD_LIB not yet implemented"
    fi

    echo BUILD_LIB not yet implemented
    ;;

  "exe")

    if test "${GAMBUILD_VERBOSE}" != ""; then
      echo "${C_COMPILER} ${FLAGS_EXE} ${DEFS_EXE} -I\"${GAMBITDIR_INCLUDE}\"  -o ${BUILD_EXE_OUTPUT_FILENAME_PARAM} ${BUILD_EXE_CC_OPTIONS_PARAM} ${BUILD_EXE_LD_OPTIONS_PRELUDE_PARAM} ${BUILD_EXE_INPUT_FILENAMES_PARAM} \"${GAMBITDIR_LIB}/libgambit.so\" ${LIBS} ${BUILD_EXE_LD_OPTIONS_PARAM}"
    fi

    ${C_COMPILER} ${FLAGS_EXE} ${DEFS_EXE} -I"${GAMBITDIR_INCLUDE}"  -o ${BUILD_EXE_OUTPUT_FILENAME_PARAM} ${BUILD_EXE_CC_OPTIONS_PARAM} ${BUILD_EXE_LD_OPTIONS_PRELUDE_PARAM} ${BUILD_EXE_INPUT_FILENAMES_PARAM} "${GAMBITDIR_LIB}/libgambit.so" ${LIBS} ${BUILD_EXE_LD_OPTIONS_PARAM}
    ;;

  "C_COMPILER")
    echo "${C_COMPILER}"
    ;;

  "C_PREPROC")
    echo "${C_PREPROC}"
    ;;

  "FLAGS_OBJ")
    echo "${FLAGS_OBJ}"
    ;;

  "FLAGS_DYN")
    echo "${FLAGS_DYN}"
    ;;

  "FLAGS_LIB")
    echo "${FLAGS_LIB}"
    ;;

  "FLAGS_EXE")
    echo "${FLAGS_EXE}"
    ;;

  "FLAGS_OPT")
    echo "${FLAGS_OPT}"
    ;;

  "FLAGS_OPT_RTS")
    echo "${FLAGS_OPT_RTS}"
    ;;

  "DEFS_OBJ")
    echo "${DEFS_OBJ}"
    ;;

  "DEFS_DYN")
    echo "${DEFS_DYN}"
    ;;

  "DEFS_LIB")
    echo "${DEFS_LIB}"
    ;;

  "DEFS_EXE")
    echo "${DEFS_EXE}"
    ;;

  "BUILD_OBJ")
    echo "${BUILD_OBJ}"
    ;;

  "BUILD_DYN")
    echo "${BUILD_DYN}"
    ;;

  "BUILD_LIB")
    echo "${BUILD_LIB}"
    ;;

  "BUILD_EXE")
    echo "${BUILD_EXE}"
    ;;

  "DEFS")
    echo "${DEFS}"
    ;;

  "LIBS")
    echo "${LIBS}"
    ;;

  "GAMBITLIB")
    echo "${GAMBITLIB}"
    ;;

  "GAMBITGSCLIB")
    echo "${GAMBITGSCLIB}"
    ;;

  "GAMBITGSILIB")
    echo "${GAMBITGSILIB}"
    ;;

  "LIB_PREFIX")
    echo "${LIB_PREFIX}"
    ;;

  "LIB_EXTENSION")
    echo "${LIB_EXTENSION}"
    ;;

  "OBJ_EXTENSION")
    echo "${OBJ_EXTENSION}"
    ;;

  "EXE_EXTENSION")
    echo "${EXE_EXTENSION}"
    ;;

  "BAT_EXTENSION")
    echo "${BAT_EXTENSION}"
    ;;

  "")
    # Dump configure script settings

    ESC_SH="sed -e s/\\\\/\\\\\\\\\\\\\\\\/g -e s/\\\"/\\\\\\\"/g -e s/\\\$/\\\\\\\$/g -e s/^/\"/ -e s/$/\"/"

    echo C_COMPILER=`echo "${C_COMPILER}" | ${ESC_SH}`
    echo C_PREPROC=`echo "${C_PREPROC}" | ${ESC_SH}`

    echo FLAGS_OBJ=`echo "${FLAGS_OBJ}" | ${ESC_SH}`
    echo FLAGS_DYN=`echo "${FLAGS_DYN}" | ${ESC_SH}`
    echo FLAGS_LIB=`echo "${FLAGS_LIB}" | ${ESC_SH}`
    echo FLAGS_EXE=`echo "${FLAGS_EXE}" | ${ESC_SH}`

    echo FLAGS_OPT=`echo "${FLAGS_OPT}" | ${ESC_SH}`
    echo FLAGS_OPT_RTS=`echo "${FLAGS_OPT_RTS}" | ${ESC_SH}`

    echo DEFS_OBJ=`echo "${DEFS_OBJ}" | ${ESC_SH}`
    echo DEFS_DYN=`echo "${DEFS_DYN}" | ${ESC_SH}`
    echo DEFS_LIB=`echo "${DEFS_LIB}" | ${ESC_SH}`
    echo DEFS_EXE=`echo "${DEFS_EXE}" | ${ESC_SH}`

    echo BUILD_OBJ=`echo "${BUILD_OBJ}" | ${ESC_SH}`
    echo BUILD_DYN=`echo "${BUILD_DYN}" | ${ESC_SH}`
    echo BUILD_LIB=`echo "${BUILD_LIB}" | ${ESC_SH}`
    echo BUILD_EXE=`echo "${BUILD_EXE}" | ${ESC_SH}`

    echo DEFS=`echo "${DEFS}" | ${ESC_SH}`
    echo LIBS=`echo "${LIBS}" | ${ESC_SH}`
    echo GAMBITLIB=`echo "${GAMBITLIB}" | ${ESC_SH}`
    echo GAMBITGSCLIB=`echo "${GAMBITGSCLIB}" | ${ESC_SH}`
    echo GAMBITGSILIB=`echo "${GAMBITGSILIB}" | ${ESC_SH}`
    echo LIB_PREFIX=`echo "${LIB_PREFIX}" | ${ESC_SH}`
    echo LIB_EXTENSION=`echo "${LIB_EXTENSION}" | ${ESC_SH}`
    echo OBJ_EXTENSION=`echo "${OBJ_EXTENSION}" | ${ESC_SH}`
    echo EXE_EXTENSION=`echo "${EXE_EXTENSION}" | ${ESC_SH}`
    echo BAT_EXTENSION=`echo "${BAT_EXTENSION}" | ${ESC_SH}`
    ;;

  *)
    echo "gambuild-C unknown operation \"$1\""
    exit 1
    ;;

esac
