#                                                   -*- shell-script -*-
#
# This file is part of the HDF4 build script. It is processed shortly
# after configure starts and defines, among other things, flags for
# the various compilation modes.

# Choosing C, Fortran, and C++ Compilers
# --------------------------------------
#
# The user should be able to specify the compiler by setting the CC, F77,
# and CXX environment variables to the name of the compiler and any
# switches it requires for proper operation. If CC is unset then this
# script may set it. If CC is unset by time this script completes then
# configure will try `gcc' and `cc' in that order (perhaps some others
# too).
#
# Note: Code later in this file may depend on the value of $CC_BASENAME
#       in order to distinguish between different compilers when
#       deciding which compiler command-line switches to use.  This
#       variable is set based on the incoming value of $CC and is only
#       used within this file.

# Use clang as the default C compiler.
if test "X-$CC" = "X-"; then
    CC=clang
    CC_BASENAME=clang
fi

# Use gfortran as the deafult F77 compiler.
if test "X-$F77" = "X-"; then
  F77=gfortran
  F77_BASENAME=gfortran
fi

case $CC_BASENAME in
  clang)
    CFLAGS="$CFLAGS"
    DEBUG_CFLAGS="-g -ansi -Wall -pedantic "
    DEBUG_CPPFLAGS=
    # There is a bug somewhere in mfhdf/libsrc that is exposed by compiling
    # with any optimization in $CC in Lion (Darwin 11) & up
    # Use -O0 for now.
    case "$host_os" in
	darwin1[1-9].*)	# Lion & Mountain Lion & Mavericks & Yosemeti
	    xOFLAG="-O0"
	    ;;
	*)		# Other OSX versions
	    xOFLAG="-O2"
	    ;;
    esac
    PROD_CFLAGS=${PROD_CFLAGS:-"$xOFLAG"}
    PROD_CPPFLAGS=
    PROFILE_CFLAGS="-pg"
    PROFILE_CPPFLAGS=
    ;;

  icc)
    CFLAGS="$CFLAGS"
    DEBUG_CFLAGS="-g"
    DEBUG_CPPFLAGS=
    # There is a bug somewhere in mfhdf/libsrc that is exposed by compiling
    # with any optimization in $CC in Lion, Mountain Lion, Mavericks and Yosemeti systems.
    # Use -O0 for now.
    case "$host_os" in
	darwin1[1-9].*)	# Lion & Mountain Lion & Mavericks & Yosemite & 5 more
	    xOFLAG="-O0"
	    ;;
	*)		# Other OSX versions
	    xOFLAG="-O2"
	    ;;
    esac
    PROD_CFLAGS=${PROD_CFLAGS:-"$xOFLAG"}
    PROD_CPPFLAGS=
    PROFILE_CFLAGS="-pg"
    PROFILE_CPPFLAGS=
    ;;

  gcc)
    CFLAGS="$CFLAGS"
    DEBUG_CFLAGS="-g -ansi -Wall -pedantic "
    DEBUG_CPPFLAGS=
    # There is a bug somewhere in mfhdf/libsrc that is exposed by compiling
    # with any optimization in $CC in Lion, Mountain Lion, Mavericks and Yosemeti systems.
    # Use -O0 for now.
    case "$host_os" in
	darwin1[1-9].*)	# Lion & Mountain Lion & Mavericks & Yosemeti & 5 more
	    xOFLAG="-O0"
	    ;;
	*)		# Other OSX versions
	    xOFLAG="-O2"
	    ;;
    esac
    PROD_CFLAGS=${PROD_CFLAGS:-"-ansi  -Wall -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wmissing-prototypes -Wnested-externs -pedantic $xOFLAG"}
    PROD_CFLAGS=${PROD_CFLAGS:-"-ansi  -Wall -pedantic $xOFLAG"}
    PROD_CPPFLAGS=
    PROFILE_CFLAGS="-pg"
    PROFILE_CPPFLAGS=
    ;;

  *)
    CFLAGS="$CFLAGS"
    DEBUG_CFLAGS="-g"
    DEBUG_CPPFLAGS=
    PROD_CFLAGS=${PROD_CFLAGS:-"-O"}
    PROD_CPPFLAGS=
    PROFILE_CFLAGS="-pg"
    PROFILE_CPPFLAGS=
    ;;
esac

case $F77_BASENAME in 
  gfortran)
    FFLAGS="$FFLAGS"
    DEBUG_FFLAGS="-g"
    PROD_FFLAGS="-O"
    PROFILE_FFLAGS="-pg"
    ;;
esac

