#
# config.site - this file is run by configure automatically
#               to set default values of environment variables

# Simple paths.

test "$prefix" = NONE && prefix=/usr
test "$mandir" = '${prefix}/man' && mandir='${prefix}/share/man' # Should this use ${datadir}?
test "$sysconfdir" = '${prefix}/etc' && sysconfdir='/etc'
test "$localstatedir" = '${prefix}/var' && localstatedir='/var'
SITE_INTERNAL_DEFAULTED=

# Force on linker, compiler and preprocessor flags that must never be
# turned off. Extra work is caused by autoconf's refusal to provide large file
# support switches if the user specifies any at all :(

# Permit an environment variable (NO_LARGEFILE) to be defined to ban the use
# of large file support (if it is broken for specific projects, say).

CPPFLAGS="$CPPFLAGS -D__NO_STRING_INLINES"
MANDATORY_CFLAGS="-D__NO_STRING_INLINES"
test "x$LDFLAGS" = "x" && \
    LDFLAGS="-s" && \
    SITE_INTERNAL_DEFAULTED="$SITE_INTERNAL_DEFAULTED LDFLAGS"

if [[ "x$NO_LARGEFILE" = "x" ]]; then
    test "x$LDFLAGS" = "x-s" && \
        LDFLAGS="$(echo "$LDFLAGS `getconf LFS_LDFLAGS` `getconf LFS64_LDFLAGS`" | sed 's/  / /g')"
    CPPFLAGS="$(echo "$CPPFLAGS `getconf LFS_CFLAGS` `getconf LFS64_CFLAGS`" | sed 's/  / /g')"
    MANDATORY_CFLAGS="$(echo "$MANDATORY_CFLAGS `getconf LFS_CFLAGS` `getconf LFS64_CFLAGS`" | sed 's/  / /g')"
    LIBS="$(echo "$LIBS `getconf LFS_LIBS` `getconf LFS64_LIBS`" | sed 's/  / /g')"
fi

MANDATORY_CXXFLAGS="$MANDATORY_CFLAGS"

# Default NONE in $build $host and $target appropriately

[[ "x$build" = "xNONE" ]] && build="$host"
[[ "x$target" = "xNONE" ]] && target="$host"
[[ "x$host" = "xNONE" ]] && host="$build"

[[ "x$host" = "xNONE" ]] && host="`config.guess`" && target="$host" && build="$target"

# This only makes sense if the build and host arches are the same.
if [[ "$build" = "$host" ]]; then

 # esperi has very little RAM; always optimize for size there.

 if [[ "$(hostname)" = "esperi" ]]; then
  SITE_INTERNAL_OPTFLAGS=-Os
 else
  SITE_INTERNAL_OPTFLAGS=-O2
 fi

 arch=`uname -m`
 test "x$CC" = "x" && CC=gcc && SITE_INTERNAL_DEFAULTED="$SITE_INTERNAL_DEFAULTED CC"

 # GCC-2.95 and 3.0, and the old egcs fork, have more flags than the older GCCs;
 # specifically, they support -march, -mcpu, and -Os.

 if [ "x`$CC --version`" = "x3.0" -o "x`$CC --version`" = "x2.95.3" -o "x`$CC --version`" = "x2.95.4" -o "x`$CC --version`" = "x2.95.2" -o `$CC --version | cut -d- -f1` = egcs ]; then
  case $arch in
   i?86) mflags="-march=$arch";;
   sparc*) mflags="-mcpu=v8 -mtune=v9 -Wa,-Av9a -m32";;
   *) mflags=""
  esac

  test "x$ASFLAGS" = "x" && ASFLAGS="$mflags -pipe" && SITE_INTERNAL_DEFAULTED="$SITE_INTERNAL_DEFAULTED ASFLAGS"

  test "x$CFLAGS" = "x" && CFLAGS="$SITE_INTERNAL_OPTFLAGS -fomit-frame-pointer $mflags -pipe" && \
      SITE_INTERNAL_DEFAULTED="$SITE_INTERNAL_DEFAULTED CFLAGS"
  test "x$GCJFLAGS" = "x" && GCJFLAGS="$SITE_INTERNAL_OPTFLAGS -fomit-frame-pointer $mflags -pipe" && \
      SITE_INTERNAL_DEFAULTED="$SITE_INTERNAL_DEFAULTED GCJFLAGS"
  test "x$FFLAGS" = "x" && FFLAGS="$SITE_INTERNAL_OPTFLAGS -fomit-frame-pointer $mflags -pipe" && \
      SITE_INTERNAL_DEFAULTED="$SITE_INTERNAL_DEFAULTED FFLAGS"
  if [ "x`$CC --version`" = "x3.0" -o "x`$CC --version`" = "x2.95.3" -o "x`$CC --version`" = "x2.95.4" -o "x`$CC --version`" = "x2.95.2" ]; then
   test "x$CXXFLAGS" = "x" && CXXFLAGS="$SITE_INTERNAL_OPTFLAGS -fomit-frame-pointer -fpermissive $mflags -pipe" && \
       SITE_INTERNAL_DEFAULTED="$SITE_INTERNAL_DEFAULTED CXXFLAGS_2_95"
  else
   test "x$CXXFLAGS" = "x" && CXXFLAGS="$SITE_INTERNAL_OPTFLAGS -fomit-frame-pointer $mflags -pipe" && \
       SITE_INTERNAL_DEFAULTED="$SITE_INTERNAL_DEFAULTED CXXFLAGS_old"
  fi
 else                                          # antique gcc; no GCJ at all
  test "x$CFLAGS" = "x" && CFLAGS="-O2 -fomit-frame-pointer -pipe" && \
      SITE_INTERNAL_DEFAULTED="$SITE_INTERNAL_DEFAULTED CFLAGS_ancient"
  FFLAGS="$CFLAGS"
  CXXFLAGS="$CXXFLAGS"
  SITE_INTERNAL_DEFAULTED="$SITE_INTERNAL_DEFAULTED FFLAGS_ancient CXXFLAGS_ancient"
 fi

 test "x$OBJCFLAGS" = "x" && OBJCFLAGS="$CFLAGS" && SITE_INTERNAL_DEFAULTED="$SITE_INTERNAL_DEFAULTED OBJCFLAGS"
 unset SITE_INTERNAL_OPTFLAGS
fi

CFLAGS="$CFLAGS $MANDATORY_CFLAGS"
CXXFLAGS="$CXXFLAGS $MANDATORY_CXXFLAGS"
unset MANDATORY_CFLAGS

if [[ -n "$SITE_INTERNAL_DEFAULTED" ]]; then
    /bin/echo -n 'site-config script adjustments...'
    for stuff in $SITE_INTERNAL_DEFAULTED; do
        case $stuff in
            CC) /bin/echo -n ' (GCC compiler)';;
            ASFLAGS) /bin/echo -n ' (assembler flags)';;
            CFLAGS) /bin/echo -n ' (C compiler flags)';;
            FFLAGS) /bin/echo -n ' (Fortran compiler flags)';;
            CXXFLAGS_2_95) /bin/echo -n ' (G++>=2.95 compiler flags)';;
            GCJFLAGS) /bin/echo -n ' (Java compiler flags)';;
            CXXFLAGS_old) /bin/echo -n ' (G++>2.7.x compiler flags)';;
            CFLAGS_ancient) /bin/echo -n ' (ancient C compiler flags)';;
            FFLAGS_ancient) /bin/echo -n ' (ancient Fortran compiler flags)';;
            CXXFLAGS_ancient) /bin/echo -n ' (ancient C++ compiler flags)';;
            OBJCFLAGS) /bin/echo -n ' (Objective C compiler flags)';;
            LDFLAGS) /bin/echo -n ' (linker flags)';;
            *) /bin/echo -n ' (unknown word in message request stream)';;
        esac
    done
    /bin/echo
fi

unset SITE_INTERNAL_DEFAULTED
unset arch
unset mflags