#! /bin/sh

# The following settings are determined by the configure script.

C_COMPILER="cc"
C_PREPROC="cc -E"

FLAGS_OBJ="-O2 -pipe   -Wno-unused -Wno-write-strings -O1 -fno-math-errno -fschedule-insns2 -fno-trapping-math -fno-strict-aliasing -fwrapv -fomit-frame-pointer -fPIC -fno-common -mieee-fp "
FLAGS_DYN=" -O2 -pipe   -Wno-unused -Wno-write-strings -O1 -fno-math-errno -fschedule-insns2 -fno-trapping-math -fno-strict-aliasing -fwrapv -fomit-frame-pointer -fPIC -fno-common -mieee-fp   -rdynamic -shared"
FLAGS_LIB=" -O2 -pipe    -rdynamic -shared -Wl,-soname,\$(LIBRARY)"
FLAGS_EXE=" -O2 -pipe   -Wno-unused -Wno-write-strings -O1 -fno-math-errno -fschedule-insns2 -fno-trapping-math -fno-strict-aliasing -fwrapv -fomit-frame-pointer -fPIC -fno-common -mieee-fp   -rdynamic"

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

BUILD_OBJ="\${C_COMPILER} \${FLAGS_OBJ} \${DEFS_OBJ} -I\"\${GAMBCDIR_INCLUDE}\" -c -o \"\${BUILD_OBJ_OUTPUT_FILENAME}\" \${BUILD_OBJ_CC_OPTIONS} \${BUILD_OBJ_INPUT_FILENAMES}"
BUILD_DYN="\${C_COMPILER} \${FLAGS_DYN} \${DEFS_DYN} -I\"\${GAMBCDIR_INCLUDE}\" -o \"\${BUILD_DYN_OUTPUT_FILENAME}\" \${BUILD_DYN_CC_OPTIONS} \${BUILD_DYN_LD_OPTIONS_PRELUDE} \${BUILD_DYN_INPUT_FILENAMES} \${BUILD_DYN_LD_OPTIONS}"
BUILD_LIB="echo BUILD_LIB not yet implemented"
BUILD_EXE="\${C_COMPILER} \${FLAGS_EXE} \${DEFS_EXE} -I\"\${GAMBCDIR_INCLUDE}\"  -o \"\${BUILD_EXE_OUTPUT_FILENAME}\" \${BUILD_EXE_CC_OPTIONS} \${BUILD_EXE_LD_OPTIONS_PRELUDE} \${BUILD_EXE_INPUT_FILENAMES} \"\${GAMBCDIR_LIB}/libgambc.so\" \${LIBS} \${BUILD_EXE_LD_OPTIONS}"

DEFS=""
LIBS="-lutil -lm "
GAMBCLIB="gambc"
GAMBCGSCLIB="gambcgsc"
GAMBCGSILIB="gambcgsi"
LIB_PREFIX="lib"
LIB_EXTENSION=".so"
OBJ_EXTENSION=".o"
EXE_EXTENSION=""
BAT_EXTENSION=""

case "$1" in

  "obj")

    if test "${GAMBC_CC_VERBOSE}" != ""; then
      echo "${C_COMPILER} ${FLAGS_OBJ} ${DEFS_OBJ} -I\"${GAMBCDIR_INCLUDE}\" -c -o \"${BUILD_OBJ_OUTPUT_FILENAME}\" ${BUILD_OBJ_CC_OPTIONS} ${BUILD_OBJ_INPUT_FILENAMES}"
    fi

    ${C_COMPILER} ${FLAGS_OBJ} ${DEFS_OBJ} -I"${GAMBCDIR_INCLUDE}" -c -o "${BUILD_OBJ_OUTPUT_FILENAME}" ${BUILD_OBJ_CC_OPTIONS} ${BUILD_OBJ_INPUT_FILENAMES}
    ;;

  "dyn")

    if test "${GAMBC_CC_VERBOSE}" != ""; then
      echo "${C_COMPILER} ${FLAGS_DYN} ${DEFS_DYN} -I\"${GAMBCDIR_INCLUDE}\" -o \"${BUILD_DYN_OUTPUT_FILENAME}\" ${BUILD_DYN_CC_OPTIONS} ${BUILD_DYN_LD_OPTIONS_PRELUDE} ${BUILD_DYN_INPUT_FILENAMES} ${BUILD_DYN_LD_OPTIONS}"
    fi

    ${C_COMPILER} ${FLAGS_DYN} ${DEFS_DYN} -I"${GAMBCDIR_INCLUDE}" -o "${BUILD_DYN_OUTPUT_FILENAME}" ${BUILD_DYN_CC_OPTIONS} ${BUILD_DYN_LD_OPTIONS_PRELUDE} ${BUILD_DYN_INPUT_FILENAMES} ${BUILD_DYN_LD_OPTIONS}
    ;;

  "lib")

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

    echo BUILD_LIB not yet implemented
    ;;

  "exe")

    if test "${GAMBC_CC_VERBOSE}" != ""; then
      echo "${C_COMPILER} ${FLAGS_EXE} ${DEFS_EXE} -I\"${GAMBCDIR_INCLUDE}\"  -o \"${BUILD_EXE_OUTPUT_FILENAME}\" ${BUILD_EXE_CC_OPTIONS} ${BUILD_EXE_LD_OPTIONS_PRELUDE} ${BUILD_EXE_INPUT_FILENAMES} \"${GAMBCDIR_LIB}/libgambc.so\" ${LIBS} ${BUILD_EXE_LD_OPTIONS}"
    fi

    ${C_COMPILER} ${FLAGS_EXE} ${DEFS_EXE} -I"${GAMBCDIR_INCLUDE}"  -o "${BUILD_EXE_OUTPUT_FILENAME}" ${BUILD_EXE_CC_OPTIONS} ${BUILD_EXE_LD_OPTIONS_PRELUDE} ${BUILD_EXE_INPUT_FILENAMES} "${GAMBCDIR_LIB}/libgambc.so" ${LIBS} ${BUILD_EXE_LD_OPTIONS}
    ;;

  "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}"
    ;;

  "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}"
    ;;

  "GAMBCLIB")
    echo "${GAMBCLIB}"
    ;;

  "GAMBCGSCLIB")
    echo "${GAMBCGSCLIB}"
    ;;

  "GAMBCGSILIB")
    echo "${GAMBCGSILIB}"
    ;;

  "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 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 GAMBCLIB=`echo "${GAMBCLIB}" | ${ESC_SH}`
    echo GAMBCGSCLIB=`echo "${GAMBCGSCLIB}" | ${ESC_SH}`
    echo GAMBCGSILIB=`echo "${GAMBCGSILIB}" | ${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 "gambc-cc unknown operation \"$1\""
    exit 1
    ;;

esac
