AC_REVISION("$Id: 1aa817aed558f1ad8abc47f3a20873e6772b346e $")
AC_INIT(interpret.c)
AC_CONFIG_HEADER(machine.h)

rm -f config.warnings 2>/dev/null

if_autoconf(2,50,[
  if test "x$cache_file" = "x/dev/null"; then
    cache_file=./config.cache
    if test -r "$cache_file"; then
      echo "loading cache $cache_file"
      . $cache_file
    else
      echo "creating cache $cache_file"
      > $cache_file
    fi
  fi
], [
  PIKE_MSG_WARN([configure script has been generated with autoconf 2.13 or earlier.])
])

# We want an absolute path to the source-dir.
case "$srcdir" in
    /*)
    ;;
    *)
	oldsrcdir="$srcdir"
	srcdir="`cd \"$srcdir\";pwd`"
	AC_MSG_WARN([Converted $oldsrcdir to $srcdir,
If this does not work, please use an absolute path to the configure script.])
    ;;
esac

# Check that we can write to the source directory.
sleep 1
if touch "$srcdir/configure~"; then
  # Check that the system time is reasonably correct.
  if test `cd "$srcdir" && ls -1t configure configure~ | head -n 1` = "configure"; then
    echo "Current system time is `date`."
    AC_MSG_ERROR([
$srcdir/configure has modification time in the future.
Check and set your system time.
])
  fi
else
  ls -ld "$srcdir"
  AC_MSG_ERROR([
Failed to write in source directory.
Fix your permissions.
])
fi

# Attempt to use bash instead of /bin/sh to run configure
# since bash is usually several orders of magnitude faster
# on machines that have a real /bin/sh.
# Some OS's also have a seriously broken /bin/sh (eg NetBSD).
if test "x$CONFIG_SHELL" = "x" -a "x$BASH" = x; then
  AC_PATH_PROG(bash_prog, bash, no)
  if test "x$ac_cv_path_bash_prog" = "xno"; then :; else
    AC_MSG_CHECKING([if $ac_cv_path_bash_prog works])
    if "$ac_cv_path_bash_prog" --norc -c : 2>&AC_FD_CC; then
      AC_MSG_RESULT(yes)
    else
      AC_MSG_RESULT(no)
      ac_cv_path_bash_prog=no
    fi
  fi
  if test "x$ac_cv_path_bash_prog" = "xno"; then :; else
    AC_MSG_WARN([Found bash as $ac_cv_path_bash_prog.
Will attempt to restart configure with bash for performance.
If this fails, please set CONFIG_SHELL to /bin/sh before starting configure.])
    CONFIG_SHELL="$ac_cv_path_bash_prog --norc"
    export CONFIG_SHELL
    echo $CONFIG_SHELL "$srcdir/configure" $ac_configure_args
    eval exec $CONFIG_SHELL "$srcdir/configure" $ac_configure_args
    exit 17
  fi
else :; fi

AC_PROG_MAKE_SET


rm -f "conftest_VPATH.in" 2>/dev/null
touch "$srcdir/conftest_VPATH.in"
if test -f conftest_VPATH.in; then :; else
  # Not building in source tree.
  AC_MSG_CHECKING([whether ${MAKE-make} supports VPATH])
  AC_CACHE_VAL(pike_cv_make_supports_VPATH, [
    cat > conftestmake <<EOF
VPATH=.:$srcdir
.SUFFIXES: .in .out
.in.out:
	cat "\$<" >"\$@"
EOF
    pike_cv_make_supports_VPATH=no
    if ${MAKE-make} -f conftestmake conftest_VPATH.out >/dev/null 2>&AC_FD_CC; then
      if test -f conftest_VPATH.out; then
        pike_cv_make_supports_VPATH=yes
      else :; fi
    else :; fi
    rm -f conftestmake conftest_VPATH.out
  ])
  AC_MSG_RESULT($pike_cv_make_supports_VPATH)
  if test "x$pike_cv_make_supports_VPATH" = "xno"; then
    AC_ERROR([
Building in a separate directory is not supported without VPATH.

Build in the source directory, or try another make (eg gnumake).
])
    exit 1
  else :; fi
fi
rm -f "$srcdir/conftest_VPATH.in" 2>/dev/null

if test -d "$srcdir/../bundles"; then
  # Some of the bundled libraries (eg nettle) set SHELL.
  AC_MSG_CHECKING([whether ${MAKE-make} supports spaces in SHELL])
  AC_CACHE_VAL(pike_cv_make_supports_spaces_in_SHELL, [
    cat > conftestmake <<EOF
SHELL=/bin/sh -n
false:
	/bin/false
true:
	:
complex_false:
	test "foo" = "foo" && /bin/false
complex_true:
	test "foo" = "bar" || :
EOF
    if ${MAKE-make} -f conftestmake false >&AC_FD_CC 2>&AC_FD_CC; then
      # /bin/sh was found, and /bin/false was not executed.
      pike_cv_make_supports_spaces_in_SHELL=yes
    elif ${MAKE-make} -f conftestmake complex_false >&AC_FD_CC 2>&AC_FD_CC; then
      # SHELL is ignored for simple targets, but not for more
      # complex expressions.
      # When SHELL is used, spaces are supported.
      pike_cv_make_supports_spaces_in_SHELL="complex only"
    elif ${MAKE-make} -f conftestmake complex_true >&AC_FD_CC 2>&AC_FD_CC; then
      # SHELL is ignored for all targets.
      pike_cv_make_supports_spaces_in_SHELL=ignored
    elif ${MAKE-make} -f conftestmake true >&AC_FD_CC 2>&AC_FD_CC; then
      # SHELL is ignored for simple targets, but not for more
      # complex expressions.
      # When SHELL is used, spaces are not supported.
      pike_cv_make_supports_spaces_in_SHELL=no
    else
      # Spaces are not supported in SHELL.
      pike_cv_make_supports_spaces_in_SHELL=no
    fi
    rm -f conftestmake
  ])
  AC_MSG_RESULT($pike_cv_make_supports_spaces_in_SHELL)
else :; fi

AC_ARG_ENABLE(pikelib, MY_DESCR([--enable-pikelib],
   [build pike as a library]),
	     [enable_pikelib=yes], [enable_pikelib=no])

if test "x$enable_pikelib" != "xno"; then
   PIKE_MSG_WARN([BUILDING PIKE AS A LIBRARY -- HIGHLY EXPERIMENTAL!])
   AC_DEFINE(LIBPIKE)
fi

AC_ARG_ENABLE(make_conf, MY_DESCR([--disable-make.conf],
   [do not use settings from /etc/make.conf]),
             [], [enable_make_conf=yes])

initial_cflags="${CFLAGS}"
initial_cppflags="${CPPFLAGS}"
initial_ldflags="${LDFLAGS}"

if test "x${CFLAGS-}" = x ; then
  cflags_is_set=no
else
  cflags_is_set=yes
fi

if test "x${CPPFLAGS-}" = x ; then
  cppflags_is_set=no
else
  cppflags_is_set=yes
fi

if test "x${LDFLAGS-}" = x ; then
  ldflags_is_set=no
else
  ldflags_is_set=yes
fi

# if test "x$enable_make_conf" = x"yes" -a -f /etc/make.conf; then
#   set >conftest.tmp
#   echo Using settings from /etc/make.conf...
#   . /etc/make.conf
#   set | diff -u conftest.tmp -  | grep '^+C'
#   PIKE_MSG_WARN([Using settings from /etc/make.conf.])
# fi

AC_ARG_WITH(cflags, MY_DESCR([--with-cflags=cflags],
			     [specify extra c compiler flags]),
	    [ CFLAGS="$with_cflags $CFLAGS" ])
AC_ARG_WITH(cppflags, MY_DESCR([--with-cppflags=cppflags],
			       [specify extra c preprocessor flags]),
	    [ CPPFLAGS="$with_cppflags $CPPFLAGS" ])
AC_ARG_WITH(ldflags, MY_DESCR([--with-ldflags=ldflags],
			      [specify extra linker flags]),
	    [ LDFLAGS="$with_ldflags $LDFLAGS" ])

# Force use of thread libs LIBS
AC_ARG_WITH(thread-library,
	    MY_DESCR([--with-thread-library=lib],
		     [Use a specific thread library]),
	    [
	      case "x$withval" in
	        x-*)
		  with_thread_library="$withval"
		;;
		*)
		  with_thread_library="-l$withval"
		;;
	      esac
	    ], [ with_thread_library=no ])

for ac_site_file in $CONFIG_SITE; do
  if test -r "$ac_site_file"; then
    PIKE_MSG_WARN([You are using a site file to initialize configure, please
note that this can lead to problems if anything in
$ac_site_file is not correct. If Pike does not compile, or
does not run, please try this to compile Pike again:
rm -f ./config.cache ; CONFIG_SITE=x ./configure ; make])
  fi
done

AC_ARG_ENABLE(binary, MY_DESCR([--disable-binary],
   [do not configure for binary build, only do tests for precompilation stuff]),
	      [], [enable_binary=yes])

if test "x$enable_binary" = "xno"; then
  PIKE_MSG_WARN([Short-circuiting configure tests for binary building. Only some
targets in the Makefile can be used, typically those that only
operates on the source directory, e.g. depend.])
  AC_DEFINE(DISABLE_BINARY)
else

  if test ! -z "$pike_cv_prog_CC_save" -a ! -z "$CC" -a "$CC" != "$pike_cv_prog_CC_save"
  then
    PIKE_MSG_WARN([CC is different than last time Pike was compiled,
It is probably best to delete ./config.cache before proceeding.])
  fi

  pike_cv_prog_CC_save="$CC"

fi

AC_ARG_ENABLE(noopt-retry, MY_DESCR([--disable-noopty-retry],
    [do not retry compilation without optimizations if it fails]),
	      [], [noopt_retry=yes])

# Do the below even when --disable-binary is used, since we need a
# real $CPP, and AC_PROG_CPP wants AC_PROG_CC to be called earlier.
# $CC will be overridden with a dummy later on.

# MY_AC_PROG_CC
# The above has problems if the smartlink binary is removed. /grubba

AC_LANG_C

# Workaround for COMPILER_EXEEXT bailing out with icc and too new gcc.
# "Command-line error: invalid GNU version number: 403".
# The following seem to be the max gcc-versions:
#
#   icc   gcc-version
#   8.1     340
#   9.0     400?
#   9.1     410?
if test "x$CC" = "x"; then :; else
  AC_MSG_CHECKING([whether we need an icc workaround])
  AC_CACHE_VAL(pike_cv_need_icc_gcc_version, [
cat >conftest.c <<EOF
  int main() { return 0; }
EOF
    ORIG_CFLAGS="$CFLAGS"
    for pike_cv_need_icc_gcc_version in no 420 410 400 340 330 320 310 no; do
      if test "x$pike_cv_need_icc_gcc_version" = "xno"; then :; else
        CFLAGS="$ORIG_CFLAGS -gcc-version=$pike_cv_need_icc_gcc_version"
      fi
      if AC_TRY_EVAL(ac_compile); then
        break;
      fi
    done
    CFLAGS="$ORIG_CFLAGS"
  ])
  AC_MSG_RESULT($pike_cv_need_icc_gcc_version)
  if test "x$pike_cv_need_icc_gcc_version" = "xno"; then :; else
    CFLAGS="$CFLAGS -gcc-version=$pike_cv_need_icc_gcc_version"
  fi
fi

# AC_PROG_CC won't modify CFLAGS if it's already set from the icc
# workaround test above, so we make sure it's always set and then
# modify CFLAGS ourselves afterwards.
: ${CFLAGS:=}

AC_PROG_CC
AC_PROG_CXX

# Only need to think of -g since -O2 or other optimization flags gets
# added through other configure tests.
test "$ac_cv_prog_cc_g" = yes && CFLAGS="-g $CFLAGS"

AC_PROG_CPP
AC_PROG_EGREP

AC_MSG_CHECKING([whether we are using Intel C])
AC_CACHE_VAL(pike_cv_prog_icc, [
  AC_EGREP_CPP([oui], [
#if defined(__ECC) || defined(__ICC) || defined(__INTEL_COMPILER)
  oui;
#endif
  ], pike_cv_prog_icc=yes, pike_cv_prog_icc=no)
])
AC_MSG_RESULT($pike_cv_prog_icc)
if test "$pike_cv_prog_icc" = "yes"; then
  ICC=yes
fi

# This segment is disabled for now.
if :; then :; else
AC_MSG_CHECKING([for option to enter C99-mode])
AC_CACHE_VAL(pike_cv_flag_c99, [
  ORIG_CPPFLAGS="$CPPFLAGS"
  for pike_cv_flag_c99 in '' '-std=gnu99' '-std=gnu9x' '-xc99' no; do
    if test "x$pike_cv_flag_c99" = "xno"; then break; fi
    # C99 is supported only in XPG6/POSIX.1-2001.
    pike_cv_flag_c99="$pike_cv_flag_c99 -D_GNU_SOURCE -D_XOPEN_SOURCE=600 -DPOSIX_C_SOURCE=200112"
    CPPFLAGS="$ORIG_CPPFLAGS $pike_cv_flag_c99"
    AC_EGREP_CPP([oui], [
/* Include THE standard header file to check for C99 compliance. */
#include <stdio.h>
#if __STDC_VERSION__ - 0 >= 199901
    oui
#endif
    ], [
      # Ok.
      break;
    ])
  done
  ORIG_CPPFLAGS="$CPPFLAGS"
])
if test "x$pike_cv_flag_c99" = "xno"; then
  AC_MSG_RESULT(not supported)
  AC_MSG_CHECKING([for level of XPG support])
  AC_CACHE_VAL(pike_cv_flag_xpg, [
    # FIXME: How determine what the max level of XPG support is?
    :;
  ])
  AC_MSG_RESULT([$pike_cv_flag_xpg])
else
  AC_MSG_RESULT([${pike_cv_flag_c99:-(none)}])
  CPPFLAGS="$CPPFLAGS $pike_cv_flag_c99"
fi
fi

#############################################################################

if test "x$enable_binary" != "xno"; then
  AC_ISC_POSIX
  AC_AIX
  AC_MINIX
fi
 
#############################################################################

# ABI selection.

PIKE_SELECT_ABI

#############################################################################

if test "x$GCC" = "x"; then
  GCC=no
else
  :;
fi

if test "x$GCC" = "xno" -a "x$TCC" = "xno"; then

  if test "x$ac_cv_prog_cc_cross" = "xyes"; then
    # The AIX 5L/cc beta can not generate working binaries without a
    # data-segment...
    AC_MSG_CHECKING([if we are really using a cross-compiler])

    AC_CACHE_VAL(pike_cv_datasegment_required, [
      ac_cv_prog_cc_cross=no;
      AC_TRY_RUN([int foo;main(){return(0);}], [
        pike_cv_datasegment_required=yes
      ], [
        pike_cv_datasegment_required=no
	ac_cv_prog_cc_cross=yes
      ], [
        pike_cv_datasegment_required=no
	ac_cv_prog_cc_cross=yes
      ])
    ])
    if test "x$pike_cv_datasegment_required" = "xyes"; then
      AC_MSG_RESULT([no -- Applying data-segment kludge])
      ac_cv_prog_cc_cross=no
      cat >conftest.c <<EOF
static int foo;
EOF
      pike_cv_datasegemnt_file=no
      if AC_TRY_EVAL(ac_compile); then
        if test -f "conftest.$ac_objext"; then
	  rm -f "data-segment.$ac_objext"
	  if mv "conftest.$ac_objext" "data-segment.$ac_objext"; then
	    if test -f "`pwd`/data-segment.$ac_objext"; then
	      pike_cv_datasegemnt_file="`pwd`/data-segment.$ac_objext"
	    else
	      PIKE_MSG_WARN(Lost track of data-segment kludge-file.)
	    fi
	  else
	    PIKE_MSG_WARN(Failed to rename data-segment kludge-file.)
	  fi
	else
	  PIKE_MSG_WARN(Can not find data-segment kludgefile.)
	fi
      else
        PIKE_MSG_WARN(Failed to compile data-segment kludge.)
      fi
      if test "x$pike_cv_datasegment_file" = "xno"; then
	PIKE_MSG_WARN(Some tests may yield false results.)
      else
        LIBS="$pike_cv_datasegment_file $LIBS"
	export LIBS
        PIKE_MSG_WARN(Data-segment kludge applied.)
      fi
    else
      AC_MSG_RESULT(yes)
    fi
  fi
elif test "x$TCC" = "xyes"; then
  AC_MSG_CHECKING(if we can use pragma TenDRA longlong)
  AC_CACHE_VAL(pike_cv_pragma_tendra_longlong, [
    AC_TRY_COMPILE([
#pragma TenDRA longlong type allow
    ], [], [ pike_cv_pragma_tendra_longlong=yes
    ], [ pike_cv_pragma_tendra_longlong=no ])
  ])
  if test "x$pike_cv_pragma_tendra_longlong" = "xyes"; then
    AC_MSG_RESULT(yes)
    AC_DEFINE(HAVE_PRAGMA_TENDRA_LONGLONG)
  else
    AC_MSG_RESULT(no)
  fi

  AC_MSG_CHECKING(if we can use pragma TenDRA set longlong type)
  AC_CACHE_VAL(pike_cv_pragma_tendra_set_longlong_type, [
    AC_TRY_COMPILE([
#ifdef HAVE_TENDRA_LONGLONG
#pragma TenDRA longlong type allow
#endif /* HAVE_TENDRA_LONGLONG */
#pragma TenDRA set longlong type : long long

long long foo;
    ], [], [ pike_cv_pragma_tendra_set_longlong_type=yes
    ], [ pike_cv_pragma_tendra_set_longlong_type=no ])
  ])
  if test "x$pike_cv_pragma_tendra_set_longlong_type" = "xyes"; then
    AC_MSG_RESULT(yes)
    AC_DEFINE(HAVE_PRAGMA_TENDRA_SET_LONGLONG_TYPE)
  else
    AC_MSG_RESULT(no)
  fi
else :; fi

#############################################################################

if test "x$enable_binary" != "xno"; then

#
# The purpose of this test is to check that there is no filesystem
# caching preventing pike from compiling correctly.
#
AC_MSG_CHECKING([filesystem synchronization])

AC_CACHE_VAL(pike_cv_filesystem_syncronization,
[
  pike_cv_filesystem_syncronization=working

  AC_EGREP_CPP(true, [ true ], , pike_cv_filesystem_syncronization=broken)
  AC_EGREP_CPP(false, [ false ], , pike_cv_filesystem_syncronization=broken)
  AC_EGREP_CPP(oui, [ oui ], , pike_cv_filesystem_syncronization=broken)
  AC_EGREP_CPP(no, [ no ], , pike_cv_filesystem_syncronization=broken)
  AC_EGREP_CPP(near, [ far ], pike_cv_filesystem_syncronization=broken, )
  AC_EGREP_CPP(up, [ up ], , pike_cv_filesystem_syncronization=broken)
  AC_EGREP_CPP(down, [ down], , pike_cv_filesystem_syncronization=broken)
])

AC_MSG_RESULT($pike_cv_filesystem_syncronization)
if test "x$pike_cv_filesystem_syncronization" = xbroken ; then
  AC_MSG_ERROR([Filesystem caching is too aggressive. If you are using
Samba, make sure to have the following line in your smb.conf:
oplocks = False
])
  exit 1
fi

fi

#############################################################################

LIBDIR=`(cd $srcdir/../lib ; pwd)`
BINDIR=`(cd $srcdir/../bin ; pwd)`
MANDIR=`(cd $srcdir/../man ; pwd)`
DOCDIR=`(cd $srcdir/../refdoc ; pwd)`
BASEDIR=`(cd $srcdir/.. ; pwd)`
BUILDDIR=`pwd`
AC_SUBST(LIBDIR)
AC_SUBST(BINDIR)
AC_SUBST(MANDIR)
AC_SUBST(DOCDIR)
AC_SUBST(BASEDIR)
AC_SUBST(BUILDDIR)

#############################################################################

#
# Some cross-compilation support and --disable-binary stuff
#

if test "x$enable_binary" = "xno"; then
  CROSS=yes
else
  CROSS="$ac_cv_prog_cc_cross"
fi
AC_SUBST(CROSS)

if test "x$enable_binary" = "xno"; then
  CC="$BINDIR/nobinary_dummy cc"
  RUNPIKE="USE_PIKE"
  RUNTPIKE="USE_PIKE"
elif test "x$cross_compiling" = "xyes"; then
  RUNPIKE="DEFAULT_RUNPIKE"
  RUNTPIKE="USE_PIKE"
else
  RUNPIKE="DEFAULT_RUNPIKE"
  RUNTPIKE="USE_TPIKE"
fi
AC_SUBST(RUNPIKE)
AC_SUBST(RUNTPIKE)

#############################################################################
if test "x$enable_binary" != "xno"; then
# The following tests are only relevant if we intend to build binaries.
#############################################################################

AC_CHECK_HEADERS(fnord/fnord/fnord.h)

AC_MSG_CHECKING([if CHECK_HEADERS works])
if test "x$ac_cv_header_fnord_fnord_fnord_h" = xyes ; then
  AC_MSG_RESULT(no)
  exit 1
fi
AC_MSG_RESULT(yes)

#############################################################################

AC_MSG_CHECKING(if we can allocate large auto variables)
AC_CACHE_VAL(pike_cv_C_supports_large_auto, [
  AC_TRY_LINK([
#include <stdio.h>
    int eat_stack(int foo)
    {
      char large_array[131072] = "";
      int i, sum = 0;

      for (i = 0; i < foo; i++) {
        /* Make sure the compiler does not optimize away the array. */
	large_array[i] = sum;
	sum += foo;
      }
      for (i = 0; i < foo; i++) {
        sum += large_array[i] - large_array[foo-1-i];
      }
      return sum;
    }
  ], [
    return !eat_stack(4711);
  ], [
    pike_cv_C_supports_large_auto=yes
  ], [
    pike_cv_C_supports_large_auto=no
  ])
])
if test "$pike_cv_C_supports_large_auto" = "yes"; then
  AC_MSG_RESULT([yes - good])
else
  AC_MSG_RESULT([no])
  AC_MSG_CHECKING([if we can make a workaround by defining _chkstk to call __chkstk])
  AC_CACHE_VAL([pike_cv_kludge__chkstk],
  [
    AC_TRY_LINK([
#include <stdio.h>
      int eat_stack(int foo)
      {
  	char large_array[131072] = "";
  	int i, sum = 0;
  
  	for (i = 0; i < foo; i++) {
  	  /* Make sure the compiler does not optimize away the array. */
  	  large_array[i] = sum;
  	  sum += foo;
  	}
  	for (i = 0; i < foo; i++) {
  	  sum += large_array[i] - large_array[foo-1-i];
  	}
  	return sum;
      }
  
      extern size_t __chkstk();
      size_t _chkstk() { return __chkstk(); }
  
    ], [
      return !eat_stack(4711);
    ], [
      pike_cv_kludge__chkstk=yes
    ], [
      pike_cv_kludge__chkstk=no
    ])
  ])
  if test "$pike_cv_kludge__chkstk" = "yes"; then
    AC_MSG_RESULT([yes - applying workaround])
    AC_DEFINE(HAVE_BROKEN_CHKSTK)
  else
    AC_MSG_RESULT([no])
    AC_ERROR([Your C compiler does not link code that uses large auto variables.

Please check config.log, and fix the problem.])
    exit 1
  fi  
fi

#############################################################################

## Build smartlink
AC_ARG_ENABLE(smartlink_binary, MY_DESCR([--disable-smartlink-binary],
              [do not build and use the smartlink binary]),
	      [if test "x$enableval" = "xno"; then
                 force_smartlink_script_only=yes
               fi])

if test -x /usr/bin/uname 2>/dev/null; then
  UNAME=`/usr/bin/uname -sr`
elif test -x /bin/uname 2>/dev/null; then
  UNAME=`/bin/uname -sr`
else
  UNAME=unknown
fi

# We need some special hacks when running slowaris
AC_PATH_PROG(uname_prog,uname,no)
AC_MSG_CHECKING(operating system)
AC_CACHE_VAL(pike_cv_sys_os,
[
if test "$cross_compiling" = "yes"; then
  case "$host_alias" in
    *amigaos*)	pike_cv_sys_os="AmigaOS";;
    *linux*)	pike_cv_sys_os="Linux";;
    *solaris*)	pike_cv_sys_os="Solaris";;
    *sunos*)	pike_cv_sys_os="SunOS";;
    *windows*)	pike_cv_sys_os="Windows_NT";;
    *mingw*|*MINGW*)
		pike_cv_sys_os="Windows_NT"
		pike_cv_is_mingw="yes";;
    *)		pike_cv_sys_os="Unknown";;
  esac
elif test "$uname_prog" != "no"; then
  # uname on UNICOS doesn't work like other people's uname...
  if getconf CRAY_RELEASE >/dev/null 2>&1; then
    pike_cv_sys_os="UNICOS"
  else
    pike_cv_sys_os="`uname`"
  fi

  case "$pike_cv_sys_os" in
    SunOS)
      case "`uname -r`" in
        5.*) pike_cv_sys_os="Solaris" ;;
      esac
    ;;
    Monterey64)
      # According to the release notes, the string "Monterey64"
      # will be changed to "AIX" in the final release.
      # (Monterey 64 is also known as AIX 5L).
      pike_cv_sys_os="AIX"
    ;;
    *Windows*|*windows*)
      pike_cv_sys_os="Windows_NT"
    ;;
    *MINGW*|*mingw*)
      pike_cv_is_mingw="yes"
      pike_cv_sys_os="Windows_NT"
    ;;

  esac
else
  pike_cv_sys_os="Not Solaris"
fi
])
AC_MSG_RESULT($pike_cv_sys_os)

if test "x$pike_cv_sys_os" = xWindows_NT; then
  PIKE_FUNCS_NEED_DECLS(yes)
fi

AC_CHECK_HEADERS(stdlib.h string.h unistd.h sys/stat.h sys/types.h sys/errno.h)

if test "$GCC" = "yes"; then :; else
#
# Special hack for HP-UX stupid cc
#
  if test "$pike_cv_sys_os" = "HP-UX"; then
    AC_TRY_COMPILE([int foo(int bar);],[],[],
    [
      OLD_CC="${CC-cc}"
      OLD_CFLAGS="$CFLAGS"
      case "/$CC" in
        */smartlink\ cc)
           if test -x /usr/bin/cc; then
	     CC="`echo $CC|sed -e 's/ cc/ \/usr\/bin\/cc/'`"
           else
             : ;
           fi
        ;;
      esac
      CFLAGS="-Ae +Olibcalls $CFLAGS"
      AC_TRY_COMPILE([int foo(int bar);],[],[],[
        CC="$OLD_CC"
	CFLAGS="$OLD_CFLAGS"
      ])
      pike_cv_prog_CC="${CC}"
    ])
  fi
fi

if test "$pike_cv_sys_os" = "Solaris" ; then
  AC_DEFINE(SOLARIS)
else
  :
fi

# Workaround for compiling Pike on some OS that have some clues
case "$pike_cv_sys_os" in
   CYGWIN*)
      # Cygwin has both Windows includes and Unix ones.
      # Hiding them makes it a somewhat Unix compliant OS.
      echo 'Cygwin host detected. Enabling workarounds...'
      # winsock.h, winbase.h, winsock2.h, windows.h, wingdi.h, windef.h
      # are part of VC api but given as headers in cygwin. We
      # should not detect them when using cygwin
      ac_cv_header_wingdi_h="no"
      ac_cv_header_windef_h="no"
      ac_cv_header_winsock_h="no"
      ac_cv_header_winsock2_h="no"
      ac_cv_header_winbase_h="no"
      ac_cv_header_windows_h="no"
      with_machine_code="no"
   ;;
  Windows_NT)
   if test "$pike_cv_is_mingw" = "yes"; then
     #with_machine_code="no"
     ac_cv_func_fpclass="no"
   fi
   ;;
  FreeBSD*)
      # FreeBSD has different naming convention for gtk-config and sdl-config
      if test "x${GTK_CONFIG}" = "x"; then
         GTK_CONFIG=`which ${ac_tool_prefix}gtk12-config`
         export GTK_CONFIG
      fi
      if test "x${SDL_CONFIG}" = "x"; then
         SDL_CONFIG=`which ${ac_tool_prefix}sdl11-config`
	 export SDL_CONFIG
      fi
   ;;
esac

# Skip if user does not wish to use smartlink binary.
if test "x$force_smartlink_script_only" = "x"; then
# Strip smartlink from $CC
REALCC="`echo $CC|sed -e 's/.*smartlink //'`"


# FIXME: Add proper tests
AC_MSG_CHECKING([for ld.so run path method])
AC_CACHE_VAL(pike_cv_ld_so_run_path_method, [
  case "$UNAME" in
    OSF1\ V4.*|OSF1\ V5.*|OSF1\ V6.*)
      pike_cv_run_path_method=rpath
    ;;
    HPUX\ 11.*)
      pike_cv_run_path_method=plus_b
    ;;
    IRIX\ 6.*)
      pike_cv_run_path_method=rpath
    ;;
    IRIX\ 5.*)
      pike_cv_run_path_method=rpath
    ;;
    SunOS\ 5.*)
      if test "$TCC" = "yes"; then
  	# tcc doesn't know about -R
        pike_cv_run_path_method=wl_r
      else
        pike_cv_run_path_method=r
      fi
    ;;
    Linux\ 2.* | GNU/kFreeBSD* )
      if test "$ICC" = "yes"; then
        # icc or ecc.
        pike_cv_run_path_method=qoption
      else
        pike_cv_run_path_method=wl
      fi
    ;;
    UnixWare\ 7.*|OpenUNIX\ 8.*)
      if test "$ac_cv_prog_gcc" = "yes"; then
        pike_cv_run_path_method=xlinker_yp_
      else
        pike_cv_run_path_method=yp_
      fi
    ;;
    *)
      pike_cv_run_path_method=ld_library_path
    ;;
  esac
])
case "$pike_cv_run_path_method" in
  rpath)
    AC_DEFINE(USE_RPATH)
    AC_MSG_RESULT([use -rpath])
  ;;
  plus_b)
    AC_DEFINE(USE_PLUS_b)
    AC_MSG_RESULT([use +b])
  ;;
  yp_)
    AC_DEFINE(USE_YP_)
    AC_MSG_RESULT([use -Yp,])
  ;;
  xlinker_yp_)
    AC_DEFINE(USE_XLINKER_YP_)
    AC_MSG_RESULT([use -Xlinker -Yp, -Xlinker])
  ;;
  wl_r)
    AC_DEFINE(USE_Wl_R)
    AC_MSG_RESULT([use -Wl,-R])
  ;;
  r)
    AC_DEFINE(USE_R)
    AC_MSG_RESULT([use -R])
  ;;
  wl)
    AC_DEFINE(USE_Wl)
    AC_MSG_RESULT([use -Wl,-rpath])
  ;;
  qoption)
    AC_DEFINE(USE_Qoption)
    AC_MSG_RESULT([use -Qoption,ld,-rpath])
  ;;
  ld_library_path|*)
    AC_DEFINE(USE_LD_LIBRARY_PATH)
    AC_MSG_RESULT([use LD_LIBRARY_PATH/LD_RUN_PATH])
  ;;
esac

# Smartlink needs to know if OS X uses flat or two-level namespace
if test "$pike_cv_sys_os" = "Darwin" ; then
  AC_MSG_CHECKING([for Darwin linker namespace])
  case "`uname -r`" in
    [1-6].*)
      AC_MSG_RESULT([flat (10.2 or older)])
      pike_cv_osx_twolevel_namespace=no
    ;;
    *)
      AC_DEFINE(USE_OSX_TWOLEVEL_NAMESPACE)
      AC_MSG_RESULT([two-level (10.3 or newer)])
      pike_cv_osx_twolevel_namespace=yes
    ;;
  esac
fi


# Fix a smartlink
SMARTLINK="$BUILDDIR/smartlink"

AC_MSG_CHECKING(if $SMARTLINK exists is up to date and works)
if ls -1tr "$SMARTLINK${ac_exeext}" "$srcdir/smartlink.$ac_ext" 2>/dev/null | head -n 1 | grep "smartlink.$ac_ext" >/dev/null 2>&AC_FD_CC && "$SMARTLINK" -v >/dev/null 2>&AC_FD_CC; then
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
  SMARTBUILDCC="${REALCC-cc}"

  if echo foo "$CC" | egrep 'rntc.|rnt.cl' >/dev/null; then
    PIKE_MSG_WARN([rntcc/rntcl/rnticl/rntecl detected.])
    AC_PATH_PROGS(SMARTBUILDCC,gcc cc egcs,gcc, $PATH:$EXTRA_PATH)
    echo Using $SMARTBUILDCC to compile smartlink.
  elif test "x$ac_cv_prog_cc_cross" = "xyes"; then
    PIKE_MSG_WARN([Crosscompiler detected.])
    AC_PATH_PROGS(SMARTBUILDCC, gcc cc egcs, gcc, /usr/bin:/bin/:/usr/ccs/bin:/usr/local/bin:/usr/sfw/bin:/opt/sfw/bin:/opt/csw/bin:$PATH:$EXTRA_PATH)
    echo Using $SMARTBUILDCC to compile smartlink.
  fi

  rm -f "$SMARTLINK"

  AC_MSG_CHECKING(whether smartlink compiles)

  link_cmd='${SMARTBUILDCC-cc} -o smartlink${ac_exeext} $CFLAGS -I. $CPPFLAGS $LDFLAGS $srcdir/smartlink.$ac_ext $LIBS 2>&AC_FD_CC'
  if { (eval echo Compiling smartlink: \"$link_cmd\") 1>&AC_FD_CC; (eval $link_cmd) 2>&AC_FD_CC; } && "$BUILDDIR/smartlink" -v >/dev/null 2>&AC_FD_CC; then
    AC_MSG_RESULT(yes)
  else
    AC_MSG_RESULT(no - use the sh script)
    SMARTLINK="$BINDIR/smartlink"
  fi
fi
else # force_smartlink_script_only
     AC_MSG_CHECKING(for smartlink build script)
     SMARTLINK="$BINDIR/smartlink"
     REALCC="$CC"
     AC_MSG_RESULT($SMARTLINK)
fi # force_smartlink_script_only

CC="$SMARTLINK $REALCC"
pike_cv_prog_CC="$CC"

# Strip smartlink from $CXX
REALCXX="`echo $CXX|sed -e 's/.*smartlink //'`"
CXX="$SMARTLINK $REALCXX"
pike_cv_prog_CXX="$CXX"

AC_SUBST(SMARTLINK)
AC_SUBST(REALCC)
AC_SUBST(REALCXX)
export REALCC REALCXX SMARTLINK

AC_MSG_CHECKING([for a fallback compiler])
# Strip smartlink from $FALLBACK_CC
FALLBACK_CC="`echo $FALLBACK_CC|sed -e 's/.*smartlink //'`"
if test "x$FALLBACK_CC" = "x"; then
  AC_MSG_RESULT(no)
else
  FALLBACK_CC="$SMARTLINK $FALLBACK_CC"
  AC_MSG_RESULT($FALLBACK_CC)
fi
AC_SUBST(FALLBACK_CC)
export FALLBACK_CC

#############################################################################
fi #if test "x$enable_binary" != "xno"
#############################################################################

# Something seems to mess with the stack ulimit on some architectures...
#
# Cause found. GNU make 3.81 apparently raises the stack ulimit to max
# without restoring it for the subprocesses. (Bug 18396 and 22010 at
# http://savannah.gnu.org/projects/make)
AC_DEFUN(PIKE_AC_DEBUG, [
  echo "DEBUG: ----------------------------------" 1>&AC_FD_CC
  echo "Current limits: " 1>&AC_FD_CC
  ulimit -a 1>&AC_FD_CC
  echo "DEBUG: ++++++++++++++++++++++++++++++++++" 1>&AC_FD_CC
])

PIKE_AC_DEBUG

if :; then :; else
# Disabled for now.
# It looks this makes it even worse...
# It seems to cause bash to loop on a SIGSEGV in the signal handler
# on Gentoo Linux/IA64.
AC_MSG_CHECKING([if the stack ulimit is excessive])
if ulimit -s 1>&AC_FD_CC 2>&AC_FD_CC; then
  orig_ulimit="`ulimit -s 2>&AC_FD_CC`"
  if test "$orig_ulimit" -gt "65536"; then
    AC_MSG_RESULT([yes, $orig_ulimit - reducing to 8192.])
    if ulimit -s 8192 1>&AC_FD_CC 2>&AC_FD_CC; then :; else
      AC_MSG_WARN([Failed to reduce stack ulimit to 8192.])
    fi
    PIKE_AC_DEBUG
  else
    AC_MSG_RESULT([no, $orig_ulimit])
  fi
else
  AC_MSG_RESULT([unknown, ulimit -s failed.])
fi
fi

AC_SYS_COMPILER_FLAG(+O3,plus_O3,OPTIMIZE, [
  AC_SYS_COMPILER_FLAG(-O3,O3,OPTIMIZE, [
    AC_SYS_COMPILER_FLAG(-O2,O2,OPTIMIZE, [
      AC_SYS_COMPILER_FLAG(-O,O,OPTIMIZE)
    ])
  ])
])

if test "$GCC" = "yes"; then
  if test "$cflags_is_set" = "no"; then
    AC_SYS_COMPILER_FLAG(-pipe, pipe, OPTIMIZE)

    # The following segment is obsolete, since executable memory is
    # now allocated with mmap instead of with malloc().
    #	/grubba 2005-06-09
    #
    #     #### For exec-shield in newer linux kernels.
    #     #### Linux's mprotect(2) is broken, so we unfortunately
    #     #### need to enable executabe stack.
    #     #### This test crashes under mingw32 so let's disable for win32 for now.
    #     if test "$pike_cv_sys_os" != "Windows_NT"; then
    #       AC_SYS_COMPILER_FLAG([[-Wa,--execstack]],executableheap,CFLAGS)
    #     fi
  fi
fi

LD='$(CC) $(CFLAGS)'
LC_REQ="-lc"

case "$pike_cv_sys_os" in
  Darwin*)
      ;;
  SCO*)
     case "$CFLAGS" in
        *-belf*) 
          AC_SYS_COMPILER_FLAG(-belf,sco_belf_option,CFLAGS,[],[
            case "$LDFLAGS" in
              *-belf*) ;;
              *)
                echo "Adding -belf option to ldflags."
                LDFLAGS="$LDFLAGS -belf"
              ;;
            esac
          ])
       ;;
       *)
	 AC_SYS_COMPILER_FLAG(-belf,belf,CFLAGS)
       ;;
     esac
     case "$LDFLAGS" in
       *-belf*) ;;
       *)
	  AC_SYS_COMPILER_FLAG(-belf,belf,LDFLAGS)
       ;;
     esac
  ;;
  SunOS*)
    # gcc on SunOS 4 forgets to define this:
    echo "SunOS. Adding -D__USE_FIXED_PROTOTYPES__"
    CFLAGS="$CFLAGS -D__USE_FIXED_PROTOTYPES__"
  ;;
  BSD/OS*)
    case "`uname -r`" in
      [4-9].*) ;;
      *) LD="$BINDIR/smartlink shlicc";;
    esac
  ;;
  UnixWare*|OpenUNIX*)
    case "$CFLAGS" in
      *-Kalloca*) ;;
      *)
	if test "$GCC" != "yes"; then
	  # We are using built-in inline function
	  CFLAGS="$CFLAGS -Kalloca"
	  CXX="$CXX -DNO_CPLUSPLUS_ALLOCA"
	  LC_REQ=""
	fi
      ;;
    esac
  ;;
  Linux*)
    if $REALCC -V 2>&1 | head -1 | grep "Intel(R) C" >/dev/null; then
      # icc or ecc.
      LC_REQ=""
    fi
  ;;
esac

AC_SUBST(LD)
AC_SUBST(LC_REQ)

#############################################################################

AC_ARG_WITH(extra_debug_checks,
	    MY_DESCR([--with-extra-debug-checks],
		     [enable some extra (possibly verbose) debug checks.]),
	    [], [
  if test "x$pike_cv_sys_os" = "xOSF1"; then
    # Attempt to detect the cause for test_resolv to fail on Unicode.so.
    with_extra_debug_checks="yes"
  elif test "x$pike_cv_sys_os" = "xOpenBSD"; then
    # Attempt to detect cause of dmalloc failure on OpenBSD.
    with_extra_debug_checks="yes"
  else
    with_extra_debug_checks=no
  fi
  ])

if test "x$with_extra_debug_checks" = "xno"; then :; else
  AC_MSG_WARN([Enabling extra debug checks.])
  AC_DEFINE([PIKE_EXTRA_DEBUG])
fi

#############################################################################

AC_ARG_WITH(patch_gcc, MY_DESCR([--with-patch-gcc],
				[attempt to patch the UA32 relocation bug.]),
	    [], [with_patch_gcc=no])

AC_ARG_WITH(force_ua32, MY_DESCR([--with-force-ua32],
				 [ignore the UA32 relocation bug.]),
	    [], [with_force_ua32=no])

# Some sanity checks.

if test "$GCC" = "yes" -a "$pike_cv_sys_os" = "Solaris" && test "`uname -p`" = "sparc"; then
  # Solaris/sparc:
  #   Check that gnu ld isn't used.
  #   It's usually hidden in $prefix/sparc-sun-solaris2.?/bin/.
  # NOTE: M4 uses [] as quotes.
  gcc_ld_path="`$CC -v 2>&1 | sed -e '1,1s/[[^\/]]*\(\/.*\/\)[[^\/]]*$/\1/p;d' | sed -e '/lib\/gcc-lib\//s/lib\/gcc-lib\///;s/\/[[0-9]]*\.[[0-9]]*\.[[0-9]]*\/$/\/bin/'`"
  if test "x$gcc_ld_path" = "x"; then :;
  elif test -d "$gcc_ld_path/."; then
    if "$gcc_ld_path/ld" -v 2>&1 | grep -i GNU >/dev/null; then
      PIKE_MSG_WARN([GNU ld found on Solaris sparc system ($gcc_ld_path/ld).
This may cause the dynamic module support to fail.])
    else :; fi
  else :; fi
  unset gcc_ld_path


  # Watch out for gcc-2.8.1 on Solaris 7 sparc machines. It generates
  # assembler code which contains .uaword directives, which in turn
  # generates code with R_SPARC_UA32 relocations, which /usr/bin/ld.so
  # has buggy support for (it doesn't relocate the MSB).

  #  Check that gcc doesn't generate uaword opcodes
  AC_MSG_CHECKING(if your gcc generates uaword opcodes)
  AC_CACHE_VAL(pike_cv_gcc_uaword, [
    cat > conftest.c <<EOF    
char *foo[[]] = { "bar" };
EOF
    pike_compile='${CC-cc} -S $CPPFLAGS conftest.c 1>&AC_FD_CC'
    pike_cv_gcc_uaword=no
    if { (eval echo configure: \"$pike_compile\") >&AC_FD_CC; (eval $pike_compile) 2>&AC_FD_CC; }; then
      if grep ".uaword" conftest.s 2>&AC_FD_CC >/dev/null; then
        echo "configure: result contains .uaword:" >&AC_FD_CC
	cat conftest.s >&AC_FD_CC
        pike_cv_gcc_uaword=yes
      else :; fi
    else
      echo "configure: failed program was:" >&AC_FD_CC
      cat conftest.c >&AC_FD_CC
    fi
    rm -rf conftest.*
  ])
  AC_MSG_RESULT($pike_cv_gcc_uaword)

  # Check if as generates R_SPARC_UA32 relocations from .uaword.
  if test "$pike_cv_gcc_uaword" = "yes"; then
    AC_MSG_CHECKING([if your as generates R_SPARC_UA32 relocations])
    AC_CACHE_VAL(pike_cv_as_r_sparc_ua32, [
      AC_TRY_ASSEMBLE([
.section	".rodata"
	.align 8
.STRING:
	.asciz	"String"
.section	".data"
	.align 4
	.type	string,#object
	.size	string,4
string:
	.uaword	.STRING
      ],[
        if /usr/ccs/bin/elfdump -r conftest.o | grep -i R_SPARC_UA32 >/dev/null 2>&AC_FD_CC; then
	  pike_cv_ac_r_sparc_ua32=yes
	else
	  pike_cv_ac_r_sparc_ua32=no
	fi
      ],[
        pike_cv_ac_r_sparc_ua32=no
      ])
    ])
    AC_MSG_RESULT($pike_cv_ac_r_sparc_ua32)
    if test "$pike_cv_ac_r_sparc_ua32" = "yes"; then
      PIKE_MSG_WARN([Your gcc/as combo may generate R_SPARC_UA32 relocations.
R_SPARC_UA32 relocations are unsupported in Solaris >= 2.3,
and have broken support in Solaris 7.])

      if test "x$with_patch_gcc$with_force_ua32" = "xnono"; then
  	if test -d "/var/sadm/patch/107058-01/."; then
  	  PIKE_MSG_WARN([Back out patch 107058-01, or
recompile gcc with a modified config/sparc/sol2.h.])
  	else
  	  PIKE_MSG_WARN([Recompile gcc with a modified config/sparc/sol2.h.])
  	fi

	PIKE_MSG_WARN([You may want to try binary patching gcc.
In that case rerun configure with --with-patch-gcc.
NOTE: Binary patching is highly experimental and risky,
      and may break your existing gcc even more.

R_SPARC_UA32 relocations are supported on some versions
of Solaris. If you want to try a binary with R_SPARC_UA32
relocations, rerun configure with --with-force-ua32.])
        exit 1
      fi

      if test "x$with_patch_gcc" = "xno"; then :; else
        AC_MSG_WARN([Will attempt to patch gcc.])

        AC_MSG_CHECKING([for cc1])
        if test "x$with_patch_gcc" = "xyes"; then
          cc1="`$CC -v 2>&1|sed -e '/\//s!^[[^/]]*\(/.*\)/specs$!\1/cc1!p' -ed`"
        else
	  cc1="$with_patch_gcc";
        fi
        if test -f "$cc1"; then
	  AC_MSG_RESULT($cc1)
        else
	  AC_MSG_RESULT(not found. Tried $cc1)
	  exit 1
        fi
       
        AC_MSG_CHECKING(if $cc1 looks unpatched)
        if /usr/bin/strings "$cc1" | grep uaword >/dev/null 2>&1; then
          AC_MSG_RESULT(yes)
        else
          AC_MSG_RESULT(no -- strange)
          exit 1
        fi
      
        AC_MSG_CHECKING(if patch_cc1 compiles)
        link_cmd='${CC-cc} -o patch_cc1${ac_exeext} $CFLAGS -I. $CPPFLAGS $LDFLAGS $srcdir/patch_cc1.$ac_ext $LIBS 2>&AC_FD_CC'
        if { (eval echo Compiling patch_cc1: \"$link_cmd\") 1>&AC_FD_CC; (eval $link_cmd) 2>&AC_FD_CC; } && "$BUILDDIR/patch_cc1" -v >/dev/null 2>&AC_FD_CC; then
          AC_MSG_RESULT(yes)
      
          if test -f "$cc1.patched"; then
            AC_MSG_ERROR([$cc1.patched already exists.
Please move it out of the way.])
            exit 1;
          fi

          if test -f "$cc1.orig"; then
            AC_MSG_ERROR([$cc1.orig already exists.
Please move it out of the way.])
            exit 1;
          fi

	  AC_MSG_CHECKING(if patch_cc1 works)
	  if ./patch_cc1 "$cc1" 2>&AC_FD_CC >"$cc1.patched"; then
	    if test -f "$cc1.patched"; then :; else
	      AC_MSG_RESULT(no - failed to create $cc1.patched)
	      exit 1
	    fi
	    if chmod 755 "$cc1.patched"; then :; else
	      AC_MSG_RESULT(no - failed to set permission to 755 on $cc1.patched)
	      exit 1
	    fi

	    if test "`/bin/ls -l \"$cc1\"|awk '{print $5}'`" = "`/bin/ls -l \"$cc1.patched\"|awk '{print $5}'`"; then
              if /usr/bin/strings "$cc1.patched" | grep uaword >/dev/null 2>&1; then
	        rm -f "$cc1.patched"
                AC_MSG_RESULT(no -- patching failed)
                exit 1
	      fi

	      if "$cc1.patched" --help >/dev/null 2>&1; then :; else
	        AC_MSG_RESULT(no -- the patched binary does not seem to work)
	        exit 1
	      fi

              AC_MSG_RESULT(yes)

	      AC_MSG_WARN([Activating the patched cc1.
NOTE: Entering critical section.
If configure fails at this point a broken gcc my result.])
	      if /usr/bin/mv -f "$cc1" "$cc1.orig"; then

	        AC_MSG_WARN([Moved $cc1 to $cc1.orig.])

	        if /usr/bin/mv -f "$cc1.patched" "$cc1"; then
	          AC_MSG_WARN([Patching seems to have succeeded.
Please rerun configure.])
		  exit 1
	        fi

	        AC_MSG_WARN([Moving the patched cc1 into place failed.
Will try to restore the old cc1.])

	        if /usr/bin/mv -f "$cc1.orig" "$cc1"; then
	          AC_MSG_WARN([The old cc1 has been restored.])
	          exit 1
	        fi

	        AC_MSG_ERROR([Restoring the old cc1 failed.
Your installation of gcc is most likely broken now.
Sorry, you will have to restore it yourself.
Please move $cc1.orig to $cc1.])
	        exit 1
	      else
	        AC_MSG_ERROR([Failed to move the old cc1 to safety.
Please replace $cc1 with $cc1.patched by hand.])
	        exit 1
	      fi
	    else
	      rm -f "$cc1.patched"
	      AC_MSG_ERROR([The size has changed.
You need to patch cc1 by hand.])
	      exit 1
	    fi
	  else
	    AC_MSG_RESULT(no -- you need to patch cc1 by hand)
	    exit 1
	  fi
        else
          AC_MSG_RESULT(no -- you need to patch cc1 by hand)
          exit 1
        fi
      fi
    else :; fi
  else :; fi
else :; fi

#############################################################################


AC_ARG_WITH(root, MY_DESCR([--with-root=path],
			   [specify a cross-compilation root-directory]),[
  case "$with_root" in
    /)
      with_root=""
    ;;
    /*)
    ;;
    no)
      with_root=""
    ;;
    *)
      PIKE_MSG_WARN([Root path $with_root is not absolute. Ignored.])
      with_root=""
    ;;
  esac
],[with_root=""])
MY_AC_ARG_WITH(relocatable_dumped_modules,
	       MY_DESCR([--with-relocatable-dumped-modules],
			[make dumped modules relocatable]),
	       [with_relocatable_dumped_modules=yes])
AC_ARG_WITH(dynamic_modules, MY_DESCR([--without-dynamic-modules],
				      [link modules statically]))
MY_AC_ARG_WITH(static_linking, MY_DESCR([--with-static-linking],
					[link statically, if possible]),
	       [with_static_linking=yes])
AC_ARG_ENABLE(dll, MY_DESCR([--disable-dll],
			    [don't link dynamic modules to DLLs on Windows]),
	      [], [enable_dll=yes])
AC_ARG_WITH(crt, MY_DESCR([--with-crt=dynamic|static],
			  [force linking with dynamic or static CRT in Visual Studio]))

# --with-debug-crt is a nop on most systems since a debug C runtime
# lib normally is used simply by setting LD_LIBRARY_PATH, but in MSVC
# the choice affects both the compiler and the linker.
#
# Note that all libs need to be linked to the same CRT in VC8 if they
# are linked to the DLL variant (i.e. using -MD), otherwise the MS
# loader won't load them. This restriction is reinforced by the
# manifest stuff that's used in VC8, and it doesn't apply when running
# directly in the build dir. See
# http://msdn2.microsoft.com/en-us/library/ms235299.aspx
#
# Also note that the debug CRT DLL in VC8 isn't redistributable.
AC_ARG_WITH(debug-crt, MY_DESCR([--with-debug-crt],
				[compile and link with debug CRT in Visual Studio]),
	    [], [with_debug_crt=no])

AC_ARG_WITH(bundles,
	    MY_DESCR([--without-bundles],
		     [do not enable bundled libraries]),
	    [], [with_bundles=yes])
pike_bundle_dir=""
if test "$with_bundles" = "no"; then
  :;
elif test -d "$with_bundles/."; then
  # The user has specified a bundle directory. Use it.
  pike_bundle_dir="$with_bundles"
elif test -d "$srcdir/../bundles/."; then
  # We have a bundle directory; enable them if needed.
  pike_bundle_dir=`cd "$srcdir/../bundles" && pwd`
fi
test -d bundles/. || mkdir bundles
if test -d bundles/.; then
  touch bundles/no_testsuites
  pike_bundle_prefix="`pwd`/bundles"  
  test -d bundles/installed/. || mkdir bundles/installed  
  test -d bundles/include/. || mkdir bundles/include
  CPPFLAGS="$CPPFLAGS -I$pike_bundle_prefix/include"
  test -d bundles/lib/. || mkdir bundles/lib
  touch bundles/lib/keep
  for d in $pike_cv_abi_suffixes; do
    test -d "bundles/lib$d/." || mkdir "bundles/lib$d"
    touch "bundles/lib$d/keep"
    LDFLAGS="$LDFLAGS -L$pike_bundle_prefix/lib$d"
  done
  test -d bundles/lib/pkgconfig/. || mkdir bundles/lib/pkgconfig
  if test "x$PKG_CONFIG_PATH" = "x"; then
    PKG_CONFIG_PATH="${pike_bundle_prefix}/lib/pkgconfig"
  else
    PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${pike_bundle_prefix}/lib/pkgconfig"
  fi
  export PKG_CONFIG_PATH
fi
export pike_bundle_dir
export pike_bundle_prefix
AC_ARG_WITH(site-prefixes,
	    MY_DESCR([--with-site-prefixes],
		     [:-separated list of prefixes to search for include, lib and bin dirs.]))
AC_ARG_WITH(include-path,
	    MY_DESCR([--with-include-path],
		     [a list of paths to search for include files.]))
AC_ARG_WITH(lib-path,
	    MY_DESCR([--with-lib-path],
		     [a list of paths to search for libraries.]))

AC_ARG_WITH(long-double-precision, MY_DESCR([--with-long-double-precision],
					    [use long double precision floats]))
AC_ARG_WITH(double-precision, MY_DESCR([--with-double-precision],
				       [use double precision floats]))

AC_ARG_WITH(long-long-int, MY_DESCR([--with-long-long-int],
				    [use long long native type int]))
AC_ARG_WITH(long-int, MY_DESCR([--with-long-int],
			       [use long native type int]))
AC_ARG_WITH(int-int, MY_DESCR([--with-int-int],
			      [use int native type int]))
dnl AC_ARG_WITH(short-int, MY_DESCR([--with-short-int],
dnl 				    [use short native type int (EXPERIMENTAL)]))
dnl AC_ARG_WITH(unsigned-long-int, MY_DESCR([--with-unsigned-long-int],
dnl 				    [use short native type int (EXPERIMENTAL)]))
dnl AC_ARG_WITH(unsigned-long-long-int, MY_DESCR([--with-unsigned-long-longint],
dnl 				    [use short native type int (EXPERIMENTAL)]))

AC_ARG_ENABLE(dlmalloc, MY_DESCR([--enable-dlmalloc],
				 [use Doug Leas malloc implementation instead of system malloc]),
	      [], [test "$pike_cv_sys_os" = Windows_NT && enable_dlmalloc=yes])
# dlmalloc is enabled by default on windows since the OS heap manager
# Sucketh. (Well, it's possible to enable a "low-fragmentation heap"
# but it only works for blocks up to 16kb.)
if test "x$enable_dlmalloc" = xyes; then
  EXTRA_OBJS="$EXTRA_OBJS malloc.o"
  AC_DEFINE(USE_DL_MALLOC)
else
  enable_dlmalloc=no
fi

MY_AC_ARG_WITH(cleanup-on-exit,
	       MY_DESCR([--with-cleanup-on-exit],
			[Do full cleanup at exit to detect leaks better.]),
	       [AC_DEFINE(DO_PIKE_CLEANUP)])
MY_AC_ARG_WITH(dmalloc, MY_DESCR([--with-dmalloc],[Enable memory leak checks.]),
	       [AC_DEFINE(DEBUG_MALLOC,10)])
MY_AC_ARG_WITH(dmalloc-malloc, MY_DESCR([--with-dmalloc-malloc],
					[Enable overloading of malloc(3)]),
	       [ AC_DEFINE(ENCAPSULATE_MALLOC,1) ])
MY_AC_ARG_WITH(dmalloc-malloc-leaks,
	       MY_DESCR([--with-dmalloc-malloc-leaks],
			[Report memory allocated by malloc(3) as leaks.]),
	       [ AC_DEFINE(REPORT_ENCAPSULATED_MALLOC,1) ])
MY_AC_ARG_WITH(dmalloc-trace, MY_DESCR([--with-dmalloc-trace],
				       [enable tracepoints]),
	       [with_dmalloc_trace="yes" AC_DEFINE(DMALLOC_TRACE,10)])
MY_AC_ARG_WITH(dmalloc-c-stack-trace, MY_DESCR([--with-dmalloc-c-stack-trace],
				       [record C stack traces for block allocations]),
	       [AC_DEFINE(DMALLOC_C_STACK_TRACE)])
MY_AC_ARG_WITH(dmalloc-track-free, MY_DESCR([--with-dmalloc-track-free],
				       [track freed memory too]),
	       [ with_dmalloc_track_free="yes"
		 AC_DEFINE(DMALLOC_TRACK_FREE,10)])
AC_ARG_WITH(debug, MY_DESCR([--with-debug],[same as --with-cdebug --with-rtldebug]),
	    [],[with_debug=])
AC_ARG_WITH(debug, MY_DESCR([--without-debug],[same as --without-cdebug --without-rtldebug]),
	    [],[with_debug=])
AC_ARG_WITH(rtldebug, MY_DESCR([--with-rtldebug],[enable run time self tests]),
	    [],[with_rtldebug=])
AC_ARG_WITH(cdebug, MY_DESCR([--without-cdebug],[disable -g]),[],[
  case "$pike_cv_sys_os:$GCC" in
    Solaris:no)
      # Solaris/cc has problems with combining optimizations and debuginfo.
      PIKE_MSG_WARN([Defaulting to --without-cdebug since the OS is Solaris,
and gcc is not being used.])
      with_cdebug=no
    ;;
    HP-UX:no|HPUX:no)
      # HP-UX/cc has problems with combining optimizations and debuginfo.
      #
      # cc: internal panic 7815: Malloc: underflow detected in free(). (7815)
      PIKE_MSG_WARN([Defaulting to --without-cdebug since the OS is HP-UX,
and gcc is not being used.])
      with_cdebug=no
    ;;
    *)
      with_cdebug=
    ;;
  esac
])
AC_ARG_WITH(copt, MY_DESCR([--without-copt], [disable -O2]), [], [with_copt=])
AC_ARG_WITH(threads, MY_DESCR([--without-threads], [disable threads support]),
	    [],[
   case "x$pike_cv_sys_os" in
     xFreeBSD*)
        if test "`uname -r|sed -e 's/\([[0-9]]*\).*/\1/'`" -lt 4; then
           PIKE_MSG_WARN([FreeBSD <= 3.x detected, disabling threads.
Use --with-threads to force threads support.])
           with_threads=no
        fi
     ;;
     xOpenBSD*)
        if test "`uname -r|sed -e 's/\([[0-9]]*\).*/\1/'`" -lt 4 \
             -a "x`uname -m`" = "xalpha"; then
           PIKE_MSG_WARN([OpenBSD/alpha <= 3.x detected, disabling threads.
Use --with-threads to force threads support.])
           with_threads=no
        fi
     ;;
   esac

   if test "x${with_threads-}" = x; then
     with_threads=yes
   fi
])

PIKE_AC_DEBUG

AC_ARG_WITH(malloc_overhead,
	    MY_DESCR([--with-malloc-overhead=n],
	             [tune the malloc block overhead (default is 2 * sizeof(void *))]),
	    [AC_DEFINE(PIKE_MALLOC_OVERHEAD,($withval))],
	    [AC_DEFINE(PIKE_MALLOC_OVERHEAD,(2 * sizeof(void *)))])
AC_ARG_WITH(malloc_page_size,
	    MY_DESCR([--with-malloc-page-size=n],
		     [tune to the memory page size (default is 4 kb)]),
	    [AC_DEFINE(PIKE_MALLOC_PAGE_SIZE,($withval))],
	    [AC_DEFINE(PIKE_MALLOC_PAGE_SIZE,(4 * 1024))])

PIKE_AC_DEBUG

AC_ARG_WITH(thread_c_stack,
	    MY_DESCR([--with-thread-c-stack=n],
	             [tune the thread c-stack (default is 1024 * 1024)]),
	    [AC_DEFINE_UNQUOTED(PIKE_THREAD_C_STACK_SIZE,($withval))],
	    [AC_DEFINE(PIKE_THREAD_C_STACK_SIZE,(1024 * 1024))])

AC_ARG_WITH(devpoll, MY_DESCR([--without-devpoll],
			      [disable support for /dev/poll]),
	    [],[with_devpoll=yes])
AC_ARG_WITH(gdbm, MY_DESCR([--without-gdbm],[no GNU database manager support]))
AC_ARG_WITH(gmp, MY_DESCR([--without-gmp],[no support for Gmp bignums]))
AC_ARG_WITH(zlib, MY_DESCR([--without-zlib],[disable gz compression support]),
	    [],[with_zlib=yes])
AC_ARG_WITH(mysql, MY_DESCR([--without-mysql],
			    [disable support for the Mysql database]),
	    [],[with_mysql=yes])
AC_ARG_WITH(valgrind, MY_DESCR([--with-valgrind=path],
	    [Support for running with valgrind. Implies --with-cleanup-on-exit.
             Specify --without-cleanup-on-exit if you do not want this.]), [
  if test "x$with_valgrind" = "xyes"; then
    AC_PATH_PROG(with_valgrind, valgrind, no)
    if test "x$with_valgrind" = "xno"; then
      PIKE_MSG_WARN(valgrind not found, disabled.)
    else :; fi
  else :; fi
], [with_valgrind=no])
AC_ARG_WITH(checker, MY_DESCR([--with-checker],
			      [add extra memory checking overhead (Purify)]))
AC_ARG_WITH(gcov, MY_DESCR([--with-gcov],
			   [compile with support for gcov (gcc-only)]))
MY_AC_ARG_WITH(profiling, MY_DESCR([--with-profiling],
				   [add code used to profile pike code]),
	       [AC_DEFINE(PROFILING)])
MY_AC_ARG_WITH(internal-profiling, MY_DESCR([--with-internal-profiling],
				   [add profiling code for various internal things]),
	       [AC_DEFINE(INTERNAL_PROFILING)])
MY_AC_ARG_WITH(pg, MY_DESCR([--with-pg],[use the gcc -pg option]),
	       [PROFIL=-pg])
AC_ARG_WITH(poll, MY_DESCR([--with-poll], [use poll instead of select]), [], [
  # Neither --with-poll nor --without-poll was specified
  case "$pike_cv_sys_os" in
    Solaris|HP-UX|OSF1|IRIX|Linux|UnixWare|OpenUNIX)
#    PIKE_MSG_WARN([Defaulting to --with-poll since the OS is $pike_cv_sys_os.])
# Nothing to warn about, really...
      with_poll=yes
    ;;
    AIX)
      # poll(2) is broken on AIX 4.1 and earlier.
      if test "`uname -r`" -ge 2 -a "`uname -v`" -ge 4 ; then
        with_poll=yes
      elif test "`uname -v`" -gt 4 ; then
        with_poll=yes
      else :; fi
    ;;
  esac
])
AC_ARG_WITH(max-fd,
	    MY_DESCR([--with-max-fd=X],
		     [set how many filedescriptors can be used at once]),
	    [pike_cv_max_open_fd=$withval])
MY_AC_ARG_WITH(oob, MY_DESCR([--without-oob],
			     [disable out-of-band data handling (INVALID)]),
[],[
  AC_MSG_ERROR([Support for out of band data is mandatory in Pike 7.5 and later.])
])
MY_AC_ARG_WITH(compiler-trace, MY_DESCR([--with-compiler-trace],
					[enable tracing of the compiler]),
	       [AC_DEFINE(YYDEBUG)])
AC_ARG_WITH(security, MY_DESCR([--with-security],
			       [enable internal pike security system]),
	    [AC_DEFINE(PIKE_SECURITY)])
AC_ARG_WITH(bignums, MY_DESCR([--without-bignums],
			      [disable internal conversion to bignums (not recommended)]),
	    [],[with_bignums=yes])
dnl Shared nodes has been disabled in an ugly way. To enable it you
dnl need to remove the line that sets the OPT_NOT_SHARED flag at the
dnl top of freeze_node in src/las.c. /mast
dnl AC_ARG_WITH(shared-nodes,
dnl 		MY_DESCR([--without-shared-nodes],
dnl 			 [disable the SHARED_NODES mode of the optimizer]),
dnl 		[],[with_shared_nodes=yes])
AC_ARG_WITH(typechecker, MY_DESCR([--with-typechecker=new|old],[]))
AC_ARG_WITH(type-checker,
	    MY_DESCR([--with-type-checker=new|old],
		     [select type-checker behaviour]),
 		[],[with_type_checker="${with_typechecker:-new}"])
if test "x$with_type_checker" = "xold"; then :;
  PIKE_MSG_WARN([Old type checker selected.])
else
  AC_DEFINE(NEW_ARG_CHECK)
fi
AC_ARG_WITH(computed-goto,
	    MY_DESCR([--with-computed-goto],
		     [enable use of gcc-style computed goto (EXPERIMENTAL).]),
	    [], [with_computed_goto=no])
AC_ARG_WITH(machine-code,
	MY_DESCR([--without-machine-code],
		 [do not try to use of machine code on supported architectures.]),
	[], [
          case "x$pike_cv_sys_os" in
            xOpenBSD*)
              PIKE_MSG_WARN([OpenBSD detected, disabling machine code.
  Use --with-machine-code to force usage of machine code support.])
              with_machine_code="no"
            ;;
            xFreeBSD*)
              PIKE_MSG_WARN([FreeBSD detected, disabling machine code.
  Use --with-machine-code to force usage of machine code support.])
              with_machine_code="no"
            ;;

          esac

          if test "x${with_machine_code-}" = x; then
            with_machine_code="yes"
          fi

	])
AC_ARG_WITH(small-eval-instruction,
	MY_DESCR([--with-small-eval-instruction],
		 [attempt to reduce the size of eval_instruction (EXPERIMENTAL).]), [
	  AC_DEFINE(PIKE_SMALL_EVAL_INSTRUCTION)
	  with_machine_code="no"
	  with_computed_goto="no"
	])

MY_AC_ARG_WITH(keypair-loop,
	MY_DESCR([--with-keypair-loop],
		 [enable use of keypair mapping loop method.]),
	       [AC_DEFINE(PIKE_MAPPING_KEYPAIR_LOOP)],[],
	       [])

MY_AC_ARG_WITH(portable-bytecode,
	MY_DESCR([--without-portable-bytecode],
		 [disable portable bytecode support.]),
	       [AC_DEFINE(PIKE_PORTABLE_BYTECODE)],[],
	       [AC_DEFINE(PIKE_PORTABLE_BYTECODE)])

MY_AC_ARG_WITH(lock,
	       MY_DESCR([--without-lock],
	  [enable experimental code for multicpu machines (EXPERIMENTAL).]),
		[],[AC_DEFINE(PIKE_RUN_UNLOCKED)])

AC_ARG_WITH(facets, MY_DESCR([--with-facets],
			       [enable experimental facet support (EXPERIMENTAL).]),
	    [AC_DEFINE(WITH_FACETS)])

AC_ARG_WITH(pike-type, MY_DESCR([--without-pike-type],
				[disable struct pike_type (IGNORED).]))

if test "x$with_pike_type" = "xno"; then
  PIKE_MSG_WARN([Disabling of USE_PIKE_TYPE is no longer supported.])
fi

if test "x$with_bignums" = xyes; then
  AC_DEFINE(AUTO_BIGNUM)
  if test "x$with_gmp" = xno; then
    AC_MSG_ERROR([Cannot compile --with-bignums without the GMP library
It is highly recommended that you install a working GMP
library on your system as that will add features to Pike
required by many applications (such as Roxen).  However,
if you know that you do not need GMP, you may re-run configure
with the option --without-bignums instead.])
  else :; fi
else
  PIKE_MSG_WARN([****** Compiling without bignum support. This is discouraged. Many
****** Pike applications might not work correctly.])
 sleep 10
fi

dnl Pike currently breaks miserably if SHARED_NODES is not defined.
dnl Shared nodes are still disabled bluntly. (See note above.)
dnl if test "x$with_shared_nodes" != xno; then
dnl  echo 'Enabling the SHARED_NODES mode of the optimizer.'
  AC_DEFINE(SHARED_NODES)
dnl else :; fi

if test "x$with_poll" = "xyes"; then
  AC_DEFINE(HAVE_AND_USE_POLL)
else :; fi

if test "x$with_valgrind" = "xno"; then
  VALGRIND=""
  VALGRINDARGS=""
else
  VALGRIND="$with_valgrind"
  # Make valgrind a bit silent by default.
  VALGRINDARGS="-q --tool=memcheck"
  AC_DEFINE(USE_VALGRIND)

  if test "x$with_cleanup_on_exit" = "x"; then
    AC_DEFINE(DO_PIKE_CLEANUP)
  fi

  if test "x$with_copt" != "xno"; then
    PIKE_MSG_WARN([--without-copt is advisable when using valgrind!])
  fi
fi
export VALGRIND VALGRINDARGS
AC_SUBST(VALGRIND)
AC_SUBST(VALGRINDARGS)

if test "x$with_checker" = "xyes"; then
  AC_DEFINE(__CHECKER__)
else :; fi

if test "x$with_relocatable_dumped_modules" = xyes; then
  PIKE_MODULE_RELOC=1
else
  PIKE_MODULE_RELOC=""
fi
AC_SUBST(PIKE_MODULE_RELOC)


#
# Allow --with(out)-debug to toggle both cdebug and rtldebug, but
# let --with(out)-{c,rtl}debug take precedence.
#
if test "x$with_cdebug" = x ; then
  with_cdebug="$with_debug"
fi

if test "x$with_rtldebug" = x ; then
  with_rtldebug="$with_debug"
fi


#
# --with-dmalloc requires --with-rtldebug
#
if test "x$with_dmalloc" = "x"; then
  :;
elif test "x$with_rtldebug" = "xyes"; then :; else
  PIKE_MSG_WARN([Debug malloc requires rtldebug. Enabling rtldebug.])
  with_rtldebug=yes
fi


#
# Defaults for cdebug and rtldebug here:
#

if test "x$with_cdebug" = x ; then
  with_cdebug=yes
fi

if test "x$with_rtldebug" = x ; then
  with_rtldebug=no
#  with_rtldebug=yes
fi

if test "x$with_rtldebug" = xyes ; then
  AC_DEFINE(PIKE_DEBUG)
fi

#############################################################################


DLOPEN_O=""
OSFLAGS=""
WARN=""
OPTIMIZE="${OPTFLAGS-}"

AC_ARG_ENABLE(pedantic, MY_DESCR([--enable-pedantic],
   [enable -pedantic compilation]))

if test "$cflags_is_set" = "no"; then
  if test "x$with_cdebug" = "xno" ; then
    CFLAGS=`echo " $CFLAGS " | sed -e 's@ -g @ @g'`
  else
    :
  fi

  if test "x$enable_pedantic" = "xyes"; then
    AC_SYS_COMPILER_FLAG(-pedantic,pedantic,WARN)
  fi


  if test "x${GCC-}" = xyes ; then
  # Do not use -Wall, since that produces a lot of warnings that are not
  # really interresting (such as the warning for if( ... ) ... if(
  # ... ) .... else
    AC_SYS_COMPILER_FLAG(-W,W,WARN)
    AC_SYS_COMPILER_FLAG(-Wall,Wall,WARN)
    AC_SYS_COMPILER_FLAG(-Wno-unused,Wno_unused,WARN)
    AC_SYS_COMPILER_FLAG(-Wcomment,Wcomment,WARN)
    AC_SYS_COMPILER_FLAG(-Wformat,Wformat,WARN)
    AC_SYS_COMPILER_FLAG(-Wformat-security,Wformat_security,WARN)
    AC_SYS_COMPILER_FLAG(-Wimplicit-function-declaration,Wimplicit_function_declaration,WARN)
    AC_SYS_COMPILER_FLAG(-Wmultichar,Wmultichar,WARN)
    AC_SYS_COMPILER_FLAG(-Wswitch,Wswitch,WARN)

    if test "x$with_copt" != xno; then
      # gcc complains that it doesn't support this when compiling
      # without optimizations.
      AC_SYS_COMPILER_FLAG(-Wuninitialized,Wuninitialized,WARN)
    fi
    AC_SYS_COMPILER_FLAG(-Wpointer-arith,Wpointer_arith,WARN)
    AC_SYS_COMPILER_FLAG(-Wchar-subscripts,Wchar_subscripts,WARN)
    AC_SYS_COMPILER_FLAG(-Wno-long-long,Wno_long_long,WARN)
    AC_SYS_COMPILER_FLAG(-Wdeclaration-after-statement,Wdeclaration_after_statement,WARN)

    if test "x${with_static_linking-}" = "xyes" ; then
      AC_SYS_COMPILER_FLAG(-static,link_static,CFLAGS)
    else
      :
    fi

    if test "x$with_gcov" = "xyes"; then
      # Support for gcov
      AC_SYS_COMPILER_FLAG(-fprofile-arcs, fprofile_arcs, CFLAGS)
      AC_SYS_COMPILER_FLAG(-ftest-coverage, ftest_coverage, CFLAGS)
    else :; fi

    if test "x$with_cdebug" = "xyes" ; then
      AC_SYS_COMPILER_FLAG(-ggdb3,ggdb3,CFLAGS)
    fi

    ##
    ## -fomit-frame-pointer does not work with egcs 1.1.1
    ## /Hubbe 1998-12-20
    ##
    #if test "x$with_cdebug" = "xno" ; then
    #  AC_SYS_COMPILER_FLAG(-fomit-frame-pointer,fomit_frame_pointer,OPTIMIZE)
    #else
    #  :
    #fi  


### Optimize for different SUN machines. If there is no working 'uname'
### no extra optimization will be done, but nothing should break either.
  case "`uname -m 2>/dev/null`" in
   sun4c)
    # The -msparclite option seems to generate assembler that /bin/as doesn't
    # understand.	/grubba 1998-07-17
    # AC_SYS_COMPILER_FLAG(-msparclite,sparclite,CFLAGS) 
   ;;
   sun4m)
    AC_SYS_COMPILER_FLAG(-mv8,microsparc,CFLAGS)
   ;;
   sun4d)
    AC_SYS_COMPILER_FLAG(-msupersparc,supersparc,CFLAGS)
   ;;
   sun4u)
    AC_SYS_COMPILER_FLAG(-mcpu=ultrasparc,mcpu_ultrasparc,CFLAGS,[
      AC_SYS_COMPILER_FLAG(-msupersparc,supersparc,CFLAGS)
    ],[],[
      # Some versions of gcc define __sparcv9 but aren't LP64.
      # Definition of __sparcv9 causes <sys/isa_defs.h> to define _LP64,
      # which is not a good thing for ILP32 systems...
      # Some versions of gcc define __sparc_v9__, which causes the
      # fix-included <limits.h> to think the same...
      AC_TRY_CPP([#include <limits.h>
#include <sys/types.h>
#if defined(_LP64) || (LONG_MAX != 2147483647L)
#error "We might have a problem."
#endif
      ],[],[
        # We might have a problem...
        # Check that we indeed have a LP64 system.
        AC_MSG_RESULT([yes, but LP64])
        AC_CHECK_SIZEOF(long, 4)
	# Note: the result for the following message is provided
	# by SYS_COMPILER_FLAG
	AC_MSG_CHECKING([are we really an LP64 system])
	if test "x$ac_cv_sizeof_long" = "x8"; then
	  :; #OK, we have an LP64 system!
	else
	  pike_cv_option_mcpu_ultrasparc=no
	fi
      ])
    ])
   ;;
   sun4v)
    AC_SYS_COMPILER_FLAG(-mcpu=niagara,mcpu_niagara,CFLAGS,[
      AC_SYS_COMPILER_FLAG(-msupersparc,supersparc,CFLAGS)
    ],[],[
      # Some versions of gcc define __sparcv9 but aren't LP64.
      # Definition of __sparcv9 causes <sys/isa_defs.h> to define _LP64,
      # which is not a good thing for ILP32 systems...
      # Some versions of gcc define __sparc_v9__, which causes the
      # fix-included <limits.h> to think the same...
      AC_TRY_CPP([#include <limits.h>
#include <sys/types.h>
#if defined(_LP64) || (LONG_MAX != 2147483647L)
#error "We might have a problem."
#endif
      ],[],[
        # We might have a problem...
        # Check that we indeed have a LP64 system.
        AC_MSG_RESULT([yes, but LP64])
        AC_CHECK_SIZEOF(long, 4)
	# Note: the result for the following message is provided
	# by SYS_COMPILER_FLAG
	AC_MSG_CHECKING([are we really an LP64 system])
	if test "x$ac_cv_sizeof_long" = "x8"; then
	  :; #OK, we have an LP64 system!
	else
	  pike_cv_option_mcpu_niagara=no
	fi
      ])
    ])
   ;;
   i586)
    AC_SYS_COMPILER_FLAG(-mtune=pentium,mtune_pentium,CFLAGS,[
	AC_SYS_COMPILER_FLAG(-mcpu=pentium,mcpu_pentium,CFLAGS,[
	    AC_SYS_COMPILER_FLAG(-mpentium,pentium,CFLAGS)
	])
    ])
   ;;
   i686)
    AC_SYS_COMPILER_FLAG(-mtune=i686,mtune_i686,CFLAGS,[
	AC_SYS_COMPILER_FLAG(-mcpu=i686,mcpu_i686,CFLAGS,[
	    AC_SYS_COMPILER_FLAG(-mpentiumpro,pentiumpro,CFLAGS,[
		AC_SYS_COMPILER_FLAG(-mcpu=pentium,mcpu_pentium,CFLAGS,[
		    AC_SYS_COMPILER_FLAG(-mpentium,pentium,CFLAGS)
		])
	    ])
	])
    ])
#    AC_SYS_COMPILER_FLAG(-march=i686,march_i686,CFLAGS)
   ;;
   x86_64)
	AC_SYS_COMPILER_FLAG(-m64,m64,CFLAGS,[
	    AC_SYS_COMPILER_FLAG(-mtune=i686,mtune_i686,CFLAGS,[
		AC_SYS_COMPILER_FLAG(-mcpu=i686,mcpu_i686,CFLAGS,[
		    AC_SYS_COMPILER_FLAG(-mpentiumpro,pentiumpro,CFLAGS,[
			AC_SYS_COMPILER_FLAG(-mcpu=pentium,mcpu_pentium,CFLAGS,[
			    AC_SYS_COMPILER_FLAG(-mpentium,pentium,CFLAGS)
			])
		    ])
		])
	    ])
	], [
	    BUNDLE_FLAGS="$BUNDLE_FLAGS --build=x86_64"
	])
   ;;
   i86pc)
     # Solaris x86
     case "`optisa \`isalist 2>/dev/null\` 2>/dev/null || isalist 2>/dev/null`" in 
	*amd64*)
	  AC_SYS_COMPILER_FLAG(-m64,m64,CFLAGS,[
	     AC_SYS_COMPILER_FLAG(-mtune=i686,mtune_i686,CFLAGS,[
		 AC_SYS_COMPILER_FLAG(-mcpu=i686,mcpu_i686,CFLAGS,[
		    AC_SYS_COMPILER_FLAG(-mpentiumpro,pentiumpro,CFLAGS,[
			AC_SYS_COMPILER_FLAG(-mcpu=pentium,mcpu_pentium,CFLAGS,[
			    AC_SYS_COMPILER_FLAG(-mpentium,pentium,CFLAGS)
			])
		    ])
		 ])
	     ])
	  ], [
	    BUNDLE_FLAGS="$BUNDLE_FLAGS --build=x86_64"
	  ])
#         AC_SYS_COMPILER_FLAG(-march=i686,march_i686,CFLAGS)
	;;
        *pentium_pro*)
	 AC_SYS_COMPILER_FLAG(-mtune=i686,mtune_i686,CFLAGS,[
	     AC_SYS_COMPILER_FLAG(-mcpu=i686,mcpu_i686,CFLAGS,[
		AC_SYS_COMPILER_FLAG(-mpentiumpro,pentiumpro,CFLAGS,[
		    AC_SYS_COMPILER_FLAG(-mcpu=pentium,mcpu_pentium,CFLAGS,[
			AC_SYS_COMPILER_FLAG(-mpentium,pentium,CFLAGS)
		    ])
	 	])
	     ])
	 ])
#         AC_SYS_COMPILER_FLAG(-march=i686,march_i686,CFLAGS)
	;;
        *pentium*)
	 AC_SYS_COMPILER_FLAG(-mtune=pentium,mtune_pentium,CFLAGS,[
	   AC_SYS_COMPILER_FLAG(-mcpu=pentium,mcpu_pentium,CFLAGS,[
	     AC_SYS_COMPILER_FLAG(-mpentium,pentium,CFLAGS,[
	       AC_SYS_COMPILER_FLAG(-m486,486,CFLAGS)
	     ])
	   ])
	 ])
	;;
     esac
   ;;
   ia64)
     case "`uname -p`" in
       [Ii]tanium*2)
         AC_SYS_COMPILER_FLAG(-mtune=itanium2,mtune_itanium2,CFLAGS)
       ;;
       [Ii]tanium)
         AC_SYS_COMPILER_FLAG(-mtune=itanium1,mtune_itanium1,CFLAGS)
       ;;
     esac
   ;;
   ppc64)
    case "`uname -p 2>/dev/null`" in
      Cell\ Broadband\ Engine*)
	AC_SYS_COMPILER_FLAG(-mcpu=cell,mcpu_cell,CFLAGS)
      ;;
    esac
   ;;
  esac

  # AIX
  DO_IF_OS(AIX,
  [
    # Tell the linker to generate a large toc if needed
    #
    # This option is not needed on AIX 5L/ia64.
    if test "x`uname -p`" = "xia64"; then :; else
      AC_SYS_COMPILER_FLAG(-bbigtoc,bbigtoc,LDFLAGS)
      AC_SYS_COMPILER_FLAG([-Wl,-bbigtoc],Wlbbigtoc,LDFLAGS)
    fi
  ])

  DO_IF_OS(Darwin,
  [
    # aka MacOS X.
    # Foundation framework needed by JavaVM.framework. The OS X 10.1 linker
    # no longer includes indirect dependencies so we need to add them here.
    AC_SYS_COMPILER_FLAG(-framework Foundation, framework_Foundation, LDFLAGS)
    AC_SYS_COMPILER_FLAG(-framework System, framework_System, LDFLAGS)

    # Needed for MakeDataExecutable which comes from CarbonLib
    AC_SYS_COMPILER_FLAG(-framework CoreServices, framework_CoreServices, LDFLAGS)
    
    # -flat_namespace only needed for linking with libMallocDebug
    # AC_SYS_COMPILER_FLAG(-flat_namespace, flat_namespace, LDFLAGS)
    
    # Take care of warning when linking with GMP libraries
    AC_SYS_COMPILER_FLAG(-read_only_relocs warning, ro_relocs_warn, LDFLAGS)

    # Tune based on processor family
    case "`machine`" in
      i486)
        # Darwin x86 runs on Intel Core Solo/Duo (based on Pentium M) and newer
        AC_SYS_COMPILER_FLAG(-march=pentium-m, arch_pentium_m, OPTIMIZE)
        AC_SYS_COMPILER_FLAG(-msse3, opt_sse3, OPTIMIZE)
        AC_SYS_COMPILER_FLAG(-mfpmath=sse, opt_mfpmath_sse, OPTIMIZE)

	# no-pic required for machine code to work
	AC_SYS_COMPILER_FLAG(-mdynamic-no-pic, dynamicnopic, OSFLAGS)

	# Silence warnings about not working on systems older than the base
	# version of the current machine. We'll convert e.g. 10.5.8 to 1050.
	AC_SYS_COMPILER_FLAG(-DMAC_OS_X_VERSION_MIN_REQUIRED=`sw_vers -productVersion | tr -d . | cut -c -3`0, osxminversion, CFLAGS)
      ;;
      ppc970|ppc7450|ppc7400)
	# Improve performance on G4 and G5. Note that if the build machine
	# is a G4 or newer the resulting pike won't run on a G3.
        AC_SYS_COMPILER_FLAG(-mcpu=7400, cpu7400, OPTIMIZE)
        AC_SYS_COMPILER_FLAG(-mtune=7400, tune7400, OPTIMIZE)
      ;;
      *)
        # G3 is the baseline on PPC since Mac OS X doesn't support anything
        # older.
        AC_SYS_COMPILER_FLAG(-mcpu=750, cpu750, OPTIMIZE)
        AC_SYS_COMPILER_FLAG(-mtune=750, tune750, OPTIMIZE)
      ;;
    esac
  ])

  DO_IF_OS(Linux,
  [
  :
  # The following segment is obsolete, since executable memory is
  # now allocated with mmap instead of with malloc().
  #	/grubba 2005-06-09
  #
  #     if test "x$with_machine_code" = "xno"; then :; else
  #       # WORKAROUND: mprotect(PROT_EXEC) doesn't work on Linux/x86.
  #       # Try to set the stackexec flag on the binary.
  #       # First try -z execstack (ld).
  #       AC_SYS_COMPILER_FLAG([-z execstack], z_execstack, LDFLAGS, [
  #         # No, try passing it directly to the linker.
  #         AC_SYS_COMPILER_FLAG([-Wl,-z,execstack], Wl_z_execstack, LDFLAGS, [
  # 	  # No, try --execstack (gas).
  # 	  AC_SYS_COMPILER_FLAG([--execstack], execstack, CFLAGS, [
  # 	    # No, try passing it directly to the assembler.
  # 	    AC_SYS_COMPILER_FLAG([-Wa,--execstack], Wa_execstack, CFLAGS, [
  # 	      # No.
  # 	      # FIXME: Add support for use of chstk(1).
  # 	      PIKE_MSG_WARN([Could not find any way to enable executable stack.])
  # 	    ])
  # 	  ])
  # 	])
  #       ])
  #     fi
  ])

  elif test "x${TCC-}" = xyes ; then

    # Yikes! We're using the TenDRA compiler!

    # Make sure we can use the system headerfiles...
    # Already done by the CC test in aclocal.m4.
    # AC_SYS_COMPILER_FLAG(-Ysystem, ysystem, CPPFLAGS)

    # Use lenient ANSI compliance...
    #AC_SYS_COMPILER_FLAG(-Xa, xa, CFLAGS)

    # Find out where libtdf.a is hidden.
    AC_MSG_CHECKING(for machine dependant library directory)
    AC_CACHE_VAL(pike_cv_tcc_lib_path,
    [
      pike_cv_tcc_lib_path="`${CC-cc} -dry conftest.c -i 2>&1 | sed -e '/tdfc/s/bin\/tdfc.*/lib\/sys/p' -ed| head -n 1`"
      if test -d "$pike_cv_tcc_lib_path/." ; then :; else
        # Failed.
        pike_cv_tcc_lib_path="no"
      fi
    ])
    AC_MSG_RESULT($pike_cv_tcc_lib_path)

    if test "$pike_cv_tcc_lib_path" = "no" ; then :; else
      LDFLAGS="$LDFLAGS -L$pike_cv_tcc_lib_path"

      # This library is needed for 64bit support on 32bit machines/OS's.
      AC_CHECK_LIB(tdf, __TDFUnot)
    fi

  else

    # Assume system compiler "cc".

    if test "x${with_static_linking-}" = "xyes" ; then
      DO_IF_OS(AIX,
      [
        AC_SYS_COMPILER_FLAG([-Wl,-bstatic],wl_link_static,CFLAGS)
        LD_FALLBACK_FLAGS="${LD_FALLBACK_FLAGS} -bstatic"
      ])

      DO_IF_OS(OSF1,
      [
        AC_SYS_COMPILER_FLAG(-non_shared,non_shared,CFLAGS)
        LD_FALLBACK_FLAGS="${LD_FALLBACK_FLAGS} -non_shared"
      ])

      DO_IF_OS(IRIX,
      [
        AC_SYS_COMPILER_FLAG(-non_shared,non_shared,CFLAGS)
        LD_FALLBACK_FLAGS="${LD_FALLBACK_FLAGS} -B static"
      ])

      # how do you link statically on HP-UX ?
    else
      :
    fi

### Non-gcc thingies. This should probably be enhanced...


    if test "x$with_cdebug" = "xyes" ; then
      # FIXME:
      # Maybe should remove the -g flag if this succeeds.
      AC_SYS_COMPILER_FLAG(-g3,g3,CFLAGS)
      AC_SYS_COMPILER_FLAG(-trapuv,trapuv,WARN)
    fi

    # Solaris
    DO_IF_OS(Solaris,
    [
      AC_SYS_COMPILER_FLAG(-fast,fast,OPTIMIZE,,[
        if test "x$with_abi" = "x64"; then
          # -fast implies -xarch=native, which implies 32-bit ABI.
          AC_SYS_COMPILER_FLAG(-xtarget=generic64, xtarget_generic64, OPTIMIZE)
          AC_SYS_COMPILER_FLAG(-xarch=generic64, xarch_generic64, OPTIMIZE)
        fi
        # -fast implies -fns, which turns off gradual underflow.
        AC_SYS_COMPILER_FLAG(-fns=no, fns_no, OPTIMIZE)
      ])
      AC_SYS_COMPILER_FLAG(-xdepend,xdepend,OPTIMIZE)
      AC_SYS_COMPILER_FLAG(-xs,xs,CFLAGS)
      # Causes __STDC__ to be 1 which causes several headerfiles to behave
      # differently.
      # AC_SYS_OS_COMPILER_FLAG(-Xc,Xc,WARN)
    ])

    # AIX
    DO_IF_OS(AIX,
    [
      # This one is needed to get the compiler to fail on errors,
      # which is needed for several configure-tests.
      AC_SYS_COMPILER_FLAG(-qhalt=e,qhalt_e,CFLAGS)
      AC_SYS_COMPILER_FLAG(-qro,qro,OPTIMIZE)
      AC_SYS_COMPILER_FLAG(-qfold,qfold,OPTIMIZE)
      AC_SYS_COMPILER_FLAG(-qwarn64,qwarn64,WARN)
      AC_SYS_COMPILER_FLAG(-qflag=w:w,qflag_w_w,WARN)
      AC_DEFUN(AC_SYS_COMPILER_FLAG_QINFO, [
        AC_SYS_COMPILER_FLAG(-qinfo=$1,qinfo_$1,WARN)
      ])
      AC_SYS_COMPILER_FLAG_QINFO(cmp)
      AC_SYS_COMPILER_FLAG_QINFO(cnd)
      AC_SYS_COMPILER_FLAG_QINFO(cns)
      AC_SYS_COMPILER_FLAG_QINFO(cnv)
      AC_SYS_COMPILER_FLAG_QINFO(dcl)
      AC_SYS_COMPILER_FLAG_QINFO(eff)
      AC_SYS_COMPILER_FLAG_QINFO(enu)
      AC_SYS_COMPILER_FLAG_QINFO(ext)
      AC_SYS_COMPILER_FLAG_QINFO(gen)
      AC_SYS_COMPILER_FLAG_QINFO(gnr)
      AC_SYS_COMPILER_FLAG_QINFO(got)
      AC_SYS_COMPILER_FLAG_QINFO(ini)
      AC_SYS_COMPILER_FLAG_QINFO(inl)
      AC_SYS_COMPILER_FLAG_QINFO(lan)
      AC_SYS_COMPILER_FLAG_QINFO(obs)
      AC_SYS_COMPILER_FLAG_QINFO(ord)
      AC_SYS_COMPILER_FLAG_QINFO(par)
      AC_SYS_COMPILER_FLAG_QINFO(por)
      # ppc disabled since it complains about the system header files.
      # AC_SYS_COMPILER_FLAG_QINFO(ppc)
      # ppt disabled since tracing the preprocessor isn't interresting.
      # AC_SYS_COMPILER_FLAG_QINFO(ppt)
      AC_SYS_COMPILER_FLAG_QINFO(pro)
      AC_SYS_COMPILER_FLAG_QINFO(rea)
      AC_SYS_COMPILER_FLAG_QINFO(ret)
      # trd disabled, since it adds extra errors (in particular 1506-419).
      # AC_SYS_COMPILER_FLAG_QINFO(trd)
      AC_SYS_COMPILER_FLAG_QINFO(tru)
      AC_SYS_COMPILER_FLAG_QINFO(uni)
      AC_SYS_COMPILER_FLAG_QINFO(use)
      # AC_SYS_COMPILER_FLAG(-qalias=addr,qalias_addr,OPTIMIZE)    
      # AC_SYS_COMPILER_FLAG(-qlibansi,qlibansi,OPTIMIZE)

      # Suppress warnings and informational messages we aren't interested in.
      AC_DEFUN(AC_SYS_COMPILER_FLAG_QSUPPRESS, [
        AC_SYS_COMPILER_FLAG(-qsuppress=$1,
  			   translit([qsuppress_$1],[-:],[__]),
  			   ifelse([$2],,WARN,[$2]))
      ])
      # 1506-010 (W) Macro XX invoked with a null argument for parameter Z.
      AC_SYS_COMPILER_FLAG_QSUPPRESS(1506-010)
      # 1506-219 (W) #line value 40140 too large.
      AC_SYS_COMPILER_FLAG_QSUPPRESS(1506-219, CPPFLAGS)
  
      # Tell the linker to generate a large toc if needed
      #
      # This option is not needed on AIX 5L/ia64.
      if test "x`uname -p`" = "xia64"; then :; else
        AC_SYS_COMPILER_FLAG(-bbigtoc,bbigtoc,LDFLAGS)
      fi
    ])

    # HP-UX
    DO_IF_OS(HP-UX,
    [
      AC_SYS_COMPILER_FLAG(-D__STDC_EXT__,stdc_ext,CFLAGS)
      AC_SYS_COMPILER_FLAG([-Wp,-H50000],cpp_buffer_size,CFLAGS)
      AC_SYS_COMPILER_FLAG(+ESlit,plus_ESlit,OPTIMIZE)
      AC_SYS_COMPILER_FLAG(+Odataprefetch,plus_Odataprefetch,OPTIMIZE)
      AC_SYS_COMPILER_FLAG(+Ofailsafe,plus_Ofailsafe,OPTIMIZE)
      # Ignore the following warnings if you enable +w1
      #   414 Optimization reduced to +O2 for compatibility with Debug.
      #   530 Casting from loose to strict alignment
      #   558 Empty declaration.
      # AC_SYS_COMPILER_FLAG(+w1,plus_w1,WARN)
    ])

    # OSF/1
    DO_IF_OS(OSF1,
    [
      AC_SYS_COMPILER_FLAG(-fast,fast,OPTIMIZE)
      # The need for -ieee is not detected properly by the FPE tests below.
      # AC_SYS_COMPILER_FLAG(-ieee,ieee,CFLAGS)
      AC_SYS_COMPILER_FLAG(-readonly_strings,readonly_strings,OPTIMIZE)
      AC_SYS_COMPILER_FLAG(-assume trusted_short_alignment,
        assume_trusted_short_alignment,OPTIMIZE)
      AC_SYS_COMPILER_FLAG(-assume aligned_objects,
        assume_aligned_objects,OPTIMIZE)
      AC_SYS_COMPILER_FLAG(-no_misalign,no_misalign,OPTIMIZE)
    
      AC_SYS_COMPILER_FLAG(-host,host,OPTIMIZE)
  
      # Flags that cause errors or change compiler behaviour
      # must go in CFLAGS, they can not go in WARN
      # /Hubbe
      AC_SYS_COMPILER_FLAG(-std1,std1,CFLAGS)
      AC_SYS_COMPILER_FLAG(-warnprotos,warnprotos,WARN)
    ])

    # IRIX
    DO_IF_OS(IRIX,
    [
      # sopt disabled since it takes too long time on interpret.c (>45min on an O²)
      # AC_SYS_COMPILER_FLAG(-sopt,sopt,OPTIMIZE)

      # -n32 moved to smartlink so it will affect cc as well as linker
      # this way the user can override it by setting LDFLAGS and/or CFLAGS
      # AC_SYS_COMPILER_FLAG(-n32,n32,CFLAGS)
      AC_SYS_COMPILER_FLAG(-fullwarn,fullwarn,WARN)
      AC_SYS_COMPILER_FLAG(-woff 1209,woff_1209,WARN)
      AC_SYS_COMPILER_FLAG(-OPT:Olimit_opt=on,OPT_Olimit_opt_on,OPTIMIZE)
      if test x$with_cdebug = xyes ; then
        AC_SYS_COMPILER_FLAG(-g3,g3,CFLAGS)
      fi
      if test x$with_rtldebug = xyes ; then
        AC_SYS_COMPILER_FLAG(-trapuw,trapuw,WARN)
      fi
    ])

    # Windows NT
    DO_IF_OS(Windows_NT,
    [
      case "x$CC" in
      *rntecl*)
        # Some options used by ecl (Intel's IA64 compiler).

        # We want threads, and link libc statically.
        AC_SYS_COMPILER_FLAG(-MT,MT,LDFLAGS)

        # Interprocedural optimizations.
        # For some reason this seems to cause the error:
        # dynamic_buffer.obj : error LNK2001: unresolved external symbol "[Entry] ?1memcpy" (.?1memcpy)
        # AC_SYS_COMPILER_FLAG(-Qip,Qip,OPTIMIZE)

        # More warnings.
        AC_SYS_COMPILER_FLAG(-W3,W3,WARN)

        if test x$with_rtldebug = xyes ; then
          # Initialize auto variables to 0xcc.
  	# (Only if optimizations are turned off with -Od).
          AC_SYS_COMPILER_FLAG(-GZ,GZ,WARN)
        fi
        ;;

      *rntcl*)
        if test x$with_debug_crt = xyes; then
  	dynamic_crt_flag=-MDd
  	static_crt_flag=-MTd
        else
  	dynamic_crt_flag=-MD
  	static_crt_flag=-MT
        fi
	# We want the full 32-bit address space (not the default 31-bit).
	AC_SYS_COMPILER_FLAG(-LARGEADDRESSAWARE,LARGEADDRESSAWARE,LDFLAGS)
        ;;
      esac

      if test x$with_dynamic_modules != xno; then
        pike_cv_sys_dynamic_loading=yes
        if test x$enable_dll != xyes; then
  	PIKE_MSG_NOTE([Enabling dynamic modules for Win32.])
    #      EXTRA_MODULE_REQUIREMENTS="${EXTRA_MODULE_REQUIREMENTS} import_functions.h"
  	DLOPEN_O="dlopen.o"
  	AC_DEFINE(USE_MY_WIN32_DLOPEN)
        fi
      fi
    ])

    dnl
    dnl This does not work with Digital UNIX cc/ld (cc thinks it is ok, ld does not)
    dnl  
    dnl AC_SYS_COMPILER_FLAG(-native,native,OPTIMIZE)
    dnl

    dnl ### Ok. This is for apcc...
    case "$CC" in
      *apcc)
        AC_SYS_COMPILER_FLAG(-XO=5,apcc_opt,OPTIMIZE)
        AC_SYS_COMPILER_FLAG(-Xcallmod=2,apcc_opt_2,OPTIMIZE)
      ;;
    esac

    # Old cc for solaris.
    #  AC_SYS_CPU_COMPILER_FLAG(sun4m,-Xpipe=micro,microsparc,OPTIMIZE)
    #  AC_SYS_CPU_COMPILER_FLAG(sun4d,-Xpipe=super,supersparc,OPTIMIZE)
    #  AC_SYS_CPU_COMPILER_FLAG(sun4u,-Xpipe=super,ultrasparc,OPTIMIZE)

    case "${CFLAGS-} $OPTIMIZE" in
      *-O*) ;;
      *+O*) ;;
      *-fast*) ;;
      *)
        case "$pike_cv_sys_os:$GCC" in
          UnixWare*:no|OpenUNIX*:no)
  	;;
  	*)
  	;;
        esac
      ;;
    esac
  fi

  if test "$ICC" = "yes"; then
    # icc or ecc.

    # Modern versions of icc and ecc claim to be gcc, so we need to have
    # this outside the main if-else segment.

    DO_IF_OS(Linux,
    [
      # Linux with Intel C++

      # Disable excessive warnings from Linux's header files:
      #   warning #1292: attribute "__nothrow__" ignored
      AC_SYS_COMPILER_FLAG(-wd1292,wd1292,WARN)
      # And from Pike:
      #   remark #177: function "MKPCHARP" was declared but never referenced
      AC_SYS_COMPILER_FLAG(-wd177,wd177,WARN)
      #   remark #279: controlling expression is constant
      AC_SYS_COMPILER_FLAG(-wd279,wd279,WARN)
      #   remark #869: parameter was never referenced
      AC_SYS_COMPILER_FLAG(-wd869,wd869,WARN)

      AC_SYS_COMPILER_FLAG(-Ob2,Ob2,OPTIMIZE)
      AC_SYS_COMPILER_FLAG(-ip,ip,OPTIMIZE)
      # Iterprocedural optimization accross object files.
      # This slows down the compiler quite a bit with Pike's
      # large number of object files.
      # AC_SYS_COMPILER_FLAG(-ipo,ipo,OPTIMIZE)
      # AC_SYS_COMPILER_FLAG(-ipo,ipo,EXTRALDFLAGS)
      # AC_SYS_COMPILER_FLAG(-ipo_obj,ipo_obj,OPTIMIZE)
      # -parallel seems to generate broken code with icc 8.0/ia64.
      # AC_SYS_COMPILER_FLAG(-parallel, parallel,OPTIMIZE)
      # AC_SYS_COMPILER_FLAG(-parallel, parallel,LDFLAGS)
      # arch dependent optimizations while maintaining
      # i386 compatibility
      AC_SYS_COMPILER_FLAG(-axKW,axKW,OPTIMIZE)
    ])
  fi
else
  # CFLAGS has already been set by the user.
  # Avoid adding anything that isn't essential.
  DO_IF_OS(AIX,
  [
    # This one is needed to get the compiler to fail on errors,
    # which is needed for several configure-tests.
    AC_SYS_COMPILER_FLAG(-qhalt=e,qhalt_e,CFLAGS)
  ])
fi

AC_SUBST(DLOPEN_O)

#############################################################################

# Script to translate from POSIX paths to native paths.
echo "Creating posix_to_native.sh..."
if test "x$PIKE_PATH_TRANSLATE" = "x"; then
  if test "x$pike_cv_is_mingw" = "xyes"; then
    # MinGW system.
    cat <<\EOF
#!/bin/sh
# Automatically generated by $Id: 1aa817aed558f1ad8abc47f3a20873e6772b346e $.
# MinGW-version. Do NOT edit.
posix_name="`cat`"
posix_prefix="/"
native_prefix="/"
case "$posix_name" in
  /*) ;;
  *) posix_name="`pwd`/$posix_name" ;;
esac
case "$posix_name" in
EOF
    # Split and recombine the lines.
    # Sort the lines according to longest path first.
    # Convert backslashes to forward slashes.
    # Escape spaces, tabs and dollars.
    # Note, dollars must be escaped both for sed, sh and sed.
    # Split, and generate the case entries.
    # Remove any duplicate sequences of slashes.
    mount | \
      sed -e 's/\(.*\) on \(.*\) type user.*/\2 _split_ \1/p' -ed | \
      sort -r | \
      sed -e 's/\\/\//g' | \
      sed -e 's/\([[ 	]]\)/\\\1/g' -e 's/\$/\\\\\\\$/g' | \
      sed -e 's/\(.*\)\\ _split_\\ \(.*\)/  \1|\1\/*)\
    posix_prefix=\1\
    native_prefix=\2\/\
  \;\;/p' -ed | \
      sed -e 's/\/\//\//g'
    cat <<\EOF
esac
echo "$posix_name" | \
  sed -e "s,^$posix_prefix,$native_prefix," | \
  sed -e 's/\/\//\//g'
EOF
  else
    # Native POSIX system.
  cat <<\EOF
#!/bin/sh
# Automatically generated by $Id: 1aa817aed558f1ad8abc47f3a20873e6772b346e $.
# POSIX-version. Do NOT edit.
cat
EOF
  fi
else
  # rntcl-style
  cat <<\EOF
#!/bin/sh
# Automatically generated by $Id: 1aa817aed558f1ad8abc47f3a20873e6772b346e $.
# RNTCL-version. Do NOT edit.
sed -e "$PIKE_PATH_TRANSLATE"
EOF
fi >posix_to_native.sh

chmod a+x posix_to_native.sh

#############################################################################

if test ! -d modules/. ; then
  mkdir modules
fi

#############################################################################

## Search for some popular places where libraries may be hidden.

#############################################################################

if test "x$pike_cv_sys_os$pike_cv_is_mingw" != xWindows_NT ; then

echo Searching for library and include directories...

#Don't add include dirs if they give us warnings...
OLD_ac_c_preproc_warn_flag="$ac_c_preproc_warn_flag"
ac_c_preproc_warn_flag=yes
AC_TRY_CPP([#include <stdio.h>], , [
  AC_MSG_WARN([Turning on preprocessor warnings causes cpp test to fail.])
  ac_c_preproc_warn_flag="$OLD_ac_c_preproc_warn_flag"
])

PIKE_INIT_REAL_DIRS

if test "x$with_lib_path" = "x"; then
  : # Actual code for this case appears later...
else
  for dd in `echo $with_lib_path | sed -e 's/:/ /g'`; do
    if test "$dd" = "/lib"; then continue; fi
    if test "$dd" = "/usr/lib"; then continue; fi
    for suff in $pike_cv_abi_suffixes; do
      d="$dd$suff"
      PIKE_CHECK_ABI_LIB_DIR($d)
    done
  done
fi

if test "x$with_include_path" = "x"; then :; else
  for d in `echo $with_include_path | sed -e 's/:/ /g'`; do
    if test "$d" = "/lib/include"; then continue; fi
    if test "$d" = "/usr/lib/include"; then continue; fi
    AC_MSG_CHECKING($d)
    if test -d "$d/." ; then
      real_dir=`cd "$d/." && /bin/pwd 2>/dev/null`
      if test "x$real_dir" = "x"; then
        real_dir="UNKNOWN"
      else
	case " $real_incs " in
	  *\ $real_dir\ *)
	    AC_MSG_RESULT(already checked)
	    continue
	  ;;
	esac
	real_incs="$real_incs $real_dir"
      fi
      case " $CPPFLAGS " in
        *\ -I$d\ * | *\ -I$real_dir\ *)
          AC_MSG_RESULT(already added)
          ;;
        *)
	  OLD_CPPFLAGS="${CPPFLAGS}"
          CPPFLAGS="${CPPFLAGS} -I$d"
	  AC_TRY_CPP([#include <stdio.h>], [
            AC_MSG_RESULT(added)
	  ], [
	    AC_MSG_RESULT(fails)
	    CPPFLAGS="${OLD_CPPFLAGS}"
	  ])
          ;;
      esac
    else
      AC_MSG_RESULT(no)
    fi
  done
fi

primary_path=""
fallback_path=""

if test $ldflags_is_set = yes -a $cppflags_is_set = yes ; then :; else
  for dd in \
    `echo "${with_site_prefixes}"|sed -e 's/:/ /g'` \
    `echo $exec_prefix | sed "s@^NONE@$prefix@g" | sed "s@^NONE@$with_root$ac_default_prefix@g"` \
    $with_root/usr \
    $with_root/usr/local $with_root/sw/local $with_root/sw \
    $with_root/usr/gnu $with_root/opt/gnu $with_root/sw/gnu \
    $with_root/usr/freeware $with_root/usr/pkg \
    `echo $with_root/opt/gnome* | sort -r` \
    `echo $with_root/usr/X* | sort -r` \
    $with_root/usr/sfw $with_root/opt/sfw $with_root/opt/csw \
    $with_root/usr/ccs
  do
    if test "$dd" = "/"; then continue; fi
    #if test "$dd" = "/usr"; then continue; fi
    AC_MSG_CHECKING($dd)
    if test -d "$dd/."; then :; else
      AC_MSG_RESULT(no)
      continue
    fi
    real_dir=`cd "$dd/." && /bin/pwd 2>/dev/null`
    if test "x$real_dir" = "x"; then
      AC_MSG_RESULT(ok but pwd failed)
    else case " $real_dirs " in
      *\ $real_dir\ *)
        AC_MSG_RESULT(already checked)
	continue
	;;
      esac
      AC_MSG_RESULT(ok)
      real_dirs="$real_dirs $real_dir"
    fi
    libs_found=""
    if test $ldflags_is_set = yes ; then :; else
      for suff in $pike_cv_abi_suffixes; do
        d="$dd/lib$suff"
        PIKE_CHECK_ABI_LIB_DIR($d, [libs_found="yes"], [
  	  if test "x$libs_found" = "x"; then
  	    libs_found="no"
  	  fi
        ], [libs_found="yes"])
      done
    fi
    AC_MSG_CHECKING($dd/bin)
    if test -d "$dd/bin/."; then
      if test "x$libs_found" = "xno"; then
        AC_MSG_RESULT(yes - use as fallback)
	if test "x$fallback_path" = "x"; then
	  fallback_path="$dd/bin"
	else
	  fallback_path="$fallback_path:$dd/bin"
	fi
      else
        AC_MSG_RESULT(yes)
	if test "x$primary_path" = "x"; then
	  primary_path="$dd/bin"
	else
	  primary_path="$primary_path:$dd/bin"
	fi
      fi
    else
      AC_MSG_RESULT(no)
    fi
    if test $cppflags_is_set = no -a "x$C_INCLUDE_PATH" = "x"; then
      d="$dd/include"
      AC_MSG_CHECKING($d)
      if test "x$libs_found" = "xno"; then
        # Don't add includes that correspond to libraries for the wrong ABI.
        AC_MSG_RESULT(skipped - bad libraries)
        continue
      fi
      if test -d "$d/." ; then
        real_dir=`cd "$d/." && /bin/pwd 2>/dev/null`
        if test "x$real_dir" = "x"; then
          real_dir="UNKNOWN"
        else
	  case " $real_incs " in
	    *\ $real_dir\ *)
	      AC_MSG_RESULT(already checked)
	      continue
	    ;;
	  esac
	  real_incs="$real_incs $real_dir"
        fi
        case " $CPPFLAGS " in
          *\ -I$d\ * | *\ -I$real_dir\ *)
            AC_MSG_RESULT(already added)
            ;;
          *)
	    OLD_CPPFLAGS="${CPPFLAGS}"
            CPPFLAGS="${CPPFLAGS} -I$d"
	    AC_TRY_CPP([#include <stdio.h>], [
              AC_MSG_RESULT(added)
	    ], [
	      AC_MSG_RESULT(fails)
	      CPPFLAGS="${OLD_CPPFLAGS}"
	    ])
            ;;
        esac
      else
        AC_MSG_RESULT(no)
      fi
    fi
  done
fi

if test "x$primary_path" = "x"; then
  EXTRA_PATH="$fallback_path"
elif test "x$fallback_path" = "x"; then
  EXTRA_PATH="$primary_path"
else
  EXTRA_PATH="$primary_path:$fallback_path"
fi
export EXTRA_PATH

#Restore preprocessor warning sensitivity
ac_c_preproc_warn_flag="$OLD_ac_c_preproc_warn_flag"

if test "x$with_lib_path" = "x"; then
  if test "x$with_dynamic_modules" = "xno"; then
    :;
  elif test "x$GCC" = "xno"; then :; else
    # Extract the default library paths from gcc,
    # so that we can pass them along to ld later on.
    for dd in `$CC -print-search-dirs 2>/dev/null | sed -e '/^libraries:/s/^[[^=]]*=//p' -ed | sed -e 's/\/:/ /g' -e 's/:/ /g' -e 's/\/$//'` /lib; do
      if test -d "$dd"; then :; else continue; fi
      # Normalize the paths.
      dd=`cd "$dd" && pwd`
      if test "$dd" = "/lib"; then continue; fi
      if test "$dd" = "/usr/lib"; then continue; fi
      for suff in $pike_cv_abi_suffixes; do
	d="$dd$suff"
	PIKE_CHECK_ABI_DIR($d, [
	  AC_MSG_CHECKING([if we need to add -L$real_dir to LDFLAGS])
	  case " $LDFLAGS " in
	    *\ -L$d\ *)
	      AC_MSG_RESULT([no - already added])
	      ;;
	    *\ -L$real_dir\ *)
	      AC_MSG_RESULT([no - already added])
	      ;;
	    *)
	      LDFLAGS="$LDFLAGS -L$real_dir"
	      AC_MSG_RESULT([yes - added])
	      ;;
	  esac
	  AC_MSG_CHECKING([if we need to add -R$real_dir to LDFLAGS])
	  case " $LDFLAGS " in
	    *\ -R$d\ *)
	      AC_MSG_RESULT([no - already added])
	      ;;
	    *\ -R$real_dir\ *)
	      AC_MSG_RESULT([no - already added])
	      ;;
	    *)
	      if test "x$abi_dir_dynamic" = "xyes"; then
	        LDFLAGS="$LDFLAGS -R$real_dir"
		AC_MSG_RESULT([yes - added])
	      else
		AC_MSG_RESULT([no - does not contain dynamic objects])
	      fi
	      ;;
	  esac
	])
      done
    done
  fi
fi

else
  # We are running NT without MinGW
  :
fi

# During the configure tests we need some extra includes that
# shouldn't be there in the final version.
CONF_CPPFLAGS_EXTRA="-I$srcdir -I`pwd`"
CPPFLAGS="${CPPFLAGS} ${CONF_CPPFLAGS_EXTRA}"  

# We want to know if we ought to append any abi indicator to the libdir.
AC_MSG_CHECKING(if an abi indicator would be appropriate for libdir)
AC_CACHE_VAL(pike_cv_lib_abi, [
  pike_cv_lib_abi=""
  for dd in "$with_root/lib" "$with_root/usr/lib" "$prefix/lib"; do
    for d in $pike_cv_abi_suffixes; do
      if test "x$d" = "x/."; then :;
      elif test -d "$dd$d/."; then
        pike_cv_lib_abi="$d"
	break
      fi
    done
  done
])
AC_MSG_RESULT($pike_cv_lib_abi)

AC_MSG_CHECKING(what libdir should be set to)
if test "x$pike_cv_lib_abi" = "x"; then :;
elif test -d `eval echo "$libdir$pike_cv_lib_abi/."` -o \
        "x$libdir" = 'x${exec_prefix}/lib'; then
  libdir="$libdir$pike_cv_lib_abi"
fi
AC_MSG_RESULT($libdir)

#############################################################################

## At this point we have at last initialized the compiler!

#############################################################################

if test ! -f confdefs.h ; then
  PIKE_MSG_WARN([Warning, lost confdefs.h, testing will be flawed!!
You might need to use bash instead of /bin/sh to get correct results.
To do this, please type the following at an sh prompt:
	\$ rm ./config.cache
	\$ CONFIG_SHELL=/path/to/bash
	\$ export CONFIG_SHELL
	\$ $CONFIG_SHELL ./configure])
fi

#############################################################################

AC_MSG_CHECKING(ansi prototype capability)
AC_CACHE_VAL(pike_cv_sys_ansi_prototypes,
[
  AC_TRY_COMPILE([int foo(int bar);],[],
  [pike_cv_sys_ansi_prototypes=yes],
  [pike_cv_sys_ansi_prototypes=no])
])

if test "$pike_cv_sys_ansi_prototypes" = "yes"; then
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT([no, giving up...])
  exit 1
fi

#############################################################################

AC_MSG_CHECKING(how to concatenate two symbols)
AC_CACHE_VAL(pike_cv_cpp_symbol_concat, [
  AC_TRY_COMPILE([
int AABB=0;
#define CONCAT(X,Y)	X##Y
  ], [
    return CONCAT(AA,BB);
  ], pike_cv_cpp_symbol_concat=ANSI, [
    AC_TRY_COMPILE([
int AABB=0;
#define CONCAT(X,Y)	X/**/Y
    ], [
      return CONCAT(AA,BB);
    ], pike_cv_cpp_symbol_concat=KR, [
      pike_cv_cpp_symbol_concat=Unknown
    ])
  ])
])
AC_MSG_RESULT($pike_cv_cpp_symbol_concat)
case "$pike_cv_cpp_symbol_concat" in
  "ANSI")
    AC_DEFINE(HAVE_ANSI_CONCAT)
  ;;
  "KR")
    AC_DEFINE(HAVE_KR_CONCAT)
  ;;
esac

#############################################################################

# The AC_PROG_INSTALL test is broken if $INSTALL is specified by hand.
# The FreeBSD ports system does this...
# Workaround:

if test "x$INSTALL" = "x"; then :; else
  # $INSTALL overrides ac_cv_path_install anyway...
  ac_cv_path_install="$INSTALL"
fi

AC_PROG_INSTALL
AC_PROG_CPP
AC_PROG_RANLIB

if test "x${AR-}" = x ; then
  AC_PATH_PROG(AR, ar, ar, $PATH:$EXTRA_PATH)
  export AR
fi
AC_SUBST(AR)

if test "x${RNTANY-}" = x ; then
  AC_PATH_PROG(RNTANY, rntany, , $PATH:$EXTRA_PATH)
  export RNTANY
fi
AC_SUBST(RNTANY)

# Wix compiler
if test "x${CANDLE-}" = x ; then
  PIKE_NT_PROG(CANDLE, candle, , $PATH:$EXTRA_PATH)
  export CANDLE
fi
AC_SUBST(CANDLE)

# Wix linker
if test "x${LIGHT-}" = x ; then
  PIKE_NT_PROG(LIGHT, light, , $PATH:$EXTRA_PATH)
  export LIGHT
fi
AC_SUBST(LIGHT)

# Wix tool
if test "x${TALLOW-}" = x ; then
  PIKE_NT_PROG(TALLOW, tallow, , $PATH:$EXTRA_PATH)
  export TALLOW
fi
AC_SUBST(TALLOW)

# VC8 manifest tool
if test "x${MTEXE-}" = x ; then
  PIKE_NT_PROG(MTEXE, mt.exe, , $PATH:$EXTRA_PATH)
  export MTEXE
fi

# Resource compiler
if test "x${RCEXE-}" = x ; then
  PIKE_NT_PROG(RCEXE, rc.exe, , $PATH:$EXTRA_PATH)
  export RCEXE
fi
AC_SUBST(RCEXE)

#############################################################################

# installbsd seems to be broken on some versions of AIX
#
# /grubba 1997-08-16

case "$ac_cv_path_install" in
  *installbsd*)
    AC_MSG_CHECKING(if $ac_cv_path_install works)
    AC_CACHE_VAL(pike_cv_install_works,
[
    if $ac_cv_path_install "$srcdir/configure.in" ./conftest >/dev/null 2>&1
    then
      if cmp "$srcdir/configure.in" ./conftest >/dev/null 2>&1; then
        pike_cv_install_works=yes;
      else
        pike_cv_install_works=no;
      fi
    else
      pike_cv_install_works=no;
    fi
    if test -f ./conftest; then
      rm -f ./conftest
    fi
])
    AC_MSG_RESULT($pike_cv_install_works)
    if test "$pike_cv_install_works" = "no"; then
      echo "Warning: Falling back to $ac_install_sh"
      INSTALL="$ac_install_sh"
    fi
  ;;
esac

#############################################################################

AC_MSG_CHECKING(for yacc clone that handles %pure_parser)
AC_CACHE_VAL(pike_cv_prog_working_yacc,
[
for YACC in pyacc byacc "bison -y" yacc "None"; do
  set dummy $YACC; ac_word=$2
  has_it=no
  IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS="${IFS}:"
  for ac_dir in $PATH; do
    test -z "$ac_dir" && ac_dir=.
    if test -f $ac_dir/$ac_word; then
      has_it="yes"
      break
    fi
  done
  IFS="$ac_save_ifs"
  
  if test "$has_it" = "yes"; then
cat >conftest.y<<\EOF
%pure_parser
%{
void parse();
void yyerror(char *);
%}
%%
all: foo bar
foo: 'f' 'o' 'o' { parse(); } ;
bar: 'b' 'a' 'r' ;
%%
int context;

int yylex(YYSTYPE *yylval)
{
  switch(context++)
  {
    case 0: return 'f';
    case 1: return 'o';
    case 2: return 'o';
    case 3: return 'b';
    case 4: return 'a';
    case 5: return 'r';
    default: return 0;
  }
}

int depth=0;
void parse()
{
  int tmp;
  if(depth++>5) return;
  tmp=context;
  context=0;
  yyparse();
  context=tmp;
}
int errors=0;
void yyerror(char *fel) { errors++; }
int main()
{
  parse();
  exit(errors);
}
EOF
    if $YACC -d conftest.y 1>&AC_FD_CC 2>&AC_FD_CC; then
      if test "x$enable_binary" = "xno"; then
        rm -f y.tab.*
	break
      else
	AC_TRY_RUN([
#include "y.tab.c"
],pure_parser_works=yes,pure_parser_works=no,pure_parser_works=no)
	rm -f y.tab.*
	if test "$pure_parser_works" = "yes"; then
	  break
	fi
      fi
    else
      rm -f y.tab.*
    fi
  fi
done
pike_cv_prog_working_yacc="$YACC"
])

YACC="$pike_cv_prog_working_yacc"

if test "x$YACC" = "xNone" ; then
  AC_MSG_RESULT([Get bison if you want to do "make export"])
  YACC="bison -y"
else
  AC_MSG_RESULT($YACC)
fi

#############################################################################

AC_MSG_CHECKING(how bison uses short)
AC_CACHE_VAL(pike_cv_short_use,
[
  pike_cv_short_use=unknown
  for short_use in CT_SHORT CT_SHORT_INT; do
    cat >conftest.y <<EOF
%{
#define $short_use
#ifdef CT_SHORT
#define short int
#else
#define short
#endif
void parse();
void yyerror(char *);
%}
%%
foo: 'f' x y ;
x: 'o' ;
y: 'o' ;
%%
int context = 0;

int yylex(YYSTYPE *yylval)
{
  switch(context++)
  {
    case 0: return 'f';
    case 1: return 'o';
    case 2: return 'o';
    default: return 0;
  }
}

int errors=0;
void yyerror(char *fel) { errors++; }
EOF
    if $YACC -d conftest.y 1>&AC_FD_CC 2>&AC_FD_CC; then
      AC_TRY_COMPILE([
#include "y.tab.c"
],[
yyparse();
exit(errors);
],ok=yes,ok=no)
      if test "$ok" = "yes"; then
	pike_cv_short_use=$short_use
	break
      fi
    fi
  done
])

case "$pike_cv_short_use" in
  CT_SHORT)
    AC_MSG_RESULT(short)
    AC_DEFINE(BISON_SHORT_EXPANSION,int)
    ;;
  CT_SHORT_INT)
    AC_MSG_RESULT(short int)
    AC_DEFINE(BISON_SHORT_EXPANSION,[])
    ;;
  *)
    AC_MSG_RESULT(unknown)
    ;;
esac

#############################################################################

AC_MSG_CHECKING(for the type of __yy_memcpy)
AC_CACHE_VAL(pike_cv___yy_memcpy_count_type, [
  pike_cv___yy_memcpy_from_const=
  pike_cv___yy_memcpy_count_type=unknown
  for count_type in "unsigned int" "size_t" "unsigned long" "int"; do
    for from_const in "const" ""; do
      cat >conftest.y <<EOF
%pure_parser
%{
#include <stdio.h>

#ifndef __GNUC__
#ifndef __cplusplus
static void __yy_memcpy(char *to, $from_const char *from, $count_type count);
#endif /* !__cplusplus */
#endif /* !__GNUC__ */

void yyerror(char *);
int yylex(void *);
%}
%%
all: foo bar
foo: 'f' 'o' 'o' { fprintf(stderr, "foo\\n"); } ;
bar: 'b' 'a' 'r' ;
%%
int yylex(void *yylval) { return 'f'; }
void yyerror(char *err) { fprintf(stderr, "ERR: %s\\n", err); }
EOF
      echo conftest.y: 1>&AC_FD_CC
      cat conftest.y 1>&AC_FD_CC
      if $YACC -d conftest.y 1>&AC_FD_CC 2>&AC_FD_CC; then
        AC_TRY_LINK([
#include "y.tab.c"
        ], [
  yyparse();
  exit(0);
        ], [
          pike_cv___yy_memcpy_count_type=$count_type
	  pike_cv___yy_memcpy_from_const="$from_const"
          break
        ])
      fi
    done
    if test "x$pike_cv___yy_memcpy_count_type" = "xunknown"; then :; else
      break
    fi
  done
])
if test "x$pike_cv___yy_memcpy_count_type" = "xunknown"; then
  AC_MSG_RESULT($pike_cv___yy_memcpy_count_type)
  AC_MSG_WARN([Defaulting to unsigned int.])
  YY_COUNT_TYPE="unsigned int"
  YY_FROM_CONST=""
else
  AC_MSG_RESULT(void __yy_memcpy(char *, $pike_cv___yy_memcpy_from_const char *, $pike_cv___yy_memcpy_count_type))
  YY_COUNT_TYPE="$pike_cv___yy_memcpy_count_type"
  YY_FROM_CONST="$pike_cv___yy_memcpy_from_const"
fi
AC_SUBST(YY_COUNT_TYPE)
AC_SUBST(YY_FROM_CONST)

#############################################################################

## At this point we have found all binaries we are going to use.

#############################################################################

AC_C_CONST

# The above doesn't find IBM C's buggy const.

if test "$ac_cv_c_const" = "yes"; then
  AC_MSG_CHECKING(if const really does work)
  AC_CACHE_VAL(pike_cv_c_really_const,[
    AC_TRY_COMPILE([
const int foo(int bar) { return bar; }
    ], [
      return bar(0);
    ], [
       pike_cv_c_really_const=yes
    ], [
       pike_cv_c_really_const=no
    ])
  ])

  AC_MSG_RESULT($pike_cv_c_really_const)
  if test "x$pike_cv_c_really_const" = xno ; then
    AC_DEFINE(const, [])
  else
    :
  fi
fi

AC_MSG_CHECKING([if restrict keyword is available (C99)])
AC_CACHE_VAL(pike_cv_keyword_restrict, [
  AC_TRY_COMPILE([
extern int foo(void *bar[restrict], void *restrict baz);
  ], [], [ pike_cv_keyword_restrict="yes" ], [ pike_cv_keyword_restrict="no" ])
])
AC_MSG_RESULT($pike_cv_keyword_restrict)
if test "x$pike_cv_keyword_restrict" = "xno"; then
  AC_DEFINE(restrict, [ /* Not supported */ ])
fi

AC_C_CHAR_UNSIGNED

AC_MSG_CHECKING(if we can cast void * to a function pointer)
AC_CACHE_VAL(pike_cv_function_cast, [
  AC_TRY_COMPILE([
    void *foo = 0;
  ],[
    void (*bar)(void) = (void (*)(void)) foo;
  ],[ pike_cv_function_cast="yes" ], [ pike_cv_function_cast="no" ])
])
if test "$pike_cv_function_cast" = "yes"; then
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
  AC_DEFINE(NO_CAST_TO_FUN)
fi

#############################################################################

AC_MSG_CHECKING(for isgraph)
AC_CACHE_VAL(pike_cv_func_isgraph, [ AC_TRY_LINK([
#include <ctype.h>
  ], [
    return(!isgraph('A'));
  ], pike_cv_func_isgraph=yes, pike_cv_func_isgraph=no)
])
AC_MSG_RESULT($pike_cv_func_isgraph)
if test "x$pike_cv_func_isgraph" = "xyes" ; then
  AC_DEFINE(HAVE_ISGRAPH)
else :; fi

#############################################################################

PIKE_AC_DEBUG

# Note: For function detection to work correctly with
# PIKE_FUNCS_NEED_DECLS (i.e. windows), it's necessary that
# AC_CHECK_HEADERS tests all potential header files for a function
# before AC_CHECK_FUNCS is used.

AC_HEADER_TIME
AC_HEADER_STDC
# Note: winsock2.h has to be included before winsock.h to avoid
# conflict. Thus check for winsock2.h before anything else in case
# winsock.h is included indirectly.
AC_CHECK_HEADERS(winsock2.h sys/rusage.h time.h sys/time.h sys/types.h \
		 unistd.h stdlib.h memory.h values.h string.h strings.h \
		 fcntl.h sys/filio.h sys/sockio.h crypt.h locale.h \
		 sys/select.h net/socket.h sys/param.h stdio.h wchar.h io.h \
		 sys/mman.h setjmp.h sys/user.h limits.h pthread.h \
		 crt/signal.h sys/id.h mach-o/dyld.h sys/ptrace.h \
		 thread.h dlfcn.h dld.h dl.h sys/times.h sched.h \
		 sys/procfs.h sys/ioct.h sys/socket.h sys/uio.h fcntl.h \
		 malloc.h netinet/in.h sys/wait.h windows.h grp.h pwd.h \
		 passwd.h group.h winsock.h signal.h sys/file.h poll.h \
		 sys/poll.h socket.h ieeefp.h fp_class.h floatingpoint.h \
		 float.h sys/priocntl.h sys/sched.h winbase.h errno.h \
		 stddef.h mmx.h asm/mmx.h sys/termio.h sys/termios.h \
		 ws2tcpip.h valgrind/memcheck.h memcheck.h valgrind.h \
		 sys/prctl.h sys/ioctl.h mach/task_info.h mach/task.h \
		 mach/mach_init.h syscall.h sys/syscall.h devices/timer.h \
		 direct.h CoreServices/CoreServices.h execinfo.h \
		 mach/mach.h mach/thread_act.h mach/clock.h,,,[
#if (defined(__WINNT__) || defined(__WIN32__)) && !defined(__NT__)
#define __NT__
#endif
#ifndef _LARGEFILE_SOURCE
#  define _FILE_OFFSET_BITS 64
#  define _LARGEFILE_SOURCE
#endif
#ifndef __STDC_EXT__
#  define __STDC_EXT__
#endif /* !__STDC_EXT__ */
#ifndef _PROTOTYPES
#  define _PROTOTYPES
#endif /* !_PROTOTYPES */
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif /* !_GNU_SOURCE */
#ifdef __NT__
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef WIN32
#define WIN32   100     /* WinNT 1.0 */
#endif
#if !defined(_WIN32_WINDOWS) || (_WIN32_WINDOWS < 0x500)
#undef _WIN32_WINDOWS
#define _WIN32_WINDOWS 0x0500
#endif
#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x500)
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
#if !defined(NTDDI_VERSION) || (NTDDI_VERSION < 0x05000000)
#undef NTDDI_VERSION
#define NTDDI_VERSION 0x05000000
#endif
#endif /* __NT__ */
#ifdef __amigaos__
#define __USE_NETINET_IN_H
#endif
#ifndef __BUILTIN_VA_ARG_INCR
#define __BUILTIN_VA_ARG_INCR   1
#endif /* !__BUILTIN_VA_ARG_INCR */
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#undef HAVE_WINDOWS_H
#endif
/* Necessary to find sys/socket.h on MacOS X 10.3 */
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
/* Necessary to find ws2tcpip.h on WIN32. */
#ifdef HAVE_WINSOCK2_H
# include <winsock2.h>
#endif
/* Necessary to find sys/user.h on OpenBSD */
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
])

# Setjmp.
#
# POSIX defines sigsetjmp().
# BSD defines both _setjmp() and setjmp(), where setjmp()
# saves the signal mask.
# SVID explicitly defines setjmp() not to save the signal mask.
AC_CHECK_FUNCS(sigsetjmp setjmp _setjmp siglongjmp longjmp _longjmp)

# Make it possible to disable use of /dev/poll.
if test "x$with_devpoll" = "xno"; then :; else
  AC_CHECK_HEADERS(sys/devpoll.h sys/event.h sys/epoll.h)

  AC_CHECK_FUNCS(kqueue)

  AC_MSG_CHECKING(for poll device)
  AC_CACHE_VAL(pike_cv_device_devpoll, [
    pike_cv_poll_device="no"
    for device in /dev/poll /dev/epoll; do
      if test -w "$device"; then
        pike_cv_poll_device="$device"
	break
      fi
    done
  ])
  AC_MSG_RESULT($pike_cv_poll_device)
  if test "x$pike_cv_poll_device" = "xno"; then :; else
    AC_DEFINE_UNQUOTED(PIKE_POLL_DEVICE, "$pike_cv_poll_device")
  fi

  if test "x$ac_cv_header_sys_epoll_h" = "xyes"; then
    AC_MSG_CHECKING(if epoll is available)
    AC_CACHE_VAL(pike_cv_epoll_works, [
      if test "x$pike_cv_poll_device" = "xno"; then
        AC_TRY_RUN([
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <sys/epoll.h>
#ifdef __stub_epoll_create
/* We have a libc without the wrappers for epoll support.
 */
#ifdef HAVE_SYSCALL_H
#include <syscall.h>
#elif defined(HAVE_SYS_SYSCALL_H)
#include <sys/syscall.h>
#endif /* HAVE_SYSCALL_H || HAVE_SYS_SYSCALL_H */
#ifndef __NR_epoll_create
/* Our libc does not even know the syscall numbers for the epoll syscalls.
 */
#ifdef __i386__
#define __NR_epoll_create 254
#elif defined(__ia64__)
#define __NR_epoll_create 1243
#elif defined(__x86_64__)
#define __NR_epoll_create 214
#else /* cpu types */
#error Syscall numbers for epoll_create et al not known on this architecture.
#endif /* cpu types */
#endif /* !defined(__NR_epoll_create) */

#if defined(_syscall1) && defined(_syscall4)
_syscall1(int, epoll_create, int, size);                               
#undef __stub_epoll_create
#else /* !_syscall1 || !_syscall4 */
#error Missing macros for generation of syscall wrappers.
#endif /* _syscall1 && _syscall4 */
#endif /* __stub_epoll_{create, ctl, wait} */
int main(int argc, char **argv)
{
  int fd;
  do {
    fd = epoll_create(32);
  } while ((fd < 0) && (errno == EINTR));
  return fd < 0;
}
        ], [
          pike_cv_epoll_works=yes
        ], [
          pike_cv_epoll_works=no
        ], [
          pike_cv_epoll_works=unknown
        ])
      else
        pike_cv_epoll_works=yes
      fi
    ])
    AC_MSG_RESULT($pike_cv_epoll_works)
    if test "x$pike_cv_epoll_works" = "xyes"; then
      AC_DEFINE(WITH_EPOLL)
    fi
  fi
fi

# some Linux systems have a broken resource.h that compiles anyway /Mirar
AC_MSG_CHECKING([for sys/resource.h])
AC_CACHE_VAL(pike_cv_sys_resource_h, [
  AC_TRY_COMPILE([
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#ifdef HAVE_TIME_H
#include <time.h>
#endif /* HAVE_TIME_H */
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif /* HAVE_SYS_TIME_H */

#include <sys/resource.h>

  ],[],
  [pike_cv_sys_resource_h=yes], [pike_cv_sys_resource_h=no])
])
if test "x$pike_cv_sys_resource_h" = "xyes"; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_SYS_RESOURCE_H)
else
  AC_MSG_RESULT(no)
fi

AC_CHECK_SIZEOF(char *,4)
AC_CHECK_SIZEOF(int, 4)
AC_CHECK_SIZEOF(short, 2)
AC_CHECK_SIZEOF(float, 4)
AC_CHECK_SIZEOF(double, 8)
AC_CHECK_SIZEOF(long double, 0)
AC_CHECK_SIZEOF(long, 4)
AC_CHECK_SIZEOF(long long, 0)
AC_CHECK_SIZEOF(__int64, 0)
AC_CHECK_SIZEOF(time_t, 4)
AC_CHECK_SIZEOF(__int128)
AC_CHECK_SIZEOF(__int128_t)
AC_CHECK_SIZEOF(unsigned __int128)
AC_CHECK_SIZEOF(unsigned __int128_t)
AC_CHECK_SIZEOF(__uint128_t)

AC_MY_CHECK_TYPE(size_t,unsigned long)
AC_MY_CHECK_TYPE(ptrdiff_t,long)
AC_MY_CHECK_TYPE(off_t,long)
AC_MY_CHECK_TYPE(pid_t,int)
AC_MY_CHECK_TYPE(uid_t,int)
AC_MY_CHECK_TYPE(gid_t,int)
AC_MY_CHECK_TYPE(time_t,INT32)
AC_MY_CHECK_TYPE(pri_t, short)

AC_CHECK_SIZEOF(off_t, 4)

AC_MSG_CHECKING(for sizeof anything)
if test "$ac_cv_sizeof_long_double" != 0 -a \
	"x$with_long_double_precision" = xyes ; then
  sizeof_float_type="$ac_cv_sizeof_long_double"
elif test "x$with_double_precision" = xyes ; then
  sizeof_float_type="$ac_cv_sizeof_double"
else
  sizeof_float_type="$ac_cv_sizeof_float"
fi

if test "$ac_cv_sizeof_long_long" != 0 -a \
	"x$with_long_long_int" = xyes ; then
  sizeof_int_type="$ac_cv_sizeof_long_long"
elif test "$ac_cv_sizeof___int64" != 0 -a \
	"x$with_long_long_int" = xyes ; then
  sizeof_int_type="$ac_cv_sizeof___int64"
elif test "x$with_long_int" = xyes ; then
  sizeof_int_type="$ac_cv_sizeof_long"
elif test "x$with_short_int" = xyes ; then
  sizeof_int_type="$ac_cv_sizeof_short"
elif test "x$with_unsigned_long_int" = xyes ; then
  sizeof_int_type="$ac_cv_sizeof_long"
elif test "$ac_cv_sizeof_long_long" != 0 -a \
	  "x$with_unsigned_long_long_int" = xyes ; then
  sizeof_int_type="$ac_cv_sizeof_long_long"
elif test "$ac_cv_sizeof___int64" != 0 -a \
	   "x$with_unsigned_long_long_int" = xyes ; then
  sizeof_int_type="$ac_cv_sizeof___int64"
else
  sizeof_int_type="$ac_cv_sizeof_int"
fi
sizeof_anything="$ac_cv_sizeof_char_p"
if test "$sizeof_float_type" -gt "$sizeof_anything"; then
  sizeof_anything="$sizeof_float_type"
fi
if test "$sizeof_int_type" -gt "$sizeof_anything"; then
  sizeof_anything="$sizeof_int_type"
fi
AC_MSG_RESULT($sizeof_anything)

AC_MSG_CHECKING(for FLOAT_TYPE)

if test "x$with_long_double_precision" = x -a \
	"x$with_double_precision" = x ; then
  # Choose the longest available float that fits in a pointer.
  if test "$ac_cv_sizeof_long_double" != 0 -a \
	  "$ac_cv_sizeof_long_double" -le "$sizeof_anything" ; then
    with_long_double_precision=yes
  elif test "$ac_cv_sizeof_double" -le "$sizeof_anything" ; then
    with_double_precision=yes
  fi
fi

if test "$ac_cv_sizeof_long_double" != 0 -a \
	"x$with_long_double_precision" = xyes ; then
  AC_MSG_RESULT(long double)
  AC_DEFINE(WITH_LONG_DOUBLE_PRECISION_SVALUE)
  AC_DEFINE(FLOAT_TYPE, long double)
  AC_DEFINE(SIZEOF_FLOAT_TYPE, SIZEOF_LONG_DOUBLE)
  float_type="long double"
  sizeof_float_type="$ac_cv_sizeof_long_double"
elif test "x$with_double_precision" = xyes ; then
  AC_MSG_RESULT(double)
  AC_DEFINE(WITH_DOUBLE_PRECISION_SVALUE)
  AC_DEFINE(FLOAT_TYPE, double)
  AC_DEFINE(SIZEOF_FLOAT_TYPE, SIZEOF_DOUBLE)
  float_type="double"
  sizeof_float_type="$ac_cv_sizeof_double"
else
  AC_MSG_RESULT(float)
  AC_DEFINE(FLOAT_TYPE, float)
  AC_DEFINE(SIZEOF_FLOAT_TYPE, SIZEOF_FLOAT)
  float_type="float"
  sizeof_float_type="$ac_cv_sizeof_float"
fi

AC_MSG_CHECKING(for INT_TYPE)

if test "x$with_long_long_int" = x -a \
	"x$with_long_int" = x -a \
	"x$with_int_int" = x -a \
	"x$with_short_int" = x ; then
  # Choose the longest available integer that fits in a pointer.
#  if test $ac_cv_sizeof_long_long != 0 -a \
#	   $ac_cv_sizeof_long_long -le $ac_cv_sizeof_char_p ; then
#    # This isn't a good idea on architectures where
#    # sizeof(long int) < sizeof(LONGEST).
#    # This is due to the gmp mpz api's using long int instead of
#    # mp_limb_{signed_}t.
#    #with_long_long_int=yes
#    :
#  fi
  if test "$ac_cv_sizeof_long" -le "$sizeof_anything" ; then
    with_long_int=yes
  else
    with_int_int=yes
  fi
  :
fi

if test "$ac_cv_sizeof_long_long" != 0 -a \
	"x$with_long_long_int" = xyes ; then
  AC_MSG_RESULT(long long)
  AC_DEFINE(WITH_LONG_LONG_INT)
  AC_DEFINE(INT_TYPE, long long)
  AC_DEFINE(SIZEOF_INT_TYPE, SIZEOF_LONG_LONG)
  int_type="long long"
  sizeof_int_type="$ac_cv_sizeof_long_long"
elif test "$ac_cv_sizeof___int64" != 0 -a \
	  "x$with_long_long_int" = xyes ; then
  AC_MSG_RESULT(__int64)
  AC_DEFINE(WITH_LONG_LONG_INT)
  AC_DEFINE(INT_TYPE, __int64)
  AC_DEFINE(SIZEOF_INT_TYPE, SIZEOF___INT64)
  int_type="__int64"
  sizeof_int_type="$ac_cv_sizeof___int64"
elif test "x$with_long_int" = xyes ; then
  AC_MSG_RESULT(long)
  AC_DEFINE(WITH_LONG_INT)
  AC_DEFINE(INT_TYPE, long)
  AC_DEFINE(SIZEOF_INT_TYPE, SIZEOF_LONG)
  int_type="long"
  sizeof_int_type="$ac_cv_sizeof_long"
dnl elif test "x$with_short_int" = xyes ; then
dnl   AC_MSG_RESULT(short)
dnl   AC_DEFINE(WITH_SHORT_INT)
dnl   AC_DEFINE(INT_TYPE, short)
dnl   AC_DEFINE(SIZEOF_INT_TYPE, SIZEOF_SHORT)
dnl elif test "x$with_unsigned_long_int" = xyes ; then
dnl   AC_MSG_RESULT(unsigned long)
dnl   AC_DEFINE(WITH_UNSIGNED_LONG_INT)
dnl   AC_DEFINE(INT_TYPE, unsigned long)
dnl   AC_DEFINE(SIZEOF_INT_TYPE, SIZEOF_LONG)
dnl elif test "$ac_cv_sizeof_long_long" != 0 -a \
dnl 	      "x$with_unsigned_long_long_int" = xyes ; then
dnl   AC_MSG_RESULT(unsigned long long)
dnl   AC_DEFINE(WITH_UNSIGNED_LONG_LONG_INT)
dnl   AC_DEFINE(INT_TYPE, unsigned long long)
dnl   AC_DEFINE(SIZEOF_INT_TYPE, SIZEOF_LONG_LONG)
dnl elif test "$ac_cv_sizeof___int64" != 0 -a \
dnl 	      "x$with_unsigned_long_long_int" = xyes ; then
dnl   AC_MSG_RESULT(unsigned __int64)
dnl   AC_DEFINE(WITH_UNSIGNED_LONG_LONG_INT)
dnl   AC_DEFINE(INT_TYPE, unsigned __int64)
dnl   AC_DEFINE(SIZEOF_INT_TYPE, SIZEOF___INT64)
else
  AC_MSG_RESULT(int)
  AC_DEFINE(WITH_INT_INT)
  AC_DEFINE(INT_TYPE, int)
  AC_DEFINE(SIZEOF_INT_TYPE, SIZEOF_INT)
  int_type="int"
  sizeof_int_type="$ac_cv_sizeof_int"
fi

AC_TYPE_SIGNAL

dnl AC_CHECK_LIB(PW, alloca)

dnl Checking if poll() call is in libpoll (in general in Darwin or BSD/OS)
AC_CHECK_LIB(poll, poll)

AC_CHECK_LIB(m, floor)

AC_CHECK_LIB(socket, socket)

if test x"$pike_cv_sys_os" = xWindows_NT ; then
  AC_MSG_CHECKING(if we should use the 64 bit API)
  AC_CACHE_VAL(pike_cv_sys_win64, [
    AC_EGREP_CPP(oui, [
#if defined(_WIN64) || defined(__WIN64__)
  oui
#else
  no
#endif
    ], [ pike_cv_sys_win64=yes ], [ pike_cv_sys_win64=no ])
  ])
  if test "x$pike_cv_sys_win64" = "xyes"; then
    AC_MSG_RESULT(yes)
    # Apparently the libraries are stilled named *32...
    # LIBS="-lkernel64 -lws2_64 -ladvapi64 $LIBS"
    LIBS="-lshell32 -lkernel32 -lws2_32 -ladvapi32 $LIBS"
  else
    AC_MSG_RESULT(no)
    LIBS="-lshell32 -lkernel32 -lws2_32 -ladvapi32 $LIBS"
  fi
fi

AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(rt, nanosleep)

AC_CHECK_LIB(dl, dlopen)
AC_CHECK_LIB(dld, shl_load)
AC_CHECK_LIB(dld, dld_link)


if test "${pike_cv_sys_os}" = "Linux"; then
  if test "${ac_cv_lib_m_floor}" = "no"; then
    AC_MSG_WARN(I will compensate for this by adding -lc -lm.)
    LIBS="${LIBS} -lc -lm"
  fi

  if test "$ac_cv_header_sched_h" = "yes"; then
    AC_MSG_CHECKING(if sched.h has a typo)
    AC_CACHE_VAL(pike_cv_broken_sched_h, [
      AC_TRY_COMPILE([
#include <sched.h>
      ],[ ],[ pike_cv_broken_shed_h=no ], [
        OLDCPPFLAGS="$CPPFLAGS"
	CPPFLAGS="$CPPFLAGS -D_P=__P"
	AC_TRY_COMPILE([
#include <sched.h>
        ],[ ],[ pike_cv_broken_sched_h=yes ],[
          pike_cv_broken_sched_h="very broken"
        ])
	CPPFLAGS="$OLDCPPFLAGS"
      ])
    ])
    AC_MSG_RESULT($pike_cv_broken_sched_h)
    if test "$pike_cv_broken_sched_h" = "yes"; then
      PIKE_MSG_WARN(Applying workaround for sched.h typo.)
      CPPFLAGS="$CPPFLAGS -D_P=__P"
    fi
  fi
fi

########################################################################

PIKE_AC_DEBUG

using_threads="no (forced)"

if test x$with_threads = xyes ; then
  using_threads="no (no known threads found)"
  OLDLIBS="$LIBS"
  OLDCFLAGS="$CFLAGS"

if test "x$pike_cv_sys_os" = "xWindows_NT" ; then
  # NT has threads...

  AC_DEFINE(_REENTRANT)
  AC_DEFINE(_THREAD_SAFE)
  AC_DEFINE(_UNIX_THREADS)
  AC_DEFINE(NT_THREADS)
  AC_DEFINE(PIKE_THREADS)
  using_threads="yes (nt)"

  pike_cv_thread_t_type=integer

else

  # Test for POSIX threads

  if test "x$with_thread_library" != "xno"; then
    AC_MSG_CHECKING([for thread library])
    AC_MSG_RESULT([$with_thread_library (--with-thread-library)])
    LIBS="${OLDLIBS} $with_thread_library"
  else
  case "x$pike_cv_sys_os" in
    xOSF1*)
#      LIBS="${OLDLIBS} -lpthread -lmach -lexc -lc"
      LIBS="${OLDLIBS} -lpthread -lmach -lexc"
    ;;
 
    xBSD/OS*)
      LIBS="${OLDLIBS}"
    ;;

    xUnixWare*|xOpenUNIX*)
      if test "$GCC" = yes ; then
        CFLAGS="${CFLAGS} -pthread"
      else
        CFLAGS="${CFLAGS} -Kthread"
      fi
    ;;

    xOpenBSD*)
      CFLAGS="${CFLAGS} -pthread"
      LDFLAGS="${LDFLAGS} -pthread"
    ;;

    xFreeBSD*)      
      # Threads on FreeBSD earlier than 1998-06-07 are broken.
      LIBS="${OLDLIBS}"
      AC_MSG_CHECKING(if this version of FreeBSD may have working threads)
      AC_CACHE_VAL(pike_cv_freebsd_threads, [
        AC_TRY_RUN([
#include <osreldate.h>

int main(int argc, char **argv)
{
  /* FreeBSD before 228000 and 300000 - 300005 have broken threads.
   */
  if (__FreeBSD_version < 228000)
    return(1);
  if (__FreeBSD_version < 300000)
    return(0);
  if (__FreeBSD_version < 300006)
    return(1);
  return(0);
}
        ], pike_cv_freebsd_threads=yes, pike_cv_freebsd_threads=no,
        pike_cv_freebsd_threads=yes)
      ])
      if test "x$pike_cv_freebsd_threads" = "xno"; then
        AC_MSG_RESULT(no)
      else
        AC_MSG_RESULT(yes)

	AC_MSG_CHECKING(if this version of FreeBSD might require use of pthread-config)
	AC_CACHE_VAL(pike_cv_freebsd_pthread_config, [
          AC_TRY_RUN([
#include <osreldate.h>

int main(int argc, char **argv)
{
  /* pthread-config is a remnant of the GNU pth library, and should not
   * be used on more recent versions of FreeBSD. */
  if (__FreeBSD_version < 500000)
    return(0);
  return(1);
}
          ], pike_cv_freebsd_pthread_config=yes, pike_cv_freebsd_pthread_config=no,
          pike_cv_freebsd_pthread_config=yes)
        ])
	if test "x$pike_cv_freebsd_pthread_config" = "xyes"; then
	  AC_MSG_RESULT(yes)
          AC_PATH_PROG(PTHREAD_CONFIG,${ac_tool_prefix}pthread-config,no)
	else
	  AC_MSG_RESULT(no)
	  PTHREAD_CONFIG=no
	fi
        if test "x$PTHREAD_CONFIG" = xno ; then
	  # -pthread should work with all versions of FreeBSD,
	  # but some custom compilers (ie tcc) may not support it.
          AC_SYS_COMPILER_FLAG(-pthread, pthread, CFLAGS, [
	    # FIXME: Might want to look at OS version:
	    #   500000 <= version < 500016: -pthread
	    #   500016 <= version < 502102: -lc_r
	    #   502102 <= version         : -lpthread
	    #
	    LIBS="$LIBS -lc_r"
            LDFLAGS="${LDFLAGS-} -lc_r"
	  ], [
            LDFLAGS="${LDFLAGS-} -pthread"
	  ])
        else
          CFLAGS="$CFLAGS `${PTHREAD_CONFIG} --cflags`"
          LIBS="${OLDLIBS} `${PTHREAD_CONFIG} --libs`"
          LDFLAGS="$CFLAGS `${PTHREAD_CONFIG} --ldflags`"
        fi
      fi
    ;;

    xAIX*)
      if test "`uname -v`" -gt 4 ; then
        LIBS="${OLDLIBS} -lpthread"
      else
        LIBS="${OLDLIBS} -lpthreads -lc_r"
      fi
    ;;

    xSolaris*)
      # Some versions of Solaris 2.5.1 require linking with -lthread too.
      LIBS="${OLDLIBS} -lpthread -lthread"
    ;;

    xDarwin*)
      LIBS="${OLDLIBS}"

    #
    # it would probably be better to create a compilation test should this
    # behavior change in the future, however for now, we accept this as "good enough"
    #
    AC_MSG_CHECKING([whether Darwin dislikes threads and mach includes])
    case "`uname -r`" in
      [1-9].*)
        AC_MSG_RESULT([no (10.5 or older)])
      ;;
      *)
	AC_DEFINE([USE_DARWIN_THREADS_WITHOUT_MACH], [1], [Define if pthreads and mach headers conflict])
        AC_MSG_RESULT([yes (10.6 or newer)])
        pike_cv_osx_threads_dislike_mach=yes
      ;;
  esac

    ;;

    *)
      LIBS="${OLDLIBS} -lpthread"
    ;;
  esac
  fi

  PIKE_AC_DEBUG

  AC_CHECK_FUNCS(pthread_init pthread_mutexattr_init pthread_kill \
                 pthread_cond_reltimedwait_np pthread_mach_thread_np)

  AC_MSG_CHECKING(posix threads)

  AC_CACHE_VAL(pike_cv_posix_threads, [
    AC_TRY_RUN([
#define _REENTRANT
#define _THREAD_SAFE
#define _MIT_POSIX_THREADS 1

#include <pthread.h>

void *foo(void *bar) { pthread_exit(0); return 0; }
pthread_mutexattr_t attr;
pthread_mutex_t tmp;
pthread_t gazonk;

int main()
{
  void *sune;
#ifdef HAVE_PTHREAD_INIT
  pthread_init();
#endif /* HAVE_PTHREAD_INIT */
#ifdef HAVE_PTHREAD_MUTEXATTR_INIT
  pthread_mutexattr_init(&attr);
#else
  memset(&attr, 0, sizeof(attr));
#endif /* HAVE_PTHREAD_MUTEXATTR_INIT */
  pthread_mutex_init(&tmp, &attr);
  pthread_mutex_lock(&tmp);
  pthread_create(&gazonk,0,foo,0);
  pthread_join(gazonk,&sune);
  exit(0);
}
    ], [ pike_cv_posix_threads=yes ], [ pike_cv_posix_threads=no ], [
      AC_TRY_LINK([
#define _REENTRANT
#define _THREAD_SAFE
#define _MIT_POSIX_THREADS 1

#include <pthread.h>

void *foo(void *bar) { pthread_exit(0); return 0; }
pthread_mutexattr_t attr;
pthread_mutex_t tmp;
pthread_t gazonk;

      ], [
{
  void *sune;
#ifdef HAVE_PTHREAD_INIT
  pthread_init();
#endif /* HAVE_PTHREAD_INIT */
#ifdef HAVE_PTHREAD_MUTEXATTR_INIT
  pthread_mutexattr_init(&attr);
#else
  memset(&attr, 0, sizeof(attr));
#endif /* HAVE_PTHREAD_MUTEXATTR_INIT */
  pthread_mutex_init(&tmp, &attr);
  pthread_mutex_lock(&tmp);
  pthread_create(&gazonk,0,foo,0);
  pthread_join(gazonk,&sune);
  exit(0);
}
      ], [ pike_cv_posix_threads=yes ], [ pike_cv_posix_threads=no ])
    ])
  ])

  if test $pike_cv_posix_threads = yes ; then
    AC_MSG_RESULT(yes)
    AC_DEFINE(_REENTRANT)
    AC_DEFINE(_THREAD_SAFE)
    AC_DEFINE(_MIT_POSIX_THREADS,1)
    AC_DEFINE(PIKE_THREADS)
    using_threads="yes (posix)"

##########################################################################

    AC_MSG_CHECKING(for pthread_attr_setstacksize)
    AC_CACHE_VAL(pike_cv_have_pthread_attr_setstacksize,[
      AC_TRY_LINK([#include <pthread.h>
        void foo(pthread_attr_t*x) { pthread_attr_setstacksize(x, 1024*1024); }
      ],[],[
        pike_cv_have_pthread_attr_setstacksize=yes
      ],[
        pike_cv_have_pthread_attr_setstacksize=no
      ])
    ])
    AC_MSG_RESULT($pike_cv_have_pthread_attr_setstacksize)
    if test x$pike_cv_have_pthread_attr_setstacksize = xyes ; then
      AC_DEFINE(HAVE_PTHREAD_ATTR_SETSTACKSIZE)
    else
      :
    fi

##########################################################################

    AC_MSG_CHECKING(for pthread_atfork)
    AC_CACHE_VAL(pike_cv_have_pthread_atfork,[
      AC_TRY_LINK([#include <pthread.h>
        void foo(void) { pthread_atfork(0,0,0); }
      ],[],[
        pike_cv_have_pthread_atfork=yes
      ],[
        pike_cv_have_pthread_atfork=no
      ])
    ])
    if test x$pike_cv_have_pthread_atfork = xyes ; then
      AC_MSG_RESULT(yes)
      AC_DEFINE(HAVE_PTHREAD_ATFORK)
    else
      AC_MSG_RESULT([no - FreeBSD?])
    fi

##########################################################################

    AC_MSG_CHECKING(for pthread_yield)
    AC_CACHE_VAL(pike_cv_have_pthread_yield,[
      AC_TRY_LINK([#include <pthread.h>
        void foo(void) { pthread_yield(); }
      ],[],[
        pike_cv_have_pthread_yield=yes
      ],[
        pike_cv_have_pthread_yield=no
      ])
    ])
    AC_MSG_RESULT($pike_cv_have_pthread_yield)
    if test x$pike_cv_have_pthread_yield = xyes ; then
      AC_DEFINE(HAVE_PTHREAD_YIELD)
    else
      :
    fi

##########################################################################

    AC_MSG_CHECKING(for pthread_yield_np)
    AC_CACHE_VAL(pike_cv_have_pthread_yield_np,[
      AC_TRY_LINK([#include <pthread.h>
        void foo(void) { pthread_yield_np(); }
      ],[],[
        pike_cv_have_pthread_yield_np=yes
      ],[
        pike_cv_have_pthread_yield_np=no
      ])
    ])
    AC_MSG_RESULT($pike_cv_have_pthread_yield_np)
    if test x$pike_cv_have_pthread_yield_np = xyes ; then
      AC_DEFINE(HAVE_PTHREAD_YIELD_NP)
    else
      :
    fi

##########################################################################

    AC_MSG_CHECKING(for pthread_cond_init)
    AC_CACHE_VAL(pike_cv_have_pthread_cond_init,[
      AC_TRY_LINK([#include <pthread.h>
        void foo(pthread_cond_t*x, pthread_condattr_t*y) { pthread_cond_init(x,y); }
      ],[],[
        pike_cv_have_pthread_cond_init=yes
      ],[
        pike_cv_have_pthread_cond_init=no
      ])
    ])
    AC_MSG_RESULT($pike_cv_have_pthread_cond_init)
    if test x$pike_cv_have_pthread_cond_init = xyes ; then
      AC_DEFINE(HAVE_PTHREAD_COND_INIT)
    else
      :
    fi

##########################################################################

    AC_MSG_CHECKING(if pthread_condattr_default is defined)
    AC_CACHE_VAL(pike_cv_have_pthread_condattr_default,[
      AC_TRY_LINK([#include <pthread.h>
        void foo(pthread_cond_t *bar) { pthread_cond_init(bar, pthread_condattr_default); }
      ],[],[
        pike_cv_have_pthread_condattr_default=yes
      ],[
        pike_cv_have_pthread_condattr_default=no
      ])
    ])

    AC_MSG_RESULT($pike_cv_have_pthread_condattr_default)

    if test x$pike_cv_have_pthread_condattr_default = xyes ; then
      AC_DEFINE(HAVE_PTHREAD_CONDATTR_DEFAULT)
    else
      :
    fi


    #
    # FreeBSD doesn't like the &, while AIX requires it...
    #

    AC_MSG_CHECKING(if pthread_condattr_default is needs an & (AIX))
    AC_CACHE_VAL(pike_cv_have_pthread_condattr_default_aix,[
      AC_TRY_LINK([#include <pthread.h>
        void foo(pthread_cond_t *bar) { pthread_cond_init(bar, &pthread_condattr_default); }
      ],[],[
        pike_cv_have_pthread_condattr_default_aix=yes
      ],[
        pike_cv_have_pthread_condattr_default_aix=no
      ])
    ])

    AC_MSG_RESULT($pike_cv_have_pthread_condattr_default_aix)

    if test x$pike_cv_have_pthread_condattr_default_aix = xyes ; then
      AC_DEFINE(HAVE_PTHREAD_CONDATTR_DEFAULT_AIX)
    else
      :
    fi

##########################################################################

    AC_MSG_CHECKING(for __pthread_initial_thread_bos)
    AC_CACHE_VAL(pike_cv_have_pthread_initial_thread_bos,[
      AC_TRY_LINK([#include <pthread.h>
        char *foo(void) { extern char *__pthread_initial_thread_bos; 
           return __pthread_initial_thread_bos; }
      ],[],[
        pike_cv_have_pthread_initial_thread_bos=yes
      ],[
        pike_cv_have_pthread_initial_thread_bos=no
      ])
    ])

    AC_MSG_RESULT($pike_cv_have_pthread_initial_thread_bos)

    if test x$pike_cv_have_pthread_initial_thread_bos = xyes ; then
      AC_DEFINE(HAVE_PTHREAD_INITIAL_THREAD_BOS)
    else
      :
    fi

##########################################################################

    # On Linux the threads don't inherit euid & egid from the main thread.
    # FIXME: Add a real test here!
	case "$pike_cv_sys_os" in
	  Linux* | *kFreeBSD*)
		AC_DEFINE(HAVE_BROKEN_LINUX_THREAD_EUID)
	  ;;
	esac

    AC_MSG_CHECKING([behaviour of the pthread_t type])
    AC_CACHE_VAL(pike_cv_thread_t_type, [
      AC_TRY_COMPILE([
#include <sys/types.h>
#ifdef STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif
#include <pthread.h>
extern pthread_t bar;
      ], [
	void *foo = (void *)(ptrdiff_t)bar;
	return 0;
      ], [ pike_cv_thread_t_type=integer ], [ pike_cv_thread_t_type=pointer ])
    ])
    AC_MSG_RESULT($pike_cv_thread_t_type)

  else
    AC_MSG_RESULT(no)
    LIBS="$OLDLIBS"
    CFLAGS="$OLDCFLAGS"

    echo "POSIX threads not working." >&AC_FD_CC
    ulimit -a >&AC_FD_CC 2>&AC_FD_CC
    echo >&AC_FD_CC

    # No POSIX threads.

    # Try UNIX threads instead

    AC_MSG_CHECKING(unix threads)
    case "x$pike_cv_sys_os" in
      xUnixWare*|xOpenUNIX*)
  	if test "$GCC" = yes ; then
  	  CFLAGS="${CFLAGS} -pthread"
  	else
  	  CFLAGS="${CFLAGS} -Kthread"
  	fi
  	CFLAGS="${CFLAGS} -D_UNIXWARE_THREADS_"
      ;;
      *)
  	LIBS="${LIBS} -lthread"
      ;;
    esac
  
    AC_CACHE_VAL(pike_cv_unix_threads, [
      AC_TRY_RUN([
#define _REENTRANT
#define _THREAD_SAFE
#define _MIT_POSIX_THREADS 1
#include <thread.h>
#ifdef _UNIXWARE_THREADS_
#include <synch.h>
#endif

void *foo(void *bar) { thr_exit(0); return 0; }
mutex_t tmp;
thread_t gazonk;

int main()
{
  void *sune;
  mutex_lock(& tmp);
  thr_create(0,0,foo,0,0,&gazonk);
  thr_join(gazonk,0,&sune);
  exit(0);
}
      ],pike_cv_unix_threads=yes,pike_cv_unix_threads=no,pike_cv_unix_threads=no)
    ])

    if test x$pike_cv_unix_threads = xyes ; then
      AC_MSG_RESULT(yes)
      AC_DEFINE(_REENTRANT)
      AC_DEFINE(_THREAD_SAFE)
      AC_DEFINE(_UNIX_THREADS)
      AC_DEFINE(PIKE_THREADS)
      using_threads="yes (unix)"
    else
      AC_MSG_RESULT(no)
      LIBS="$OLDLIBS"
      CFLAGS="$OLDCFLAGS"

      # Now we've sunk really low -- test for proprietary threads

      # SGI old-style shared group processes
      # AC_CHECK_FUNCS(sproc oserror)
      # 
      # AC_MSG_CHECKING(Fallback to sproc)
      # 
      # if test x$ac_cv_func_sproc$ac_cv_func_oserror = xyesyes; then
      #   AC_MSG_RESULT(yes)
      #   AC_DEFINE(_REENTRANT)
      #   AC_DEFINE(_THREAD_SAFE)
      #   AC_DEFINE(_SGI_SPROC_THREADS)
      #   AC_DEFINE(_SGI_MP_SOURCE)
      #   using_threads="yes (sgi)"
      # else
      #   AC_MSG_RESULT(no)
      #   :
      # fi
    fi # UNIX threads

    pike_cv_thread_t_type=integer
  fi # POSIX threads
fi  # NT
else
  # Without threads
  pike_cv_thread_t_type=integer
  :
fi

if test "x$pike_cv_thread_t_type" = "xpointer"; then
  AC_DEFINE(PIKE_THREAD_T_IS_POINTER)
fi

if test "x$pike_cv_sys_os" = "xWindows_NT" -o "x$pike_cv_sys_os" = "xAmigaOS"; then :; else
  AC_MSG_CHECKING(initial stack limit)
  AC_CACHE_VAL(pike_cv_initial_stack_size,[
    old_core_limit=`ulimit -c`
    ulimit -Sc 0
    rm -f confdefs.out.2 >/dev/null 2>&1 || :
    AC_TRY_RUN([
#include <stdio.h>

      static int depth=0;
      FILE *f;

      void save_depth(void);

      void use_stack(void *page)
      {
        void *X[8190];
        X[0]=page;
        save_depth();
        use_stack(&X);
      }

      void save_depth(void)
      {
        depth+=sizeof(void *)*8192;
        fprintf(f,"%d\n",depth);
        fflush(f);
        if(depth>0x80000000) exit(0);
      }

      int main(int argc)
      {
        f=fopen("confdefs.out.2", "w");
	/* weird filename to circumvent configure weirdness */
        save_depth();
        use_stack(0);
      }
    ], [pike_cv_initial_stack_size=''], [
      pike_cv_initial_stack_size=32768
      while read x; do
	# Some paranoia in case fprintf outputs junk at and of stack...
	if test "$pike_cv_initial_stack_size" -lt "$x"; then
          pike_cv_initial_stack_size="$x";
	fi
      done <confdefs.out.2
    ], [pike_cv_initial_stack_size=''])
    ulimit -c $old_core_limit
    unset old_core_limit
    rm -f confdefs.out.2 >/dev/null 2>/dev/null || :
  ])
  if test x$pike_cv_initial_stack_size = x ; then
    AC_MSG_RESULT(unlimited)
  else
    AC_MSG_RESULT($pike_cv_initial_stack_size)
    AC_DEFINE_UNQUOTED(Pike_INITIAL_STACK_SIZE,$pike_cv_initial_stack_size)
  fi
fi

########################################################################

PIKE_CHECK_CONSTANTS(mutex error check flag,
                     PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK_NP, [
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
#elif defined (HAVE_THREAD_H)
#include <thread.h>
#endif
                     ], PIKE_MUTEX_ERRORCHECK)

########################################################################

PIKE_CHECK_CONSTANTS(recursive mutex flag,
                     PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP, [
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
#elif defined (HAVE_THREAD_H)
#include <thread.h>
#endif
                     ], PIKE_MUTEX_RECURSIVE)

########################################################################

# NOTE: The following test is hardcoded to fail when crosscompiling
# It also clobbers $LIBOBJS.

ifdef([m4_pattern_allow], [
  # Handle the latest autoconf incompatibility...
  m4_pattern_allow(LIBOBJS)
])
OLD_LIBOBJS="${LIBOBJS}"

AC_FUNC_MEMCMP

# Old Autoconf set memcmp_clean while newer define memcmp_working
if test "x$ac_cv_func_memcmp_clean" = "xyes" -o \
        "x$ac_cv_func_memcmp_working" = "xyes"; then
  AC_DEFINE(HAVE_MEMCMP)
fi

LIBOBJS="${OLD_LIBOBJS}"

########################################################################

AC_FUNC_MMAP

if test "x$ac_cv_func_mmap_fixed_mapped" = "xyes"; then
  # Mac OS X has an mmap that fails with ENODEV if we try
  # to use it for mexec_alloc et al.
  #
  # NB: mmap with MAP_ANON does however work.
  AC_MSG_CHECKING([if mmap can be used to allocate PROT_EXEC])
  AC_CACHE_VAL(pike_cv_mmap_PROT_EXEC, [
    AC_TRY_RUN([
#include <stdio.h>

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif

#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif

#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif

#include <errno.h>

#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
#define MAP_ANONYMOUS	MAP_ANON
#endif /* !MAP_ANONYMOUS && MAP_ANON */

      int main(int argc, char **argv)
      {
        void *ptr;
	int dev_zero = -1;
#ifndef MAP_ANONYMOUS
        /* Neither MAP_ANONYMOUS nor MAP_ANON.
         * Map some /dev/zero.
         */
        dev_zero = open("/dev/zero", O_RDONLY);
	if (dev_zero < 0) {
	  fprintf(stderr, "open(\"/dev/zero\", O_RDONLY) failed. errno: %d\n",
		  errno);
	  return 1;
	}
#define MAP_ANONYMOUS	0
#endif /* !MAP_ANONYMOUS */
	if ((ptr = mmap(NULL, 8192, PROT_EXEC|PROT_READ|PROT_WRITE,
		        MAP_PRIVATE|MAP_ANONYMOUS,
			dev_zero, 0)) == MAP_FAILED) {
	  fprintf(stderr, "mmap(NULL, 8192, PROT_EXEC|PROT_READ|PROT_WRITE,\n"
			  "MAP_PRIVATE|MAP_ANONYMOUS, %d, 0) failed. errno: %d\n",
		  dev_zero,
		  errno);
	  return 2;
	}
	return 0;
      }
    ], [
      pike_cv_mmap_PROT_EXEC="yes"
    ], [
      pike_cv_mmap_PROT_EXEC="no"
    ], [
      AC_TRY_COMPILE([
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif

#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif

#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif

#include <errno.h>

#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
#define MAP_ANONYMOUS	MAP_ANON
#endif /* !MAP_ANONYMOUS && MAP_ANON */

#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
#define MAP_ANONYMOUS	MAP_ANON
#endif /* !MAP_ANONYMOUS && MAP_ANON */
      ], [
        void *ptr;
	int dev_zero = -1;
#ifndef MAP_ANONYMOUS
        /* Neither MAP_ANONYMOUS nor MAP_ANON.
         * Map some /dev/zero.
         */
        dev_zero = open("/dev/zero", O_RDONLY);
	if (dev_zero < 0) return 1;
#define MAP_ANONYMOUS	0
#endif /* !MAP_ANONYMOUS */
	if ((ptr = mmap(NULL, 8192, PROT_EXEC|PROT_READ|PROT_WRITE,
		        MAP_PRIVATE|MAP_ANONYMOUS,
			dev_zero, 0)) == MAP_FAILED) {
	  return 2;
	}
	return 0;
      ], [
        pike_cv_mmap_PROT_EXEC="yes"
      ], [
        pike_cv_mmap_PROT_EXEC="no"
      ])
    ])
  ])
  AC_MSG_RESULT($pike_cv_mmap_PROT_EXEC)
  if test "x$pike_cv_mmap_PROT_EXEC" = "xyes"; then
    AC_DEFINE(MEXEC_USES_MMAP)
  fi
fi

AC_CHECK_FUNCS( \
 _alldiv \
 _aullshr \
 _crypt \
 poll \
 bcopy \
 bzero \
 clock \
 closefrom \
 crypt \
 fchmod \
 fdwalk \
 gethrtime \
 gethrvtime \
 getenv \
 getrlimit \
 getrusage \
 gettimeofday \
 index \
 inet_ntop \
 localtime \
 gmtime \
 gmtime_r \
 gmtime_s \
 mallinfo \
 mallopt \
 memchr \
 mktime \
 perror \
 ptrace \
 recvmsg \
 rindex \
 sendmsg \
 setbuf \
 setlocale \
 setrlimit \
 setresuid \
 setvbuf \
 signal \
 sigaction \
 sigblock \
 sigprocmask \
 sigvec \
 strcasecmp \
 strnlen \
 strncmp \
 strchr \
 strcspn \
 strerror \
 strtod \
 strtol \
 time \
 times \
 tzset \
 vfprintf \
 vsprintf \
 _snprintf \
 snprintf \
 vsnprintf \
 wait3 \
 wait4 \
 waitpid \
 munmap \
 shl_load \
 dld_link \
 dld_get_func \
 pipe \
 strdup \
 kill \
 alarm \
 fork1 \
 flock \
 lockf \
 setuid getuid seteuid geteuid \
 setgid getgid setegid getegid \
 getpwent getpwnam getpwuid \
 getgrent getgrnam \
 setsid setpgrp getpgrp setpgid getpgid \
 initgroups setgroups \
 socketpair \
 fpclass \
 fp_class_d \
 isinf \
 isnan \
 iszero \
 finite \
 signbit \
 nan \
 nice \
 __priocntl \
 sched_setscheduler \
 setpriority \
 usleep \
 nanosleep \
 sched_yield \
 thr_yield \
 prctl \
 SetFilePointerEx \
 sync_instruction_memory \
 MakeDataExecutable \
 _get_timezone \
 _get_daylight \
 localtime_s \
 sysconf \
 getpagesize \
 GetSystemInfo \
 clock_getcpuclockid \
 backtrace \
 SetErrorMode \
 thread_info \
 host_get_clock_service \
)

# SunOS 4 realloc() returns NULL when reallocing NULL.
AC_MSG_CHECKING([if realloc(NULL, SZ) works])
AC_CACHE_VAL(pike_cv_realloc_null_works, [
  AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
  void *foo = realloc(NULL, 16);

  return !foo;
}
  ], [ pike_cv_realloc_null_works=yes
  ], [ pike_cv_realloc_null_works=no
  ], [ pike_cv_realloc_null_works=no
  ])
])
if test "x$pike_cv_realloc_null_works" = "xyes"; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_WORKING_REALLOC_NULL)
else
  AC_MSG_RESULT(no)
fi

AC_MSG_CHECKING(for the type of the last argument to accept)
AC_CACHE_VAL(pike_cv_accept_size_t, [
  for t in socklen_t size_t int; do
    AC_TRY_COMPILE([
#ifndef _LARGEFILE_SOURCE
#  define _FILE_OFFSET_BITS 64
#  define _LARGEFILE_SOURCE
#  define _LARGEFILE64_SOURCE 1
#endif
/* HPUX needs these too... */
#ifndef __STDC_EXT__
#  define __STDC_EXT__
#endif /* !__STDC_EXT__ */

#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif

/* NT */
#ifdef HAVE_WINSOCK2_H
#include <WinSock2.h>
#ifdef HAVE_WS2TCPIP_H
/* Needed for IPv6 support. */
#include <WS2tcpip.h>
#endif
#elif defined(HAVE_WINSOCK_H)
#include <winsock.h>
#endif

/* Here is the actual test: */
int accept(int, struct sockaddr *, $t *);
    ], [
      /* EMPTY */
    ], [
      pike_cv_accept_size_t=$t
      break
    ], [
      AC_TRY_COMPILE([
#ifndef _LARGEFILE_SOURCE
#  define _FILE_OFFSET_BITS 64
#  define _LARGEFILE_SOURCE
#  define _LARGEFILE64_SOURCE 1
#endif
/* HPUX needs these too... */
#ifndef __STDC_EXT__
#  define __STDC_EXT__
#endif /* !__STDC_EXT__ */

#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif

/* NT */
#ifdef HAVE_WINSOCK2_H
#include <WinSock2.h>
#ifdef HAVE_WS2TCPIP_H
/* Needed for IPv6 support. */
#include <WS2tcpip.h>
#endif
#elif defined(HAVE_WINSOCK_H)
#include <winsock.h>
#endif

/* Here is the actual test: */
SOCKET accept(SOCKET, struct sockaddr *, $t *);
      ], [
        /* EMPTY */
      ], [
	pike_cv_accept_size_t=$t
	break
      ], [])
    ])
  done
  if test "x$pike_cv_accept_size_t" = "x"; then
    # Check if it could be a Psocklen_t
    # Psocklen_t is a stupid typedef of socklen_t *.
    AC_TRY_COMPILE([
#ifndef _LARGEFILE_SOURCE
#  define _FILE_OFFSET_BITS 64
#  define _LARGEFILE_SOURCE
#  define _LARGEFILE64_SOURCE 1
#endif
/* HPUX needs these too... */
#ifndef __STDC_EXT__
#  define __STDC_EXT__
#endif /* !__STDC_EXT__ */

#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif

/* NT */
#ifdef HAVE_WINSOCK2_H
#include <WinSock2.h>
#ifdef HAVE_WS2TCPIP_H
/* Needed for IPv6 support. */
#include <WS2tcpip.h>
#endif
#elif defined(HAVE_WINSOCK_H)
#include <winsock.h>
#endif

/* Here is the actual test: */
int accept(int, struct sockaddr *, Psocklen_t);
    ], [
      /* EMPTY */
    ], [
      pike_cv_accept_size_t=socklen_t
    ], [
      # FIXME: Should probably have a warning here.
      # FIXME: Should we check if socklen_t exists, and use that?
      pike_cv_accept_size_t=int
    ])
  fi
])
AC_MSG_RESULT($pike_cv_accept_size_t *)
AC_DEFINE_UNQUOTED(ACCEPT_SIZE_T, $pike_cv_accept_size_t)

if test x"$pike_cv_sys_os" = xWindows_NT ; then
 AC_DEFINE(HAVE_LOADLIBRARY)
 AC_DEFINE(HAVE_FREELIBRARY)
 AC_DEFINE(HAVE_GETPROCADDRESS)
 AC_DEFINE(DL_EXPORT, _dlspec(export))
else
 AC_DEFINE(DL_EXPORT, [])
fi

if test $ac_cv_func_crypt$ac_cv_func__crypt = nono ; then
  AC_CHECK_LIB(crypt,crypt,[LIBS="${LIBS} -lcrypt" ; AC_DEFINE(HAVE_CRYPT)],
[
  if test -f "$srcdir/crypt.c"; then
    AC_MSG_RESULT(Using crypt.c for BSD style crypt())
    EXTRA_OBJS="${EXTRA_OBJS} crypt.o"
    AC_DEFINE(HAVE_CRYPT)
    AC_DEFINE(USE_CRYPT_C)
  else
    :
  fi
])

fi


#############################################################################
MY_CHECK_FUNCTION(infnan,
[
#include <errno.h>
#include <math.h>
], [
  double pinf = infnan(ERANGE);
  double ninf = infnan(-ERANGE);
  double nan = infnan(EDOM);
  exit(!(isinf(pinf)>0 && isinf(ninf)<0 && isnan(nan)));
])
#############################################################################
MY_CHECK_FUNCTION(_isnan,
[
#include <float.h>
], [
  exit(_isnan(0.0));
])
#############################################################################

# FreeBSD 3.0 has broken F_SETFD when running with threads.

AC_MSG_CHECKING(whether F_SETFD exists and works)

AC_CACHE_VAL(pike_cv_broken_f_setfd, [
  AC_TRY_RUN([
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#include <sys/stat.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif /* HAVE_FCNTL_H */
#include <stdio.h>
#ifndef FD_CLOEXEC
#define FD_CLOEXEC 1
#endif /* FD_CLOEXEC */
int main(int argc, char **argv)
{
  int fd = 0;
  if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
    exit(1);
  }
  if (fcntl(fd, F_GETFD) != FD_CLOEXEC) {
    exit(1);
  }
  exit(0);
}
], pike_cv_broken_f_setfd=no, pike_cv_broken_f_setfd=yes,
   pike_cv_broken_f_setfd=yes)
])

if test "x$pike_cv_broken_f_setfd" = "xyes"; then
  AC_MSG_RESULT(no)
  AC_DEFINE(HAVE_BROKEN_F_SETFD)
else
  AC_MSG_RESULT(yes)
fi

#############################################################################

AC_STRUCT_TM

#############################################################################

AC_MSG_CHECKING(extern int timezone)

AC_CACHE_VAL(pike_cv_has_external_timezone,[
AC_TRY_LINK([
#include <time.h>
],[
  int _tz;
  _tz=timezone;
  timezone=_tz;
],pike_cv_has_external_timezone=yes,pike_cv_has_external_timezone=no)
])

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

AC_MSG_RESULT($pike_cv_has_external_timezone)

#############################################################################

# No test for this yet...
AC_DEFINE(HAVE_STRUCT_TIMEVAL)

#############################################################################

AC_MSG_CHECKING(struct sockaddr_in6)

AC_CACHE_VAL(pike_cv_has_struct_sockaddr_in6,[
AC_TRY_LINK([
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif /* HAVE_SYS_SOCKET_H */
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif /* HAVE_NETINET_IN_H */
#ifdef HAVE_WINSOCK2_H
#include <WinSock2.h>
#ifdef HAVE_WS2TCPIP_H
#include <WS2tcpip.h>
#endif
#elif defined(HAVE_WINSOCK_H)
#include <winsock.h>
#endif
],[
  struct sockaddr_in6 foo;
],pike_cv_has_struct_sockaddr_in6=yes,pike_cv_has_struct_sockaddr_in6=no)
])

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

AC_MSG_RESULT($pike_cv_has_struct_sockaddr_in6)

#############################################################################

if test $ac_cv_header_malloc_h = yes; then
  AC_MSG_CHECKING(struct mallinfo in malloc.h)
  AC_CACHE_VAL(pike_cv_struct_mallinfo, [
    AC_TRY_LINK([
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
    ], [
      struct mallinfo foo;
    ], pike_cv_struct_mallinfo=yes, pike_cv_struct_mallinfo=no)
  ])
  if test $pike_cv_struct_mallinfo = yes; then
    AC_DEFINE(HAVE_STRUCT_MALLINFO, 1,
	      [Defined if malloc.h contains a struct mallinfo.])
  fi
  AC_MSG_RESULT($pike_cv_struct_mallinfo)
fi

#############################################################################

if test "x$ac_cv_func_strtol" = "xyes"; then
  AC_MSG_CHECKING(if strtol works for large hexadecimal constants)
  AC_CACHE_VAL(pike_cv_func_strtol_works, [
    AC_TRY_RUN([
#include <stdlib.h>
int main(int argc, char **argv)
{
  /* On some OS:s strtol() rounds this to 0x7fffffff. */
  return(strtol("0xffffffff", NULL, 0) != 0xffffffff);
}
    ], pike_cv_func_strtol_works=yes,
       pike_cv_func_strtol_works=no,
       pike_cv_func_strtol_works=no)
  ])
  AC_MSG_RESULT($pike_cv_func_strtol_works)
  if test "x$pike_cv_func_strtol_works" = "xyes"; then
    AC_DEFINE(HAVE_WORKING_STRTOL)
  else :; fi
else :; fi

#############################################################################

#   if test "x$ac_cv_func_gethrtime" != "xyes"; then
#     AC_MSG_CHECKING(if we can make gethrtime by the RDTSC instruction)
#     AC_CACHE_VAL(pike_cv_own_gethrtime_rdtsc, [
#   	 AC_TRY_RUN([
#   #include <unistd.h>
#   #include <stdio.h>
#   #include <sys/time.h>
#   
#   static long long hrtime_rtsc_zero;
#   static long long hrtime_rtsc_last;
#   static long long hrtime_max;
#   static struct timeval hrtime_timeval_zero;
#   static long double hrtime_conv=0.0;
#   
#   #define GETTIMEOFDAY(PTR) gettimeofday(PTR,NULL)
#   
#   #define RTSC(x)   							\
#      __asm__ __volatile__ (  "rdtsc"                			\
#   			       :"=a" (((unsigned long*)&x)[0]), 		\
#   			       "=d" (((unsigned long*)&x)[1]))
#   
#   void own_gethrtime_init()
#   {
#      GETTIMEOFDAY(&hrtime_timeval_zero);
#      RTSC(hrtime_rtsc_zero);
#      hrtime_rtsc_last=hrtime_rtsc_zero;
#      hrtime_max=0;
#   }
#   
#   int own_gethrtime_update(struct timeval *ptr)
#   {
#      long long td,t,now;
#      GETTIMEOFDAY(ptr);
#      RTSC(now);
#      td=((long long)ptr->tv_sec-hrtime_timeval_zero.tv_sec)*1000000000+
#   	  ((long long)ptr->tv_usec-hrtime_timeval_zero.tv_usec)*1000;
#   
#      hrtime_rtsc_last=now;
#      t=now-hrtime_rtsc_zero;
#      if (t) hrtime_conv=((long double)td)/t;
#   
#      return 1;
#   }
#   
#   /* this is very sensitive to the compiler; keep all crap */
#   
#   long long gethrtime()
#   {
#      long long now;
#      struct timeval tv;
#   
#      if (hrtime_conv==0.0) 
#      {
#   	  if (!own_gethrtime_update(&tv))  /* not calibrated yet */
#   	  {
#   	     return
#   		hrtime_max=
#   		((long long)tv.tv_sec-hrtime_timeval_zero.tv_sec)*1000000000+
#   		((long long)tv.tv_usec-hrtime_timeval_zero.tv_usec)*1000;
#   	  }
#      }
#   
#      RTSC(now);
#   
#      if (now-hrtime_rtsc_last > 2000000000) 
#      {
#   	  own_gethrtime_update(&tv);
#   	  return gethrtime();
#      }
#   
#      now = (long long) ( (long double)(now-hrtime_rtsc_zero) * hrtime_conv );
#   
#      if (now<hrtime_max) now=hrtime_max;
#      return hrtime_max=now;
#   }
#   
#   #include <stdio.h>
#   
#   int main()
#   {
#      struct timeval tv1,tv2;
#      long long td,t1,t2;
#      own_gethrtime_init();
#   
#      usleep(10);
#      own_gethrtime_update(&tv2);
#   
#      t1=gethrtime();
#      
#      gettimeofday(&tv1,NULL);
#      for (;;) /* busy loop */
#      {
#   	  GETTIMEOFDAY(&tv2);
#   	  td=((long long)tv2.tv_sec-tv1.tv_sec)*1000000000+
#   	     ((long long)tv2.tv_usec-tv1.tv_usec)*1000;
#   	  if (td>1000000) break;
#      }
#      t2=gethrtime();
#   
#   /*   printf("t2-t1=%lld\n",t2-t1);  */
#   
#      if (t2==hrtime_rtsc_zero ||
#   	   t2-t1>1100000 ||
#   	   t2-t1<900000) return 1;
#   
#      return 0;
#   }], pike_cv_own_gethrtime_rdtsc=yes,
#   	    pike_cv_own_gethrtime_rdtsc=no, pike_cv_own_gethrtime_rdtsc=no)
#   	    ])
#     if test "x$pike_cv_own_gethrtime_rdtsc" = "xyes"; then
#   	AC_MSG_RESULT(yes)
#   	AC_DEFINE(OWN_GETHRTIME)
#   	AC_DEFINE(OWN_GETHRTIME_RDTSC)
#   	AC_DEFINE(HAVE_GETHRTIME)
#     else 
#   	AC_MSG_RESULT([no])
#     fi
#   fi
#   
AC_MSG_CHECKING(if struct tm has tm_gmtoff)

AC_CACHE_VAL(pike_cv_struct_tm_has_gmtoff,[
AC_TRY_COMPILE([
#ifdef TM_IN_SYS_TIME
#include <sys/time.h>
#else
#include <time.h>
#endif
],[
  int _tz;
  struct tm foo;
  _tz=foo.tm_gmtoff;
],pike_cv_struct_tm_has_gmtoff=yes,pike_cv_struct_tm_has_gmtoff=no)
])

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

AC_MSG_RESULT($pike_cv_struct_tm_has_gmtoff)

AC_MSG_CHECKING(if struct tm has __tm_gmtoff)

AC_CACHE_VAL(pike_cv_struct_tm_has___tm_gmtoff,[
AC_TRY_COMPILE([
#ifdef TM_IN_SYS_TIME
#include <sys/time.h>
#else
#include <time.h>
#endif
],[
  int _tz;
  struct tm foo;
  _tz=foo.__tm_gmtoff;
],pike_cv_struct_tm_has___tm_gmtoff=yes,pike_cv_struct_tm_has___tm_gmtoff=no)
])

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

AC_MSG_RESULT($pike_cv_struct_tm_has___tm_gmtoff)

#############################################################################
# iovec

AC_MSG_CHECKING(if struct iovec is defined)
AC_CACHE_VAL(pike_cv_struct_iovec, [
  AC_TRY_COMPILE([
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#include <unistd.h>
#ifdef HAVE_SYS_UIO_H
#include <sys/uio.h>
#endif /* HAVE_SYS_UIO_H */
  ],[
    struct iovec iov;

    iov.iov_base = (void *)0;
    iov.iov_len = 0;
  ], [ pike_cv_struct_iovec=yes ], [ pike_cv_struct_iovec=no ])
])
if test "$pike_cv_struct_iovec" = "yes"; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_STRUCT_IOVEC)
else
  AC_MSG_RESULT(no)
fi

#############################################################################
# msghdr et al.

AC_MSG_CHECKING(if struct msghdr is defined)
AC_CACHE_VAL(pike_cv_struct_msghdr, [
  AC_TRY_COMPILE([
/* Needed for <sys/socket.h> on FreeBSD 4.9. */
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
  ],[
    struct msghdr msg;

    msg.msg_iov = (void *)0;
    msg.msg_iovlen = 0;
  ], [ pike_cv_struct_msghdr=yes ], [ pike_cv_struct_msghdr=no ])
])
if test "$pike_cv_struct_msghdr" = "yes"; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_STRUCT_MSGHDR)

  AC_MSG_CHECKING(if struct msghdr has the member msg_control (XPG 4.2))
  AC_CACHE_VAL(pike_cv_struct_msghdr_msg_control, [
    AC_TRY_COMPILE([
/* Needed for <sys/socket.h> on FreeBSD 4.9. */
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
    ],[
      struct msghdr msg;
  
      msg.msg_control = (void *)0;
      msg.msg_controllen = 0;
    ], [ pike_cv_struct_msghdr_msg_control=yes ], [
      pike_cv_struct_msghdr_msg_control=no ])
  ])
  if test "$pike_cv_struct_msghdr_msg_control" = "yes"; then
    AC_MSG_RESULT(yes)
    AC_DEFINE(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
  else
    AC_MSG_RESULT(no)
  fi

  AC_MSG_CHECKING(if struct msghdr has the member msg_accrights (old BSD))
  AC_CACHE_VAL(pike_cv_struct_msghdr_msg_accrights, [
    AC_TRY_COMPILE([
/* Needed for <sys/socket.h> on FreeBSD 4.9. */
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
    ],[
      struct msghdr msg;
  
      msg.msg_accrights = (void *)0;
      msg.msg_accrightslen = 0;
    ], [ pike_cv_struct_msghdr_msg_accrights=yes ], [
      pike_cv_struct_msghdr_msg_accrights=no ])
  ])
  if test "$pike_cv_struct_msghdr_msg_accrights" = "yes"; then
    AC_MSG_RESULT(yes)
    AC_DEFINE(HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS)
  else
    AC_MSG_RESULT(no)
  fi

else
  AC_MSG_RESULT(no)
fi

#############################################################################

AC_MSG_CHECKING(for USHRT_MAX definition)

AC_CACHE_VAL(pike_cv_ushrt_max_is_defined,[
AC_EGREP_CPP(oui,[
#include <limits.h>
#ifdef USHRT_MAX
oui
#endif
],pike_cv_ushrt_max_is_defined=yes,pike_cv_ushrt_max_is_defined=no)
])

if test "$pike_cv_ushrt_max_is_defined" = "no" ; then
  AC_DEFINE(USHRT_MAX,65535)
fi

AC_MSG_RESULT($pike_cv_ushrt_max_is_defined)

define(MY_CHECK_HEADERS,
[
 AC_MSG_CHECKING(for $1 declaration)
 AC_CACHE_VAL(pike_cv_decl_$1,
 [
   OLD_CPPFLAGS="$CPPFLAGS"
   pike_cv_decl_$1=nonexistent
   for a in $2
   do
     AC_EGREP_HEADER($1,$a,[ pike_cv_decl_$1=existent; break ])
     
     # Kludge for MacOS X. Retry with the traditional cpp...
     CPPFLAGS="$CPPFLAGS -traditional-cpp"
     AC_EGREP_HEADER($1,$a,[ pike_cv_decl_$1=existent; break ])
     CPPFLAGS="$OLD_CPPFLAGS"
   done
   CPPFLAGS="$OLD_CPPFLAGS"
 ])
 AC_MSG_RESULT($pike_cv_decl_$1)
 if test "$pike_cv_decl_$1" = nonexistent -o "$pike_cv_decl_$1" = nonexistant; then
   AC_DEFINE(translit($1,[a-z],[A-Z])[]_DECL_MISSING)
 fi
])

MY_CHECK_HEADERS(strchr,string.h unistd.h stdlib.h)
MY_CHECK_HEADERS(malloc,memory.h unistd.h stdlib.h)
MY_CHECK_HEADERS(getpeername,sys/socket.h sys/socketvar.h sys/socketio.h winsock.h winsock2.h ws2tcpip.h)
MY_CHECK_HEADERS(popen,stdio.h unistd.h)
MY_CHECK_HEADERS(getenv,unistd.h stdlib.h)
MY_CHECK_HEADERS(gethostname,unistd.h netdb.h winsock.h winsock2.h ws2tcpip.h)

AC_ALLOCA

AC_C_CONST
AC_C_INLINE

AC_CHECK_FUNCS(ualarm setitimer)

if test "x$ac_cv_func_ualarm" = "xyes"; then
  AC_MSG_CHECKING(no of arguments to ualarm)
  AC_CACHE_VAL(pike_cv_ualarm_takes_two_args,
  [
    AC_TRY_COMPILE([
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
    ],[
      ualarm(0,0);
    ],pike_cv_ualarm_takes_two_args=yes,pike_cv_ualarm_takes_two_args=no)
  ])
  if test "$pike_cv_ualarm_takes_two_args" = yes; then
    AC_MSG_RESULT(2)
    AC_DEFINE(UALARM_TAKES_TWO_ARGS)
  else
    AC_MSG_RESULT(1)
  fi
fi

if test "x$ac_cv_func_ptrace" = "xyes"; then
  AC_MSG_CHECKING(no of arguments to ptrace)
  AC_CACHE_VAL(pike_cv_ptrace_takes_four_args,
  [
    AC_TRY_COMPILE([
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#ifdef HAVE_SYS_PTRACE_H
#include <sys/ptrace.h>
#endif /* HAVE_SYS_PTRACE_H */
    ],[
      ptrace(0,0,0,0);
    ],pike_cv_ptrace_takes_four_args=yes,pike_cv_ptrace_takes_four_args=no)
  ])
  if test "$pike_cv_ptrace_takes_four_args" = yes; then
    AC_MSG_RESULT(4)
    AC_DEFINE(PTRACE_TAKES_FOUR_ARGS)
  else
    AC_MSG_RESULT(5)
  fi
  AC_MSG_CHECKING([type of argument 3 (addr) to ptrace])
  AC_CACHE_VAL(pike_cv_ptrace_addr_type, [
    AC_TRY_COMPILE([
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#ifdef HAVE_SYS_PTRACE_H
#include <sys/ptrace.h>
#endif /* HAVE_SYS_PTRACE_H */
    ],[
#ifdef PTRACE_TAKES_FOUR_ARGS
      ptrace(0,0,(void *)0,0);
#else
      ptrace(0,0,(void *)0,0,0);
#endif
    ],pike_cv_ptrace_addr_type=pointer,pike_cv_ptrace_addr_type=integer)
  ])
  if test "$pike_cv_ptrace_addr_type" = pointer; then
    AC_MSG_RESULT(pointer)
    AC_DEFINE(PTRACE_ADDR_TYPE_IS_POINTER)
  else
    AC_MSG_RESULT([integer (SVID)])
  fi
fi



########################################################################
AC_MSG_CHECKING(stack direction)
AC_CACHE_VAL(pike_cv_hardware_stack_direction,
[
  AC_TRY_RUN([
#include <stdio.h>
static int find_stack_direction(void *foo, int cnt)
{
  if (cnt) return 1*find_stack_direction(foo, cnt>>1);
  if (((void *)&foo) > foo) {
    return 1;
  } else {
    return -1;
  }
}

int main() { void *bar; exit( find_stack_direction(&bar, 0x10) > 0); }
  ], [ pike_cv_hardware_stack_direction=down
  ], [ pike_cv_hardware_stack_direction=up
  ], [
    AC_MSG_WARN([Defaulting to down.])
    pike_cv_hardware_stack_direction=down
  ])
])

AC_MSG_RESULT($pike_cv_hardware_stack_direction)

if grep STACK_DIRECTION confdefs.h >/dev/null 2>&1; then
  :
elif test "x$pike_cv_hardware_stack_direction" = "xup" ; then
  AC_DEFINE(STACK_DIRECTION, 1)
else
  AC_DEFINE(STACK_DIRECTION, -1)
fi

########################################################################

AC_MSG_CHECKING(byteorder)
AC_CACHE_VAL(pike_cv_hardware_byteorder,
[
if test "x$enable_binary" = "xno"; then
  pike_cv_hardware_byteorder=0
else
AC_TRY_RUN([
#include <stdio.h>

int main()
{
#if SIZEOF_INT == 4
#define T int
#else
#define T long
#endif
  FILE *f;
  T a;
  int e;
  for(e=0;e<sizeof(T);e++)
    ((char *)&a)[e]=(e+1) % 10;

  f=fopen("conftest.out.2","w");
  for(e=0;e<sizeof(T);e++)
  {
    fprintf(f,"%d",(int)(a & 255));
    a>>=8;
  }
  fprintf(f,"\n");
  fclose(f);
  
  return 0;
}],
pike_cv_hardware_byteorder=`cat conftest.out.2`
,
pike_cv_hardware_byteorder=0
,
pike_cv_hardware_byteorder=0
)
fi
])

AC_MSG_RESULT($pike_cv_hardware_byteorder)
AC_DEFINE_UNQUOTED(PIKE_BYTEORDER,$pike_cv_hardware_byteorder)

########################################################################

AC_MSG_CHECKING(pointer alignment)
AC_CACHE_VAL(pike_cv_hardware_alignment,
[
  if test "x$enable_binary" = "xno"; then
    pike_cv_hardware_alignment=4
  else
    AC_TRY_RUN([
#include <stdio.h>

struct x { char a; void *b; };

struct y { void *a; char b; };

int main(int argc, char *argv[])
{
  FILE *f;
  int align = (int)&(((struct x *)0)->b);
  if (align > sizeof(struct y)-sizeof(void *))
    align = sizeof(struct y) - sizeof(void *);

  if(!(f=fopen("conftest.out.2","w")))
    return 1;

  fprintf(f, "%d\n", align);
  fclose(f);
  return 0;
}
    ],
      pike_cv_hardware_alignment=`cat conftest.out.2`,
      pike_cv_hardware_alignment=4,
      pike_cv_hardware_alignment=4
    )
  fi
])

AC_MSG_RESULT($pike_cv_hardware_alignment)
AC_DEFINE_UNQUOTED(PIKE_POINTER_ALIGNMENT,$pike_cv_hardware_alignment)

#############################################################################

## Check if we should default to --with-machine-code

#############################################################################

if test "$with_machine_code" = "no"; then :; else

  AC_MSG_CHECKING(machine code architecture)
  AC_CACHE_VAL(pike_cv_machine_code_arch, [
    pike_cv_machine_code_arch=unknown
    AC_TRY_COMPILE([
#if defined(__GNUC__)
#if !defined(__i386__) && !defined(__i386)
#error Not ia32 architecture
#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
#error Not supported with gcc 4.6.0 and later.
#endif
#elif defined(_MSC_VER)
#if !defined(_M_IX86)
#error Not ia32 architecture
#endif
#else
#error Unsupported compiler
#endif
    ], [], [
      pike_cv_machine_code_arch=ia32
    ], [])
    AC_TRY_COMPILE([
#if defined(__GNUC__)
#if !defined(sparc) && !defined(__sparc__) && !defined(__sparc)
#error Not sparc architecture
#endif
#else
#error Unsupported compiler
#endif
    ], [], [
      pike_cv_machine_code_arch=sparc
    ], [])
    AC_TRY_COMPILE([
#if defined(__GNUC__)
#if !defined(__ppc__) && !defined(__powerpc__) && !defined(_POWER)
#error Not ppc32 architecture
#endif
#else
#error Unsupported compiler
#endif
    ], [], [
      pike_cv_machine_code_arch=ppc32
    ], [])
    AC_TRY_COMPILE([
#if defined(__GNUC__)
#if !defined(__PPC64__) && !defined(__powerpc64__)
#error Not ppc64 architecture
#endif
#else
#error Unsupported compiler
#endif
    ], [], [
      pike_cv_machine_code_arch=ppc64
    ], [])
  ])
  AC_MSG_RESULT($pike_cv_machine_code_arch)
  if test "x$pike_cv_machine_code_arch" = xunknown ; then
    with_machine_code="no"
  else
    with_machine_code="yes"
    AC_DEFINE(PIKE_USE_MACHINE_CODE)
    case "x$pike_cv_machine_code_arch" in
      xia32)
        # Force gmp to build for ia32 and not for x86_64.
        BUNDLE_FLAGS="$BUNDLE_FLAGS --build=i486"
      ;;
    esac
  fi
fi

########################################################################

if test yes = "$with_machine_code"; then
  AC_MSG_CHECKING(register name convention)
  AC_CACHE_VAL(pike_cv_cpu_reg_prefix,
  [
    for pike_cv_cpu_reg_prefix in "default" "" "r" "%%" "%%r" "unknown"; do
      AC_TRY_COMPILE([
#define REGPREFIX "$pike_cv_cpu_reg_prefix"
  ], [
#if defined(__ppc__) || defined(__powerpc__) || defined(_POWER)
	__asm__ __volatile__(" li "REGPREFIX"11,1");
#else
	; /* Do not need to find out */
#endif
    ],[break])
    done
  ])
  case "$pike_cv_cpu_reg_prefix" in
    default|unknown) AC_MSG_RESULT($pike_cv_cpu_reg_prefix);;
    *) AC_MSG_RESULT(${pike_cv_cpu_reg_prefix}0)
       AC_DEFINE_UNQUOTED(PIKE_CPU_REG_PREFIX,"$pike_cv_cpu_reg_prefix");;
  esac
else :; fi

########################################################################
MY_CHECK_FUNCTION(fork,
[
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
], [
  exit(fork()==-1);
])

########################################################################
MY_CHECK_FUNCTION(fpsetmask,
[
#include <math.h>
#ifdef HAVE_FLOATINGPOINT_H
#include <floatingpoint.h>
#endif

#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
], [
  fpsetmask(0);
  exit(0);
])
########################################################################
MY_CHECK_FUNCTION(fpsetround,
[
#include <math.h>
#ifdef HAVE_FLOATINGPOINT_H
#include <floatingpoint.h>
#endif

#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif

#ifndef FP_RN
#define FP_RN 0
#endif /* FP_RN */
], [
  fpsetround(FP_RN);
  exit(0);
])
########################################################################
MY_CHECK_FUNCTION(isless,
[
#include <math.h>
#ifdef HAVE_FLOATINGPOINT_H
#include <floatingpoint.h>
#endif

#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif

], [
  int t = isless(0.0, 0.0);
  exit(0);
])
########################################################################
MY_CHECK_FUNCTION(isunordered,
[
#include <math.h>
#ifdef HAVE_FLOATINGPOINT_H
#include <floatingpoint.h>
#endif

#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif

], [
  int t = isunordered(0.0, 0.0);
  exit(0);
])
########################################################################
MY_CHECK_FUNCTION(dlopen,
[
#include <dlfcn.h>
], [
  dlopen(0, 0);
  exit(0);
])
########################################################################

MY_CHECK_FUNCTION(ldexp,
[
#include <math.h>
], [
  double x;
  int p;

  for(x=0.0;x<2.0;x+=1.0/64.0)
    for(p=-6;p<7;p++)
      if(ldexp(x,p) != x*pow(2.0, (double)p))
	exit(1);
    exit(0);
])

########################################################################
MY_CHECK_FUNCTION(rint,
[
#include <math.h>
#ifdef HAVE_FLOATINGPOINT_H
#include <floatingpoint.h>
#endif

#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif /* HAVE_IEEEFP_H */
], [
#ifdef HAVE_FPSETROUND
  /* Round to nearest */
#ifndef FP_RN
#define FP_RN 0
#endif /* FP_RN */
  fpsetround(FP_RN);
#endif /* HAVE_FPSETROUND */
  if(rint(0.1) != 0.0 ||
     rint(0.6) != 1.0) exit(1);
  exit(0);
])

########################################################################

MY_CHECK_FUNCTION(frexp,
[
#include <math.h>
], [
  double x,y;
  int p,e;

  x=frexp(1.0, &e);
  if(x * pow(2.0,(double)e) != 1.0) exit(3);

  p=-7;
  for(x=3.0/4.0*pow(2.0,(double)p);x<50000.0;x*=2.0,p++)
  {
    if(frexp(x, &e)!=3.0/4.0) exit(1);
    if(e!=p) exit(2);
  }
  exit(0);
])

#############################################################################
MY_CHECK_FUNCTION(GetSystemTimeAsFileTime,
[
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif
#ifdef HAVE_WINBASE_H
#include <winbase.h>
#endif
], [
  FILETIME f;
  GetSystemTimeAsFileTime(&f);
  exit(0);
])
#############################################################################
MY_CHECK_FUNCTION(gethostname,
[
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#elif defined(HAVE_WINSOCK_H)
#include <winsock.h>
#endif
], [
  char buffer[10000];
  char *x=gethostname(buffer,sizeof(buffer));
  exit(0);
])
#############################################################################
MY_CHECK_FUNCTION(strcoll,
[
#include <string.h>
#include <locale.h>
], [
  setlocale(LC_CTYPE, "ISO-8859-1");
  exit(strcoll("abc", "def") >= 0 ||
       strcoll("ABC", "DEF") >= 0 ||
       strcoll("ABC", "ABCD") >= 0 ||
       strcoll("ABCD", "ABC") <= 0 ||
       strcoll("*^#", "*^#") != 0 ||
       strcoll("123", "456") >= 0);
])

########################################################################

MY_CHECK_FUNCTION(memmem,
[
#include <string.h>
char *a="foo bar gazonk";
char *b="foo";
char *c="bar";
char *d="gazonk";
], [
  if(((char *)memmem(b,strlen(b),a,strlen(a)))!=a ||
     ((char *)memmem(c,strlen(c),a,strlen(a)))!=(a+4) ||
     ((char *)memmem(d,strlen(d),a,strlen(a)))!=(a+8) ||
     ((char *)memmem(d,0,a,strlen(a)))!=a ||
     memmem(d,strlen(d)+1,a,strlen(a))!=0)
    exit(1);
  exit(0);
])

########################################################################

MY_CHECK_FUNCTION(memcpy,
[
#include <string.h>
char *a="foo bar gazonk";
char foo[23];
], [
  memcpy(foo, a, strlen(a)+1);
  memcpy(foo, a+4, 3);
  if(strcmp(foo,"bar bar gazonk")) exit(1);
  exit(0);
])

########################################################################

MY_CHECK_FUNCTION(memset,
[
#ifdef HAVE_STDDEF_H
#include <stddef.h>
#endif /* HAVE_STDDEF_H */
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif /* HAVE_STDLIB_H */
#include <stdio.h>
#include <string.h>
char foo[23];

struct pike_string {
  int refs;
  int size_shift;
  ptrdiff_t len;
  size_t hval;
  struct pike_string *next;
  char str[1];
};

struct pike_string *begin_shared_string(int len)
{
  return (struct pike_string *)malloc(sizeof(struct pike_string) + len);
}

], [
  int i;
  struct pike_string *str;
  ptrdiff_t len;

  memset(foo, 0, 11);
  memset(foo, 'a', 10);
  memset(foo, 'b', 5);
  fprintf(stderr, "1\n");
  if(strcmp(foo,"bbbbbaaaaa")) {
    exit(1);
  }
  memset(foo, 0, 6);
  fprintf(stderr, "2\n");
  for (i=6; i--;) {
    if (foo[i]) {
      exit(1);
    }
  }
  memset(foo+1, 1, 6);
  fprintf(stderr, "3\n");
  for (i=6; i--;) {
    if (foo[i+1] != 1) {
      exit(1);
    }
  }
  memset(foo+2, 0, 6);
  fprintf(stderr, "4\n");
  for (i=6; i--;) {
    if (foo[i+2]) {
      exit(1);
    }
  }
  memset(foo+3, 1, 6);
  fprintf(stderr, "5\n");
  for (i=6; i--;) {
    if (foo[i+3] != 1) {
      exit(1);
    }
  }
  memset(foo+4, 0, 6);
  fprintf(stderr, "6\n");
  for (i=6; i--;) {
    if (foo[i+4]) {
      exit(1);
    }
  }
  memset(foo+5, 1, 6);
  fprintf(stderr, "7\n");
  for (i=6; i--;) {
    if (foo[i+5] != 1) {
      exit(1);
    }
  }
  memset(foo+6, 0, 6);
  fprintf(stderr, "8\n");
  for (i=6; i--;) {
    if (foo[i+6]) {
      exit(1);
    }
  }
  memset(foo+7, 1, 6);
  fprintf(stderr, "9\n");
  for (i=6; i--;) {
    if (foo[i+7] != 1) {
      exit(1);
    }
  }

  len = 6;
  str = begin_shared_string(len);

  fprintf(stderr, "string start\n");
  if (!str) exit(1);

  for (i=len; i--;) {
    str->str[i] = ~0;
  }
  memset(str->str, 0, len);
  fprintf(stderr, "string end\n");
  for (i = len; i--;) {
    if (str->str[i]) {
      exit(1);
    }
  }
  free(str);
  exit(0);
])

########################################################################

MY_CHECK_FUNCTION(memmove,
[
#include <string.h>
char buf[100];
], [
  strcpy(buf,"foo bar gazonk elefantsnabel.");
  if(strcmp(buf,"foo bar gazonk elefantsnabel.")) exit(1);
  memmove(buf,buf+1,7);
  if(strcmp(buf,"oo bar  gazonk elefantsnabel.")) exit(1);
  memmove(buf+1,buf+1,9);
  if(strcmp(buf,"oo bar  gazonk elefantsnabel.")) exit(1);
  memmove(buf+1,buf,11);
  if(strcmp(buf,"ooo bar  gaznk elefantsnabel.")) exit(1);
  exit(0);
])

########################################################################

MY_CHECK_FUNCTION(isspace,
[
#include <ctype.h>
], [
  if(isspace(' ')) exit(0);
  exit(1);
])

#############################################################################

AC_MSG_CHECKING(if we can declare environ)
AC_CACHE_VAL(pike_cv_declare_environ,[
AC_TRY_COMPILE([
#include <stdlib.h>
],[
  extern char **environ;
  exit(0);
],pike_cv_declare_environ=yes,pike_cv_declare_environ=no,pike_cv_declare_environ=yes)
])

AC_MSG_RESULT($pike_cv_declare_environ)
if test "x$pike_cv_declare_environ" = xyes ; then
  AC_DEFINE(DECLARE_ENVIRON)
fi

#############################################################################

AC_MSG_CHECKING([for union wait (old BSD convention)])
AC_CACHE_VAL(pike_cv_union_wait, [ AC_TRY_COMPILE([
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif /* HAVE_SYS_WAIT_H */
], [
  union wait status;
  exit(0);
], pike_cv_union_wait=yes, pike_cv_union_wait=no)
])

AC_MSG_RESULT($pike_cv_union_wait)
if test "x$pike_cv_union_wait" = "xyes" ; then
  AC_MSG_CHECKING([whether union wait is really needed])
  AC_CACHE_VAL(pike_cv_union_wait_needed, [ AC_TRY_COMPILE([
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif /* HAVE_SYS_WAIT_H */
], [
  int status;
  return WIFEXITED(status) || 0;
], pike_cv_union_wait_needed=no, pike_cv_union_wait_needed=yes)
])
  AC_MSG_RESULT($pike_cv_union_wait_needed)
  if test "x$pike_cv_union_wait_needed" = "xyes" ; then
    AC_DEFINE(HAVE_UNION_WAIT)
  else :; fi
else :; fi

#############################################################################

AC_MSG_CHECKING(how to extract an unsigned char)
AC_CACHE_VAL(pike_cv_method_extract_uchar,
[
AC_TRY_RUN([
int main()
{
  char i,*p;
  i=-10;
  p=&i;
  if(*(unsigned char *)(p)!= 0x100 - 10) exit(1);
  exit(0);
}
],pike_cv_method_extract_uchar=by_cast,
pike_cv_method_extract_uchar=not_by_cast,
pike_cv_method_extract_uchar=not_by_cast)])

if test "$pike_cv_method_extract_uchar" = by_cast; then
  AC_MSG_RESULT(by cast)
  AC_DEFINE(EXTRACT_UCHAR_BY_CAST)
else
  AC_MSG_RESULT(not by cast)
fi

########################################################################

AC_MSG_CHECKING(how to extract a signed char)
AC_CACHE_VAL(pike_cv_method_extract_char,
[
AC_TRY_RUN([
int main()
{
  char i,*p;
  i=-10;
  p=&i;
  if(*(signed char *)(p)!= -10) exit(1);
  exit(0);
}
],pike_cv_method_extract_char=by_cast,
pike_cv_method_extract_char=not_by_cast,
pike_cv_method_extract_char=not_by_cast)])

if test "$pike_cv_method_extract_char" = by_cast; then
  AC_MSG_RESULT(by cast)
  AC_DEFINE(EXTRACT_CHAR_BY_CAST)
else
  AC_MSG_RESULT(not by cast)
fi

#############################################################################
AC_ARG_WITH(mmx, MY_DESCR([--without-mmx], [disable MMX usage]), [], [with_mmx=])

mmx_reason=' (no mmx.h found)'
if test "x$with_mmx" = xno; then
   mmx_reason=' (--without-mmx)'
   unset pike_cv_sys_has_working_mmx
elif test "x$ac_cv_header_mmx_h" = xyes -o "x$ac_cv_header_asm_mmx_h" = xyes; then
  AC_MSG_CHECKING(for working MMX)
  mmx_reason=' (mmx.h found, but mmx operations failed)'

  AC_CACHE_VAL(pike_cv_sys_has_working_mmx,
  [
    AC_TRY_LINK([
#ifdef HAVE_MMX_H
#include <mmx.h>
#endif
#ifdef HAVE_ASM_MMX_H
#include <asm/mmx.h>
#endif
    ],[
    {
      int try_use_mmx;
      char a[8];
      movq_m2r( *a, mm0 );
      paddb_r2r( mm0, mm0 );
      movq_r2m( mm0, *a );
      try_use_mmx=mmx_ok();
    }
    ],pike_cv_sys_has_working_mmx=yes,pike_cv_sys_has_working_mmx=no)
  ])

  AC_MSG_RESULT($pike_cv_sys_has_working_mmx)

  if test "x$pike_cv_sys_has_working_mmx" = xyes ; then
    AC_DEFINE(TRY_USE_MMX)
    mmx_reason=''
  else :; fi

  if test "x$with_copt" = "xno"; then
    PIKE_MSG_WARN([--without-mmx is advisable when using --without-copt.])
  fi
else :; fi

#############################################################################

AC_MSG_CHECKING(if float conversion can cause SIGFPE)
AC_CACHE_VAL(pike_cv_sys_idiot_sigfpe,
[
 AC_TRY_RUN([
#include <math.h>

#ifdef HAVE_FLOATINGPOINT_H
#include <floatingpoint.h>
#endif

#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif

float foo_float = 0.0;

int main(int argc, char **argv)
{
  float x=2.0, y=-128.0;
#ifdef HAVE_FPSETMASK
  fpsetmask(0);
#endif
  x = pow(2.0, -128.0);
  foo_float = x;
  if (x == 2.0) exit(1);
  x = pow(2.0, 1024.0);
  foo_float = x;
  if(x == 2.0) exit(1);
  exit(0);
}
],pike_cv_sys_idiot_sigfpe=no,pike_cv_sys_idiot_sigfpe=yes,
  pike_cv_sys_idiot_sigfpe=yes)
])

if test $pike_cv_sys_idiot_sigfpe = yes ; then
  AC_MSG_RESULT(yes)

  IEEE_FLAG=no
  if test "x${GCC-}" = xyes ; then
    AC_SYS_COMPILER_FLAG(-mieee, mieee, CFLAGS,[],IEEE_FLAG=yes)
  else
    AC_SYS_COMPILER_FLAG(-ieee, ieee, CFLAGS,[],IEEE_FLAG=yes)
  fi
  TEST_IGNORE_SIGFPE=yes

  if test $IEEE_FLAG = yes; then
    AC_MSG_CHECKING(if float conversion is still broken)
    AC_CACHE_VAL(pike_cv_sys_idiot_sigfpe_with_ieee,
[
 OLD_CFLAGS="$CFLAGS"
 CFLAGS="$CFLAGS $OPTIMIZE"
 AC_TRY_RUN([
#include <math.h>

#ifdef HAVE_FLOATINGPOINT_H
#include <floatingpoint.h>
#endif

#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif

float foo_float = 0.0;

int main(int argc, char **argv)
{
  float x=2.0, y=-128.0;
#ifdef HAVE_FPSETMASK
  fpsetmask(0);
#endif
  x = pow(2.0, -128.0);
  foo_float = x;
  if (x == 2.0) exit(1);
  x = pow(2.0, 1024.0);
  foo_float = x;
  if(x == 2.0) exit(1);
  exit(0);
}
],pike_cv_sys_idiot_sigfpe_with_ieee=no,pike_cv_sys_idiot_sigfpe_with_ieee=yes,
  pike_cv_sys_idiot_sigfpe_with_ieee=yes)
  CFLAGS="$OLD_CFLAGS"
])
   
  if test $pike_cv_sys_idiot_sigfpe_with_ieee = yes ; then
    AC_MSG_RESULT(yes)
  else
    AC_MSG_RESULT(no)
    TEST_IGNORE_SIGFPE=no
  fi
fi # IEEE_FLAG

if test $TEST_IGNORE_SIGFPE = yes; then
  AC_MSG_CHECKING(if ignoring SIGFPE helps)
  AC_CACHE_VAL(pike_cv_sys_ignore_sigfpe,
[
 OLD_CFLAGS="$CFLAGS"
 CFLAGS="$CFLAGS $OPTIMIZE"
AC_TRY_RUN([
#include <signal.h>
#include <math.h>
int counter=0;
RETSIGTYPE func(void)
{
 if(counter++>10) exit(7);
 signal(SIGFPE,func);
}

float foo_float = 0.0;

int main(int argc, char **argv)
{
  float x=2.0, y=-128.0;
  signal(SIGFPE,func);
  x = pow(2.0, -128.0);
  foo_float = x;
  if (x == 2.0) exit(1);
  x = pow(2.0, 1024.0);
  foo_float = x;
  if(x == 2.0) exit(1);
  exit(0);
}
],pike_cv_sys_ignore_sigfpe=yes,pike_cv_sys_ignore_sigfpe=no,
  pike_cv_sys_ignore_sigfpe=yes)
  CFLAGS="$OLD_CFLAGS"
])

if test "$pike_cv_sys_ignore_sigfpe" = yes; then
 AC_MSG_RESULT(yes)
 AC_DEFINE(IGNORE_SIGFPE)
else
 AC_MSG_RESULT(no)
fi
fi # TEST_IGNORE_SIGFPE

else
 AC_MSG_RESULT(no)
fi # pike_cv_sys_idiot_sigfpe

#############################################################################

define(float_check, [[
#include <math.h>
#define TY $1
#define TEST_$1
#define TEST_$2
#define EXPECTED_SIZE_float 4
#define EXPECTED_SIZE_double 8
void check(TY n, char *pf, char *pd)
{
  int i;
  char *p, *p2 = (char*)&n;
#ifdef TEST_float
    p = pf;
#else
    p = pd;
#endif
  for(i=0; i<sizeof(TY); i++)
#ifdef TEST_BIG
    if(p[i] != p2[i])
      exit(1);
#else
    if(p[i] != p2[sizeof(TY)-i-1])
      exit(1);
#endif
}
int main()
{
  if(sizeof(TY)!=EXPECTED_SIZE_$1)
    exit(1);
  check((TY)0.0, "\000\000\000\000", "\000\000\000\000\000\000\000\000");
  check((TY)1.0, "\077\200\000\000", "\077\360\000\000\000\000\000\000");
  check((TY)-1.0, "\277\200\000\000", "\277\360\000\000\000\000\000\000");
  check((TY)2.0, "\100\000\000\000", "\100\000\000\000\000\000\000\000");
  check((TY)1.5, "\077\300\000\000", "\077\370\000\000\000\000\000\000");
  check((TY)0.032999999821186065673828125, "\075\007\053\002", "\077\240\345\140\100\000\000\000");
  exit(0);
}
]])

AC_MSG_CHECKING(for type of float)
AC_CACHE_VAL(pike_cv_float_type, [
  AC_TRY_RUN(float_check(float,BIG), pike_cv_float_type=ieee_big, [
    AC_TRY_RUN(float_check(float,LITTLE), pike_cv_float_type=ieee_little,
      pike_cv_float_type=not_ieee, pike_cv_float_type=not_ieee)
  ], [
    echo $ac_n "crosscompiling... $ac_c" 1>&6
    # Use some magical constants...
    cat > conftest.$ac_ext <<EOF
dnl This sometimes fails to find confdefs.h, for some reason.
dnl [#]line __oline__ "[$]0"
[#]line __oline__ "configure"
#include "confdefs.h"
#include <stdio.h>
float float_info[[]] = {
  0.0,
  14914788644012054221422592.0, 16305677175569252352.0,
  0.0
};
EOF
    if AC_TRY_EVAL(ac_compile); then
      if test -f "conftest.$ac_objext"; then
        if strings "conftest.$ac_objext" | grep "iEeE_bIg" >/dev/null; then
	  pike_cv_float_type=ieee_big
        elif strings "conftest.$ac_objext" | grep "EeEigIb_" >/dev/null; then
	  pike_cv_float_type=ieee_little
	else
	  pike_cv_float_type=not_ieee
	fi
      else
        AC_MSG_WARN([Object file not found - using default.])
	pike_cv_float_type=not_ieee
      fi
    else
      pike_cv_float_type=not_ieee
    fi
    rm -rf conftest*
  ])
])
if test "$pike_cv_float_type" = ieee_big; then
  AC_MSG_RESULT(IEEE big endian)
  AC_DEFINE(FLOAT_IS_IEEE_BIG)
elif test "$pike_cv_float_type" = ieee_little; then
  AC_MSG_RESULT(IEEE little endian)
  AC_DEFINE(FLOAT_IS_IEEE_LITTLE)
else
  AC_MSG_RESULT(not IEEE)
fi

AC_MSG_CHECKING(for type of double)
AC_CACHE_VAL(pike_cv_double_type, [
  AC_TRY_RUN(float_check(double,BIG), pike_cv_double_type=ieee_big, [
    AC_TRY_RUN(float_check(double,LITTLE), pike_cv_double_type=ieee_little,
      pike_cv_double_type=not_ieee, pike_cv_double_type=not_ieee)
  ], [
    echo $ac_n "crosscompiling... $ac_c" 1>&6
    # Use some magical constants...
    cat > conftest.$ac_ext <<EOF
dnl This sometimes fails to find confdefs.h, for some reason.
dnl [#]line __oline__ "[$]0"
[#]line __oline__ "configure"
#include "confdefs.h"
#include <stdio.h>
double double_info[[]] = {
  0.0,
  12794738495187527498222028847205909954314554441725728393516969126669975252147490126864122090122288822751876426313291683594796075946303753742007913302630260537160845833197547903208108732031187791380480.0,
  0.0
};
EOF
    if AC_TRY_EVAL(ac_compile); then
      if test -f "conftest.$ac_objext"; then
        if strings "conftest.$ac_objext" | grep "iEeE_bIg" >/dev/null; then
	  pike_cv_double_type=ieee_big
        elif strings "conftest.$ac_objext" | grep "gIb_EeEi" >/dev/null; then
	  pike_cv_double_type=ieee_little
	else
	  pike_cv_double_type=not_ieee
	fi
      else
        AC_MSG_WARN([Object file not found - using default.])
	pike_cv_float_type=not_ieee
      fi
    else
      pike_cv_float_type=not_ieee
    fi
    rm -rf conftest*
  ])
])
if test "$pike_cv_double_type" = ieee_big; then
  AC_MSG_RESULT(IEEE big endian)
  AC_DEFINE(DOUBLE_IS_IEEE_BIG)
elif test "$pike_cv_double_type" = ieee_little; then
  AC_MSG_RESULT(IEEE little endian)
  AC_DEFINE(DOUBLE_IS_IEEE_LITTLE)
else
  AC_MSG_RESULT(not IEEE)
fi

#############################################################################

AC_MSG_CHECKING(for volatile)
AC_CACHE_VAL(pike_cv_volatile,
[
 AC_TRY_COMPILE([],[ volatile int foo=1;], pike_cv_volatile=yes,pike_cv_volatile=no)
])

if test "$pike_cv_volatile" = yes; then
 AC_MSG_RESULT(yes)
 AC_DEFINE(VOLATILE,volatile)
else
 AC_MSG_RESULT(no)
 AC_DEFINE(VOLATILE,)
fi

########################################################################

AC_MSG_CHECKING(for sig_atomic_t)
AC_CACHE_VAL(ac_cv_type_sig_atomic_t,
[
  AC_EGREP_CPP(sig_atomic_t, [
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
#ifdef HAVE_CRT_SIGNAL_H
#include <crt/signal.h>
#endif
#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif
  ], ac_cv_type_sig_atomic_t=yes, ac_cv_type_sig_atomic_t=no)
])
AC_MSG_RESULT($ac_cv_type_sig_atomic_t)
if test x"$ac_cv_type_sig_atomic_t" = xno; then
  AC_DEFINE(sig_atomic_t, int)
else
  :
fi

AC_MSG_CHECKING(if signal handlers reset automatically)
AC_CACHE_VAL(pike_cv_sys_signal_oneshot,
[
  AC_TRY_RUN([
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
VOLATILE sig_atomic_t sigrun[2]= { 0, 0 };
RETSIGTYPE func(int sig)
{
  write(2, "func called\n", sizeof("func called\n") - sizeof(""));
  sigrun[0] = -1;
}

int main()
{
#define sig SIGSEGV

#ifdef HAVE_SIGACTION
  {
    static struct sigaction action;
    action.sa_handler= func;
    sigfillset(&action.sa_mask);
#ifdef SA_INTERRUPT
    action.sa_flags=SA_INTERRUPT;
#endif
    sigaction(sig,&action,0);
  }
#else
#ifdef HAVE_SIGVEC
  {
    static struct sigvec action;
    action.sv_handler= func;
    action.sv_mask=-1;
#ifdef SV_INTERRUPT
    action.sv_flags=SV_INTERRUPT;
#endif
    sigvec(sig,&action,0);
  }
#else
  signal(sig, func);
#endif
#endif

  kill(getpid(), sig);
#ifdef HAVE_POLL
  struct pollfd sentinel;
  while(!strlen((char *)sigrun)) poll(&sentinel,0,100);
#else
  while(!strlen((char *)sigrun)) sleep(1);
#endif
  sigrun[0]=0;
  kill(getpid(), sig);
#ifdef HAVE_POLL
  while(!strlen((char *)sigrun)) poll(&sentinel,0,100);
#else
  while(!strlen((char *)sigrun)) sleep(1);
#endif
  sigrun[0]=0;
  exit(0);
}
  ],pike_cv_sys_signal_oneshot=no,pike_cv_sys_signal_oneshot=yes,pike_cv_sys_signal_oneshot=yes)
])

if test "$pike_cv_sys_signal_oneshot" = yes; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(SIGNAL_ONESHOT)
else
  AC_MSG_RESULT(no)
fi

########################################################################

AC_MSG_CHECKING(available file descriptors)
AC_CACHE_VAL(pike_cv_max_open_fd,
[
  if test "x$enable_binary" = "xno"; then
    pike_cv_max_open_fd=256
  else
    AC_TRY_RUN([
#include <stdio.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif

#ifndef MAX_FD
#define MAX_FD 65536
#endif

int main()
{
  FILE *f;
  long limit;

#if !defined(RLIMIT_NOFILE) && defined(RLIMIT_OFILE)
#define RLIMIT_NOFILE RLIMIT_OFILE
#endif

#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)
  struct rlimit lim;

  if(getrlimit(RLIMIT_NOFILE,&lim))
  {
    limit = MAX_FD;
  }else{
    if(lim.rlim_max == RLIM_INFINITY)
    {
      limit = 1024 * 1024 * 2; /* Noone needs more :-) */
      
#if defined(OPEN_MAX)
      /* On Darwin we can find a reasonable limit in OPEN_MAX which limits.h
         will include from sys/syslimits.h. */
      limit = (OPEN_MAX < limit) ? OPEN_MAX : limit;
#endif	 
    }else{
      limit=lim.rlim_max;
      if(limit > 1024 * 1024 * 2) limit= 1024 * 1024 * 2;
    }
  }
#else
  limit = MAX_FD;
#endif

  f=fopen("conftest.out.2","w");
  fprintf(f,"%ld\n",(long)limit);
  fclose(f);

  return 0;
}
    ],
    pike_cv_max_open_fd=`cat conftest.out.2`
    ,
    pike_cv_max_open_fd=256
    ,
    pike_cv_max_open_fd=256
  )
  fi
])
AC_MSG_RESULT($pike_cv_max_open_fd)
AC_DEFINE_UNQUOTED(MAX_OPEN_FILEDESCRIPTORS,$pike_cv_max_open_fd)

AC_MSG_CHECKING(full availability of struct rusage members)
AC_CACHE_VAL(pike_cv_func_getrusage_full,
[
  AC_TRY_LINK([
#include <sys/time.h>
#ifdef HAVE_SYS_RUSAGE_H
#include <sys/rusage.h>
#endif
#include <sys/resource.h>
#ifndef RUSAGE_SELF
#define RUSAGE_SELF     0
#endif
  ],[
    struct rusage rus;
    long *v = (long *)main;
    getrusage(RUSAGE_SELF, &rus);
    *v++ = rus.ru_maxrss;
    *v++ = rus.ru_ixrss;
    *v++ = rus.ru_idrss;
    *v++ = rus.ru_isrss;
    *v++ = rus.ru_minflt;
    *v++ = rus.ru_majflt;
    *v++ = rus.ru_nswap;
    *v++ = rus.ru_inblock;
    *v++ = rus.ru_oublock;
    *v++ = rus.ru_msgsnd;
    *v++ = rus.ru_msgrcv;
    *v++ = rus.ru_nsignals;
    *v++ = rus.ru_nvcsw;
    *v++ = rus.ru_nivcsw;
  ],
    pike_cv_func_getrusage_full=yes
  ,
    pike_cv_func_getrusage_full=no
  )
])

if test "$pike_cv_func_getrusage_full" = yes; then
  AC_MSG_RESULT(all there)
else
  AC_MSG_RESULT(getrusage is restricted)
  AC_DEFINE(GETRUSAGE_RESTRICTED)
fi

########################################################################
# 
# IRIX also has procfs support, but it it different, a separate test
# should be made. /Hubbe
#

if test "$ac_cv_header_sys_procfs_h" = "yes"; then
  AC_MSG_CHECKING(getrusage() through procfs)
  AC_CACHE_VAL(pike_cv_getrusage_procfs, [
    AC_TRY_COMPILE([
#ifndef _LARGEFILE_SOURCE
#  define _FILE_OFFSET_BITS 64
#  define _LARGEFILE_SOURCE
#  define _LARGEFILE64_SOURCE 1
#endif
#include <sys/procfs.h>
#include <sys/fcntl.h>
int proc_fd;
long tmp;
char proc_name[20];
prusage_t  pru;
    ],[
      sprintf(proc_name, "/proc/%05d", getpid());
      proc_fd = open(proc_name, O_RDONLY);
      ioctl(proc_fd, PIOCUSAGE, &pru);
      tmp=pru.pr_utime.tv_sec;
    ],
      pike_cv_getrusage_procfs=yes
    ,
      pike_cv_getrusage_procfs=no
    )
  ])

  if test "$pike_cv_getrusage_procfs" = yes; then
    AC_MSG_RESULT(yes)
    AC_DEFINE(GETRUSAGE_THROUGH_PROCFS)
  else
    AC_MSG_RESULT(no)
  fi
fi

#############################################################################

if test "$ac_cv_getrusage_procfs" = "yes"; then
  AC_MSG_CHECKING(prstatus_t contains pr_brksize and pr_stksize)
  AC_CACHE_VAL(pike_cv_getrusage_procfs_prs, [
    AC_TRY_COMPILE([
#ifndef _LARGEFILE_SOURCE
#  define _FILE_OFFSET_BITS 64
#  define _LARGEFILE_SOURCE
#  define _LARGEFILE64_SOURCE 1
#endif
#include <sys/procfs.h>
#include <sys/fcntl.h>
int proc_fd;
long tmp;
char proc_name[20];
prstatus_t prs;
    ],[
      sprintf(proc_name, "/proc/%05d", getpid());
      proc_fd = open(proc_name, O_RDONLY);
      ioctl(proc_fd, PIOCSTATUS, &prs);
      tmp=prs.pr_brksize + prs.pr_stksize;
    ],
      pike_cv_getrusage_procfs_prs=yes
    ,
      pike_cv_getrusage_procfs_prs=no
    )
  ])

  if test "$pike_cv_getrusage_procfs_prs" = yes; then
    AC_MSG_RESULT(yes)
    AC_DEFINE(GETRUSAGE_THROUGH_PROCFS_PRS)
  else
    AC_MSG_RESULT(no)
  fi
fi

#############################################################################
#
# __func__ is new in ISO C 9x
#
# It should expand to the name of the current function, and is
# useful for debug.

AC_MSG_CHECKING(if __func__ exists and works)
AC_CACHE_VAL(pike_cv_have_working___func__,
[
  AC_TRY_RUN([
#ifdef HAVE_STRING_H
#include <string.h>
#else /* !HAVE_STRING_H */
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRIGNS_H */
#endif /* HAVE_STRING_H */
int main()
{
  exit(strcmp("main", __func__));
}
  ], pike_cv_have_working___func__=yes, pike_cv_have_working___func__=no,
     pike_cv_have_working___func__=no)
])
AC_MSG_RESULT($pike_cv_have_working___func__)
if test "$pike_cv_have_working___func__" = yes; then
  AC_DEFINE(HAVE_WORKING___FUNC__)
else :; fi

# gcc has __FUNCTION__ instead.

AC_MSG_CHECKING(if __FUNCTION__ exists and works)
AC_CACHE_VAL(pike_cv_have_working___FUNCTION__,
[
  AC_TRY_RUN([
#ifdef HAVE_STRING_H
#include <string.h>
#else /* !HAVE_STRING_H */
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRIGNS_H */
#endif /* HAVE_STRING_H */
int main()
{
  exit(strcmp("main", __FUNCTION__));
}
  ], pike_cv_have_working___FUNCTION__=yes,
     pike_cv_have_working___FUNCTION__=no,
     pike_cv_have_working___FUNCTION__=no)
])
AC_MSG_RESULT($pike_cv_have_working___FUNCTION__)
if test "$pike_cv_have_working___FUNCTION__" = yes; then
  AC_DEFINE(HAVE_WORKING___FUNCTION__)
else :; fi

#############################################################################

if test "x$with_computed_goto" = "xyes"; then
  AC_MSG_CHECKING(for gcc-style computed goto)
  AC_CACHE_VAL(pike_cv_gcc_computed_goto, [
    AC_TRY_COMPILE([], [
      void *skip = &&label;

      goto *skip;

      return 1;

    label:
      return 0;
    ], [ pike_cv_gcc_computed_goto=yes ], [ pike_cv_gcc_computed_goto=no ])
  ])
  AC_MSG_RESULT($pike_cv_gcc_computed_goto)
  if test "x$pike_cv_gcc_computed_goto" = "xyes"; then
    PIKE_MSG_WARN([Enabling computed goto (EXPERIMENTAL).])
    AC_DEFINE(HAVE_COMPUTED_GOTO)
  else :; fi
else :; fi

#############################################################################

if test "$with_machine_code" = "yes" ; then
  AC_DEFINE_UNQUOTED(PIKE_BYTECODE_METHOD, [[PIKE_BYTECODE_`echo $pike_cv_machine_code_arch | tr '[a-z]' '[A-Z]'`]])
  byte_code_format=$pike_cv_machine_code_arch
elif test "x$with_computed_goto" = "xyes" -a "x$pike_cv_gcc_computed_goto" = "xyes"; then
  AC_DEFINE(PIKE_BYTECODE_METHOD, PIKE_BYTECODE_GOTO)
  byte_code_format="computed goto"
else
  AC_DEFINE(PIKE_BYTECODE_METHOD, PIKE_BYTECODE_DEFAULT)
  byte_code_format="virtual machine"
fi

#############################################################################

AC_MSG_CHECKING(for lc __declspec)
AC_CACHE_VAL(pike_cv_lc___declspec,
[
  AC_TRY_RUN([
#include <stdarg.h>
__declspec(noreturn) void fatal(char *foo,...);

__declspec(noreturn) void fatal(char *foo,...)
{
  va_list args;
  va_start(foo,args);
  printf(foo,args);
  va_end(args);
  exit(2);
}

int main() {  exit(0); }

  ], pike_cv_lc___declspec=yes, pike_cv_lc___declspec=no, [
    echo $ac_n "crosscompiling... $ac_c" 1>&6
    AC_TRY_LINK([
#include <stdarg.h>
__declspec(noreturn) void fatal(char *foo,...);

__declspec(noreturn) void fatal(char *foo,...)
{
  va_list args;
  va_start(foo,args);
  printf(foo,args);
  va_end(args);
  exit(2);
}
    ], [
  exit(0);
    ], pike_cv_lc___declspec=yes, pike_cv_lc___declspec=no)
  ])
])

AC_MSG_RESULT($pike_cv_lc___declspec)
if test "$pike_cv_lc___declspec" = yes; then
  AC_DEFINE(HAVE_DECLSPEC)
else

  # NOTE: Avoid using __attribute__ if __declspec is available.
  #       This is a kludge to descrease the number of warnings
  #       on ecc.

  AC_MSG_CHECKING(for gcc function attributes)
  AC_CACHE_VAL(pike_cv_gcc_attributes,
  [
    AC_TRY_RUN([
#include <stdarg.h>
void fatal(char *foo,...) __attribute__ ((noreturn,format (printf,1,2)));
int sqr(int x) __attribute__ ((const));

int sqr(int x) { return x*x; }

void fatal(char *foo,...)
{
  va_list args;
  va_start(foo,args);
  printf(foo,args);
  va_end(args);
  exit(2);
}

int main() {  exit(0); }

    ], pike_cv_gcc_attributes=yes, pike_cv_gcc_attributes=no, [
      echo $ac_n "crosscompiling... $ac_c" 1>&6
      AC_TRY_LINK([
#include <stdarg.h>
void fatal(char *foo,...) __attribute__ ((noreturn,format (printf,1,2)));
int sqr(int x) __attribute__ ((const));

int sqr(int x) { return x*x; }

void fatal(char *foo,...)
{
  va_list args;
  va_start(foo,args);
  printf(foo,args);
  va_end(args);
  exit(2);
}
      ], [
  exit(0);
      ], pike_cv_gcc_attributes=yes, pike_cv_gcc_attributes=no)
    ])
  ])

  AC_MSG_RESULT($pike_cv_gcc_attributes)
  if test "$pike_cv_gcc_attributes" = yes; then
    AC_DEFINE(HAVE_FUNCTION_ATTRIBUTES)
  fi
fi

AC_MSG_CHECKING(if va_list is a state pointer)
AC_CACHE_VAL(pike_cv_va_list_is_state_ptr, [
  AC_TRY_RUN([
#include <stdarg.h>

void bar(va_list args)
{
  va_arg(args, int);
}

int foo(int a, ...)
{
  va_list args;

  va_start(args, a);

  bar(args);

  a = va_arg(args, int);

  va_end(args);

  return a;
}

int main()
{
  return foo(2, 1, 0);
}
  ], pike_cv_va_list_is_state_ptr=yes,
    pike_cv_va_list_is_state_ptr=no,
    # FIXME:
    pike_cv_va_list_is_state_ptr=unknown
)
])
if test "$pike_cv_va_list_is_state_ptr" = "yes"; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(VA_LIST_IS_STATE_PTR)
elif test "$pike_cv_va_list_is_state_ptr" = "unknown"; then
  # FIXME: "no" works on most stuff except gcc/x86_64.
  AC_MSG_RESULT(unknown -- assume no)
else
  AC_MSG_RESULT(no)
fi

# Can't use AC_CHECK_FUNC for this since it usually is a macro.
AC_MSG_CHECKING(for va_copy)
AC_CACHE_VAL(pike_cv_has_va_copy, [
  AC_TRY_LINK([
#include <stdarg.h>
#ifndef va_copy
    void *f = (void *) va_copy;
#endif
  ], [
#ifdef va_copy
    /* If there is a macro with this name we assume it takes the place of the function. */
    return 0;
#else
    return f != va_copy;
#endif
  ], pike_cv_has_va_copy=yes, pike_cv_has_va_copy=no)
])
if test "$pike_cv_has_va_copy" = yes; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_VA_COPY)
else
  AC_MSG_RESULT(no)
fi

#############################################################################

AC_MSG_CHECKING(how to set things nonblocking)
AC_CACHE_VAL(pike_cv_sys_nonblock,
[
  # Kludge needed for AmigaOS
  if test "$pike_cv_sys_os" = "AmigaOS" ; then
    pike_cv_sys_nonblock=USE_FCNTL_O_NONBLOCK
  else
    OCPPFLAGS="$CPPFLAGS"
    pike_cv_sys_bad_signal_handling=""
    pike_cv_sys_nonblock=UNKNOWN
    # USE_FCNTL_O_NONBLOCK seems to be the most common, so let's start
    # with it.
    for method in USE_FCNTL_O_NONBLOCK USE_FCNTL_FNDELAY USE_FCNTL_O_NDELAY \
		  USE_IOCTL_FIONBIO USE_IOCTLSOCKET_FIONBIO; do
      # Make sure we can run configure in a separate directory,
      # and set the method to try.
      CPPFLAGS="$OCPPFLAGS -D$method"
      AC_TRY_RUN([
#define TESTING
#include "fd_control.c"
      ], [
        pike_cv_sys_nonblock=$method
	break;
      ], [], [
        AC_TRY_LINK([
#define TESTING
#include "fd_control.c"
#define main dummy_main
        ], [], [
	  pike_cv_sys_nonblock=$method
	  break;
	])
      ])
    done
    if test "$pike_cv_sys_nonblock" = "UNKNOWN"; then
      # Some OS's don't like signals in combination with threads.
      # Try compiling half the test...

      # USE_FCNTL_O_NONBLOCK seems to be the most common, so let's start
      # with it.
      for method in USE_FCNTL_O_NONBLOCK USE_FCNTL_FNDELAY USE_FCNTL_O_NDELAY \
		    USE_IOCTL_FIONBIO USE_IOCTLSOCKET_FIONBIO; do
	# Make sure we can run configure in a separate directory,
	# and set the method to try.
	CPPFLAGS="$OCPPFLAGS -D$method -DSHORT_TEST"
	AC_TRY_RUN([
#define TESTING
#include "fd_control.c"
        ], [
	  pike_cv_sys_bad_signal_handling=" (signal handling failed)"
          pike_cv_sys_nonblock=$method
          break;
        ], [], [
	  :; # Not meaningful.
  	])
      done
    else :; fi
    # Restore CPPFLAGS
    CPPFLAGS="$OCPPFLAGS"
  fi
])

if test "${pike_cv_sys_nonblock}" = "UNKNOWN"; then
  AC_MSG_RESULT(none found)
  if test "${pike_cv_sys_os}" = "Windows_NT"; then :; else
    config_fail="No way to set nonblocking I/O"
  fi
else
  AC_MSG_RESULT($pike_cv_sys_nonblock$pike_cv_sys_bad_signal_handling)
  AC_DEFINE_UNQUOTED($pike_cv_sys_nonblock)
fi

rm -f core

##########################################################################
AC_MSG_CHECKING(how well OOB handling works)
AC_CACHE_VAL(pike_cv_system_oob_working,[
  if test "x$enable_binary" = "xno"; then
    pike_cv_system_oob_working=WORKING
  else
    AC_TRY_RUN([
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/stat.h>
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_SYS_POLL_H
#include <sys/poll.h>
#endif
#include <fcntl.h>
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif

#define SP_DEBUG(X)	fprintf X

#ifndef POLLRDNORM
#define POLLRDNORM      POLLIN
#endif

#ifndef POLLRDBAND
#define POLLRDBAND      POLLPRI
#endif

#ifndef POLLWRBAND
#define POLLWRBAND      POLLOUT
#endif

int set_nonblocking(int fd,int which)
{
  int ret;
  do 
  {
#if defined(USE_IOCTL_FIONBIO) || defined(__NT__)
    ret=ioctl(fd, FIONBIO, &which);
#else

#ifdef USE_FCNTL_O_NDELAY
    ret=fcntl(fd, F_SETFL, which?O_NDELAY:0);
#else

#ifdef USE_FCNTL_O_NONBLOCK
    ret=fcntl(fd, F_SETFL, which?O_NONBLOCK:0);
#else

#ifdef USE_FCNTL_FNDELAY
    ret=fcntl(fd, F_SETFL, which?FNDELAY:0);
#else

#error Do not know how to set your filedescriptors nonblocking.

#endif
#endif
#endif
#endif
  } while(ret <0 && errno==EINTR);
  return ret;
}


FILE *output;
static int socketpair_fd = -1;
int my_socketpair(int family, int type, int protocol, int sv[2])
{
  static struct sockaddr_in my_addr;
  struct sockaddr_in addr,addr2;
  int retries=0;
  ACCEPT_SIZE_T len;

  memset((char *)&addr,0,sizeof(struct sockaddr_in));

  if(socketpair_fd==-1)
  {
    if((socketpair_fd=socket(AF_INET, SOCK_STREAM, 0)) < 0) {
      SP_DEBUG((stderr, "my_socketpair:socket() failed, errno:%d\n",
		errno));
      return -1;
    }

    memset((char *)&my_addr,0,sizeof(struct sockaddr_in));
    my_addr.sin_family=AF_INET;
    my_addr.sin_addr.s_addr=htonl(INADDR_ANY);
    my_addr.sin_port=htons(0);


    if(bind(socketpair_fd, (struct sockaddr *)&my_addr, sizeof(addr)) < 0)
    {
      SP_DEBUG((stderr, "my_socketpair:bind() failed, errno:%d\n",
		errno));
      close(socketpair_fd);
      socketpair_fd=-1;
      return -1;
    }

    len = sizeof(my_addr);
    if(getsockname(socketpair_fd,(struct sockaddr *)&my_addr,&len) < 0)
    {
      SP_DEBUG((stderr, "my_socketpair:getsockname() failed, errno:%d\n",
		errno));
      close(socketpair_fd);
      socketpair_fd=-1;
      return -1;
    }

    if(listen(socketpair_fd, 5) < 0)
    {
      SP_DEBUG((stderr, "my_socketpair:listen() failed, errno:%d\n",
		errno));
      close(socketpair_fd);
      socketpair_fd=-1;
      return -1;
    }

    set_nonblocking(socketpair_fd, 1);

    my_addr.sin_addr.s_addr=inet_addr("127.0.0.1");
  }


  if((sv[1]=socket(AF_INET, SOCK_STREAM, 0)) <0) {
    SP_DEBUG((stderr, "my_socketpair:socket() failed, errno:%d (2)\n",
	      errno));
    return -1;
  }


retry_connect:
  retries++;
  if(connect(sv[1], (struct sockaddr *)&my_addr, sizeof(addr)) < 0)
  {
    SP_DEBUG((stderr, "my_socketpair:connect() failed, errno:%d (%d)\n",
	      errno, EWOULDBLOCK));
    if(errno != EWOULDBLOCK)
    {
      int tmp2;
#ifdef ETIMEDOUT
      if (errno == ETIMEDOUT) {
        SP_DEBUG((stderr,
	          "my_socketpair: ETIMEDOUT!\n"
		  "Do you have a firewall in the way?\n"));
	/* ETIMEDOUT hints that quite a bit of time has passed,
	 * so no need for further retries. */
	fprintf(output, "TIMEOUT\n");
	exit(0);
      }
#endif
#ifdef ECONNREFUSED
      if (errno == ECONNREFUSED) {
        SP_DEBUG((stderr,
	          "my_socketpair: ECONNREFUSED!\n"
		  "Do you have a firewall in the way?\n"));
      }
#endif
      for(tmp2=0;tmp2<20;tmp2++)
      {
	int tmp;
	ACCEPT_SIZE_T len2;

	len2=sizeof(addr);
	tmp=accept(socketpair_fd,(struct sockaddr *)&addr,&len2);

	if(tmp!=-1) {
	  SP_DEBUG((stderr, "my_socketpair:accept() failed, errno:%d\n",
		    errno));
	  close(tmp);
	}
	else
	  break;
      }
      if(retries > 20) return -1;
      goto retry_connect;
    }
  }


  do
  {
    ACCEPT_SIZE_T len3;

    len3=sizeof(addr);
  retry_accept:
    sv[0]=accept(socketpair_fd,(struct sockaddr *)&addr,&len3);

    if(sv[0] < 0) {
      SP_DEBUG((stderr, "my_socketpair:accept() failed, errno:%d (2)\n",
		errno));
      if(errno==EINTR) goto retry_accept;
      close(sv[1]);
      return -1;
    }

    set_nonblocking(sv[0],0);

    len=sizeof(addr);
    if(getpeername(sv[0], (struct sockaddr *)&addr,&len)) {
      SP_DEBUG((stderr, "my_socketpair:getpeername() failed, errno:%d\n",
		errno));
      return -1;
    }
    len=sizeof(addr);
    if(getsockname(sv[1],(struct sockaddr *)&addr2,&len) < 0) {
      SP_DEBUG((stderr, "my_socketpair:getsockname() failed, errno:%d\n",
		errno));
      return -1;
    }
  }while(len < (int)sizeof(addr) ||
	 addr2.sin_addr.s_addr != addr.sin_addr.s_addr ||
	 addr2.sin_port != addr.sin_port);

  SP_DEBUG((stderr, "my_socketpair: succeeded\n",
	    errno));

  return 0;
}

int socketpair_ultra(int family, int type, int protocol, int sv[2])
{
  int retries=0;

  while(1)
  {
    int ret=my_socketpair(family, type, protocol, sv);
    if(ret>=0) return ret;

    switch(errno)
    {
      case EAGAIN: break;

      case EADDRINUSE:
	if(retries++ > 10) return ret;
	break;

      default:
	return ret;
    }
  }
}


struct pollfd pollset[2];
int fds[2];
static int sent=0;
int xcalls=0;

int ping(int fd)
{
  int r;
  sent++;
  if(sent > 10000)
  {
    fprintf(output,xcalls ? "SEMIWORKING" : "WORKING");
    exit(0);
  }
  do {
    r=send(fds[fd],"x",1,MSG_OOB);
  }while(r < 0 && errno==EINTR);
  if(r!=1)
  {
    SP_DEBUG((stderr,
	      "ping(%d): send(%d, \"x\", 1, MSG_OOB) failed with errno %d\n",
	      fd, fds[fd], errno));
    fprintf(output,"XBYTES\n");
    exit(0);
  }

  pollset[fd].events &=~ POLLWRBAND;
  pollset[!fd].events |= POLLRDBAND;
}

int pong(int fd)
{
  char foo[2];
  int r;
   do {
    r=recv(fds[fd], &foo, 2, MSG_OOB);
  }while(r < 0 && errno==EINTR);
  if(r!=1)
  {
    fprintf(output,"XBYTES\n");
    exit(0);
  }

  pollset[fd].events &=~ POLLRDBAND;
  pollset[fd].events |=  POLLWRBAND;
}

void pang(int fd)
{
  char foo[2];
  int r;
  xcalls++;
   do {
    r=recv(fds[fd], &foo, 2, 0);
  }while(r < 0 && errno==EINTR);
  if(r<0 && errno==EAGAIN) return;

  fprintf(output,"INLINED\n");
  exit(0);
}

int main(int argc, char **argv)
{
  int e;
  output=fopen("conftest.out.2","w");
  socketpair_ultra(AF_UNIX, SOCK_STREAM, 0, fds);

#define INIT(X) do {\
  set_nonblocking(fds[X],1); \
  pollset[X].fd=fds[X]; \
  pollset[X].events=POLLIN; \
}while(0);

  INIT(0);
  INIT(1);

  ping(0);

  while(1)
  {
    if(!poll(pollset, 2, 10000))
    {
      fprintf(output,sent>1 ? "WORKS_A_LITTLE\n" : "TIMEOUT\n");
      exit(0);
    }

    for(e=0;e<2;e++)
    {
      if(pollset[e].revents & POLLRDBAND) pong(e);
      if(pollset[e].revents & POLLWRBAND) ping(e);
      if(pollset[e].revents & POLLIN) pang(e);
    }
  }
}
    ],
    pike_cv_system_oob_working="`cat conftest.out.2`",
    pike_cv_system_oob_working=UNKNOWN,
    pike_cv_system_oob_working=UNKNOWN)
  
    rm -f conftest.out.2 >/dev/null 2>/dev/null || :
  fi
])
AC_MSG_RESULT($pike_cv_system_oob_working)

case "x$pike_cv_system_oob_working" in
  xWORKING)        AC_DEFINE_UNQUOTED(PIKE_OOB_WORKS,3)  ;;
  xSEMIWORKING)    AC_DEFINE_UNQUOTED(PIKE_OOB_WORKS,2)  ;;
  xINLINED)        AC_DEFINE_UNQUOTED(PIKE_OOB_WORKS,1)  ;;
  xWORKS_A_LITTLE) AC_DEFINE_UNQUOTED(PIKE_OOB_WORKS,1)  ;;
  xXBYTES)         AC_DEFINE_UNQUOTED(PIKE_OOB_WORKS,0)  ;;
  xTIMEOUT)        AC_DEFINE_UNQUOTED(PIKE_OOB_WORKS,0)  ;;
  *)               AC_DEFINE_UNQUOTED(PIKE_OOB_WORKS,-1) ;; #unknown
esac

#######################################################################

MY_AC_CHECK_PRINTF_INT_TYPE(size_t,
			    "z" "" "l" "ll" "L", "",
			    PRINTSIZET,
			    [%${res}u, %${res}x])
MY_AC_CHECK_PRINTF_INT_TYPE(ptrdiff_t,
			    "t" "" "l" "ll" "L", "",
			    PRINTPTRDIFFT,
			    [%${res}d, %${res}x])
MY_AC_CHECK_PRINTF_INT_TYPE(off_t,
			    "" "t" "j" "l" "ll" "L", "",
			    PRINTOFFT,
			    [%${res}d, %${res}x])
MY_AC_CHECK_PRINTF_INT_TYPE(INT64,
			    "" "l" "ll" "I64" "L", "l",
			    PRINTINT64,
			    [%${res}d, %${res}x])

#######################################################################

AC_MSG_CHECKING(if union initialization works)
AC_CACHE_VAL(pike_cv_have_union_init, [
  AC_TRY_RUN([
    struct foo {int a;};
    struct bar {char b[2];};
    union anything
    {
      struct foo foo;
      struct bar bar;
    };
    struct svalue
    {
      unsigned type;
      unsigned subtype;
      union anything u;
    };
    struct svalue my_svalue = {0, 0, {{4711}}};
    int main() {
      return !(my_svalue.u.foo.a == 4711);
    }
  ],
  pike_cv_have_union_init=yes,
  pike_cv_have_union_init=no,
  pike_cv_have_union_init=no)
])
AC_MSG_RESULT($pike_cv_have_union_init)
if test "$pike_cv_have_union_init" = yes; then
  AC_DEFINE(HAVE_UNION_INIT)
fi

#############################################################################

AC_MSG_CHECKING(if port.c works in CONFIGURE_TEST mode)
AC_CACHE_VAL(pike_cv_configure_test_port_c, [
  AC_TRY_RUN([
#include <stdio.h>

#define CONFIGURE_TEST
/* The following headers can cause problems in this mode, and they easily
   get indirectly included unless we do this. */
#define STRALLOC_H
#define SVALUE_H
#define ARRAY_H

#include "port.c"

int main()
{
  return 0;
}
  ], pike_cv_configure_test_port_c=yes,
     pike_cv_configure_test_port_c=no,
     pike_cv_configure_test_port_c=unknown)
])
AC_MSG_RESULT($pike_cv_configure_test_port_c)
if test "x$pike_cv_configure_test_port_c" = xno; then
  AC_MSG_ERROR([

port.c does not work in CONFIGURE_TEST mode. This is an internal
problem in Pike. configure aborted since further configure tests will
be unreliable.
])
  exit 1
fi

#############################################################################

AC_MSG_CHECKING(if gettimeofday takes two arguments)
AC_CACHE_VAL(pike_cv_func_gettimeofday_has_two_args,
[
  AC_TRY_RUN([
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  if HAVE_TIME_H
#   include <time.h>
#  endif
# endif
#endif

#ifndef HAVE_STRUCT_TIMEVAL
struct timeval
{
  long tv_sec;
  long tv_usec;
};
#endif

int main() {
  struct timeval tv;
  gettimeofday(&tv,(void *)0);
  exit(0);
}
  ], [ pike_cv_func_gettimeofday_has_two_args=yes
  ], [ pike_cv_func_gettimeofday_has_two_args=no
  ], [
    AC_TRY_LINK([
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  if HAVE_TIME_H
#   include <time.h>
#  endif
# endif
#endif

#ifndef HAVE_STRUCT_TIMEVAL
struct timeval
{
  long tv_sec;
  long tv_usec;
};
#endif
    ], [
{
  struct timeval tv;
  gettimeofday(&tv,(void *)0);
  exit(0);
}
    ], [ pike_cv_func_gettimeofday_has_two_args=yes ], [pike_cv_func_gettimeofday_has_two_args=no])
  ])
])

if test $pike_cv_func_gettimeofday_has_two_args = yes; then
  AC_DEFINE(GETTIMEOFDAY_TAKES_TWO_ARGS)
fi

AC_MSG_RESULT($pike_cv_func_gettimeofday_has_two_args)

if test "x$ac_cv_func_gethrvtime" = xyes; then
  AC_MSG_CHECKING(if gethrvtime really works)
  AC_CACHE_VAL(pike_cv_func_gethrvtime_works, [
    AC_TRY_RUN([
#include <stdio.h>

#define CONFIGURE_TEST
/* The following headers can cause problems in this mode, and they easily
   get indirectly included unless we do this. */
#define STRALLOC_H
#define SVALUE_H
#define ARRAY_H

#include "port.c"

int main()
{
  time_t start = TIME (0), now;
  hrtime_t vt = gethrvtime(), next_vt;
  if (start == (time_t) -1) return 1; /* Normal time doesn't work. */
  do { /* Take some cpu time. */
    now = TIME (0);
    next_vt = gethrvtime();
    if (next_vt < vt) return 2; /* Shouldn't go backward. */
    vt = next_vt;
  } while (now != (time_t) -1 && now <= start + 1);
  if (now == (time_t) -1) return 3; /* Normal time does not work. */
  if (vt <= 0) return 4; /* Should have accounted for some cpu time. */
  return 0;
}
    ], pike_cv_func_gethrvtime_works=yes,
       pike_cv_func_gethrvtime_works=no,
       pike_cv_func_gethrvtime_works=no)
  ])
  AC_MSG_RESULT($pike_cv_func_gethrvtime_works)
  if test "x$pike_cv_func_gethrvtime_works" = xyes; then
    AC_DEFINE(HAVE_WORKING_GETHRVTIME)
  fi
fi

#######################################################################

AC_MSG_CHECKING(if rusage.c works in CONFIGURE_TEST mode)
AC_CACHE_VAL(pike_cv_configure_test_rusage_c, [
  AC_TRY_RUN([
#include <stdio.h>

#define CONFIGURE_TEST
/* The following headers can cause problems in this mode, and they easily
   get indirectly included unless we do this. */
#define STRALLOC_H
#define SVALUE_H
#define ARRAY_H

#include "port.c"		/* Tested earlier, but might be required. */
#include "rusage.c"

int main()
{
  init_rusage();
  return 0;
}
  ], pike_cv_configure_test_rusage_c=yes,
     pike_cv_configure_test_rusage_c=no,
     pike_cv_configure_test_rusage_c=unknown)
])
AC_MSG_RESULT($pike_cv_configure_test_rusage_c)
if test "x$pike_cv_configure_test_rusage_c" = xno; then
  AC_MSG_ERROR([

rusage.c does not work in CONFIGURE_TEST mode. This is an internal
problem in Pike. configure aborted since further configure tests will
be unreliable.
])
  exit 1
fi

AC_MSG_CHECKING(if threads.c works in CONFIGURE_TEST mode)
AC_CACHE_VAL(pike_cv_configure_test_threads_c, [
  AC_TRY_RUN([
#include <stdio.h>

#define CONFIGURE_TEST
/* The following headers can cause problems in this mode, and they easily
   get indirectly included unless we do this. */
#define STRALLOC_H
#define SVALUE_H
#define ARRAY_H

#include "port.c"		/* Tested earlier, but might be required. */
#include "threads.c"

int main()
{
  return 0;
}
  ], pike_cv_configure_test_threads_c=yes,
     pike_cv_configure_test_threads_c=no,
     pike_cv_configure_test_threads_c=unknown)
])
AC_MSG_RESULT($pike_cv_configure_test_threads_c)
if test "x$pike_cv_configure_test_threads_c" = xno; then
  AC_MSG_ERROR([

threads.c does not work in CONFIGURE_TEST mode. This is an internal
problem in Pike. configure aborted since further configure tests will
be unreliable.
])
  exit 1
fi

#######################################################################

AC_MSG_CHECKING(if fallback cpu time is thread local)
AC_CACHE_VAL(pike_cv_thread_local_cpu_time, [
  rm -f confdefs.out.2 2>/dev/null
  AC_TRY_RUN([
#include <stdio.h>

/* libc_r:fputs on AIX 4.2 is broken. */
#define FPUTS(S, F)	fwrite(S, sizeof(S)-sizeof(""), 1, F)

#ifdef PIKE_THREADS

#define CONFIGURE_TEST
#define CONFIGURE_TEST_FALLBACK_GCT
/* The following headers can cause problems in this mode, and they easily
   get indirectly included unless we do this. */
#define STRALLOC_H
#define SVALUE_H
#define ARRAY_H

#include "port.c"
#include "rusage.c"
#include "threads.c"

PIKE_MUTEX_T m;
COND_T c;

cpu_time_t work_time, wait_time;

TH_RETURN_TYPE work_thread (void *dummy)
{
  struct timeval rt_start, rt;
  cpu_time_t start;
  FPUTS("work_thread waiting.\n", stderr);
  mt_lock (&m);
  FPUTS("work_thread start.\n", stderr);
  GETTIMEOFDAY (&rt_start);
  start = get_cpu_time();
  do {
    cpu_time_t t = get_cpu_time();
    GETTIMEOFDAY (&rt);
    if (t == (cpu_time_t) -1) {
      work_time = t;
      break;
    }
    work_time = t - start;
  } while (work_time < (CPU_TIME_TICKS / 10) && rt.tv_sec <= rt_start.tv_sec + 1);
  FPUTS("work_thread releasing main.\n", stderr);
  co_signal (&c);
  mt_unlock (&m);
  FPUTS("work_thread done.\n", stderr);
  return 0;
}

int main()
{
  cpu_time_t start;
  THREAD_T worker;
  FILE *res = fopen ("confdefs.out.2", "w"); /* weird name to circumvent configure cleanups */
  if (!res) return 2;

  init_rusage();
  really_low_th_init();

  mt_init (&m);
  co_init (&c);

  mt_lock (&m);
  FPUTS("Creating work_thread.\n", stderr);
  if (th_create (&worker, work_thread, NULL)) {
    FPUTS("unknown (failed to create thread)", res);
    fclose (res);
    return 3;
  }

  start = get_cpu_time();
  co_wait (&c, &m);
  wait_time = get_cpu_time() - start;
  if (start == (cpu_time_t) -1 || work_time == (cpu_time_t) -1) {
    FPUTS("unknown (get_cpu_time does not work)", res);
    fclose (res);
    return 4;
  }
  if (work_time < (CPU_TIME_TICKS / 10)) {
    fprintf (res, "unknown (get_cpu_time does not work - loop took only %ld ms)",
	     (long) (work_time / (CPU_TIME_TICKS / 1000)));
    fclose (res);
    return 5;
  }

  if (work_time > wait_time)
    return 0; /* It is thread local. */
  else {
    FPUTS("no", res);
    fclose (res);
    return 1; /* It is not thread local. */
  }
}

#else
int main()
{
  FILE *res = fopen ("confdefs.out.2", "w"); /* weird name to circumvent configure cleanups */
  if (!res) return 6;
  FPUTS("no", res);
  fclose (res);
  return 1;
}
#endif
    ], [
      pike_cv_thread_local_cpu_time=yes
    ], [
      if test -f confdefs.out.2 && test "x`cat confdefs.out.2`" != x; then
        pike_cv_thread_local_cpu_time=`cat confdefs.out.2`
      else
	AC_MSG_ERROR([

Test failed to compile or execute.
Problems in port.c, rusage.c or threads.c with CONFIGURE_TEST is defined?
])
        # Don't set pike_cv_thread_local_cpu_time here so that the
        # failure doesn't get cached.
	result="unknown (compilation or execution failed)"
	exit 1
      fi
    ], [
      pike_cv_thread_local_cpu_time="unknown (cross compilation)"
    ])
  rm -f confdefs.out.2 2>/dev/null
])
test x"$pike_cv_thread_local_cpu_time" != x && result="$pike_cv_thread_local_cpu_time"
AC_MSG_RESULT($result)
if test "$pike_cv_thread_local_cpu_time" = yes; then
  AC_DEFINE(FB_CPU_TIME_IS_THREAD_LOCAL, PIKE_YES)
elif test "$pike_cv_thread_local_cpu_time" = no; then
  AC_DEFINE(FB_CPU_TIME_IS_THREAD_LOCAL, PIKE_NO)
else
  AC_DEFINE(FB_CPU_TIME_IS_THREAD_LOCAL, PIKE_UNKNOWN)
fi

#######################################################################

AC_CHECK_FUNCS([setenv unsetenv])

if test "$ac_cv_func_setenv:$ac_cv_func_unsetenv" = "yes:yes"; then
  :
else
  AC_MSG_CHECKING([if putenv() always requires a '='])
  AC_CACHE_VAL(pike_cv_putenv_always_requires_equal, [
    AC_TRY_RUN([
  #include <stdlib.h>
  
      int main()
      {
        putenv ("foo=bar");
        if (putenv ("foo") && !putenv ("foo=") && !getenv ("foo")) return 1;
        return 0;
      }],
      pike_cv_putenv_always_requires_equal=no,
      pike_cv_putenv_always_requires_equal=yes
    )
  ])
  AC_MSG_RESULT($pike_cv_putenv_always_requires_equal)
  if test "x$pike_cv_putenv_always_requires_equal" = "xyes"; then
    AC_DEFINE(PUTENV_ALWAYS_REQUIRES_EQUAL, [],
  	    [Defined if putenv() always requires a '='])
  fi
fi

#######################################################################

# Set info about shared libraries.
AC_SUBST(SO)
AC_SUBST(LDSHARED)
AC_SUBST(LDSHARED_BASE_REQS)
AC_SUBST(LDSHARED_MODULE_REQS)
AC_SUBST(CCSHARED)
AC_SUBST(LINKFORSHARED)

# SO is the extension of shared libraries
# -- usually so, sl on HP-UX
AC_MSG_CHECKING(SO)
if test -z "$SO"
then
	case "$pike_cv_sys_os" in
	hp*|HP*)   SO=sl;;
	*)	   SO=so;;
	esac
fi
AC_MSG_RESULT($SO)
# LDSHARED is the ld *command* used to create shared library
# -- "ld" on SunOS 4.x.x, "ld -G" on SunOS 5.x, "ld -shared" on IRIX 5
AC_MSG_CHECKING(LDSHARED)
if test -z "$LDSHARED" ; then
  case "$pike_cv_sys_os" in
    AIX*)
      if test "$GCC" = yes ; then
        if test "`uname -r`" -ge 2 -a "`uname -v`" -eq 4 ; then
          LDSHARED="ld -G -bexpall"
	elif test "`uname -v`" -gt 4 ; then
	  # AIX 5L+
	  LDSHARED="ld -G"
	else
	  # AIX 4.1 and earlier don't have/have unreliable
	  # handling of dlopen et al.
	  #
	  # Even AIX 4.2.1 has buggy dlopen -- NEVER attempt
	  # to dlopen a file that hasn't been linked with -G.
	  pike_cv_sys_dynamic_loading=no
	  LDSHARED="ld"
        fi
      elif test "`uname -r`" -ge 3 -a "`uname -v`" -eq 4 ; then
        LDSHARED="ld -G -bexpall"
      elif test "`uname -v`" -gt 4 ; then
	# AIX 5L+
	LDSHARED="ld -G"
      else
	# AIX 4.1 and earlier don't have/have unreliable
	# handling of dlopen et al.
	#
	# Even AIX 4.2.1 has buggy dlopen -- NEVER attempt
	# to dlopen a file that hasn't been linked with -G.
	pike_cv_sys_dynamic_loading=no
	LDSHARED="ld"
      fi
    ;;
    Darwin*)
      if test "$pike_cv_osx_twolevel_namespace" = yes ; then
        # 10.3 or newer take advantage of two-level namespaces to avoid
        # symbol collisions for e.g. libjpeg which is referenced from both
        # _Image_JPEG and _Image_TIFF. It requires MACOSX_DEPLOYMENT_TARGET
        # which is initialized in smartlink to 10.3.
        LDSHARED="$REALCC $CFLAGS -bundle -bind_at_load -undefined dynamic_lookup"
      else
        # Mac OS X prior to 10.3 need -flat_namespace to support dynamic modules
        LDSHARED="$REALCC $CFLAGS -bundle -bind_at_load -flat_namespace -undefined suppress"
      fi
    ;;
    IRIX*)
      if test "$GCC" = yes ; then
        # egcs defaults to building -n32 objects
        LDSHARED="ld -shared -n32"
      else
        LDSHARED="ld -shared"
      fi
      # -woff isn't understood by ld on Irix 5.
      if test "`uname -r`" -ge 6 ; then
        LDSHARED="$LDSHARED -woff 84,85,134"
      else :; fi
    ;;
    SunOS*) LDSHARED="ld";;
    Solaris) LDSHARED="/usr/ccs/bin/ld -G";;
    hp*|HP*) LDSHARED="ld -b";;
    OSF*) LDSHARED="ld -expect_unresolved '*' -shared -msym -O3";;
    DYNIX/ptx*) LDSHARED="ld -G";;
    next*) LDSHARED="$REALCC $CFLAGS -nostdlib -r";;
    Linux*) LDSHARED="$REALCC -shared";;
    GNU/kFreeBSD*) LDSHARED="$REALCC -shared";;
    GNU*) LDSHARED="$REALCC -Wl,-Bshareable";;
    FreeBSD*) LDSHARED="$REALCC -Wl,-Bshareable";;
    NetBSD*) LDSHARED="$REALCC -Wl,-Bshareable";;
    OpenBSD*) LDSHARED="$REALCC -Wl,-Bshareable";;
    BSD/OS*)
      case "`uname -r`" in
       [4-9].*) LDSHARED="$REALCC -shared";;
        *) LDSHARED="shlicc -r";;
      esac
    ;;
    SCO_SV*) LDSHARED="$REALCC -G -KPIC -Wl,-Bexport";;
    UNIX_SV*) LDSHARED="ld -G";;
    UnixWare*|OpenUNIX*)
      if test "$GCC" = yes ; then
        LDSHARED="$REALCC -G -fPIC"
      else
        LDSHARED="$REALCC -G -KPIC -Wl,-Bexport"
      fi
    ;;
    Windows_NT*|NT*)
      if test x$with_dynamic_modules != xno; then
	if test x$enable_dll = xno; then
	 LDSHARED="pntld"
	else
	  # It's important that we use $(CC) unexpanded here so that any
	  # -MD/-MDd flags also gets passed to the linker.
	  LDSHARED='$(CC) -shared'
	  LDSHARED_BASE_REQS=pike.lib
	  LDSHARED_MODULE_ARGS="-l`pwd`/pike"
	  LDSHARED_MODULE_REQS="`pwd`/pike.lib"
	fi
	LDSHARED_MODULE_ARGS="$LDSHARED_MODULE_ARGS -pdb:\$\$modname.pdb"
      fi
    ;;
    *) LDSHARED="ld";;
  esac
fi
AC_MSG_RESULT($LDSHARED)

# CCSHARED are the C *flags* used to create objects to go into a shared
# library -- this is only needed for a few systems
AC_MSG_CHECKING(CCSHARED)
AC_CACHE_VAL(pike_cv_sys_ccshared,[
  if test -z "$CCSHARED" ; then
    if test "$GCC" = yes ; then
      case "$pike_cv_sys_os" in
	BSD/OS*)
         case "`uname -r`" in
           4.*) CCSHARED="-fPIC";;
           *) CCSHARED="";;
         esac
	;;
	Darwin*)
	  CCSHARED="-fPIC"
	;;
	Solaris*)
	  # The Image module runs out of symbol reference space unless we
	  # use the large PIC model:
	  # ld: fatal: too many symbols require `small' PIC references:
	  # 	have 2205, maximum 2048 -- recompile some modules -K PIC.
	  CCSHARED="-fPIC"
	;;
	*)
	  AC_SYS_COMPILER_FLAG(-fPIC, fPIC, CCSHARED, [
	    AC_SYS_COMPILER_FLAG(-fpic, fpic, CCSHARED)
	  ])
	;;
      esac
    else
      case "$pike_cv_sys_os" in
	Darwin*)
	  CCSHARED="-fPIC"
	;;
        IRIX*)
          AC_SYS_COMPILER_FLAG(-share,cc_shared,CCSHARED)
        ;;
	hp*|HP*) CCSHARED="+z"; ;;
	FreeBSD*) CCSHARED="-fpic";;
	SCO_SV*) CCSHARED="-KPIC -dy -Bdynamic";;
        UnixWare*|OpenUNIX*) CCSHARED="-KPIC -dy -Bdynamic";;
	Solaris*)
	  CCSHARED="-KPIC -Bdynamic"
	  # Note: The Image module fails with
	  #   Failed to load library: ld.so.1: pike: fatal:
	  #   relocation error: R_AMD64_PC32: file Image.so:
	  #   symbol really_free_svalue: value 0x28001ca5b2d does not fit
	  # if the module is compiled with the default model.
	  AC_SYS_COMPILER_FLAG(-xmodel=medium, xmodel_medium, CCSHARED)
	;;
	Windows_NT*) CCSHARED="-shared" ;;
      esac
    fi
  fi
  OLD_CFLAGS="$CFLAGS"
  CFLAGS="$CFLAGS $CCSHARED"
  AC_TRY_COMPILE([], [exit(0);],
    pike_cv_sys_ccshared="$CCSHARED", pike_cv_sys_ccshared='')
  CFLAGS="$OLD_CFLAGS"
])
CCSHARED="$pike_cv_sys_ccshared"
AC_MSG_RESULT($CCSHARED)

AC_MSG_CHECKING(LINKFORSHARED)

AC_CACHE_VAL(pike_cv_sys_linkforshared,[
# LINKFORSHARED are the flags passed to the $(CC) command that links
# the pike executable -- this is only needed for a few systems
if test -z "$LINKFORSHARED"
then
  LINKFORSHARED=""
  if test "$GCC" = yes ; then
    case "$pike_cv_sys_os" in
      AIX*)
        if test "`uname -v`" -gt 4 ; then
	  # This is probably wrong, but I don't have a man page for ld yet.
	  LINKFORSHARED=""
	else
	  LINKFORSHARED="-Wl,-bexpall -Wl,-brtl"
	fi
      ;;
      Darwin*) LINKFORSHARED="-dynamic";;
      hp*|HP*) LINKFORSHARED="-Wl,-E";;
      Linux*) LINKFORSHARED="-rdynamic";;
      BSD/OS*)
        case "`uname -r`" in
         4.*) LINKFORSHARED="-rdynamic";;
       esac
      ;;
      BSD/OS*)
        case "`uname -r`" in
         4.*) LINKFORSHARED="-rdynamic";;
       esac
      ;;
      GNU*) LINKFORSHARED="-rdynamic";;
      NetBSD*) LINKFORSHARED="-Wl,-E";;
      OpenBSD*) LINKFORSHARED="-Wl,-E";;
      next*) LINKFORSHARED="-u libsys_s";;
      SCO_SV*) LINKFORSHARED="-fpic -Wl,-Bexport";;
      # What about UNIX_SV?
      UnixWare*|OpenUNIX*) LINKFORSHARED="-fpic -Wl,-Bexport";;

      FreeBSD*)
        AC_TRY_RUN([int main(){exit(
#ifdef __ELF__
    0
#else
    1
#endif
);}
        ],LINKFORSHARED=-rdynamic)
      ;;
    esac
  else
    case "$pike_cv_sys_os" in
      AIX*)
        if test "`uname -v`" -gt 4 ; then
	  LINKFORSHARED="-Bexport"
	else
	  LINKFORSHARED="-Wl,-bexpall -Wl,-brtl"
	fi
      ;;
      Darwin*) LINKFORSHARED="-dynamic";;
      hp*|HP*) LINKFORSHARED="-Wl,-E";;
      Linux*) LINKFORSHARED="-rdynamic";;
      GNU*) LINKFORSHARED="-rdynamic";;
      next*) LINKFORSHARED="-u libsys_s";;
      SCO_SV*) LINKFORSHARED="-Bdynamic -dy -Wl,-Bexport";;
      # What about UNIX_SV?
      UnixWare*|OpenUNIX*) LINKFORSHARED="-Bdynamic -dy -Wl,-Bexport";;
      Windows_NT*|NT*)
	test x$enable_dll != xyes && LINKFORSHARED="-rdynamic";;

      FreeBSD*)
        AC_TRY_RUN([int main(){exit(
#ifdef __ELF__
    0
#else
    1
#endif
);}
        ],LINKFORSHARED=-rdynamic)
      ;;
    esac
  fi
fi


   OLD_CFLAGS="$CFLAGS"
   CFLAGS="$CFLAGS $LINKFORSHARED"
   AC_TRY_RUN([int main() { exit(0); }],
 pike_cv_sys_linkforshared="$LINKFORSHARED", pike_cv_sys_linkforshared='', pike_cv_sys_linkforshared='')
   CFLAGS="$OLD_CFLAGS"
])

LINKFORSHARED="$pike_cv_sys_linkforshared"

AC_MSG_RESULT($LINKFORSHARED)

#############################################################################

# In case we're going to use gcc for linking shared objects,
# we should use the -static-libgcc flag if it exists.
# Shared libgcc is nothing but trouble.
STATIC_LIBGCC=""
if test yes = "$GCC" ; then
  AC_SYS_COMPILER_FLAG(-static-libgcc,static_libgcc,STATIC_LIBGCC)
else :; fi

#############################################################################

AC_MSG_CHECKING(if dynamic loading works)
AC_CACHE_VAL(pike_cv_sys_dynamic_loading,
[
  cat >conftest.c <<EOF
#include <stdio.h>
#include <stdlib.h>
void testfunc(void) {
  fprintf(stderr,"Calling testfunc2\n");
  testfunc2();
  fprintf(stderr,"testfunc2 returned!\n");
  exit(1);
}
EOF

  echo $CC -c $CFLAGS $CCSHARED conftest.c -o conftest.o 1>&AC_FD_CC
  $CC -c $CFLAGS $CCSHARED conftest.c -o conftest.o 1>&AC_FD_CC 2>&AC_FD_CC

  echo $BINDIR/smartlink $LDSHARED $LDFLAGS conftest.o -o conftest.$SO 1>&AC_FD_CC
  $BINDIR/smartlink $LDSHARED $LDFLAGS conftest.o -o conftest.$SO 1>&AC_FD_CC 2>&AC_FD_CC

  if test -f conftest.$SO ; then
    mv conftest.$SO myconftest.so

    OLD_CFLAGS="$CFLAGS"
    
    CFLAGS="$CFLAGS $LINKFORSHARED"
    OLD_CC="$CC"
    case "$LD" in
      *shlicc)
        CC="$BINDIR/smartlink shlicc"
      ;;
    esac
    AC_TRY_RUN([
#define TESTING
#include "dynamic_load.c"
void testfunc2(void) { exit(0); }
], pike_cv_sys_dynamic_loading=yes, pike_cv_sys_dynamic_loading=no, pike_cv_sys_dynamic_loading=no)
    CFLAGS="$OLD_CFLAGS"
    CC="$OLD_CC"
  else    
    pike_cv_sys_dynamic_loading=no
  fi
  rm -f myconftest.so >/dev/null 2>/dev/null
])
AC_MSG_RESULT($pike_cv_sys_dynamic_loading)


if test "x$with_dynamic_modules" != "xno" ; then
  if test x$pike_cv_sys_dynamic_loading = xno ; then
    with_dynamic_modules=no
  else
    with_dynamic_modules=yes
  fi
fi

crt_type=static

if test x$with_dynamic_modules = xyes \
     -a x$enable_dll = xyes \
     -a "x$pike_cv_sys_os" = xWindows_NT ; then
  # If dlls are enabled then compile for and link with the dynamic crt
  # to make all modules share the same crt instance.
  crt_type=dynamic
  AC_DEFINE(USE_DLL)
fi

# Let the --with-crt argument override the chosen crt linkage.
test x"$with_crt" != x && crt_type="$with_crt"

INSTALL_EXPORT_ARGS=

if test x"$crt_type" = xdynamic; then
  CFLAGS="$CFLAGS $dynamic_crt_flag"
  if test x$with_debug_crt = xyes; then
    INSTALL_EXPORT_ARGS="${INSTALL_EXPORT_ARGS} --debug-crt"
  else
    INSTALL_EXPORT_ARGS="${INSTALL_EXPORT_ARGS} --release-crt"
  fi
elif test x"$crt_type" = xstatic; then
  CFLAGS="$CFLAGS $static_crt_flag"
else
  AC_MSG_ERROR([Pass either "static" or "dynamic" to --with-crt])
fi

AC_SUBST(INSTALL_EXPORT_ARGS)

# In case the normal libz is linked to the dynamic crt we need to use
# a different one linked with the static crt for the exe installer. We
# check if there is such a thing in the build environment with the
# nonstandard name "z_static".
UNCOMPRESS_LIBZ=-lz
AC_CHECK_LIB(z_static, inflate, [UNCOMPRESS_LIBZ=-lz_static])
AC_SUBST(UNCOMPRESS_LIBZ)

#######################################################################
# Since configure doesn't always know if we will be linking with ld or cc,
# We use this little code snippet to add flags to ld that would otherwise
# be given automatically by $(CC) $(CFLAGS)
# /Hubbe
#
if test "$ldflags_is_set" = no ; then
case "x$LD $LDFLAGS" in
  *\$\(CFLAGS\)*)
    # Options in CFLAGS, no stuff needs to be added
  ;;
  x$CC*|x\$\(CC\)*)
    LD="$LD \$(CFLAGS)"
  ;;
  *)
    LD="$LD ${LD_FALLBACK_FLAGS-}"
  ;;
esac

case "x$LDSHARED $LDFLAGS" in
  *\$\(CFLAGS\)*)
    # Options in CFLAGS, no stuff needs to be added
  ;;
  x$CC*|x\$\(CC\)*)
    LDSHARED="$LDSHARED $STATIC_LIBGCC \$(CFLAGS)"
  ;;
  *)
    LDSHARED="$LDSHARED ${LD_FALLBACK_FLAGS-}"
  ;;
esac
fi

##########################################################################

case "x$pike_cv_sys_os" in
  xWindows_NT)
    signal_handler="custom NT"
  ;;

  xAmigaOS)
    signal_handler="custom AmigaOS"
  ;;

  xLinux | *kFreeBSD*)
    # Linux's stupid thread implementation doesn't survive USE_WAIT_THREAD.
    signal_handler="SIGCHILD"
    AC_DEFINE(USE_SIGCHILD)
  ;;

  *)
    # This is valid for at least Solaris, AIX and Darwin.
    if grep _REENTRANT confdefs.h >/dev/null 2>&1; then
      signal_handler="wait thread"
      AC_DEFINE(USE_WAIT_THREAD)
    else
      signal_handler="SIGCHILD"
      AC_DEFINE(USE_SIGCHILD)
    fi
  ;;
esac

#######################################################################
# Since all $OPTIMIZE flags have to be automatically included in $CFLAGS
# (because otherwise the tests will not be accurate) we have to remove all
# OPTIMIZE flags from the regular CFLAGS...
# (also some other misc work on the flags)

INTERPRET_DEOPTIMIZE=

OPT_GOT_OFLAG=no
OPT_GOT_MCPU=no
OPT_GOT_MTUNE=no
OPT_GOT_MARCH=no
NEW_CFLAGS=
NEW_OPTIMIZE=
OPT_NOT_USED=
for opt in ${CFLAGS-}
do
   case " $OPTIMIZE " in
     *\ $opt\ *) ;;
     *)
       case "$opt" in
	  +O*|-O*)
	    if test "x$OPT_GOT_OFLAG" = "xno"; then
              # only use the first -O flag (from make.conf etc)
	      OPT_GOT_OFLAG=yes 
	      if test "x$with_copt" != xno; then 
		OPTIMIZE="${OPTIMIZE-} $opt" 
	      else
	        OPT_NOT_USED="${OPT_NOT_USED-} $opt"
              fi
	    fi
	    ;;
	  -f*) 
	    if test "x$opt" = "x-fomit-frame-pointer" -a \
	            "x$with_machine_code" = xyes; then
	       INTERPRET_DEOPTIMIZE=-fno-omit-frame-pointer
	       PIKE_MSG_WARN([-fno-omit-frame-pointer used for interpret.c,
since the use of machine code is broken by -fomit-frame-pointer.])
	    fi

	    if test "x$with_copt" != xno; then 
	      OPTIMIZE="${OPTIMIZE-} $opt" 
	    else
	      OPT_NOT_USED="${OPT_NOT_USED-} $opt"
	    fi
	    ;;
	  -parallel|-ip*)
	    # Flags used by icc and ecc.
	    # They need to be propagated to the linker.
	    OPTIMIZE="${OPTIMIZE-} $opt"
	    EXTRALDFLAGS="${EXTRALDFLAGS} $opt"
	    ;;
          -pipe) 
	    OPTIMIZE="${OPTIMIZE-} $opt" 
	    ;;
	  -mcpu*)
            if test "x$OPT_GOT_MCPU" = xno; then 
 	      NEW_CFLAGS="$NEW_CFLAGS $opt"  
	      OPT_GOT_MCPU=yes
	    fi
            ;;
	  -mtune*)
	    if test "x$OPT_GOT_MTUNE" = xno; then
 	      NEW_CFLAGS="$NEW_CFLAGS $opt"  
	      OPT_GOT_MTUNE=yes
	    fi
            ;;
	  -march*)
            if test "x$OPT_GOT_MARCH" = xno; then 
 	      NEW_CFLAGS="$NEW_CFLAGS $opt"  
	      OPT_GOT_MARCH=yes
	    fi
            ;;
          *)  
	    NEW_CFLAGS="$NEW_CFLAGS $opt" 
	    ;;
       esac
     ;;
   esac
done
CFLAGS="$NEW_CFLAGS"

unset NEW_CFLAGS
unset OPT_GOT_OFLAG
unset OPT_GOT_MCPU
unset OPT_GOT_MTUNE
unset OPT_GOT_ARCH

AC_SUBST(INTERPRET_DEOPTIMIZE)

#############################################################################
dnl handled above in the CFLAGS/OPTIMIZE split
dnl if test "x$with_copt" = xno ; then
dnl   OPTIMIZE=

dnl The unused code below can be used to implement a good/bad-list
dnl to determine when to zap the -O2 for buggy gccs...
dnl
dnl  else
dnl
dnl  if test "x$GCC" = xyes; then
dnl    BAD=unknown
dnl    case `gcc -v 2>&1` in
dnl      */i?86-*/2.95.3/*19991030*) BAD=no ;;
dnl    esac
dnl  fi

dnl fi

#############################################################################
# Remove the extra args temporarily added to CPPFLAGS.

for extra_arg in $CONF_CPPFLAGS_EXTRA; do
  NEW_CPPFLAGS=""
  for arg in $CPPFLAGS; do
    test "$arg" = "$extra_arg" || NEW_CPPFLAGS="$NEW_CPPFLAGS $arg"
  done
  CPPFLAGS="$NEW_CPPFLAGS"
done

#############################################################################

# The following set of substitution variables are used to implement
# two quite different building orders in the makefile. See the comment
# above the "pike" target in Makefile.in.

if test x$with_dynamic_modules = xyes ; then
  dmmsrc="modules/dynamic_module_makefile.in"
  DYNAMIC_MODULE_FLAGS="-DDYNAMIC_MODULE"
  CCSHARED="${CCSHARED} ${DYNAMIC_MODULE_FLAGS}"
  PIKE_LIB="libpike.so"
  MODULE_O=tmodule.o
  BUILD_PIKE=pike
  POST_MODULE_BUILD_TYPE=dynamic
  STATIC_POST_MODULES_LINKOPTS=
else
  dmmsrc="modules/static_module_makefile.in"
  PIKE_LIB="libpike.a"
  MODULE_O=module.o
  BUILD_PIKE=tpike
  POST_MODULE_BUILD_TYPE=static
  STATIC_POST_MODULES_LINKOPTS=post_modules/linker_options
  DYNAMIC_MODULE_FLAGS=""
fi

AC_SUBST(PIKE_LIB)
AC_SUBST(MODULE_O)
AC_SUBST(BUILD_PIKE)
AC_SUBST(POST_MODULE_BUILD_TYPE)
AC_SUBST(STATIC_POST_MODULES_LINKOPTS)
AC_SUBST(DYNAMIC_MODULE_FLAGS)

#############################################################################

PMOD_TARGETS=`echo $srcdir/*.cmod | sed -e "s/\.cmod/\.c/g" | sed -e "s|$srcdir/|\\$(SRCDIR)/|g"`
test "$PMOD_TARGETS" = '$(SRCDIR)/*.c' && PMOD_TARGETS=
AC_SUBST(PMOD_TARGETS)

#############################################################################

# Microsoft has decided to make our lives yet more complicated by
# introducing a fancy dependency tracking system in VC8. It got
# manifest files (oooh!) written in xml (aahh!). It got a linker that
# can't make binaries with the dependency info built in from the
# beginning. It got an amazing array of special cases and quirky rules
# on how crt dlls may be loaded and not that's almost certain to nail
# you sooner or later. All in all, it's the most insanely overcomplex
# system to keep your exe and dlls from loading that stinkin' little
# crt dll you can ever imagine. For the full story, see
# http://www.codeproject.com/cpp/vcredists_x86.asp.

if test "x$MTEXE" != x; then
  # Embed the manifests. C.f. http://msdn2.microsoft.com/en-us/library/ms235591.aspx
  # You might want to disable this if you want to try private crts.
  # See also the PRIVATE_CRT parts of install.pike.
  MT_FIX_PIKE_EXE="\
    @if test -f pike.exe.manifest; then \
      echo \"$MTEXE -nologo -manifest pike.exe.manifest '-outputresource:pike.exe;1'\"; \
      $MTEXE -nologo -manifest pike.exe.manifest '-outputresource:pike.exe;1'; \
    else :; fi"
  MT_FIX_MODULE_SO="\
    @if test -f module.so.manifest; then \
      echo \"$MTEXE -nologo -manifest module.so.manifest '-outputresource:module.so;2'\"; \
      $MTEXE -nologo -manifest module.so.manifest '-outputresource:module.so;2'; \
    else :; fi"
else
  MT_FIX_PIKE_EXE=@:
  MT_FIX_MODULE_SO=@:
fi

AC_SUBST(MT_FIX_PIKE_EXE)

if test "x$RCEXE" != x; then
  # Windows icon
  PIKE_ICON_RES=pike_icon.res
fi
AC_SUBST(PIKE_ICON_RES)

if test "x$enable_pikelib" != "xno"; then
  # Everything needs to be compiled for library use.
  CFLAGS="$CFLAGS $CCSHARED"
  CCSHARED=""
fi

#############################################################################

echo
echo "Compiler summary:"
echo
echo "C Compiler:    $CC"
echo "Preprocessor:  $CPP"
echo "Linker:        $LD"
echo "Shared linker: $LDSHARED"
echo
echo "Shared object extension: $SO"
echo "Dynamic modules: $with_dynamic_modules"
echo
echo "PIKE_LIB:      $PIKE_LIB"
echo
echo "CPPFLAGS:      $CPPFLAGS"
echo "CFLAGS:        $CFLAGS"
echo "CCSHARED:      $CCSHARED"
echo "LINKFORSHARED: $LINKFORSHARED"
echo "LIBGCC:        $LIBGCC"
echo "WARN:          $WARN"
echo "PROFIL:        $PROFIL"
echo "OPTIMIZE:      $OPTIMIZE"
echo "LDFLAGS:       $LDFLAGS"
echo "LIBS:          $LIBS"
echo "prefix:        $prefix"
echo

#############################################################################

export LDFLAGS CFLAGS CPPFLAGS LIBS
export prefix exec_prefix OTHERFLAGS
export DEFINES INSTALL
export noopt_retry

PIKE_SRC_DIR=$srcdir
export PIKE_SRC_DIR
BUILD_BASE=`pwd`
export BUILD_BASE

if test "$pike_cv_sys_os" = "Windows_NT"; then
  # If this doesn't begin with '/', it's relative to pike.exe.
  default_master=../lib/master.pike
else
  default_master=$prefix/pike/%d.%d.%d/lib/master.pike
fi
AC_DEFINE_UNQUOTED(DEFAULT_MASTER,"$default_master")

AC_SUBST(OSFLAGS)
AC_SUBST(WARN)
AC_SUBST(PROFIL)
AC_SUBST(OPTIMIZE)
AC_SUBST(EXTRA_OBJS)
AC_SUBST(RANLIB)
AC_SUBST(DEBUGDEF)
AC_SUBST(EXTRA_MODULE_REQUIREMENTS)
AC_SUBST(noopt_retry)

pike_cv_prog_CC="${CC}"

#############################################################################

AC_CONFIG_SUBDIRS(modules post_modules)

AC_SUBST_FILE(dependencies)
dependencies=$srcdir/dependencies

AC_SUBST(YACC)
AC_SUBST(INSTALL)
AC_SUBST(ac_configure_args)

AC_SUBST(dmmsrc)

common_module_makefile=modules/common_module_makefile
AC_SUBST_FILE(common_module_makefile)

# Assignments for make_variables.in.

# Afaik BUILDDIR/TMP_BUILDDIR and BINDIR/TMP_BINDIR are always the
# same thing. Can it be cleaned up? /mast
TMP_BUILDDIR=$BUILDDIR
TMP_BINDIR=$BINDIR

BASE_CFLAGS=$CFLAGS
BASE_CPPFLAGS=$CPPFLAGS
MOD_LDSHARED="$LDSHARED $LDSHARED_MODULE_ARGS"

# Put LIBS into the LDFLAGS that the modules will use. This is
# necessary to keep compatibility with module configure scripts. Some
# modules don't expand @LIBS@ at all, so we can't use a BASE_LIBS to
# init the module LIBS.
BASE_LDFLAGS="$LDFLAGS $LIBS"

#
# Note: We must output before visiting the subdirs,
#       since we need *_module_makefile to exist.
#

AC_OUTPUT(Makefile \
          modules/common_module_makefile \
          modules/static_module_makefile \
          post_modules/static_module_makefile:modules/static_module_makefile.in \
          modules/dynamic_module_makefile:$dmmsrc \
          post_modules/dynamic_module_makefile:$dmmsrc \
	  precompile.sh specs, [
	    case "x$CONFIG_HEADERS" in
	      *machine.h*) echo foo >stamp-h ;;
	    esac
	    chmod +x precompile.sh
          ])

# Check if we have to enable some bundles
if test "$pike_bundle_dir" = ""; then :; else
  bundle_info="`find . -type f -name '*.bundle'`"
  until test "x$bundle_info" = "x"; do
    # We have some bundles to enable.

    cat <<EOF


###################################################
# Extracting bundles...
#   Requested from:
`echo "$bundle_info"|sed -e 's/^/#     /'`
EOF
    bundles=`echo "$bundle_info" | sed -e 's/.*\///g' -e 's/\.bundle$//' | sort | uniq`
    # FIXME: Intra-bundle dependencies?
    for bundle in $bundles; do
      AC_MSG_CHECKING(for bundle $bundle)
      dist_file=no
      for dist in no `cd "$pike_bundle_dir" && echo ${bundle}*.tar.gz`; do
        if test -f "$pike_bundle_dir/$dist"; then
	  dist_file="$pike_bundle_dir/$dist"
	fi
      done
      AC_MSG_RESULT($dist_file)
      if test "$dist_file" = "no"; then
        AC_MSG_WARN([Bundle $bundle not found.
Requested from:
$bundle_info])
	if test "x$RECONFIGURE_BUNDLES" = "xyes"; then
	  # Avoid infinite loop.
	  exit 1;
	fi
      elif test -f "$pike_bundle_prefix/installed/$bundle"; then
	AC_MSG_WARN([Bundle $bundle already installed.
Requested from:
$bundle_info])
	if test "x$RECONFIGURE_BUNDLES" = "xyes"; then
	  # Avoid infinite loop.
	  exit 1;
	fi
      else
	# Mark bundle as installed to avoid loops.
	# FIXME: Depencencies between bundles?
	touch "${pike_bundle_prefix}/installed/$bundle"

        # First extract the bundle.

        # Bundle source is expected to be extracted into a directory
	# of the same name as the bundle.
        bundle_source_dir=`echo "$dist_file"|sed -e 's/.tar.gz$//'`

        if test -f "$bundle_source_dir/configure"; then
	  # Bundle source already extracted.
	  :
	else
	  echo "Extracting bundle $dist_file..."
	  ( cd "$pike_bundle_dir" && \
	    gzip -cd "$dist_file" | tar xf -
	  )
	fi
	patch_dir=`echo "${bundle_source_dir}" | sed -e "s@^${pike_bundle_dir}@${pike_bundle_dir}/patches@"`
	if test -d "${patch_dir}/."; then
	  # There are patches.
	  if test -f "${bundle_source_dir}/pike-patch.stamp"; then :; else
	    echo "Patching bundle $dist_file with files from ${patch_dir}..."
	    ( cd "${patch_dir}" && tar cf - . ) | \
	      ( cd "${bundle_source_dir}" && tar xf -)
	    if test -f "${patch_dir}/.touch-list"; then
	      for f in `cat "${patch_dir}/.touch-list"` pike-patch.stamp; do
	        touch "${bundle_source_dir}/$f"
	      done
	    else
	      touch "${bundle_source_dir}/pike-patch.stamp"
	    fi
	  fi
	fi
	if test -d "bundles/$bundle.build" || \
	   mkdir "bundles/$bundle.build"; then :; else
	  echo "Failed to create bundle build directory bundles/$bundle.build"
	  exit 1
	fi
	( cd "bundles/$bundle.build" || exit 1

	  # Make sure stuff in /usr/ccs/bin and the like can be found.
	  # We also want to hide some possibly broken binaries (notably
	  # makeinfo) with ${pike_bundle_prefix}/bin.
	  OLD_PATH="$PATH"
	  PATH="${pike_bundle_prefix}/bin:$PATH:$EXTRA_PATH"
	  export PATH

	  if test -f "Makefile"; then :; else
            # Configure bundle.
	    # Note
	    #  * Configure for installation in $pike_bundle_prefix.
	    #  * Make sure that only static libraries are built.
	    #  * Make sure it uses a cache file, and that it doesn't
	    #    conflict with ours.

	    if test -f "$bundle_source_dir/configure"; then :; else
	      echo "Bundle configure script $bundle_source_dir/configure not found."
	      exit 1
	    fi

	    echo "Configuring bundle $bundle_source_dir in `pwd`..."

	    if test "$BUNDLE_FLAGS" = ""; then :; else
	      echo "BUNDLE_FLAGS: $BUNDLE_FLAGS"
	    fi

	    # INSTALL seems to be thrashed here, since we're in a
	    # subshell unsetting it shouldn't be a problem.
	    unset INSTALL

	    # Any libraries must be compiled with -pic, since we want
	    # to be able use them in dynamic modules.
	    OLD_CFLAGS="$CFLAGS"
	    CFLAGS="$CCSHARED $CFLAGS"
	    export CFLAGS

	    # --disable-openssl
	    #   The Nettle 1.13 checks for openssl aren't strict enough, so
	    #   linking with openssl is enabled even though there are
	    #   missing symbols. This also disables compilation of some
	    #   dead benchmark code.
	    #
	    # --disable-dependency-tracking
	    #   Nettles Makefiles aren't compatible with some makes
	    #   (BSD make in particular) if this is enabled, and
	    #   since we build from scratch the dependencies aren't
	    #   needed anyway.
	    extra_configure_args="$BUNDLE_FLAGS --disable-openssl --disable-dependency-tracking"

	    # Some libraries insist in using config.guess;
	    # they tend to have problems with rntcl...
	    # Let's help them along.
	    # They might also try to assemble machinecode, which is
	    # not likely to work with rntcl et al.
	    if echo foo "$CC" | egrep 'rntc.|rnt.cl' >/dev/null; then
	      cpu="`uname -m`"
	      case "$cpu-$with_abi" in
	        *86-32|*amd*-32|*86_64-32)
	          # Normalize the cpu.
	          cpu="i386"
		;;
		*86-64|*amd*-64|*86_64-64)
		  cpu="x86_64"
		;;
	      esac
	      extra_configure_args="${extra_configure_args} --build=${cpu}-unknown-winnt`uname -r|sed -e 's/-/_/g'` --disable-assembler"
	    else
	    # Regular cross-compilation, without rtncl
	      if test "x$cross_compiling" = "xyes" -a "x$host_alias" != x; then
		extra_configure_args="${extra_configure_args} --host=$host_alias"
	      fi
	    fi

	    echo "${CONFIG_SHELL-/bin/sh} \"$bundle_source_dir/configure\"" \
	      "--prefix=\"$pike_bundle_prefix\"" ${extra_configure_args} \
	      "--disable-shared --cache-file=config.cache"
	    ${CONFIG_SHELL-/bin/sh} "$bundle_source_dir/configure" \
	      --prefix="$pike_bundle_prefix" ${extra_configure_args} \
	      --disable-shared --cache-file=config.cache

	    code="$?"

	    # Restore CFLAGS
	    CFLAGS="$OLD_CFLAGS"

	    if test "x$code" = "x0"; then :; else
	      echo "Configure of bundle $bundle failed. Disabling." >&2
	      echo "Configure of bundle $bundle failed. Disabling." >&AC_FD_CC
	      exit 1
	    fi

	    if test -f "Makefile"; then :; else
	      echo "Makefile not found in `pwd`."
	      exit 1
	    fi
	  fi

	  # Do we need to patch the Makefiles with respect to SHELL?
	  if test "$pike_cv_make_supports_spaces_in_SHELL" = "no"; then
	    echo "Patching Makefiles..."
	    echo "Patching Makefiles..." >&AC_FD_CC
	    for f in `find . -type f \( -name Makefile -o -name makefile \) -print`; do
	      echo "  Patching $f..."
	      echo "  Patching $f..." >&AC_FD_CC
	      sed -e '/^SHELL[ 	]*=/s/^SHELL/PIKE_SHELL/' \
		  -e 's/\$(SHELL)/\$(PIKE_SHELL)/g' <"$f" >"$f.pike.patch" \
		  2>&AC_FD_CC || exit 1
	      if cmp "$f" "$f.pike.patch" >&AC_FD_CC 2>&AC_FD_CC; then
	        echo "  No change."
	        echo "  No change." >&AC_FD_CC
	        rm -f "$f.pike.patch"
	      else
	        echo "  Changed."
	        echo "  Diff:" >&AC_FD_CC
	        diff "$f" "$f.pike.patch" >&AC_FD_CC 2>&AC_FD_CC
	        mv -f "$f.pike.patch" "$f" || exit 1
	      fi
	    done
	  fi

	  # Do we need to patch the assembler files?
	  if test "$pike_cv_sys_os" = "Darwin"; then
	    uname -p | if egrep 'i[[3-9]]86' >/dev/null; then
	      # as/Darwin/x86 complains about alignments > 15.
	      # Nettle uses alignment 16...
	      echo "Darwin `uname -p` detected."
	      echo "Searching for asm files..."
	      find . -name '*.asm' -print | while read asm; do
	        echo "Found $asm."
	        if egrep '^[[ 	]]*.align[[ 	]]*16' "$asm" >/dev/null; then
	          echo "Patching alignment in $asm..."
	          if sed -e 's/^\([[ 	]]*.align[[ 	]]*\)16/\18/' \
		    <"$asm" >"$asm.new"; then
		    mv "$asm" "$asm.orig"
		    mv -f "$asm.new" "$asm"
		  else
		    PIKE_MSG_WARN(Patching of bundle assembler file $asm failed.)
		  fi
	        fi
	      done
	    fi
	  fi

	  # Compile bundle.
	  echo "Compiling bundle $bundle in `pwd`..."
	  ${MAKE-make} || exit 1

	  # Install bundle.
	  echo "Installing bundle $bundle in ${pike_bundle_prefix}..."
	  ${MAKE-make} install || exit 1

	  # Restore PATH
	  PATH="$OLD_PATH"

	  # Done.
	  echo "Bundle $bundle installed successfully."
	) || (
	  PIKE_MSG_WARN([Failed to install bundle $bundle.])
        )
      fi
    done
    echo "Fixing libraries..."
    # Kludge for rntcl in case *.lib hasn't been copied on install.
    if echo foo "$CC" | egrep 'rntc.|rnt.cl' >/dev/null; then
      for f in `(cd bundles/lib && echo lib*.a)` no; do
        if test "$f" = "no"; then
	  break
	fi
        lib_name="`echo $f|sed -e 's/^lib\(.*\)\.a$/\1.lib/'`"
	if cmp "bundles/lib/$f" "bundles/lib/$lib_name" 2>/dev/null; then
	  :
	else
	  echo "  $f ==> $lib_name"
	  rm -f "bundles/lib/$lib_name" 2>/dev/null
	  cp "bundles/lib/$f" "bundles/lib/$lib_name"
	fi
      done
    fi
    # Kludge for some OSes needing ranlib to be run on archives after install.
    for f in bundles/lib/lib*.a no; do
      if test "$f" = "no"; then
	break
      fi
      $RANLIB $f
    done
    # Clear the caches.
    echo Clearing cached variables related to the bundles.
    for varname in `cat $bundle_info|sed -e 's/^[[ 	]]*//'|sort|uniq` no; do
      if test "$varname" = "no"; then :; else
	unset $varname
      fi
    done
    if test -r "$cache_file"; then
      for varname in `cat $bundle_info|sed -e 's/^[[ 	]]*//'|sort|uniq` no; do
        if test "$varname" = "no"; then :; else
          sed -e '/^'"$varname"'=/d' <"$cache_file" >"$cache_file.new" && \
            mv -f "$cache_file.new" "$cache_file" || exit 1
        fi
      done
    fi
    # Rerun configure
    cat <<EOF


Rerunning halted configures with the bundles `echo $bundles` enabled.


EOF

    # Inform the sub-configures that only the modules that requested
    # bundles to be enabled need to be reconfigured.

    RECONFIGURE_BUNDLES="yes"
    export RECONFIGURE_BUNDLES

    _AC_OUTPUT_SUBDIRS

    bundle_info="`find . -type f -name '*.bundle'`"
  done
fi

# NOTE: M4 uses [] as quotes.

PIKE_VERSION="`sed -n -e 's/^.*PIKE_MAJOR_VERSION[[ \t]]*\([[^ \t]]*\)/\1/p' <$srcdir/version.h`.`sed -n -e 's/^.*PIKE_MINOR_VERSION[[ \t]]*\([[^ \t]]*\)/\1/p' <$srcdir/version.h`.`sed -n -e 's/^.*PIKE_BUILD_VERSION[[ \t]]*\([[^ \t]]*\)/\1/p' <$srcdir/version.h`"
PIKE_VERSION_LONG="Pike v`sed -n -e 's/^.*PIKE_MAJOR_VERSION[[ \t]]*\([[^ \t]]*\)/\1/p' <$srcdir/version.h`.`sed -n -e 's/^.*PIKE_MINOR_VERSION[[ \t]]*\([[^ \t]]*\)/\1/p' <$srcdir/version.h` release `sed -n -e 's/^.*PIKE_BUILD_VERSION[[ \t]]*\([[^ \t]]*\)/\1/p' <$srcdir/version.h`"


if test "x$with_cdebug" = x; then
  with_cdebug=no
fi
if test "x$with_rtldebug" = x; then
  with_rtldebug=no
fi
if test "x$with_dmalloc" = x; then
  with_dmalloc=no
fi
with_mmx=$pike_cv_sys_has_working_mmx
if test "x$with_mmx" = x; then
  with_mmx=no
fi

if test "x$with_copt" = xno ; then 
  opt_reasons="  ($OPT_NOT_USED turned off with --without-copt)"
else
  opt_reasons=
fi

rm -f config.info 2>/dev/null

float_is_ieee=""
if test "x$float_type" = "xfloat" -a "x$pike_cv_float_type" = "xieee_big"; then
  float_is_ieee=" (ieee big endian)"
elif test "x$float_type" = "xfloat" -a "x$pike_cv_float_type" = "xieee_little"; then
  float_is_ieee=" (ieee little endian)"
elif test "x$float_type" = "xdouble" -a "x$pike_cv_double_type" = "xieee_big"; then
  float_is_ieee=" (ieee big endian)"
elif test "x$float_type" = "xdouble" -a "x$pike_cv_double_type" = "xieee_little"; then
  float_is_ieee=" (ieee little endian)"
fi

cat >>config.info <<EOF
=========================================================
$PIKE_VERSION_LONG configuration summary

install information:
prefix........ $prefix
pike binary... $prefix/bin/pike
pike library.. $prefix/pike/${PIKE_VERSION}/lib

system information:
system.... $UNAME`echo $pike_cv_libgcc_filename | sed -n -e 's+^.*gcc-lib/\([[^/]]*\)/.*$+ (\1)+p'`
EOF

uname -a >/dev/null 2>/dev/null && echo "uname..... `uname -a`" >>config.info
hostname >/dev/null 2>/dev/null && echo "hostname.. `hostname`" >>config.info
whoami >/dev/null 2>/dev/null   && echo "user...... `whoami`" >>config.info

# too many dots makes too long lines, keep them as short as possible
# inside each section

cat >>config.info <<EOF

build information:
source path..... $srcdir
build path...... $BUILDDIR
ABI............. $with_abi
cpp............. $CPP
cc.............. $CC
ld.............. $LD
cc shared....... $CCSHARED
ld shared....... $LINKFORSHARED
pike............ $PIKE
install......... $INSTALL
shared object... .$SO
libs............ $LIBS
cross-compiled.. $cross_compiling
building lib.... $enable_pikelib
CPPFLAGS........$CPPFLAGS
CFLAGS (opt)....$OPTIMIZE$opt_reasons
CFLAGS (warn)...$WARN
CFLAGS (misc)...$CFLAGS $OSFLAGS $PROFIL
LDFLAGS.........$LDFLAGS $LINKFORSHARED $EXTRALDFLAGS
EOF

# insert information about debugging tools here, if they are turned on
if test "x$with_valgrind" != xno ; then 
  cat >>config.info <<EOF
valgrind........ yes, using $VALGRIND $VALGRINDARGS
EOF
fi

cat >>config.info <<EOF

features:
PAD_FEATURE([dynamic loading])$pike_cv_sys_dynamic_loading
PAD_FEATURE([threads])$using_threads
PAD_FEATURE([signal handler])$signal_handler
PAD_FEATURE([cdebug])$with_cdebug
PAD_FEATURE([rtldebug])$with_rtldebug
PAD_FEATURE([dmalloc])$with_dmalloc
PAD_FEATURE([dlmalloc])$enable_dlmalloc
PAD_FEATURE([mmx])$with_mmx$mmx_reason
PAD_FEATURE([byte code format])$byte_code_format
PAD_FEATURE([module reloc])${with_relocatable_dumped_modules:-no}
PAD_FEATURE([use machine code])$with_machine_code
PAD_FEATURE([int type])$int_type ($sizeof_int_type bytes)
PAD_FEATURE([float type])$float_type ($sizeof_float_type bytes)$float_is_ieee
PAD_FEATURE([pointer size])$ac_cv_sizeof_char_p bytes
EOF

touch confdefs.h 2>/dev/null

OLD_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="-I. -I$srcdir $CPPFLAGS"
AC_TRY_RUN([
#include <stdio.h>
#include "svalue.h"

int main()
{
   FILE *fp, *out;
   char float_type[80] = "?";
   char int_type[80] = "?";
   char *s;
   struct svalue sval;

   out=fopen("config.info", "a");
   if (!out) return 1;

   fprintf(out,"]PAD_FEATURE([svalue size])[%d bytes (%d+%d+%d)\n",
           sizeof(sval),
           sizeof(sval.type),
           sizeof(sval.subtype),
           sizeof(sval.u));

   fclose(out);

   return 0;
}
],[],[],[:])
rm -f conftypes.txt 2>/dev/null
CPPFLAGS="$OLD_CPPFLAGS"

echo >>config.info

ls -1 pike_*.feature 2>/dev/null | xargs cat | sort >>config.info 
ls -1 post_modules/*/pike_*.feature modules/*/pike_*.feature 2>/dev/null |  xargs cat | sort >>config.info

if test -f config.warnings; then
  echo >>config.info
  echo 'Warnings and notes summary:' >>config.info
  echo >>config.info
  cat config.warnings >>config.info
fi

echo

echo "=========================================================" >>config.info

cat config.info

if test "x$config_fail" = "x"; then :; else
  echo 1>&2
  echo 1>&2
  echo "Configuration error: $config_fail" 1>&2
  echo 1>&2
  exit 1
fi
