#                                                   -*- 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 and Fortran Compilers
# --------------------------------------
#
# The user should be able to specify the compiler by setting the CC
# and F77 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.

if test "X-$CC" = "X-"; then
  CC=gcc
  CC_BASENAME=gcc
fi
#Make IBM xlf compiler a default
if test "X-$F77" = "X-"; then
  F77=xlf
  F77_BASENAME=xlf

else
    case $F77 in
        # The PGI and Intel compilers are automatically detected below
        xlf*|f95*)
            ;;

        *)
            # Figure out which compiler we are using: pgf90 or Absoft f95
            RM='rm -f'
            tmpfile=/tmp/cmpver.$$
            $F77 -V >$tmpfile
            if test -s "$tmpfile"; then
            #Absoft compiler f95 doesn't recognize -V flag; we will use
            #the error message it produces to identify the compiler
            #    if( grep -s 'Absoft' $tmpfile > /dev/null) then
                if( grep -s 'ERROR: No input files' $tmpfile > /dev/null) then
                    F77_BASENAME=f95
                fi
                if( grep -s 'IBM XL' $tmpfile > /dev/null) then
                    F77_BASENAME=xlf
                fi
            fi
            $RM $tmpfile
            ;;
    esac
fi


# C and Fortran Compiler and Preprocessor Flags
# ---------------------------------------------------
#
# - Flags that end with `_CFLAGS' are always passed to the C compiler.
# - Flags that end with `_FFLAGS' are always passed to the Fortran
#   compiler.
# - Flags that end with `_CPPFLAGS' are passed to the C compiler
#   when compiling but not when linking.
#
#   DEBUG_CFLAGS
#   DEBUG_FFLAGS
#   DEBUG_CPPFLAGS  - Flags to pass to the compiler to create a
#                     library suitable for use with debugging
#                      tools. Usually this list will exclude
#                     optimization switches (like `-O') and include
#                     switches that turn on symbolic debugging support
#                     (like `-g').
#
#   PROD_CFLAGS
#   PROD_FFLAGS
#   PROD_CPPFLAGS   - Flags to pass to the compiler to create a
#                     production version of the library. These
#                     usually exclude symbolic debugging switches (like
#                     `-g') and include optimization switches (like
#                     `-O').
#
#   PROFILE_CFLAGS
#   PROFILE_FFLAGS
#   PROFILE_CPPFLAGS- Flags to pass to the compiler to create a
#                     library suitable for performance testing (like
#                     `-pg').  This may or may not include debugging or
#                     production flags.
#
#   FFLAGS
#   CFLAGS          - Flags can be added to these variable which
#                     might already be partially initialized. These
#                     flags will always be passed to the compiler and
#                     should include switches to turn on full warnings.
#
#                     WARNING: flags do not have to be added to the CFLAGS
#                     or FFLAGS variable if the compiler is the GNU gcc
#                     and g77 compiler.
#
#                     FFLAGS and CFLAGS should contain *something* or else
#                     configure will probably add `-g'. For most systems
#                     this isn't a problem but some systems will disable
#                     optimizations in favor of the `-g'. The configure
#                     script will remove the `-g' flag in production mode
#                     only.
#
# These flags should be set according to the compiler being used.
# There are two ways to check the compiler. You can try using `-v' or
# `--version' to see if the compiler will print a version string.  You
# can use the value of $FOO_BASENAME which is the base name of the
# first word in $FOO, where FOO is either CC or F77 (note that the
# value of CC may have changed above).

case $CC_BASENAME in
  gcc)
    if test $cc_vers_major -ge 10; then
        CFLAGS="$CFLAGS -Wno-error=implicit-function-declaration"
    else
        CFLAGS="$CFLAGS"
    fi
    DEBUG_CFLAGS="-g -ansi -Wall -pedantic "
    DEBUG_CPPFLAGS=
    PROD_CFLAGS="-ansi -Wall -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wmissing-prototypes -Wnested-externs -pedantic -O2"
    PROD_CPPFLAGS=
    PROFILE_CFLAGS="-pg"
    PROFILE_CPPFLAGS=
    ;;

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

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

  f95)
    #
    # Assume Absoft compiler
    #
    # Set a flag for compiling C stubs
    CFLAGS="$CFLAGS -DH4_ABSOFT"
    FFLAGS="$FFLAGS -YEXT_NAMES=UCS"
    DEBUG_FFLAGS="-g"
    PROD_FFLAGS="-O"
    PROFILE_FFLAGS="-pg"
    ;;
esac


# Overriding Configure Tests
# --------------------------
#
# Values for overriding configuration tests when cross compiling.

# Set this to `yes' or `no' depending on whether the target is big
# endian or little endian.
#ac_cv_c_bigendian=${ac_cv_c_bigendian='yes'}
