# Copyright (C) 2010 Swedish Institute of Computer Science.
# NOTE!! do not detabbify this buffer
# NOTE!! do not reindent (beware of indenting EOF markers)
#
# Configure-script source-code for SICStus
# Original author: Jesper Eskilson <jojo@sics.se>
#
#
# *** Process this file with autoconf to produce a configure script. ***
#

dnl [PM] 4.0 Useful emacs trick to so that M-s can find various hard to see syntax errors:
dnl (setq regexp-search-ring (cons X regexp-search-ring))
dnl where X is one of:
dnl "^[^{}\n]*\\({[^{}\n]*}\\)*[^{}\n]*{[^{}\n]*\\({[^{}\n]*}\\)*[^{}\n]*$" % mismatched '{'
dnl "^[^{}\n]*\\({[^{}\n]*}\\)*[^{}\n]*}[^{}\n]*\\({[^{}\n]*}\\)*[^{}\n]*$" % mismatched '}'
dnl "^[^'\n]*\\('[^'\n]*'\\)*[^'\n]*'[^'\n]*$"                              % mismatched '
dnl "^[^\"\n]*\\(\"[^\"\n]*\"\\)*[^\"\n]*\"[^\"\n]*$"                       % mismatched "
dnl
dnl other useful tricks for hunting syntax errors:
dnl bash -n ./configure ...  # only syntax checks, much faster
dnl bash -v ./configure      # show script lines as they are read

dnl "$[^\"\n]*\\(\"[^\"\n]*\"\\)*\"[^\"\n]*\\(\"[^\"\n]*\"\\)*" "[^;] then" "^[^\"\n]*\"[^\"\n]*$" "$[^\"]*\"[^\"]*" "if[^;\n]*then" "if[^;]*then" "if[^;]then" "\\${.*%"))

AC_INIT(configure.in)

AC_PREREQ(2.61)

dnl ============================================================
dnl ============================================================


# [PM] 3.9b5 (PRM 2956) For binary installations the install time
# platform (e.g. x86-linux-glibc2.2) may differ from the platform used
# to build the binary installer (e.g. x86-linux-glibc2.1).
#
# When the platform name is used as part of the directory structure
# (e.g., library/<PLATFORM>) the build-time $PLATFORM should be used
# (as is done by InstallSICStus, spld, splfr). However, the $PLATFORM
# during installation by configure (this file) will be the install
# time PLATFORM which will be used to substitute any occurrences of
# @PLATFORM@. Currently we can ignore this mismatch since nothing uses
# @PLATFORM@ at install time (except to set 
# INSTALL_PLATFORM in distrib.in, spld.config.in).
# InstallSICStus will warn if $INSTALL_PLATFORM differs from $BUILD_PLATFORM.


# [PM] 3.8.5 Someone should document the meaning
# of $host vs. $PLATFORM in this configure script
# I suspect that only one should be used, I cannot see a pattern for
# whether $host and $PLATFORM is used in this file
# [PM] 3.8.5 used to set host but need --host for sparc64
real_host=`./sp_platform`
# [PD] 3.8.5: make sure $PLATFORM is not affected by the change above
PLATFORM=$real_host
# [PM] 3.8.5 If --host not specified use sp_platform
# [PM] autoconf 2.13 sets host to NONE even if AC_CANONICAL_HOST is not used
(test "x$host" = xNONE || test "x$host" = x ) && host=$real_host


dnl ============================================================
dnl ============================================================
dnl [PM] 3.10 Starting port to 64bit AIX 5L 5.1 suggests general 64bit
dnl option instead of, e.g., --with-solaris64
dnl
dnl [PM] 3.11.3 FIXME: introduce platform_defaults_64bit=yes for all default-64bit platforms?
platform_defaults_64bit=no
AC_MSG_NOTICE([The original platform is $PLATFORM])
case $PLATFORM in
   *-solaris-*)
      platform_supports_64bit=yes
   ;;
   rs6000-aix-*)
      platform_supports_64bit=yes
   ;;
   ipf*-hpux-*)
      platform_supports_64bit=yes
   ;;
   x86_64-linux-*)
      platform_supports_64bit=yes
      platform_defaults_64bit=yes
   ;;
   i386-darwin-9.*)
      platform_supports_64bit=yes
   ;;
   # [PM] 4.2.3 assume that any newer Darwin defaults 64-bit (Darwin 12 is Mac OS X 10.8)
   i*86-darwin-*)
   # i*86-darwin-10.*|i*86-darwin-11.*)
      platform_defaults_64bit=yes
      platform_supports_64bit=yes      
   ;;
dnl    i386-darwin-*)
dnl       platform_supports_64bit=yes
dnl dnl ============================================================
dnl dnl src-begin
dnl dnl ============================================================
dnl     AC_MSG_ERROR([Unknown Darwin platform ($PLATFORM)])
dnl dnl ============================================================
dnl dnl src-end
dnl dnl ============================================================
dnl    ;;
   powerpc64-linux-*|powerpc6432-linux-*)
      dnl [PM] 3.12.1+ NOTE: IBM Red-Hat on 64bit Power does NOT default to 64-bit executables
      platform_supports_64bit=yes
   ;;
   *win32*)
      platform_supports_64bit=yes
   ;;
   *)
      platform_supports_64bit=no
   ;;
esac

AC_ARG_ENABLE(64bit,  [  --enable-64bit            64bit support],
	[enable_64bit=$enableval],
        [enable_64bit=${platform_defaults_64bit}]
        )
case "$enable_64bit" in
  yes|no)
    dnl nothing
  ;;
  *)
    AC_MSG_ERROR([Illegal --enable-64bit value])
  ;;
esac

if test "$platform_supports_64bit" = no; then
  if test "$enable_64bit" = yes; then
    AC_MSG_ERROR([64bit builds is not supported on this platform])
  fi
fi

if test $platform_supports_64bit = yes; then

AC_MSG_CHECKING([whether 64bit is enabled])
AC_MSG_RESULT([$enable_64bit])

dnl [PM] 3.10 put "64" after the processor part if 64bit-mode.
dnl NOTE: Should usually not be done for platforms where 64bit is the default (or only) option (e.g., Tru64).
if test "${enable_64bit}" = "yes"; then
   case "${host}" in
   x86_64-linux-*)
     dnl [PM] 3.11.3
     dnl do nothing, we use x86_64 for the 64bit platform
     ;;
   i386-darwin-*)
     dnl [PM] 4.0 Use x86_64 (instead of i38664) for alignment with Apple convention
     [host64=`echo "$host" | sed -n -e  's/^i386-/x86_64-/p'`]
     if test -z "$host64"; then
       AC_MSG_ERROR([Could not create 64bit equivialent name for host ($host)])
     fi
     host="$host64"
     ;;
   i386-solaris-*)
     dnl [PM] 4.0 Use amd64 (instead of i38664) for alignment with Sun convention
     [host64=`echo "$host" | sed -n -e  's/^i386-/amd64-/p'`]
     if test -z "$host64"; then
       AC_MSG_ERROR([Could not create 64bit equivialent name for host ($host)])
     fi
     host="$host64"
     ;;
   ia64-*-*)
     dnl [PM] 3.10.2
     AC_MSG_ERROR([Need to re-work the 64bit hostname for ia64 (or change processor name to ipf)])
     ;;
   powerpc6432-linux-*)
     dnl [PM] 3.12.1+
     [host64=`echo "$host" | sed -n -e  's/^powerpc6432\(-.*-.*\)$/powerpc64\1/p'`] # akk
     if test -z "$host64"; then
       AC_MSG_ERROR([Could not create 64bit equivialent name for host ($host)])
     fi
     host="$host64"
     ;;
   x86-win32-nt-4)
     host="x86_64-win32-nt-4"
     ;;
   *64-*-*)
     dnl Nothing, 64bit name was set explicitly by user
     AC_MSG_WARN([host should no longer be used with 64bit, use --enable-64bit instead.])
     ;;
   *-*-*)
     [host64=`echo "$host" | sed -n -e  's/^\([^-]*\)\(-.*-.*\)$/\164\2/p'`]
     if test -z "$host64"; then
       AC_MSG_ERROR([Could not create 64bit equivialent name for host ($host)])
     fi
     host="$host64"
     ;;
   *)
     AC_MSG_ERROR([Malformed host type ($host)])
     ;;
   esac
else dnl ! --enable-64bit
   case "${host}" in
   x86_64-linux-*)
     dnl [PM] 3.11.3 Use plain x86-linux-... for 32bit builds on x86_64
     [host32=`echo "$host" | sed -n -e  's/^x86_64/x86/p'`]
     if test -z "$host32"; then
       AC_MSG_ERROR([Could not create 32bit equivialent name for host ($host)])
     fi
     host="$host32"
     ;;
   ia64-*-*)
     dnl [PM] 3.10.2
     AC_MSG_ERROR([Need to re-work the 64bit hostname for ia64 (or change processor name to ipf)])
     ;;
   ipf-*-*)
     dnl [PM] 3.10.2 for IPF (HP ia64) we use ipf64 and ipf32 and never plain 'ipf'
     [host32=`echo "$host" | sed -n -e  's/^\([^-]*\)\(-.*-.*\)$/\132\2/p'`]
     if test -z "$host32"; then
       AC_MSG_ERROR([Could not create 32bit equivialent name for host ($host)])
     fi
     host="$host32"
     ;;
   *-*-*)
     :
     ;;
   *)
     AC_MSG_ERROR([Malformed host type ($host)])
     ;;
   esac
fi

if test $enable_64bit = yes; then
   case "$PLATFORM" in
   x86_64-linux-*)
     dnl [PM] 3.11.3
     dnl do nothing, we use x86_64 for the 64bit platform
     ;;
   i386-darwin-*)
     dnl [PM] 4.0 Use x86_64 (instead of i38664) for alignment with Apple convention
     [PLATFORM64=`echo "$PLATFORM" | sed -n -e  's/^i386-/x86_64-/p'`]
     if test -z "$PLATFORM64"; then
       AC_MSG_ERROR([Could not create 64bit equivialent name for PLATFORM ($PLATFORM)])
     fi
     PLATFORM="$PLATFORM64"
     ;;
   i386-solaris-*)
     dnl [PM] 4.0 Use amd64 (instead of i38664) for alignment with Sun convention
     [PLATFORM64=`echo "$PLATFORM" | sed -n -e  's/^i386-/amd64-/p'`]
     if test -z "$PLATFORM64"; then
       AC_MSG_ERROR([Could not create 64bit equivialent name for PLATFORM ($PLATFORM)])
     fi
     PLATFORM="$PLATFORM64"
     ;;
   ia64-*-*)
     dnl [PM] 3.10.2
     AC_MSG_ERROR([Need to re-work the 64bit hostname for ia64 (or change processor name to ipf)])
     ;;
   powerpc6432-linux-*)
     dnl [PM] 3.12.1+
     [PLATFORM64=`echo "$PLATFORM" | sed -n -e  's/^powerpc6432\(-.*-.*\)$/powerpc64\1/p'`] # akk
     if test -z "$PLATFORM64"; then
       AC_MSG_ERROR([Could not create 64bit equivialent name for PLATFORM ($PLATFORM)])
     fi
     PLATFORM="$PLATFORM64"
     ;;
   x86-win32-nt-4)
     PLATFORM="x86_64-win32-nt-4"
     ;;
   *64-*-*)
     dnl Nothing, 64bit name was set explicitly by user
     AC_MSG_WARN([host should no longer be used with 64bit, use --enable-64bit instead.])
     ;;
   *-*-*)
     [PLATFORM64=`echo "$PLATFORM" | sed -n -e  's/^\([^-]*\)\(-.*-.*\)$/\164\2/p'`]
     if test -z "$PLATFORM64"; then
       AC_MSG_ERROR([Could not create 64bit equivialent name for PLATFORM ($PLATFORM)])
     fi
     PLATFORM="$PLATFORM64"
     ;;
   *)
     AC_MSG_ERROR([Malformed PLATFORM type ($PLATFORM)])
     ;;
   esac
else dnl ! --enable-64bit
   case "$PLATFORM" in
   x86_64-linux-*)
     dnl [PM] 3.11.3 Use plain x86-linux-... for 32bit builds on x86_64
     [PLATFORM32=`echo "$PLATFORM" | sed -n -e  's/^x86_64/x86/p'`]
     if test -z "$PLATFORM32"; then
       AC_MSG_ERROR([Could not create 32bit equivialent name for PLATFORM ($PLATFORM)])
     fi
     PLATFORM="$PLATFORM32"
     ;;
   ia64-*-*)
     dnl [PM] 3.10.2
     AC_MSG_ERROR([Need to re-work the 64bit hostname for ia64 (or change processor name to ipf)])
     ;;
   ipf-*-*)
     dnl [PM] 3.10.2 for IPF (HP ia64) we use ipf64 and ipf32 and never plain 'ipf'
     [PLATFORM32=`echo "$PLATFORM" | sed -n -e  's/^\([^-]*\)\(-.*-.*\)$/\132\2/p'`]
     if test -z "$PLATFORM32"; then
       AC_MSG_ERROR([Could not create 32bit equivialent name for PLATFORM ($PLATFORM)])
     fi
     PLATFORM="$PLATFORM32"
     ;;
   *-*-*)
     :
     ;;
   *)
     AC_MSG_ERROR([Malformed PLATFORM type ($PLATFORM)])
     ;;
   esac
fi

fi dnl $platform_supports_64bit = yes; then

AC_MSG_CHECKING([for 32/64 bit specific platform name])
AC_MSG_RESULT([${PLATFORM}])
dnl ============================================================
dnl ============================================================


AC_SUBST(PLATFORM)

dnl [PM] 4.0.3 Mac OS X 10.5.2 Intel seems to work with 2 Cores (iMac)
dnl [PD] 4.0.0 Set number of CPUs to use. Used to disable all but one CPU for
dnl            the test suite in Distrib/Makefile on Mac OS X, since
dnl            library(timeout) doesn't work with multiple CPUs.
dnl
AC_ARG_WITH(number_of_cpus,  [  --with-number-of-cpus          Internal, how many CPUs to use],
	[with_number_of_cpus=$withval],
	[with_number_of_cpus=0])

CPUCOUNTCOMMAND=":"

case $with_number_of_cpus in
  0)
    :
    ;;
  *)
    case $PLATFORM in
      *-darwin-*)
	CPUCOUNTCOMMAND="hwprefs cpu_count=$with_number_of_cpus"
        ;;
      *)
        :
	;;
    esac
esac

AC_SUBST(CPUCOUNTCOMMAND)

# Check if config.cache was made on the same platform. If not, remove it
# and run configure again. Useful is you use the same directory for 
# building on several platforms.
PCACHE=./platform.cache
dnl used as make dependancy
AC_SUBST(PCACHE)
if test -f "${PCACHE}"; then
    AC_MSG_CHECKING([validity of ${PCACHE}])
    # [PM] 3.8.7 platform.cache may contain spaces ("Unknown host type ...")
    if test "x`cat "${PCACHE}"`" != "x${host}"; then
      dnl [PM] 3.12.0 if platform.cache is bogus you definitely need to do a make maintainerclean!
        AC_MSG_RESULT([no, invalid])
        AC_MSG_ERROR([You need to do make maintainerclean and re-configure])
    else
	AC_MSG_RESULT([ok])
    fi
else
    echo "${host}" > "${PCACHE}"
fi

sp_isbindistr=yes

dnl ============================================================
dnl ============================================================

dnl [PM] 4.1.0 AC_EXEEXT and AC_OBJEXT are obsolete no-ops
dnl nowadays. Their function has been incorporated into the compiler
dnl checking macros which we call much later. Instead do our own
dnl version
AC_MSG_CHECKING([for executable and object file extensions])
case $PLATFORM in
     *win32*)
       # Note that exeext is really exe-suffix and includes the period.
       ac_cv_exeext='.exe'
       ac_cv_objext='obj'
     ;;
     *)
       ac_cv_exeext=''
       ac_cv_objext='o'
     ;;
esac
EXEEXT="$ac_cv_exeext"
OBJEXT="$ac_cv_objext"
AC_MSG_RESULT(["$EXEEXT" and ".$OBJEXT"])
dnl AC_EXEEXT()
dnl AC_OBJEXT() 

dnl ============================================================
dnl ============================================================


dnl PREBUILT_INSTALL_ENABLED!=no means this platform can support pre-built binary
dnl   installs.
dnl install_prebuilt means configure is running on behalf of a
dnl   pre-built binary install

if test $sp_isbindistr = yes; then
   AC_MSG_CHECKING([whether this is a pre-built installation])
   install_prebuilt=$PREBUILT_INSTALL_ENABLED
   AC_MSG_RESULT([$install_prebuilt])
else dnl a source build
   install_prebuilt=no
   AC_MSG_CHECKING([whether prebuilt installations are supported])
   AC_MSG_RESULT([$PREBUILT_INSTALL_ENABLED])
fi

dnl ============================================================
dnl ============================================================

# SP_CHECK_ABSOLUTE(VAR)
# -------------------------------
# [PM] 4.2.1 Ensure variable is absolute, if non-empty.
# All variables used with AC_PATH_PROG/AC_PATH_PROGS must be absolute
# (the Autoconf 2.61 docs incorrectly claims that any value makes
# AC_PATH_PROG do nothing)
m4_define([SP_CHECK_ABSOLUTE],
   [{ case "${$1:-/}" in /*) ;; *) AC_MSG_ERROR([$1 ($$1) must be an absolute path]); ;; esac; } ])

dnl [PD] 3.12.1beta1
AC_ARG_VAR([SORT])
SP_CHECK_ABSOLUTE([SORT])
AC_PATH_PROG([SORT],[sort${EXEEXT}],,[/bin:/usr/bin:${PATH}])

AC_ARG_VAR([UNAME])
SP_CHECK_ABSOLUTE([UNAME])
AC_PATH_PROG([UNAME],[uname${EXEEXT}])

# [PM] 4.1 also if !src since we need POSIX_GREP for test suite
AC_MSG_CHECKING([for POSIX compliant grep])
AC_ARG_VAR(POSIX_GREP,[full path to POSIX compliant grep (e.g. GNU grep)])

case "${host}" in
  *solaris*)
    # command is broken on Solaris
    : ${POSIX_GREP:='/usr/xpg4/bin/grep'}
  ;;
  *)
    : ${POSIX_GREP:=`command -p command -p -v grep 2> /dev/null`}
  ;;
esac

if test -n "${POSIX_GREP}"; then
  AC_MSG_RESULT([${POSIX_GREP}])
else

dnl [PM] 3.12.0 used by rbuild.sh
dnl [PM] 4.3 Used by Suite/Makefile so do it also when not SRC build
AC_ARG_VAR(BASH,[])
SP_CHECK_ABSOLUTE([BASH])
AC_PATH_PROG([BASH],[bash$EXEEXT])


dnl [PM] 4.1 this ensures !POSIX_GREP is fatal when building from source
dnl ============================================================
dnl ============================================================
  dnl [PM] 4.1 will only come here if !src so fall back and just warn
  AC_MSG_WARN([Could not find POSIX compliant grep, falling back to PATH lookup])
  SP_CHECK_ABSOLUTE([POSIX_GREP])
  AC_PATH_PROG([POSIX_GREP],[grep$EXEEXT])
fi

# [PM] 4.2 Check for POSIX shell (not clear whether this is really needed when !src)
AC_MSG_CHECKING([for POSIX compliant shell])
AC_ARG_VAR(POSIX_SHELL,[full path to POSIX compliant shell (e.g. bash or /bin/sh)])

case "${host}" in
  *solaris*)
    # command is broken on Solaris
    : ${POSIX_SHELL:='/usr/xpg4/bin/sh'}
  ;;
  *)
    if test -z "${POSIX_SHELL}"; then
       if posix_shell=`command -p command -p -v sh` 2>/dev/null; then
           : ${POSIX_SHELL:="${posix_shell}"}
       fi
    fi
  ;;
esac

if test -n "${POSIX_SHELL}"; then
  AC_MSG_RESULT([${POSIX_SHELL}])
else

dnl [PM] 4.2 this ensures !POSIX_SHELL is fatal when building from source
dnl ============================================================
dnl ============================================================
  dnl [PM] 4.2 will only come here if !src so fall back and just warn
  AC_MSG_WARN([Could not find POSIX compliant shell, falling back to PATH lookup])
  SP_CHECK_ABSOLUTE([POSIX_SHELL])
  AC_PATH_PROG([POSIX_SHELL],[sh$EXEEXT])
fi

if test "x${prefix}" = "xNONE"; then
   prefix=/usr/local
fi

if test "x${exec_prefix}" = "xNONE"; then
   exec_prefix=$prefix
fi

dnl [PM] 3.8.5 These should be the only four variables where the version is specified
dnl [PM] 3.9 Note: these are called SICSTUS_XX_VERSION everywhere except in this file (huh?)
SICSTUS_MAJOR_VERSION=4
SICSTUS_MINOR_VERSION=3
SICSTUS_REVISION_VERSION=0
dnl [PM] 3.8.5,3.9 set this to zero when going final. Otherwise, e.g., 1
SICSTUS_BETA_VERSION=0

dnl [PM] 3.11.3 SICSTUS_MICRO_VERSION is to ensure version numbers are
dnl increasing also when going from beta to final. The hack is to
dnl treat the final version as beta 1000. SICSTUS_MICRO_VERSION is
dnl indended for file versions on Windows etc. Introduced for Win32
dnl Wix installer.
if test "$SICSTUS_BETA_VERSION" = "0"; then
   SICSTUS_MICRO_VERSION=1000
else
   SICSTUS_MICRO_VERSION=${SICSTUS_BETA_VERSION}
fi
SICSTUS_BUILD_VERSION="${SICSTUS_MAJOR_VERSION}.${SICSTUS_MINOR_VERSION}.${SICSTUS_REVISION_VERSION}.${SICSTUS_MICRO_VERSION}"

# [PM] DBGFLAG should be set for binary distributions as well. (overwritten if src build)
DBGFLAG=yes
# [PM] 3.9.1 OPTFLAG should be set for binary distributions as well. (overwritten if src build)
OPTFLAG=yes


dnl [PM] 4.2.1 This must be done also if not src so that we can build a release with --enable-dbg=1
AC_MSG_CHECKING([debugging])
AC_ARG_ENABLE(dbg,      [  --enable-dbg            Enable debugging. Default on.],
	[DBGFLAG="$enableval"])
AC_MSG_RESULT([${DBGFLAG}])
if test "${DBGFLAG}" != yes; then
    PERSISTENT_CONFIGURE_OPTIONS="${PERSISTENT_CONFIGURE_OPTIONS} --enable-dbg=$DBGFLAG"
fi

dnl [PM] 4.2.1 experiment with removing -DDBG from CFLAGS (so customer
dnl cflags do not need to change when building against a debug built
dnl SP).
SP_NEW_DBG_POLICY_default=yes

AC_MSG_CHECKING([new debug flag policy])
new_policy="${SP_NEW_DBG_POLICY_default}"
AC_ARG_ENABLE(dbg,      [  --enable-new-dbg-policy            internal.],
	[new_policy="$enableval"])

if test "${new_policy:-no}" != no; then
  SP_NEW_DBG_POLICY=yes
  AC_DEFINE([SP_NEW_DBG_POLICY], [1])
else
  SP_NEW_DBG_POLICY=no
fi
AC_MSG_RESULT([${SP_NEW_DBG_POLICY}])
if test "${SP_NEW_DBG_POLICY}" != "${SP_NEW_DBG_POLICY_default}"; then
    PERSISTENT_CONFIGURE_OPTIONS="${PERSISTENT_CONFIGURE_OPTIONS} --enable-new-dbg-policy=${SP_NEW_DBG_POLICY}"
fi

case "${DBGFLAG:-yes}" in
    yes|no)
	DEBUG_BUILD=no
	;;
    *)
        dnl [PM] 4.2 NOTE: You must not set CFLAGS before AC_PROG_CC!
        dnl CFLAGS="$CFLAGS -DDBG=$DBGFLAG"
        AC_DEFINE_UNQUOTED([SICSTUS_DBG],[$DBGFLAG])
	DEBUG_BUILD=yes
	;;
esac
AC_SUBST([DEBUG_BUILD])
AC_SUBST([DBGFLAG])

# [PM] 4.1 we need to set SICSTUS_RELEASE_BUILD also in binary
# installs to enable analyze_bench_speed Suite target.
# AND for SPLD_CONFIG_CFLAGS (SPRM 11482)

if test "${DEBUG_BUILD}" = "yes"; then 
  SICSTUS_RELEASE_BUILD_default="no"
elif test "$SICSTUS_BETA_VERSION" != "0"; then
  SICSTUS_RELEASE_BUILD_default="no"
else
  SICSTUS_RELEASE_BUILD_default="yes"
fi
AC_MSG_CHECKING([whether this is a release build])
AC_ARG_ENABLE(release-build,[  --enable-release-build        For building release candidates. Suppresses assertions etc even if beta.],
    [SICSTUS_RELEASE_BUILD="$enableval"],
    [SICSTUS_RELEASE_BUILD="${SICSTUS_RELEASE_BUILD_default}"])

if test "${SICSTUS_RELEASE_BUILD}" = "yes"; then
  SICSTUS_RELEASE_BUILD="yes"
  AC_DEFINE([SICSTUS_RELEASE_BUILD], [1])
else # !SICSTUS_RELEASE_BUILD
  if test "${SICSTUS_RELEASE_BUILD_default}" != "no"; then
    dnl [PM] 4.3 We do not to build a non-debug non-beta and somehow still have SICSTUS_RELEASE_BUILD false.
    AC_MSG_ERROR([Can not use --disable-release-build])
  fi
  SICSTUS_RELEASE_BUILD="no"
  AC_DEFINE([SICSTUS_RELEASE_BUILD], [0])
fi
AC_MSG_RESULT([${SICSTUS_RELEASE_BUILD}])

AC_SUBST([SICSTUS_RELEASE_BUILD])

dnl ============================================================
dnl ============================================================


AC_DEFINE_UNQUOTED(SICSTUS_MAJOR_VERSION,$SICSTUS_MAJOR_VERSION)
AC_DEFINE_UNQUOTED(SICSTUS_MINOR_VERSION,$SICSTUS_MINOR_VERSION)
AC_DEFINE_UNQUOTED(SICSTUS_REVISION_VERSION,$SICSTUS_REVISION_VERSION)
AC_DEFINE_UNQUOTED(SICSTUS_BETA_VERSION,$SICSTUS_BETA_VERSION)
dnl AC_DEFINE_UNQUOTED(SICSTUS_MICRO_VERSION,$SICSTUS_MICRO_VERSION)

if test "${SICSTUS_BETA_VERSION:-0}" = "0"; then
  SICSTUS_BETA_VERSION_STRING=""
else
  SICSTUS_BETA_VERSION_STRING="beta$SICSTUS_BETA_VERSION"
fi

SICSTUS_VERSION_STRING="$SICSTUS_MAJOR_VERSION.$SICSTUS_MINOR_VERSION.$SICSTUS_REVISION_VERSION$SICSTUS_BETA_VERSION_STRING"
SP_DIRNAME="sicstus-$SICSTUS_VERSION_STRING"
dnl [PM] 3.9.1 SP_RTSYS_DIRNAME will be set to this unless we decide
dnl backward compability is an issue (was "lib" on Solaris 3.9.0 and
dnl Linux 3.9.0 and on all UNIX in 3.8, although 3.8 compatibility is
dnl less of an issue. Was sp39 in Win32 3.9.0)
dnl
dnl Note: We cannot use sprt-$SICSTUS_VERSION_STRING (as documented
dnl in 3.9.1b1) since that coincides with the versioned name of sprt.
dnl
dnl [PM] 3.10.1 Also used in doc/*.texi
SP_RTSYS_DIRNAME_UNIX="sp-$SICSTUS_VERSION_STRING"
dnl [PM] 3.10.1 for doc/ and version.c
dnl [PM] 4.0.0beta1 Now the same as for UNIX
SP_RTSYS_DIRNAME_WIN="${SP_RTSYS_DIRNAME_UNIX}"


AC_MSG_CHECKING([SICStus version])
AC_MSG_RESULT([$SICSTUS_VERSION_STRING])

AC_SUBST(SICSTUS_VERSION_STRING)
AC_DEFINE_UNQUOTED([SICSTUS_VERSION_STRING], ["$SICSTUS_VERSION_STRING"])
# [PM 4.0.5 printf '%.2d%.2d%.2d' is tempting but would become octal if major version is single digit.
SICSTUS_VERSION=`expr '(' '(' '(' "$SICSTUS_MAJOR_VERSION" '*' 100 ')' '+' "$SICSTUS_MINOR_VERSION" ')' '*' 100 ')' '+' "$SICSTUS_REVISION_VERSION"`
AC_DEFINE_UNQUOTED([SICSTUS_VERSION], [ $SICSTUS_VERSION ])
AC_SUBST(SICSTUS_VERSION)
AC_MSG_CHECKING([version specific name for SP_get_dispatch])
SP_GET_DISPATCH_NAME="SP_get_dispatch_${SICSTUS_VERSION}"
AC_DEFINE_UNQUOTED([SP_GET_DISPATCH_NAME], [ $SP_GET_DISPATCH_NAME ])
AC_SUBST(SP_GET_DISPATCH_NAME)
AC_MSG_RESULT([$SP_GET_DISPATCH_NAME])

AC_SUBST(SP_BINDISTR_NAME)
AC_SUBST(SP_DIRNAME)


dnl ============================================================
dnl ============================================================

# [PM] 4.3 SP_AVOID_PREFIX_MINUS_ARGUMENT_BRACKETING must be seen in
# product installs so the test suite does the right thing for iso
# suite.

AC_MSG_CHECKING([whether bracketing should be avoided in the argument to prefix minus])
SP_AVOID_PREFIX_MINUS_ARGUMENT_BRACKETING_default=no
AC_ARG_ENABLE(avoid-prefix-minus-argument-bracketing,  [  --enable-avoid-prefix-minus-argument-bracketing        internal],
	if test "${enableval:-no}" = "yes"; then
	    SP_AVOID_PREFIX_MINUS_ARGUMENT_BRACKETING=yes
	else
	    SP_AVOID_PREFIX_MINUS_ARGUMENT_BRACKETING=no
	fi,
	SP_AVOID_PREFIX_MINUS_ARGUMENT_BRACKETING=${SP_AVOID_PREFIX_MINUS_ARGUMENT_BRACKETING_default})
AC_SUBST([SP_AVOID_PREFIX_MINUS_ARGUMENT_BRACKETING])
AC_MSG_RESULT([$SP_AVOID_PREFIX_MINUS_ARGUMENT_BRACKETING])


# [PM] 4.3 SP_CLAUSE_ISO_BODY must be seen in product installs so the
# test suite does the right thing for iso suite.
AC_MSG_CHECKING([whether clause/2 et al. should hide the non-ISO-compliant rewriting we do])

# [PM] 4.3 Was, in effect, 'no' pre 4.3. Need 'yes' for 13322-1 compliance.
SP_CLAUSE_ISO_BODY_default=yes
AC_ARG_ENABLE(iso-body,  [  --enable-iso-body        internal],
	if test "${enableval:-no}" = "yes"; then
	    SP_CLAUSE_ISO_BODY=yes
	else
	    SP_CLAUSE_ISO_BODY=no
	fi,
	SP_CLAUSE_ISO_BODY=${SP_CLAUSE_ISO_BODY_default})

AC_SUBST([SP_CLAUSE_ISO_BODY])
if test "${SP_CLAUSE_ISO_BODY}" = "yes"; then
  AC_DEFINE([SP_CLAUSE_ISO_BODY],[1])
else
  AC_DEFINE([SP_CLAUSE_ISO_BODY],[0])
fi
if test "${SP_CLAUSE_ISO_BODY}" = "yes"; then
   AC_MSG_RESULT([$SP_CLAUSE_ISO_BODY (ISO 13322-1 compatible)])
else
   AC_MSG_RESULT([$SP_CLAUSE_ISO_BODY (not ISO 13322-1 compatible)])
fi

# [PM] 4.3 SP_CLAUSE_ISO_BODY_NO_META_ARGUMENT_WRAPPING must be seen
# in product installs so the test suite does the right thing for iso
# suite.
if test "${SP_CLAUSE_ISO_BODY}" = "yes"; then
  AC_MSG_CHECKING([whether clause/2 et al. should hide the module wrapping of meta argument done in callers])
  # [PM] 4.3 Was, in effect, 'no' pre 4.3. Need 'yes' for 13322-1 compliance.
  SP_CLAUSE_ISO_BODY_NO_META_ARGUMENT_WRAPPING_default=yes

  AC_ARG_ENABLE(iso-body-hide-meta-wrapping,  [  --enable-iso-body-hide-meta-wrapping        internal],
          if test "${enableval:-no}" = "yes"; then
              SP_CLAUSE_ISO_BODY_NO_META_ARGUMENT_WRAPPING=yes
          else
              SP_CLAUSE_ISO_BODY_NO_META_ARGUMENT_WRAPPING=no
          fi,
          SP_CLAUSE_ISO_BODY_NO_META_ARGUMENT_WRAPPING=${SP_CLAUSE_ISO_BODY_NO_META_ARGUMENT_WRAPPING_default})

  AC_SUBST([SP_CLAUSE_ISO_BODY_NO_META_ARGUMENT_WRAPPING])
  if test "${SP_CLAUSE_ISO_BODY_NO_META_ARGUMENT_WRAPPING}" = "yes"; then
    AC_DEFINE([SP_CLAUSE_ISO_BODY_NO_META_ARGUMENT_WRAPPING],[1])
  else
    AC_DEFINE([SP_CLAUSE_ISO_BODY_NO_META_ARGUMENT_WRAPPING],[0])
  fi
  if test "${SP_CLAUSE_ISO_BODY_NO_META_ARGUMENT_WRAPPING}" = "yes"; then
     AC_MSG_RESULT([$SP_CLAUSE_ISO_BODY_NO_META_ARGUMENT_WRAPPING (ISO 13322-1 compatible)])
  else
     AC_MSG_RESULT([$SP_CLAUSE_ISO_BODY_NO_META_ARGUMENT_WRAPPING (not ISO 13322-1 compatible)])
  fi
fi # SP_CLAUSE_ISO_BODY



dnl ============================================================
dnl ============================================================

dnl [PM] 3.10.2 FIXME: CYGPATH, UNSLASH and a lot of Win32-specific should be src-only

dnl [PM] 3.11.1 Made CYGPATH win32-only, introduced NATIVEPATH make function
dnl AC_CHECK_PROG(CYGPATH,cygpath,cygpath -w,echo)
case $PLATFORM in
       *win32*)
         CYGPATH="cygpath -m" # -m uses forward slash
         CYGPATHBACKSLASH="cygpath -w"

         dnl [PM] 3.11.1 do not use CYGPATH explicitly in make
         dnl files. Instead call NATIVEPATH. See Common.in for usage instructions.
         dnl The use of strip is to remove leading space when $(call
         dnl NATIVEPATH, foo) is used instead of (call NATIVEPATH,foo)
         dnl (the space between the comman and the argument path will
         dnl become part of $(1).

         dnl [PM] 4.0.1 Note: the argument to NATIVEPATH is always a
         dnl _single_ file, use foreach manually if you need to
         dnl transform more than one path.
         dnl
         dnl FIXME: Since CYGPATH now generates paths with forward
         dnl slashes there should be no need for the " | ${UNSLASH}"
         dnl sprinkled throughout this file
         NATIVEPATH='$(shell $(CYGPATH) "$(strip $(1))")'
         NATIVEPATHBACKSLASH='$(shell $(CYGPATHBACKSLASH) "$(strip $(1))")'
       ;;
       *)
         CYGPATH=echo
         CYGPATHBACKSLASH=echo
         NATIVEPATH='$(strip $(1))' 
         NATIVEPATHBACKSLASH='$(strip $(1))'
      ;;
esac
AC_MSG_CHECKING([for CYGPATH])
AC_MSG_RESULT([$CYGPATH])
AC_MSG_CHECKING([for CYGPATHBACKSLASH])
AC_MSG_RESULT([$CYGPATHBACKSLASH])
AC_MSG_CHECKING([for NATIVEPATH])
AC_MSG_RESULT([$NATIVEPATH])
AC_MSG_CHECKING([for NATIVEPATHBACKSLASH])
AC_MSG_RESULT([$NATIVEPATHBACKSLASH])

AC_SUBST(CYGPATH)
AC_SUBST(CYGPATHBACKSLASH)
AC_SUBST(NATIVEPATH)
AC_SUBST(NATIVEPATHBACKSLASH)

dnl [PM] 3.12.1 (strange quoting to make the following work both substituted and un-substituted:
dnl -*- Mode:foo; dummy:"@EMACS_MODE_LINE_BUFFER_READONLY@" -*-
dnl which is legal and after expansion becomes:
dnl -*- Mode:foo; dummy:""; buffer-read-only:t; dummy2:"" -*-
dnl which is also legal and makes the buffer read-only
dnl
EMACS_MODE_LINE_BUFFER_READONLY='"; buffer-read-only:t; dummy2:"'
AC_SUBST(EMACS_MODE_LINE_BUFFER_READONLY)

dnl [PM] 3.11.2 see configure_wince.ac
AC_SUBST(CYGWIN_MAKEFILE_ENV_EXPORTS, [])

dnl *TOP_SRCDIR is the toplevel source code directory
dnl [PM] 3.8.7 Was PWD= but PWD is read-only on Darwin 1.3 (MacOS X 10.0.1)
CURR_PWD="`pwd`"

case $host in
    *win32*)
        AC_MSG_CHECKING([whether CURR_PWD ($CURR_PWD) path needs spaces removed])
        if expr "X${CURR_PWD}" : ".* .*" 1>/dev/null 2>&1; then # contains a space
           CURR_PWD_NATIVE_PATH=`cygpath -m -s "${CURR_PWD}"`
           if test -n "${CURR_PWD_NATIVE_PATH}"; then
              CURR_PWD="`cygpath -u "${CURR_PWD_NATIVE_PATH}"`"
              AC_MSG_RESULT([yes ($CURR_PWD)])
           else
              AC_MSG_ERROR([Failed to remove spaces from CURR_PWD path ($CURR_PWD)])
           fi
        else
           AC_MSG_RESULT([no])
        fi
     ;;
esac

TOP_SRCDIR="$CURR_PWD"

AC_SUBST(TOP_SRCDIR)

dnl These definitions need to be reviewed; most of them are overruled in
dnl Common, for example.

dnl SP_ROOTDIR is the root of the SICStus installation tree. If we're
dnl installing a binary distribution, this is always equal to prefix.
if test $sp_isbindistr = yes; then
    SP_ROOTDIR="$prefix"
else
   case $PLATFORM in 
       *win32*)
          SP_ROOTDIR="$TOP_SRCDIR"
       ;;
       *)
          SP_ROOTDIR="$TOP_SRCDIR/Utils/$host"
       ;;
   esac
fi
dnl [PM] 3.9.1 not used:
dnl AC_SUBST(SP_ROOTDIR)

dnl [PM] 3.11.2 not used
dnl SP_INCDIR="$SP_ROOTDIR/include"
dnl AC_SUBST(SP_INCDIR)

dnl Main executables (sicstus, sptmp, spld, splfr, etc.)
SP_BINDIR="$SP_ROOTDIR/bin"
dnl Needed in distrib.in
AC_SUBST(SP_BINDIR)

dnl [PM] 3.9.1b4
SPLD_CONFIG_FILE_BASENAME="spconfig-$SICSTUS_VERSION_STRING"
AC_SUBST(SPLD_CONFIG_FILE_BASENAME)

dnl [PM] 3.9b4 must make config name version specific (See Utils/Makefile)
dnl : ${SPLD_CONFIG_FILE="$SP_BINDIR/spld.config"}
: ${SPLD_CONFIG_FILE="$SP_BINDIR/$SPLD_CONFIG_FILE_BASENAME"}
AC_SUBST(SPLD_CONFIG_FILE)

dnl [PM] 3.9.1 moved below AC_SUBST(SPLD_DSFLAGS)
: ${JASPER_SPLFR_FLAGS=""}
AC_SUBST(JASPER_SPLFR_FLAGS)


dnl [PM] 3.9.1 SP_ROOTLIBDIR is where the sprt shared object runtime is located.
case $PLATFORM in 
    *win32*)
      SP_ROOTLIBDIR="$SP_ROOTDIR"
    ;;
    *)
      SP_ROOTLIBDIR="$SP_ROOTDIR/lib"
    ;;
esac
AC_SUBST(SP_ROOTLIBDIR)

dnl SP_PATHDIR is ...? FIXME docs
dnl [PM] 3.9.1 On UNIX this is like .../lib/sicstus-3.9.1beta2
dnl [PM] 3.9.1 On Win32 this is SP_ROOTDIR (e.g. /c/Program Files/SICStus Prolog 3.9.1)
dnl ([PM] 3.9.1 old bogus comment:) Value of SP_PATH to be encoded in wrappers generated by spld
case $PLATFORM in 
    *win32*)
       SP_PATHDIR="$SP_ROOTDIR"
    ;;
    *)
       SP_PATHDIR="$SP_ROOTLIBDIR/$SP_DIRNAME"
    ;;
esac
AC_SUBST(SP_PATHDIR)

dnl [PM] 3.9.1 Now OK for UNIX and Win32
dnl Support binaries (sp.o, spds.sav, sprt.sav, etc.)
SP_BINAUXDIR="$SP_PATHDIR/bin"
AC_SUBST(SP_BINAUXDIR)

# Library-modules
dnl [PM] 3.9b5 used to be called SP_LIBDIR but that is used for something different too.
SP_LIBRARY_DIR="$SP_PATHDIR/library"
AC_SUBST(SP_LIBRARY_DIR)

dnl # Info-dir
dnl SP_INFODIR="$SP_ROOTDIR/info"
dnl AC_SUBST(SP_INFODIR)

dnl [PM] 3.9.1 not used (but see doc/Makefile)
dnl # Man-dir
dnl SP_MANDIR="$SP_ROOTDIR/man"
dnl AC_SUBST(SP_MANDIR)

dnl # Other documentation (HTML & Postscript)
dnl SP_DOCDIR="$SP_PATHDIR/doc"
dnl AC_SUBST(SP_DOCDIR)

dnl [PM] 4.0 Incompatible DSOs should have different names. We are not
dnl      compatible enough between revisions so include all version
dnl      info in the name.
dnl      The result will be something like libsprt-4-1-2.so or sprt-4-0-1-beta2.dll
SPVER="${SICSTUS_MAJOR_VERSION}-${SICSTUS_MINOR_VERSION}-${SICSTUS_REVISION_VERSION}${SICSTUS_BETA_VERSION_STRING:+-}${SICSTUS_BETA_VERSION_STRING}"


dnl [PM] 3.10.1 default name on UNIX and used in documentation on *all* platforms
UNIX_RTKERNEL_BASENAME_SANS_SUFFIX="libsprt${SPVER}"
AC_SUBST(UNIX_RTKERNEL_BASENAME_SANS_SUFFIX)
dnl [PM] 3.10.1 default name on Win32 and used in documentation on *all* platforms
WIN32_RTKERNEL_BASENAME_SANS_SUFFIX="sprt${SPVER}"
AC_SUBST(WIN32_RTKERNEL_BASENAME_SANS_SUFFIX)

case "${PLATFORM}" in 
    *win32*)
       RTKERNEL_BASENAME_SANS_SUFFIX="${WIN32_RTKERNEL_BASENAME_SANS_SUFFIX}"
    ;;
    *)
       RTKERNEL_BASENAME_SANS_SUFFIX="${UNIX_RTKERNEL_BASENAME_SANS_SUFFIX}"
    ;;
esac


RTKERNEL_INSTANCE_TEMPLATE="${RTKERNEL_BASENAME_SANS_SUFFIX}-instance-XX"
AC_SUBST(RTKERNEL_INSTANCE_TEMPLATE)
AC_DEFINE_UNQUOTED([RTKERNEL_INSTANCE_TEMPLATE_STRING], ["${RTKERNEL_INSTANCE_TEMPLATE}"])

AC_ARG_WITH(release-month,     [  --with-release-month            Internal],
  [RELEASE_MONTH=$withval],
  [RELEASE_MONTH=`date +%B`] dnl Locales full month name
  )
AC_SUBST(RELEASE_MONTH)

AC_ARG_WITH(release-year,     [  --with-release-year            Internal],
  [RELEASE_YEAR=$withval], 
  [RELEASE_YEAR=`date +%Y`]
  )
AC_SUBST(RELEASE_YEAR)
AC_DEFINE_UNQUOTED([RELEASE_YEAR], [$RELEASE_YEAR])


AC_ARG_VAR(MAKE,[])
SP_CHECK_ABSOLUTE([MAKE])
AC_PATH_PROG([MAKE],[make$EXEEXT])

AC_PROG_MAKE_SET()

# Set CONFIG_AUX_DIR to an absolute path. This is needed in order for
# INSTALL to be set to an absolute path if no install-program is found
# and install-sh is used as a fallback.
AC_CONFIG_AUX_DIR([$TOP_SRCDIR])

dnl [PM] 3.11.3 INSTALL is only needed during src build
dnl ============================================================
dnl ============================================================

dnl [PM] 3.9.1 We now support running the test suite in binary
dnl            installs.
AC_MSG_CHECKING(testsuite)
AC_ARG_WITH(suite,     [  --without-suite            Enable/disable the test-suite.],
    [SUITE=$withval
     EXPLICIT_SUITE=yes],
    [SUITE=yes
     EXPLICIT_SUITE=no])
AC_MSG_RESULT($SUITE)
if test "x$SUITE" != "xyes"; then
  EXPLICIT_SUITE=no
fi

#################################################################
#
# Check for C compiler.
#
#################################################################
case $host in
    *win32*)    # Use cl per default on cygwin hosts
	: ${CC=cl.exe}
	: ${CXX=cl.exe}
        : ${CPP="cl.exe -nologo -E"}
dnl [PM] 4.0 better than various (broken) tests like "test $CC = cl"
        msvc_cc=yes
	;;
    *)
        msvc_cc=no
        ;;
esac

AC_MSG_CHECKING([default C-compiler])
AC_ARG_ENABLE(cc,       [  --enable-cc             Try to use C compiler cc.],
	[
        if test "$enableval" = "yes"; then	    
	    CC='cc'
	else
	    CC=$enableval
	fi
        ])

if test -z "${CC}"; then
    AC_MSG_RESULT(no)
else
    AC_MSG_RESULT([${CC}])
fi

AC_MSG_CHECKING([default C++ compiler])
AC_ARG_ENABLE(CC,       [  --enable-CC             Try to use C++ compiler CC.],
	[
        case "$enableval" in
        yes)
	    CXX='CC'
            ;;
        no) dnl [PM] 3.9.1b4 --disable-CC makes it possible to avoid C++ test-Suite
            sp_prog_cxx_succeeds=no
            unset CXX
            ;;
	*)
	    CXX="$enableval"
            ;;
	esac
        ])

if test "x$sp_prog_cxx_succeeds" = "xno"; then
  AC_MSG_RESULT([disabled])
else
  if test -z "$CXX"; then
      AC_MSG_RESULT([no])
  else
      AC_MSG_RESULT([$CXX])
  fi
fi

dnl ============================================================
dnl ============================================================


dnl ============================================================
dnl ============================================================


dnl ============================================================
dnl ============================================================

dnl AC_MSG_CHECKING([C flags before PROG_CC])
dnl AC_MSG_RESULT([$CFLAGS])

dnl [PM] 3.11.3 I think AC_ARG_VAR is done by AC_PROG_CC but that is not documented
AC_ARG_VAR(CC,[])
AC_PROG_CC()

if test "${GCC:-no}" = "yes"; then
    AC_MSG_CHECKING([whether gcc ($CC) is really Intel icc])
    AC_TRY_COMPILE([], [#ifndef __INTEL_COMPILER
     not intel compiler
    #endif], [ICC=[yes]], [ICC=[no]])
    AC_MSG_RESULT([$ICC]);

    AC_MSG_CHECKING([whether gcc ($CC) is really clang])
    cc_version=`$CC --version | head -n 1` 2> /dev/null
    case "${cc_version}" in
     *clang*)
       CLANG=yes
     ;;
     *)
       CLANG=no
     ;;
    esac
    dnl if $CC --version 2> /dev/null | grep 'clang' >/dev/null; then
    dnl     CLANG=yes
    dnl else
    dnl     CLANG=no
    dnl fi
    AC_MSG_RESULT([$CLANG])
    if test $CLANG = yes ; then
      AC_MSG_CHECKING([clang version])
      clang_version="${cc_version}"
      [ # protect from M4 BEGIN
        if echo "${clang_version}" | $POSIX_GREP '[Aa][Pp][Pp][Ll][Ee]' 2>/dev/null ; then
         # Apple version
	   clang_apple_version=`echo "$cc_version" | sed -n 's/[Aa][Pp][Pp][Ll][Ee] LLVM version \([1-9][0-9]*\.[0-9][0-9]*\).*/\1/p'`
	   clang_llvm_version=`echo "$cc_version" | sed -n 's/.* LLVM \([1-9][0-9]*\.[0-9][0-9]*\).*/\1/p'`
	   clang_llvm_version_major=`echo "$clang_llvm_version" | sed -n 's/\([1-9][0-9]*\)\..*/\1/p'`
	   clang_llvm_version_minor=`echo "$clang_llvm_version" | sed -n 's/[1-9][0-9]*\.\([0-9][0-9]*\).*/\1/p'`
        else # Not Apple version (e.g. MacPorts)
         # something like "clang version 3.4 (tags/RELEASE_34/final)"
	   clang_apple_version=''
	   clang_llvm_version=`echo "$cc_version" | sed -n 's/.*clang *version *\([1-9][0-9]*\.[0-9][0-9]*\).*/\1/p'`
	   clang_llvm_version_major=`echo "$clang_llvm_version" | sed -n 's/\([1-9][0-9]*\)\..*/\1/p'`
	   clang_llvm_version_minor=`echo "$clang_llvm_version" | sed -n 's/[1-9][0-9]*\.\([0-9][0-9]*\).*/\1/p'`
        fi
      ] # protect from M4 END

      AC_MSG_RESULT([\"${clang_version}\"${clang_llvm_version:+ (LLVM $clang_llvm_version, Major: ${clang_llvm_version_major}, Minor: ${clang_llvm_version_minor})}${clang_apple_version:+ (Apple $clang_apple_version)}])

      

      dnl [PM] 4.3 Set them to 'unknown' if we have clang but do not know the version, empty if no clang.
      : ${clang_version:=unknown}
      : ${clang_llvm_version:=unknown}
      : ${clang_apple_version:=unknown}
    else
      dnl [PM] 4.3 Set them to empty if we do not have clang
      clang_version=''
      clang_apple_version=''
      clang_llvm_version=''
    fi
fi

dnl AC_MSG_CHECKING([C flags after PROG_CC])
dnl AC_MSG_RESULT([$CFLAGS])

case "${DBGFLAG:-yes}" in
    yes|no)
	;;
    *)
        dnl [PM] 4.2 NOTE: You must not set CFLAGS before AC_PROG_CC!
        if test "${SP_NEW_DBG_POLICY:-no}" = "yes"; then
          dnl [PM] 4.2.1 Code should get DBG or SICSTUS_DBG from config.h

          dnl [PM] 4.2.1 temporary, should not pass any of DBG/DBG_ on CFLAGS/command line
          dnl CFLAGS="$CFLAGS -DDBG_DO_NOT_USE_THIS_=$DBGFLAG"
          dnl [PM] 4.2.1 This definition of DBG ensures that any users
          dnl will get compilation error. This poisoned definition is
          dnl undone in config.h
          CFLAGS="$CFLAGS -DDBG=1.2.3.4DO_NOT_USE6.7.8 -DDBG_POISON"
        else
          CFLAGS="$CFLAGS -DDBG=$DBGFLAG"
        fi
	;;
esac



case $PLATFORM in
   *darwin-*)
      has_apple_gcc_default=yes
      AC_ARG_ENABLE(apple-gcc,      [  --disable-apple-gcc            Internal Mac OS X],
           [has_apple_gcc="$enableval"],
           [has_apple_gcc="${has_apple_gcc_default}"])
      # normalize
      case "${has_apple_gcc:-yes}" in
        no)
        ;;
        *)
        has_apple_gcc=yes
        ;;
      esac

      if test "${CLANG:-no}" = "yes"; then
         no_cpp_precomp=''
      fi

      if test "${has_apple_gcc:-yes}" = "yes" ; then
         : ${no_cpp_precomp='-no-cpp-precomp'}
      fi

      if test "${GCC:-no}" = "yes"; then
         dnl [PM] 3.9.1 -no-cpp-precomp turns off the broken preprocessor (barfs on wam.c)
         dnl            AC_PROG_CPP would use "${CC} -E
         dnl            -traditional-cpp" which I believe is worse
         dnl            since we do not use -traditional-cpp when
         dnl            compiling (and -traditional-cpp gives a
         dnl            non-ANSI preprocessor).
         dnl xref CFLAGS/CPPFLAGS below

         : ${CPP="${CC} -E ${no_cpp_precomp}"}
      fi
   ;;
   *)
   ;;
esac

AC_PROG_CPP()

dnl ============================================================
dnl ============================================================


dnl ============================================================
dnl ============================================================


# [PM] 3.8.7,3.9b2 autoconf 2.52 configure will incorrectly add -g to
#            CFLAGS even though cl does not permit it. So, remove -g
#            if win32 cl or if explicitly requesting no debugging info
AC_MSG_CHECKING([whether -g should be passed to C compiler (${CC})])
keep_minus_g=yes
case $host in
    *win32*)
        
        if test "${msvc_cc}" = yes; then
           keep_minus_g=no
        fi
	;;
    *)
	if test "${DBGFLAG:-yes}" = no; then
           keep_minus_g=no
        fi
        ;;
esac
AC_MSG_RESULT([${keep_minus_g}])

dnl AC_MSG_CHECKING([C flags before filtering -g])
dnl AC_MSG_RESULT([$CFLAGS])

if test "${keep_minus_g}" = no; then
  NEW_CFLAGS=''
  for cflag in $CFLAGS 
  do
      case "${cflag}" in
          -g)
              : # discard -g
              ;;
          *)
              NEW_CFLAGS="$NEW_CFLAGS $cflag"
              ;;
      esac
  done

  CFLAGS="${NEW_CFLAGS}"
  dnl AC_MSG_CHECKING([C flags after filtering -g])
  dnl AC_MSG_RESULT([$CFLAGS])
fi # !keep_minus_g

AC_MSG_CHECKING([whether C compiler should warn about unused variables etc])
AC_ARG_ENABLE(cc-warning-unused,  [  --enable-cc-warning-unused            Warn for unused variables etc.],
	[cc_warning_unused=$enableval],
        [cc_warning_unused=yes] # [PM] 3.9b5 default on
        )
AC_MSG_RESULT($cc_warning_unused)

dnl [PM] 3.10.1b1 (except when DBG>0) spld and splfr will only use
dnl      CFLAGS without CFLAGS_EXTRA so anything non-standard that we
dnl      want for our code should go on CFLAGS_EXTRA (extra warnings,
dnl      treat warnings as error, non-standard calling conventions (Win32)).
dnl [PM] 3.10.2 NOTE: Some things should go on CFLAGS_EXTRA_SEMANTICS
dnl      instead (below).
dnl [PM] 3.9 Add things here that should go on CFLAGS but that should
dnl not be seen by configure. Intended for 'treat warnings as errors'
dnl flags and such. (Cannot add <treat warnings as errors> to CFLAGS
dnl since it breaks the compilations tests performed by configure.
dnl
dnl Also, -Gr (MSVC CL.EXE use __fastcall calling convention) must go
dnl here so that an ordinary main declaration (without explicit
dnl __cdecl) does not barf

CFLAGS_EXTRA=""

dnl [PM] 3.10.2 Things that could affect configure run-time tests but
dnl that should not be used for user code. (e.g., floating point
dnl behavior).
CFLAGS_EXTRA_SEMANTICS=""


dnl ============================================================
dnl ============================================================

dnl [PM] 3.11.3 this ensures that warning are never errors for binary releases, even for beta versions
: ${cc_warnings_are_errors=no}


dnl ============================================================
dnl ============================================================

dnl [PM] 3.11.3 never picky for binary releases
: ${picky_cc=no}

# Not all compilers rejects unknown parameters.
if test "${GCC:-no}" = "yes"; then
    AC_MSG_CHECKING([whether the C compiler (${CC}) accepts -pipe])
    echo "int main() { return 0; }" > dummy.c
    if "${CC}" -pipe dummy.c -o dummy >/dev/null 2>&1 && ./dummy; then
	AC_MSG_RESULT(yes)
	CFLAGS="$CFLAGS -pipe"
    else
	AC_MSG_RESULT(no)
    fi
    rm -f dummy*
fi

if test "${GCC:-no}" = "yes"; then
    AC_MSG_CHECKING([gcc version])

    dnl [PM] 3.10 we do not want newlines in GCC_VERSION when it is
    dnl used for versions (since this will give a cc warning about
    dnl newlines in character strings).
    GCC_VERSION=`${CC} --version | tr '\n' ' '`

    cat > gcctmp.c <<EOF
#include <stdio.h>
int main(int argc, char **argv) {
    int gcc_minor = 
#ifdef __GNUC__
    printf("%d",(int)__GNUC__);
#endif
    return 0;
}
EOF
    ${CC-cc} gcctmp.c -o ./gcctmp
    GCC_MAJOR=`./gcctmp`
    : ${GCC_MAJOR:=0}


    cat > gcctmp.c <<EOF
#include <stdio.h>
int main(int argc, char **argv) {
    int gcc_minor = 
#ifdef __GNUC_MINOR__
    printf("%d",(int)__GNUC_MINOR__);
#endif
    return 0;
}
EOF
    ${CC-cc} gcctmp.c -o ./gcctmp
    GCC_MINOR=`./gcctmp`
    : ${GCC_MINOR:=0}

    AC_MSG_RESULT([Major version $GCC_MAJOR, minor version $GCC_MINOR])
    rm -f gcctmp*
fi

if test "${GCC:-no}" = "yes"; then
    VERBOSE_FLAG="-v"
    NOVERBOSE_FLAG=""
else
    VERBOSE_FLAG=""
    NOVERBOSE_FLAG=""
fi
AC_SUBST(VERBOSE_FLAG)
AC_SUBST(NOVERBOSE_FLAG)


dnl [PM] 3.9.1 On some platforms we traditionally use some kind of linker
dnl instead of CC to link shared libs. This is "a bad thing(tm)".
dnl Experiment with using ${CC} on these platforms instead

AC_MSG_CHECKING(whether the C compiler (${CC}) should be used for shared linking)
AC_ARG_ENABLE(cc-shld,  [  --enable-cc-shld            Internal use],
	[enable_cc_shld=$enableval],
        [enable_cc_shld="default"]
        )
AC_MSG_RESULT($enable_cc_shld)


ENABLE_GPROF=no
ENABLE_GCOV=no


AC_ARG_VAR([VALGRIND])
SP_CHECK_ABSOLUTE([VALGRIND])
AC_PATH_PROG([VALGRIND],[valgrind$EXEEXT])

dnl VALGRIND_FLAGS are checked later (after JIT)

AC_ARG_VAR([VALGRIND_SUPPRESSIONS_FILES])
AC_MSG_CHECKING([for valgrind suppression files])
if test -z "${VALGRIND_SUPPRESSIONS_FILES}"; then
  AC_MSG_RESULT([none])
else
  AC_MSG_RESULT([${VALGRIND_SUPPRESSIONS_FILES}])
fi
AC_SUBST([VALGRIND_SUPPRESSIONS_FILES])


# [PM] 4.3 Try to figure out MINIZINC_DIR, preferably from explicit argument, otherwise from explicit SOLNS2OUT or MZN2FZN
# Note: We do not want to use a path found on PATH here, so use the raw SOLNS2OUT, MZN2FZN
AC_MSG_CHECKING([for path to MiniZinc])
AC_ARG_VAR([MINIZINC_DIR])
if test -n "${MINIZINC_DIR}"; then
  AC_MSG_RESULT([${MINIZINC_DIR}])
else # MINIZINC_DIR not set
  minizinc_bin_dir=''
  # First try path to SOLNS2OUT, assuming it is in ${MINIZINC_DIR}/bin/
  if test -z "${MINIZINC_DIR}"; then
     if test -n "${SOLNS2OUT}"; then
       minizinc_bin_dir=`dirname "${SOLNS2OUT}"`
       MINIZINC_DIR=`dirname "${minizinc_bin_dir}"`
       if test -n "${MINIZINC_DIR}"; then
         AC_MSG_RESULT([${MINIZINC_DIR} (from SOLNS2OUT)])
       fi
     fi
  fi
  # Second try path to MZN2FZN, assuming it is in ${MINIZINC_DIR}/bin/ or ${MINIZINC_DIR}/bin/private
  if test -z "${MINIZINC_DIR}"; then
     if test -n "${MZN2FZN}"; then
       minizinc_bin_dir=`dirname "${MZN2FZN}"`
       case "${minizinc_bin_dir}" in
         */private)
           minizinc_bin_dir=`dirname minizinc_bin_dir`
           ;;
       esac
       minizinc_bin_dir=`dirname "${minizinc_bin_dir}"`
       MINIZINC_DIR=$(dirname "${minizinc_bin_dir}")
       if test -n "${MINIZINC_DIR}"; then
         AC_MSG_RESULT([${MINIZINC_DIR} (from MZN2FZN)])
       fi
     fi
  fi

  if test -z "${MINIZINC_DIR}"; then
    AC_MSG_RESULT([none])
  fi
fi # MINIZINC_DIR not set
   
SP_CHECK_ABSOLUTE([MINIZINC_DIR])

AC_ARG_VAR([MZN2FZN])
SP_CHECK_ABSOLUTE([MZN2FZN])
AC_PATH_PROG([MZN2FZN],[mzn2fzn${EXEEXT}], [],
   [${MINIZINC_DIR}${MINIZINC_DIR:+/bin:}:${PATH}])

AC_ARG_VAR([SOLNS2OUT])
SP_CHECK_ABSOLUTE([SOLNS2OUT])
AC_PATH_PROG([SOLNS2OUT],[solns2out${EXEEXT}], [],
   [${MINIZINC_DIR}${MINIZINC_DIR:+/bin:}:${PATH}])



dnl ============================================================
dnl ============================================================

AC_ARG_VAR([VALGRIND_FLAGS])

case $PLATFORM in
    *linux*)
      if test "${enable_64bit}" = "yes"; then
         # [PM] 4.0.5 valgrind defaults to 8 also on 64-bit platforms. SICStus requires 16-byte alignment from malloc().
         VALGRIND_FLAGS="${VALGRIND_FLAGS}${VALGRIND_FLAGS:+ }--alignment=16"
      fi
    ;;
    *-darwin*)
       VALGRIND_FLAGS="${VALGRIND_FLAGS}${VALGRIND_FLAGS:+ }--dsymutil=yes"
    ;;
esac
if test "${JIT:-no}" = "yes"; then
   valgrind_smc_check_jit_option=--smc-check=all
   if test ${VALGRIND:-unset} != unset; then
     AC_MSG_CHECKING([whether valgrind supports --smc-check=all-non-file (new in 3.7.0)])
     if ${VALGRIND} --help 2> /dev/null | ${POSIX_GREP} -e '--smc-check=.*all-non-file' 2> /dev/null 1>&2 ; then
       AC_MSG_RESULT([yes])
       valgrind_smc_check_jit_option=--smc-check=all-non-file
     else
       AC_MSG_RESULT([no, or unknown. Fall back to --smc-check=all (slow)])
     fi
     AC_MSG_CHECKING([valgrind option for proper JIT handling])
     AC_MSG_RESULT([$valgrind_smc_check_jit_option])
   fi # VALGRIND

   VALGRIND_FLAGS="${VALGRIND_FLAGS}${VALGRIND_FLAGS:+ }${valgrind_smc_check_jit_option}"
fi

AC_MSG_CHECKING([for valgrind flags])
if test -z "${VALGRIND_FLAGS}"; then
  AC_MSG_RESULT([none])
else
  AC_MSG_RESULT([${VALGRIND_FLAGS}])
fi

AC_SUBST([VALGRIND_FLAGS])


dnl [PM] 3.9.1 (comment added) Ensures AC_PROG_CPP has been called.
AC_EGREP_CPP(,[],:)

AC_ARG_VAR([PERL],[])
SP_CHECK_ABSOLUTE([PERL])
AC_PATH_PROG([PERL],[perl$EXEEXT])

if test -n "${PERL}"; then
    dnl [PM] 3.9.1b4 FIXME: should replace all this with something like ( perl -e 'require 5.004_03' || barf ) see InstallSICStus.in

    AC_MSG_CHECKING([Perl version])
    # This is perl, version 5.005_03 built for i386-linux
    # This is perl, version 5.004_03
    # This is perl, v5.6.0 built for i686-linux

    perl_version=`$PERL -version | grep "This is perl"`
    if echo $perl_version | grep '5\.' >/dev/null; then
	AC_MSG_RESULT(ok)
    else
	AC_MSG_ERROR([no (you need Perl 5 or later)])
    fi
fi

dnl [PM] 3.8.4 missing PERL used to be silently ignored (the next
dnl      three lines were commented away.
if test -z "${PERL}"; then
    AC_MSG_ERROR([could not find a usable Perl])
fi

dnl [PM] 3.11.2 long gone
dnl AC_SUBST(PERL_LFLAGS)
dnl AC_SUBST(PERL_CFLAGS)
dnl AC_SUBST(PERL_CORE)
dnl AC_SUBST(PERL_MODULE)


dnl [PM] 3.9.1  The test suite src begin marker used to be here
dnl             However, nowadays we run the Suite on binary
dnl             installs. Besides, there are so little done here
dnl             anyway. (Was a problem since CXX did not get set)


if test $SUITE = "yes"; then
    dnl [PM] 3.9.1b4 We want to enable the test-suite in binary installs
    dnl but we do not want to abort if there is no C++. Unfortunately
    dnl AC_PROG_CXX will use exit 1 if it fails to find a working
    dnl C++ compiler.
    dnl As a horrid hack we dry-run the test first in a subshell to
    dnl see if it will succeed.

    AC_MSG_CHECKING([if A${EMPTY_STRING}C${EMPTY_STRING}_PROG_CXX will succeed])

    dnl [PM] 3.9.1b4 --disable-CC will set sp_prog_cxx_succeeds to "no"
    : ${sp_prog_cxx_succeeds=yes}

    if test "x$sp_prog_cxx_succeeds" != "xno"; then
      dnl [PM] 3.9.0 if we have not set the C++ compiler and are using
      dnl            a, perhaps explicitly given, gcc as CC then use
      dnl            that gcc for C++ code as well.
      if test "${GCC:-no}" = "yes"; then
         : ${CXX=${CC}}
      fi

      AC_MSG_RESULT([])
      dnl [PM] 3.9.1 if --with-suite was explicitly specified we should
      dnl barf if C++ cannot be configured.
      if test $EXPLICIT_SUITE != yes; then
      ( AC_PROG_CXX() ) && sp_prog_cxx_succeeds=yes || sp_prog_cxx_succeeds=no
      fi
    else
      AC_MSG_RESULT([C++ disabled])
    fi

    if test "${sp_prog_cxx_succeeds:-no}" = "yes"; then
      dnl Check for C++ compiler, used in the testsuite. If C++ compiler is GCC,
      dnl also check for location of -lgcc.

dnl [PM] 4.0 I do not think linking with -lgcc is needed
          GCCLIB=''
dnl
dnl       dnl [PM] 3.11.3 I think AC_ARG_VAR is done by AC_PROG_CXX but that is not documented
dnl       AC_PROG_CXX()
dnl       if test "${GXX:-no}" = "yes"; then
dnl         dnl [PM] 3.10 FIXME: check if -lgcc is still (or ever was) needed.
dnl           AC_MSG_CHECKING(location of -lgcc)
dnl           libgcc_filename=`$CXX --print-libgcc-file-name 2>/dev/null`
dnl           # [PM] 3.8.7 Note: MacOS X cc gives a non-absolute path (contrary to the docs)
dnl           #            We zap GCCLIB later on for MacOS X.
dnl           if test x$libgcc_filename != x; then
dnl               AC_MSG_RESULT($libgcc_filename)
dnl               GCCLIB="-L`dirname $libgcc_filename` -lgcc"
dnl           else
dnl               AC_MSG_RESULT(no)
dnl               GCCLIB=""
dnl           fi
dnl       fi
    fi dnl sp_prog_cxx_succeeds

    AC_SUBST(GCCLIB)
fi # $SUITE

dnl [PM] 3.9.1  the test suite src end marker used to end here


dnl [PM] 3.10.2 SPRM 6748, SPRM 7358
AC_MSG_CHECKING([whether floating point consistency should be maintained])
AC_ARG_ENABLE(float-consistency,      [  --enable-float-consistency            Increase floating point consistency (cl /Op, gcc -ffloat-store)],
        [float_consistency=$enableval],
        [float_consistency=yes])
AC_MSG_RESULT([$float_consistency])

dnl [PM] 3.10.2 long time ago replaced by CFLAGS_EXTRA_SEMANTICS and CFLAGS_EXTRA
dnl # Save away CFLAGS before adding additional warning and optimization
dnl # flags. This saved value is used when compiling glue-code, to avoid
dnl # splfr to show unnecessary compiler warnings to the user.
dnl CFLAGS_NOWARN=$CFLAGS
dnl AC_SUBST(CFLAGS_NOWARN)

if test "${GCC:-no}" = "yes"; then

    dnl [PM] 4.0 Embed C macro definitions in debug info
    dnl      Explicitly use Dwarf 2
    dnl [PM] 4.3 OS X 10.5 and later use DWARF by but it seems
    dnl      clang/lldb does not save/use the macro definitions. So,
    dnl      no need for explicit -gdwarf-2 on OS X, and no need for
    dnl      -g3 in OS X -versions where we use clang. See
    dnl      http://stackoverflow.com/questions/10044697/where-how-does-apples-gcc-store-dwarf-inside-an-executable
    dnl      http://wiki.dwarfstd.org/index.php?title=Apple%27s_%22Lazy%22_DWARF_Scheme
    dnl
    dnl [PM] 4.3 DWARF is now at DWARF-3, so explicitly requesting
    dnl      DWARF-2 seems like a bad idea on any platform. (and
    dnl      G3CFLAG is only used by the SICStus developers, not by
    dnl      end users)

    case $PLATFORM in
       *-darwin-*)
         enable_dwarf2_default=no
         G3CFLAG='-g'
       ;;
       *)
         G3CFLAG='-g3'
         enable_dwarf2_default=no
       ;;
    esac

    if test "${enable_dwarf2:-$enable_dwarf2_default}" = "yes"; then
      G3CFLAG="${G3CFLAG} -gdwarf-2"
    fi

    if test "${ENABLEG3:-no}" = "yes"; then
      CFLAGS_EXTRA="$CFLAGS_EXTRA $G3CFLAG"
    fi

    gcc_warnings=""

    dnl [PM] 3.10.1b1 Moved from CFLAGS since -Wall belongs on CFLAGS_EXTRA
    dnl CFLAGS="$CFLAGS -Wall"
    gcc_warnings="$gcc_warnings -Wall"

dnl GCC
       # DBG
       # [PM] The only reason these warnings are not on in release
       # builds is that CFLAGS are used by splfr/spld also for
       # compiling user (C) code (but see SPLD_CONFIG_CFLAGS)
       # 2001-01-10 SICStus 3.9 and testsuit builds without triggering
       # any warning! Keep it that way (without disabling warnings :-)

       # [PM] 3.9 -Wparentheses finds if-else nesting bugs, keep!
       # gcc_warnings="$gcc_warnings -Wno-parentheses"
       
       # [PM] 3.9b5 see if we can work around any legitimate unused locals instead.
       # gcc_warnings="$gcc_warnings -Wno-unused" # We have lots of unused arguments (e.g. `w')

       if test "$cc_warning_unused" = "no"; then
          if test "x$picky_cc" = "xno"; then # turn off no warnings with picky cc
             gcc_warnings="$gcc_warnings -Wno-unused " # after -Wall!
          fi
       else
          gcc_warnings="-Wunused $gcc_warnings"
       fi
       gcc_warnings="$gcc_warnings -Wstrict-aliasing"

       dnl [PM] 4.0.5 Only warn about missing optimizations if we do (full) optimization.
       dnl This prevents gcc -O1 warnings (-funit-at-a-time is
       dnl required for inlining of functions that are only called
       dnl once) with GCC 4.3.2 on Ubuntu.
       if test "${OPTFLAG:-no}" = "yes"; then
         AC_MSG_CHECKING([whether ${CC} supports -Wdisabled-optimization support])
         if test "${ICC:-no}" = "yes"; then
           # [PM] 4.2.1 icc only warns so the try-compile test does no good.
           can_Wdisabled_optimization=no
         else
	   cflags_old="${CFLAGS}";
	   CFLAGS="${CFLAGS} -Wdisabled-optimization"
	   AC_TRY_COMPILE([], [],[can_Wdisabled_optimization=yes],[can_Wdisabled_optimization=no])
	   CFLAGS="${cflags_old}"
         fi
         if test "${can_Wdisabled_optimization:-no}" = "yes"; then
           dnl [PM] 4.0 warn if gcc disables optimization due to function size etc.
           gcc_warnings="${gcc_warnings} -Wdisabled-optimization"
           AC_MSG_RESULT([yes])
         else
           AC_MSG_RESULT([no])
         fi
       fi # OPTFLAG = yes
dnl GCC
       gcc_warnings="$gcc_warnings -Wmissing-prototypes"

       dnl [P] 3.10.1b1 gcc_warnings is now on CFLAGS_EXTRA
       dnl # [PM] 3.9b4 Yeah! (note, cannot go on CFLAGS)
       dnl CFLAGS_EXTRA="-Wstrict-prototypes $CFLAGS_EXTRA"
       dnl CFLAGS_EXTRA="-Wmissing-declarations $CFLAGS_EXTRA"
       gcc_warnings="-Wstrict-prototypes $gcc_warnings"
       gcc_warnings="-Wmissing-declarations $gcc_warnings"

       if test "${ICC:-no}" = "yes"; then
         # [PM] 4.2.1 Happens for zlib code (and probably some of our code as well)
         # error #310: old-style parameter list (anachronism)
         diag_disable="${diag_disable:+${diag_disable},}310"

         # [PM] 4.2.1 Happens for COMPILE_TIME_ASSERT_DECLARATION()
         # error #1419: external declaration in primary source file
         diag_disable="${diag_disable:+${diag_disable},}1419"

         # [PM] 4.2.1 Happens a lot in clpfd
         # error #188: enumerated type mixed with another type
         diag_disable="${diag_disable:+${diag_disable},}188"
         gcc_warnings="${gcc_warnings}${diag_disable:+ -diag-disable ${diag_disable}}"
       else
	 dnl [PM] 4.1.0 By default GCC allows declaration after
	 dnl statement which is not C89 and which some other compilers
	 dnl barfs at.
	 gcc_warnings="-Wdeclaration-after-statement $gcc_warnings"
         gcc_warnings="$gcc_warnings -Wnested-externs"
       fi

       # NO: gcc_warnings="$gcc_warnings -Wconversion"

       # [PM] 4.3 Not yet (and see --enable-cc-Wconversion)
       # # [PM] 4.3 See if we can have this. It is the default on
       # # Windows and we want to use similar warning on all platforms.
       # gcc_warnings="$gcc_warnings -Wconversion"
       # # [PM] 4.3 But we do not want to warn about sign conversion (e.g. from size_t to spio_t_offset)
       # if test "x$picky_cc" = "xno"; then
       #   gcc_warnings="$gcc_warnings -Wno-sign-conversion"
       # fi


       # No: gcc_warnings="$gcc_warnings -Wwrite-strings"
       gcc_warnings="$gcc_warnings -Wpointer-arith"

dnl [PM] 4.1.3+ See if any platforms still has this problem. One
dnl particular case is worked around in spio_unix.c (environ with
dnl _GNU_SOURCE)
dnl
dnl       case "${PLATFORM}" in
dnl         x86-linux-glibc2.2)
dnl           dnl [PM] 4.0 system headers triggers -Wredundant-decls
dnl           SPIO_CFLAGS_DISABLE_WREDUNDANT_DECLS=yes
dnl           AC_SUBST(SPIO_CFLAGS_DISABLE_WREDUNDANT_DECLS)
dnl         ;;
dnl       esac
dnl 
dnl        if test "${SPIO_CFLAGS_DISABLE_WREDUNDANT_DECLS:-no}" != "yes"; then
dnl           gcc_warnings="$gcc_warnings -Wredundant-decls"
dnl        fi
       
       if test "${ICC:-no}" = "yes"; then
          :
       else
         # Some additional warnings
         gcc_warnings="$gcc_warnings -W"
       fi

       # Turn off some that are turned on by -W
       if test "x$picky_cc" = "xno"; then # turn off no warnings with picky cc
          gcc_warnings="$gcc_warnings -Wno-sign-compare" # signed unsigned compares are everywhere
       fi
dnl GCC
    dnl [PM] 3.10.1b1 Up to 3.10.0 behavior was as if CFLAGS="$CFLAGS $gcc_warnings"
    dnl      Now instead put warning options on CFLAGS_EXTRA so they
    dnl      can be enabled in release builds as well
    CFLAGS_EXTRA="$CFLAGS_EXTRA $gcc_warnings"

dnl GCC
    dnl [PM] 3.9.1 Some platforms has too broken headers for this to work. They set cc_warnings_are_errors to "" below.
    dnl      -Werror is  put into CFLAGS_EXTRA later on.
    dnl if test "x$cc_warnings_are_errors" = "xyes"; then
    dnl    CFLAGS_EXTRA=" -Werror"
    dnl fi
    cc_Werror="-Werror"

    # [PM] 4.2.1+

    if test "${CLANG:-no}" = "yes"; then
      # [PM] 4.3 
      cc_Wconversion_option='-Wconversion -Wno-sign-conversion'
      cc_Wno_conversion_option='-Wno-conversion'    
    elif test "$GCC_MAJOR" -gt "4" || { test "$GCC_MAJOR" = "4" && test "$GCC_MINOR" -ge "3"; }; then # >= 4.3
      cc_Wconversion_option='-Wconversion -Wno-sign-conversion'
      cc_Wno_conversion_option='-Wno-conversion'
    else # < 4.2
      # [PM] 4.2.1+ -Wconversion in GCC <= 4.2 is something else, that we do not want.
      cc_Wconversion_option=''
      cc_Wno_conversion_option='-Wno-conversion'
    fi

    if test "x$picky_cc" != "xno"; then
       CFLAGS_EXTRA="-Wstrict-prototypes $CFLAGS_EXTRA"
       CFLAGS_EXTRA="-Wmissing-declarations -Wmissing-prototypes $CFLAGS_EXTRA"

       if test $picky_cc -gt 1; then
          # -Wshadow is off by default since there are hard to avoid cases in wam().
          CFLAGS_EXTRA="-Wshadow $CFLAGS_EXTRA"
       fi
dnl GCC
       if test $picky_cc -gt 2; then
          # Warns about, e.g., casting a return value of integral type
          # to a pointer or vice versa. Happens a lot in SICStus (TAGGED<->Ptr)
          # So, it is pretty useless for SICStus
          # We could perhaps start using a type-safe cast, something like:
          # To cast x of type From to y of type To do (in a suitable macro):
          # {
          #   From tmp_x = x; // $(CC) will barf if x not close to type From
          #   To tmp_y = (To)tmp_x; // -Wbad-function-cast will not complain
          #   tmp_y # GCC extension, tmp_y is the value returned from the compound expression
          # }
          # Could then define Cast so that y = Cast(To,From,x) expands to the above.
          # Without GCC we could use inline functions, one for each From type,
          # inline From castFrom(From x) { return x; }
          # #define Cast(To,From,X) (To) cast ## From ((x))
          # Thus y = Cast(void*,TAGGED,x) expands to y = (void*)castTAGGED(x)
          # (This gives a "type safe" cast but does not help the -Wbad-function-cast issue.)
          #          
          CFLAGS_EXTRA="-Wbad-function-cast $CFLAGS_EXTRA"
dnl GCC
          # This is turned off by default above
          CFLAGS_EXTRA="-Wsign-compare $CFLAGS_EXTRA"

          # Very common in SICStus, thus not very useful.
          CFLAGS_EXTRA="-Wconversion $CFLAGS_EXTRA"

          CFLAGS_EXTRA="-Wunused $CFLAGS_EXTRA"
       fi
    fi

dnl GCC
    NO_UNKNOWN_PRAGMAS="-Wno-unknown-pragmas"

    AC_SUBST(NO_UNKNOWN_PRAGMAS)

    if test "${ENABLE_GPROF:-unset}" = "yes"; then
	CFLAGS_EXTRA="-pg ${CFLAGS_EXTRA}"
        SPLD_EXE_LDFLAGS="${SPLD_EXE_LDFLAGS} -pg"
        dnl [PM] 4.0 gprof does not seem to work well if sprt is a DSO
        SPLD_TOOLFLAGS="${SPLD_TOOLFLAGS:+${SPLD_TOOLFLAGS} }--static"
    fi
    if test "${ENABLE_GCOV:-unset}" = "yes"; then
	CFLAGS_EXTRA="-fprofile-arcs -ftest-coverage ${CFLAGS_EXTRA}"
        dnl [PM] 4.0 Apparenly no extra flags needed when linking
    fi

dnl GCC
    AC_MSG_CHECKING([whether -fstrict-aliasing should be used])
    dnl [PM] 3.9.0 strict-aliasing is the default in some versions of
    dnl GCC including GCC 3. Unfortunately SICStus run-time seems to
    dnl break the aliasing rules.
    dnl As an example X is 1.0. tends to bind X to some surprising value.
    dnl -fno-strict-aliasing is supported by all versions of GCC that we care about (2.95 onwards)
    dnl xref SPLD_CONFIG_CFLAGS
    dnl Probably need to go after -O2
    use_fstrict_aliasing_default=no
    AC_ARG_ENABLE(fstrict-aliasing, [  --enable-fstrict-aliasing    Internal ],
        [use_fstrict_aliasing="${enableval}"],
        [use_fstrict_aliasing="${use_fstrict_aliasing_default}"])
    if test "${use_fstrict_aliasing:-no}" = "yes"; then
      AC_MSG_RESULT([yes])
      # [PM] 4.1 It is the default for < -O2
      CFLAGS_EXTRA_SEMANTICS="$CFLAGS_EXTRA_SEMANTICS -fstrict-aliasing"
    else
      AC_MSG_RESULT([no])
      CFLAGS_EXTRA_SEMANTICS="$CFLAGS_EXTRA_SEMANTICS -fno-strict-aliasing"
    fi

    dnl [PM] 4.0.2+ experiment with turning it back on now that we use gcc 4.x mostly
    DISABLE_WSEQUENCE_POINT_DEFAULT=no
    AC_ARG_ENABLE(Wsequence-point, [  --disable-Wsequence-point    Internal ],
        [DISABLE_WSEQUENCE_POINT="${enableval}"]
        [DISABLE_WSEQUENCE_POINT="${DISABLE_WSEQUENCE_POINT_DEFAULT}"])

    if test "${DISABLE_WSEQUENCE_POINT:-no}" = "yes"; then
      dnl [PM] 3.9.0 The GCC 3 sequence point warning trigger for the
      dnl            code generated for SICStus API functions declared
      dnl            SPEXPFLAG_PREINIT. As far as I can see the warning
      dnl            is incorrect for those cases. (Still true for MacOS X gcc (GCC) 3.1 20020420 (prerelease))
      dnl
      dnl            The warning needs to be turned off also when spld
      dnl            compiles user code that calls the SICStus API.
      dnl Add the option only if this version of gcc supports it.
      AC_MSG_CHECKING(whether the C compiler (${CC}) supports -Wno-sequence-point)
      if ${CC} -Wno-sequence-point -S -o /dev/null -x c /dev/null >/dev/null 2>&1; then
         AC_MSG_RESULT(yes)
         dnl must come after -W and others that turn on -Wsequence-point
         CFLAGS_EXTRA="$CFLAGS_EXTRA -Wno-sequence-point"
      else
         AC_MSG_RESULT(no)
      fi
    fi # DISABLE_WSEQUENCE_POINT

dnl GCC
    dnl [PM] 3.10.1 FIXME Should this be on CFLAGS_EXTRA
    dnl [PM] 3.9.1 detect if uninitialized global variables gets defined in several files.
    CFLAGS_EXTRA="$CFLAGS_EXTRA -fno-common"

    dnl [PM] 4.2.1 does it make sense to use -ffloat-store on non x86/x86_64 (e.g. PPC/SPARC)?
    if test "${ICC:-no}" = "yes"; then
      dnl [PM] 4.2.1 FIXME: float consistency?
      cflags_float_consistency=''
    elif test "${CLANG:-no}" = "yes"; then
      dnl [PM] 4.2.1 FIXME: float consistency?
      cflags_float_consistency=''
    else
      cflags_float_consistency="-ffloat-store"
    fi

    # Machine-specific GCC-options.
    case "`$UNAME -m`" in
	*86|x86*|i86*)
dnl             dnl [PM] 3.9.1 by default turn off the explicit requests for alignment
dnl             dnl Rationale:
dnl             dnl 1. These cause warnings with GCC 3.1 (SPRM 3403)
dnl             dnl 2. These are likely to be worse than what modern
dnl             dnl    versions of GCC can figure out by itself.
dnl             dnl 3. The old comment by Jojo indicate that he reached
dnl             dnl    the same conclusion a long time ago.
dnl             dnl However, consider -mcpu=i686 to schedule the code
dnl             dnl according to the preference of a particular processor.
dnl             AC_MSG_CHECKING([whether -malign-XXX should be used])
dnl             AC_ARG_ENABLE(malign,      [  --enable-malign      Internal use only.],
dnl                           [enable_x86_align_directives=$enableval],
dnl                           [enable_x86_align_directives=no])
dnl             AC_MSG_RESULT([$enable_x86_align_directives])
dnl
dnl             if test "${enable_x86_align_directives:-no}" = "yes"; then
dnl               dnl These probably does no good. --Jojo
dnl               CFLAGS="$CFLAGS -malign-loops=2 -malign-jumps=2 -malign-functions=2"
dnl             fi

dnl GCC

dnl [PM] 4.0 According to the GCC docs, GCC now turn it on for `-O',
dnl	    `-O2', `-O3', `-Os. (although this is probably wrong, the
dnl	    docs also says "     `-O' also turns on
dnl	    `-fomit-frame-pointer' on machines where doing so does not
dnl	    interfere with debugging."
dnl
	    case $PLATFORM in
		*solaris*)
                   # [PM] 4.2.3+ Ensure we disable it on i386 Solaris (so we do not require that Distrib/rbuild_vars passes it explicitly)
		   if test "${enable_64bit}" = "no"; then
dnl         On Solaris 10 i386 -fomit-frame-pointer seems to interfere
dnl	    with pthread_cancel. What happens is that we get a SIGSEGV
dnl	    when cancelling read(). On the stack is _ex_unwind_local()
dnl	    and, _t_cancel(). _ex_unwind_local crashes when it tries
dnl	    to dereference the value found in %ebx
                      enable_omit_framepointer_default=no
		   fi
		;;
		*-darwin*)
		   if test "${enable_64bit}" = "yes"; then
                      # [PM] 4.2.3+ Symptom was that library(tcltk) crashed in libunwind on OS 10.8.2 x86_64. SPRM 12939.
                      enable_omit_framepointer_default=no
		   fi
		;;
                *)
                   enable_omit_framepointer_default=yes
                ;;
	    esac


dnl	    # fomit-frame-pointer is not compatible with -pg
	    if test "${ENABLE_GPROF:-no}" = "yes"; then
               enable_omit_framepointer_default=no
            fi

            enable_omit_framepointer=dummy
            if test "${OPTFLAG:-no}" = "yes"; then
               AC_MSG_CHECKING([whether GCC option -fomit-frame-pointer should be used])
               AC_ARG_ENABLE(gcc-fomit-frame-pointer,      [--disable-gcc-fomit-frame-pointer       Internal use only.],
                             [enable_omit_framepointer=$enableval],
                             [enable_omit_framepointer=${enable_omit_framepointer_default}])
               AC_MSG_RESULT([$enable_omit_framepointer])
            fi # OPTFLAG
            if test ${enable_omit_framepointer} = yes; then
              fomit_frame_pointer="-fomit-frame-pointer"
            else
              fomit_frame_pointer=""
            fi
            CFLAGS_EXTRA="${CFLAGS_EXTRA} ${fomit_frame_pointer}"

            dnl 4.0 -mieee-fp "... handle correctly the case where the result of a comparison is unordered."
            if test "${ICC:-no}" = "yes"; then
              :
            elif test "${CLANG:-no}" = "yes"; then
              :
            else
              cflags_float_consistency="${cflags_float_consistency} -mieee-fp"
            fi
            
	    ;;

    esac


    dnl [PM] 4.0 this is really not GCC-specific. We should move this below and let compiler specifics set cflags_float_consistency
    if test "$float_consistency" = "yes"; then
       CFLAGS_EXTRA_SEMANTICS="$CFLAGS_EXTRA_SEMANTICS ${cflags_float_consistency}"
    fi

    if test "${DEBUG_BUILD:-no}" = "yes"; then
       dnl [PM] 4.0.5 may be set by --enable-valgrind/--with-valgrind
       : ${use_ftrapv_default=yes}
    else
       use_ftrapv_default=no
    fi
    AC_MSG_CHECKING([whether -ftrapv should be used])

    AC_ARG_ENABLE(ftrapv,      [  --enable-ftrapv            Internal GCC],
                  [use_ftrapv=$enableval],
                  [use_ftrapv=$use_ftrapv_default])

    if test "${use_ftrapv:-no}" = "yes"; then
       dnl [PM] 4.0 abort if signed integer arithmetics overflows.
       CFLAGS_EXTRA="$CFLAGS_EXTRA -ftrapv"
       AC_MSG_RESULT([yes])
    else
       AC_MSG_RESULT([no])
    fi
    # [PM] 4.2.1 add clang option -fcatch-undefined-behavior if -ftrapv
    if test "${use_ftrapv:-no}" = "yes"; then
       # [PM] 4.3 figure out the version specific options
       if test "${CLANG:-no}" = "yes"; then
          AC_MSG_CHECKING([whether clang supports -fsanitize=<checks> option])
          # [PM] 4.3 Apple clang does not accept the same options as
          # the corresponding LLVM version
          # Xcode 5.0.{0,1,2}  cc --version: Apple LLVM version 5.0 (clang-500.2.76) (based on LLVM 3.3svn)
          #   Supports -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error
          #   Does not support [-ftrapv] -fsanitize=undefined-trap
          #       clang: error: '-fsanitize-undefined-trap-on-error' required with '-fsanitize=undefined-trap' option
          #   Does not support [-ftrapv] -fsanitize=undefined
          #       Gives contradictory error messages:
          #       clang: error: '-fsanitize-undefined-trap-on-error' required with '-fsanitize=undefined' option
          #       clang: error: unsupported argument 'undefined' to option 'fsanitize='
          #
          # Xcode 5.1          cc --version: Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
          #   Supports [-ftrapv] -fsanitize-undefined-trap-on-error
          #        BUT: does not trap all (any?) of the things -fsanitize=undefined traps (e.g. ((int)1)<<100)
          #   Does not support [-ftrapv] -fsanitize=undefined
          #        Lack lib: ld: file not found: .../lib/darwin/libclang_rt.ubsan_osx.a
          #   Does not support [-ftrapv] -fsanitize=undefined -fsanitize-undefined-trap-on-error
          #        clang: error: invalid argument '-fsanitize=undefined' not allowed with '-fsanitize-undefined-trap-on-error'
          #   Does not support [-ftrapv] -fsanitize=undefined-trap [-fsanitize-undefined-trap-on-error]
          #        clang: error: unsupported argument 'undefined-trap' to option 'fsanitize='
          #   Does not support [-ftrapv] -fsanitize=undefined -fsanitize-undefined-trap-on-error
          #        clang: error: invalid argument '-fsanitize=undefined' not allowed with '-fsanitize-undefined-trap-on-error'

          # LLVM >= 3.3 seems to support -fsanitize=<check>
          if test ${clang_llvm_version_major:-0} -gt 3 || { test ${clang_llvm_version_major:-0} = 3 && test ${clang_llvm_version_minor:-0} -ge 3 ; } ; then
             clang_supports_sanitize_option=yes
          else
             clang_supports_sanitize_option=no
          fi
          AC_MSG_RESULT([$clang_supports_sanitize_option])

          clang_broken_sanitize_undefined=no

          AC_MSG_CHECKING([clang options to trap undefined behavior])
          if test ${clang_supports_sanitize_option:-no} = yes ; then
            case "${clang_apple_version:-unknown}" in
              unknown) # not Apple version
                # -fsanitize=undefined-trap and -fsanitize-undefined-trap-on-error is documented for LLVM 3.4 at least

                # [PM] 4.3 tested with port install clang-3.4
                # [PM] 4.3 undefined-trap works too but does not give the nice explanations
                # clang_sanitize_undefined_check_variant='undefined-trap'
                # clang_extra_sanitize_undefined_option='-fsanitize-undefined-trap-on-error'

		# Also reguires: Distrib/make.sh extra_kernel_shld_libs=-fsanitize=undefined SPLFRFLAGS='--verbose -fsanitize=undefined ' SPLDFLAGS='--verbose -fsanitize=undefined'
                dnl The full 'undefined' gives false positives on array range checks
                dnl clang_sanitize_undefined_check_variant='undefined'
                dnl clang_extra_sanitize_undefined_option=''
                
                dnl ,bounds -- cannot use array bounds checking since it triggers on our variadic arrays in structs
                dnl ,function -- not allowed in C, it seems
                clang_sanitize_undefined_check_variant='alignment,bool,enum,float-cast-overflow,float-divide-by-zero,integer-divide-by-zero,null,object-size,return,shift,signed-integer-overflow,unreachable'
                # Use -fno-sanitize-recover (to stop immediately on error)
                clang_extra_sanitize_undefined_option='-fno-sanitize-recover'
              ;;
              5.0)
                clang_sanitize_undefined_check_variant='undefined-trap'
                clang_extra_sanitize_undefined_option='-fsanitize-undefined-trap-on-error'
              ;;
              *) # 5.1 or newer
                # With luck we can enable this post Xcode 5.1:
                # clang_sanitize_undefined_check_variant='undefined'
                # clang_extra_sanitize_undefined_option=''
                clang_sanitize_undefined_check_variant=''
                clang_extra_sanitize_undefined_option='-fsanitize-undefined-trap-on-error'
                clang_broken_sanitize_undefined=yes
              ;;
            esac
            clang_trap_undefined_options="${clang_sanitize_undefined_check_variant:+-fsanitize=${clang_sanitize_undefined_check_variant}} ${clang_extra_sanitize_undefined_option}"

          else
            # [PM] 4.3 assume -fcatch-undefined-behavior is supported prior to LLVM 3.1
            clang_trap_undefined_options="-fcatch-undefined-behavior"
          fi
          AC_MSG_RESULT([${clang_trap_undefined_options}])
          CFLAGS_EXTRA="$CFLAGS_EXTRA ${clang_trap_undefined_options}"
          if test ${clang_broken_sanitize_undefined:-no} = "yes" ; then
	     AC_MSG_WARN([Trapping undefined behavior is broken in this version of clang ($clang_version)])
          fi

       fi # CLANG
    fi # -ftrapv


    # [PM] 4.1.3 Consider enabling _FORTIFY_SOURCE for release builds too
    if test "${DEBUG_BUILD:-no}" = "yes"; then
       use_fortify_source_default=yes
    else
       use_fortify_source_default=no
    fi
    AC_MSG_CHECKING([whether -D_FORTIFY_SOURCE=2 should be used])

    AC_ARG_ENABLE(fortify_source,      [  --enable-fortify_source            Internal GCC],
                  [use_fortify_source=$enableval],
                  [use_fortify_source=$use_fortify_source_default])


    if test "${use_fortify_source:-no}" = "yes"; then
       dnl [PM] 4.0 RH feature that adds run-time checks for buffer overflows etc.
       dnl [PM] 4.0 See <http://www.redhat.com/magazine/009jul05/features/execshield/#checks> (and SPRM 9679)
       CFLAGS_EXTRA="$CFLAGS_EXTRA -D_FORTIFY_SOURCE=2"
       AC_MSG_RESULT([yes])
    else
       AC_MSG_RESULT([no])
    fi

    if test "${DEBUG_BUILD:-no}" = "yes"; then
       use_stack_protector_all_default=yes
    else
       use_stack_protector_all_default=no
    fi
    # [PM] 4.1.3 Consider enabling -fstack-protector for release builds too.
    # [PM] 4.1.3 UPDATE: Do _not_ enable in release builds. It seems
    # to require libssp.so which may not be present on users machines
    # (was an issue when enabling stack protection on zjuk).

    if test "${DEBUG_BUILD:-no}" = "yes"; then
       use_stack_protector_default=yes
    else
       use_stack_protector_default=no
    fi

    use_stack_protector_explicit=no
    AC_ARG_ENABLE(stack-protector,      [  --enable-stack-protector            Internal GCC],
                  [use_stack_protector=$enableval
                   use_stack_protector_explicit=yes],
                  [use_stack_protector=$use_stack_protector_default])

    AC_ARG_ENABLE(stack-protector-all,      [  --enable-stack-protector-all            Internal GCC],
                  [use_stack_protector_all=$enableval],
                  [use_stack_protector_all=$use_stack_protector_all_default])

    use_stack_protector_disabled=no
    if test "${use_stack_protector_explicit:-no}" = "yes"; then
      if test "${use_stack_protector:-yes}" = "no"; then
        # [PM] 4.1.3 Explicitly disabled. Needed for platforms lacking libssp.so.
        use_stack_protector_disabled=yes
      fi # use_stack_protector
    fi # use_stack_protector_explicit


    AC_MSG_CHECKING([whether -fstack-protector-all should be used])
    if test "${use_stack_protector_disabled:-no}" = "yes"; then
      use_stack_protector_all=no
      AC_MSG_RESULT([no (explicitly disabled)])
    else
      if test "${use_stack_protector_all:-no}" = "yes"; then
        if test -n "${gcc_opt_fstack_protector_all}"; then
          AC_MSG_RESULT([yes])
          CFLAGS_EXTRA="${CFLAGS_EXTRA}${gcc_opt_fstack_protector_all:+ ${gcc_opt_fstack_protector_all}}"
        else
          AC_MSG_RESULT([no (option not supported by $CC)])
        fi
      else
        AC_MSG_RESULT([no])
      fi
    fi

    AC_MSG_CHECKING([whether -fstack-protector should be used])
    if test "${use_stack_protector_disabled:-no}" = "yes"; then
      use_stack_protector=no
      AC_MSG_RESULT([no (explicitly disabled)])
    else
      if test "${use_stack_protector:-no}" = "yes"; then
        if test -n "${gcc_opt_fstack_protector}"; then
          if test "${use_stack_protector_all:-no}" = "yes"; then
            AC_MSG_RESULT([no (implied by $gcc_opt_fstack_protector_all)])
          else
            AC_MSG_RESULT([yes])
            CFLAGS_EXTRA="${CFLAGS_EXTRA}${gcc_opt_fstack_protector:+ ${gcc_opt_fstack_protector}}"
          fi
        else
          AC_MSG_RESULT([no (option not supported by $CC)])
        fi
      else
        AC_MSG_RESULT([no])
      fi
    fi

    dnl [PM] 4.0 Note: The SunPro compilers also support this feature (under another name)
    AC_MSG_CHECKING([whether -fvisibility=hidden should be used])
    use_fvisibility_default=no
    AC_ARG_ENABLE(fvisibility,      [  --enable-fvisibility            Internal GCC/ELF],
                  [use_fvisibility=$enableval],
                  [use_fvisibility=$use_fvisibility_default])
    : ${use_fvisibility:=${use_fvisibility_default}}
    AC_MSG_RESULT([${use_fvisibility}])
    if test "${use_fvisibility}" = "yes"; then
      AC_DEFINE(SP_USE_GCC_VISIBILITY, [1])
      CFLAGS_EXTRA="${CFLAGS_EXTRA} -fvisibility=hidden"
      SP_USE_GCC_VISIBILITY=yes
    else
      SP_USE_GCC_VISIBILITY=no
    fi
    AC_SUBST(SP_USE_GCC_VISIBILITY)


dnl GCC
fi


dnl [PM] 3.8.7,3.9b2 [AC_CYGWIN] calls [AC_CANONICAL_HOST] and will thus
dnl            overwrite $host instead check $host_os (which will be
dnl            empty until we start using [AC_CANONICAL_HOST] but that
dnl            does not matter since we never build SICStus for cygwin
dnl            anyway.

case "x$host_os" in
  *cygwin* ) CYGWIN=yes;;
         * ) CYGWIN=no;;
esac
dnl [AC_CYGWIN()]


##################################################################
#
# Check for some misc programs
# 
##################################################################

AC_PROG_RANLIB()
AC_PROG_LN_S()
: ${LN='ln -s'}

AC_CHECK_PROG(RM,rm,rm)
AC_CHECK_PROG(CP,cp,cp)
AC_CHECK_PROG(MV,mv,mv)
AC_ARG_VAR([AR],[])
AC_CHECK_PROG(AR,ar,ar)
dnl [PD] 3.10.2 Move the TAR check to *after* the big platform case
dnl AC_CHECK_PROG(TAR,tar,tar)
AC_CHECK_PROG(CHMOD,chmod,chmod)

AC_MSG_CHECKING([if mkdir accepts -p])
mkdir_tmpdir=`pwd`/tmpdir/foo/bar
if mkdir -p $mkdir_tmpdir >/dev/null 2>&1 && test -d $mkdir_tmpdir; then
    AC_MSG_RESULT(yes)
    : ${MKDIR='mkdir -p'}
else
    AC_MSG_RESULT(no)
    : ${MKDIR="$TOP_SRCDIR/ensdir"}
fi
rm -rf `pwd`/tmpdir


dnl ============================================================
dnl ============================================================


# Misc. stuff

dnl [PM] 3.9.1 We are migrating from using LDFLAGS to using SPLD_EXE_LIBS
dnl            (which is more like what LIBS is supposed to be anyway)
dnl            Note, though, that LDFLAGS is passed to CC by
dnl            AC_CHECK_FUNCS et al.

unset LDFLAGS

# Remember if TCLLIB or TCLINC has ben set by the user.
if test ."$TCLLIB". != .. || test ."$TCLINC". != ..; then
    user_tcltk_config=yes
else
    user_tcltk_config=no
fi

# Some (currently only HP/UX) architectures requires statements of the
# form 'sleep 1' to placed at strategic places in the makefile in order 
# to ensure that targets are created strictly later than their dependencies.
#
# This defaults to ''.
SLEEP=''

dnl ##################################################################

# [PM] Support code needed for API dispatch table (sp_GlobalSICStus)
SPAUXOBJ="spaux.$OBJEXT"

dnl [PM] 3.9.1 This is always empty, used to be what is now SPAUXOBJ
SPAUXMAINOBJ=""


dnl
dnl [PD] 3.9.1 options for configure to set fields in the file Distrib/features
dnl

AC_ARG_WITH(installer-java-dirs,        [  --with-installer-java-dirs            Colon separated list of directories where SICStusInstaller should search for Java],
    [INSTALLER_JAVA_DIRS="$withval"],
    [])
AC_ARG_WITH(installer-tcltk-dirs,       [  --with-installer-tcltk-dirs           Colon separated list of directories where SICStusInstaller should search for TCL/TK],
    [INSTALLER_TCLTK_DIRS="$withval"],
    [])
AC_ARG_WITH(installer-bdb-dirs,         [  --with-installer-bdb-dirs             Colon separated list of directories where SICStusInstaller should search for BDB],
    [INSTALLER_BDB_DIRS="$withval"],
    [])

AC_SUBST(INSTALLER_JAVA_DIRS)
AC_SUBST(INSTALLER_TCLTK_DIRS)
AC_SUBST(INSTALLER_BDB_DIRS)

dnl ============================================================
dnl ============================================================

AC_MSG_CHECKING([for en_US.utf8 locale name])
# [PM] 4.1.3 platforms differ in case and hyphenation (delete space and tab, output by cygwin local command)
en_US_utf8_locale_name="`locale -a | ${POSIX_GREP} -i -e 'en_us\.utf-*8' | tr -d ' 	' 2>/dev/null`"
if test "${en_US_utf8_locale_name:+set}" = "set"; then
  AC_MSG_RESULT([${en_US_utf8_locale_name}])
  LC_ALL_UTF8_LOCALE_NAME="${en_US_utf8_locale_name}"
else
: ${LC_ALL_UTF8_LOCALE_NAME:='en_US.utf8'}
  AC_MSG_RESULT([none. Fallback to ${LC_ALL_UTF8_LOCALE_NAME}])
fi
AC_SUBST(LC_ALL_UTF8_LOCALE_NAME)


dnl ============================================================
dnl ============================================================

dnl [PM] 4.2.1+ 
sp_fli_apply_asm_generic_default=no
AC_ARG_ENABLE(generic-fli,      [  --enable-generic-fli            Use SPLFR-generated glue for FLI-calls],
        [
         case "${enableval:-no}" in
         yes)
           enableval=yes
           ;;
         *)
           enableval=no
           ;;
         esac
         SP_FLI_APPLY_ASM_GENERIC=$enableval
         PERSISTENT_CONFIGURE_OPTIONS="${PERSISTENT_CONFIGURE_OPTIONS} --enable-generic-fli=$enableval"
        ],
        [SP_FLI_APPLY_ASM_GENERIC=$sp_fli_apply_asm_generic_default])

##################################################################
#
# Check platform characteristics
# 
##################################################################


case $PLATFORM in
    *-win32*)
    ;;
    *)
        dnl only Windows can mix C and C++ freely.
        SUITE_SKIPPED_TESTS="${SUITE_SKIPPED_TESTS}${SUITE_SKIPPED_TESTS:+ }cplus cplus_stat"
    ;;
esac
dnl [PM] 4.2.1 All platforms are expected to fail these tests:

dnl [PM] 4.3 sprm11916 (writing variables) is fixed in 4.3:
dnl SUITE_EXPECTED_FAILURES="${SUITE_EXPECTED_FAILURES}${SUITE_EXPECTED_FAILURES:+ }sprm11916"

# [PM] 4.0 Set this to yes if SHLD is gcc (for -pg)
gcc_shld=no
HIGH_RESOLUTION_TIME_CP=no # assume cp -p drops some time info

case $PLATFORM in
    *-aix-*) dnl [PM] 3.9.1 rewrite
dnl AIX
        dnl needed for mutex initializer in multi_sp.c
        EXPECT_WARNINGS_MULTI_SP_C=yes

        if test "${GCC:-no}" = "yes"; then
          cc_opt_Wl="-Wl,"
          cc_opt_64bit="-maix64"
        else
          cc_opt_Wl=""
          cc_opt_64bit="-q64"
        fi
        ld_opt_64bit="-b64"
        if test $enable_64bit = yes; then
           cc_opt_32_or_64bit="$cc_opt_64bit"
           ld_opt_32_or_64bit="$ld_opt_64bit"
        else
           cc_opt_32_or_64bit=""
           ld_opt_32_or_64bit=""
        fi
        dnl [PM] WinCE used to go in config.c
        AC_DEFINE(SP_AIX)
        
        # [PM] 4.0 AIX default seems to be to limit this. We need unlimited for test suite
        ULIMIT_DATA='ulimit -d unlimited;'

dnl AIX
        dnl [PM] 3.9.1 One segment (0x10000000) is the same as
        dnl non-maxdata programs get but it ensures that malloc et
        dnl al will return memory at segment 3 instead of 2.
        dnl Since the JDK 1.3.1 Java launcher is a big data program
        dnl we can only be compatible with java-as-top-level if we
        dnl have a MallocBase compatible with large data programs
        dnl (i.e., programs linked with -bmaxdata).
        AC_MSG_CHECKING([whether SICStus executables should be configured for large address space])
        if test $enable_64bit = yes; then
          dnl SPRM 8306
          with_maxdata_default=no
        else
          with_maxdata_default=yes
        fi
        AC_ARG_WITH(maxdata,      [  --with-maxdata            Internal, AIX specific],
             [with_maxdata=$withval],
             [with_maxdata=$with_maxdata_default])
        case $with_maxdata in
          yes)
            maxdata_size="0x10000000"
            with_maxdata=yes
            ;;
          no)
            with_maxdata=no
            ;;
           *)
            maxdata_size="$with_maxdata"
            with_maxdata=yes
            ;;
        esac
        if test $enable_64bit = yes; then
          with_maxdata=no
          AC_MSG_RESULT([no, 64bit target])
        elif test $with_maxdata = yes; then
          dnl [PM] WinCE used to go in config.c
          AC_MSG_RESULT([yes, -bmaxdata:${maxdata_size}])
        else
          dnl [PM] WinCE used to go in config.c
          AC_MSG_RESULT([no])
        fi

dnl AIX

        dnl [PM] 3.9.1 NOTE: On AIX dynamically loadable object files
        dnl can have suffix .o and are traditionaly contained within
        dnl ar archives (with suffix .a). Thus, on AIX, a library
        dnl called foo.a may in fact be a dynamic library. We use the
        dnl new style dynamic libraries with suffix .so. However, we
        dnl do not use dynamic linking, we use import/export files as
        dnl is traditional on AIX (similar to Windows import
        dnl libraries).
        dnl
dnl AIX
        dnl [PM] 3.9.1 authoritive sources on net says that (as of AIX 
        dnl            4.x) -H512 -T512 should not be used.
        dnl [PM] April 2000 (3.8.3).
        dnl      . Use -G. This should also fix the duplicate symbols
        dnl      warnings (caused by the default autoexp option).
        dnl      . Drop the -H and -T options. Why they were used have
        dnl        been lost in time. They affect alignment of text,
        dnl        data, loader sections (-H) and the starting address
        dnl        of the text section (-T).
        dnl      . Drop -bexpall from SPLFR_SHLDFLAGS since splfr now
        dnl        generates an export file on-the-fly
        dnl      . Add -bernotok since this is what was always the
        dnl        default until -G was added. (report error on
        dnl        unresolved external references). not critical, the -G
        dnl        provided default -berok perhaps makes more sense.
        dnl      . Drop -bnolibpath from SHLDFLAGS. SHLDFLAGS is only
        dnl        used for building spld<XX>.so and the only libpaths
        dnl        that could come into play would be from -L args of
        dnl        which there are none when building spld<XX>.so
        dnl        Note that spld uses AIXNOLIBPATH when -bnolibpath is
        dnl        really needed (spld --movable).
        dnl Older notes:
        dnl SHLDFLAGS could possibly be replaced by a simple "-G", which 
        dnl according to the manual is equivalent to the -b options erok,
        dnl rtl, nortllib, nosymbolic, noautoexp, and M:SRE.
dnl AIX
        dnl [PM] 4.0 Now other platforms complains so we set LIBS to KERNEL_SHLD_LIBS below
        dnl dnl [PM] 3.9.1 This is needed for AC_CHECK_LIB(tcl...)
        dnl dnl            It is somewhat of a mystery why no other platforms complains
        dnl LIBS="$LIBS -lm"

dnl AIX
        dnl : ${SHLDFLAGS='-H512 -T512 -bM:SRE -brtl -bnolibpath -lc -lm'}
        dnl : ${SPLFR_SHLDFLAGS='-H512 -T512 -bM:SRE -brtl -bexpall -lc -lm'}

        if test $enable_cc_shld = "default"; then

           dnl [PM] 3.9.1 UPDATE: We now does some ugly things to
           dnl avoid generating calls to __ashldi3. This is so that
           dnl non-GCC main apps can dlopen our GCC compiled dynamic
           dnl libraries. See CANNOT_USE_LARGE_INT_SHIFT in sicstus.c
           dnl
           dnl [PM] 3.9.1 With gcc we need to use gcc as
           dnl shld. Otherwise we get "ld: 0711-317 ERROR: Undefined
           dnl symbol: .__ashldi3". I beleive ashldi3 is used when
           dnl shifting 64bit integers (which we started doing in
           dnl 3.9.1beta 3 as part of
           dnl SP_put_integer_bytes/SP_get_integer_bytes).
           enable_cc_shld=yes
        fi
dnl AIX
        : ${LD=ld}
        gcc_shld=no
        cc_shld=no
        if test $enable_cc_shld = "yes"; then
           : ${SHLD="${CC}"}
           if test "${GCC:-no}" = "yes"; then
              gcc_shld=yes
           else
              cc_shld=yes
           fi
        else
           : ${SHLD="$LD"}
        fi
dnl AIX
        dnl [PM] 3.9.1 FIXME consider -textro (at least for debug builds)


        dnl [PM] 3.9.1 pre 3.9 was:
        dnl : ${SHLDFLAGS='-G -bernotok -lc -lm'}
        dnl : ${SPLFR_SHLDFLAGS='-G -bernotok -lc -lm'}

dnl [MC]	if test "${SPIO:-no}" != "no"; then
dnl [MC]	   dnl [PM] 4.0 not tested
dnl [MC]	   spio_libs="-lrt"
dnl [MC]	fi
        dnl [PM] 3.9.1 -lm needed? yes (e.g., Suite resinit_static)
        dnl            -lpthread needed? yes (e.g., Suite resinit_static)

        if test "${GCC:-no}" != "yes"; then # !GCC
          # needed both when compiling and linking
          cc_qthreaded='-qthreaded'
        fi # !GCC
        ld_qthreaded='-qthreaded'

        SPLD_EXE_LIBS="-lm -lpthread ${spio_libs}"
        dnl [PM] 3.9.1 used by spld --jnilib
        SPLD_JNI_LIBS="-lm -lpthread ${spio_libs}"

        bdb_extra_libs="-lpthread ${spio_libs}"

        dnl FIXME check if -lm is needed if SHLD != ld
        KERNEL_SHLD_LIBS="$SPLD_EXE_LIBS"
dnl AIX
        if test $gcc_shld = yes; then
          shld_opt_Wl='-Wl,'
          dnl [PM] 3.9.1 FIXME: Do we need/want to use -Wl,-bernotok; -bnoentry, -bsymbolic -btextro (gcc default I think); more?
          dnl Apparently we do not need -bnoentry
          SHLDFLAGS='--shared'
          SHLDFLAGS="$SHLDFLAGS ${cc_qthreaded}" # [PM] 4.0
          SHLDFLAGS="$SHLDFLAGS ${cc_opt_32_or_64bit}"
        elif test $cc_shld = yes; then
          shld_opt_Wl=''
          SHLDFLAGS=''
          SHLDFLAGS="$SHLDFLAGS ${cc_qthreaded}" # [PM] 4.0
          SHLDFLAGS="$SHLDFLAGS ${cc_opt_32_or_64bit}"
          dnl cc takes the same options as ld but -G is special (which 
          dnl is not mentioned in the C docs but in a RedBook).
          dnl man ld: "The -G flag is equivalent to specifying the
          dnl erok, rtl, nortllib, nosymbolic, noautoexp, and M:SRE
          dnl options with the -b flag."
          dnl Add the -G equivalent options, except:
          dnl   -brtl -bnortllib (added below)
          dnl   -berok (we want -bernotok, added below)
          dnl   -bnosymbolic (we want -bsymbolic, added below)
          SHLDFLAGS="$SHLDFLAGS -bnoautoexp -bM:SRE"

          dnl no entry point
          SHLDFLAGS="$SHLDFLAGS -bnoentry"

          dnl below
          dnl dnl undefined symbols should give error
          dnl SHLDFLAGS="$SHLDFLAGS -bernotok"
          dnl below
          dnl dnl [PM] 3.9.1 -bsymbolic is the recommended (but non-default) setting
          dnl SHLDFLAGS="$SHLDFLAGS -bsymbolic"
dnl AIX
        else # SHLD=$LD
          shld_opt_Wl=''
          dnl AC_MSG_WARN([FIXME: need -lc and -lm (and more?) if SHLD is $LD])
          KERNEL_SHLD_LIBS="-lc $KERNEL_SHLD_LIBS"

          SHLDFLAGS='-G'
          SHLDFLAGS="$SHLDFLAGS ${ld_opt_32_or_64bit}"

          dnl no entry point
          SHLDFLAGS="$SHLDFLAGS -bnoentry"
          SHLDFLAGS="$SHLDFLAGS ${ld_qthreaded}" # [PM] 4.0

          dnl below
          dnl dnl undefined symbols should give error
          dnl SHLDFLAGS="$SHLDFLAGS -bernotok"
          dnl below
          dnl dnl [PM] 3.9.1 -bsymbolic is the recommended (but non-default) setting
          dnl SHLDFLAGS="$SHLDFLAGS -bsymbolic"

          dnl [PM] 3.9.1 -lc is needed with ld but should be added by C-compiler automatically
          SHLDFLAGS="$SHLDFLAGS -lc"
        fi
dnl AIX
        dnl [PM] 3.9.1 -brtl is needed for ld to look for shared
        dnl objects named *.so (even though we do not need run-time
        dnl linking) (note that on AIX shared objects can be contained
        dnl in *.a files, so looking for .so extension is non-standard
        dnl on AIX). (One symptom without this was that libspnative.so
        dnl linked with libsprt39.a which contains only the static
        dnl version).
        dnl
        dnl -bnortllib should always be used for shared objects since,
        dnl if it is needed at all, it should only be linked to the
        dnl main executable.
        SHLDFLAGS="$SHLDFLAGS ${shld_opt_Wl}-brtl ${shld_opt_Wl}-bnortllib"

        dnl [PM] 3.9.1b4 undefined symbols should give error
        SHLDFLAGS="$SHLDFLAGS ${shld_opt_Wl}-bernotok"

        dnl [PM] 3.9.1b4 -bsymbolic is the recommended (but non-default) setting
        SHLDFLAGS="$SHLDFLAGS ${shld_opt_Wl}-bsymbolic"


        SPLFR_SHLDFLAGS="$SHLDFLAGS"

dnl AIX
        dnl [PM] 3.8.4 solved this instead by building a static version of tcltk as well.
        dnl            *BUG* LDFLAGS is passed to SHLFR_LD even if
        dnl            SHLFR_LD is ld and not (g)cc. This is a bug
        dnl            since LDFLAGS are linker flags for (G)CC, e.g.,
        dnl            -Wl,-brtl. In the forthcoming cleanup we should
        dnl            perhaps do as tcltk, i.e., se if SHLFR_LD etc
        dnl            are ld and in that case replace -Wl, with space
        dnl            (and then all commas with space too).
        dnl        # [PM] 3.8.4 This is needed so that AC_CHECK_LIB will find the DLL version of tcl/tk.
        dnl        #      I do not know the ramification of using -brtl for sicstus. Might be the right thing.
        dnl     if test "${GCC:-no}" = "yes"; then
        dnl                     : ${LDFLAGS="-Wl,-brtl"}
        dnl        else # [PM] untested
        dnl                     : ${LDFLAGS="-brtl"}
        dnl        fi
dnl AIX
        dnl [PM] CC_NOLIBPATH is passed by spld to ${CC} when building --moveable
        dnl      -bnolibpath means roughly "do not add -L<DIR>s to RPATH"
        dnl      -bnoipath means ignore path components of any libs
        dnl      specified with full paths (as opposed to -l<LIB>)
        dnl used to be called AIXNOLIBPATH
        dnl AIXNOLIBPATH="-bnolibpath -bnoipath"
        if test "${GCC:-no}" = "yes"; then
          CC_NOLIBPATH="-Wl,-bnolibpath -Wl,-bnoipath"
        else # CC != gcc
          CC_NOLIBPATH="-bnolibpath -bnoipath"
        fi

        dnl [PM] 3.9.1 FIXED: AIXRTL could go on
        dnl            @SPLD_EXE_DYNAMIC_LDFLAGS if we had such a
        dnl            beast (we only have @SPLD_EXE_LDFLAGS which is
        dnl            used even if --static is passed to spld (but
        dnl            that may not be a problem!? Even with spld
        dnl            --static we want to be able to open shared
        dnl            objects! So, put AIXRTL on SPLD_EXE_LDFLAGS!
        dnl            Rationale: spld --static should not produce a
        dnl            static executable but rather an executable that 
        dnl            links with a static version of the SP runtime
        dnl            and resources.
dnl AIX
        dnl [PM] 3.9.1 docs are confusing. However, it seems that
        dnl            -brtl is needed to link against .so files
        dnl            (which we want to do).
        dnl            -brtl implies -bsymbolic and -brtllib
        dnl            On the other hand the docs seems to imply that
        dnl            -bnortl (the default) will ensure that symbols
        dnl            found in a .so file by ld will resolve at
        dnl            run-time to definition in the same .so file,
        dnl            even if the symbol is also defined in other
        dnl            loaded .so files (this is something like what
        dnl            MacOS X does, I believe). So, maybe we want
        dnl            -bnortl (or is it -brtl -bno? But we probably want -bsymbolic
dnl AIX
        dnl [PM] 3.9.1 We do rely on .so files (so need -brtl) but
        dnl            could probably cope with -nortllib (no run-time
        dnl            linking needed now that we use SP_DISPATCH_API)

        dnl [PM] 3.10.1 JDK 1.3.1 with sicstus as top-level will barf with 
        dnl   _XmGetDefaultDisplay cannot be used prior to VendorS.Initialize, returns NULL
        dnl       stackpointer=34a8b298
        dnl if sicstus is built with just -brtl (we _must_ use -brtl for the linker to find libsprtXX.so)
        dnl (The _XmGetDefaultDisplay is a symptom of libXt symbols being found before libXm (Motif) symbols).
        dnl However, we can use -brtl -bnortllib to avoid run-time
        dnl linking but still tell the linker to look for .so-files.
        dnl Note that the JDK 1.3.1 README.html does say:
        dnl    The Developer Kit does not support runtime linking
        dnl    (using the -brtl loader option). Any applications built
        dnl    for use with the Developer Kit should not rely on
        dnl    runtime linking functionality.
        dnl Which I ([PM]) suspect is not really referring to the
        dnl 'Motif' problem but still indicates that using -brtl is
        dnl dangerous at best.
        AC_MSG_CHECKING([whether spld should build executables with -bnortllib])
        AC_ARG_ENABLE(nortllib,      [  --disable-nortllib            Internal AIX],
             [aix_spld_exe_nortllib=$enableval],
             [aix_spld_exe_nortllib=yes])

        if test "x${aix_spld_exe_nortllib}" != "xno"; then
          AC_MSG_RESULT([yes])
          SPLD_EXE_NORTLLIB="${cc_opt_Wl}-bnortllib"
        else
          AC_MSG_RESULT([no])
          SPLD_EXE_NORTLLIB=""
        fi
dnl AIX

        SPLD_EXE_LDFLAGS="$SPLD_EXE_LDFLAGS ${cc_qthreaded}" # [PM] 4.0
        SPLD_EXE_LDFLAGS="$SPLD_EXE_LDFLAGS ${cc_opt_Wl}-brtl ${SPLD_EXE_NORTLLIB}"
        SPLD_EXE_LDFLAGS="$SPLD_EXE_LDFLAGS ${cc_opt_32_or_64bit}"
        
        if test "x${with_maxdata}" = "xyes"; then
          SPLD_EXE_LDFLAGS="$SPLD_EXE_LDFLAGS ${cc_opt_Wl}-bmaxdata:${maxdata_size}"
        fi

dnl ============================================================
dnl ============================================================

        LDFLAGS="$SPLD_EXE_LDFLAGS"

dnl AIX
        dnl LD_ROPT="-blibpath:"
        # [PM] 3.9.1 AIX ld will add any -L<DIR> to libpath so spld need not do it
        LD_BUILDS_RPATH_FROM_L=yes

        dnl [PM] 3.9.1 no symbol prefix in export files
        EXPFILE_SYMBOL_PREFIX=""
dnl AIX
        dnl [PM] 3.9.1 the name rtkernel.exp will cause a simple file
        dnl with one line per exported symbol to be built by
        dnl Emulator/Makefile.

        RTKERNEL_EXPFILE=rtkernel.exp
        gcc_ropt="-Wl,-blibpath:"
        ld_ropt="-blibpath:"
        cc_ropt="${ld_ropt}"

        if test "${GCC:-no}" = "yes"; then
          CC_ROPT="$gcc_ropt"
        else
          CC_ROPT="$cc_ropt"
        fi

        ld_SHLD_RTKERNELEXP='-bE:$(filter $(RTKERNEL_EXPFILE),$^)'
        ld_SPLFR_SHLD_EXPORT_ARG='-bE:@SP_EXPORT_FILE@'
dnl AIX
        if test $gcc_shld = yes; then
          dnl part of a make action Emulator/Makefile
          SHLD_RTKERNELEXP="-Wl,${ld_SHLD_RTKERNELEXP}"
          SPLFR_SHLD_EXPORT_ARG="-Wl,${ld_SPLFR_SHLD_EXPORT_ARG}"
          SHLD_ROPT="$gcc_ropt"
          SPLD_SHLD_JNILIB_FLAGS=""
        elif test $cc_shld = yes; then
          dnl part of a make action
          SHLD_RTKERNELEXP="${ld_SHLD_RTKERNELEXP}"
          SPLFR_SHLD_EXPORT_ARG="${ld_SPLFR_SHLD_EXPORT_ARG}"
          SHLD_ROPT="$cc_ropt"
          dnl [PM] 3.9.1b4 We do not have an expfile for spnative.c
          dnl      When SHLD=gcc gcc (collect2) automatically creates an expfile.
          dnl
          dnl      Using -G with xlc also produce an expfile (this is
          dnl      according to some IBM non-xlc docs that also
          dnl      mentions that this is contrary to the xlc docs).
          dnl
          dnl SPLD_SHLD_JNILIB_FLAGS="-bexpall"
          dnl [PM] 3.9.1b4 UPDATE: the xlc -G flag is apparently not
          dnl      supported by the C compiler we have. Fallback to
          dnl      -bexpall (FIXME: ideally configure should check if
          dnl      xlc -G is supported).
          dnl SPLD_SHLD_JNILIB_FLAGS="-G"
          SPLD_SHLD_JNILIB_FLAGS="-bexpall"
        else # SHLD = $LD
          dnl part of a make action
          SHLD_RTKERNELEXP="${ld_SHLD_RTKERNELEXP}"
          SPLFR_SHLD_EXPORT_ARG="${ld_SPLFR_SHLD_EXPORT_ARG}"
          SHLD_ROPT="$ld_ropt"
          dnl [PM] 3.9.1b4 not tested (but we should no longer use SHLD=ld)
          SPLD_SHLD_JNILIB_FLAGS="-bexpall"
        fi
        dnl [PM] 3.9.1 experiment, the docs are not clear about if export file can be used with ld -r
        dnl SPLFR_LD_EXPORT_ARG='-bE:@SP_EXPORT_FILE@'
        SPLFR_LD_EXPORT_ARG="${ld_SPLFR_SHLD_EXPORT_ARG}"

        SPLFR_LD_r_FLAGS=""
        SPLFR_LD_r_FLAGS="$SPLFR_LD_r_FLAGS ${ld_opt_32_or_64bit}"

dnl AIX
        dnl [PM] 3.9.1 no need to export anything from spld-generated
        dnl            exe (because we now use SP_DISPATCH_API)
        dnl # [PM] 3.8.4 SPRM 1516, Use the export file for (static)
        dnl #            development system too.
        dnl #            cleaner than -bexpall, i.e., -rdynamic or -Wl,-E
        dnl #            used on other platforms. 
        dnl #            We should use explicit export on all platforms
        dnl #            (or stub/dispatch table)
        dnl # [PM] 3.8.5 SPRM 1707
        dnl # Was: 
        dnl # : ${AIXDSEXP="-Wl,-bE:${TOP_SRCDIR}/Emulator/sprt.exp"}
        dnl : ${AIXDSEXP="-Wl,-bE:$SP_BINDIR/sprt-${SICSTUS_VERSION_STRING}.exp"}
dnl AIX
        dnl [PM] 3.9.1 not needed.
        dnl # [PM] 3.9 Used by InstallSICStus. If empty do not attempt to install it.
        dnl : ${SP_EXPFILE="sprt.exp"}
        
        dnl [PM] 3.9.1 FIXME pass  -halt:0 to linker for debugging
        if test "${GCC:-no}" != "yes"; then
            if test "${OPTFLAG:-no}" != "no"; then
                dnl [PM] 3.9.1b4 we got segfaults at resource loading with      
                dnl these opt flags. CFLAGS="$CFLAGS -O3 -qstrict"
                dnl [PM] 3.9.1b4 try these less aggressive settings:
                dnl      (-O is the same as -O2)
                CFLAGS="$CFLAGS -O"
dnl AIX
                dnl [PM] 3.9.1b4 still get SIGSEGV all over the place
                dnl      (e.g., Suite/arithm) with -O. See if the
                dnl      aliasing assumptions is the cause.
                dnl      (Note that similar aliasing asumptions are
                dnl      known to cause (other) trouble with gcc so
                dnl      they should be turned off).
                dnl
                dnl -qoption default value "ansi:typeptr:noallptrs:noaddrtaken"
                dnl
                dnl Purpose 
                dnl Requests the compiler to apply aliasing assertions to your
                dnl compilation unit. The compiler will take advantage of the aliasing
                dnl assertions to improve optimizations where possible, unless you
                dnl specify otherwise.
                dnl
                dnl Example 
                dnl To specify worst-case aliasing assumptions when compiling myprogram.c, enter:
                dnl 
                dnl xlc myprogram.c -O -qalias=noansi
                dnl
                CFLAGS="$CFLAGS -qalias=noansi"

                dnl [PM] 3.9.1b4 Let cc use unlimited memory for optimization.
                dnl              Note that -O3 implies -qmaxmem=-1
                CFLAGS="$CFLAGS -qmaxmem=-1"
            fi dnl OPTFLAG!=no

            if test "${DEBUG_BUILD:-no}" = "yes"; then
              if test "${picky_cc:-no}" != "no"; then
                dnl [PM] 3.10 warn about 64-bit issues such as pointer to int conversions
                CFLAGS_EXTRA="$CFLAGS_EXTRA -qwarn64"
              fi
            fi
            dnl [PM] 4.0 disable some warnings we do not care about in release builds
            if test "${DEBUG_BUILD:-no}" = "no"; then
              # 1506-221 (E) Initializer must be a valid constant expression.
              CFLAGS_EXTRA="$CFLAGS_EXTRA -qsuppress=1506-221"
            fi
                        
        fi dnl GCC!=yes

        dnl [PM] 4.0 These should go on CFLAGS, not just on CFLAGS_EXTRA_SEMANTICS
        CFLAGS="${CFLAGS} ${cc_qthreaded} -D_THREAD_SAFE"

        dnl [PM] 64bit file offsets
        CFLAGS_EXTRA_SEMANTICS="${CFLAGS_EXTRA_SEMANTICS} -D_LARGE_FILES"

        dnl [PM] 3.10 -q64 can probably affect the preprocessor symbols
        CPPFLAGS="$CPPFLAGS ${cc_opt_32_or_64bit}"
        dnl [PM] FIXME: We should start using $(CC) $(CPPFLAGS) $(CFLAGS) instead of just $(CC) $(CFLAGS) 
        dnl             or prepend CPPFLAGS to CFLAGS before AC_SUBST.
        CFLAGS="$CFLAGS ${cc_opt_32_or_64bit}"

        if test $enable_64bit = yes; then
           dnl The default is to ignore 64bit objects
           dnl 32
           dnl   Processes only 32-bit object files
           dnl 64
           dnl   Processes only 64-bit object files
           dnl 32_64
           dnl   Processes both 32-bit and 64-bit object files
           ARFLAGS="-X 64" # We could use 32_64
        fi
dnl AIX


dnl [PM] 4.1.3+ gone
dnl        # [Jojo] 'uname' talks mumbo-jumbo here
dnl        hardware="rs6000"

        # [PM] 3.12.8 Was always required (see relnotes.tex) but some update for java now aborts if LDR_CNTRL is not set correctly
        java_env_vars="AIXTHREAD_SCOPE=S AIXTHREAD_MUTEX_DEBUG=OFF AIXTHREAD_RWLOCK_DEBUG=OFF AIXTHREAD_COND_DEBUG=OFF LDR_CNTRL=USERREGS"

        dnl [PM] 3.12.8 Need to add ``${LD_LIBRARY_PATH_name}=${java_ld_library_path}'' to JASPER_ENV_ARGS
        jasper_env_args_need_LD_LIBRARY_PATH=yes

        JASPER_ENV_ARGS="${JASPER_ENV_ARGS} ${java_env_vars}"

        FLI_FILE=fli_dl.c
        case $PLATFORM in
          rs6000-*)
            if test "${SP_FLI_APPLY_ASM_GENERIC:-no}" != "yes"; then
              FLI_APPLY_ASM_FILE=fli_rs6000_aix.s
              AC_DEFINE(FLI_APPLY_ASM_ABI_PPC, [1])
            fi
            ASFLAGS=''
          ;;
          rs600064-*)
            if test "${SP_FLI_APPLY_ASM_GENERIC:-no}" != "yes"; then
              FLI_APPLY_ASM_FILE=fli_rs6000_aix64.s
              AC_DEFINE(FLI_APPLY_ASM_ABI_PPC, [1])
            fi
            ASFLAGS='-a64 -mppc64'
          ;;
        esac

        dnl [PM] 3.9.1 I do not know what libld is (and can't be
        dnl bothered to look it up). Let's see if it is really needed.
        dnl tcltk_extra_libs="$tcltk_extra_libs -lld"

        LD_LIBRARY_PATH_name="LIBPATH"
        dnl [PM] 3.9.1 these should not be used as -L<DIR> or module specific rpath 
        dnl This was an issue with AIX JDK 1.3.1 java.library.path that contains /usr/lib
        sys_L_dirs="/lib:/usr/lib"

        dnl [PM] 3.10 setitimer signals sometimes arrive too early. See library/timeout.c
        AC_DEFINE(SETITIMER_EARLY)

	dnl [PD] 3.10.2  We need a default path to find the standard tar.
	DEFAULT_POSIX_PATH=/usr/bin
dnl AIX
        ;;
    hppa-hpux-*)
dnl HPUX32
        dnl [PM] 3.9.1 complete rewrite.

        AC_DEFINE(SP_HPUX, [1])

        dnl [PM] 3.9.1 shl_unload is broken (it does not maintain a
        dnl            reference count). for this reason we cannot
        dnl            support multiple sicstuses that all load the
        dnl            same dynamic foreign resource into the same
        dnl            process. (or rather, the problem comes when
        dnl            they try to unload the foreign resource).
        dnl NOTE:      If we ever enable multi-sp we must do something
        dnl            about the problem with using SHLD_RTKERNELEXP
        dnl            with gcc, see gcc_shld below.

        : ${SP_NO_MULTI_SP_FEATURE="yes"}
        dnl [PM] 3.11.2 /bin/sh tends to get SIGBUS during install
        : ${INSTALLSICSTUS_SH=/bin/ksh}

        dnl [PM] WinCE used to go in config.c

dnl [PM] 4.1.3+ gone
dnl	hardware=`$UNAME -m`

        dnl Man stdsyms(5) tells all about POSIX/XOPEN/...

dnl HPUX32
        dnl [PM] 3.9.1 ld -r -d will cause problems like:
        dnl /usr/bin/ld: Duplicate symbol "__tdsize" in files ...system.s.o and ...charsio.s.o
        dnl (at least with GCC but since we are using ld -r directly
        dnl here I do not thing this problem is GCC specific (unless
        dnl __tdsize is a GCC-specific symbol))
        dnl
        dnl dnl [PM] 3.9.1 Experiment with using -d (a.k.a no-common)
        dnl SPLFR_LD_r_FLAGS="-d"
        SPLFR_LD_r_FLAGS=""

        : ${LD=ld}
        SPLFR_LD_EXPORT_ARG=''
        SPLFR_LD_r_FLAGS=''

        dnl [PM] 3.9.1 use ${CC} for linking. This is the only correct
        dnl way. If you think differently you are mistaken (although,
        dnl as the single exception, HPUX 11 cc cannot link shared
        dnl libraries)

        if test $enable_cc_shld = "default"; then
           enable_cc_shld=yes
        fi
dnl HPUX32
        if test "${GCC:-no}" != "yes"; then

           dnl [PM] 3.9.1 HPUX 11 cc is not able to produce shared
           dnl libraries, all HP examples use ld when building shared
           dnl libs.

           enable_cc_shld=no
        fi

        gcc_shld=no
        cc_shld=no
        ld_shld=no
        if test $enable_cc_shld = "yes"; then
           : ${SHLD="${CC}"}
           if test "${GCC:-no}" = "yes"; then 
             gcc_shld=yes
           else # SHLD is cc/c89
              dnl [PM] see enable_cc_shld above
              AC_MSG_ERROR([Internal error cannot use cc for linking shared libraries])
              cc_shld=yes
           fi
        else # [PM] 3.9.1 SHLD is ld by default in 3.8 and 3.9.0. Probably CC is better
           : ${SHLD="$LD"}
           ld_shld=yes
        fi
dnl HPUX32
        if test $gcc_shld = yes; then     # SHLD = GCC

dnl gcc FAQ: (on why -fpic is needed when linking too)
dnl        Why can't I build a shared library?
dnl
dnl        When building a shared library you may get an error message
dnl        from the linker like `assert pure-text failed:' or `DP
dnl        relative code in file'.
dnl
dnl        This kind of error occurs when you've failed to provide
dnl        proper flags to gcc when linking the shared library.
dnl
dnl        You can get this error even if all the .o files for the
dnl        shared library were compiled with the proper PIC
dnl        option. When building a shared library, gcc will compile
dnl        additional code to be included in the library. That
dnl        additional code must also be compiled with the proper PIC
dnl        option.
dnl
dnl        Adding the proper PIC option (-fpic or -fPIC) to the link
dnl        line which creates the shared library will fix this problem
dnl        on targets that support PIC in this manner. For example:
dnl
dnl          gcc -c -fPIC myfile.c
dnl          gcc -shared -o libmyfile.so -fPIC myfile.o
dnl
dnl HPUX32
           SHLDFLAGS="-shared -fPIC"
           dnl [PM] 3.9.1 see SPLD_EXE_LDFLAGS for these
           SHLDFLAGS="$SHLDFLAGS -Wl,+s,+b,:"

           gcc_shld_export_opt="-Wl,+e,"

           dnl [PM] 3.9.1 FIXME:
           dnl AC_MSG_WARN([SHOULD RE-ENABLE_ SPLFR_SHLD_EXPORT_ARG/PM])
           dnl
           dnl [PM] 3.9.1 see spld case below, got problem with prelinking
           dnl dynamic foreign resources.
           dnl SPLFR_SHLD_EXPORT_OPT="${gcc_shld_export_opt}"
           dnl SPLFR_SHLD_EXPORT_OPT=""
           SPLFR_SHLD_EXPORT_ARG=""

           dnl We cannot hide all other symbols since this will give:
           dnl /usr/bin/ld: Unsatisfied symbols:
           dnl    _GLOBAL__FD_libsprt39_sl (code)
           dnl    _GLOBAL__FI_libsprt39_sl (code)
           dnl These symbols are apparently used by GCC to call static
           dnl (C++) constructors and destructors. Search the net but
           dnl found nothing.
           dnl This is not a showstopper since we cannot use multi-sp
           dnl anyway due to the tragic state of shld_unload, see
           dnl SP_NO_MULTI_SP_FEATURE above.
           dnl

           dnl Further analysis (in the context of static pre-linking
           dnl with dynamic foreign resources) reveals that the
           dnl problem is with collect2, it creates a C file that
           dnl refers to the _GLOBAL__FD and _FI symbols, presumably
           dnl since nm does not show these as hidden although they
           dnl really are. On the other hand, if there are
           dnl constructors then we do want them to be called (but
           dnl then also when we use shl_load...)

           dnl SHLD_RTKERNELEXP="${gcc_shld_export_opt}SP_get_dispatch"
           SHLD_RTKERNELEXP=""

        elif test $cc_shld = yes; then # SHLD = cc
           AC_MSG_ERROR([SHLD=cc (${CC}) not  supported for $PLATFORM])
        elif test $ld_shld = yes; then
dnl HPUX32
           dnl from man ld:
           dnl [PM] 3.9.0 Probably do not need -E (a.k.a. -rdynamic) anymore 
           dnl  -E             This option is accepted but ignored by the 64 bit
           dnl                 ld.  Mark all symbols defined by a program for
           dnl                 export to shared libraries.  By default, ld marks
           dnl                 only those symbols that are actually referenced by
           dnl                 a shared library seen at link time.


           dnl [PM] 3.8 did this: : ${SHLDFLAGS='-b -E +b : +s'}

           dnl  -b             Create a shared library rather than a normal
           dnl                 executable file.  Object files processed with this
           dnl                 option must contain position-independent code
           SHLDFLAGS="-b"
dnl HPUX32
           dnl  +s             Indicates that at run-time, the shared library
           dnl                 loader can use the environment variable SHLIB_PATH
           dnl                 and LD_LIBRARY_PATH (64 bit only) to locate shared
           dnl                 libraries needed by the executable output file
           dnl                 that were specified with either the -l or -l:
           dnl                 option. The environment variables should be set to
           dnl                 a colon-separated list of directories. If both +s
           dnl                 and +b are used, their relative order on the
           dnl                 command line indicates which path list will be
           dnl                 searched first (see the +b option).
           dnl
           dnl [PM] 3.9 +s before +b so SHLIB_PATH is preferred
           SHLDFLAGS="$SHLDFLAGS +s"

           dnl  +b path_list   Specify a colon-separated list of directories to
           dnl                 be searched at program run-time to locate shared
           dnl                 libraries needed by the executable output file
           dnl                 that were specified with either the -l or -l:
           dnl                 option.  An argument consisting of a single colon
           dnl                 (:) indicates that ld should build the list using
           dnl                 all the directories specified by the -L option and
           dnl                 the LPATH environment variable (see the +s
           dnl                 option).
           dnl
           SHLDFLAGS="$SHLDFLAGS +b :"

           ld_shld_export_opt="+e " # note space at end
           SPLFR_SHLD_EXPORT_ARG="${ld_shld_export_opt}@SP_MAIN_NAME@"
           SHLD_RTKERNELEXP="${ld_shld_export_opt}${SP_GET_DISPATCH_NAME}"

        fi

dnl HPUX32
	: ${SHSFX='sl'}
	dnl LD_ROPT=""
        CC_ROPT=""
        SHLD_ROPT=""

	dnl [PM] 3.9 1 does not seem to be needed anymore
        dnl SLEEP='sleep 1'

	FLI_FILE=fli_hpux.c
        LD_LIBRARY_PATH_name="SHLIB_PATH"

        dnl [PM] 3.9.1
        dnl AC_MSG_ERROR([LDFLAGS set, should use SPLD_EXE_LIBS])
        dnl : ${LDFLAGS="-ldld"}

        dnl [PM] 4.0 not tested
        spio_libs="-lrt"

dnl HPUX32

        SPLD_EXE_LIBS="-lm -ldld -lpthread ${spio_libs}"
        KERNEL_SHLD_LIBS="$SPLD_EXE_LIBS"


dnl Man pthread(3T):
dnl      Note: When explicitly specifying ANSI compilation (via "-Aa"),
dnl      defining the POSIX revision level restricts the program to using
dnl      interfaces within the POSIX namespaces.  If interfaces in the larger
dnl      X/Open namespace are to be called, either of the compiler options,
dnl      -D_XOPEN_SOURCE_EXTENDED or -D_HPUX_SOURCE, must be specified in
dnl      addition to -D_POSIX_C_SOURCE=199506L.  Alternatively, compiling with
dnl      -Ae (or not specifying "-A") will implicitly specify -D_HPUX_SOURCE.
dnl
dnl      Note: Some documentation will recommend the use of -D_REENTRANT for
dnl      compilation.  While THIS also FUNCTIONS PROPERLY, it is considered an
dnl      obsolescent form. (my emph.)

dnl HPUX32

dnl Man stdsyms(5)
dnl           _HPUX_SOURCE
dnl                     The programmer can define the _HPUX_SOURCE feature test
dnl                     macro to obtain the HP-UX namespace and complete HP-UX
dnl                     functionality.  Note that the HP-UX namespace is
dnl                     currently a superset of all of the above mentioned
dnl                     namespaces. ([PM] i.e., POSIX, XPG4)
dnl [PM] 3.9.1 I take this to mean that -D_HPUX_SOURCE subsumes -D_REENTRANT 
dnl but -D_REENTRANT ought not to do any harm.

        dnl [PM] 3.8.5 HPUX 11
        dnl When not using -Ae with HP c++ we need -D_HPUX_SOURCE to
        dnl define isnan/isfinite in math.h. See man page for
        dnl isnan(3m)
        defs="-D_HPUX_SOURCE"
        defs="$defs -D_REENTRANT"

        EXPECT_WARNINGS_MULTI_SP_C=yes
        dnl [PM] 3.10 see if EXPECT_WARNINGS_MULTI_SP_C=yes suffice
        dnl dnl [PM] 3.9.1 headers are too broken, we cannot avoid warnings. In particular PTHREAD_MUTEX_INITIALIZER.
        dnl cc_warnings_are_errors=no
dnl HPUX32
        dnl we use ld flags "+s +b :" to make ld embed -L<dir>s on runpath
        LD_BUILDS_RPATH_FROM_L=yes

        if test "${GCC:-no}" = "yes"; then
            CFLAGS="$CFLAGS ${defs}"
            dnl [PM] 3.9.1 CPPFLAGS needed?
            CPPFLAGS="$CPPFLAGS ${defs}"

            dnl [PM] 3.9.1b4 FIXME: what gcc options correspond to +DAportable, +DS2.0?

            dnl gcc 2.95.2 seems to (no docs, sorry) pass -z to ld (*NULL => SIGSEGV)

            dnl [PM] 3.9.1 gcc 2.95.2 docs does not list HPUX
            dnl processors among those where -fpic vs -fPIC makes a
            dnl difference. This contradicts the fact that both +z and
            dnl +Z exists for cc.
            dnl But, cannot blame the docs, FSF does not support GCC 2.XX for HP-UX at all
            : ${INCR_CFLAGS='-fPIC'}
            dnl [PM] 3.9.1 " +s +b :" gives behavior similar to AIX with -L<dirs> embedded
            dnl also on SHLDFLAGS
            SPLD_EXE_LDFLAGS="$SPLD_EXE_LDFLAGS -Wl,+s,+b,:"
dnl HPUX32
        else dnl !GCC test "${GCC:-no}" != "yes"
            dnl [PM] 3.10.1 for non-GCC AC PROG CC does not add -O
            if test "$OPTFLAG" != "no"; then
                CFLAGS="$CFLAGS -O"
            fi

            CFLAGS="$CFLAGS ${defs}"
            dnl [PM] 3.9.1 CPPFLAGS needed?
            CPPFLAGS="$CPPFLAGS ${defs}"

            dnl -Ae "compilation in ANSI C mode with HP C
            dnl      extensions. This option is the same as specifying
            dnl      -Aa, -D_HPUX_SOURCE, and +e. This is the default
            dnl      for the HP-UX 10.30 and later operating system
            dnl      releases." (So -D_HPUX_SOURCE above is redundant with -Ae)

            dnl Note that c89 does not accept (but will ignore) -Ae
            dnl and -Aa so explicit "-Aa +e -D_HPUX_SOURCE" may be a
            dnl better idea (+e *is* accepted by c89)

            CFLAGS="$CFLAGS -Ae"

            dnl "+DAportable generates code compatible across all HP
            dnl 9000 workstations and servers"

            CFLAGS="$CFLAGS +DAportable"

            dnl [PM] -z disallows NULL referencing
            dnl      -Z (default) *NULL = zero 
            dnl      (not to be confused with +z/+Z)

            CFLAGS="$CFLAGS -z"
dnl HPUX32
            dnl -dynamic
            dnl "This option produces dynamically bound
            dnl  executables. These support shared libraries and use
            dnl  the features of the dynamic loader. The shl_load and
            dnl  dlopen APIs are fully supported. The linker links in
            dnl  shared libraries first and then archive
            dnl  libraries. Only PIC is supported."
            dnl
            dnl -dynamic is the default according to the docs of the
            dnl -noshared option.
            dnl
            dnl Consider putting -dynamic on SPLD_EXE_LDFLAGS instead
            CFLAGS="$CFLAGS -dynamic"
dnl HPUX32
            dnl Instruction scheduling.
            dnl "Object code with scheduling tuned for a particular
            dnl  model or processor will execute on other HP 9000
            dnl  systems, although possibly less efficiently"
            dnl "If you plan to run your program on both PA-RISC 1.1 and
            dnl  2.0 systems, in general we recommend you use +DS2.0"
            CFLAGS="$CFLAGS +DS2.0"

            dnl It seems we cannot safely use +ESnoparmeloc due to how 
            dnl HP compiles their own libraries.
dnl HPUX32

            dnl cc +z is like -fpic +Z is like -fPIC
            dnl "Generates object code that can be added to a shared
            dnl  library. Object code generated with this option is
            dnl  position independent, containing no absolute
            dnl  addresses. All addresses are either pc-relative or
            dnl  indirect references. This is the same as the +Z
            dnl  option in 64-bit mode. The -pand -G options are
            dnl  incompatible with this option and are ignored. See
            dnl  the HP-UX Linker and Libraries Online User Guide for
            dnl  detailed information on shared libraries."
            dnl [PM] 3.9.1 Use +Z/-fPIC (+z probably would *often* work
            dnl            too and be a little faster)
            : ${INCR_CFLAGS='+Z'}
            SPLD_EXE_LDFLAGS="$SPLD_EXE_LDFLAGS -Wl,+s,+b,:"
dnl HPUX32
            if test "${DEBUG_BUILD:-no}" = "yes"; then
               # -w1 all warnings, -w2 only warn if code generation could be affected, -w3 no warnings
               CFLAGS="$CFLAGS -w1"
            fi
dnl HPUX32
            dnl [PM] warn about possibly uninitialized variables and do not init them
            CFLAGS="$CFLAGS +Onoinitcheck"

            if test no != "$OPTFLAG"; then # Optimization related flags for cc
                dnl [PM] 3.9.1 consider adding +Osize (inhibit optimizations that increase size of code)

                dnl [PM] 3.9.1 tell us if cc optimizer encounters internal errors
                CFLAGS="$CFLAGS +Onofail_safe"

                dnl do not limit time spent optimizing
                CFLAGS="$CFLAGS +Onolimit"
                
                dnl [PM] 3.10.1 +Ofastaccess is incompatible with -g
                dnl dnl fast access to global data (whatever it is, it sounds like something we want)
                dnl CFLAGS="$CFLAGS +Ofastaccess"

                dnl Do not assume that the type of a pointer tells
                dnl anything about what it could alias (similar to
                dnl -fno-strict-aliasing)
                dnl
                dnl Rationale: gcc -fstrict-aliasing is known to cause
                dnl problems on some platforms so I turn this off for
                dnl safety. Note that optimizations based on type safe
                dnl aliasing is already off by default, we only make
                dnl it explicit)
                CFLAGS="$CFLAGS +Onoptrs_strongly_typed +Onoptrs_ansi"

                dnl [PM] 3.9.1b4 removed due to cold feet. CFLAGS will 
                dnl also be used (by spld/splfr) to compiler user code 
                dnl which may use shared memory.
                dnl dnl +signedpointers will give incorrect results if shared memory is used. We do not use shared memory
                dnl CFLAGS="$CFLAGS +Osignedpointers"

            fi
        fi
	dnl [PD] 3.10.2  We need a default path to find the standard tar.
	DEFAULT_POSIX_PATH=/usr/bin
dnl HPUX32
        ;;

    ipf*-hpux-*)
    dnl Itanium Processor Family (IPF), also known as Intel Architecture 64 (ia64)

dnl HPUXIPF
        dnl [PM] 3.10.2 Started ia64 HPUX 11 port. Note, all
        dnl      pre-3.10.2 comments refer to the older 32bit HPPA port
        dnl cc -V says cc: HP ANSI C++/C B3910B A.05.36 [May 20 2002]
        dnl aCC -V sayse aCC: HP ANSI C++/C B3910B A.05.36 [May 20 2002]

        dnl 3.10.2 FIXME:
        dnl Consider cc -exec for main programs
        dnl   -exec          Indicates that any object files created will be used to
        dnl                  create an executable file.  Constants with a protected
        dnl                  or hidden export class are placed in the read-only data
        dnl                  section.  This option also implies -Bprotected and
        dnl                  -dynamic.
        dnl Consider cc -mt to get multi-thread safe defines and -lpthread
        dnl Check if the HP compiler still has the SP_INHIBIT_IMPLICIT_APIPROCINIT bug.
        dnl    (bug last seen in cc -V cc: HP aC++/ANSI C B3910B A.05.41 [Nov 1 2002])

        
        dnl [PM] 3.9.1 complete rewrite.

        dnl [PM] 3.9.1 shl_unload is broken (it does not maintain a
        dnl            reference count). for this reason we cannot
        dnl            support multiple sicstuses that all load the
        dnl            same dynamic foreign resource into the same
        dnl            process. (or rather, the problem comes when
        dnl            they try to unload the foreign resource).
        dnl NOTE:      If we ever enable multi-sp we must do something
        dnl            about the problem with using SHLD_RTKERNELEXP
        dnl            with gcc, see gcc_shld below.

        AC_DEFINE(SP_HPUX, [1])

        dnl [PM] 3.10.2 Using ELF dlopen instead of broken shl_unload
        dnl : ${SP_NO_MULTI_SP_FEATURE="yes"}
        : ${SP_NO_MULTI_SP_FEATURE="no"}

dnl [PM] 4.1.3+ gone
dnl	hardware=`$UNAME -m`

dnl HPUXIPF

        if test $enable_64bit = yes; then
           dnl [PM] 3.10.2 We need the 64-bit version of the JDK 1.4.1 JVM
           : ${JAVA_EXECOPTS=-d64}
        fi
        dnl [PM] JDK 1.4.1 libjvm.so cannot be loaded via dlopen (due
        dnl      to its use of thread local storage.
        enable_preload_jvm=yes
        LIBJVM_SO_name="libjvm.so"
        LD_PRELOAD_name="LD_PRELOAD"

        if test "${GCC:-no}" != "yes"; then
           dnl [PM] 3.10.2 See spaux.h.in for details
           AC_DEFINE(SP_INHIBIT_IMPLICIT_APIPROCINIT)
        fi


        if test "${GCC:-no}" = "yes"; then
          cc_opt_Wl="-Wl,"
          cc_opt_32bit="-milp32"
          cc_opt_64bit="-mlp64"
        else
          cc_opt_Wl="-Wl,"
          cc_opt_32bit="+DD32"
          cc_opt_64bit="+DD64"
        fi
        ld_opt_32bit="+DD32"
        ld_opt_64bit="+DD64"

        if test $enable_64bit = yes; then
           cc_opt_32_or_64bit="$cc_opt_64bit"
           ld_opt_32_or_64bit="$ld_opt_64bit"
        else
           cc_opt_32_or_64bit="$cc_opt_32bit"
           ld_opt_32_or_64bit="$ld_opt_32bit"
        fi

        dnl Man stdsyms(5) tells all about POSIX/XOPEN/...

dnl HPUXIPF
        dnl [PM] 3.9.1 ld -r -d will cause problems like:
        dnl /usr/bin/ld: Duplicate symbol "__tdsize" in files ...system.s.o and ...charsio.s.o
        dnl (at least with GCC but since we are using ld -r directly
        dnl here I do not thing this problem is GCC specific (unless
        dnl __tdsize is a GCC-specific symbol))
        dnl
        dnl dnl [PM] 3.9.1 Experiment with using -d (a.k.a no-common)
        dnl SPLFR_LD_r_FLAGS="-d"
        SPLFR_LD_r_FLAGS=""

        : ${LD=ld}
        SPLFR_LD_EXPORT_ARG=''
        SPLFR_LD_r_FLAGS=''


        dnl [PM] 3.9.1 use ${CC} for linking. This is the only correct
        dnl way. If you think differently you are mistaken (although,
        dnl as the single exception, HPUX 11 cc cannot link shared
        dnl libraries)

        if test $enable_cc_shld = "default"; then
           enable_cc_shld=yes
        fi
dnl HPUXIPF

        dnl [PM] 3.10.2 cc is now the recommended linker
        dnl if test "${GCC:-no}" != "yes"; then 
        dnl    dnl [PM] 3.9.1 HPUX 11 cc is not able to produce shared
        dnl    dnl libraries, all HP examples use ld when building shared
        dnl    dnl libs.
        dnl    enable_cc_shld=no
        dnl fi

        gcc_shld=no
        cc_shld=no
        ld_shld=no
        if test $enable_cc_shld = "yes"; then
           : ${SHLD="${CC}"}
           if test "${GCC:-no}" = "yes"; then 
             gcc_shld=yes
           else # SHLD is cc/c89
              dnl dnl [PM] see enable_cc_shld above
              dnl AC_MSG_ERROR([Internal error cannot use cc for linking shared libraries])
              cc_shld=yes
           fi
        else # [PM] 3.9.1 SHLD is ld by default in 3.8 and 3.9.0. Probably CC is better
           : ${SHLD="$LD"}
           ld_shld=yes
        fi
dnl HPUXIPF
        if test $gcc_shld = yes; then     # SHLD = GCC
          dnl AC_MSG_ERROR([gcc not yet supported in 64bit HP-UX ($PLATFORM)])

dnl gcc FAQ: (on why -fpic is needed when linking too)
dnl        Why can't I build a shared library?
dnl
dnl        When building a shared library you may get an error message
dnl        from the linker like `assert pure-text failed:' or `DP
dnl        relative code in file'.
dnl
dnl        This kind of error occurs when you've failed to provide
dnl        proper flags to gcc when linking the shared library.
dnl
dnl        You can get this error even if all the .o files for the
dnl        shared library were compiled with the proper PIC
dnl        option. When building a shared library, gcc will compile
dnl        additional code to be included in the library. That
dnl        additional code must also be compiled with the proper PIC
dnl        option.
dnl
dnl        Adding the proper PIC option (-fpic or -fPIC) to the link
dnl        line which creates the shared library will fix this problem
dnl        on targets that support PIC in this manner. For example:
dnl
dnl          gcc -c -fPIC myfile.c
dnl          gcc -shared -o libmyfile.so -fPIC myfile.o
dnl
dnl HPUXIPF
           dnl [PM] 3.10.2 docs hint that IPF always -fPIC, should not hurt to be explicit
           SHLDFLAGS="-shared -fPIC"

           dnl [PM] 3.10.2 FIXME: RUNPATH/RPATH issues
           dnl dnl [PM] 3.9.1 see SPLD_EXE_LDFLAGS for these
           dnl SHLDFLAGS="$SHLDFLAGS -Wl,+s,+b,:"

           gcc_shld_export_opt="-Wl,+e,"

           SHLDFLAGS="$SHLDFLAGS ${cc_opt_32_or_64bit}"
           ld_shld_export_opt="-Wl,+e,"
           SPLFR_SHLD_EXPORT_ARG="${ld_shld_export_opt}@SP_MAIN_NAME@"
           SHLD_RTKERNELEXP="${ld_shld_export_opt}${SP_GET_DISPATCH_NAME}"

           dnl We cannot hide all other symbols since this will give:
           dnl /usr/bin/ld: Unsatisfied symbols:
           dnl    _GLOBAL__FD_libsprt39_sl (code)
           dnl    _GLOBAL__FI_libsprt39_sl (code)
           dnl These symbols are apparently used by GCC to call static
           dnl (C++) constructors and destructors. Search the net but
           dnl found nothing.
           dnl This is not a showstopper since we cannot use multi-sp
           dnl anyway due to the tragic state of shld_unload, see
           dnl SP_NO_MULTI_SP_FEATURE above.
           dnl
dnl HPUXIPF
           dnl Further analysis (in the context of static pre-linking
           dnl with dynamic foreign resources) reveals that the
           dnl problem is with collect2, it creates a C file that
           dnl refers to the _GLOBAL__FD and _FI symbols, presumably
           dnl since nm does not show these as hidden although they
           dnl really are. On the other hand, if there are
           dnl constructors then we do want them to be called (but
           dnl then also when we use shl_load...)

           dnl dnl SHLD_RTKERNELEXP="${gcc_shld_export_opt}SP_get_dispatch"
           dnl SHLD_RTKERNELEXP=""

        elif test $cc_shld = yes; then # SHLD = cc
           dnl AC_MSG_ERROR([SHLD=cc (${CC}) not  supported for $PLATFORM])

           dnl [PM] 3.10.2 man cc:
           dnl    -b             Cause the linker ld(1) to create a shared library
           SHLDFLAGS="$SHLDFLAGS -b "

           SHLDFLAGS="$SHLDFLAGS ${cc_opt_32_or_64bit}"
           ld_shld_export_opt="-Wl,+e,"
           SPLFR_SHLD_EXPORT_ARG="${ld_shld_export_opt}@SP_MAIN_NAME@"
           SHLD_RTKERNELEXP="${ld_shld_export_opt}${SP_GET_DISPATCH_NAME}"

        elif test $ld_shld = yes; then
          AC_MSG_ERROR([SHLD=ld not yet supported in 64bit HP-UX ($PLATFORM)])

dnl HPUXIPF
           dnl from man ld:
           dnl [PM] 3.9.0 Probably do not need -E (a.k.a. -rdynamic) anymore 
           dnl  -E             This option is accepted but ignored by the 64 bit
           dnl                 ld.  Mark all symbols defined by a program for
           dnl                 export to shared libraries.  By default, ld marks
           dnl                 only those symbols that are actually referenced by
           dnl                 a shared library seen at link time.


           dnl [PM] 3.8 did this: : ${SHLDFLAGS='-b -E +b : +s'}

           dnl  -b             Create a shared library rather than a normal
           dnl                 executable file.  Object files processed with this
           dnl                 option must contain position-independent code
           SHLDFLAGS="-b"
dnl HPUXIPF
           dnl  +s             Indicates that at run-time, the shared library
           dnl                 loader can use the environment variable SHLIB_PATH
           dnl                 and LD_LIBRARY_PATH (64 bit only) to locate shared
           dnl                 libraries needed by the executable output file
           dnl                 that were specified with either the -l or -l:
           dnl                 option. The environment variables should be set to
           dnl                 a colon-separated list of directories. If both +s
           dnl                 and +b are used, their relative order on the
           dnl                 command line indicates which path list will be
           dnl                 searched first (see the +b option).
           dnl
           dnl [PM] 3.9 +s before +b so SHLIB_PATH is preferred
           SHLDFLAGS="$SHLDFLAGS +s"

           dnl  +b path_list   Specify a colon-separated list of directories to
           dnl                 be searched at program run-time to locate shared
           dnl                 libraries needed by the executable output file
           dnl                 that were specified with either the -l or -l:
           dnl                 option.  An argument consisting of a single colon
           dnl                 (:) indicates that ld should build the list using
           dnl                 all the directories specified by the -L option and
           dnl                 the LPATH environment variable (see the +s
           dnl                 option).
           dnl
           SHLDFLAGS="$SHLDFLAGS +b :"

           ld_shld_export_opt="+e " # note space at end
           SPLFR_SHLD_EXPORT_ARG="${ld_shld_export_opt}@SP_MAIN_NAME@"
           SHLD_RTKERNELEXP="${ld_shld_export_opt}${SP_GET_DISPATCH_NAME}"

        fi # ld_shld

dnl HPUXIPF
        dnl [PM] 3.10.2 ILP32 and PA64/ILP64/ia64 use .so
	: ${SHSFX='so'}

        dnl [PM] 3.10.2 SysV dlopen et al
	FLI_FILE=fli_dl.c
        LD_LIBRARY_PATH_name="LD_LIBRARY_PATH"

        dnl [PM] 4.0 not tested
        spio_libs="-lrt"

        dnl [PM] 3.10.2 FIXME: Should we add -lwp as is used in some Java JNI example?
        SPLD_EXE_LIBS="-ldl -lm -lpthread ${spio_libs}"

        KERNEL_SHLD_LIBS="$SPLD_EXE_LIBS"

        dnl [PM] 3.10.2 We must avoid -lxnet since that is not the
        dnl default *and* is not binary compatible with getsockname et
        dnl al. in libc.so.. Therefore we must also avoid
        dnl _XOPEN_SOURCE_EXTENDED (which gives the prototypes that
        dnl corresponds to -lxnet and thus makes the executable
        dnl require -lxnet)
        dnl See library/sockets.c and
        dnl SP_FORCE_SOCKETS_XOPEN_SOURCE_EXTENDED (which should never
        dnl be used).
        dnl
        dnl 
        dnl dnl [PM] 3.10.2 it is not enough to link sockets.so with
        dnl dnl      -lxnet, it needs to go into the main executable.
        dnl dnl      
        dnl dnl dnl [PM] 3.10.2 without -lxnet Suite/autosock fails to work (FIXME: may not be enough!).
        dnl dnl dnl My guess is that _XOPEN_SOURCE_EXTENDED requires -lxnet
        dnl dnl : ${SOCKETLIB='-lxnet'}
        dnl SPLD_EXE_LIBS="$SPLD_EXE_LIBS -lxnet"
        
        dnl [PM] 3.10.2 Also, we must not use socklen_t even though it
        dnl is defined in the headers, since getsockname et al is
        dnl *not* prototyped to use it when !_XOPEN_SOURCE_EXTENDED
        dnl Shortcut the AC_CHECK_TYPES below by setting the cached
        dnl value
        ac_cv_type_socklen_t=no

dnl Man pthread(3T):
dnl      Note: When explicitly specifying ANSI compilation (via "-Aa"),
dnl      defining the POSIX revision level restricts the program to using
dnl      interfaces within the POSIX namespaces.  If interfaces in the larger
dnl      X/Open namespace are to be called, either of the compiler options,
dnl      -D_XOPEN_SOURCE_EXTENDED or -D_HPUX_SOURCE, must be specified in
dnl      addition to -D_POSIX_C_SOURCE=199506L.  Alternatively, compiling with
dnl      -Ae (or not specifying "-A") will implicitly specify -D_HPUX_SOURCE.
dnl
dnl      Note: Some documentation will recommend the use of -D_REENTRANT for
dnl      compilation.  While THIS also FUNCTIONS PROPERLY, it is considered an
dnl      obsolescent form. (my emph.)

dnl HPUXIPF

dnl Man stdsyms(5)
dnl           _HPUX_SOURCE
dnl                     The programmer can define the _HPUX_SOURCE feature test
dnl                     macro to obtain the HP-UX namespace and complete HP-UX
dnl                     functionality.  Note that the HP-UX namespace is
dnl                     currently a superset of all of the above mentioned
dnl                     namespaces. ([PM] i.e., POSIX, XPG4, and presumably _XOPEN_SOURCE_EXTENDED)
dnl [PM] 3.9.1 I take this to mean that -D_HPUX_SOURCE subsumes -D_REENTRANT 
dnl but -D_REENTRANT ought not to do any harm.

        dnl [PM] 3.10.2 We must never use _XOPEN_SOURCE_EXTENDED on HP-UX IPF64 (see above)
        dnl [PM] 3.8.5 HPUX 11
        dnl When not using -Ae with HP c++ we need -D_HPUX_SOURCE to
        dnl define isnan/isfinite in math.h. See man page for
        dnl isnan(3m)
        defs="-D_HPUX_SOURCE"
        defs="$defs -D_REENTRANT"

        dnl [PM] 3.10.2 Still needed with gcc and ipf-hpux-B.11.22
        EXPECT_WARNINGS_MULTI_SP_C=yes

        dnl [PM] 3.10 see if EXPECT_WARNINGS_MULTI_SP_C=yes suffice
        dnl dnl [PM] 3.9.1 headers are too broken, we cannot avoid warnings. In particular PTHREAD_MUTEX_INITIALIZER.
        dnl cc_warnings_are_errors=no
dnl HPUXIPF


        dnl [PM] 3.10.2 
        dnl +b : is the default, meaning add -L paths to DT_RUNPATH
        dnl We do not want to use +b since that loses the "default
        dnl locations", see spld.pl.in for a discussion of this
        dnl problem (exectly the same as on AIX).
        LD_BUILDS_RPATH_FROM_L=yes
        CC_ROPT=""
        SHLD_ROPT=""

        # [PM] 3.10.2 DT_RUNPATH can contain $ORIGIN for location
        # independent implicit dependency
        HAVE_SYSV_ORIGIN=yes

        if test "${GCC:-no}" = "yes"; then
            CFLAGS="$CFLAGS ${defs}"
            CFLAGS="$CFLAGS ${cc_opt_32_or_64bit}"

            dnl [PM] 3.9.1 CPPFLAGS needed?
            CPPFLAGS="$CPPFLAGS ${defs}"

            dnl [PM] 3.9.1b4 FIXME: what gcc options correspond to +DAportable, +DS2.0?

            dnl gcc 2.95.2 seems to (no docs, sorry) pass -z to ld (*NULL => SIGSEGV)

            dnl [PM] 3.10.2 docs hint that IPF always -fPIC, should not hurt to be explicit
            : ${INCR_CFLAGS='-fPIC'}

            dnl [PM] 3.10.2 FIXME: 
            dnl dnl [PM] 3.9.1 " +s +b :" gives behavior similar to AIX with -L<dirs> embedded
            dnl dnl also on SHLDFLAGS
            dnl SPLD_EXE_LDFLAGS="$SPLD_EXE_LDFLAGS -Wl,+s,+b,:"
dnl HPUXIPF
        else dnl !GCC test "${GCC:-no}" != "yes"
            dnl [PM] 3.10.1 for non-GCC AC PROG CC does not add -O
            if test "$OPTFLAG" != "no"; then
                CFLAGS="$CFLAGS -O"
            fi

            CFLAGS="$CFLAGS ${defs}"
            dnl [PM] 3.9.1 CPPFLAGS needed?
            CPPFLAGS="$CPPFLAGS ${defs}"

            dnl -Ae "compilation in ANSI C mode with HP C
            dnl      extensions. This option is the same as specifying
            dnl      -Aa, -D_HPUX_SOURCE, and +e. This is the default
            dnl      for the HP-UX 10.30 and later operating system
            dnl      releases." (So -D_HPUX_SOURCE above is redundant with -Ae)

            dnl Note that c89 does not accept (but will ignore) -Ae
            dnl and -Aa so explicit "-Aa +e -D_HPUX_SOURCE" may be a
            dnl better idea (+e *is* accepted by c89)

            CFLAGS="$CFLAGS -Ae"

dnl HPUXIPF
            CFLAGS="$CFLAGS ${cc_opt_32_or_64bit}"

            dnl [PM] 3.10.2 -Z is still the default
            dnl [PM] -z disallows NULL referencing
            dnl      -Z (default) *NULL = zero 
            dnl      (not to be confused with +z/+Z)

            CFLAGS="$CFLAGS -z"

            dnl -dynamic
            dnl "This option produces dynamically bound
            dnl  executables. These support shared libraries and use
            dnl  the features of the dynamic loader. The shl_load and
            dnl  dlopen APIs are fully supported. The linker links in
            dnl  shared libraries first and then archive
            dnl  libraries. Only PIC is supported."
            dnl
            dnl -dynamic is the default according to the docs of the
            dnl -noshared option.
            dnl
            dnl Consider putting -dynamic on SPLD_EXE_LDFLAGS instead
            CFLAGS="$CFLAGS -dynamic"
dnl HPUXIPF
            dnl Instruction scheduling.
            dnl "Object code with scheduling tuned for a particular
            dnl  model or processor will execute on other HP 9000
            dnl  systems, although possibly less efficiently"
            dnl [PM] 3.10.2 default is blended, run well on both itanium and itanium2
            dnl dnl "If you plan to run your program on both PA-RISC 1.1 and
            dnl dnl  2.0 systems, in general we recommend you use +DS2.0"
            dnl CFLAGS="$CFLAGS +DS2.0"

            dnl It seems we cannot safely use +ESnoparmeloc due to how 
            dnl HP compiles their own libraries.
dnl HPUXIPF

            dnl [PM] 3.10.2 docs hint that IPF always -fPIC, should not hurt to be explicit
            dnl dnl cc +z is like -fpic +Z is like -fPIC
            dnl dnl "Generates object code that can be added to a shared
            dnl dnl  library. Object code generated with this option is
            dnl dnl  position independent, containing no absolute
            dnl dnl  addresses. All addresses are either pc-relative or
            dnl dnl  indirect references. This is the same as the +Z
            dnl dnl  option in 64-bit mode. The -pand -G options are
            dnl dnl  incompatible with this option and are ignored. See
            dnl dnl  the HP-UX Linker and Libraries Online User Guide for
            dnl dnl  detailed information on shared libraries."
            dnl dnl [PM] 3.9.1 Use +Z/-fPIC (+z probably would *often* work
            dnl dnl            too and be a little faster)
            : ${INCR_CFLAGS='+Z'}

            dnl [PM] 3.10.2 FIXME: check this
            dnl SPLD_EXE_LDFLAGS="$SPLD_EXE_LDFLAGS -Wl,+s,+b,:"
dnl HPUXIPF

            WARNING_CFLAGS=""
            dnl [PM] 3.10.2 -w1 not supported (anymore?)
            dnl dnl -w1 all warnings, -w2 only warn if code generation could be affected, -w3 no warnings
            dnl WARNING_CFLAGS="$WARNING_CFLAGS -w1"

            dnl [PM] FIXME: documented but cc says "+M1" is unsupported in this release.
            dnl dnl [PM] 3.10.2 +M1 Warn about PA to IPF architecture issues
            dnl WARNING_CFLAGS="$WARNING_CFLAGS +M1"

            dnl dnl [PM] 3.10.2 +M2 Warn about 32 to 64 bit issues
            dnl WARNING_CFLAGS="$WARNING_CFLAGS +M2"

            dnl [PM] 3.10.2 +w warn about all questionable constructs
            WARNING_CFLAGS="$WARNING_CFLAGS +w1"
            dnl [PM] 3.10.2 turn off some warnings
            dnl 392: # Conversion unnecessary; expression was already of type 'foo'.
            dnl  44: # Consider updating old-style (non-prototype) function definition.
            dnl 887: # Type 'unsigned int' is smaller than type 'unsigned long', unwanted widening in value may result.
            dnl [PM] 3.10.2 FIXME: The code should be fixed to avoid the following:
            dnl 818: # Type 'unsigned long' is larger than type 'int', truncation in value may result.
            dnl 819: # Initialization of type 'int' with 'unsigned long' may result in truncation of value.
            dnl 863: # Result of operator << is widened from int to unsigned long.
            dnl 684: # Integer constant -4 = 0xFFFFFFFFFFFFFFFC is out of range for type unsigned long
            dnl        Only happens for 32bit code.
            if test $enable_64bit != yes; then
              cc_nowarn_32bit=',684'
              cc_nowarn_64bit=''
            else
              cc_nowarn_32bit=''
              cc_nowarn_64bit=''
            fi

            WARNING_CFLAGS="$WARNING_CFLAGS +W392,44,887,818,819,863${cc_nowarn_32bit}${cc_nowarn_64bit}"

            dnl [PM] 3.10.2 warn about possibly uninitialized variables and do not init them
            WARNING_CFLAGS="$WARNING_CFLAGS +Onoinitcheck"

            dnl [PM] 3.10.2 always use the debug msgs for our code but only for all code if DBG
            if test "${DEBUG_BUILD:-no}" = "yes"; then
               CFLAGS="$CFLAGS $WARNING_CFLAGS"
            else
               CFLAGS_EXTRA="$CFLAGS_EXTRA $WARNING_CFLAGS"
            fi
            dnl [PM] 3.10.2 no option to treat all warnings as errors?
            dnl cc_Werror="+We"
            cc_Werror=''

dnl HPUXIPF

            if test no != "$OPTFLAG"; then # Optimization related flags for cc
                dnl [PM] 3.9.1 consider adding +Osize (inhibit optimizations that increase size of code)

                dnl [PM] 3.10.2 Strange, there is now a +O[no]failsafe,
                dnl has it changed name? In either case the default is
                dnl now +Onofailsafe which is OK.
                dnl
                dnl dnl [PM] 3.9.1 tell us if cc optimizer encounters internal errors
                dnl CFLAGS="$CFLAGS +Onofail_safe"

                dnl [PM] 3.10.2 do not limit time spent optimizing,
                dnl same as +Olimit=none
                CFLAGS="$CFLAGS +Onolimit"

                dnl Do not assume that the type of a pointer tells
                dnl anything about what it could alias (similar to
                dnl -fno-strict-aliasing)
                dnl
                dnl Rationale: gcc -fstrict-aliasing is known to cause
                dnl problems on some platforms so I turn this off for
                dnl safety. Note that optimizations based on type safe
                dnl aliasing is already off by default, we only make
                dnl it explicit)

                dnl [PM] 3.10.2 synonym to +Otype_safety=off (the default)
                CFLAGS="$CFLAGS +Onoptrs_strongly_typed +Onoptrs_ansi"

                dnl [PM] 3.10.2 did not help (and is deprecated)
                dnl if test $enable_64bit != yes; then
                dnl   dnl [PM] 3.10.2 See if this avoids the core dumps
                dnl   CFLAGS="$CFLAGS +Oconservative"
                dnl fi
            fi
        fi

        dnl [PM] 3.10.2
        AC_CHECK_FUNCS(dlget dlgetname dlmodinfo)
        dnl AC_CHECK_HEADERS(sys/pset.h)

	dnl [PD] 3.10.2  We need a default path to find the standard tar.
	DEFAULT_POSIX_PATH=/usr/bin

dnl HPUXIPF
        ;;

    *linux*)
        dnl [PM] 3.11.3 Note that some flags are x86/x86_64-specific
        dnl             and will have to be changed for other architectures.

        dnl [PM] 3.9.1 in 3.9 we need pthreads and _REENTRANT regardless of Java
        dnl [PM] old comment
        dnl # -D_REENTRANT and -lpthread added to make it possible to
        dnl # link with Blackdown's JDK 1.2 native threads version.

        dnl [PM] 3.9.1 note that _REENTRANT is not implied by _GNU_SOURCE

        CFLAGS="$CFLAGS -D_REENTRANT"
        dnl [PM] 3.9.1 We use things that are hidden by default. May as well enable all features by using _GNU_SOURCE
        CFLAGS="$CFLAGS -D_GNU_SOURCE"
        dnl [PM] 4.0 We want all file APIs to use 64bit sizes
        CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64"

        AC_DEFINE(HAVE_LINUX_PROC_SELF_EXE, [1])

	case "${PLATFORM}" in
	x86_64-*)
            SP_JIT_ABI=linuxx64
	    ;;
        x86-*)
            SP_JIT_ABI=linuxx86
            ;;
        esac

        if test "${enable_64bit}" != "${platform_defaults_64bit}"; then
          dnl non-standard 32/64-bit settings
          if test "${enable_64bit}" = "yes"; then # force 64 bit when 32 bit is the default
            dnl 64-bit is the default, at least on gcc (GCC) 3.3.3 20040412 (Red Hat Linux 3.3.3-7) Fedora Core release 2 (Tettnang)
            CFLAGS="${CFLAGS} -m64"
            SHLD_architecture='-m64'
dnl            SPLFR_LD_r_FLAGS='-m elf_x86_64'
	    case "${PLATFORM}" in
	    x86_64-*)
            	SPLFR_LD_r_FLAGS='-m elf_x86_64'
                ASFLAGS="${ASFLAGS} --64"
	        ;;
	    powerpc64-*)
		SPLFR_LD_r_FLAGS='-m elf64ppc'
		# [PM] 4.0.6 what gcc uses (I do not know what -a64 does; -Qy is ignored according to info)
                ASFLAGS='-a64 -mppc64 -many -Qy'
                ;;
            esac
          else # force 32 bit when 64 bit is the default
            CFLAGS="${CFLAGS} -m32"
            SHLD_architecture='-m32'

	    case "${PLATFORM}" in
	    x86*)
                SPLFR_LD_r_FLAGS='-m elf_i386'
                ASFLAGS="${ASFLAGS} --32"
	        ;;
	    powerpc64*)
                dnl [PM] 4.0 I am guessing here, this is not tested (what about ASFLAGS?)
		dnl [PM] 4.0.6 should this be -m elf32ppclinux?
		SPLFR_LD_r_FLAGS='-m elf32ppc'
                ;;
            esac
          fi
        fi # non-standard setting

        case $PLATFORM in
         *)
           dnl [PM] 4.1.3 Work around what seems to be an OS bug.
           dnl Happens on x86 Linux (Linux r2d2 2.6.24-28-generic #1 SMP Sat Jul 31 16:10:32 UTC 2010 i686 GNU/Linux)
           dnl Not tested on x86_64 (on Mac OS X reproducing seems to need a multi-core machine)
           dnl Happens on 32- and 64-bit PowerPC (Linux 172_29_147_39.dal-ebis.ihost.com 2.6.18-194.el5 #1 SMP Tue Mar 16 22:03:12 EDT 2010 ppc64 ppc64 ppc64 GNU/Linux, Red Hat Enterprise Linux Server release 5.5 (Tikanga))
           dnl
           dnl [PM] 4.2.1 Fixed in recent RH patches
           dnl (http://bugzilla.redhat.com/684808) but they are not
           dnl everywhere yet and the workaround is probably
           dnl harmless.

           AVOID_PTHREAD_CANCEL_DEFAULT=yes
           ;;
        esac


dnl linux
        JAVA_LDFLAGS="$JAVA_LDFLAGS -lpthread"
        case $PLATFORM in
	  powerpc64*) # powerpc64 or powerpc6432
	    if test "${enable_64bit:-no}" = "yes"; then  
	       : ${JAVA_EXECOPTS=-d64}
	    fi
	    dnl [PM] 4.1 Now done for all platforms, below
    	    dnl sys_L_dirs='/lib:/lib64:/usr/lib:/usr/lib64'
          ;;
        esac
	dnl [PM] 4.2.1 several Suite tests complains about early
	dnl timeouts. Either a new problem with recent Linuxes or
	dnl something JIT-related. Work around for now.
        AC_DEFINE(SETITIMER_EARLY)

        dnl [PM] 3.11.3 -lpthread needed on zjuk (BDB 4.1.24, Fedora,
        dnl x86_64-linux-glibc2.3) and (says SPRM 8295) for BDB 4.2 on
        dnl RH9 x86-linux-glibc2.3)
        bdb_extra_libs="-lpthread"

        FLI_FILE=fli_dl.c
        hugepages_enabled_default=no
        case $PLATFORM in
          x86-*)
            if test "${SP_FLI_APPLY_ASM_GENERIC:-no}" != "yes"; then
              FLI_APPLY_ASM_FILE=fli_x86.s
            fi
            hugepages_enabled_default=yes
          ;;
          x86_64-*)
            if test "${SP_FLI_APPLY_ASM_GENERIC:-no}" != "yes"; then
              FLI_APPLY_ASM_FILE=fli_sysv_abi_x86_64.s
              AC_DEFINE(FLI_APPLY_ASM_SYSV_ABI_X86_64, [1])
            fi
            hugepages_enabled_default=yes
          ;;
          powerpc6432-*)
            if test "${SP_FLI_APPLY_ASM_GENERIC:-no}" != "yes"; then
              FLI_APPLY_ASM_FILE=fli_sysv_abi_ppc32.c
              AC_DEFINE(FLI_APPLY_ASM_SYSV_ABI_PPC32, [1])
            fi
            dnl Use fallback method since something goes wrong with PowerPC ELF.
            : ${resgen_type_default="cc"}
	  ;;
          powerpc64-*)
            if test "${SP_FLI_APPLY_ASM_GENERIC:-no}" != "yes"; then
              FLI_APPLY_ASM_FILE=fli_sysv_abi_ppc64.s
              AC_DEFINE(FLI_APPLY_ASM_ABI_PPC, [1])
            fi
            : ${resgen_type_default="cc"}
	  ;;
        esac
        AC_MSG_CHECKING([whether huge pages should be supported])
        AC_ARG_ENABLE(hugepages,      [  --enable-hugepages            Enable huge pages support],
             [hugepages_enabled=$enableval],
             [hugepages_enabled=$hugepages_enabled_default])
        if test "${hugepages_enabled:-no}" = "yes"; then
          hugepages_enabled=yes
          AC_DEFINE([SP_HUGEPAGES], [1])
        else
          hugepages_enabled=no
          AC_DEFINE([SP_HUGEPAGES], [0])
        fi
        AC_MSG_RESULT([$hugepages_enabled])
        # [PM] 4.2.1 Currently the hugepage support is not used unless
        # explicitly enabled at runtime.
        AC_DEFINE([SP_HUGEPAGES_DEFAULT], [0])

        if test "${enable_64bit}" = "yes"; then
           dnl resgen.pl does not know how to generate 64bit ELF. Use cc as fallback
           : ${resgen_type_default="cc"}
        else # 32-bit elf
           : ${resgen_type_default="prefix"}
        fi
        dnl [PM] 3.12.1+ There were some problems with "prefix" on IBM Power. Make it possible to change manually.
        AC_ARG_WITH(resgen-type,      [  --with-resgen-type=TYPE            Internal],
             [resgen_type=$withval],
             [resgen_type=$resgen_type_default])
        RESGEN_TYPE="${resgen_type}"

        dnl [PM] 3.8.6 used to inherit the default LD_ROPT (-R) which
        dnl means something completely different with GNU LD. It worked
        dnl because of a hack in the GNU LD source (lexsup.c):
        dnl case 'R':
        dnl   /* The GNU linker traditionally uses -R to mean to include
        dnl      only the symbols from a file.  The Solaris linker uses -R
        dnl      to set the path used by the runtime linker to find
        dnl      libraries.  This is the GNU linker -rpath argument.  We
        dnl      try to support both simultaneously by checking the file
        dnl      named.  If it is a directory, rather than a regular file,
        dnl      we assume -rpath was meant.  */
        dnl LD_ROPT="-rpath "
        gcc_ropt="-Wl,-rpath,"
        dnl currently only support gcc (there are others, e.g., the Intel compiler)
        CC_ROPT="$gcc_ropt"
        SHLD_ROPT="$gcc_ropt"
        
dnl linux
        # [PM] 3.9b4 DT_RPATH can contain $ORIGIN for location
        # independent implicit dependency
        HAVE_SYSV_ORIGIN=yes
        
        LD_LIBRARY_PATH_name="LD_LIBRARY_PATH"

        gcc_shld=yes
	: ${SHLD="${CC}"}
        : ${LD="ld"}
        dnl [PM] 3.9b5 sp_GlobalSICStus is now name mangled so -Bsymbolic is not needed anymore
        dnl if test "x$SICSTUS_BETA_VERSION" = "x" || test "x$SICSTUS_BETA_VERSION" = "x0"; then
        dnl     AC_MSG_ERROR([Need to resolve the problem with sp_GlobalSICStus needing -Bsymbolic for foreign resources])
        dnl else # BETA
        dnl    # [PM] 3.9b4 -Bsymbolic is needed so that the
        dnl    # sp_GlobalSICStus in a dynamic foreign resource is
        dnl    # resolved locally and does not bind to the application
        dnl    # global with the same name.
        dnl    # The right way would be to have a sp_GlobalSICStus_<RESNAME> or some such.
        dnl    : ${SPLFR_SHLDFLAGS="-shared -Wl,-Bsymbolic"}
        dnl fi
dnl linux        
        dnl [PM] 3.9.1 Unfortunately --no-undefined does not work, it
        dnl            gives a lot of warnings from libc.so.6 about
        dnl            _dl_XXX symbols.
        dnl            One theory (mentioned for similar symptoms on
        dnl            the net) is that this is a bug in RH 7.1
        dnl            binutils and that upgrading binutils would
        dnl            help.

        # SHLD_Wlno_undefined="-Wl,--no-undefined"
        SHLD_Wlno_undefined=""


        dnl [PM] 3.9b5 removed -rdynamic since we no longer rely on runtime linker
        dnl [PM] 3.8.4 added -rdynamic for PRM 1516
        dnl : ${LDFLAGS="-rdynamic -ldl -lpthread"}
dnl linux
        dnl [PM] 3.9.1
        dnl AC_MSG_WARN([LDFLAGS set, should use SPLD_EXE_LIBS])
        dnl : ${LDFLAGS="-ldl -lpthread"}

        SPLD_EXE_OPAGENT_LIB=''
        OPAGENT_LIB=''
        if test "${use_oprofile:-no}" = "yes"; then
           libdirs32=
           for base in '' /usr/lib /usr/lib32 /usr/lib64; do
             d="${base}"
             for sub in '' oprofile; do
               if test -z "${base}"; then
                 if test -n "${sub}"; then
                   # do not look for sub-dirs in emtpy base
                   continue
                 fi
               else
                 if test -n "${sub}"; then
                   d="${d}/${sub}"
                 fi
               fi

               if test -n "${d}"; then
                 if test -d "${d}"; then
                    :
                 else
                    continue;
                 fi
               fi
               OPAGENT_LIB_L="${d}"
               opagent_linked_successfully=no
               if test "${opagent_linked_successfully:-no}" != yes; then
                 OPAGENT_LIB="${OPAGENT_LIB_L:+ -L${OPAGENT_LIB_L} }-lopagent"
                 AC_MSG_CHECKING([whether linking works with ${OPAGENT_LIB}])

                 PUSH_LIBS="$LIBS"
                 LIBS="$LIBS ${OPAGENT_LIB}"
                 AC_TRY_LINK([
                               #include <stdint.h> /* missing requirement in opagent.h */
                               #include <opagent.h>
                             ],
                             [  op_open_agent();
                             ],
                             [
                                AC_MSG_RESULT([yes])
                                opagent_linked_successfully=yes
                             ],
                             [
                                AC_MSG_RESULT([no])
                             ]
                             )
                 LIBS="$PUSH_LIBS"
               fi # without -lbfd

               if test "${opagent_linked_successfully:-no}" != yes; then
                 OPAGENT_LIB="${OPAGENT_LIB_L:+ -L${OPAGENT_LIB_L} }-lopagent -lbfd"
                 AC_MSG_CHECKING([whether linking works with ${OPAGENT_LIB}])
                 PUSH_LIBS="$LIBS"
                 LIBS="$LIBS ${OPAGENT_LIB}"
                 AC_TRY_LINK([
                               #include <stdint.h> /* missing requirement in opagent.h */
                               #include <opagent.h>
                             ],
                             [  op_open_agent();
                             ],
                             [
                                AC_MSG_RESULT([yes])
                                opagent_linked_successfully=yes
                             ],
                             [
                                AC_MSG_RESULT([no])
                             ]
                             )
                 LIBS="$PUSH_LIBS"
               fi # try with -lbfd
               if test "${opagent_linked_successfully:-no}" = yes; then
                 if test "{$kernel_oprofile:-no}" = "yes"; then
                   KERNEL_SHLD_LIBS_EXTRA="${KERNEL_SHLD_LIBS_EXTRA:+${KERNEL_SHLD_LIBS_EXTRA} }${OPAGENT_LIB}"
                   SPLD_EXE_OPAGENT_LIB="${OPAGENT_LIB}"
                 fi
                 break 2
               else
                 OPAGENT_LIB=''
               fi
            done # sub
          done # d
	fi
        AC_SUBST([OPAGENT_LIB])


        dnl [PM] 4.0 not tested
        spio_libs="-lrt"

        SPLD_EXE_LIBS="-ldl -lm -lpthread${spio_libs:+ ${spio_libs}}${SPLD_EXE_OPAGENT_LIB:+ ${SPLD_EXE_OPAGENT_LIB}}"
        KERNEL_SHLD_LIBS="$SPLD_EXE_LIBS"

        
        dnl [PM] 3.9.1b4 all tools need to be built moveable by us so
        dnl they can be installed by just copying.
        if test ${PREBUILT_INSTALL_ENABLED:-no} = yes; then
          can_prebuilt=yes
          SPLD_TOOLFLAGS="${SPLD_TOOLFLAGS:+${SPLD_TOOLFLAGS} }--moveable"
        fi
        # [PM] 4.2 Make spld --moveable the default
        enable_moveable_default='yes'

        dnl [PM] 4.2.1 they are silently accepted by default on Linux.
        if test "${fatal_text_relocs:-no}" = "yes"; then
           # Note that --warn-shared-textrel is not supported by older GNU ld
           shld_JIT_flags="${shld_JIT_flags} -Wl,--warn-shared-textrel -Wl,--fatal-warnings"
        fi


        dnl [PM] 3.9.1 Added --no-undefined, there should be no unresolved references in the shared libraries we build.
        dnl            (see above for if SHLD_Wlno_undefined is really set or not)
        dnl            Consider moving ${SHLD_Wlno_undefined} to KERNEL_SHLD_FLAGS
        : ${SHLDFLAGS="-shared ${SHLD_architecture} ${SHLD_Wlno_undefined} ${shld_JIT_flags}"}
        : ${SPLFR_SHLDFLAGS="$SHLDFLAGS"}
dnl linux
        : ${INCR_CFLAGS="-fPIC"}
        # [PM] 3.9.1 See also SHLD_RTKERNELEXP
        # [PD] 3.9 Add option for scope reduction of symbols.
        #          On linux SHLD is gcc which calls GNU ld. 
        MAPFILEOPT="-Wl,--version-script="
        # [PM] 3.9.1 must be "" if MAPFILEOPT is used
        SHLD_RTKERNELEXP=""

        dnl For hiding all but the main procedure of foreign resources
        dnl # "" disables that feature for now
        dnl AC_MSG_WARN([Should enable SPLFR_SHLD_EXPORT_OPT on Linux before 3.9.1 release/PM])
        dnl SPLFR_SHLD_EXPORT_OPT=""
        SPLFR_SHLD_EXPORT_ARG='-Wl,--version-script=@SP_MAP_FILE@'
        dnl [PM] 3.9.1 GNU ld cannot take version script with ld -r. Possibly strip could be used.
        SPLFR_LD_EXPORT_ARG=""

        dnl [PM] 3.9.1 to be backward compatible with 3.9.0 we could use:
        dnl SP_RTSYS_DIRNAME="lib"

dnl ============================================================
dnl ============================================================


dnl linux

        dnl [PM] 3.10 Use the superior gzip format since we know that all Linux systems have gzip.
        dnl Note that, even though gzip (or tar -z) is needed to
        dnl uncompress the sicstus distribution (unless the Java
        dnl Installer Tool is used), we cannot rely on gzip being
        dnl available at any standard location on most other platforms.
        MKDISTR_COMPRESS=gzip
        MKDISTR_COMPRESS_ARGS=-9
        SP_INSTALL_ZCAT=zcat

        AC_DEFINE(HAVE_PROC_SELF_FD)

	dnl [PD] 3.10.2  We need a default path to find the standard tar.
	DEFAULT_POSIX_PATH=/bin:/usr/bin

dnl linux
        ;;

    *-freebsd*|*-netbsd*|*-openbsd*)
        AC_MSG_ERROR([SICStus is not yet supported for $PLATFORM, contact sicstus-support@sics.se])
        ;;

    *darwin-*)
dnl darwin
        dnl [PM] 4.2.1 probably obsolete dylib info:
        dnl [PM] 3.9.1 got this from the net (lacking proper docs from Apple)
        dnl The general recipe for building dynamic shared libraries on Darwin is:
        dnl 
        dnl 1. Compile your object files with the -fno-common option. This isn't 
        dnl strictly necessary as long as you initialize all your global 
        dnl variables, but ported code rarely does. ([PM] We should
        dnl use this on all platforms, at least for foreign resources
        dnl (static and dynamic) ([PM] 3.9.1b4 in fact we do use it on
        dnl all platforms, it is added to GCC specific CFLAGS)
        dnl 
        dnl 2. Use "-dynamiclib -undefined suppress" to build the dynamic shared 
        dnl library. Dynamic shared libraries on Darwin use the .dylib suffix 
        dnl instead of .so.
        dnl 
        dnl So a complete build might look like:
        dnl 
        dnl cc -fno-common -o afile.o afile.c
        dnl cc -fno-common -o bfile.o bfile.c
        dnl cc -dynamiclib -undefined suppress -o ablibrary.dylib afile.o bfile.o
dnl darwin
        dnl PIC options are not necessary because PowerPC code is always position 
        dnl independent and the Darwin option to generate position independent 
        dnl code, -dynamic, is on by default.

dnl darwin
        dnl [PM] WinCE moved from config.c
        AC_DEFINE(SP_DARWIN)
        darwin=yes

	dnl [PM] 4.1 need in non-src too
        AC_MSG_CHECKING([whether this is Darwin 9 (Mac OS 10.5) or newer])
        case "$PLATFORM" in
        *darwin-8.*)
          darwin_9_or_newer=no
          ;;
        *)
          darwin_9_or_newer=yes
          ;;
        esac
        AC_MSG_RESULT([$darwin_9_or_newer])
        AC_MSG_CHECKING([whether this is Darwin 10 (Mac OS 10.6) or newer])
        if test "${darwin_9_or_newer:-no}" != "yes"; then
          darwin_10_or_newer=no
        else
          case "$PLATFORM" in
          *darwin-9.*)
            darwin_10_or_newer=no
            ;;
          *)
            darwin_10_or_newer=yes
            ;;
          esac
        fi
        AC_MSG_RESULT([$darwin_10_or_newer])

         AC_MSG_CHECKING([for xcrun --show-sdk-path])
         # xcrun --show-sdk-path is new in Xcode 5. Ignore errors, just let it become empty.
         XCRUN_SDK_PATH=$( xcrun --sdk macosx --show-sdk-path 2>/dev/null )
         AC_MSG_RESULT([${XCRUN_SDK_PATH:-none}])

dnl ============================================================
dnl ============================================================

	dnl [PD] 3.12.8 This subst must be outside src-begin/src-end.
        AC_SUBST(MACOSX_MAKEFILE_ENV_EXPORTS)

        # [PM] 3.8.7 avoid memory allocation errors when running test suite (see relnotes)
        # Should be empty or semi-colon terminated (used as "$(ULIMIT_DATA) sicstus -f ...")
        ULIMIT_DATA='ulimit -d unlimited;'
        # [PM] 3.8.7 the MacOS X rm does not like being called without arguments
        #      To ensure rm is never called without arguments, always do
        #      rm -f ...whildcard... $(RMDUMMY)
        RMDUMMY=nonexisting_dummy_file
dnl        WHICH="type -p"

        dnl LD_ROPT=""
        CC_ROPT=""
        SHLD_ROPT=""

dnl darwin

dnl         # [PM] 3.8.7 (the deprecated) library(db) does not work as is
dnl         #            and I have not bothered to figure out why.
dnl         DB_MODULE=''

	if test "${GCC:-no}" != "yes"; then
	    AC_MSG_ERROR([non-gcc compiler for Darwin not supported]) #  are there any others? MetroWerks, Motorola?
	fi

dnl darwin
        dnl [PM] 3.9.1 do not add Carbon to this, it will make libsprt39 fail with
        dnl "kCGErrorIllegalArgument : initCGDisplayState: cannot map display interlocks."
        dnl at least when running from a ssh session.

        dnl [PM] 3.10.1 Neither -framework nor -I is needed for frameworks located in the "standard" places
        KERNEL_FRAMEWORKS_I=''
        dnl KERNEL_FRAMEWORKS_I="-I/System/Library/Frameworks/CoreFoundation.framework/Headers"

        dnl [PD] 3.12.7 Mac/64-bit; CoreFoundation is not 64-bit capable until Darwin 9.x/Mac OS 10.5/Leopard
        if test "${darwin_9_or_newer:-no}" != "yes" && test "${enable_64bit:-no}" = "yes"; then
           :
        else # 32-bit or Darwin 9
           KERNEL_FRAMEWORKS="-framework CoreFoundation"
        fi

        : ${SHSFX='dylib'}


        # [PM] 3.8.7 GCCLIB in fact breaks the cplus test suite and does not seem to be needed.
        GCCLIB=''

        dnl [PM] 3.9.1 Experiment with using -d (a.k.a no-common)
        SPLFR_LD_r_FLAGS="-d"
        : ${LD=ld}
dnl darwin
        : ${SHLD="${CC}"}

        dnl [PM] 3.9.1 We expect no duplicate symbols
        shld_error_duplicate_symbols="-Wl,-multiply_defined,error"

        dnl [PD] 3.12.7 Make sure spld/splfr generates the "correct" type of binary.
        case $PLATFORM in
        powerpc-*)
            if test "${has_apple_gcc:-yes}" = "yes" ; then
              shld_cpu_opts="-arch ppc"
            fi
            ac_cv_c_bigendian=yes
            ;;
        i386-*)
            if test "${has_apple_gcc:-yes}" = "yes" ; then
              shld_cpu_opts="-arch i386"
            fi
            ac_cv_c_bigendian=no
            ;;
        esac

        if test "${enable_64bit:-no}" = "yes"; then
               shld_arch_width_opts='-m64'
        else
               shld_arch_width_opts='-m32'
        fi
dnl darwin
        dnl shld_arch_opts also used by SPLFR_SHLDFLAGS
        shld_arch_opts="${shld_cpu_opts} ${shld_arch_width_opts}"
        shld_JIT_flags=''
        if test "${JIT:-no}" = "yes"; then
          dnl [PM] 4.2.1 kernel.s4 need text relocs (i.e. it is not
          dnl properly position independent). Do not barf but warn
          dnl about it.  Could suppress the warnings but we want to
          dnl fix the underlying problem before going final (so we do
          dnl not cause problem with user code that embeds SP).

          dnl [PM] 4.2.1 no longer needed. kernel.s4 is PIC-safe
          dnl shld_JIT_flags='-read_only_relocs warning'
          dnl [PM] 4.2.1 they are fatal by default.
          if test "${fatal_text_relocs:-yes}" = "no"; then
             shld_JIT_flags='-read_only_relocs warning'
          fi
          
          dnl [PM] 4.2.1 alignment should now be fixed in kernel. (and -mstackrealign is unavailbale on amd64).
          dnl
          dnl dnl [PM] 4.2.1 kernel.s4 does not ensure that the stack is
          dnl dnl aligned when calling C code. Mac OS X x86-32 ABI
          dnl dnl requires 16 byte(?) alignment. Until we fix kernel.s4 we
          dnl dnl tell all our C code to adjust the incoming stack. (One
          dnl dnl crash happened in some SSE2 floating point instruction
          dnl dnl generated when computing percentages in alloc.c...)
          dnl dnl NOTE: It is unclear whether Linux x86 ABI also requires
          dnl dnl 16byte alignment, see for instance
          dnl dnl http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838 
          dnl dnl FIXME: We should either fix the alignment in the caller
          dnl dnl (kernel.s4) or have all misaligned calls go via a a
          dnl dnl special file (compiled with -mstackrealign) so that we
          dnl dnl do not have to compile all our code with -mstackrealign.
          dnl dnl [PM] 4.2.1 FIXME: Instead we should mark all C functions
          dnl dnl called (with potentially misaligned stack) from
          dnl dnl kernel.s4 with
          dnl dnl __attribute__((force_align_arg_pointer)). Hopefully
          dnl dnl there are not that many such functions.
          dnl CFLAGS_EXTRA="${CFLAGS_EXTRA} -mstackrealign"
        fi
        dnl [PM] 3.9.1 try to do without -undefined suppress
        : ${SHLDFLAGS="-dynamiclib ${shld_arch_opts} ${shld_error_duplicate_symbols} ${shld_JIT_flags}"}

        LD_LIBRARY_PATH_name="DYLD_LIBRARY_PATH"
        # [PM] 4.2 Mac OS X 10.5 and later has @loader_path which should better than @executable_path (and closer to $ORIGIN semantics)
        : ${KERNEL_SHLD_FLAGS="-install_name @loader_path/${SP_RTSYS_DIRNAME_UNIX}/${RTKERNEL_BASENAME_SANS_SUFFIX}.${SHSFX}"}
        dnl # [PM] 3.9.1 '@executable_path' is similar to SysV $ORIGIN, it makes exes linked against libsprt39.dylib moveable
        dnl #            Consider using the ld option -dylib_file instead when linking --moveable executables.
        dnl : ${KERNEL_SHLD_FLAGS="-install_name @executable_path/${SP_RTSYS_DIRNAME_UNIX}/${RTKERNEL_BASENAME_SANS_SUFFIX}.${SHSFX}"}

        dnl [PM] Darwin does not have all XSI functions, e.g. no waitid()
        use_xsi_cache=no

dnl [PM] 4.0 Man pages indicate that at least aio_write and pwrite are in standard c library (libc).
        spio_libs=""
        : ${KERNEL_SHLD_LIBS="${KERNEL_FRAMEWORKS}"}
dnl darwin
        dnl [PM] 3.9.1 Actually ${KERNEL_FRAMEWORKS} is only needed if linking with a static version of libsprt.
        dnl            FIXME: we need a KERNEL_LIBS for spld to use when linking with a static sprt
        SPLD_EXE_LIBS="${KERNEL_FRAMEWORKS}"

        dnl [PM] 3.9.1 no longer need --wrapper
        : ${SPLD_OPT_WRAPPER_DEFAULT="no"}
dnl darwin
        dnl [PM] 3.9.1 We now have a link in the bin-dir so that we can pre-build the tools for binary installs.
        dnl            Still experimental.
        dnl dnl [PM] 3.9.1 --wrapper is no longer the default on MacOS X
        dnl dnl but it is needed if there is no SP_RTSYS_DIRNAME
        dnl dnl subdirectory.
        dnl : ${SPLD_TOOLFLAGS="--wrapper"}
        # [PM] 4.2 Make spld --moveable the default
        enable_moveable_default='yes'
        # [PM] 4.2 Now --moveable is the default:
        # SPLD_TOOLFLAGS="${SPLD_TOOLFLAGS:+${SPLD_TOOLFLAGS} }--moveable"

        dnl [PM] 3.9.1 spld --moveable is needed if --enable-prebuilt whatever we decide is the default
        if test ${PREBUILT_INSTALL_ENABLED:-no} = yes; then
          can_prebuilt=yes
          SPLD_TOOLFLAGS="${SPLD_TOOLFLAGS:+${SPLD_TOOLFLAGS} }--moveable"
        fi

        if test $sp_isbindistr != yes; then
          dnl [PM] 3.9.1b4 I no longer remember the significance of this FIXME.
          AC_MSG_WARN([FIXME: need a KERNEL_LIBS/KERNEL_STATIC_LIBS for static linking against SP run-time/PM])
        fi
dnl darwin
        if test "${DEBUG_BUILD:-no}" = "yes"; then
           dnl [PM] 3.9.1 We should explicitly initialize all global
           dnl            data. If we do not I rather get a linker error.
           cc_no_common=""
        else
            cc_no_common="-fno-common"
        fi

        dnl [PM] 4.0 My hope is that this will make pthread_cancel
        dnl work. Should not hurt, anyway (UPDATE: pthread
        dnl cancellation points are still broken but _APPLE_C_SOURCE
        dnl is probably a good idea anyway)
        CFLAGS="${CFLAGS} -D_APPLE_C_SOURCE"

        : ${INCR_CFLAGS="$cc_no_common -dynamic"}

        : ${SPLFR_SHLD="${CC}"}
        dnl [PM] 3.9.1 MacOS 10.1 two-level namespaces require -undefined error (the default)
        dnl : ${SPLFR_SHLDFLAGS="-bundle -undefined suppress"}

        : ${SPLFR_SHLDFLAGS="-bundle -undefined error ${shld_arch_opts}"}
dnl darwin
        dnl [PM] 4.0 All code must know CPU and width, including user-code compiled by spld/splfr
        CFLAGS="${CFLAGS} ${shld_arch_opts}"

        dnl [PM] 4.0 we add shld_arch_flag to CFLAGS so I do not think we need to change SPLD_EXE_LDFLAGS
        dnl SP3 does: 1.618        (pd       18-Sep-06): 	SPLD_EXE_LDFLAGS="$SPLD_EXE_LDFLAGS $splfr_shld_arch_flag"

dnl darwin
        dnl [PM] 3.9.1 -no-cpp-precomp turns off the broken preprocessor (barfs on wam.c)
        dnl            Not sure if setting both CFLAGS and CPPFLAGS is needed
        dnl      xref hack preceeding AC_CPP above
        CPPFLAGS="${no_cpp_precomp} $CPPFLAGS"
        CFLAGS="${no_cpp_precomp} ${KERNEL_FRAMEWORKS_I} ${CFLAGS}"

	# FLI_FILE=fli_rhap.c
        FLI_FILE=fli_dl.c
dnl darwin
        case "${PLATFORM}" in
               i386-*)
                if test "${SP_FLI_APPLY_ASM_GENERIC:-no}" != "yes"; then
                  FLI_APPLY_ASM_FILE=fli_i386_darwin.s
                fi
                ASFLAGS='-arch i386'
                SP_JIT_ABI=darwinx86
               ;;
               x86_64-*|i38664-*)
                if test "${SP_FLI_APPLY_ASM_GENERIC:-no}" != "yes"; then
                  FLI_APPLY_ASM_FILE=fli_sysv_abi_x86_64.s
                  AC_DEFINE(FLI_APPLY_ASM_SYSV_ABI_X86_64, [1])
                fi            

                ASFLAGS='-arch x86_64'
                SP_JIT_ABI=darwinx64
               ;;
               powerpc-*)
                if test "${SP_FLI_APPLY_ASM_GENERIC:-no}" != "yes"; then
                  FLI_APPLY_ASM_FILE=fli_apple_abi_ppc32.s
                  AC_DEFINE(FLI_APPLY_ASM_ABI_PPC, [1])
                fi
                ASFLAGS='-arch ppc'
               ;;
               powerpc64-*)
                AC_MSG_ERROR([PPC64-support is not available])
                ASFLAGS='-arch ppc64'
               ;;
        esac

dnl darwin

        dnl [PM] 4.0 No longer needed, -D_APPLE_C_SOURCE makes the signals prototyped.
        dnl # [PM] MacOS X 10.1 headers do not have proper prototypes for SIG_IGN et al.
        dnl #      unless _ANSI_SOURCE is defined but _ANSI_SOURCE seems to hide too much other things.
        dnl HAVE_PROTOTYPED_SIG_IGN=no

dnl darwin
        
        # [PM] 4.3 "jnilib" does not work with Java 8, "dylib" should work with from Java 5, so use that.
        # [PM] 4.3 "Java HotSpot also recognizes .dylib as a valid JNI
        #          library format as of OS X v10.5."
        #
        #          Java 8 System.mapLibraryName("foo") now uses suffix
        #          "dylib" instead of "jnilib" as in Java 6 (and
        #          perhaps 7?).
        #
        # # [PM] 3.9.1 MacOS X JDK 1.3.1 System.loadLibrary("NAME") loads libNAME.jnilib
        # JNI_SHSFX="jnilib"
        JNI_SHSFX="dylib"

        # [PM] 3.9.1 MacOS X dynamic foreign resources are bundles,
        # not dynamic libraries and so should not, as was done in 3.8,
        # use .dylib but rather .bundle (or something like .splib)
        FLI_SHSFX="bundle"
dnl [PM] 4.1.3+ gone
dnl        # Dynamic foreign resources cannot be passed to linker
dnl        FLI_SHARED_PRELINKS=no
dnl darwin
        dnl [PM] 4.1 Nowadays we can use -exported_symbol (and Mac OS
        dnl X 10.6 no longer support our old nmedit post-processing
        dnl trick).
        AC_MSG_CHECKING([method for hiding symbols])
        if test "${darwin_9_or_newer:-no}" = "yes"; then
dnl darwin
          AC_MSG_RESULT([-exported_symbol])
          dnl [PM] 4.1 It seems 10.4 ld has -exported_symbols_list so
          dnl we would not need to use nmedit there and could in fact
          dnl use -exported_symbols_list (instead of -exported_symbol)
          dnl on all platforms.

          dnl [PM] 4.1 tell linker about exports (note the prefixed underscore)
          SPLFR_SHLD_EXPORT_ARG="-Wl,-exported_symbol,_@SP_MAIN_NAME@"

          dnl dnl [PM] 3.9.1 post-process the static .o file in the same way.
          dnl SPLFR_LD_R_POST_PROCESS="$SPLFR_SHLD_POST_PROCESS"
          dnl SPLFR_LD_R_POST_PROCESS_EXPFILE_OPT="$SPLFR_SHLD_POST_PROCESS_EXPFILE_OPT"
          dnl SPLFR_LD_R_POST_PROCESS_LIB_OPT="$SPLFR_SHLD_POST_PROCESS_LIB_OPT" # note space
dnl darwin

          SPLFR_LD_EXPORT_ARG="-exported_symbol _@SP_MAIN_NAME@"

          SHLD_RTKERNELEXP='-Wl,-exported_symbol,_$(SP_GET_DISPATCH_NAME)'
        else # <= Mac OS X 10.4
          dnl [PM] 4.1 We could use -exported_symbols_list also on
          dnl          Mac OS X 10.4, see above.
          dnl dnl [PM] 3.9.1 There is no --export <SYM> option SHLD, instead
          dnl dnl use nmedit to post process the file

          AC_MSG_RESULT([nmedit])
          dnl [PM] 4.0 SP3 adds an -arch x86_64 option here but I do not think that is needed since -arch all is the default.
          : ${NMEDIT=nmedit}

          EXPFILE_SYMBOL_PREFIX="_"
          RTKERNEL_EXPFILE=rtkernel.exp

          dnl [PM] RTKERNEL_POST_PROCESS is a make file action
          RTKERNEL_POST_PROCESS='$(NMEDIT) -s $(filter $(RTKERNEL_EXPFILE),$^) $@'
 
dnl darwin
          dnl [PM] 3.9.1 run nmedit as "nmedit -s foo_glue.exp foo.bundle"
          SPLFR_SHLD_POST_PROCESS="$NMEDIT"
          SPLFR_SHLD_POST_PROCESS_EXPFILE_OPT="-s " # note space
          SPLFR_SHLD_POST_PROCESS_LIB_OPT=" " # note space
          SPLFR_SHLD_EXPORT_ARG=""

          dnl [PM] 3.9.1 post-process the static .o file in the same way.
          SPLFR_LD_R_POST_PROCESS="$SPLFR_SHLD_POST_PROCESS"
          SPLFR_LD_R_POST_PROCESS_EXPFILE_OPT="$SPLFR_SHLD_POST_PROCESS_EXPFILE_OPT"
          SPLFR_LD_R_POST_PROCESS_LIB_OPT="$SPLFR_SHLD_POST_PROCESS_LIB_OPT" # note space
          SPLFR_LD_EXPORT_ARG=""

          SHLD_RTKERNELEXP=""
        fi
dnl darwin

        # [PM] 3.9.1 Never use -native on MacOS X, if supported it is the default anyway.
        : ${JAVA_NATIVE_ARG=""}

        # [PM] 4.1 64-bit Java is in Mac OS 10.5 and newer.
        # [PM] 4.1 Consider separating the Jasper options (which needs
        # -d64) from the PrologBeans options (which ought to use the
        # default, i.e. 32-bit, Java

        if test "${darwin_9_or_newer:-no}" = "yes"; then
           if test $enable_64bit = yes; then
             : ${JAVA_EXECOPTS=-d64}
           else
             # [PM] 4.1 be explicit, Java on 10.6 defaults to 64-bit
             : ${JAVA_EXECOPTS=-d32}
           fi
        fi


dnl darwin

        dnl [PM] 4.0 Suite/iso_compiled complained about early timeout return
        AC_DEFINE(SETITIMER_EARLY)

dnl ============================================================
dnl ============================================================

        AC_SUBST(MACOSX_MALLOC_SCRIBBLE_KLUDGE)

        
        SUITE_EXPECTED_FAILURES="${SUITE_EXPECTED_FAILURES}${SUITE_EXPECTED_FAILURES:+ }posix_wait_test_wnohang cplus cplus_stat"

        case "$PLATFORM" in
          *darwin-9.*)
              # [PM] 4.2.2 odbc_suite crashes with segfault. iODBC is
              # broken in Mac OS X 10.5. See
              # https://issues.apache.org/ooo/show_bug.cgi?format=multiple&id=88823,
              # which seems to describe the same underlying problem.
              SUITE_EXPECTED_FAILURES="${SUITE_EXPECTED_FAILURES}${SUITE_EXPECTED_FAILURES:+ }odbc_suite"
              SUITE_SKIPPED_TESTS="${SUITE_SKIPPED_TESTS}${SUITE_SKIPPED_TESTS:+ }odbc_suite"
          ;;
        esac


        dnl [PM] 3.10 Use the superior gzip format since we know that
        dnl all MacOS X systems have gzip.  Note that, even though
        dnl gzip (or tar -z) is needed to uncompress the sicstus
        dnl distribution (unless the Java Installer Tool is used), we
        dnl cannot rely on gzip being available at any standard
        dnl location on most other platforms.
        MKDISTR_COMPRESS=gzip
        MKDISTR_COMPRESS_ARGS=-9
        SP_INSTALL_ZCAT=zcat

	dnl [PD] 3.10.2  We need a default path to find the standard tar.
	DEFAULT_POSIX_PATH=/usr/bin

dnl darwin
	;;

    *-solaris-*)
dnl [PM] 4.1.3+ gone
dnl        hardware=`$UNAME -p`

dnl SOLARIS

        JAVA_LDFLAGS="$JAVA_LDFLAGS -lthread"

        dnl [PM] 3.9.1 -R is the default but make it explicit for maintainability
        dnl LD_ROPT="-R "
        gcc_ropt="-Wl,-R,"
        cc_ropt="-R "
        ld_ropt="-R "

        if test "${GCC:-no}" = "yes"; then
          CC_ROPT="$gcc_ropt"
        else
          CC_ROPT="$cc_ropt"
        fi
        
        # [PM] 3.9b4 DT_RPATH can contain $ORIGIN for location
        # independent implicit dependency
        HAVE_SYSV_ORIGIN=yes

        if test "${enable_64bit:-no}" = "yes"; then
           LD_LIBRARY_PATH_name="LD_LIBRARY_PATH_64"
        else
           LD_LIBRARY_PATH_name="LD_LIBRARY_PATH"
        fi
dnl SOLARIS
        dnl [PM] 3.9.1 use ${CC} for linking. This is the only correct
        dnl            way. If you think differently you are mistaken.
        if test $enable_cc_shld = "default"; then
           enable_cc_shld=yes
        fi

        gcc_shld=no
        sunpro_shld=no
        if test $enable_cc_shld = "yes"; then
           : ${SHLD="${CC}"}
           if test "${GCC:-no}" = "yes"; then
              gcc_shld=yes
              SHLD_ROPT="$gcc_ropt"
           else
              sunpro_shld=yes
              SHLD_ROPT="$cc_ropt"
           fi
        else # [PM] 3.9.1 SHLD is ld by default in 3.8 and 3.9.0. Probably CC is better
           dnl [PM] 3.9b5 WHY not use ${CC}??
           : ${SHLD='/usr/ccs/bin/ld'}
           SHLD_ROPT="$ld_ropt"
        fi
        : ${LD='/usr/ccs/bin/ld'}

dnl SOLARIS
        AC_MSG_CHECKING(if we should work around broken ar)
        if test "${enable_64bit:-no}" = "yes"; then
           dnl [PM] 3.8.7 For some reason the libsprt38.a does not get a valid archive
           dnl            symbol table. ranlib is a no-op so force regeneration of symbol
           dnl            table (using -s). -t is only there because -s is not allowed to
           dnl            appear by itself
           dnl            ([PM] 3.9.1 have similar symptoms om MacOS X
           dnl             caused by ar embedding the modification date
           dnl             into the file. The modification date is then
           dnl             changed by install. Perhaps the cause is the
           dnl             same on Solaris?).
           RANLIB="$AR -st"
           AC_MSG_RESULT([yes ($RANLIB)])
        else
           AC_MSG_RESULT(no)
        fi
dnl SOLARIS
        AC_MSG_CHECKING([whether cc is Sun Pro Workshop])
        AC_EGREP_CPP(sicstus_found_it,
            [
#ifdef __SUNPRO_C
sicstus_found_it
#endif
            ], has_sunprocc=yes, has_sunprocc=no)
        if test "${has_sunprocc:-no}" = "yes"; then
	    [SUNPRO_MAJOR=`${CC} -V 2>&1 | sed -n -e '1s/^.*[\t ]\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/\1/p'`]
	    [SUNPRO_MINOR=`${CC} -V 2>&1 | sed -n -e '1s/^.*[\t ]\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/\2/p'`]
            AC_MSG_RESULT([yes, version ${SUNPRO_MAJOR}.${SUNPRO_MINOR}])
        else
          AC_MSG_RESULT([no])
        fi

        # [PM] 3.9b2 -D_REENTRANT for Solaris threads semantics.
        #            See Sun "Multithreaded Programming Guide"
        CFLAGS_EXTRA_SEMANTICS="$CFLAGS_EXTRA_SEMANTICS -D_REENTRANT"
        dnl [PM] 4.0 Should these go on CFLAGS_EXTRA?
        # [PM] 4.0 (is this needed?)
        CFLAGS_EXTRA_SEMANTICS="$CFLAGS_EXTRA_SEMANTICS -D_FILE_OFFSET_BITS=64"
        dnl [PM] 4.0 FIXME: consider this as well
        dnl CFLAGS_EXTRA_SEMANTICS="$CFLAGS_EXTRA_SEMANTICS -D_LARGEFILE_SOURCE"
       
        dnl [PM] 4.0 Use standard compliant interfaces when in conflict with traditional Solaris
        CFLAGS_EXTRA_SEMANTICS="$CFLAGS_EXTRA_SEMANTICS -D_POSIX_PTHREAD_SEMANTICS"

        # [PM] 4.0 
        CFLAGS_EXTRA="$CFLAGS_EXTRA -D__EXTENSIONS__"
        dnl [PM] 4.0 Cannot set _XOPEN_SOURCE=600 unless we compile with c99
        dnl CFLAGS_EXTRA="$CFLAGS_EXTRA -D_XOPEN_SOURCE=600"

        if test "${has_sunprocc:-no}" = "yes"; then
            sun_pro_warnings=''
            cc_Werror=-errwarn
            if test "${DEBUG_BUILD:-no}" = "yes"; then
               dnl [PM]3.9b4 print error message tags to make it easier do selectively disable
               sun_pro_warnings="${sun_pro_warnings} -errtags=yes"
            fi

            dnl [PM] Suppress "warning: non-constant initializer: op "++" (E_NON_CONST_INIT)"
            dnl unfortunately this is not accepted by CC so will give
            dnl warning in Suite/cplus(s/d)
            dnl [PM] 3.9b4 Work around a bug in WorkShop cc 5.0. Reportedly fixed in 5.1
            dnl warns about non-constant initalizer in code like { int foo = bar++; ... }
            sun_pro_warnings="-erroff=E_NON_CONST_INIT $sun_pro_warnings"

            dnl [PM] 4.0 need to suppress these warnings also when not debug build
            dnl [PM] 3.9b4 cc warns about unreachable <CODE> for switch(...) if (0) {case 42: <CODE>}
            dnl      This happens a lot in wam() when in debug mode.
            dnl [PM] 3.9.1 we used to ignore E_STMT_NOT_REACHED, has the message changed name!?
            sun_pro_warnings="-erroff=E_STATEMENT_NOT_REACHED $sun_pro_warnings"
            CFLAGS_EXTRA="$CFLAGS_EXTRA -xstrconst"

dnl SOLARIS
            # [PM] 4.0 removed -dalign (it is unsafe, as noted below)
            # [PM] 3.8.6 Removed -Xa flag since it is default for cc and gives warning for CC
            # [PM] 3.8.6 Adding -Xa and -XO2 does not make a lot of sense, they are default
            # [PM] some 3.9 items brought into 3.8 trunk:
            # [MC] 3.9   -dalign is unsafe with some 3rd-party software (see PRM 2507)
            # [PM] 3.9b2 -mt (-D_REENTRANT and link with libthread)
            #            See Sun "Multithreaded Programming Guide"
            CFLAGS_EXTRA="$CFLAGS_EXTRA -mt $sun_pro_warnings"

            if test "${OPTFLAG:-no}" = "yes" ; then
                dnl [PM] 4.2 Sun Studio 11 incorrectly claims, at
                dnl least in some of its documentation, that -O is the
                dnl same as -xO2 on SPARC. This is false. Instead -O
                dnl seems to be -Ox3 (which is documented in Solaris
                dnl Studio 12u1). Using -O, kanyl64 miscompiled
                dnl copy_term.c, causing segfault when building
                dnl sprt.sav (using buildbinaries.sh but now when
                dnl doing manual build...).  So, we keep -xO2, also on
                dnl newer versions of Solaris Studio, until we
                dnl understand the issues involved.
                CFLAGS="$CFLAGS -xO2"

		AC_MSG_CHECKING([whether wam.c should be compiled with less optimization])
        AC_ARG_ENABLE(wam_c_less_optimizad,  [  --enable-wam_c_less_optimizad    Use decreased optimization level for wam.c to work around C compiler problems],
                [ use_wam_c_less_optimizad=$enableval ],
                [ use_wam_c_less_optimizad=no])
                if test "${use_wam_c_less_optimizad:-no}" = "yes"; then
  		  # [PM] 4.1.3 Sun Pro 12u1 (even with patch 141858-05) gets out of memory when compiling wam.c with -xO2 or above.
		  WAM_O_CFLAGS_EXTRA='-xO1'
                  AC_MSG_RESULT([yes ($WAM_O_CFLAGS_EXTRA)])
                else
                  AC_MSG_RESULT([no])
                fi
            fi

            # [PM] 4.0.3 Note: SunPro 12 says -KPIC is deprecated on
            # SPARC (but not x86) and that -xcode=pic32 should be used
            # instead on SPARC (but it is not available on x86). For
            # now we use -KPIC on SPARC as well since it is equivalent
            # to -xcode=pic32.
            : ${INCR_CFLAGS="$INCR_CFLAGS -KPIC"}

            case $PLATFORM in
              i386*|amd64*)
                   dnl FIXME: tune for specific CPU?
                   sunpro_cpu_flags=''
                   sunpro_app_regs_flags=""
              ;;
              sparc*)
                   dnl FIXME: tune for specific CPU?
                   sunpro_cpu_flags=''
                   dnl xref gcc_app_regs_flag below
                   sunpro_app_regs_flags="-xregs=no%appl"
              ;;
            esac
            case $PLATFORM in
              sparc64*)
                 # The SunPro (5.9?) compiler generates incorrect code when
                 # many floating point arguments are passed to a
                 # function. This breaks the apply_asm tests but does
                 # not affect SICStus itself.
                 SUITE_EXPECTED_FAILURES="${SUITE_EXPECTED_FAILURES}${SUITE_EXPECTED_FAILURES:+ }apply_asm apply_asm_consulted"
              ;;
            esac

dnl SOLARIS
            if test "${enable_64bit:-no}" = "yes"; then
                # [PM] 4.0.3 Old way to specificy sparc64 target
                sunpro_xtarget=-xtarget=generic64
                if "${CC}" -flags 2>/dev/null | ${POSIX_GREP} -F -q -e '-m64'; then
                  # [PM] 4.0.3 SunPro 12 way uses -m64/-m32 and complains about xtarget=generic64
                  sunpro_xtarget='-xtarget=generic -m64'
                fi

dnl [PM] 4.0 the SPARC64 target does not compile anyway with the SunPro 5.0 compiler so no need to special case it.
dnl                 case "$PLATFORM" in
dnl                   sparc*)
dnl                        dnl [PM] 4.0 generic64 is not supported by SunPro 5.0. When we start requiring SunPro 5.8 or later we can use it for all 64-bit targets
dnl                        dnl          -xarch=v9 should work for both 5.0 and newer compilers
dnl                        dnl sunpro_xtarget=-xtarget=generic64
dnl                        sunpro_xtarget=-xarch=v9
dnl                   ;;
dnl                 esac
            else # ! 64bit
                sunpro_xtarget=-xtarget=generic
            fi
            sunpro_arch_flags="${sunpro_cpu_flags} ${sunpro_xtarget}"
            CFLAGS="$CFLAGS $sunpro_arch_flags $sunpro_app_regs_flags"


            dnl [PM] 3.10.1 incremental linker in SunPro 5.0 barfs on
            dnl the object file generated for the data resource in
            dnl make test TESTS=spld1b_all_in_one.  We do not need the
            dnl incremental linker so turn it off unconditionally (also for user code)
            XILDOFF=-xildoff
            CFLAGS="${XILDOFF} $CFLAGS"

        elif test "${GCC:-no}" = "yes"; then
            : ${INCR_CFLAGS='-fPIC'}
dnl SOLARIS

            case $PLATFORM in
              i386*|amd64)
                   gcc_cpu_flags="-mtune=opteron"
                   gcc_app_regs_flags=""
              ;;
              sparc*)
                   gcc_cpu_flags="-mcpu=v9"
                   dnl To be fully SVR4 ABI compliant at the cost of some performance
                   dnl loss, specify `-mno-app-regs'.  You should compile libraries and
                   dnl system software with this option.
                   gcc_app_regs_flags="-mno-app-regs"
              ;;
            esac

            if test "${enable_64bit:-no}" = "yes"; then
                gcc_arch_flags="${gcc_cpu_flags} -m64"
            else # ! 64bit
                dnl [PM] 4.0 target v9 CPUs for 32 bit too. Now explcitly 32bits.
                gcc_arch_flags="${gcc_cpu_flags} -m32"
            fi
            CFLAGS="$CFLAGS $gcc_arch_flags $gcc_app_regs_flags"

        else # !GCC && !SunPro
            dnl [PM] 3.9.1 really not supported
            AC_MSG_ERROR([Compiler ${CC} not supported])
        fi
dnl SOLARIS

        dnl [PM] 4.0 Use pthreads instead of solaris threads.
        SOLARIS_THREADS="0"
        threads_libs="-lpthread"
        dnl : ${SOLARIS_THREADS=1}
        dnl threads_libs="-lthread"

        AC_MSG_CHECKING([os revision])
        os_rev=`uname -r 2> /dev/null`;
        AC_MSG_RESULT([${os_rev:-unknown}])
        AC_MSG_CHECKING([whether alternate thread library should be used])

        # [PM] 4.0 On Solaris 8 we need the new thread library (default from Solaris 9)
        if test "${os_rev:-unknown}" = "5.8"; then
          dnl [PM] Path to new alternative (T2) thread dir introduced
          dnl in Solaris 8 (and default in Solaris 9 and later).
          dnl We need it for library(timeout) and apparently for SPIO
          dnl I/O (see JasperThreadTest below).
          if test "${enable_64bit:-no}" = "yes"; then
            solaris_t2_thread_lib_dir=/usr/lib/lwp/64
          else
            solaris_t2_thread_lib_dir=/usr/lib/lwp
          fi
          SPLD_EXE_EXTRA_RPATH="${solaris_t2_thread_lib_dir}"
          KERNEL_SHLD_FLAGS="${KERNEL_SHLD_FLAGS:+${KERNEL_SHLD_FLAGS} }${SHLD_ROPT}${SPLD_EXE_EXTRA_RPATH}"
          if test "${SOLARIS_THREADS:-0}" = "0"; then # Using pthreads
            dnl [PM] 4.0 to get /usr/lib/lwp/{32,64}/libthread.so we need to link it explicitly when we use libpthread.so.
            dnl      Otherwise libpthread.so will load libthread using
            dnl      the RPATH of libthread.so which does not include
            dnl      /usr/lib/lwp/
            threads_libs="${threads_libs} -lthread"
          fi
        fi
        if test -n "${SPLD_EXE_EXTRA_RPATH}"; then
          AC_MSG_RESULT([yes, ${SPLD_EXE_EXTRA_RPATH}])
        else
          AC_MSG_RESULT([no])
        fi

dnl SOLARIS

        dnl [PM] 4.0 intro(3) says:
        dnl         "If portability is not required, the sockets
        dnl          interfaces in libsocket and libnsl are
        dnl          recommended over those in libxnet"
        dnl socket_libs="-lxnet"
        socket_libs="-lsocket -lnsl"

        dnl AIO
        spio_libs="-lrt"
        dnl Sockets (getaddrinfo et al)
        spio_libs="${spio_libs} ${socket_libs}"

        SOLARIS_LIBS="-ldl ${threads_libs} -lm ${spio_libs}"
        SPLD_EXE_LIBS="$SOLARIS_LIBS"
        KERNEL_SHLD_LIBS="$SOLARIS_LIBS"

        if test ${PREBUILT_INSTALL_ENABLED:-no} = yes; then
          can_prebuilt=yes
          SPLD_TOOLFLAGS="${SPLD_TOOLFLAGS:+${SPLD_TOOLFLAGS} }--moveable"
        fi
        # [PM] 4.2 Make spld --moveable the default
        enable_moveable_default='yes'

dnl SOLARIS
        dnl man sun ld:
        dnl -G        In dynamic mode only,  produce  a  shared  object.
        dnl           Undefined symbols are allowed.
        dnl -B symbolic
        dnl          In dynamic  mode  only.  When  building  a  shared
        dnl          object,  binds  references  to  global  symbols to
        dnl          their  definitions,  if  available,   within   the
        dnl          object.
        dnl FIXME: there are other -z flags we should consider

        dnl [PM] 3.9.1 See also SHLD_RTKERNELEXP
        dnl [PM] Note: map-file is sent to SHLD, not CC
        dnl [PD] 3.9 add option for scope reduction of symbols

        dnl [PM] 3.9.1 FIXME consider adding -z origin to SPLD_EXE_LDFLAGS.
        dnl A problem is that SPLD_EXE_LDFLAGS is passed to CC and (if
        dnl spld --shared/--jnilib) to SPLD_SHLD.
dnl SOLARIS
        dnl [PM] 3.9.1 consider adding no_undefined only to KERNEL_SHLD_FLAGS

        dnl [PM] 3.9.1 must be "" if MAPFILEOPT is used
        SHLD_RTKERNELEXP=""
        if test $gcc_shld = yes; then     # SHLD = GCC
           MAPFILEOPT="-Wl,-M,"
           # [PM] 3.9.1 Cannot have no undefined with GCC. Lots of 
           # "(symbol belongs to implicit dependency /usr/lib/libc.so.1)"
           # no_undefined="-Wl,-z,defs"
           no_undefined=""
           dnl [PM] 4.0 We must not depend on dynamic libgcc. Two reasons:
           dnl          1. The default setting got runtime linker
           dnl             errors when starting sicstus (probably
           dnl             fixable).
           dnl          2. We must not depend on the customer (and her
           dnl             customer) to have the dynamic libgcc
           dnl             installed (and findable by the run-time
           dnl             linker).
           dnl          The main downside appears to be that GCC
           dnl          exceptions will not work between DSO and/or
           dnl          executables built with static libgcc.
           dnl FIXME: do we need to explicitly pass -static-libgcc when
           dnl        building (spld-generated) executables as well?.
           dnl
           static_libgcc_flags='-static-libgcc'
           SHLDFLAGS="-shared $static_libgcc_flags $gcc_arch_flags"
        elif test $sunpro_shld = yes; then # SHLD = SunPro cc
           MAPFILEOPT="-Wl,-M,"
           dnl See gcc_shld above: no_undefined="-Wl,-z,defs"
           dnl  [PM] 3.10.1 -G implies -xildoff (see XILDOFF above)
           SHLDFLAGS="-G $sunpro_arch_flags"
        else                               # SHLD = ld
           MAPFILEOPT="-M " # note trailing space
           # [PM] 3.9.1 Cannot have no undefined with ld. Lots of 
           # "(symbol belongs to implicit dependency /usr/lib/libc.so.1)"
           # Unsurprising since we do not (and should not) pass -lc to SHLD
           # no_undefined="-z defs"
           no_undefined=""
           SHLDFLAGS="-G"
        fi
dnl SOLARIS
        dnl [PM] 3.9.1 Find unresolved refs while debugging (but not in users code in release)
        if test "${DEBUG_BUILD:-no}" = "yes"; then
           SHLDFLAGS="$SHLDFLAGS $no_undefined"
        fi

dnl SOLARIS
        : ${SPLFR_SHLD=$SHLD}
        : ${SPLFR_SHLDFLAGS="$SHLDFLAGS"}

dnl SOLARIS
        : ${SOCKETLIB='-lsocket'}

        case $PLATFORM in
         *-5.8) # Solaris 8
           dnl [PM] 4.0.3 Solaris 8 (at least our old unpatched 2000
           dnl version) hangs in JasperThreadTest unless the new
           dnl 'alternative (T2)' thread library is used.
           JAVAEXEC_ENV_ARGS="${JAVAEXEC_ENV_ARGS:+${JAVAEXEC_ENV_ARGS} }${LD_LIBRARY_PATH_name}=${solaris_t2_thread_lib_dir}"
         ;;
        esac

        if test "${enable_64bit:-no}" = "yes"; then  
           # [PM] 3.9.1 We need the 64-bit version of the JDK 1.4 JVM
           : ${JAVA_EXECOPTS=-d64}
        fi


        FLI_FILE=fli_dl.c
        case $PLATFORM in
          sparc-*)
            if test "${SP_FLI_APPLY_ASM_GENERIC:-no}" != "yes"; then
              FLI_APPLY_ASM_FILE=fli_sparc.s
            fi
            as_flags="-xarch=v8plus"
            gas_flags="-Av8plus -32"

          ;;
          sparc64-*)
            if test "${SP_FLI_APPLY_ASM_GENERIC:-no}" != "yes"; then
              FLI_APPLY_ASM_FILE=fli_sparc64.s
            fi
            as_flags="-xarch=v9"
            gas_flags="-Av9 -64"
          ;;
          i386-*)
            if test "${SP_FLI_APPLY_ASM_GENERIC:-no}" != "yes"; then
              FLI_APPLY_ASM_FILE=fli_x86.s
            fi
            as_flags=""
            gas_flags="--32"
          ;;
          amd64-*|i38664-*)
            if test "${SP_FLI_APPLY_ASM_GENERIC:-no}" != "yes"; then
              FLI_APPLY_ASM_FILE=fli_sysv_abi_x86_64.s
              AC_DEFINE(FLI_APPLY_ASM_SYSV_ABI_X86_64, [1])
            fi
            as_flags="-xarch=generic64"
            gas_flags="--64"
          ;;
        esac
        dnl [PM] 4.0 FIXME: We should consider using CC to compile assembly instead
        case "`${AS:-true} -V /dev/null 2>&1`" in
           *GNU*)
             ASFLAGS="${gas_flags}"
           ;;
           *)
             ASFLAGS="${as_flags}"
           ;;
        esac

        if test "${enable_64bit:-no}" = "yes"; then
           # resgen.pl does not know how to generate 64bit ELF. Use cc as fallback
           RESGEN_TYPE="cc"
        else
           RESGEN_TYPE="prefix"
        fi

        # [PM] Solaris headers do not have proper prototypes for SIG_IGN et al.        
        HAVE_PROTOTYPED_SIG_IGN=no
dnl SOLARIS

        dnl [PM] 4.0 setitimer signals sometimes arrive too early (seen on blues, SPARC32 Solaris 10). See library/timeout.c
        AC_DEFINE(SETITIMER_EARLY)

        dnl [PM] 3.9.1 to be backward compatible with 3.9.0 we could use:
        dnl SP_RTSYS_DIRNAME="lib"

        dnl For hiding all but the main procedure of foreign resources
        dnl # "" disables that feature for now
        dnl AC_MSG_WARN([Should enable SPLFR_SHLD_EXPORT_OPT on Solaris before 3.9.1 release/PM])
        dnl SPLFR_SHLD_EXPORT_OPT=""
        SPLFR_SHLD_EXPORT_ARG="${MAPFILEOPT}@SP_MAP_FILE@"
        dnl [PM] 3.9.1 Setting SPLFR_LD_EXPORT_ARG to "" will also work if the map-file hacking proves to be problematic
        dnl      We use a map-file to hide all functions except the main entry (e.g., sp_main_SPENV_charsio)
        dnl      We use -B reduce to make the symbol visibility reduction take effect immediately when ld -r is done
        dnl      We use -z noversion so that we can link against, e.g., charsio.s.o without requiring the final link to use a map file.
        dnl      If we do not use -z noversion we will, when using spld --static, get a lot of errors like 
        dnl "fu1_log                             /.../libsprt39.a(wamfunc.o)  (symbol has no version assigned)"
        dnl
        dnl For some reason -z noversion does not seem to be needed
        dnl with SPARC64 SunPro C 5.0. Why this is so I do not know. I
        dnl have not tried SPARC32 SunPro to see if this is SunPro or
        dnl 64bit related.
        
        SPLFR_LD_EXPORT_ARG="-M @SP_MAP_FILE@ -B reduce -z noversion"

        # [PM] 3.9.1 Solaris ld will apparently *not* add any -L<DIR> to runpath
        # (contrary to what GNU ld does on Solaris)
        LD_BUILDS_RPATH_FROM_L=no

	dnl [PD] 3.10.2  We need a default path to find the standard tar.
	DEFAULT_POSIX_PATH=/usr/bin

        AC_DEFINE(HAVE_PROC_SELF_FD)
        # [PM] 4.0 SunOS 5.8 does not have strerror_r but strerror is thread safe on Solaris
        AC_DEFINE(HAVE_THREAD_SAFE_STRERROR)

dnl SOLARIS
        ;;

dnl Windows-support using Cygwin shell tools
dnl [PM] 3.11.3 All Win32 stuff is only for source builds
dnl ============================================================
dnl ============================================================

dnl ============================================================
dnl ============================================================

    *)
        AC_MSG_ERROR([Unsupported platform: $PLATFORM])
        ;;
esac
dnl #################### END OF PLATFORM CFLAGS SETUP ETC ###############
dnl #####################################################################

dnl [PM] 4.2.1 SPRM 12368 We want all our code (and users foreign
dnl code) to be useable in DSOs, e.g. for all-in-one DSOs. The
dnl simplest fix is to ensure all code is compiled with INCR_CFLAGS
dnl and make INCR_CFLAGS a no-op.
CFLAGS="${CFLAGS} ${INCR_CFLAGS}"
dnl [PM] 4.2.1 No need for separate flags
INCR_CFLAGS=''


dnl ============================================================
dnl ============================================================

dnl [PM] 3.10.2 ################ THERE SHOULD BE LITTLE OR NO AC TRY RUN above
dnl [PM] 3.10.2 ################ CFLAGS should not have options added below
dnl See USER_CFLAGS and CFLAGS_EXTRA_SEMANTICS (which can affect
dnl floating point semantics among other things).

dnl [PM] 3.10.2 USER_CFLAGS is what user code should be compiled with
dnl             CFLAGS is what configure will use so should include
dnl             semantics-related flags.
USER_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $CFLAGS_EXTRA_SEMANTICS"

AC_MSG_CHECKING([C compiler flags during configure])
AC_MSG_RESULT([$CFLAGS])

AC_MSG_CHECKING([C compiler flags for user code])
AC_MSG_RESULT([$USER_CFLAGS])

AC_MSG_CHECKING([data resource support])
# [PM] "prefix" (direct .o(-prefix) generation), "win32res", "cc" (generic generate C), see spld.pl.in
: ${RESGEN_TYPE="cc"}
AC_MSG_RESULT($RESGEN_TYPE)

AC_SUBST(RESGEN_TYPE)

AC_MSG_CHECKING([whether multiple SICStus run-times is supported])
AC_ARG_ENABLE(multi-sp,      [  --disable-multi-sp            Disable multiple run-time support],
[enable_multi_sp_feature=$enableval])
dnl [PM] 3.11.2 Attention! multiple negations ahead
if test "${enable_multi_sp_feature:-yes}" = "no"; then
  SP_NO_MULTI_SP_FEATURE=yes
fi

: ${SP_NO_MULTI_SP_FEATURE:="no"}
if test "$SP_NO_MULTI_SP_FEATURE" != "no"; then
   AC_MSG_RESULT([no])
   AC_DEFINE(SP_NO_MULTI_SP_FEATURE)
   AC_SUBST(SP_NO_MULTI_SP_FEATURE)
   PERSISTENT_CONFIGURE_OPTIONS="$PERSISTENT_CONFIGURE_OPTIONS --disable-multi-sp"
else
   AC_MSG_RESULT([yes])

   AC_DEFINE(SP_NO_MULTI_SP_FEATURE, 0)
   AC_SUBST(SP_NO_MULTI_SP_FEATURE)
fi

dnl Inverted logic
AC_MSG_CHECKING([whether memory allocation can be hooked])
if test "${SP_NO_MEMORY_HOOKS:-no}" = "yes"; then
  AC_MSG_RESULT([no])
else
  AC_MSG_RESULT([yes])
fi
AC_SUBST([SP_NO_MEMORY_HOOKS])

AC_MSG_CHECKING([for JIT ABI])
if test "${SP_JIT_ABI:-unset}" = "unset"; then
   AC_MSG_RESULT([none])
else
   AC_MSG_RESULT([${SP_JIT_ABI}])
fi
AC_DEFINE_UNQUOTED([SP_JIT_ABI_STRING], ["${SP_JIT_ABI}"])
AC_SUBST([SP_JIT_ABI])

dnl [PM] 3.9.1 These should be set explicitly. It is too hard to get
dnl shared libs right for any useful defaults to make sense.
: ${LD='bad_default'}
if test "x$LD" = "xbad_default"; then
   AC_MSG_ERROR([LD not set. Do not rely on default value of LD and SHLD, Set them explicitly.])
fi
: ${SHLD='bad_default'}
if test "x$SHLD" = "xbad_default"; then
   AC_MSG_ERROR([SHLD not set. Do not rely on default value of LD and SHLD, Set them explicitly.])
fi

dnl [PM] 3.9.1 The name of the environment variable known as LD_LIBRARY_PATH on SysV ABI platforms.
dnl            E.g., DYLD_LIBRARY_PATH, LD_LIBRARYN32_PATH, ...
: ${LD_LIBRARY_PATH_name="bad_default"}
if test "x$LD_LIBRARY_PATH_name" = "xbad_default"; then
   AC_MSG_ERROR([LD_LIBRARY_PATH_name not set. Set it explicitly (possibly to empty if N/A).])
fi
AC_SUBST(LD_LIBRARY_PATH_name)


dnl Option to hard-code paths to dynamic library dependencies.
dnl [PM] 3.9.1b4 split LD_ROPT into CC_ROPT and SHLD_ROPT
dnl dnl [PM] 3.9.1 Was never right (missing space) : ${LD_ROPT="-R"}
dnl : ${LD_ROPT="bad_default"}
dnl if test "x$LD_ROPT" = "xbad_default"; then
dnl   AC_MSG_ERROR([LD_ROPT not set. Set it explicitly (possibly to empty if N/A).])
dnl fi

dnl AC_SUBST(LD_ROPT)

: ${CC_ROPT="bad_default"}
if test "x${CC_ROPT}" = "xbad_default"; then
   AC_MSG_ERROR([CC_ROPT not set. Set it explicitly (possibly to empty if N/A).])
fi

AC_SUBST(CC_ROPT)

: ${SHLD_ROPT="bad_default"}
if test "x$SHLD_ROPT" = "xbad_default"; then
   AC_MSG_ERROR([SHLD_ROPT not set. Set it explicitly (possibly to empty if N/A).])
fi

AC_SUBST(SHLD_ROPT)

: ${SPLD_SHLD_JNILIB_FLAGS=""}
AC_SUBST(SPLD_SHLD_JNILIB_FLAGS)


dnl [PM] 3.9.1 yes on platforms where ld adds -L<DIR> dirs to rpath
: ${LD_BUILDS_RPATH_FROM_L=no}
AC_SUBST(LD_BUILDS_RPATH_FROM_L)



dnl [PM] 4.1.3+ gone
dnl dnl [PM] 3.9.1 used by real-ld to call the real linker
dnl : ${GCC_PROG_NAME_LD="ld"}
dnl AC_MSG_CHECKING([ld program invoked by gcc])
dnl if test "x$GCC_PROG_NAME_LD" = "x"; then
dnl    AC_MSG_RESULT(unknown)
dnl else
dnl    AC_MSG_RESULT($GCC_PROG_NAME_LD)
dnl fi
dnl AC_SUBST(GCC_PROG_NAME_LD)

dnl [PM] 4.1.3+ gone
dnl # [PM] 3.9.1 Used also by InstallSICStus to determine if real-ld should be installed
dnl : ${SP_NEED_REAL_LD=no}
dnl AC_SUBST(SP_NEED_REAL_LD)

if test -z "$SHLDFLAGS"; then
   # [PM] 3.9.0 SHLD/SHLDFLAGS is not something for which there is a reasonable default
   AC_MSG_WARN([Expected SHLDFLAGS to be set in platform dependant way here])
   : ${SHLDFLAGS='-shared'}
fi

dnl [PM] 4.0 LIBS is what AC_CHECK_FUNCS uses and we want AC_CHECK_FUNCS to test what functions are available for the kernel.
LIBS="${KERNEL_SHLD_LIBS}"

AC_MSG_CHECKING([whether generic foreign language glue should be used])
if test "${SP_FLI_APPLY_ASM_GENERIC:-no}" = "yes"; then
  AC_DEFINE(SP_FLI_APPLY_ASM_GENERIC, [1])
  FLI_APPLY_ASM_FILE='' # fli_apply_asm_generic.c
  AC_MSG_RESULT([yes])
else
  AC_MSG_RESULT([no])
fi


dnl ============================================================
dnl ============================================================

AC_SUBST(PERLAPP_MODE)
AC_SUBST(PERLAPP_ENABLED)

dnl [PM] 3.10 decrypt and decompress sicstus.tar

dnl [PM] 3.11.3 always yes: AC_SUBST([MKDISTR_COMPRESS_AND_CRYPT],[yes])

: ${SP_INSTALL_DECRYPT=./spdecrypt}
AC_SUBST(SP_INSTALL_DECRYPT)

SP_CHECK_ABSOLUTE([ZCAT])
AC_PATH_PROG([ZCAT],[zcat$EXEEXT])

dnl must match MKDISTR_COMPRESS

dnl [PM] 3.10.1 SPRM 4391 This must be a path that is valid at install
dnl             time. Rely on PATH instead of hardwiring SICS specific location.
: ${SP_INSTALL_ZCAT=zcat}
AC_SUBST(SP_INSTALL_ZCAT)



dnl ============================================================
dnl ============================================================
dnl [PM] 3.11.0 USE_PAX, STDTAR are needed by InstallSICStus!

dnl [PD] 3.10.2 Use pax instead of tar in mkdistr for all platforms except
dnl             Linux. This is for the "inner" tar-package. For the "outer"
dnl             tar-package we use tar on all platforms, but make sure that
dnl             the tar-file can be read by old tar programs.
USE_PAX=yes

dnl [PD] 3.10.2 pax interchange format can handle very long paths and, as a
dnl             bonus which we perhaps should not take advantage of, non-ASCII
dnl             characters in file names.
dnl PAX_ARCHIVE_FORMAT=pax
dnl [PD] 3.10.2 Solaris can't handle pax interchange format. Use cpio instead.
PAX_ARCHIVE_FORMAT=cpio

case $PLATFORM in
    *linux*)
	USE_PAX=no
    ;;
esac
AC_SUBST(USE_PAX)
AC_SUBST(PAX_ARCHIVE_FORMAT)


if test "${DEFAULT_POSIX_PATH+set}" != set; then
  AC_MSG_ERROR([DEFAULT_POSIX_PATH not set, configure.in error])
fi

dnl [PM] 3.11.0 STDTAR is used by InstallSICStus if USE_PAX
dnl [PD] 3.10.2 check for standard tar and GNU tar
SP_CHECK_ABSOLUTE([STDTAR])
AC_PATH_PROG([STDTAR],[tar$EXEEXT],[false],[${DEFAULT_POSIX_PATH}])


dnl ============================================================
dnl ============================================================

#################################################################
#
# Default values
#
#################################################################

: ${CC='cc'}
dnl [PM] 3.10.2 always set : ${CFLAGS='-O'}
: ${ENABLE_STATLIB=yes}
: ${LD='ld'}
: ${HAVE_SYSV_ORIGIN=no}
: ${LD_R='ld -r'}
: ${SHSFX='so'}
dnl [PM] 3.9.1 suffix for static version of sprt. .lib on win32. Could
dnl            consider .s.o or .o for some platforms.
: ${RTKERNEL_STSFX="a"}

: ${RTKERNEL_BASENAME_WITH_DSO_SUFFIX="${RTKERNEL_BASENAME_SANS_SUFFIX}.${SHSFX}"}
: ${RTKERNEL_BASENAME_WITH_STAT_SUFFIX="${RTKERNEL_BASENAME_SANS_SUFFIX}.${RTKERNEL_STSFX}"}

: ${FLI_SHSFX="$SHSFX"}
: ${JNI_SHSFX="$SHSFX"}
dnl [PM] 4.1.3+ gone
dnl dnl [PM] 4.0 pre-linking dynamic resources was never good idea. Now disallow on all platforms
dnl : ${FLI_SHARED_PRELINKS=no}
: ${SHPRE='lib'}

: ${HIGH_RESOLUTION_TIME_CP=no}
AC_SUBST(HIGH_RESOLUTION_TIME_CP)

dnl [PM] 4.0 I do not know what -G was supposed to do. M4_FLAGS is always set here if M4 is.
dnl dnl [PM] 3.9.2b3 see M4_FLAGS above (I do not think M4 is ever unset
dnl dnl here since we use A C CHECK_PROG to search for m4 above.)
dnl dnl : ${M4='m4 -G'}
dnl : ${M4_FLAGS='-G'}
: ${SHELL='/bin/sh'}
: ${SOCKETLIB=''}
dnl [PM] WinCE
: ${COMCLIENTLIB=''}
: ${STSFX='s.o'}
: ${OUTPUT_OPT="-o "} # observe space after -o
: ${NOLINK_OUTPUT_OPT="-o "} # Note the space after -o
: ${SHLD_OUTPUT_OPT="-o "} # Note the space after -o
: ${MKDIR="${TOP_SRCDIR}/ensdir"}
dnl [PM] 3.9.1 not used : ${MKAUTOGEN="${TOP_SRCDIR}/mkautogen"}
: ${NOLINK_OPT="-c"}
dnl : ${WHICH=which}

dnl [PM] 4.1.3+ gone
dnl : ${hardware=`$UNAME -m`}

: ${LIBTOOL=""}
: ${DSMAINOBJ="main.$OBJEXT"} # [PM] 3.9 no SPAUXMAINOBJ here
: ${WINMAINOBJ=""}
dnl# [PM] 3.9b5 removed some unneded (Win32-only) objects
: ${CHARMAINOBJ="charmain.$OBJEXT intrpt.$OBJEXT $SPAUXMAINOBJ"}
dnl : ${CHARMAINOBJ="charmain.$OBJEXT spstdio.$OBJEXT cmdproc.$OBJEXT intrpt.$OBJEXT $SPAUXMAINOBJ"}
: ${KERNEL_SHLD_GENIMPLIB=""}
: ${SPLFR_SHLD_LASTARG=""}
dnl [PM] 3.10 gone : ${GENIMPLIB_MULTI_SP=""}
: ${IMPLIB=""}
dnl [PM] 3.10 gone : ${IMPLIB_MULTI_SP=""}
: ${QUOTECHAR="\""}
: ${PATHSEP=":"}
: ${RMDUMMY=""}
: ${TCLTK_DEFAULT="/usr/local /usr"}
: ${ULIMIT_DATA=""}
: ${MALLOC_ENV=""}
dnl [PM] 3.11.1 no ulimit on Win32
: ${ULIMIT_CMD="ulimit"}
: ${WIN32="no"}
: ${WIN64="no"}
: ${WINCE="no"}
dnl : ${AIXRTL=""}
dnl [PM] 3.9.1 renamed : ${AIXNOLIBPATH=""}
: ${CC_NOLIBPATH=""}

dnl [PM] 3.9.1 gone : ${AIXDSEXP=""}
dnl [PM] 3.9.1 gone : ${AIXRTEXP=""}
dnl [PM] 3.9.1 gone : ${SP_EXPFILE=""}
dnl : ${AIXRTKERNELEXP=""}
: ${SPLFR_SHLD=$SHLD}
: ${SPLFR_SHLDFLAGS=$SHLDFLAGS}
: ${SOLARIS_THREADS=0}
: ${SPCDECL=""}

# [PM] 3.9b5 whether SIG_IGN et al are properly prototyped. This is
# false on Solaris 7 but true on most other systems so we default to
# true.
: ${HAVE_PROTOTYPED_SIG_IGN=yes}
dnl # [PM] 3.9 no db support
dnl : ${DB_MODULE=''}
# [PM] 3.9b4 now on Win32 as well
: ${TIMEOUT_MODULE=timeout.po}
dnl [PM] 4.0 This will be used during installations. FIXME: Disable spaceout.po unconditionally until it is reimplemented.
: ${SPACEOUT_MODULE=''}

dnl [PM] 3.11.2 
: ${CLPQ_MODULE='clpq.po'}
: ${CLPR_MODULE='clpr.po'}

dnl [PM] See Suite/Makefile
AC_ARG_VAR(BENCH_ITERATIONS_SCALE,[])
: ${BENCH_ITERATIONS_SCALE=100}
AC_SUBST(BENCH_ITERATIONS_SCALE)


if test "x$ENABLE_STATLIB" = "xyes"; then
dnl : ${KERNEL_STATLIB="${RTKERNEL_BASENAME_SANS_SUFFIX}.${RTKERNEL_STSFX}"}
: ${RTKERNEL_BASENAME_WITH_STAT_SUFFIX="${RTKERNEL_BASENAME_SANS_SUFFIX}.${RTKERNEL_STSFX}"}
fi
dnl AC_SUBST(KERNEL_STATLIB)

if test ! -z "$IMPLIB"; then
  AC_MSG_CHECKING([what name to use for the kernel import library])
  AC_MSG_RESULT([$IMPLIB])
fi

AC_MSG_CHECKING([what name to use for the kernel static library])
AC_MSG_RESULT([$RTKERNEL_BASENAME_WITH_STAT_SUFFIX])

dnl [PM] 4.1.3+ gone
dnl AC_MSG_CHECKING([whether shared foreign resource (<res>.$FLI_SHSFX) can be prelinked])
dnl AC_MSG_RESULT([$FLI_SHARED_PRELINKS])

dnl [PM] 3.9.1 On MacOS X this is "-install_name @executable_path/....." ([PM] 4.2 or similiar)
: ${KERNEL_SHLD_FLAGS=""}
AC_MSG_CHECKING([special flags when linking runtime kernel])
if test -z "${KERNEL_SHLD_FLAGS}"; then
   AC_MSG_RESULT([none])
else
   AC_MSG_RESULT([${KERNEL_SHLD_FLAGS}])
fi
AC_SUBST(KERNEL_SHLD_FLAGS)

dnl [PM] 3.9.1 FIXME should print out special libs used when linking SP RT and when linking against static SP RT...

dnl [PM] 3.9.1 SP_RTSYS_DIRNAME is the name of the directory
dnl co-located with a run-time system where all the sicstus stuff
dnl resides. In 3.8 and 3.9.0 this was "lib" for UNIX and sp39 for
dnl windows. However, "lib" is obviously a bad choice since it is not
dnl a sicstus specific name (although ../lib would have made some
dnl sense).  The poor choice of name becomes an issue on MacOS X where
dnl we always want to embed this name using -install_name for
dnl libsprt39.dylib

dnl [PM] 3.9.1 backward-compatibilty-be-gone
dnl : ${SP_RTSYS_DIRNAME="lib"}

dnl [PM] 3.11.2 overridden for win32
: ${SP_RTSYS_DIRNAME="${SP_RTSYS_DIRNAME_UNIX}"}


AC_SUBST(SP_RTSYS_DIRNAME)
AC_DEFINE_UNQUOTED(SP_RTSYS_DIRNAME, "$SP_RTSYS_DIRNAME")


dnl [PM] 3.10.1 Default UNIX name needed for doc/ for all platforms
AC_SUBST(SP_RTSYS_DIRNAME_UNIX)

dnl [PM] 3.10.1 Windows name needed for doc/ for all platforms and version.c on Win.
AC_SUBST(SP_RTSYS_DIRNAME_WIN)

: ${SP_EMULATOR_DIRNAME="$SP_DIRNAME"}
AC_SUBST(SP_EMULATOR_DIRNAME)
AC_DEFINE_UNQUOTED(SP_EMULATOR_DIRNAME, "$SP_EMULATOR_DIRNAME")


AC_SUBST(SPLFR_SHLD)
AC_SUBST(SPLFR_SHLDFLAGS)

dnl
: ${SPLFR_SHLD_EXPORT_ARG=bad_value}
if test "x$SPLFR_SHLD_EXPORT_ARG" = "xbad_value"; then
  AC_MSG_ERROR([SPLFR_SHLD_EXPORT_ARG should be set explicitly (to empty if N/A)])
fi
AC_MSG_CHECKING([splfr shared linker export argument])
if test -z "$SPLFR_SHLD_EXPORT_ARG"; then
  AC_MSG_RESULT([none])
else
  AC_MSG_RESULT([$SPLFR_SHLD_EXPORT_ARG])
fi

AC_SUBST(SPLFR_SHLD_EXPORT_ARG)

: ${SPLFR_LD_EXPORT_ARG=bad_value}
if test "x$SPLFR_LD_EXPORT_ARG" = "xbad_value"; then
  AC_MSG_ERROR([SPLFR_LD_EXPORT_ARG should be set explicitly (to empty if N/A)])
fi
AC_SUBST(SPLFR_LD_EXPORT_ARG)

dnl [PM] 3.9.1 SPLFR_SHLD_EXPORT_OPT has been generalized to SPLFR_SHLD_EXPORT_ARG
dnl dnl [PM] 3.9.1 SPLFR_SHLD_EXPORT_OPT is used to export only the foreign resource set-up function
dnl dnl            e.g., "-exported_symbol ". It should be set to "" if not applicable
dnl : ${SPLFR_SHLD_EXPORT_OPT=bad_value}
dnl if test "x$SPLFR_SHLD_EXPORT_OPT" = "xbad_value"; then
dnl   AC_MSG_ERROR([SPLFR_SHLD_EXPORT_OPT should be set explicitly (to empty if N/A)])
dnl fi
dnl AC_SUBST(SPLFR_SHLD_EXPORT_OPT)

: ${SHLD_RTKERNELEXP="bad_value"}
if test "x$SHLD_RTKERNELEXP" = "xbad_value"; then
   AC_MSG_ERROR([SHLD_RTKERNELEXP not set. Set it explicitly (possibly to empty if N/A).])
fi
AC_SUBST(SHLD_RTKERNELEXP)

case $PLATFORM in
   *win32*)
     AC_MSG_CHECKING([for Win32 special spld flags to SHLD ($SHLD)])
     if test -z "$WIN32_SPLD_SHLD_SPECIAL"; then
       AC_MSG_RESULT(none)
     else
       AC_MSG_RESULT($WIN32_SPLD_SHLD_SPECIAL)
     fi

     AC_MSG_CHECKING([for Win32 special spld flags to C-compiler (${CC})])
     if test -z "$WIN32_SPLD_CC_SPECIAL"; then
       AC_MSG_RESULT(none)
     else
       AC_MSG_RESULT($WIN32_CC_SHLD_SPECIAL)
     fi

   ;;
esac

dnl [PM] 3.9.1 gone: AC_SUBST(SP_EXPFILE)
AC_SUBST(LIBTOOL)
AC_SUBST(LD)
AC_SUBST(LD_R)
AC_SUBST(HAVE_SYSV_ORIGIN)
AC_SUBST(OUTPUT_OPT)
AC_SUBST(NOLINK_OUTPUT_OPT)
AC_SUBST(SHLD_OUTPUT_OPT)
AC_SUBST(NOLINK_OPT)
AC_SUBST(KERNEL_SHLD_GENIMPLIB)
AC_SUBST(SPLFR_SHLD_LASTARG)
dnl [PM] 3.10 gone AC_SUBST(GENIMPLIB_MULTI_SP)
AC_SUBST(ENABLE_STATLIB)
dnl AC_SUBST(WHICH)
AC_SUBST(PATHSEP)
AC_SUBST(WIN32_EXTRAOBJS)
AC_SUBST(WIN32_SPLD_SHLD_SPECIAL)
AC_SUBST(WIN32_SPLD_CC_SPECIAL)
AC_SUBST(WIN32)
AC_SUBST(WIN64)
AC_SUBST(WINCE)
AC_SUBST(IMPLIB)
dnl [PM] 3.10 gone AC_SUBST(IMPLIB_MULTI_SP)
AC_SUBST(QUOTECHAR)
AC_SUBST(DSMAINOBJ)
AC_SUBST(WINMAINOBJ)
AC_SUBST(CHARMAINOBJ)
AC_SUBST(SPAUXOBJ)
AC_SUBST(SHPRE)
AC_SUBST(ULIMIT_DATA)
AC_SUBST(ULIMIT_CMD)
AC_SUBST(RMDUMMY)
AC_SUBST(TIMEOUT_MODULE)
AC_SUBST(SPACEOUT_MODULE)
: ${CHR_MODULE=chr.po}
AC_SUBST(CHR_MODULE)
AC_SUBST(CLPQ_MODULE)
AC_SUBST(CLPR_MODULE)
AC_SUBST(MALLOC_ENV)

AC_DEFINE_UNQUOTED(SPCDECL,$SPCDECL)

dnl [PM] 4.1.3+ gone
dnl AC_DEFINE_UNQUOTED(HOST_TYPE,"$host")
AC_DEFINE_UNQUOTED(SHSFX,"$SHSFX")
AC_DEFINE_UNQUOTED(FLI_SHSFX,"$FLI_SHSFX")
dnl AC_DEFINE_UNQUOTED(JNI_SHSFX,"$JNI_SHSFX")
AC_DEFINE_UNQUOTED(RTKERNEL_BASENAME_SANS_SUFFIX_STRING, "$RTKERNEL_BASENAME_SANS_SUFFIX")
AC_DEFINE_UNQUOTED(RTKERNEL_BASENAME_WITH_DSO_SUFFIX_STRING, "$RTKERNEL_BASENAME_WITH_DSO_SUFFIX")
AC_DEFINE_UNQUOTED(SHPRE,"$SHPRE") dnl for config.h
AC_DEFINE_UNQUOTED(SYSTEM_NAME,"$PLATFORM")
dnl [PM] 4.1.3+ gone
dnl AC_DEFINE_UNQUOTED(HARDWARE_NAME,"$hardware")
dnl [PM] 4.1.3+ gone
dnl AC_DEFINE_UNQUOTED(NODE_NAME,"$nodename")
AC_DEFINE_UNQUOTED(SOLARIS_THREADS,$SOLARIS_THREADS)

: ${CANNOT_SET_APP_PATHS=no}
dnl CANNOT_SET_APP_PATHS has inverted meaning from AC_MSG_CHECKING
AC_MSG_CHECKING([whether SICStus can set SP_APP_DIR/SP_RT_DIR])
if test "x$CANNOT_SET_APP_PATHS" != "xyes"; then
   AC_MSG_RESULT(yes)
else
   AC_MSG_RESULT(no)
   AC_DEFINE(CANNOT_SET_APP_PATHS)
fi


# [PM] 3.9 (roughly "have POSIXLY correct sigaction")
: ${POSIX_SIGNALS=yes}

if test "$POSIX_SIGNALS" = "yes"; then
   AC_DEFINE(POSIX_SIGNALS)
fi

dnl ============================================================
dnl ============================================================


if test ".$shsfx_needs_versions." = ".yes."; then
    SHVER=".$SICSTUS_MAJOR_VERSION.$SICSTUS_MINOR_VERSION"
else
    SHVER=""
fi
AC_SUBST(SHVER)

dnl [PM] 3.9.1 removed. -lm should be added elsewhere if needed (probably on SPLD_EXE_LIBS et al)
dnl case $PLATFORM in 
dnl     *win32*|*rhapsody-*|*darwin-*)
dnl         : # no-op, they have no -lm
dnl         ;;
dnl     *)
dnl         LDFLAGS="$LDFLAGS -lm"
dnl         tcltk_extra_libs="$tcltk_extra_libs -lm"
dnl         ;;
dnl esac

    
dnl ============================================================
dnl ============================================================

dnl [PM] 3.10.1 this part is needed in distributions to fill in ENABLE_CLPFD in Common for Suite/Makefile
AC_MSG_CHECKING(CLPFD)
ENABLE_CLPFD=yes

dnl ============================================================
dnl ============================================================

dnl [PM] 3.10.1 this part is needed in distributions to fill in ENABLE_CLPFD in Common for Suite/Makefile
AC_MSG_RESULT($ENABLE_CLPFD)
if test ".$ENABLE_CLPFD" != ".yes"; then
   AC_DEFINE(ENABLE_CLPFD,0)
else
   AC_DEFINE(ENABLE_CLPFD,1)
fi
AC_SUBST(ENABLE_CLPFD)

dnl ============================================================
dnl ============================================================


dnl [PM] 3.9.1 type sizes
dnl Since the name of available types may differe between compilers on
dnl the same platform we do this even on binary installs. Not clear
dnl what would be the best way to handle this.
dnl
dnl We want our own SP_-prefixed names so we need explicit AC_DEFINE_UNQUOTED.
dnl Remarkably the use of the cache-names (ac_cv_...) is documented as
dnl the way to do these kind of things.

dnl [PM] Adding a zero for cross-compilation default inhibits a warning from autoconf.
dnl      We do not support cross compiling anyway.

AC_CHECK_SIZEOF(void *,0) dnl [PM] 3.10.1 SIZEOF_VOID_P and ac_cv_sizeof_void_p, see below

AC_CHECK_SIZEOF(short,0) dnl SIZEOF_SHORT
AC_DEFINE_UNQUOTED(SP_SIZEOF_SHORT, $ac_cv_sizeof_short)

AC_CHECK_SIZEOF(int,0) dnl SIZEOF_INT
AC_DEFINE_UNQUOTED(SP_SIZEOF_INT, $ac_cv_sizeof_int)

AC_CHECK_SIZEOF(long,0) dnl SIZEOF_LONG
AC_DEFINE_UNQUOTED(SP_SIZEOF_LONG, $ac_cv_sizeof_long)

AC_CHECK_SIZEOF(void *,0) dnl SIZEOF_VOID_P
AC_DEFINE_UNQUOTED(SP_SIZEOF_VOID_P, $ac_cv_sizeof_void_p)

dnl [PM] 4.0.5 see prolog_primitive_type_size
AC_CHECK_ALIGNOF(char)
AC_CHECK_ALIGNOF(short)
AC_CHECK_ALIGNOF(int)
AC_CHECK_ALIGNOF(long)
AC_CHECK_ALIGNOF(long long)
AC_CHECK_ALIGNOF(float)
AC_CHECK_ALIGNOF(double)
AC_CHECK_ALIGNOF(void *)

dnl [PM] 3.9.1b4 moved from config.c
AC_MSG_CHECKING([for log2 sizeof word])
case $ac_cv_sizeof_void_p in
  4)
    AC_DEFINE(LogSizeOfWord, 2)
    AC_MSG_RESULT(2)
  ;;
  8)
    AC_DEFINE(LogSizeOfWord, 3)
    AC_MSG_RESULT(3)
  ;;
  *)
    AC_MSG_ERROR([unsupported size ($ac_cv_sizeof_void_p) of void*. Expected sizeof(void*) to be 4 or 8])
esac

AC_CHECK_SIZEOF(long long,0) dnl SIZEOF_LONG_LONG
AC_DEFINE_UNQUOTED(SP_SIZEOF_LONG_LONG, $ac_cv_sizeof_long_long)

dnl AIX, Win32
AC_CHECK_SIZEOF(__int64,0) dnl SIZEOF___INT64
AC_DEFINE_UNQUOTED(SP_SIZEOF___INT64, $ac_cv_sizeof___int64)

dnl [PM] 4.0.5 autoconf 2.63 can get the idea that we are compiling for universal binaries on Mac OS X.
dnl            The symptom of incorrect SP_BIGENDIAN is a segfault in sicstus -R
dnl
dnl Formatting of the arguments is a little sensitive
AC_C_BIGENDIAN([
                 # if true
                 AC_DEFINE(SP_BIGENDIAN)
                 AC_SUBST(SP_BIGENDIAN, yes)
               ],
               [
                 # if false
                 AC_SUBST(SP_BIGENDIAN, no)
               ],
               [
                 # if unknown
                 AC_MSG_ERROR([unknown endianness presetting ac_cv_c_bigendian=no (or yes) will help])
               ],
               [
                 # if universal (should not happen, need to set ac_cv_c_bigendian above
                 AC_MSG_ERROR([universal endianness is not supported. Presetting ac_cv_c_bigendian=no (or yes) will help])
               ])
               
dnl 
dnl if test $ac_cv_c_bigendian = yes; then
dnl   AC_DEFINE(SP_BIGENDIAN)
dnl   AC_SUBST(SP_BIGENDIAN, yes)
dnl else
dnl   AC_SUBST(SP_BIGENDIAN, no)
dnl fi


dnl ################################################################
dnl #
dnl # X11
dnl #
dnl ################################################################

dnl [PM] 4.0 Turns out that AC_PATH_XTRA is broken, it will not find
dnl the 32-bit libs on a x86_64 Linux whatever we do (due to imake
dnl lossage or some such, I think).
dnl
dnl [PM] 4.0 NOTE: X11 (and similar) must be processed AFTER setting CC, CFLAGS, etc.
dnl      What happened was that 64-bit libraries were used when
dnl      building with --disable-64bit on Linux x86_64 (zjuk).

dnl AC_PATH_X
AC_PATH_XTRA


dnl ################################################################
dnl #
dnl # Berkeley DB
dnl #
dnl ################################################################

# [PD] 3.9.2 Add option to explicitly set the required minimum version of BDB
# [PD] 3.10 Default is now 4.1.24
# [PD] 4.0 Bump to 4.4.16
# [PD] 4.0.0 Bump to 4.5.20
# [PM] 4.1.0 Bump to 4.8.24
# [PM] 4.3.0 Bump to 6.0.30
BDB_VERSION_REQUIRED_default='6.0.30'
AC_ARG_WITH(bdbversion,
                        [  --with-bdbversion     Specify Berkeley DB version. E.g: 4.8.24, 6.0.30 or similar],
	    [ BDB_VERSION_REQUIRED=$withval ],
	    [ BDB_VERSION_REQUIRED="${BDB_VERSION_REQUIRED_default}"])
AC_MSG_CHECKING([required Berkeley DB version])
AC_MSG_RESULT([$BDB_VERSION_REQUIRED])

if test "${BDB_VERSION_REQUIRED}" != "${BDB_VERSION_REQUIRED_default}"; then
    PERSISTENT_CONFIGURE_OPTIONS="${PERSISTENT_CONFIGURE_OPTIONS} --with-bdbversion=${BDB_VERSION_REQUIRED}"
fi


BDB_MAJOR_REQUIRED=`echo "${BDB_VERSION_REQUIRED}" | sed -n -e 's/^\(.*\)\..*\..*$/\1/p'`
BDB_MINOR_REQUIRED=`echo "${BDB_VERSION_REQUIRED}" | sed -n -e 's/^.*\.\(.*\)\..*$/\1/p'`
BDB_PATCH_REQUIRED=`echo "${BDB_VERSION_REQUIRED}" | sed -n -e 's/^.*\..*\.\(.*\)$/\1/p'`


SP_BDB_LIB_BASE_NAME_WIN=libdb${BDB_MAJOR_REQUIRED}${BDB_MINOR_REQUIRED}
SP_BDB_LIB_BASE_NAME_UNIX=db-${BDB_MAJOR_REQUIRED}.${BDB_MINOR_REQUIRED}

dnl [PM] 3.10.1 needed in doc/
AC_SUBST(SP_BDB_LIB_BASE_NAME_WIN)
AC_SUBST(SP_BDB_LIB_BASE_NAME_UNIX)


AC_MSG_CHECKING([whether to use Berkeley DB])
AC_ARG_WITH(bdb,        [  --with-bdb=DIR          Location of Berkeley DB installation, e.g., /usr/local/BerkeleyDB],
    [bdb_path_arg="$withval"],
    [bdb_path_arg=""])

dnl [PM] 3.9.1+ Used by GUI installer (this arg was not in the initial 3.9.1 build).
AC_ARG_WITH(libdb,
[  --with-libdb            Specify full path of libdb<ver>.so. 
                           Used by installer. Overrides --with-bdb but not --without-bdb],
	    [LIBDB_PATH=$withval])

if test "${enable_foreign_resources:-yes}" != "no"; then
  bdb_wanted=yes
else
  bdb_wanted=no
fi
bdb_explicit=no

case "${LIBDB_PATH:-no}" in
  yes)
    AC_MSG_ERROR([--with-libdb must have an argument])
  ;;
  no) # --without-libdb
    LIBDB_PATH='' # ignore --without-libdbd and --with-libdb=""
  ;;
  *) # --with-libdb=PATH
    bdb_explicit=yes 
  ;;
esac

case "${bdb_path_arg}" in
  "") # no --with(out)-bdb argument at all
    :
  ;;
  yes) # --with-bdb, --with-bdb=yes
    bdb_explicit=yes
    bdb_path_arg=''
  ;;
  no) # --without-bdb overrides --with-libdb
    LIBDB_PATH=''
    bdb_explicit=no
    bdb_wanted=no
  ;;
  *) # --with-bdb=PATH
    bdb_path_arg=${bdb_path_arg%/} # strip trailing /
    bdb_explicit=yes
    :
  ;;
esac


## [PM] 3.8.6 Allow to configure without BDB (--without-bdb)
if test "${bdb_wanted:-no}" = "no"; then
   AC_MSG_RESULT([no])
   bdb_path_arg=""
elif test "${bdb_explicit:-no}" = "yes"; then
   AC_MSG_RESULT([yes])
else
   AC_MSG_RESULT([yes, if possible])
fi

## [PM] 4.0
## here bdb_wanted=yes if bdb should be configured, otherwise
## bdb_explicit=no means failure to configure should not be considered an error

if test "${bdb_wanted}" = "yes"; then

dnl [PM] 4.0 Rewrite BDB detection
dnl
dnl Input:
dnl   bdb_path_arg   This must be a common prefix of the path to the import lib (i.e. UNIX DSO) and the include directory
dnl   LIBDB_PATH     This should be the path to the UNIX DSO (used from the GUI installer)
dnl
dnl   These two are mutually exclusive, LIBDB_PATH overrides. If neither specified, use heuristics(*) if binary install.
dnl   
dnl   possible paths:
dnl   . bdb_path/include, bdb_path/lib (expected case)
dnl   . bdb_path/include/VERS, bdb_path/lib/VERS (VERS == db${BDB_MAJOR} for DarwinPorts on MacOS X)
dnl   . bdb_path/include/VERS, bdb_path/lib      (VERS == db${BDB_MAJOR}${BDB_MINOR} for fink on MacOS X)
dnl   We will treat all VERS-patterns the same and try all naming variants.
dnl   
dnl   (*) heuristics used:
dnl   . system include, system lib so no extra flags needed
dnl   . /usr/local/BerkeleyDB.$BDB_MAJOR_REQUIRED.$BDB_MINOR_REQUIRED/{include,lib}
dnl
dnl Output: (BDBINC, BDBLIB, BDB_MODULE are also needed by InstallSICStus)
dnl   BDBINC
dnl   BDBLIB
dnl   BDB_MODULE
dnl   BDB_PATH   Used by spld to replace prefixes of paths in BDBLIB

if test "${WIN32:-no}" = "yes"; then
  dnl Win32 has not been updated for new bdb detection
  bdb_use_new_detection=no
else # UNIX
  dnl [PM] 4.0 now default, set to "no" to use old bdb detection
  bdb_use_new_detection_default=yes
fi

AC_ARG_ENABLE(bdb-new-detection,       [  --enable-bdb-new-detection        Internal],
	[bdb_use_new_detection="$enableval"],
	[bdb_use_new_detection="$bdb_use_new_detection_default"])


if test "${bdb_use_new_detection:-no}" = "yes"; then # new bdb detection
dnl AC_MSG_NOTICE([DBG: using new BDB detection])

dnl Note: "${bdb_use_new_detection:-no}" = "yes" (only used on Posix nowadays)

dnl [PM] 4.0.3 BDBINC is needed by InstallSICStus
dnl if test "${sp_isbindistr:-no}" = "yes"; then
dnl   bdb_includedir_needed=no
dnl else
  bdb_includedir_needed=yes
dnl fi

bdb_configured=no

if test -z "${bdb_path_arg}"; then
  dnl 'system' is treated specially
  bdb_path_heuristics="system"

  dnl platform specific defaults
  case "${PLATFORM}" in
     *darwin-*)
       bdb_path_heuristics="${bdb_path_heuristics} /opt/local" # DarwinPorts
       bdb_path_heuristics="${bdb_path_heuristics} /sw" # fink
     ;;
  esac

  dnl platform independent defaults

  dnl finally look in bdb build-from-source default installation directory
  dnl Should match what bdb configure.ac does, currently (4.4.16) AC PREFIX DEFAULT(/usr/local/BerkeleyDB.MAJOR.MINOR)
  bdb_path_heuristics="${bdb_path_heuristics} /usr/local/BerkeleyDB.$BDB_MAJOR_REQUIRED.$BDB_MINOR_REQUIRED"
fi


# If this ends with bdb_configured=yes then it shold have set BDBINC, BDBLIB, BDB_MODULE, BDB_PATH
#
for templates in \
                 "BDB_PATH/include BDB_PATH/lib"           \
                 "BDB_PATH/include/VERS BDB_PATH/lib/VERS" \
                 "BDB_PATH/include/VERS BDB_PATH/lib"      \
              ; do
  dnl AC_MSG_NOTICE([DBG: trying templates ${templates}])
  if test "${bdb_configured:-no}" = "yes"; then
    dnl AC_MSG_NOTICE([DBG: already found configuration])
    break
  fi

  # set include_template = templates[0]
  # set lib_template     = templates[1]
  include_template=""
  lib_template=""
  for template in ${templates}; do
     if test -z "${include_template}"; then
       include_template="${template}"
     else
       lib_template="${template}"
     fi
  done # template
  dnl AC_MSG_NOTICE([DBG: trying include_template=${include_template}, lib_template=${lib_template}])

  dnl if LIBDB_PATH is set then only loop once, with bdb_path=""
  dnl if explicit --with-bdb then only loop once with bdb_path set to that path
  dnl otherwise, loop through all paths on bdb_path_heuristics 
  dnl [PM] 3.12.8 The following line gives a syntax error on Solaris default shell. That shell is broken, not this configure file!
  dnl             The right fix is to invoke configure with /usr/xpg4/bin/sh on solaris (as is done by SP4 InstallSICStus).
  dnl
  for bdb_path in ${LIBDB_PATH:+""} ${LIBDB_PATH:-${bdb_path_arg:+${bdb_path_arg}} ${bdb_path_arg:-${bdb_path_heuristics}} }; do
    dnl AC_MSG_NOTICE([DBG: trying bdb_pat "${bdb_path}"])

    if test "${bdb_configured:-no}" = "yes"; then
      dnl AC_MSG_NOTICE([DBG: already found configuration])
      break
    fi

  for vers in "db${BDB_MAJOR_REQUIRED}${BDB_MINOR_REQUIRED}" "db${BDB_MAJOR_REQUIRED}"; do
    dnl AC_MSG_NOTICE([DBG: trying vers ${vers}])

    if test "${bdb_configured:-no}" = "yes"; then
      dnl AC_MSG_NOTICE([DBG: already found configuration])
      break
    fi

    lib_vers_template=`echo "${lib_template}" | sed -e "s@VERS@${vers}@"`
    # lib_vers_template is now something like BDB_PATH/lib/db44
    dnl AC_MSG_NOTICE([DBG: trying lib_vers_template=${lib_vers_template}])

    include_vers_template=`echo "${include_template}" | sed -e "s@VERS@${vers}@"`
    # include_vers_template is now something like BDB_PATH/include/db44

    bdb_path_candidate=""
    bdb_libdir_candidate=""
    # Set bdb_path_candidate and bdb_libdir_candidate
    if test -n "${LIBDB_PATH}"; then # --with-libdb case
      dnl AC_MSG_NOTICE([DBG: LIBDB_PATH case])

      lib_vers_sed_pattern=`echo "${lib_vers_template}" | sed -e 's@BDB_PATH@\\\\(..*\\\\)@'`
      # lib_vers_sed_pattern is now something like \(..*\)/lib/db44

      bdb_libdir_candidate=`dirname "$LIBDB_PATH"`
      # bdb_libdir_candidate is now something like /opt/local/lib/db44

      dnl AC_MSG_NOTICE([DBG: lib_vers_sed_pattern==${lib_vers_sed_pattern}, bdb_libdir_candidate=${bdb_libdir_candidate}])
      echo DEBUG DEBUG DBG: sed -e 's@^'"${lib_vers_sed_pattern}"'$@\1@'
      bdb_path_candidate=`echo "${bdb_libdir_candidate}" | sed -e 's@^'"${lib_vers_sed_pattern}"'$@\1@'`
      # bdb_path_candidate is now something like /opt/local
    elif test "${bdb_path}" = "system"; then # special --with-bdb case, use system defaults
      dnl AC_MSG_NOTICE([DBG: --with-bdb try system defaults])
      bdb_path_candidate='system'
      bdb_libdir_candidate='system'
    else # --with-bdb case
      dnl AC_MSG_NOTICE([DBG: --with-bdb or with-bdb=PATH case])

      bdb_path_candidate="${bdb_path}"
      # bdb_path_candidate is now something like /opt/local

      bdb_libdir_candidate=`echo "${lib_vers_template}" | sed -n -e "s@BDB_PATH@${bdb_path_candidate}@p"`
      # bdb_libdir_candidate is now something like /opt/local/lib/db44

      # FIXME: verify that there is an appropriately named DSO in bdb_libdir_candidate (is this really needed, given AC TRY LINK below)
      dnl AC_MSG_NOTICE([DBG: FIXME: VERIFY THAT THERE IS AN APPROPRIATELY NAMED DSO IN BDB_LIBDIR_CANDIDATE])

    fi # --with-bdb case
    dnl AC_MSG_NOTICE([DBG: bdb_libdir_candidate=${bdb_libdir_candidate}])

    if test "${bdb_libdir_candidate}" != "system" && test ! -d "${bdb_libdir_candidate}"; then
       dnl AC_MSG_NOTICE([DBG: bdb_libdir_candidate=${bdb_libdir_candidate} does not exist, continue searching])

        # bdb_libdir_candidate does not exist, continue searching
        continue
    fi

    ### bdb_libdir_candidate (and therefore bdb_path_candidate) is an existing directory (or "system")
    dnl AC_MSG_NOTICE([DBG: bdb_libdir_candidate=${bdb_libdir_candidate} exists])

    bdb_includedir_candidate=""
    # set bdb_includedir_candidate if needed
    if test "${bdb_includedir_needed:-no}" = "yes"; then # i.e source distro
      if test "${bdb_path_candidate}" != "system"; then
        bdb_includedir_candidate=`echo "${include_vers_template}" | sed -n -e "s@BDB_PATH@${bdb_path_candidate}@p"`
        # bdb_includedir_candidate is now something like /opt/local/include/db44

        AC_MSG_CHECKING([whether db.h exists in ${bdb_includedir_candidate}]) # DBG
        if test -f "${bdb_includedir_candidate}/db.h"; then
           AC_MSG_RESULT([yes]) # DBG
           :
        else # ! bdb_includedir_candidate
           AC_MSG_RESULT([no]) # DBG
           bdb_includedir_candidate=""
        fi
      else # bdb_path_candidate = system
        dnl AC_MSG_NOTICE([DBG: trying to use db from system default])
        AC_MSG_CHECKING([whether system db.h is compatible with ${BDB_VERSION_REQUIRED}])

        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
          #include <db.h>
          #if DB_VERSION_MAJOR == $BDB_MAJOR_REQUIRED && DB_VERSION_MINOR == $BDB_MINOR_REQUIRED && DB_VERSION_PATCH >= $BDB_PATCH_REQUIRED
          #else
          #error "db.h version is not compatible with ${BDB_MAJOR_REQUIRED}.${BDB_MINOR_REQUIRED}"
          #endif
        ]])],
        [
         bdb_includedir_candidate=system
         AC_MSG_RESULT([yes])
         BDB_VERSION="${BDB_MAJOR_REQUIRED}.${BDB_MINOR_REQUIRED}.?"
        ],
        [
         bdb_includedir_candidate=system
         AC_MSG_RESULT([no])
        ]
         )
      fi # bdb_path_candidate = system
    fi # bdb_includedir_needed

dnl     if test "${bdb_path_candidate}" = "system"; then
dnl       AC_MSG_NOTICE([DBG: Trying to use system default -L paths])
dnl       bdb_libdir_candidate='' # try system default -L path
dnl     fi
    #### We have candidate BDB directories
    # Now test that everything works as expected with
    #   bdb_libdir_candidate (may be "system" if system defaults should be used
    #   bdb_includedir_candidate (if needed) may be "system" if system defaults should be used

    dnl AC_MSG_NOTICE([DBG: Trying to use bdb_includedir_candidate=${bdb_includedir_candidate}, bdb_libdir_candidate=${bdb_libdir_candidate}])

    bdb_candidate_broken=no

    dnl bdb_includedir_candidate may be "system", empty or a real path here
    if test "${bdb_includedir_needed:-no}" = "yes"; then # i.e source distro
      AC_MSG_CHECKING([whether BDB include dir was found using BDB path ${bdb_path_candidate}]) # DBG
      if test -n "${bdb_includedir_candidate}"; then
         AC_MSG_RESULT([yes (${bdb_includedir_candidate})]) # DBG
         :
      else
         AC_MSG_RESULT([no]) # DBG
         bdb_candidate_broken=yes
      fi
    fi # bdb_includedir_needed


    if test "${bdb_candidate_broken}" = "no"; then

      bdb_lib_base_name="${SP_BDB_LIB_BASE_NAME_UNIX}"

      PUSH_LDFLAGS="$LDFLAGS"
      if test "${bdb_libdir_candidate}" = "system"; then
        LDFLAGS=''
      else
        LDFLAGS="${bdb_libdir_candidate:+-L${bdb_libdir_candidate}}"
      fi
      bdb_linked_ok=no

      dnl Remove cached AC CHECK LIB value between iterations (name gleaned from generated configure
      bdb_cache_var=`echo "ac_cv_lib_${bdb_lib_base_name}''_db_env_create" | $as_tr_sh`
      eval "unset ${bdb_cache_var}"

      AC_CHECK_LIB(${bdb_lib_base_name},db_env_create,[bdb_linked_ok=yes],[bdb_linked_ok=no], ${bdb_extra_libs})
      LDFLAGS="$PUSH_LDFLAGS"
dnl ============================================================
dnl ============================================================


      if test "${bdb_linked_ok:-no}" = "no"; then
         bdb_candidate_broken=yes
      fi

    fi # !bdb_candidate_broken

    
    AC_MSG_CHECKING([whether BDB path ${bdb_path_candidate} can be used])
    if test "${bdb_candidate_broken}" = "no"; then
      AC_MSG_RESULT([yes])
      if test "${bdb_includedir_candidate}" = "system"; then
        BDBINC=''
      else # bdb_includedir_candidate != system
        BDBINC="${bdb_includedir_candidate:+-I${bdb_includedir_candidate}}" # empty if no bdb_includedir_candidate
      fi
      if test "${bdb_libdir_candidate}" = "system"; then
        BDBLIB="-l${bdb_lib_base_name}"
      else
        BDBLIB="${bdb_libdir_candidate:+-L${bdb_libdir_candidate} }-l${bdb_lib_base_name}"
      fi
      BDB_PATH="${bdb_path_candidate}"
      BDB_MODULE="bdb.po"
      bdb_configured=yes

    else # bdb_candidate_broken
      AC_MSG_RESULT([no])
    fi # bdb_candidate_broken

  done # for vers
  done # for bdb_path
done # for templates

AC_MSG_CHECKING([whether BDB was successfully configured]) # DBG
if test "${bdb_configured:-no}" = "yes"; then
  AC_MSG_RESULT([yes]) # DBG
  :
else # !bdb_configured
  AC_MSG_RESULT([no]) # DBG
fi # !bdb_configured


fi # "${bdb_use_new_detection:-no}" = "yes" (only used on Posix nowadays)

fi # bdb_wanted


if test "${bdb_wanted}" = "yes"; then

if test "${bdb_use_new_detection:-no}" = "no"; then # old bdb detection (WINDOWS)

dnl [PM] 4.0 bdb_path is the old name of bdb_path_arg
bdb_path="${bdb_path_arg}"

dnl [PM] 3.9.1+
if test -n "$LIBDB_PATH"; then
   AC_MSG_RESULT([using libdb path ($LIBDB_PATH)])

   AC_MSG_CHECKING([BDB lib location])
   dnl sed removes "/libdb.so" suffix.
   [ bdb_path=`echo "$LIBDB_PATH" | sed -n -e 's@^\(.*\)/[^/]*$@\1@p'` ]
   case "$bdb_path" in
     */lib)
       dnl [PM] 4.0 this will not work with DarwinPorts (that uses, e.g. /opt/local/lib/db44)
       dnl [PM] 3.9.1+ it must end in lib since "lib" is what will be added to $bdb_path
       bdb_path=`echo "$bdb_path" | sed -n -e 's@^\(.*\)/lib$@\1@p'`
       AC_MSG_RESULT([$bdb_path])
       ;;
     *)
       AC_MSG_RESULT([])
       AC_MSG_WARN([Berkeley DB library ($LIBDB_PATH) must be located in a directory called lib])
       bdb_path=''
       ;;
   esac

   AC_MSG_CHECKING([BDB using BDB lib info ($bdb_path)])
fi

dnl Note: "${bdb_use_new_detection:-no}" = "no" (only used on Windows nowadays)

# [PM] 3.11.3 set bdb_ok=yes and  bdb_path='' when bdb is a system lib
bdb_ok=no
if test "${WIN32:-no}" = "no"; then
    dnl [PM] 3.9.2b2 Do not use libdb (-ldb) since that may be a link to some other version than 4.0.14.
    dnl              In particular that happened on AIX 5L 5.1 (Louis) where /usr/lib/libdb.a is a link to libdb-3.3.a
    dnl
    dnl libdb-4.0 in bdb 4.0.14, libdb-3.3 in ??
    dnl
    dnl [PD] 3.10 Use the required version to construct the base name
    dnl bdb_lib_base_name=db-4.0
    dnl bdb_lib_base_name=db-$BDB_MAJOR_REQUIRED.$BDB_MINOR_REQUIRED
    bdb_lib_base_name="${SP_BDB_LIB_BASE_NAME_UNIX}"
dnl UNIX
    dnl [PM] 3.11.3 We would like to the following but has_libpthread is src-only
    dnl             Instead we set bdb_extra_libs for linux and AIX above
    dnl if test "x$has_libpthread" = "xyes"; then
    dnl   : ${bdb_extra_libs="-lpthread"}
    dnl fi
    : ${bdb_extra_libs=""}

dnl Note: "${bdb_use_new_detection:-no}" = "no" (only used on Windows nowadays)

dnl UNIX
    if test "${sp_isbindistr}" = "yes"; then
      dnl [PM] 3.11.3 Only done in binary distributions. Source release must have explicit bdb_path
      dnl [PM] 3.11.3 First try default library locations
      if test -z "$bdb_path"; then
          AC_MSG_RESULT([])
          AC_CHECK_LIB(${bdb_lib_base_name},db_env_create,[bdb_ok=yes],[bdb_ok=no], ${bdb_extra_libs})
          AC_MSG_CHECKING([whether BDB is a system library])
          AC_MSG_RESULT([${bdb_ok}])
          if test "$bdb_ok" != yes; then
            AC_MSG_CHECKING([whether BDB is in default location])
          fi

dnl UNIX
          dnl [PM] 3.11.3 Note that bdb_ok = yes here will still have bdb_path empty
      fi
    fi
dnl UNIX
    if test "${bdb_ok:-no}" != yes; then
      if test -z "$bdb_path"; then
          dnl [PM] 3.9.1 should match Berkeley DBs configure.ac (currently it does AC_PREFIX_DEFAULT(/usr/local/BerkeleyDB.@DB_VERSION_MAJOR@.@DB_VERSION_MINOR@) )
          dnl [PD] 3.10 Use reqired version
          dnl path=/usr/local/BerkeleyDB.4.0
          path=/usr/local/BerkeleyDB.$BDB_MAJOR_REQUIRED.$BDB_MINOR_REQUIRED
          if test -f $path/lib/lib${bdb_lib_base_name}.$SHSFX || test -f $path/lib/lib${bdb_lib_base_name}.a; then
              bdb_path="$path"
          fi
      fi
    fi # !bdb_ok

    dnl [PM] 3.11.3 anything that sets bdb_path must go above
dnl UNIX
    dnl [PM] 3.11.3 if bdb_path is empty then either we failed or bdb_ok=yes and we already did AC MSG RESULT for bdb_path
    if test -n "$bdb_path"; then
	AC_MSG_RESULT([$bdb_path])
    fi
dnl Note: "${bdb_use_new_detection:-no}" = "no" (only used on Windows nowadays)

dnl UNIX
    if test "$bdb_ok" = yes || test -n "$bdb_path"; then # [PM] 4.0 Huh?
      dnl [PM] 3.11.3 This ensures it is done also for the case bdb_ok=yes, bdb_path=''
      bdblibdir="${bdb_path:+${bdb_path}/lib}"
    fi
    if test -n "${bdblibdir}"; then
      AC_MSG_CHECKING([for Berkeley DB libraries])
      BDBLIB="${bdblibdir:+-L${bdblibdir}} -l${bdb_lib_base_name}"
      AC_MSG_RESULT([$BDBLIB])
    fi

dnl Note: "${bdb_use_new_detection:-no}" = "no" (only used on Windows nowadays)
dnl UNIX
    if test "${bdb_ok:-no}" != yes; then
      if test -n "$bdb_path"; then
          PUSH_LDFLAGS="$LDFLAGS"
          LDFLAGS="-L${bdblibdir}"

          AC_CHECK_LIB(${bdb_lib_base_name},db_env_create,[bdb_ok=yes],[bdb_ok=no], ${bdb_extra_libs})

          LDFLAGS="$PUSH_LDFLAGS"

      else # !bdb_path
          AC_MSG_RESULT([not found])
      fi # !bdb_path
    fi
dnl UNIX


dnl Note: "${bdb_use_new_detection:-no}" = "no" (only used on Windows nowadays)
    BDBINC="";

    dnl [PM] 3.11.3 Only look for headers when building from source
    if test "${sp_isbindistr}" = "no"; then
      if test "$bdb_ok" = yes; then
        if test -n "$bdb_path"; then
            AC_MSG_CHECKING([for Berkeley DB headers])
dnl UNIX
            dnl [PM] 3.9.1 MacOS X Fink has both the BDB 3 and the BDB
            dnl includes in include/db3/ and include/db4 respectively.
            dnl [PM] 4.0 DarwinPorts.org has 4.4.x includes in /opt/local/lib/db44/
            for dir in $bdb_path/include \
                       $bdb_path/include/db${BDB_MAJOR_REQUIRED}${BDB_MINOR_REQUIRED} \
                       $bdb_path/include/db${BDB_MAJOR_REQUIRED} ; do
               if test -f "$dir/db.h"; then
                  BDBINC="-I$dir"
                  break;
               fi
            done
            if test -z "$BDBINC"; then
               AC_MSG_RESULT([no])
               dnl [PM] 3.11.3 was WARN but now only in source build so better barf fatally
               AC_MSG_ERROR([could not find db.h])
            else
               AC_MSG_RESULT([$BDBINC])
            fi
        fi
      fi # bdb_ok
    fi # !sp_isbindistr
dnl Note: "${bdb_use_new_detection:-no}" = "no" (only used on Windows nowadays)

dnl UNIX
    if test "$bdb_ok" = yes; then
        BDB_MODULE=bdb.po
    fi
fi # !WIN32

dnl Note: "${bdb_use_new_detection:-no}" = "no" (only used on Windows nowadays)

dnl Win32 is src only
dnl ============================================================
dnl ============================================================

dnl [PM] 3.11.3 Only look for headers when building from source
if test "${sp_isbindistr:-no}" = "no"; then
# Test Berkeley DB version
if test -n "$BDB_MODULE"; then
    AC_MSG_CHECKING([Berkeley DB header version])
    cat > bdb_tmp.c <<EOF
#include <stdio.h>  /* [PM] 3.8.6 printf */
#include <db.h>
int main(int argc, char **argv) {
    (void)argc; (void)argv;
    printf("%d.%d.%d",DB_VERSION_MAJOR,DB_VERSION_MINOR,DB_VERSION_PATCH);
/* [PD] 3.9 From BDB version 3 there is no need check for exact patch
   version, but we haven't used a version prior to 3.2.9, so start there. */
/* [PD] 3.9.2 Compare found version to given version possibly given by option */
#if DB_VERSION_MAJOR == $BDB_MAJOR_REQUIRED && DB_VERSION_MINOR == $BDB_MINOR_REQUIRED && DB_VERSION_PATCH >= $BDB_PATCH_REQUIRED
    return 0;
#else
    return 1;
#endif
}
EOF
dnl Note: "${bdb_use_new_detection:-no}" = "no" (only used on Windows nowadays)
    BDB_VERSION=''
    # (x)>&5 redirects compiler messages to config.log
    if ${CC-cc} $CFLAGS $BDBINC bdb_tmp.c ${OUTPUT_OPT}./bdb_tmp.exe 1>&5 2>&5; then
      if BDB_VERSION=`./bdb_tmp.exe` ; then
	AC_MSG_RESULT([$BDB_VERSION])
      else
	AC_MSG_RESULT([no (need ${BDB_MAJOR_REQUIRED}.${BDB_MINOR_REQUIRED}.${BDB_PATCH_REQUIRED} or later in the ${BDB_MAJOR_REQUIRED}.${BDB_MINOR_REQUIRED}.x series)])
        BDB_VERSION=''
      fi
    else
      AC_MSG_RESULT([compiling test program failed])
      BDB_VERSION=''
    fi

    if test -z "${BDB_VERSION}"; then
	bdb_path=""
        BDB_MODULE=""
    fi
    rm -f bdb_tmp*
fi
fi # ! sp_isbindistr
dnl Note: "${bdb_use_new_detection:-no}" = "no" (only used on Windows nowadays)

if test -z "$BDB_MODULE" ; then
    BDBLIB=""
    BDBINC=""
    BDB_PATH=""
else
    BDB_PATH="$bdb_path"
fi
dnl Note: "${bdb_use_new_detection:-no}" = "no" (only used on Windows nowadays)

fi # "${bdb_use_new_detection:-no}" = "no" (only used on Windows nowadays)

fi # bdb_wanted

if test "${bdb_wanted:-yes}" = "no"; then
    BDB_MODULE=""
    BDBLIB=""
    BDBINC=""
    BDB_PATH=""
fi # !bdb_wanted



dnl ============================================================
dnl ============================================================


AC_SUBST(BDBINC)
AC_SUBST(BDBLIB)
AC_SUBST(BDB_MODULE)
AC_SUBST(BDB_PATH)

dnl [PD] 3.9.1 For SICStusInstaller
INSTALLER_BDB_VERSION=$BDB_VERSION
AC_SUBST(INSTALLER_BDB_VERSION)

dnl [PD] 3.11.1 For InstallSICStus
if test "x$BDB_MODULE" = "x"; then
   INSTALLER_HAS_BDB=no
else
   INSTALLER_HAS_BDB=yes
fi
AC_SUBST(INSTALLER_HAS_BDB)


dnl ################################################################
dnl #
dnl # ODBC
dnl #
dnl ################################################################

# strnlen (in UNIX but not ISO C) used by library/odbc.c 
AC_CHECK_FUNCS([strnlen])

dnl ################################################################

AC_MSG_CHECKING([whether to use ODBC])
AC_ARG_WITH(odbc,        [  --with-odbc=DIR          Location of ODBC installation, e.g., /usr/local/unixODBC],
    [odbc_path_arg="$withval"],
    [odbc_path_arg=""])

dnl [PM] Used by GUI installer
AC_ARG_WITH(libodbc,
[  --with-libodbc            Specify full path of libodbc.so. 
                           Used by installer. Overrides --with-odbc but not --without-odbc],
	    [LIBODBC_PATH=$withval])

if test "${enable_foreign_resources:-yes}" != "no"; then
  odbc_wanted=yes
else
  odbc_wanted=no
fi
odbc_explicit=no

case "${LIBODBC_PATH:-no}" in
  yes)
    AC_MSG_ERROR([--with-libodbc must have an argument])
  ;;
  no) # --without-libodbc
    LIBODBC_PATH='' # ignore --without-libodbcd and --with-libodbc=""
  ;;
  *) # --with-libodbc=PATH
    odbc_explicit=yes 
  ;;
esac

case "${odbc_path_arg}" in
  "") # no --with(out)-odbc argument at all
    :
  ;;
  yes) # --with-odbc, --with-odbc=yes
    odbc_explicit=yes
    odbc_path_arg=''
  ;;
  no) # --without-odbc overrides --with-libodbc
    LIBODBC_PATH=''
    odbc_explicit=no
    odbc_wanted=no
  ;;
  *) # --with-odbc=PATH
    odbc_path_arg=${odbc_path_arg%/} # strip trailing /
    odbc_explicit=yes
    AC_MSG_ERROR([Explicit --with-odbc path is currently not supported])
  ;;
esac

## [PM] 4.1.3 Allow to configure without ODBC (--without-odbc)
if test "${odbc_wanted}" = "no"; then
   AC_MSG_RESULT([no])
   odbc_path_arg=""
elif test "${odbc_explicit:-no}" = "yes"; then
   AC_MSG_RESULT([yes])
else
   AC_MSG_RESULT([yes, if possible])
fi


dnl [PD] 4.1 We should perhaps use AC_SEARCH_LIBS instead?

if test "${odbc_wanted}" = "yes"; then
AC_MSG_CHECKING([for ODBC support])
case $PLATFORM in
  *darwin-*)
    AC_CHECK_LIB(iodbc, SQLAllocHandle, [has_odbc=yes], [has_odbc=no])
    ;;
  *win32*)
    AC_MSG_CHECKING([for ODBC support])
    # Windows always has ODBC
    has_odbc=yes
    AC_MSG_RESULT([yes])
    ;;    
  *)
    AC_CHECK_LIB(odbc, SQLAllocHandle, [has_odbc=yes], [has_odbc=no])
    ;;
esac
fi # odbc_wanted

dnl [PD] 4.1 ODBC_PATH is introduced here for future expansion when we implement
dnl          the '--with-odbc=DIR' option

if test "${has_odbc:-no}" = "yes"; then
   case $PLATFORM in
  *darwin-*)
      ODBCLIB=-liodbc
      ODBC_MODULE=odbc.po
      ODBC_PATH=""
      AC_MSG_CHECKING([For iODBC header folder])
      # [PM] 4.3 There is no good way to handle iODBC on OS X. It is a mess and, as of OS X 10.9 Mavericks, no headers are included.
      # Look for separately installed iODBC framework headers (but we never link with the iODBC framework, we always use the plain -liodbc).
      for incdir in /Library/Frameworks/iODBC.framework/Headers; do
        if test -f "$incdir/iodbcunix.h" ; then
	   # [PM] 4.3 Use conditional assignment so it can be overridden from environment, as a fallback.
           : ${ODBCINC="-I$incdir"}
	   break
        fi
      done
      if test -n "${ODBCINC}"; then
        AC_MSG_RESULT([none])
      else
        AC_MSG_RESULT([${ODBCINC}])
      fi

      ;;
  *win32*)
      ODBC_MODULE=odbc.po
      ODBC_PATH=""
      ODBCINC=""
      ;;
  *)
      ODBCLIB=-lodbc
      ODBC_MODULE=odbc.po
      ODBC_PATH=""
      ODBCINC=""
      ;;
  esac
else
    has_odbc='no'
    ODBCLIB=""
    ODBC_MODULE=""
    ODBC_PATH=""
    ODBCINC=""
fi

AC_SUBST([ODBCLIB])
AC_SUBST([ODBCINC])
AC_SUBST([ODBC_MODULE])
AC_SUBST([ODBC_PATH])

dnl [PM] 4.1.3 For InstallSICStus
if test "${ODBC_MODULE:-unset}" = "unset"; then
   INSTALLER_HAS_ODBC=no
else
   INSTALLER_HAS_ODBC=yes
fi
AC_SUBST([INSTALLER_HAS_ODBC])

dnl ============================================================
dnl ============================================================



dnl ============================================================
dnl ============================================================


dnl ############
dnl #
dnl # Checking Java flags for Jasper
dnl #
dnl ############


dnl [PM] 3.11.2 Updated Java configuration.
dnl We used to have Java if and only if we supported Jasper and had
dnl everyone look at JASPER_MODULE to determine if Java and Jasper
dnl were supported. However, now that we have Prologbeans we want to
dnl distinguish two things:
dnl . We have Java (and javac) so we can compile and run Java code
dnl . We can use JNI to link Java with SICStus and vice versa, this is
dnl   needed for library(jasper) but not for library(prologbeans).
dnl Now have:
dnl --with-java[=path] -- this is the default and can specify a path
dnl                       to a Java installation
dnl                       Sets opt_enable_java={yes|no} (read-only)
dnl --enable-java-jni  -- this is the default unless --without-java
dnl                       was specified. This means that Java JNI
dnl                       should be used to link SICStus with Java. It
dnl                       is a requirement for Jasper.
dnl                       Sets opt_enable_java_jni={yes|no} (read-only)
dnl Variables:
dnl   Used in configure:
dnl     ENABLE_JAVA_JNI={yes|no} -- yes iff JNI could be configured
dnl     ENABLE_JAVA={yes|no} -- yes iff Java could be configured
dnl
dnl   Output from configure
dnl     JASPER_MODULE={"jasper.po"|""} -- empty if Jasper should not be used
dnl     HAVE_JAVA={yes|no} -- yes if we have a working Java
dnl     JAVAEXEC, JAVAC, ... -- full path to executable
dnl     ...
dnl

AC_MSG_CHECKING([for Java support])

AC_ARG_WITH(java,       [  --with-java=DIR        Location of Java-installation, e.g. /usr/local/jdk1.2.2],
	[java_path="$withval"],
	[
	dnl [PM] 4.2.1+ FIXME: Why does this disable java just because we have no foreign resources? What about, e.g., PrologBeans.
        if test "${enable_foreign_resources:-yes}" = no; then
          java_path=no
        fi
        ])

java_explicit=no

if test ".$java_path" = ".no"; then # --without-java
   opt_enable_java=no

   AC_MSG_RESULT([disabled])
   java_explicit=no
else
   opt_enable_java=yes

   AC_MSG_RESULT([enabled])
   if test -z "$java_path"; then
     java_explicit=no
   else
     java_explicit=yes

     if test ".$java_path" = ".yes"; then # --with-java without a path
       java_path=""
     fi
   fi
fi

dnl [PM] 3.11.2 on some platforms (HPPA HPUX) we cannot link SICStus and Java together with JNI.
AC_MSG_CHECKING([whether SICStus should use Java JNI])
opt_enable_java_jni_default="$opt_enable_java"

dnl [PM] 4.3 This was forcibly true since -r 1.209 ". jasper is
dnl enabled by default in configure. This may break some platforms
dnl temporarily.". I do not see why this was done but it breaks
dnl platforms where we can not compile with Java.
dnl
dnl opt_enable_java_jni_default=yes

AC_ARG_ENABLE(java-jni,       [  --disable-java-jni        Disable linking with Java, e.g., library(jasper)],
	[opt_enable_java_jni="$enableval"],
	[opt_enable_java_jni="$opt_enable_java_jni_default"])
if test "${opt_enable_java_jni}" = no; then
  PERSISTENT_CONFIGURE_OPTIONS="${PERSISTENT_CONFIGURE_OPTIONS} --disable-java-jni"
else
  dnl normalize
  opt_enable_java_jni=yes
fi
AC_MSG_RESULT([$opt_enable_java_jni])


dnl [PM] 3.9.1 save away original arg before doing ../-tricks on it
java_path_arg="$java_path"

if test "$opt_enable_java" = "yes"; then
dnl [PD] 3.9.1
dnl If $java_path is not a directory, then it should be the javac compiler, so
dnl the Java directory is ".."
dnl [PM] changed from ! -d  to -f so that a non-existing java_path is not treated like a non-directory
  if    test -n "$java_path" && test -f "$java_path"; then
    dnl Strip the file and the last directory in the path, but first remove any
    dnl trailing "/".
    dnl We don't have to worry about $java_path being "/" since the -f test above
    dnl will catch that.
    java_path=`echo $java_path | sed -e 's%\(.*\)/$%\1%' | sed -e 's%^\(.*\)/.*/.*$%\1%'`
  fi
fi dnl opt_enable_java

dnl ============================================================
dnl ============================================================

AC_ARG_ENABLE(jdk-rpath,        [  --enable-jdk-rpath          Embed rpath to JDK (default)],
    [enable_jdk_rpath="$enableval"],
     [
       case $PLATFORM in 
           *win32*)
               # no rpath on Win32
               enable_jdk_rpath=no
               ;;
           *darwin-*)
               # no rpath on MacOS X
               enable_jdk_rpath=no
               ;;
           *)
               enable_jdk_rpath=yes
               ;;
       esac
     ])


# [PM] 3.9.1 We should set this explicitly for all platforms. Booby trap it.
default_jdk_rpath_set=yes;
# [PM] 3.8.6
case $PLATFORM in 
    *solaris*)
        default_jdk_rpath_in_ds=no
        default_jdk_rpath_in_jasper=yes
        ;;
    *linux*)
        # This case should really be 'uses glibc ld.so'
        : ${default_jdk_rpath_in_ds=yes}
        dnl [PM] 4.1.3 SPRM 11938 This was needed on OpenSUSE 11.2 (Glibc 2.10)
        dnl It probably does not hurt to also have it in ds, in case that is still needed
        : ${default_jdk_rpath_in_jasper=yes}
        ;;
    *aix*)
        dnl [PM] 3.9.1 FIXME: what about all the environment variables needed by AIX Java
        dnl           Currently we bail out and just document them in relnotes.tex
        dnl           with JDK 1.3.1 the test-Suite passes even with no environment vars

        dnl [PM] 3.9.1 JDK 1.3.1 Rationale:
        dnl            1. rpath in jasper and not in ds makes jasper load 
        dnl               without problem but jasper_initialize barfs with
        dnl               "Unable to dlopen libjava.a: No such file or directory"
        dnl               My guess is that this is because libjvm
        dnl               dlopens libjava.a (the dlopen will use the
        dnl               exe runpath, not the jasper.so runpath that
        dnl               was used to locate libjvm.a.
        dnl               Setting LIBPATH worked around the problem
        dnl            2. rpath in ds but not in jasper is now default.
        dnl               It seems to work (with JDK 1.3.1)
        default_jdk_rpath_in_ds=yes
        default_jdk_rpath_in_jasper=no
        ;;
    ipf*-hpux-*)
        dnl [PM] 3.10.2 HP ELF loaded uses rpath of parent, e.g., jasper.so, _only_ 
        default_jdk_rpath_in_ds=no
        default_jdk_rpath_in_jasper=yes
        ;;
    hppa-hpux-*)
        dnl [PM] 3.9.1 see if this works
        default_jdk_rpath_in_ds=yes
        default_jdk_rpath_in_jasper=no
        ;;
    *irix*)
        dnl [PM] 3.9.1 see if this works
        default_jdk_rpath_in_ds=no
        default_jdk_rpath_in_jasper=yes
        ;;
    *osf1*)
        dnl [PM] 3.9.1 see if this works
        default_jdk_rpath_in_ds=yes
        default_jdk_rpath_in_jasper=no
        ;;
    *)
        # [PM] do not know what is a reasonable default
        default_jdk_rpath_in_ds=yes
        default_jdk_rpath_in_jasper=no
        default_jdk_rpath_set=no;
        ;;
esac

# [PM] 3.8.6
if test $enable_jdk_rpath != yes; then
   # Do not embed JDK rpath anywhere (not default)
   jdk_rpath_in_ds=no
   jdk_rpath_in_jasper=no
   default_jdk_rpath_set=yes
else
   jdk_rpath_in_ds=$default_jdk_rpath_in_ds
   jdk_rpath_in_jasper=$default_jdk_rpath_in_jasper
fi


dnl [PM] 3.11.2 Even newer way to detect java

dnl [PM] 3.11.2 assume failure.
ENABLE_JAVA=no

java_done=no
dnl The output of this loop is, if ENABLE_JAVA=yes
dnl . java_path nonempty and valid
dnl . JAVAEXEC et al
dnl . ...?
dnl for loop makes it possible to use break for non-local exit on failure
for x in y; do

if test $opt_enable_java = no; then break; fi

dnl [PM] 3.8.6 New cleaner way to detect Java settings. The problem with
dnl the old way was that it sometimes found green_threads things in JDK
dnl 1.2.2 and server or classic things in JDK 1.3.X.
dnl Now give up on ultra heuristics and use knowledge of Sun JDK.
dnl We target only Sun JDK 1.2.2 and Sun JDK 1.3.X
dnl We target only Solaris, Linux and Win32.
dnl The documentation below is Unix-centric, (as usual) things are
dnl easier on Win32
dnl
dnl JDK directory structure:
dnl <JDK> (the --with-java=<JDK> argument, $java_path)
dnl ./bin/ (development tools (and java launcher, unfortunately)
dnl    |
dnl    -->java
dnl    -->javac
dnl    -->javah
dnl    ...
dnl ./include/
dnl    |
dnl    -->jni.h
dnl    --><OS>/  (linux, solaris, win32)
dnl        |
dnl        ->jni_md.h
dnl ./jre (Java run-time environment, no development tools)
dnl    |
dnl    -->bin/
dnl        |
dnl        ->java (again)
dnl        ...
dnl    -->lib/
dnl        |
dnl        --><cpu>/
dnl             |
dnl             -->client/ (JDK 1.3) (a.k.a hotspot, the default JVM in 1.3)
dnl             -->server/ (JDK 1.3)
dnl             -->classic/ (JDK 1.2.2 & JDK 1.3 [deprecated])
dnl                   ||
dnl                    ==>libjvm.so
dnl             -->native_threads/
dnl             -->green_threads/ (We (and JDK 1.3) do not support green threads)
dnl                   ||
dnl                    ==>libhpi.so
dnl [PM] 3.11.2 
dnl   For Win32 jre/lib/ looks different but is not used by us
dnl
dnl
dnl This makes finding the Java executables easy.
dnl The hard part is to determine:
dnl . Where to look for these libraries, at link time and run-time
dnl   Fortunately the UNIX java launcher has a (undocumented) hook
dnl   ($DEBUG_PROG) that makes it possible to detect how the Java
dnl   launcher sets up LD_LIBRARY_PATH before launching java. We use the
dnl   same directories to tell the linker where to find libraries at
dnl   link-time and also where to find them at run-time (-L and
dnl   -R/-rpath arguments).
dnl . What libraries to link with (libjvm.so/jvm.dll). In 3.8.5 and
dnl   earlier we tried to find other libs as well (e.g., libhpi.so). It
dnl   turns out this was a mistake. We only need to link with jvm, the
dnl   problem is to set-up -L/-R(-rpath) correctly.
dnl . Where to find the <OS>/jni_md.h platform specific header
dnl
dnl TODO:
dnl To make things a little more interesting we should attempt to
dnl support JRE-only installations since this configure is used for
dnl binary installations as well.
dnl

case $PLATFORM in
   *darwin-9.*|*darwin-10.*|*darwin-11.*)
       dnl JDK installation On MacOS X is non-standard
       default_jdk_path=/System/Library/Frameworks/JavaVM.framework
       macosx_jdk=yes
       ;;
   *darwin-*) # >= Darwin 12, i.e. >= 10.8 
       dnl JDK installation On MacOS X is non-standard
       default_jdk_path=$(/usr/libexec/java_home)
       if test -d "${default_jdk_path}/include" && test -d "${default_jdk_path}/bin"; then
          # [PM] 4.3 Special trick for OS X with (Oracle) Java 7 or later. Do not use heuristics, trust /usr/libexec/java_home if it looks sane.
          #          Note that java_home --task BundledApp (or --task
          #          JNI) still replies with Apple legacy Java 6, in
          #          both Orace Java 7 and Oracle Java 8.
          java_path="${default_jdk_path}"
       fi
       macosx_jdk=no
       ;;
   *)
       macosx_jdk=no
       ;;
esac

if test $macosx_jdk = yes; then
   dnl java_path should be like
   dnl /System/Library/Frameworks/JavaVM.framework (default)
   dnl /System/Library/Frameworks/JavaVM.framework/Versions/1.3.1 (does this work?)

   dnl Ignore if not a directory
   if test ! -d "$java_path"; then
      java_path=""
   fi

   if test -z "$java_path"; then
      java_path="$default_jdk_path"
   fi

   # override the JDK standard layout
   java_exec_path="$java_path/Commands"
   jni_h_dir="$java_path/Headers"
   # [PM] 3.9.1 FIXME if nonstandard java_path then perhaps -F$java_path should be used!?
   #            Ignore this issue until JDK 1.4 for MacOS X is releases
   java_inc_flags=" -I$jni_h_dir "
   java_ld_L_flags=" -framework JavaVM "
   JAVALIB="$java_ld_L_flags $JAVA_LDFLAGS"
fi dnl macosx_jdk

dnl if no explicit --with-java, use heuristics
dnl JDK in PATH
if test -z "$java_path"; then
    # [PM] 3.9.1 We will not get here for MacOS X

    # On NT java.exe will be found in WINNT\system32, instead look
    # for Java development system. Also no risk of finding the
    # jre/bin directory instead of <JDK>/bin
    #
    AC_MSG_CHECKING([for Java in PATH])
    AC_MSG_RESULT([])
    AC_PATH_PROG([java_in_path],[javac$EXEEXT])

    if test -f "$java_in_path"; then
        javaexecdir="`dirname \"$java_in_path\"`"
        jdkdir="$javaexecdir/.."
        realdir="`(cd $jdkdir && pwd)`"
        # paranoid, fail if not there
        if test -n "$realdir"; then
          java_path="$realdir"
        fi
    fi
fi
dnl JDK default location
if test -z "$java_path"; then
  AC_MSG_CHECKING([for default path to Java])
  java_path="${default_jdk_path}"
  if test -n "${java_path}" && test -d "${java_path}"; then
    AC_MSG_RESULT([${java_path}])
  else
    java_path=""
    AC_MSG_RESULT([none])
  fi
fi

dnl java_path set here
AC_MSG_CHECKING([for path to Java])
if test -n "$java_path"; then
   AC_MSG_RESULT([$java_path])
else
   AC_MSG_RESULT([not found, giving up])
   break
fi

dnl java_path is set-up here

AC_MSG_CHECKING([for java executables])
AC_MSG_RESULT()

dnl [PM] 3.9.1 MacOS X overrides java_exec_path
: ${java_exec_path=$java_path/bin}

dnl overkill, we really expect each PROG to be java_exec_path/PROG.
dnl [PM] 3.9.1b4 autoconf 2.53 has a bug where : in last arg to
dnl AC_PATH_PROG does not work. (This is fixed in forthcoming
dnl autoconf 2.54).

java_search_path="$java_exec_path:$PATH"
SP_CHECK_ABSOLUTE([JAVAEXEC])
AC_PATH_PROG([JAVAEXEC],[java$EXEEXT],,[$java_search_path])
SP_CHECK_ABSOLUTE([JAVAC])
AC_PATH_PROG([JAVAC],[javac$EXEEXT],,[$java_search_path])
SP_CHECK_ABSOLUTE([JAVAH])
AC_PATH_PROG([JAVAH],[javah$EXEEXT],,[$java_search_path])
SP_CHECK_ABSOLUTE([JAVADOC])
AC_PATH_PROG([JAVADOC],[javadoc$EXEEXT],[false],[$java_search_path])
SP_CHECK_ABSOLUTE([JAR])
AC_PATH_PROG([JAR],[jar$EXEEXT],[false],[$java_search_path])

# JAVAEXEC should really be there once we get to this point
if test -z "$JAVAEXEC"; then
   AC_MSG_WARN([Did not find java launcher, giving up])
   break
fi

dnl [PM] 4.0.2+ All our source code uses Latin 1 encoding. Pass it to
dnl      JAVAC and JAVADOC so they do not use locale.  .
java_source_encoding='ISO-8859-1'

dnl ============================================================
dnl ============================================================

dnl All Java executables are set-up here

dnl [PM] 3.11.2 if we get here then Java is available
ENABLE_JAVA=yes
done dnl for x in y ENABLE_JAVA tests

AC_SUBST(ENABLE_JAVA)

if test $ENABLE_JAVA = yes; then
dnl By doing these as conditional defines we allow overriding with,
dnl e.g, "-server"
dnl Note that platforms that need special flags for java can
dnl set JAVA_EXECOPTS earlier. (Win32, Tru64, Solaris, HPUX IPF)
dnl JDK 1.4, at least on linux, does not support a -native argument.
dnl JDK 1.3.1 on Win32 supports (ignores, probably) -native
: ${JAVA_EXECOPTS=""}

dnl [PM] 3.9.1 check separately for support of -native arg. Set
dnl            JAVA_NATIVE_ARG to "" to never use -native on this platform
AC_MSG_CHECKING([whether java supports the -native argument])
: ${JAVA_NATIVE_ARG=bad_value}

if test "x$JAVA_NATIVE_ARG" = "xbad_value"; then # was not set at all
   if "$JAVAEXEC" -native -version > /dev/null 2>&1; then
      JAVA_NATIVE_ARG="-native"
   else # java -native -version failed
      JAVA_NATIVE_ARG=""
   fi
fi
if test -z "$JAVA_NATIVE_ARG"; then # was explicitly set to empty
   AC_MSG_RESULT([no])
else
   AC_MSG_RESULT([yes ($JAVA_NATIVE_ARG)])
fi
JAVA_EXECOPTS="$JAVA_NATIVE_ARG $JAVA_EXECOPTS"

AC_MSG_CHECKING([for arguments to $JAVAEXEC])
AC_MSG_RESULT([$JAVA_EXECOPTS])

if true; then
  dnl [PM] 4.3 Avoid explicit -source arg since it triggers warnings like "warning: [options] bootstrap class path not set in conjunction with -source 1.6"
  dnl Instead, assume that these days the Java we use can cope with our source.
  javac_source_arg=''
else
dnl dnl [PM] 4.3 We now require Java >= 1.6
  java_source_version='1.6'
  javac_source_arg="-source ${java_source_version}"
  AC_MSG_CHECKING([whether javac supports ${javac_source_arg} flag])
  cat > ./config_tmp.java <<EOF
  /* Dummy Java source file */
EOF
  if "$JAVAC" ${javac_source_arg} ./config_tmp.java 1> /dev/null 2>&1 ; then
    AC_MSG_RESULT([yes])
  else
    javac_source_arg=''
    AC_MSG_RESULT([no])
  fi
  rm -f ./config_tmp.java
fi

dnl [PM] 4.3 Only support 1.6 or newer.
java_target_version='1.6'
javac_target_arg="-target ${java_target_version}"
AC_MSG_CHECKING([whether javac supports ${javac_target_arg} flag])
cat > ./config_tmp.java <<EOF
/* Dummy Java target file */
EOF
if "$JAVAC" ${javac_target_arg} ./config_tmp.java 1> /dev/null 2>&1 ; then
  AC_MSG_RESULT([yes])
else
  javac_target_arg=''
  AC_MSG_RESULT([no])
fi
rm -f ./config_tmp.java

dnl [PD] 3.12.1 Make sure javac does not use it's default. We wan't to be
dnl locale-independent.
JAVACFLAGS="${JAVACFLAGS}${JAVACFLAGS:+ }-encoding ${java_source_encoding}"


AC_MSG_CHECKING([extra options to javac])
if test "${DBGFLAG:-unset}" != "no"; then
   JAVACDBGFLAGS="-g $JAVACDBGFLAGS"
fi

dnl [PM] 3.11.3 Explicitly telling javac about what kind of source we
dnl             use avoids warnings from the JDK 1.5 compiler
dnl [PD] 4.0.3beta1 include -target option
JAVACFLAGS="${javac_source_arg} ${javac_target_arg} ${JAVACFLAGS}"

if test -n "$JAVACFLAGS$JAVACDBGFLAGS"; then
    AC_MSG_RESULT([$JAVACFLAGS $JAVACDBGFLAGS])
else
    AC_MSG_RESULT([none])
fi

fi                              # ENABLE_JAVA


dnl [PM] 3.11.2 break out if JNI cannot/should not be configured
dnl The output of this loop is, if ENABLE_JAVA_JNI=yes
dnl . java_inc_flags
dnl . ...?
dnl
ENABLE_JAVA_JNI=no
for x in y; do
if test ${ENABLE_JAVA} = no; then break; fi

if test ${opt_enable_java_jni} = no; then break; fi

AC_MSG_CHECKING([for java include directory])

# [PM] 3.9.1 MacOS X overrides jni_h_dir
: ${jni_h_dir=$java_path/include}

jni_h=$jni_h_dir/jni.h
if test -f "$jni_h"; then
   AC_MSG_RESULT([$jni_h_dir])
else
   AC_MSG_RESULT([not found])
   # give up
   break
fi

dnl [PM] 3.9.1 MacOS X overrides $java_inc_flags
if test -z "$java_inc_flags"; then
   AC_MSG_CHECKING([for java OS specific include directory])

   dnl use the first (and, in JDK 1.2.2, 1.3, 1.3.1beta, the only) subdir
   dnl TODO: if more than one is found warn/do something reasonable
   dnl       (such as add to -I or choose right OS version)
   dnl [PM] 3.8.7 -print is needed after -prune on (broken) find 4.1.6 (RedHat 7.1)
   jni_md_h_dir=`find $jni_h_dir/* -follow -type d -prune -print 2>/dev/null | head -n 1`
   jni_md_h=$jni_md_h_dir/jni_md.h
   if test -f "$jni_md_h"; then
      AC_MSG_RESULT([$jni_md_h_dir])
   else
      dnl [PM] 3.11.2 FIXME: is this fatal on all platforms?
      AC_MSG_RESULT([none found])
   fi

   for dir in "$jni_h_dir" "$jni_md_h_dir"; do
      if test -n "$dir"; then
         native_dir=`$CYGPATH "$dir"`
         java_inc_flags="$java_inc_flags -I$native_dir"
      fi
   done
fi

dnl Java include directories have been set-up here

: ${java_cflags="-D_REENTRANT"}
AC_MSG_CHECKING([JDK version])
dnl Compile a small program to check the JNI version
java_tmp=java_tmp$$
dnl beware: lines start with TAB
cat > $java_tmp.c <<EOF
	#include <jni.h>
	int main(int argc, char **argv) {
	#ifdef JNI_VERSION_1_2
	    return 0;
	#else
	    return 1;
	#endif
	}
EOF
rm -f ./$java_tmp$EXEEXT
"${CC}" $java_cflags $java_inc_flags $java_tmp.c ${OUTPUT_OPT}$java_tmp$EXEEXT >/dev/null 2>&1

if test -f ./$java_tmp$EXEEXT && ./$java_tmp$EXEEXT; then
   dnl [PM] This is only for debugging
   test -n "$JAVAEXEC" \
   && [JAVA_VERSION=`$JAVAEXEC -version 2>&1 | head -1 | sed -n -e 's/java *version.*"\([^"]*\)".*/\1/p'`]

   if test -n "$JAVA_VERSION"; then
      AC_MSG_RESULT([$JAVA_VERSION])
   else
      AC_MSG_RESULT([ok, JNI_VERSION_1_2 or larger])
   fi
else
   AC_MSG_RESULT([your JDK is broken or too old (SICStus/Jasper requires 1.2 or later)])
   rm -f $java_tmp*
   dnl give up
   break
fi
rm -f $java_tmp*

dnl We have JDK 1.2 or later at this point

dnl Now figure out how to link with java.


AC_MSG_CHECKING([for JDK shared library directories])
AC_MSG_RESULT([])

jdk_link_flags_done=no


# *** Apple legacy Java SDK
if test "$macosx_jdk" = "yes"; then
   # MacOS X 10.1
   # link with -framework JavaVM

   PUSH_LDFLAGS="$LDFLAGS"
   LDFLAGS="$java_ld_L_flags"
   AC_TRY_LINK_FUNC(JNI_CreateJavaVM,[java_links=yes],[java_links=no])
   LDFLAGS="$PUSH_LDFLAGS"

   if test "$java_links" != "yes"; then
      AC_MSG_WARN([Could not link with JavaVM])
      break
   fi
   jdk_link_flags_done=yes
elif test "${darwin:-no}" = "yes";  then # OS X but not Apple legacy Java SDK
   # java.library.path property is useless on OS X, so we must figure this out manually
dnl   AC_MSG_ERROR([Need to figure out how to link with Oracle Java on OS X])
   jre_lib_dir="${java_path}/jre/lib/server"
   java_ld_L_flags="-L${jre_lib_dir}"
   JAVALIB="${java_ld_L_flags} -ljvm"

   PUSH_LDFLAGS="$LDFLAGS"
   LDFLAGS="$JAVALIB"
   AC_TRY_LINK_FUNC(JNI_CreateJavaVM,[java_links=yes],[java_links=no])
   LDFLAGS="$PUSH_LDFLAGS"
   JASPER_ENV_ARGS="DYLD_LIBRARY_PATH=${jre_lib_dir}"
   if test "$java_links" != "yes"; then
      AC_MSG_WARN([Could not link with JavaVM])
      break
   fi

   jdk_link_flags_done=yes
fi



dnl *** Win32
if test "${WIN32:-no}" = "yes"; then
   posix_javalib="$java_path/lib/jvm.lib"
   if test ! -f "${posix_javalib}"; then
     AC_MSG_ERROR([Cannot find ${posix_javalib}])
   fi
   JAVALIB="`$CYGPATH "$posix_javalib"`"
   jdk_link_flags_done=yes
fi

# [PM] 4.3 Also needed in non-src build.
GETSYSTEMPROPERTYJAR_BASENAME=GetSystemProperty.jar

dnl ============================================================
dnl ============================================================


dnl *** UNIX

# [PM] 4.3 New way to figure out linker -L<DIR> -ljvm for linking with
# Java. The old way, using the system property java.library.path, does
# not work, e.g in Oracle Java 7.

if test "$jdk_link_flags_done" = "no"; then

   # [PM] 4.3 Kludge alert (there is no documented way to ask java about
   # how to link with libjvm.so).
   #### BEGIN new Java -L detection

   GETSYSTEMPROPERTYJAR=$GETSYSTEMPROPERTYJAR_BASENAME
   if test -f "$GETSYSTEMPROPERTYJAR"; then
      :
   else # not present in CWD
      GETSYSTEMPROPERTYJAR=se/sics/sicstus/configure/$GETSYSTEMPROPERTYJAR_BASENAME
   fi

   AC_MSG_CHECKING([whether sun.boot.library.path can be obtained])
   if test -f "$GETSYSTEMPROPERTYJAR"; then
      if sun_boot_library_path=`"$JAVAEXEC" $JAVA_EXECOPTS -jar "$GETSYSTEMPROPERTYJAR" sun.boot.library.path`; then
         AC_MSG_RESULT([yes ($sun_boot_library_path)])
      else
         AC_MSG_RESULT([no])
         sun_boot_library_path=''
      fi
   else # GetSystemProperty.jar not present
      AC_MSG_RESULT([no])
      AC_MSG_WARN([$GETSYSTEMPROPERTYJAR was not found])
      sun_boot_library_path=''
   fi

   found_jvm_dso_full_path=''
   found_jvm_dso_parent_full_path=''
   jvm_dso="libjvm.$SHSFX"
   dummy="$sun_boot_library_path"
   save_ifs="$IFS"; IFS=":"
   for dir in $dummy; do 
      tmp_ifs="$IFS"; IFS="$save_ifs";
      {
        AC_MSG_NOTICE([Checking for $jvm_dso below $dir])
        for vmdir in server j9vm client; do
          jvm_dso_parent="${dir}/${vmdir}"
          jvm_dso_full_path="${jvm_dso_parent}/${jvm_dso}"
          AC_MSG_CHECKING([whether $jvm_dso_full_path exists])
          if test -f "$jvm_dso_full_path"; then
             AC_MSG_RESULT([yes])
             found_jvm_dso_full_path="$jvm_dso_full_path"
             found_jvm_dso_parent_full_path="$jvm_dso_parent"
             break
          else
             AC_MSG_RESULT([no])
          fi
        done
        if test -n "$found_jvm_dso_full_path"; then
           break;
        fi
      }
      IFS="$tmp_ifs"
   done
   IFS="$save_ifs"
   AC_MSG_CHECKING([whether the folder containing $jvm_dso could be found])
   if test -n "$found_jvm_dso_parent_full_path"; then
      AC_MSG_RESULT([yes ($found_jvm_dso_parent_full_path)])
      java_ld_library_path="$found_jvm_dso_parent_full_path"
   else
      AC_MSG_RESULT([no])
   fi


   ## Output:
   ##  java_ld_library_path -- colon separated for finding libjvm.so with
   ##                          ld -L<DIR> or LD_LIBRARY_PATH

   #### END new Java -L detection

fi # "$jdk_link_flags_done" = "no"


if test "$jdk_link_flags_done" = "no"; then

   if test -z "$java_ld_library_path"; then # [PM] 4.3 may be set above by new detection

   dnl# UNIX CASE: library/link parameters
   dnl Kludge alert

   dnl On Unix JDK 1.2, 1.3, 1.3.1 but not 1.4 java is a shell script that figures out what real
   dnl program to execute and sets up LD_LIBRARY_PATH before doing
   dnl it. Furthermore it is hookable by invoking the real program as:
   dnl   exec $DEBUG_PROG "$prog" "$@"
   dnl we hook into this by defining DEBUG_PROG to something that
   dnl picks up LD_LIBRARY_PATH


   debug_prog=./debug_prog$$.sh
   dnl - means remove preceeding tabs from all lines NOTE! do not detabbify this buffer
   : ${JAVA_LD_LIBRARY_PATH_name="$LD_LIBRARY_PATH_name"}
   [
   cat > $debug_prog <<EOF
   #!/bin/sh

   # Clean up the list of directories
   # Remove "/foo/.."
   # Replace "::" with single colon
   # Remove ":" at start of path
   # Remove ":" at end of path
   CLEAN_LD_LIBRARY_PATH=\`echo "\$$JAVA_LD_LIBRARY_PATH_name" | sed -e 's%/[^/]*/\.\.%%g' -e 's/::/:/g' -e 's/^://' -e 's/:$//'\`
   # Find all the .so files java can find through LD_LIBRARY_PATH
   # find  \`echo "\$CLEAN_LD_LIBRARY_PATH" | sed -e 'y/:/ /'\` -maxdepth 1 -name '*.so'
   echo LD_LIBRARY_PATH=="\$CLEAN_LD_LIBRARY_PATH"
EOF
   ]

   AC_MSG_CHECKING([if Java shared library locations can be obtained using DEBUG_PROG with wrapper])
   chmod a+x $debug_prog
   ld_library_path_set=`DEBUG_PROG=$debug_prog $JAVAEXEC $JAVA_EXECOPTS -version 2> /dev/null`
   rm -f $debug_prog
   dnl ld_library_path_set= should be "LD_LIBRARY_PATH=...." here
   case "$ld_library_path_set" in
     LD_LIBRARY_PATH==*) # success using DEBUG_PROG hack
       AC_MSG_RESULT(yes)
       ;;
     *)
       AC_MSG_RESULT(no)

       GETSYSTEMPROPERTYJAR=$GETSYSTEMPROPERTYJAR_BASENAME

       if test ! -f "$GETSYSTEMPROPERTYJAR"; then # not present
          GETSYSTEMPROPERTYJAR=se/sics/sicstus/configure/$GETSYSTEMPROPERTYJAR_BASENAME
       fi

       AC_MSG_CHECKING([whether java.library.path can be obtained instead])
       if test -f "$GETSYSTEMPROPERTYJAR"; then
          if ld_library_path_set=`"$JAVAEXEC" $JAVA_EXECOPTS -jar "$GETSYSTEMPROPERTYJAR" java.library.path`; then
             AC_MSG_RESULT([yes])
          else
             AC_MSG_RESULT([no])
             ld_library_path_set=""
          fi
       else # GetSystemProperty.jar not present
          AC_MSG_RESULT([no])
          AC_MSG_WARN([$GETSYSTEMPROPERTYJAR was not found])
          ld_library_path_set=""
       fi
       ;;
   esac

   AC_MSG_CHECKING([whether java shared library locations could be determined])
   if test -z "$ld_library_path_set"; then
      dnl something went wrong, should at least be "LD_LIBRARY_PATH="
      AC_MSG_RESULT([no, giving up])
      break
   else
      AC_MSG_RESULT(yes)
   fi
   dnl remove LD_LIBRARY_PATH== or java.library.path==
   dnl [PM] 3.9.1 used to have
   dnl \(LD_LIBRARY_PATH\|java\.library\.path\)== but IRIX 6.5 sed
   dnl does not appear to support \| in the regexp (!?!)
   java_ld_library_path=`echo "$ld_library_path_set" | sed -e 's/^java\.library\.path==/LD_LIBRARY_PATH==/' -e 's/^LD_LIBRARY_PATH==\(.*\)/\1/'`

   fi # [PM] 4.3 if test -z "$java_ld_library_path";


   AC_MSG_CHECKING([Java shared library locations])
   if test -z "$java_ld_library_path"; then
      AC_MSG_RESULT([none])
      java_library_dirs=""
      prefixed_java_library_path=""
   else # java_ld_library_path != ""
      dnl [PM] 3.9.1 AIX 4.3.3. JDK 1.3.1 has /usr/lib on java.library.path
      dnl but that should not go on LIBPATH and not be used as -L
      dnl directory. Such system lib directories should go on sys_L_dirs

      dnl [PM] 3.9.1 filter away any dir on sys_L_dirs (e.g., /usr/lib, /lib)
      dnl FILTER BEGIN

      dnl [PM] 4.0.2+ Cleanup on Solaris etc, too.
      dnl [PM] 4.0.8+ For linux PowerPC we add lib64 as one of the "usual places".
      : ${sys_L_dirs:='/lib:/lib64:/usr/lib:/usr/lib64'}
      dnl : ${sys_L_dirs="/lib:/usr/lib"}

      dnl [PM] 3.11.2 now always do this so the automount filtering gets done
      dnl if test -z "$sys_L_dirs"; then
      dnl  : # nothing
      dnl else
        # [PM] 3.11.3
        java_automount_dir=`( cd ${java_path} && /bin/pwd )` 2>/dev/null
        if test "${java_path}" = "${java_automount_dir}"; then
          java_automount_dir=''
        fi
        save_ifs="$IFS"; IFS=":"
        new_path=""
        elt_prefix=""
        dummy="$java_ld_library_path"
        for dir in $dummy; do 
          tmp_ifs="$IFS"; IFS="$save_ifs"; # [PM] 4.1.3 SPRM 11929
          if test -z "$dir"; then
            : # nothing
          else
            # [PM] 3.11.3 try to replace automount specific prefix with $java_path
            if test -n "${java_automount_dir}"; then
              pretty_dir=`echo "${dir}" | sed -n -e "s,^${java_automount_dir}/,${java_path}/,p"`
              if test -d "${pretty_dir}"; then
                dir="${pretty_dir}"
              fi
            fi
            bad_dir=no
            save_ifs2="$IFS"; IFS=":"; # [PM] 4.1.3 SPRM 11929
              for sys_dir in $sys_L_dirs; do
                tmp_ifs2="$IFS"; IFS="$save_ifs2";
                   if test "$sys_dir" = "$dir"; then
                     bad_dir=yes
                     IFS="$save_ifs"
                     AC_MSG_RESULT([removed system dir $dir from java_ld_library_path]);
                     IFS=":"
                     break
                   fi
                IFS="$tmp_ifs2"
              done
            IFS="$save_ifs2"

            if test $bad_dir = no; then
              new_path="$new_path$elt_prefix$dir"
              elt_prefix=":"
            fi
          fi
          IFS="$tmp_ifs" # [PM] 4.1.3
        done
        java_ld_library_path="$new_path"
        IFS="$save_ifs"



            ##################################################
            # GENERIC FILTERING CODE BEGIN (KEEP SYNCHRONIZED)
            # Set up input for filtering
            original_dirs="${java_ld_library_path}"
            bad_dirs="${sys_L_dirs}"
            path_title='Java link'
            # BEGIN generic block
            {
              # Input: original_dirs (colon separated)
              # Input: bad_dirs (colon separated)
              # Input: path_title (for messages, e.g. 'Tcl/Tk linker')
              # Output: cleaned_dirs (colon-separated)
              cleaned_dirs=''
              # for-loop over colon separated
              {
                save_ifs="$IFS"; IFS=":"
                for dir in $original_dirs; do
                  tmp_ifs="$IFS"; IFS="$save_ifs"; # [PM] 4.1.3 SPRM 11929
                  # Body is using outer IFS
                  {
                    if test -z "$dir"; then
                      : # nothing
                    else
                      is_bad_dir=no

                      # for-loop over colon separated
                      {
                        save_ifs1="$IFS"; IFS=":"
                        for bad_dir in ${bad_dirs}; do
                          tmp_ifs1="$IFS"; IFS="$save_ifs1";
                          # Body is using outer IFS
                          {
                            if test "$bad_dir" = "$dir"; then
                              is_bad_dir=yes
                              AC_MSG_RESULT([removed system dir $dir from $path_title path]);
                              break
                            fi
                          }
                          # Restore for-loop IFS at end of body
                          IFS="$tmp_ifs1"
                        done
                        # Restore IFS after for-loop
                        IFS="${save_ifs1}"
                      }
                      # pre for-loop IFS has been restored

                      if test "${is_bad_dir}" = no; then
                        cleaned_dirs="$cleaned_dirs$elt_prefix$dir"
                        elt_prefix=":"
                      fi
                    fi
                  }
                  # Restore for-loop IFS at end of body
                  IFS="$tmp_ifs" # [PM] 4.1.3
                done
                # Restore IFS after for-loop
                IFS="$save_ifs"
              }
              # pre for-loop IFS has been restored
            }
            # END generic block
            #
            # Propagate output variables
            candidate_lib_dirs="${cleaned_dirs}"
            # Reset local variables
            original_dirs='can_not_happen'
            bad_dirs='can_not_happen'
            path_title='can_not_happen'
            cleaned_dirs='can_not_happen'
            # GENERIC FILTERING CODE END (KEEP SYNCHRONIZED)
            ##################################################
            java_ld_library_path="${candidate_lib_dirs}"

      dnl fi # non-empty sys_L_dirs

      dnl FILTER END

      dnl space separate
      java_library_dirs=`echo "$java_ld_library_path" | sed -e 's/:/ /g'`


      AC_MSG_RESULT([$java_library_dirs])
      prefixed_java_library_path=":$java_ld_library_path"

      # [PM] 3.12.8 for platforms (like recent?) AIX Java 1.3.1 that
      # need to have its shared libraries pointed out via an
      # environment variable (as opposed to relying on RPATH or
      # similar).
      if test ${jasper_env_args_need_LD_LIBRARY_PATH:-no} = yes; then
         JASPER_ENV_ARGS="${JASPER_ENV_ARGS:+${JASPER_ENV_ARGS} }${LD_LIBRARY_PATH_name}=${java_ld_library_path}"
      fi
   fi # java_ld_library_path != ""
   dnl [PM] 3.11.2 not used: JAVA_RTL_PATH="$java_ld_library_path"

   dnl The LD_LIBRARY_PATH for Java has been set up

   dnl Check that it is possible to link with JVM.
   dnl Eventually this should be done for Win32 too.
   java_lib_name=jvm

   AC_MSG_CHECKING([Java link flags])
   dnl -L<DIR> for each :<DIR>:<DIR>:<DIR> on prefixed_java_library_path
   dnl [PM] 3.9.1 MacOS X overrides $java_ld_L_flags
   if test "${java_ld_L_flags+set}" != "set"; then
     dnl [PM] 4.0.2+ this creates the -L flags in the wrong order. The
     dnl effect is that the embeded RPATH/RUNPATH becomes in the
     dnl reversed order compared to the java.library.path. This in
     dnl turn crashes Java 5 and 6 on i386 Solaris when
     dnl JNI_CreateJavaVM is called.
     dnl : ${java_ld_L_flags=`echo "$prefixed_java_library_path" | sed -e 's/:/ -L/g'`}

     save_ifs="$IFS"; IFS=":"
     java_ld_L_flags=""
     for dir in $java_ld_library_path; do
       tmp_ifs="$IFS"; IFS="$save_ifs"; # [PM] 4.1.3 SPRM 11929
       if test -z "$dir"; then
         : # nothing
       else
         java_ld_L_flags="-L${dir}${java_ld_L_flags:+ }${java_ld_L_flags}"
       fi
       IFS="$tmp_ifs" # [PM] 4.1.3
     done
     IFS="$save_ifs"
   fi
   if test -n "${java_ld_L_flags}"; then
     AC_MSG_RESULT([${java_ld_L_flags}])
   else
     AC_MSG_RESULT([none])
   fi

   dnl Set up run-time library search path.
   dnl also used (by GNU LD) to locate dependencies of libjvm.so at
   dnl AC_CHECK_LIB() link time
   dnl java_ld_R_flags=""
   dnl instead of -R/-rpath use LD_RUN_PATH

   dnl LD_RUN_PATH is needed by GNU LD (Linux) in order for LD to find
   dnl the dependencies of libjvm.so.
   dnl For Solaris LD it does not matter (Somebody, please find the
   dnl documentation of this issue for Solaris LD)
   save_LD_RUN_PATH="$LD_RUN_PATH"
   LD_RUN_PATH="$java_ld_library_path"
   export LD_RUN_PATH

   dnl [PM] setting LDFLAGS is a kludge to pass -L<dir> to AC_CHECK_LIB
   PUSH_LDFLAGS="$LDFLAGS"
   LDFLAGS="$java_ld_L_flags"
   AC_CHECK_LIB($java_lib_name,JNI_CreateJavaVM,[java_links=yes],[java_links=no])
   LDFLAGS="$PUSH_LDFLAGS"
   LD_RUN_PATH="$save_LD_RUN_PATH"

   if test ".$java_links" != ".yes"; then
      AC_MSG_WARN([Could not link with JVM])
      break
   fi
fi # UNIX

ENABLE_JAVA_JNI=yes
done dnl [PM] 3.11.2 opt_enable_java_jni

AC_SUBST(ENABLE_JAVA_JNI)

if test ${ENABLE_JAVA_JNI} = yes; then

   dnl [PM] 3.10.2 On HP-UX IPF/ia64 the libjvm.so cannot be loaded with dlopen
   dnl    Must pre-load it with LD_PRELOAD, see HP-UX B.11.22 dld.so
   dnl    man-page and JDK 1.4.1_02 release notes.
   AC_MSG_CHECKING([whether JVM shared library need to be pre-loaded])
   : ${enable_preload_jvm=no}
   if test "x$enable_preload_jvm" = "xyes"; then
     AC_MSG_RESULT([yes])
     dnl [PM] 3.10.2 set in platform dependant way above
     if test -z "$LIBJVM_SO_name"; then
       AC_MSG_ERROR([Internal configure error, LIBJVM_SO_name not set])
     fi
     if test -z "$LD_PRELOAD_name"; then
       AC_MSG_ERROR([Internal configure error, LD_PRELOAD_name not set])
     fi
     AC_MSG_CHECKING([for location of jvm ($LIBJVM_SO_name)])

     jvm_path=""
     save_ifs="$IFS"; IFS=":"
     for dir in $java_ld_library_path; do
        tmp_ifs="$IFS"; IFS="$save_ifs"; # [PM] 4.1.3 SPRM 11929
        if test -f "$dir/$LIBJVM_SO_name"; then
          jvm_path="$dir/$LIBJVM_SO_name"
          break;
        fi
        IFS="$tmp_ifs" # [PM] 4.1.3
     done
     IFS="$save_ifs"
     if test -z "$jvm_path"; then
       AC_MSG_RESULT([not found])
       AC_MSG_WARN([$LIBJVM_SO_name not found])
     else
       AC_MSG_RESULT([$jvm_path])
     fi
     JAVA_PRELOAD="$LD_PRELOAD_name=$jvm_path"
     AC_MSG_CHECKING([how to pre-load the jvm shared library])
     AC_MSG_RESULT([$JAVA_PRELOAD])
   else   
     AC_MSG_RESULT([no])  
   fi
   dnl AC_SUBST(JAVA_PRELOAD)
   JASPER_ENV_ARGS="${JASPER_ENV_ARGS} ${JAVA_PRELOAD}"
   AC_SUBST(JASPER_ENV_ARGS)

   AC_SUBST(JAVAEXEC_ENV_ARGS)
fi #ENABLE_JAVA_JNI=yes

if test "$ENABLE_JAVA" = "yes"; then
dnl Everything found. Now set up the vars.
dnl When done should have:
dnl java_path -- the root JDK/SDK directory
dnl JDK_PATH  -- native version of java_path.
dnl JAVA_EXECOPTS -- extra options to java launcher. Can be set from
dnl                  environment. Useful value could be
dnl                  "-native -server" for JDK 1.3
dnl JASPER_MODULE -- jasper.po Makefiles and scripts look at this to
dnl                  determine if Jasper support is available.
dnl java_rtl_path -- Path for run-time linker when libjvm.so is used
dnl                  (i.e., what to set LD_LIBRARY_PATH to). Used as JDK_RPATH
dnl JAVALIB -- Link flags for Java (e.g., "-L... -ljvm -lthread").
dnl JAVAINC -- -I flags for jni.h and jni_md.h include dirs
dnl JAVAEXEC -- Full Unix/Cygwin path to java launcher.
dnl JAVAH -- path to javah
dnl JAVAC -- path to javac
dnl JAVADOC -- path to javadoc
dnl JAR -- path to jar
dnl JAVACFLAGS -- flags to javac (Currently not set, consider
dnl                  optimization flags)
dnl JAVACDBGFLAGS -- javac flags for debugging (-g when --enable-dbg)
dnl JAVA_CLASSPATH -- not set, not used.
dnl


   JDK_PATH=`$CYGPATH "$java_path"`
   AC_SUBST(JDK_PATH)

   AC_SUBST(JAVA_EXECOPTS)

   if test ${ENABLE_JAVA_JNI} = yes; then
      JASPER_MODULE="jasper.po"
   else
      JASPER_MODULE=""
   fi
   AC_SUBST(JASPER_MODULE)

   if test ${ENABLE_JAVA_JNI} = yes; then
      java_rtl_path="$java_ld_library_path"

      dnl JAVALIB are built up of
      dnl (1) $java_ld_L_flags: -L options pointing out where the JDK is
      dnl (2) $java_lib_name: Always jvm for now
      dnl (3) $JAVA_LDFLAGS: linker flags necessary for the Jasper-resource (e.g, -lthread)
      dnl [PM] 3.9.1 MacOS X overrides $JAVALIB
      dnl [PM] 3.11.2 Win32 overrides JAVALIB
      : ${JAVALIB="$java_ld_L_flags -l$java_lib_name $JAVA_LDFLAGS"}
      AC_SUBST(JAVALIB)

      JAVAINC="$java_inc_flags"
      AC_SUBST(JAVAINC)
   fi

   AC_SUBST(JAVACFLAGS)
   AC_SUBST(JAVACDBGFLAGS)

   AC_SUBST(JAVA_CLASSPATH)

   dnl [PD] 3.9.1 For SICStusInstaller
   INSTALLER_JAVA_VERSION=$JAVA_VERSION
   AC_SUBST(INSTALLER_JAVA_VERSION)
	
   java_done=yes
fi                              # [PM] 3.11.2 ENABLE_JAVA


dnl [PM] 3.8.6 JDK_RPATH: rpath to use for applications (such as
dnl            sicstus) that want to be able to use libjvm.so.
dnl
dnl            Note that (at least on Linux RedHat 6.1, libc-2.1.2.so)
dnl            setting the rpath of libjasper (as was done in 3.8.5 and
dnl            earlier) will not be enough since this rpath will not be
dnl            used when libjvm dlopens libjava.so and libzip.so.  The
dnl            reason it "worked" on 3.8.5 was that we linked
dnl            libjasper.so with libjava.so and libzip.so. This makes
dnl            libjava.so and libzip.so be dependencies that are found
dnl            by the dynamic loader when libjasper is dlopened and at
dnl            this time the rpath of libjasper *will* be used. When
dnl            libjvm.so later dlopens libjava.so and libzip.so (using
dnl            full pathnames obtained by using dladdr()) the dynamic
dnl            loader will determine that they are already loaded and
dnl            therefore their dependecies (which at this point would
dnl            not be found) will not need to be loaded. (in JDK 1.2.2
dnl            libjava.so has a dependency on libzip.so (or perhaps it
dnl            was the other way around)).
dnl
dnl            To work around this problem by guessing what other
dnl            libraries need to be linked in addition to libjvm.so is
dnl            simply wrong (and we did not get it right for JDK
dnl            1.3). Guessing what libjvm.so to use by using 'find' is
dnl            also unlikely to yield the right result (there is
dnl            typically at least two to choose from). To have the
dnl            libjvm.so rpath in libjasper.so is also not "the right
dnl            thing" (tm) in the case where a different jvm (e.g., java
dnl            -server) is used to embed sicstus in Java.
dnl            
dnl            What the java launcher does it to set-up LD_LIBRARY_PATH
dnl            in a wrapper shell script before calling the real java
dnl            launcher (we use this to determine the value of
dnl            JDK_RPATH, see earlier in this configure script). In our
dnl            case this would correspond to using a wrapper script for
dnl            sicstus. An alternative is to add JDK_RPATH to the rpath
dnl            of the sicstus executable. This has the following
dnl            advantages:
dnl            . Will work for both JDK 1.2 and 1.3 (there are unrelated,
dnl              signal handling issues with JDK 1.3)
dnl            . Will not risk loading the wrong JVM when SICStus is
dnl              embedded into a Java VM different from the default.
dnl            . Will behave the same as in 3.8.5, i.e., no user visible
dnl              changes.
dnl            The following are disadvantages:
dnl            . More things on rpath may make loading of shared
dnl              libraries slower.
dnl            . It will not possible to use a non-standard JDK without
dnl              rebuilding sicstus. (on the other hand, rebuilding
dnl              sicstus is trivial with spld and you can hava more than
dnl              one sicstus, whereas rebuilding libjasper.so is a black
dnl              art and there can only be one libjasper.so in a sicstus
dnl              installation). In either case this is no worse than in
dnl              3.8.5.
dnl            . Does not work on Solaris! (unwelcome surprise).
dnl 



dnl ============================================================
dnl ============================================================



dnl [PM] 3.8.6 Not yet documented: a minus sign before the resource is
dnl interpreted as "do not link but add rpath".

dnl [PM] 3.8.6 extra spld flags used in Utils/Makefile for building
dnl development system. In particular --resources=-jasper for JDK rpath
dnl issue. Set separately in InstallSICStus
dnl If JDK rpath is hardwired into development system executable then it
dnl should not (--no-rpath) be hardwired into libjasper.so foreign
dnl resource and vice versa. On Linux we hardwire in sicstus, on Solaris
dnl we hardwire in libjasper.so. This is due to differences in the way
dnl the dynamic linkers (does not!) find dependencies in dlopened files
dnl (e.g., in libjasper.so ([PM] 3.9.x what is now the plain foreign resource jasper.$FLI_SFX))
dnl
dnl NEW LATE 3.8.6
dnl We should do this:
dnl 1. enable (default) or disable hardwiring $enable_jdk_rpath
dnl 2. platform dependent: where to hardwire (sicstus/libjasper.so)
dnl    $jdk_rpath_in_ds, $jdk_rpath_in_jasper

if test ".$JASPER_MODULE." != ".."; then
   AC_MSG_CHECKING([extra JDK related --resources options to spld])

   if test "$default_jdk_rpath_set" != "yes"; then
     dnl [PM] 3.9.1 booby trap. If you encounter this you should set
     dnl default_jdk_rpath_in_jasper and default_jdk_rpath_in_ds above.
     AC_MSG_ERROR([need to explicitly set whether to embed JDK rpath])
   fi


   if test ".$jdk_rpath_in_ds" = ".yes"; then
      resname=jasper

      if test "x$SPLD_DS_RESOURCES" = "x"; then # not yet set
         res_prefix=""
      else # separate with comma
         res_prefix=","
      fi
      SPLD_DS_RESOURCES="${SPLD_DS_RESOURCES}${res_prefix}-${resname}"
      AC_MSG_RESULT([${SPLD_DS_RESOURCES}])
   else
      AC_MSG_RESULT([none])
   fi

   AC_MSG_CHECKING(extra JDK related options to splfr)

   if test ".$jdk_rpath_in_jasper" != ".yes"; then
      JASPER_SPLFR_FLAGS=' --no-rpath '
   fi
   if test -n "$JASPER_SPLFR_FLAGS"; then
      AC_MSG_RESULT([$JASPER_SPLFR_FLAGS])
   else
      AC_MSG_RESULT(none)
   fi

fi dnl JASPER_MODULE


JDK_RPATH="$java_rtl_path"
AC_SUBST(JDK_RPATH)

AC_SUBST(JDK_PATH)
AC_SUBST(JAVA_EXECOPTS)
AC_SUBST(JASPER_MODULE)
: ${JAVADOCFLAGS=''}
AC_SUBST(JAVADOCFLAGS)

dnl [PD] 3.11.1 For InstallSICStus
if test "$ENABLE_JAVA_JNI" = "yes"; then
   INSTALLER_HAS_JAVA_JNI=yes
else
   INSTALLER_HAS_JAVA_JNI=no
fi
AC_SUBST(INSTALLER_HAS_JAVA_JNI)

#########
#
# Checking Tcl/Tk version. This is quite hairy.
# 


AC_ARG_WITH(tcltkversion,
    [  --with-tcltkversion     Specify Tcl/Tk version (rarely needed). Ex: 8.0, 8.0/8.3],
    [
        case "$withval" in
          no)
            # pointless but ignore it
            :
          ;;
          yes)
            AC_MSG_ERROR([--with-tcltkversion must specify a version])
          ;;
          *)
	    TCLTK_VERSION=$withval
            tcltk_version_explicit=yes
          ;;
        esac
    ],
    [
      tcltk_version_explicit=no
    ]
)
AC_ARG_WITH(tcltk,
                        [  --with-tcltk            Specify path to Tcl/Tk installation, e.g., /usr/local],
	    [TCLTK_PATH=$withval],
            [
            if test "${enable_foreign_resources:-yes}" = "no"; then
              TCLTK_PATH=no
            fi
            ])
AC_ARG_WITH(tcl,
                        [  --with-tcl              Specify path to Tcl installation. Overrides --with-tcltk.],
	    [TCL_PATH=$withval])
AC_ARG_WITH(tk,
                        [  --with-tk               Specify path to Tcl installation. Overrides --with-tcltk.],
	    [TK_PATH=$withval])

AC_ARG_WITH(libtk,
[  --with-libtk            Specify full path of libtk<ver>.so. 
                          Used by installer. Overrides --with-tcltk.],
	    [LIBTK_PATH=$withval])
dnl [PD] 4.0.5
AC_ARG_ENABLE([tcltk-version-fallback], [  --enable-tcltk-version-fallback     Internal. Used by InstallSICStus],
	      [
	       tcltk_version_fallback=yes
	      ],
	      [
	       tcltk_version_fallback=no
	      ]
	     ) 

dnl [PM] 3.9.1 used by the GUI installer. Sets up TCLTK_VERSION and
dnl TCLTK_PATH so the rest of configure will do the right thing.
if test "x$LIBTK_PATH" != "x"; then
   AC_MSG_CHECKING([How to locate Tcl/Tk])
   AC_MSG_RESULT([using libtk path ($LIBTK_PATH)])

   AC_MSG_CHECKING([Tk lib version])
   [ TCLTK_VERSION=`echo "$LIBTK_PATH" | sed -n -e 's/^.*[a-zA-Z]\([0-9][0-9]*\.[0-9][0-9]*\)\.[a-zA-Z]*$/\1/p'` ]
   AC_MSG_RESULT([$TCLTK_VERSION])

   AC_MSG_CHECKING([Tk lib location])
   [ TCLTK_PATH=`echo "$LIBTK_PATH" | sed -n -e 's@^\(.*\)/[^/]*$@\1@p'` ]
   case "$TCLTK_PATH" in
     */lib)
       dnl [PM] 3.9.1+ it must end in lib since "lib" is what will be added to TCLTK_PATH 
       TCLTK_PATH=`echo "$TCLTK_PATH" | sed -n -e 's@^\(.*\)/lib$@\1@p'`
       AC_MSG_RESULT([$TCLTK_PATH])
       ;;
     *)
       AC_MSG_RESULT([])
       AC_MSG_WARN([Tk library ($LIBTK_PATH) must be located in a directory called lib])
       TCLTK_PATH=''
       ;;
   esac
   AC_MSG_CHECKING([Tcl/Tk using Tk lib info ($TCLTK_PATH)])
   AC_MSG_RESULT([])
fi

tcltk_failure_fatal=no

tcltk_explicit=no
if test ".$TCLTK_PATH" = ".yes"; then
   TCLTK_PATH=''
   tcltk_explicit=yes
fi

if test "${TCLTK_PATH:-yes}" != "no"; then

tcltk_already_configured=no
case $PLATFORM in
   *darwin-*)

      AC_MSG_CHECKING([method for setting MacOS X Tcl/Tk Aqua foreground process])
      # [PM] 4.2.3 Tcl/Tk takes care of this (transforming process to UI process) automatically nowadays.
      USE_TransformProcessType_default=no
      AC_ARG_ENABLE(darwin-transformprocesstype, [  --enable-darwin-transformprocesstype  Use MacOS 10.3 TransformProcessType to allow MacOS X Tcl/Tk GUI],
                    [
                      case "${enableval:-${USE_TransformProcessType_default}}" in
                       "yes")
                          USE_TransformProcessType=yes
                       ;;
                       "no")
                          USE_TransformProcessType=no
                       ;;
                       *)
                          USE_TransformProcessType=${USE_TransformProcessType_default}
                       ;;
                      esac
                    ],
                    [
                          dnl [PM] 4.0.1 Note: 3.12.7 says that
                          dnl TransformProcessType does not work but
                          dnl it does not matter since we use neither
                          dnl by default now that we assume Mac OS X
                          dnl 10.4 or later.
                          dnl
                          dnl [PM] 3.11.1 WARNING: should default to yes on MacOS X 10.3 or later
                          USE_TransformProcessType=${USE_TransformProcessType_default}
                    ])

      dnl [PM] 3.10.1 Use undocumented CPSEnableForegroundOperation to
      dnl allow the non-bundled sicstus to launch GUI stuff etc.
      AC_ARG_ENABLE(dockable-tcltk, [  --enable-dockable-tcltk  Use un-documented functions to allow MacOS X Tcl/Tk GUI],
                    [
                      case "${enableval:-no}" in
                       "yes")
                          USE_CPSEnableForegroundOperation=yes
                       ;;
                       *)
                          USE_CPSEnableForegroundOperation=no
                       ;;
                      esac
                    ],
                    [
                          if test ${USE_TransformProcessType:-no} = yes; then
                             USE_CPSEnableForegroundOperation=no
                          else
                             # [PM] 4.2.3 Never use unless explicitly requested.
                             USE_CPSEnableForegroundOperation=no
                          fi
                    ])
      method="none"
      FRAMEWORK_TCLDEFS=""

      if test ${USE_TransformProcessType:-no} = yes; then
         method="TransformProcessType (>= 10.3 only)"
         FRAMEWORK_TCLDEFS="-DUSE_TransformProcessType"
         USE_CPSEnableForegroundOperation=no
         EXTRA_TCLLIB="-framework ApplicationServices"
      fi
      if test "$USE_CPSEnableForegroundOperation" = "yes"; then
        method="CPSEnableForegroundOperation (undocumented hack, works in 10.2)"
        FRAMEWORK_TCLDEFS="-DUSE_CPSEnableForegroundOperation"
        EXTRA_TCLLIB="-framework ApplicationServices"
      fi

dnl [PM] 4.0 These should only be passed on command line. They are no
dnl          longer in config.h.in
dnl       if test $USE_TransformProcessType = yes; then
dnl          AC_DEFINE(USE_TransformProcessType,1)
dnl       else
dnl          AC_DEFINE(USE_TransformProcessType,0)
dnl       fi
dnl       if test "$USE_CPSEnableForegroundOperation" = "yes"; then
dnl         AC_DEFINE(USE_CPSEnableForegroundOperation,1)
dnl       else
dnl         AC_DEFINE(USE_CPSEnableForegroundOperation,0)
dnl       fi


      AC_MSG_RESULT([$method])
      dnl [PM] 3.10.1 Default to framework-version if no explicit tcltk path.

      dnl [PM] 3.10.1 FIXME: If TCLTK_PATH != "" then we should ideally check to see if -F is truly needed.
      tcltk_framework_in_standard_location=no

      if test -z "$TCLTK_PATH"; then
         AC_MSG_CHECKING([for Tcl/Tk framework in standard locations])

         # [PM] 4.1 On my Mac (updated from 10.5, and perhaps
         #          ultimately from 10.4) there is a 32-bit-only Tk in
         #          /Library/Frameworks which will prevent
         #          library(tcltk) from building. However, changing
         #          the search order here will not help unless we lie
         #          and set tcltk_framework_in_standard_location=no to
         #          force an explicit framework path. Instead I fixed
         #          my machine and just removed the obsolete
         #          frameworks (from 2007).

         # [PM] 4.1 Removed ~/Library/Frameworks  /Network/Library/Frameworks which are not searched by default
         #          We could do a separate search for these and set
         #          tcltk_framework_in_standard_location=no
         # The run-time order for frameworks are 
         # 1. The path embedded in the binary
         # 2. /Library/Frameworks (i.e. third-party frameworks)
         # 3 /System/Library/Frameworks (i.e. OS frameworks)
         # See Framework Programming Guide at apple.com

         for sdk_path in ${XCRUN_SDK_PATH} / ; do 
            dnl AC_MSG_NOTICE([looking in sdk_path=${sdk_path}])
            # strip the terminating slash, if any and then re-add a slash between sdk_path and the suffix
	    for framework_dir in ${sdk_path%/}/Library/Frameworks ${sdk_path%/}/System/Library/Frameworks  ; do
               dnl AC_MSG_NOTICE([looking in framework_dir=${framework_dir}])
	       if test -d "${framework_dir}/Tk.framework" && test -d "${framework_dir}/Tcl.framework" ; then
                  dnl AC_MSG_NOTICE([using framework_dir=${framework_dir}])
		  TCLTK_PATH="${framework_dir}"
		  tcltk_framework_in_standard_location=yes
		  break;
	       fi
	    done # framework_dir
            if test -z "$TCLTK_PATH"; then
              :
            else
              break
            fi
         done # sdk_path
         if test -z "$TCLTK_PATH"; then
            AC_MSG_RESULT([none])
         else
            AC_MSG_RESULT([$TCLTK_PATH])
         fi
      fi
      case "$TCLTK_PATH" in
         /)
           :
         ;;
         */)
            AC_MSG_WARN([Removing trailing slash from TCLTK_PATH ($TCLTK_PATH)])
            tmp_path=`echo "$TCLTK_PATH" | sed -e 's%\(.*\)/$%\1%'`
            TCLTK_PATH="$tmp_path"
         ;;
      esac

      AC_MSG_CHECKING([whether MacOS X Tcl/Tk framework should be used])
      dnl [PM] 4.3 always use framework
      use_tcltk_framework=yes
      AC_MSG_RESULT([$use_tcltk_framework])

      if test "$use_tcltk_framework" = yes; then
         FRAMEWORK_TCLDEFS="-DMACOSX_TCLTK_FRAMEWORK $FRAMEWORK_TCLDEFS"
         tcltk_already_configured=yes

         TCLLIB=""
         if test "$tcltk_framework_in_standard_location" = "no"; then
            dnl -F<path> additional framework location
            TCLLIB="-F$TCLTK_PATH"
            # [PM] 4.3 Assume that if the path is explicit then it has the headers too
            TCLTK_SDK_FRAMEWORKS="$TCLTK_PATH"
         else # tcltk_framework_in_standard_location = yes
            # [PM] 4.3 TCLTK_SDK_FRAMEWORKS should be set to the SDK Frameworks directory
AC_MSG_WARN([FIXME: Resolve Tcl/Tk include issues on OS X 10.9])
            TCLTK_SDK_FRAMEWORKS="$TCLTK_PATH"  
         fi
         TCLLIB="$TCLLIB -framework Tcl -framework Tk $EXTRA_TCLLIB"
         TCLINC="$FRAMEWORK_TCLDEFS"

         dnl [PM] 4.3 The headers are gone from the OS X 10.9
         dnl (Mavericks) system framework directories. Instead need to
         dnl look in the SDK version
         dnl TCLINC="$TCLINC -I$TCLTK_PATH/Tcl.framework/Headers -I$TCLTK_PATH/Tcl.framework/PrivateHeaders -I$TCLTK_PATH/Tk.framework/Headers -I$TCLTK_PATH/Tk.framework/PrivateHeaders"

         
         for d in Tcl.framework/Headers Tcl.framework/PrivateHeaders Tk.framework/Headers Tk.framework/PrivateHeaders; do
            abs_dir="$TCLTK_SDK_FRAMEWORKS/$d"
     AC_MSG_CHECKING([for $abs_dir])
            if test -d "$abs_dir"; then
     AC_MSG_RESULT([yes])
              TCLINC="$TCLINC -I$abs_dir"
            else
     AC_MSG_RESULT([no])
            fi
         done

         TCL_LIBRARY=''
         TK_LIBRARY=''
         TCLTK_MODULE="tcltk.po"
         dnl these could be empty
         TCL_PATH="$TCLTK_PATH"
         TK_PATH="$TCLTK_PATH"
      fi
   ;;
   *)
      :
   ;;
esac

fi                              dnl TCL_PATH != no


if test "$tcltk_already_configured" != "yes"; then dnl [PM] 3.10.1
AC_MSG_CHECKING([Tcl/Tk])
if test ".$TCLTK_PATH" = ".no"; then
    AC_MSG_RESULT(no)
    : ${TCLLIB=""}
else
    tcl_ok=no

    # [PM] 3.9b2 TCLTK_PATH is a cygwin path here

    # If --with-tcltk is specified, use it unless --with-tcl or --with-tk has been given
    if test -n "$TCLTK_PATH"; then
	: ${TCL_PATH:="${TCLTK_PATH}"}
	: ${TK_PATH:="${TCLTK_PATH}"}
	tcl_ok=yes
        tcltk_explicit=yes
    fi
    
    # [PM] 3.9b2 TCLTK_PATH, TCL_PATH, TK_PATH are cygwin paths here
    
    # If they are equal, set TCLTK_PATH to that value.
    if test -n "$TCL_PATH" && test -n "$TK_PATH"; then
	if test "X$TCL_PATH" = "X$TK_PATH"; then
	    TCLTK_PATH=$TCL_PATH
	fi
	tcl_ok=yes
    fi

    # [PM] 3.9b2 TCLTK_PATH, TCL_PATH, TK_PATH are cygwin paths here

    # X_CFLAGS are flags needed to correctly compile C-code with X
    INCPATHFLAGS="$X_CFLAGS"

    if test -n "$TCLTK_PATH"; then
	tcl_ok=yes

        ## [PM] 3.8.6 on TclPro 1.4 (at least) the platform
        ## independent include file is located one level up from the
        ## platform dependent bin and lib directories (SPRM 2008)

        # [PM] 3.9b2 --with-tcltk is now a cygwin path like the other -with-XXX paths.
        tcltk_native_path=`$CYGPATH "$TCLTK_PATH"`
        tcltk_native_include_dir="$tcltk_native_path/include"

        ## [PM] 3.8.6 The -d in the test should be -e (in case of
        ## symbolic links) but /usr/ucb/test on solaris does not
        ## recognize the -e primitive
        if test -d "$TCLTK_PATH/bin" && test -d "$TCLTK_PATH/lib" && test ! -f "$TCLTK_PATH/include/tcl.h"; then
           if test -f "$TCLTK_PATH/../include/tcl.h"; then
              tcltk_native_include_dir=`$CYGPATH "$TCLTK_PATH/../include"`
           fi
        fi

        # [PM] 3.9b2 TCLTK_PATH, TCL_PATH, TK_PATH are cygwin paths here
        #             tcltk_native_include_dir is a Win32 path (on windows)

	INCPATHFLAGS="-I$tcltk_native_include_dir $INCPATHFLAGS"
	tcltk_path_lib_dir="$TCLTK_PATH/lib"

	if test "${msvc_cc}" != yes; then
dnl	    LIBPATHFLAGS="-L$TCLTK_PATH/lib $LIBPATHFLAGS"

	    # [PM] 4.1/4.0.8+ Filter out the "usual places".
	    # Was a problem since /usr/lib was added when building on
	    # 64-bit RHEL 5.4 POWER5 where /usr/lib64 is the default,
	    # causing 32-bit libs to be picked up causing failure to
	    # detect Tcl/Tk.
            # [PM] 4.3 this filtering was broken (since 4.1.3 SPRM
            # 11929?) and this affected CentOS 5.10 x86_64 in the same
            # way as RHEL 45.4 POWER5.

	    # [PM] 4.1 set to empty if one of the system dirs
            candidate_lib_dirs="$tcltk_path_lib_dir"

	    dnl FILTER BEGIN (generic code, candidate_lib_dirs can be a colon separated path list)
	    dnl [PM] 4.1 
	    : ${sys_L_dirs:="/lib:/lib64:/usr/lib:/usr/lib64"}

	    cleaned_dirs=""
	    elt_prefix=""

            ##################################################
            # GENERIC FILTERING CODE BEGIN (KEEP SYNCHRONIZED)
            # Set up input for filtering
            original_dirs="${candidate_lib_dirs}"
            bad_dirs="${sys_L_dirs}"
            path_title='Tcl/Tk link'
            # BEGIN generic block
            {
              # Input: original_dirs (colon separated)
              # Input: bad_dirs (colon separated)
              # Input: path_title (for messages, e.g. 'Tcl/Tk linker')
              # Output: cleaned_dirs (colon-separated)
              cleaned_dirs=''
              # for-loop over colon separated
              {
                save_ifs="$IFS"; IFS=":"
                for dir in $original_dirs; do
                  tmp_ifs="$IFS"; IFS="$save_ifs"; # [PM] 4.1.3 SPRM 11929
                  # Body is using outer IFS
                  {
                    if test -z "$dir"; then
                      : # nothing
                    else
                      is_bad_dir=no

                      # for-loop over colon separated
                      {
                        save_ifs1="$IFS"; IFS=":"
                        for bad_dir in ${bad_dirs}; do
                          tmp_ifs1="$IFS"; IFS="$save_ifs1";
                          # Body is using outer IFS
                          {
                            if test "$bad_dir" = "$dir"; then
                              is_bad_dir=yes
                              AC_MSG_RESULT([removed system dir $dir from $path_title path]);
                              break
                            fi
                          }
                          # Restore for-loop IFS at end of body
                          IFS="$tmp_ifs1"
                        done
                        # Restore IFS after for-loop
                        IFS="${save_ifs1}"
                      }
                      # pre for-loop IFS has been restored

                      if test "${is_bad_dir}" = no; then
                        cleaned_dirs="$cleaned_dirs$elt_prefix$dir"
                        elt_prefix=":"
                      fi
                    fi
                  }
                  # Restore for-loop IFS at end of body
                  IFS="$tmp_ifs" # [PM] 4.1.3
                done
                # Restore IFS after for-loop
                IFS="$save_ifs"
              }
              # pre for-loop IFS has been restored
            }
            # END generic block
            #
            # Propagate output variables
            candidate_lib_dirs="${cleaned_dirs}"
            # Reset local variables
            original_dirs='can_not_happen'
            bad_dirs='can_not_happen'
            path_title='can_not_happen'
            cleaned_dirs='can_not_happen'
            # GENERIC FILTERING CODE END (KEEP SYNCHRONIZED)
            ##################################################

	    # We know there is at most one entry on candidate_lib_dirs
            tcltk_path_lib_dir="$candidate_lib_dirs"
	    if test -n "$tcltk_path_lib_dir"; then
              LIBPATHFLAGS="-L$tcltk_path_lib_dir $LIBPATHFLAGS"
            fi
	fi
        # [PM] 3.9b2 TCLTK_PATH, TCL_PATH, TK_PATH are cygwin paths here
        #            tcltk_native_include_dir is native here (a Win32 path on windows)
        #            INCPATHFLAGS is native here 

    else # TCLTK_PATH empty
	# This place is only reached if none of the Tcl/Tk path variables
	# are set, or if TCL_PATH and TK_PATH are different.

	# Give them default values if they aren't set. This would not be
	# necessary if your ${CC} and $LD always search /usr/local/lib (or
	# whatever the default path is.  that is often not the case.

	# Check if $TCLTK_DEFAULT seems to have a Tcl/Tk installation.
	# Use the existance of tcl.h as the test.
	tcl_ok=no

        ## ([PM] 3.8.6 No TclPro hack here since TclPro should not be on TCLTK_DEFAULT)
        for dir in $TCLTK_DEFAULT; do # [PM] 3.9b2 TCLTK_DEFAULT is cygwin path on Win32
            # [PM] 4.0.2 On Ubuntu /usr/include/tcl8.5/{tcl,tk}.h is used
            for suffix in ${TCLTK_VERSION:+"/tcl${TCLTK_VERSION}"} ""; do
              includedir="${dir}/include${suffix}"
              if test -f "${includedir}/tcl.h"; then
                  tcldef="$dir"
                  tcl_ok=yes
                  if test -z "${suffix}" && test ${tcltk_version_fallback:-no} = "yes"; then
                      # [PD] 4.0.5 We found tcl.h in an include directory without version number
                      TCLTK_VERSION=""
                  fi
                  : ${TCL_PATH:="$tcldef"}
                  : ${TK_PATH:="$tcldef"}
                  : ${TCLTK_PATH:="$tcldef"}
                  TCLTK_INCLUDE_DIR="${includedir}"
                  tcl_native_include_dir=`$CYGPATH "${TCLTK_INCLUDE_DIR}"`
                  # [PM] 4.0.2+ No longer support separate Tcl and Tk directories
                  # tk_native_include_dir=`$CYGPATH "$TK_PATH/../include"`
                  # INCPATHFLAGS="-I$tcl_native_include_dir -I$tk_native_include_dir $INCPATHFLAGS"
                  INCPATHFLAGS="-I$tcl_native_include_dir $INCPATHFLAGS"

                  # [PM] 3.9b2 TCLTK_PATH, TCL_PATH, TK_PATH are cygwin paths here
                  #            tcltk_native_include_dir is native here (a Win32 path on windows)
                  #            INCPATHFLAGS is native here


                  # Under Windows, we specify the tcltk libs with a full
                  # path. Therefore no -L<dir> are needed on windows to
                  # find the tcltk libs.
                  if test "${msvc_cc}" != yes; then
dnl                      if test "$TCL_PATH" = "$TK_PATH"; then
dnl                           LIBPATHFLAGS="-L$TCL_PATH/lib $LIBPATHFLAGS"
dnl                       else
dnl                           LIBPATHFLAGS="-L$TCL_PATH/lib -L$TK_PATH/lib $LIBPATHFLAGS"
dnl                       fi

                    # [PM] 4.1/4.0.8+ Filter out the "usual places".
                    # Was a problem since /usr/lib was added when building on
                    # 64-bit RHEL 5.4 POWER5 where /usr/lib64 is the default,
                    # causing 32-bit libs to be picked up causing failure to
                    # detect Tcl/Tk.

                    if test "$TCL_PATH" = "$TK_PATH"; then
                      tcltk_path_lib_dirs="$TCL_PATH/lib"
                    else
                      tcltk_path_lib_dirs="$TCL_PATH/lib:$TK_PATH/lib"
                    fi

                    # [PM] 4.1 entries are removed if one of the system dirs
                    candidate_lib_dirs="$tcltk_path_lib_dirs"
                    dnl [PM] 4.1 
                    : ${sys_L_dirs:="/lib:/lib64:/usr/lib:/usr/lib64"}


            ##################################################
            # GENERIC FILTERING CODE BEGIN (KEEP SYNCHRONIZED)
            # Set up input for filtering
            original_dirs="${candidate_lib_dirs}"
            bad_dirs="${sys_L_dirs}"
            path_title='Tcl/Tk link'
            # BEGIN generic block
            {
              # Input: original_dirs (colon separated)
              # Input: bad_dirs (colon separated)
              # Input: path_title (for messages, e.g. 'Tcl/Tk linker')
              # Output: cleaned_dirs (colon-separated)
              cleaned_dirs=''
              # for-loop over colon separated
              {
                save_ifs="$IFS"; IFS=":"
                for dir in $original_dirs; do
                  tmp_ifs="$IFS"; IFS="$save_ifs"; # [PM] 4.1.3 SPRM 11929
                  # Body is using outer IFS
                  {
                    if test -z "$dir"; then
                      : # nothing
                    else
                      is_bad_dir=no

                      # for-loop over colon separated
                      {
                        save_ifs1="$IFS"; IFS=":"
                        for bad_dir in ${bad_dirs}; do
                          tmp_ifs1="$IFS"; IFS="$save_ifs1";
                          # Body is using outer IFS
                          {
                            if test "$bad_dir" = "$dir"; then
                              is_bad_dir=yes
                              AC_MSG_RESULT([removed system dir $dir from $path_title path]);
                              break
                            fi
                          }
                          # Restore for-loop IFS at end of body
                          IFS="$tmp_ifs1"
                        done
                        # Restore IFS after for-loop
                        IFS="${save_ifs1}"
                      }
                      # pre for-loop IFS has been restored

                      if test "${is_bad_dir}" = no; then
                        cleaned_dirs="$cleaned_dirs$elt_prefix$dir"
                        elt_prefix=":"
                      fi
                    fi
                  }
                  # Restore for-loop IFS at end of body
                  IFS="$tmp_ifs" # [PM] 4.1.3
                done
                # Restore IFS after for-loop
                IFS="$save_ifs"
              }
              # pre for-loop IFS has been restored
            }
            # END generic block
            #
            # Propagate output variables
            candidate_lib_dirs="${cleaned_dirs}"
            # Reset local variables
            original_dirs='can_not_happen'
            bad_dirs='can_not_happen'
            path_title='can_not_happen'
            cleaned_dirs='can_not_happen'
            # GENERIC FILTERING CODE END (KEEP SYNCHRONIZED)
            ##################################################

                    tcltk_path_lib_dirs="$candidate_lib_dirs"

                    save_ifs="$IFS"; IFS=":"
                    for dir in $tcltk_path_lib_dirs; do 
                      tmp_ifs="$IFS"; IFS="$save_ifs"; # [PM] 4.1.3 SPRM 11929
                      if test -n "$dir"; then
                        LIBPATHFLAGS="-L$dir $LIBPATHFLAGS"
                      fi
                      IFS="$tmp_ifs" # [PM] 4.1.3
                    done
                    IFS="$save_ifs"
                    break
                fi # !msvc
              fi
          done # for suffix
          # [PD] 4.0.5 Don't keep on looping if we found tcl.h
          if test "${tcl_ok:-no}" = "yes"; then
              break
          fi
        done # for dir
    fi

    # [PM] 3.9b2 TCLTK_PATH, TCL_PATH, TK_PATH are cygwin paths here
    #            tcltk_native_include_dir is native here (a Win32 path on windows)
    #            INCPATHFLAGS is native here
    AC_MSG_CHECKING([Tcl/Tk install directories])
    if test $tcl_ok = no; then
	AC_MSG_RESULT([not found])
    else
	if test "$TCL_PATH" != "$TK_PATH"; then
	    AC_MSG_RESULT([yes ($TCL_PATH and $TK_PATH)])
	else
	    AC_MSG_RESULT([yes ($TCLTK_PATH)])
	fi

	if test "$x_includes" && test "$x_includes" != "NONE"; then
	    : ${TCLINC="$INCPATHFLAGS -I$x_includes $X_CFLAGS"}
	else
	    : ${TCLINC="$INCPATHFLAGS $X_CFLAGS"}
	fi

        # [PM] 3.9b2 TCLTK_PATH, TCL_PATH, TK_PATH are cygwin paths here
        #            tcltk_native_include_dir is native here (a Win32 path on windows)
        #            INCPATHFLAGS is native here
        #            TCLINC is native here
    
	PUSH_CPPFLAGS="$CPPFLAGS"
	CPPFLAGS="$CPPFLAGS $TCLINC"
    
	AC_CHECK_HEADER(tcl.h,[tcltk_inc_found=yes],[tcltk_inc_found=no])
        if test "$tcltk_inc_found" = "yes"; then
           AC_CHECK_HEADER(tk.h,[tcltk_inc_found=yes],[tcltk_inc_found=no])
        fi
    
	CPPFLAGS="$PUSH_CPPFLAGS"
	
	AC_MSG_CHECKING([Tcl/Tk version])

        dnl [PM] 3.9.1b4 TCLTK_VERSION may be set to empty if
        dnl --with-libtk is used (and is something like .../libtk.so)
	if test "${TCLTK_VERSION:+set}" = "set"; then
            if test -z "$TCLTK_VERSION"; then
              AC_MSG_RESULT([not specified])
            else
              AC_MSG_RESULT([$TCLTK_VERSION])
            fi
	else
	    # Try to compile a small program to find the Tcl/Tk version.
	    cat > tcltk_tmp.c <<EOF
#include <tcl.h>
#include <tk.h>
#include <string.h> /* [PM] 3.8.6 strcmp */
#include <stdio.h>  /* [PM] 3.8.6 printf */
int main(int argc, char **argv) {
  char *tcl_ver = TCL_VERSION;
  char *tk_ver = TK_VERSION;
  if (strcmp(tcl_ver,tk_ver))
    printf(TCL_VERSION "/" TK_VERSION);
  else printf(TCL_VERSION);
  return 1;
}
EOF
	    if test $tcltk_inc_found = "yes" && \
		${CC} ${TCLINC} tcltk_tmp.c -o tcltk_tmp >/dev/null 2>&1; then
		TCLTK_VERSION=`./tcltk_tmp`
	    else
		TCLTK_VERSION="8.0"
	    fi
	    AC_MSG_RESULT($TCLTK_VERSION)
	    rm -f tcltk_tmp*
	fi
    
	# If on the form x.y/x.y, extract version numbers
	if test "`echo $TCLTK_VERSION | sed 's/^\(.*\)\/\(.*\)$/match/'`" = "match"; then
	    TCL_VERSION=`echo $TCLTK_VERSION | sed 's/\/\(.*\)$//'`
	    TK_VERSION=`echo $TCLTK_VERSION | sed 's/^\(.*\)\///'`
	else
	    TCL_VERSION=$TCLTK_VERSION
	    TK_VERSION=$TCLTK_VERSION
	fi
    	
	# No X for Tcl/Tk under Win32 (FIXME: what about Mac OS X/Aqua?)
	if test "${WIN32:-no}" != "yes"; then
	    tcltk_xflags="${X_LIBS} ${X_PRE_LIBS} -lX11 ${X_EXTRA_LIBS}"
	fi
    
	if test "${msvc_cc}" != yes; then
	    if test $no_dots_in_libnames; then
		TCL_LIBSFX="`echo ${TCL_VERSION} | tr -d .`"
		TK_LIBSFX="`echo ${TK_VERSION} | tr -d .`"
	    else
		TCL_LIBSFX="$TCL_VERSION"
		TK_LIBSFX="$TK_VERSION"
	    fi
	    : ${TCLTK_LIBS="$LIBPATHFLAGS -ltk$TK_LIBSFX -ltcl$TCL_LIBSFX"}
	    : ${TCLLIB="$TCLTK_LIBS $tcltk_xflags $tcltk_extra_libs"}
	    
	    PUSH_LIBS="$LIBS"
	    LIBS="$TCLLIB $LIBS"

            dnl [PM] 3.9.1b4 ugly hack so that AC_CHECK_LIB will
            dnl really look in the --with-tcltk directories.
            PUSH_LDFLAGS="$LDFLAGS"

            dnl [PM] 3.9.2 AIX 5 Added in LDFLAGS since LDFLAGS
            dnl contains -brtl which is needed to find .so-versions of
            dnl libs
            LDFLAGS="$LIBPATHFLAGS $LDFLAGS"

	    AC_CHECK_LIB(tcl$TCL_LIBSFX,Tcl_Init,[tcltk_lib_found=yes],[tcltk_lib_found=no],
		[$tcltk_xflags $tcltk_extra_libs])
	    AC_CHECK_LIB(tk$TK_LIBSFX,Tk_Init,[tcltk_lib_found=yes],[tcltk_lib_found=no],
		[$tcltk_xflags $tcltk_extra_libs])

            LDFLAGS="$PUSH_LDFLAGS"
	    LIBS="$PUSH_LIBS"

	    if test $tcltk_lib_found = no; then
		tcl_ok=no;
	    fi

	else # "${msvc_cc}" = yes (Win32)

            # [PM] 3.9b2 TCLTK_PATH, TCL_PATH, TK_PATH are cygwin paths here
            #            tcltk_native_include_dir is native here (a Win32 path on windows)
            #            INCPATHFLAGS is native here
            #            TCLINC is native here

	    TCL_LIBNAME=tcl`echo ${TCL_VERSION} | tr -d .`.lib
	    TK_LIBNAME=tk`echo ${TK_VERSION} | tr -d .`.lib
            tcl_native_dir=`$CYGPATH "$TCLTK_PATH"`
            tk_native_dir=`$CYGPATH "$TK_PATH"`
	    : ${TCLTK_LIBS="$tcl_native_dir/lib/$TCL_LIBNAME $tk_native_dir/lib/$TK_LIBNAME"}
	    : ${TCLLIB="$TCLTK_LIBS $tcltk_xflags $tcltk_extra_libs"}

            # [PM] 3.9b2 TCLTK_PATH, TCL_PATH, TK_PATH are cygwin paths here
            #            tcltk_native_include_dir is native here (a Win32 path on windows)
            #            INCPATHFLAGS is native here
            #            TCLINC is native here
            #            TCLTK_LIBS, TCLLIB are native here
	    
	    PUSH_LIBS="$LIBS"
	    LIBS="$TCLLIB $LIBS"
	    
	    AC_MSG_CHECKING([for Tcl_Init() in $TCL_LIBNAME])
	    AC_TRY_LINK([],[Tcl_Init()],[TCLINIT_FOUND=yes],[TCLINIT_FOUND=no])
	    AC_MSG_RESULT($TCLINIT_FOUND)
	    
	    AC_MSG_CHECKING([for Tk_Init() in $TK_LIBNAME])
	    AC_TRY_LINK([],[Tk_Init()],[TKINIT_FOUND=yes],[TKINIT_FOUND=no])
	    AC_MSG_RESULT($TKINIT_FOUND)
	    
	    LIBS="$PUSH_LIBS"

	    if test $TCLINIT_FOUND = no || test $TKINIT_FOUND = no; then
		tcl_ok=no
	    fi
	fi
        # [PM] 3.9b2 TCLTK_PATH, TCL_PATH, TK_PATH are cygwin paths here
        #            INCPATHFLAGS is native here
        #            TCLINC is native here
        #            TCLTK_LIBS, TCLLIB are native here

        # [PM] 3.8.7 mainly for MacOS X (wrapper sets TCL/TK_LIBRARY)
        if test $tcl_ok = yes; then
           TCL_LIBRARY="$TCL_PATH/lib/tcl$TCL_VERSION"
           TK_LIBRARY="$TK_PATH/lib/tk$TK_VERSION"
        fi

	AC_MSG_CHECKING([Tcl/Tk configuration results])
	if test $user_tcltk_config = yes || test $tcl_ok = yes; then
	    : ${TCLTK_MODULE="tcltk.po"}
dnl [PM] 3.10.1 unused:	    : ${TCLTK_NOBUILD_TARGETS="tkterm.tcl tkconsol.tcl tcltk.pl"}
dnl [PM] 3.10.1 unused:	    : ${TCLTK_RTL_PATH="${TCLTK_RTL_PATH}:"}
	    # If we come here without successful Tcl/Tk link, it means that the
	    # user has specified his/her own TCLLIB and TCLINC. We let them continue,
	    # but warn them first.
	    if test $tcl_ok = no; then
		AC_MSG_RESULT([failed])
		AC_MSG_WARN([User-defined values for TCLLIB and TCLINC did not work])
	    else
		AC_MSG_RESULT([ok])
	    fi
	else
	    AC_MSG_RESULT([failed])
	fi
    fi
fi
fi dnl [PM] 3.10.1 tcltk_already_configured

dnl ============================================================
dnl ============================================================


# [PM] 3.9b2 TCLTK_PATH, TCL_PATH, TK_PATH are cygwin paths
#            here. They need to be made native before AC_SUBST.
#            The rest are already native:
#            INCPATHFLAGS is native here
#            TCLINC is native here
#            TCLTK_LIBS, TCLLIB are native here

tcltk_native_path=`$CYGPATH "$TCLTK_PATH"`
tcl_native_path=`$CYGPATH "$TCL_PATH"`
tk_native_path=`$CYGPATH "$TK_PATH"`

TCLTK_PATH=$tcltk_native_path
TCL_PATH=$tcl_native_path
TK_PATH=$tk_native_path

dnl [PM] these are in src-only part below
dnl AC_SUBST(TCLLIB)
dnl AC_SUBST(TCLINC)


AC_SUBST(TCL_LIBRARY)
AC_SUBST(TK_LIBRARY)

AC_SUBST(TCLTK_MODULE)
AC_SUBST(TCL_PATH)
AC_SUBST(TK_PATH)
AC_SUBST(TCLTK_PATH)

dnl [PD] 3.9.1 For SICStusInstaller
INSTALLER_TCLTK_VERSION=$TCLTK_VERSION
AC_SUBST(INSTALLER_TCLTK_VERSION)

dnl [PD] 3.11.1 For InstallSICStus
if test "x$TCLTK_MODULE" = "x"; then
   INSTALLER_HAS_TCLTK=no
else
   INSTALLER_HAS_TCLTK=yes
fi
AC_SUBST(INSTALLER_HAS_TCLTK)

##############################
#
# [PM] 3.9.1 Tru64 port
# If dlopen of foreign resources ignored the RPATH of the .so file but
# does use the RPATH in the exe then we should embed paths to
# third-party libraries into the executable
#
#############################

dnl [PM] 3.9.0 Tru64 5.1 port
dnl yes if the platform violates the SysV ABI by ignoring the RPATH in
dnl a dlopened.so file and instead uses the RPATH of the executable.
: ${DLOPEN_ONLY_USES_RPATH_IN_EXE=no}

AC_MSG_CHECKING([if paths to third-party libraries should be embedded in the sicstus development system])

AC_ARG_ENABLE(tp-rpaths,        [  --enable-tp-rpath          Internal use. Embed rpath to third party libraries into sicstus exe],
    [enable_tp_rpath="$enableval"],
    [enable_tp_rpath="$DLOPEN_ONLY_USES_RPATH_IN_EXE"])

AC_MSG_RESULT($enable_tp_rpath)

if test ".$TCLTK_MODULE." != ..; then
   AC_MSG_CHECKING([if paths to Tcl/Tk libraries should be embedded])
   AC_MSG_RESULT($enable_tp_rpath)
   resname=tcltk

   if test "$enable_tp_rpath" = yes; then
      if test "x$SPLD_DS_RESOURCES" = "x"; then # not yet set
         res_prefix=""
      else # separate with comma
         res_prefix=","
      fi
      SPLD_DS_RESOURCES="${SPLD_DS_RESOURCES}${res_prefix}-${resname}"
   fi
fi

if test -n "$BDB_MODULE" ; then
   AC_MSG_CHECKING([if paths to Berkeley DB libraries should be embedded])
   AC_MSG_RESULT([$enable_tp_rpath])
   resname=bdb

   if test "$enable_tp_rpath" = yes; then
      if test -z "$SPLD_DS_RESOURCES"; then # not yet set
         res_prefix=""
      else # separate with comma
         res_prefix=","
      fi
      SPLD_DS_RESOURCES="${SPLD_DS_RESOURCES}${res_prefix}-${resname}"
   fi
fi


if test "x${SPLD_DS_RESOURCES}" != "x"; then
   SPLD_DSFLAGS="$SPLD_DSFLAGS --resources=$SPLD_DS_RESOURCES"
fi
AC_MSG_CHECKING(for extra spld flags for SICStus development system)
if test "x${SPLD_DSFLAGS}" != "x"; then
   AC_MSG_RESULT(${SPLD_DSFLAGS})
else
   AC_MSG_RESULT(none)
fi
AC_SUBST(SPLD_DSFLAGS)

# [PM] 4.2 We always used this for all platforms that support
# pre-built but it did not use to be the default.
AC_MSG_CHECKING([whether spld --moveable should be the default])
: ${enable_moveable_default:=no}
AC_ARG_ENABLE(spld-moveable,        [  --enable-spld-moveable          Internal use. Make spld --moveable the default.],
    [enable_moveable"$enableval"],
    [enable_moveable="$enable_moveable_default"])
case "${enable_moveable}" in
   no)
      SPLD_OPT_MOVEABLE_DEFAULT='no'
   ;;
   yes)
      SPLD_OPT_MOVEABLE_DEFAULT='yes'
   ;;
   *)
      AC_MSG_ERROR([invalid --enable-spld-moveable option ($enable_moveable)])
   ;;
esac
AC_MSG_RESULT([$SPLD_OPT_MOVEABLE_DEFAULT])
AC_SUBST([SPLD_OPT_MOVEABLE_DEFAULT])

: ${SPLD_OPT_WRAPPER_DEFAULT="no"}
AC_SUBST(SPLD_OPT_WRAPPER_DEFAULT)
AC_MSG_CHECKING([if spld should generate wrapper script by default])
AC_MSG_RESULT($SPLD_OPT_WRAPPER_DEFAULT)

# [PM] 3.9.1 For platforms that lack SysV ORIGIN or something similar, see spld.pl.in
: ${SPLD_OPT_MOVEABLE_NEEDS_WRAPPER="no"}
AC_SUBST(SPLD_OPT_MOVEABLE_NEEDS_WRAPPER)
AC_MSG_CHECKING([if spld --moveable implies --wrapper])
AC_MSG_RESULT($SPLD_OPT_MOVEABLE_NEEDS_WRAPPER)

# [PM] 4.3 Whether spld-generated main() should set process locale from environment.
# (Ignored on Windows)
# See spld and spaux.c
SPLD_OPT_USE_LOCALE_DEFAULT=yes
AC_SUBST(SPLD_OPT_USE_LOCALE_DEFAULT)
# empty means let OS determine locale from environment
SPLD_OPT_LOCALE_NAME_DEFAULT=''
AC_SUBST(SPLD_OPT_LOCALE_NAME_DEFAULT)


dnl [PM] 3.9.1 The SP tools (sicstus, spdet, spxref) are installed in
dnl a directory that does not have a correct run-time structure. In
dnl particular they are installed in a directory that lacks a
dnl $SP_RTSYS_DIRNAME subdirectory.
dnl On some platforms this may not work unless some non-default flags
dnl are passed to spld. ([PM] 4.2 obsolete:) In particular, on MacOS X/Darwin, we must use
dnl --wrapper.
: ${SPLD_TOOLFLAGS=""}
AC_SUBST(SPLD_TOOLFLAGS)
AC_MSG_CHECKING([special spld flags for SICStus tools])
if test -n "${SPLD_TOOLFLAGS}"; then
  AC_MSG_RESULT([none])
else
  AC_MSG_RESULT([${SPLD_TOOLFLAGS}])
fi

dnl ============================================================
dnl ============================================================

dnl [PM] 3.9.1 not used
dnl AC_SUBST(FORCE_STATIC)
dnl AC_SUBST(FORCE_DYNAMIC)

: ${cc_Werror=''}
: ${cc_Wno_conversion_option=''}


AC_MSG_CHECKING([whether C compiler warnings should be fatal])
if test "x$cc_warnings_are_errors" = "xyes"; then
   AC_MSG_RESULT(yes)
   CFLAGS_EXTRA="$cc_Werror $CFLAGS_EXTRA"
else
   AC_MSG_RESULT(no)
fi

AC_MSG_CHECKING([whether implicit conversion to smaller type should generate warning])
if test "${cc_w_conversion:-no}" = "yes"; then
   AC_MSG_RESULT([yes ($cc_Wconversion_option)])
   CFLAGS_EXTRA="$cc_Wconversion_option $CFLAGS_EXTRA"
else
   AC_MSG_RESULT(no)
fi

dnl [PM] 3.10 special hack to not balk at warnings about mutex initializer
: ${EXPECT_WARNINGS_MULTI_SP_C=no}
AC_SUBST(EXPECT_WARNINGS_MULTI_SP_C)
AC_SUBST(CC_WERROR, "$cc_Werror")
AC_SUBST(CC_WNO_CONVERSION_OPTION, "$cc_Wno_conversion_option")


dnl [PM] 3.9b5 The SPLD_CONFIG_CFLAGS compiles user code so it should be
dnl            fairly standard.
dnl [PM] 3.10.1b1 now done:
dnl            We should consider just setting it to CFLAGS without
dnl            CFLAGS_EXTRA. That way we could keep -Werror etc for our
dnl            code also in release versions.

AC_MSG_CHECKING([whether spld/splfr should use a special C compiler])
AC_ARG_ENABLE(spld-cc,       [  --enable-spld-cc             C compiler to use for spld/splfr],
	[
        case "$enableval" in
        yes) # plain --enable-spld-cc
	    AC_MSG_ERROR([--enable-spld-cc requires an argument])
            ;;
        *) # compiler name/path or --disable-spld-cc
	    SPLD_CC="$enableval"
            ;;
        esac
        ], [ : ${SPLD_CC:=no}])

if test "${SPLD_CC}" = "no"; then
    SPLD_CC="${CC}"
    AC_MSG_RESULT([no (${SPLD_CC})])
else
    AC_MSG_RESULT([yes, (${SPLD_CC})])
fi

AC_MSG_CHECKING([C compiler flags for spld/splfr])
dnl [PM] 3.10.1b1 now CFLAGS_EXTRA (3.10.2 and CFLAGS_EXTRA_SEMANTICS)
dnl may contain non-standard things for release
dnl builds as well so must not be used for user code.

dnl [PM] 3.10.2 Use USER_CFLAGS instead of CFLAGS
if test "${SICSTUS_RELEASE_BUILD}" != "yes"; then
  SPLD_CONFIG_CFLAGS="$USER_CFLAGS $CFLAGS_EXTRA"
else
  SPLD_CONFIG_CFLAGS="$USER_CFLAGS"
fi

AC_MSG_RESULT([$SPLD_CONFIG_CFLAGS])

AC_MSG_CHECKING([C compiler flags])
dnl [PM] 3.10.2 important that CFLAGS_EXTRA goes last for
dnl             --enable-float-consistency (Win32)
CFLAGS="$CFLAGS $CFLAGS_EXTRA"
AC_MSG_RESULT($CFLAGS)

AC_MSG_CHECKING([extra C compiler flags for wam.c])
if test -n "${WAM_O_CFLAGS_EXTRA}"; then
  AC_MSG_RESULT([$WAM_O_CFLAGS_EXTRA])
else
  AC_MSG_RESULT([none])
fi
AC_SUBST([WAM_O_CFLAGS_EXTRA])

AC_MSG_CHECKING([C compiler flags for dynamic linking])
AC_MSG_RESULT($INCR_CFLAGS)
AC_MSG_CHECKING(linker flags)
AC_MSG_RESULT($LDFLAGS)

dnl [PM] 3.9.1 migrating from LDFLAGS to SPLD_EXE_LIBS
AC_MSG_CHECKING([LDFLAGS for spld generated executables])
AC_MSG_RESULT([$SPLD_EXE_LDFLAGS])
AC_MSG_CHECKING([LIBS for spld generated executables])
AC_MSG_RESULT([$SPLD_EXE_LIBS])

AC_MSG_CHECKING([LIBS for spld generated JNI lib])
AC_MSG_RESULT($SPLD_JNI_LIBS)

AC_MSG_CHECKING([dynamic linker])
AC_MSG_RESULT($SHLD)
AC_MSG_CHECKING([dynamic linker flags])
AC_MSG_RESULT($SHLDFLAGS)


dnl ============================================================
dnl ============================================================


AC_MSG_CHECKING([tests to skip])
dnl AC_ARG_VAR([SUITE_SKIPPED_TESTS],[])
AC_MSG_RESULT([${SUITE_SKIPPED_TESTS:-none}])
AC_SUBST([SUITE_SKIPPED_TESTS])

AC_MSG_CHECKING([tests expected to fail])
dnl AC_ARG_VAR([SUITE_EXPECTED_FAILURES],[])
AC_MSG_RESULT([${SUITE_EXPECTED_FAILURES:-none}])
AC_SUBST([SUITE_EXPECTED_FAILURES])


dnl [PM] 3.9.1 define this as, e.g., "_" if export file needs a prefix
dnl On MacOS X/darwin this is '_' for nmedit -s <expfile>
: ${EXPFILE_SYMBOL_PREFIX=''}
AC_SUBST(EXPFILE_SYMBOL_PREFIX)

dnl [PM] 3.9.1 Used by splfr to do nmedit on MacOS X/Darwin
AC_MSG_CHECKING([splfr SHLD post-processing])
: ${SPLFR_SHLD_POST_PROCESS=''}
: ${SPLFR_SHLD_POST_PROCESS_EXPFILE_OPT=''}
: ${SPLFR_SHLD_POST_PROCESS_LIB_OPT=''}
AC_SUBST(SPLFR_SHLD_POST_PROCESS)
AC_SUBST(SPLFR_SHLD_POST_PROCESS_EXPFILE_OPT)
AC_SUBST(SPLFR_SHLD_POST_PROCESS_LIB_OPT)
if test "x$SPLFR_SHLD_POST_PROCESS" = "x"; then
  AC_MSG_RESULT(none)
else
  AC_MSG_RESULT([${SPLFR_SHLD_POST_PROCESS} ${SPLFR_SHLD_POST_PROCESS_EXPFILE_OPT}<EXPFILE> ${SPLFR_SHLD_POST_PROCESS_LIB_OPT}<RESOURCE>])
fi

dnl [PM] 3.9.1 Used by splfr to do nmedit on MacOS X/Darwin
AC_MSG_CHECKING([splfr --static post-processing])
: ${SPLFR_LD_R_POST_PROCESS=''}
: ${SPLFR_LD_R_POST_PROCESS_EXPFILE_OPT=''}
: ${SPLFR_LD_R_POST_PROCESS_LIB_OPT=''}
AC_SUBST(SPLFR_LD_R_POST_PROCESS)
AC_SUBST(SPLFR_LD_R_POST_PROCESS_EXPFILE_OPT)
AC_SUBST(SPLFR_LD_R_POST_PROCESS_LIB_OPT)
if test "x$SPLFR_LD_R_POST_PROCESS" = "x"; then
  AC_MSG_RESULT(none)
else
  AC_MSG_RESULT([${SPLFR_LD_R_POST_PROCESS} ${SPLFR_LD_R_POST_PROCESS_EXPFILE_OPT}<EXPFILE> ${SPLFR_LD_R_POST_PROCESS_LIB_OPT}<RESOURCE>])
fi


dnl ============================================================
dnl ============================================================


# Variables to substitute.
AC_SUBST(CFLAGS)

dnl [PD] C# compiler (.NET)
AC_SUBST(CSC)
: ${CSCFLAGS=""}
AC_SUBST(CSCFLAGS)

dnl [PD] J# compiler (.NET)
AC_SUBST(VJC)
: ${VJCFLAGS=""}
AC_SUBST(VJCFLAGS)

dnl WinCE
: ${DT_CFLAGS=""}
AC_SUBST(DT_CFLAGS)
: ${DT_ENV_INCLUDE=''}
AC_SUBST(DT_ENV_INCLUDE)
: ${DT_ENV_LIB=''}
AC_SUBST(DT_ENV_LIB)
: ${DT_OUTPUT_OPT=''}
AC_SUBST(DT_OUTPUT_OPT)
: ${DT_CC=''}
AC_SUBST(DT_CC)
: ${DT_CC_PATH=''}
AC_SUBST(DT_CC_PATH)
: ${DT_CPPFLAGS=''}
AC_SUBST(DT_CPPFLAGS)
: ${DT_LIBS=''}
AC_SUBST(DT_LIBS)

AC_SUBST(SPLD_CONFIG_CFLAGS)
dnl [PM] 3.9.1 LDFLAGS-be-gone
dnl AC_SUBST(LDFLAGS)
AC_SUBST(SPLD_EXE_LIBS)
AC_SUBST(SPLD_JNI_LIBS)
AC_SUBST(SPLD_EXE_LDFLAGS)
: ${SPLD_EXE_EXTRA_RPATH=''}
AC_SUBST(SPLD_EXE_EXTRA_RPATH)
: ${SPLD_CC:="${CC}"}
AC_SUBST([SPLD_CC])

dnl [PM] 3.9.1 SPLM_LIBS is only used on Win32 for the C based splm
AC_SUBST(SPLM_LIBS)

: ${SPLFR_LD_r_FLAGS=""}
AC_SUBST(SPLFR_LD_r_FLAGS)

AC_SUBST(INCR_CFLAGS)
AC_SUBST(SHLD)
AC_SUBST(SHLDFLAGS)
AC_SUBST(MAPFILEOPT)
: ${RTKERNEL_EXPFILE=""}
AC_SUBST(RTKERNEL_EXPFILE)
AC_SUBST(NMEDIT)

AC_SUBST(SHSFX)
AC_SUBST(FLI_SHSFX)
AC_SUBST(JNI_SHSFX)
AC_SUBST(STSFX)
dnl [PM] 4.1.3+ gone
dnl AC_SUBST(FLI_SHARED_PRELINKS)
AC_SUBST(LN)
: ${ARFLAGS=""}
AC_SUBST(ARFLAGS)
AC_SUBST(M4_FLAGS)
AC_SUBST(PLFLAGS)
AC_SUBST(SYSTEMLIB)
AC_SUBST(SOCKETLIB)
AC_SUBST(COMCLIENTLIB)
dnl AC_SUBST(DBLIB)
dnl AC_SUBST(DB_MODULE)
AC_SUBST(TCLLIB)
AC_SUBST(TCLINC)
AC_SUBST(JAVALIB)
AC_SUBST(JAVAINC)
AC_SUBST(JAVACDBGFLAGS)
AC_SUBST(JAVA_CLASSPATH)
AC_SUBST(CC_NOLIBPATH)


AC_SUBST(MKDIR)

dnl [PM] 3.8.6/3.9 not used (or at least not set) (for a long time)
dnl AC_SUBST(SP_BIN)
dnl AC_SUBST(SP_LIB)
dnl AC_SUBST(SP_DIR)
dnl AC_SUBST(SP_INC)
dnl AC_SUBST(SP_LFLAGS)

AC_SUBST(MKAUTOGEN)
AC_SUBST(SLEEP)

AC_SUBST(OLDSICSTUS)
AC_SUBST(WAMFILTER)

dnl AC_SUBST(RTKERNEL)
AC_SUBST(RTKERNEL_BASENAME_SANS_SUFFIX)
AC_SUBST(RTKERNEL_BASENAME_WITH_DSO_SUFFIX)
AC_SUBST(RTKERNEL_BASENAME_WITH_STAT_SUFFIX)
dnl AC_SUBST(DSEXT)
AC_SUBST(CODETYPE)
AC_SUBST(PARMAKE)

dnl the version parts are also #defines
AC_SUBST(SICSTUS_MAJOR_VERSION)
AC_SUBST(SICSTUS_MINOR_VERSION)
AC_SUBST(SICSTUS_REVISION_VERSION)
AC_SUBST(SICSTUS_BETA_VERSION)
AC_SUBST(SICSTUS_MICRO_VERSION)
AC_SUBST(SICSTUS_BUILD_VERSION)

AC_SUBST(X_CFLAGS)
AC_SUBST(X_LIBS)
AC_SUBST(X_PRE_LIBS)
AC_SUBST(X_EXTRA_LIBS)

dnl ============================================================
dnl ============================================================

dnl NOTE!! The following lines are uncommented in binary installers
dnl        
dnl ============================================================

dnl [PM] 4.2 now generated on demand
dnl     spld.config_tmp:spld.config.in \
dnl     splm \
dnl     spld.pl:spld_prefix.pl.in:spld_suffix.pl \
dnl     splfr.pl:spld_prefix.pl.in:splfr_suffix.pl \
dnl     distrib \

AC_CONFIG_FILES([\
Common \
])
AC_OUTPUT

dnl ============================================================
