#! /bin/sh

# The following settings are determined by the configure script.

C_COMPILER="gcc"
C_PREPROC="gcc -E"

FLAGS_OBJ="-march=pentium4 -mtune=generic -O2 -pipe -fno-plt -fexceptions         -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security         -fstack-clash-protection  -g -ffile-prefix-map=/build/gambit-c/src=/usr/src/debug/gambit-c   -Wno-unused -Wno-write-strings -Wdisabled-optimization -fwrapv -fno-strict-aliasing -fno-trapping-math -fno-math-errno -fschedule-insns2 -foptimize-sibling-calls -fmodulo-sched -freschedule-modulo-scheduled-loops -fomit-frame-pointer -fPIC -fno-common -mpc64 "
FLAGS_DYN="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -march=pentium4 -mtune=generic -O2 -pipe -fno-plt -fexceptions         -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security         -fstack-clash-protection  -g -ffile-prefix-map=/build/gambit-c/src=/usr/src/debug/gambit-c   -Wno-unused -Wno-write-strings -Wdisabled-optimization -fwrapv -fno-strict-aliasing -fno-trapping-math -fno-math-errno -fschedule-insns2 -foptimize-sibling-calls -fmodulo-sched -freschedule-modulo-scheduled-loops -fomit-frame-pointer -fPIC -fno-common -mpc64   -rdynamic -shared"
FLAGS_LIB="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -march=pentium4 -mtune=generic -O2 -pipe -fno-plt -fexceptions         -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security         -fstack-clash-protection  -g -ffile-prefix-map=/build/gambit-c/src=/usr/src/debug/gambit-c    -rdynamic -shared"
FLAGS_EXE="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -march=pentium4 -mtune=generic -O2 -pipe -fno-plt -fexceptions         -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security         -fstack-clash-protection  -g -ffile-prefix-map=/build/gambit-c/src=/usr/src/debug/gambit-c   -Wno-unused -Wno-write-strings -Wdisabled-optimization -fwrapv -fno-strict-aliasing -fno-trapping-math -fno-math-errno -fschedule-insns2 -foptimize-sibling-calls -fmodulo-sched -freschedule-modulo-scheduled-loops -fomit-frame-pointer -fPIC -fno-common -mpc64   -rdynamic"

FLAGS_OPT=" -O1"
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.a\" \${LIBS} \${BUILD_EXE_LD_OPTIONS_PARAM}"

DEFS=""
LIBS="-lm "
GAMBITLIB="gambit"
GAMBITGSCLIB="gambitgsc"
GAMBITGSILIB="gambitgsi"
LIB_PREFIX="lib"
LIB_EXTENSION=".a"
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.a\" ${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.a" ${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
