Restore deprecation warnings, except for older libpng.
[bpt/emacs.git] / configure.in
index 0504033..4df1284 100644 (file)
@@ -37,9 +37,11 @@ dnl hence the single quotes.  This is per the GNU coding standards, see
 dnl (autoconf) Installation Directory Variables
 dnl See also epaths.h below.
 lispdir='${datadir}/emacs/${version}/lisp'
+leimdir='${datadir}/emacs/${version}/leim'
+standardlisppath='${lispdir}:${leimdir}'
 locallisppath='${datadir}/emacs/${version}/site-lisp:'\
 '${datadir}/emacs/site-lisp'
-lisppath='${locallisppath}:${lispdir}:${datadir}/emacs/${version}/leim'
+lisppath='${locallisppath}:${standardlisppath}'
 etcdir='${datadir}/emacs/${version}/etc'
 archlibdir='${libexecdir}/emacs/${version}/${configuration}'
 docdir='${datadir}/emacs/${version}/etc'
@@ -229,24 +231,6 @@ AC_ARG_ENABLE(ns-self-contained,
    EN_NS_SELF_CONTAINED=$enableval,
    EN_NS_SELF_CONTAINED=yes)
 
-AC_ARG_ENABLE(asserts,
-[AS_HELP_STRING([--enable-asserts], [compile code with asserts enabled])],
-      USE_XASSERTS=$enableval,
-      USE_XASSERTS=no)
-
-AC_ARG_ENABLE(maintainer-mode,
-[AS_HELP_STRING([--disable-maintainer-mode],
-                [disable make rules and dependencies not useful (and sometimes
-                confusing) to the casual installer])],
-      USE_MAINTAINER_MODE=$enableval,
-      USE_MAINTAINER_MODE=yes)
-if test $USE_MAINTAINER_MODE = yes; then
-  MAINT=
-else
-  MAINT=#
-fi
-AC_SUBST(MAINT)
-
 AC_ARG_ENABLE(locallisppath,
 [AS_HELP_STRING([--enable-locallisppath=PATH],
                 [directories Emacs should search for lisp files specific
@@ -263,7 +247,7 @@ AC_ARG_ENABLE(checking,
                 enable only specific categories of checks.
                 Categories are: all,yes,no.
                 Flags are: stringbytes, stringoverrun, stringfreelist,
-                xmallocoverrun, conslist])],
+                xmallocoverrun, conslist, glyphs])],
 [ac_checking_flags="${enableval}"],[])
 IFS="${IFS=    }"; ac_save_IFS="$IFS"; IFS="$IFS,"
 for check in $ac_checking_flags
@@ -276,19 +260,22 @@ do
                        ac_gc_check_string_overrun= ;
                        ac_gc_check_string_free_list= ;
                        ac_xmalloc_overrun= ;
-                       ac_gc_check_cons_list= ;;
+                       ac_gc_check_cons_list= ;
+                       ac_glyphs_debug= ;;
        all)            ac_enable_checking=1 ;
                        ac_gc_check_stringbytes=1 ;
                        ac_gc_check_string_overrun=1 ;
                        ac_gc_check_string_free_list=1 ;
                        ac_xmalloc_overrun=1 ;
-                       ac_gc_check_cons_list=1 ;;
+                       ac_gc_check_cons_list=1 ;
+                       ac_glyphs_debug=1 ;;
        # these enable particular checks
        stringbytes)    ac_gc_check_stringbytes=1 ;;
        stringoverrun)  ac_gc_check_string_overrun=1 ;;
        stringfreelist) ac_gc_check_string_free_list=1 ;;
        xmallocoverrun) ac_xmalloc_overrun=1 ;;
        conslist)       ac_gc_check_cons_list=1 ;;
+       glyphs)         ac_glyphs_debug=1 ;;
        *)      AC_MSG_ERROR(unknown check category $check) ;;
        esac
 done
@@ -296,7 +283,7 @@ IFS="$ac_save_IFS"
 
 if test x$ac_enable_checking != x ; then
   AC_DEFINE(ENABLE_CHECKING, 1,
-[Enable expensive run-time checking of data types?])
+[Define to 1 if expensive run-time data type and consistency checks are enabled.])
 fi
 if test x$ac_gc_check_stringbytes != x ; then
   AC_DEFINE(GC_CHECK_STRING_BYTES, 1,
@@ -320,14 +307,18 @@ if test x$ac_gc_check_cons_list != x ; then
   AC_DEFINE(GC_CHECK_CONS_LIST, 1,
 [Define this to check for errors in cons list.])
 fi
+if test x$ac_glyphs_debug != x ; then
+  AC_DEFINE(GLYPH_DEBUG, 1,
+[Define this to enable glyphs debugging code.])
+fi
 
-AC_ARG_ENABLE(use-lisp-union-type,
-[AS_HELP_STRING([--enable-use-lisp-union-type],
-                [use a union for the Lisp_Object data type.
-               This is only useful for development for catching certain types of bugs.])],
+AC_ARG_ENABLE(check-lisp-object-type,
+[AS_HELP_STRING([--enable-check-lisp-object-type],
+                [enable compile time checks for the Lisp_Object data type.
+               This is useful for development for catching certain types of bugs.])],
 if test "${enableval}" != "no"; then
-   AC_DEFINE(USE_LISP_UNION_TYPE, 1,
-   [Define this to use a lisp union for the Lisp_Object data type.])
+   AC_DEFINE(CHECK_LISP_OBJECT_TYPE, 1,
+   [Define this to enable compile time checks for the Lisp_Object data type.])
 fi)
 
 
@@ -374,8 +365,8 @@ case "${srcdir}" in
   *  ) srcdir="`(cd ${srcdir}; pwd)`" ;;
 esac
 
-#### Given the configuration name, set machfile and opsysfile to the
-#### names of the m/*.h and s/*.h files we should use.
+#### Given the configuration name, set opsysfile to the
+#### name of s/*.h file we should use.
 
 ### Canonicalize the configuration name.
 
@@ -395,13 +386,11 @@ dnl quotation begins
 
 ### If you add support for a new configuration, add code to this
 ### switch statement to recognize your configuration name and select
-### the appropriate operating system and machine description files.
+### the appropriate operating system file.
 
-### You would hope that you could choose an m/*.h file pretty much
-### based on the machine portion of the configuration name, and an s/*.h
+### You would hope that you could choose an s/*.h
 ### file based on the operating system portion.  However, it turns out
-### that each m/*.h file is pretty manufacturer-specific - for
-### example mips.h is MIPS
+### that each s/*.h file is pretty manufacturer-specific.
 ### So we basically have to have a special case for each
 ### configuration name.
 ###
@@ -411,95 +400,49 @@ dnl quotation begins
 ### prepared to handle anything reasonably.  If version numbers
 ### matter, be sure /etc/MACHINES says something about it.
 
-machine='' opsys='' unported=no
+opsys='' unported=no
 case "${canonical}" in
 
   ## GNU/Linux and similar ports
   *-*-linux* )
     opsys=gnu-linux
-    case ${canonical} in
-      alpha*)  machine=alpha ;;
-      s390x-*) machine=ibms390x ;;
-      powerpc*)        machine=macppc ;;
-      sparc*)  machine=sparc ;;
-      ia64*)   machine=ia64 ;;
-      m68k*)   machine=m68k ;;
-      x86_64*) machine=amdx86-64 ;;
-    esac
   ;;
 
   ## FreeBSD ports
   *-*-freebsd* )
     opsys=freebsd
-    case "${canonical}" in
-      alpha*)           machine=alpha ;;
-      amd64-*|x86_64-*) machine=amdx86-64 ;;
-      ia64-*)           machine=ia64 ;;
-      i[3456]86-*)      machine=intel386 ;;
-      powerpc-*)        machine=macppc ;;
-      sparc-*)          machine=sparc ;;
-      sparc64-*)        machine=sparc ;;
-    esac
   ;;
 
   ## FreeBSD kernel + glibc based userland
   *-*-kfreebsd*gnu* )
     opsys=gnu-kfreebsd
-    case "${canonical}" in
-      alpha*)           machine=alpha ;;
-      amd64-*|x86_64-*) machine=amdx86-64 ;;
-      ia64-*)           machine=ia64 ;;
-      i[3456]86-*)      machine=intel386 ;;
-      powerpc-*)        machine=macppc ;;
-      sparc-*)          machine=sparc ;;
-      sparc64-*)        machine=sparc ;;
-    esac
   ;;
 
   ## NetBSD ports
   *-*-netbsd* )
     opsys=netbsd
-    case "${canonical}" in
-      alpha*)      machine=alpha ;;
-      x86_64-*)    machine=amdx86-64 ;;
-      i[3456]86-*) machine=intel386 ;;
-      m68k-*)      machine=m68k ;;
-      powerpc-*)   machine=macppc ;;
-      sparc*-)     machine=sparc ;;
-      vax-*)       machine=vax ;;
-    esac
   ;;
 
   ## OpenBSD ports
   *-*-openbsd* )
     opsys=openbsd
-    case "${canonical}" in
-      alpha*)    machine=alpha ;;
-      x86_64-*)  machine=amdx86-64 ;;
-      i386-*)    machine=intel386 ;;
-      powerpc-*) machine=macppc ;;
-      sparc*)    machine=sparc ;;
-      vax-*)     machine=vax ;;
-    esac
   ;;
 
   ## Apple Darwin / Mac OS X
   *-apple-darwin* )
     case "${canonical}" in
-      i[3456]86-* )  machine=intel386 ;;
-      powerpc-* )    machine=macppc ;;
-      x86_64-* )     machine=amdx86-64 ;;
+      i[3456]86-* )  ;;
+      powerpc-* )    ;;
+      x86_64-* )     ;;
       * )            unported=yes ;;
     esac
     opsys=darwin
-    # Define CPP as follows to make autoconf work correctly.
-    CPP="${CC-cc} -E -no-cpp-precomp"
-    # Use fink packages if available.
-    if test -d /sw/include && test -d /sw/lib; then
-      GCC_TEST_OPTIONS="-I/sw/include -L/sw/lib"
-      CPP="${CPP} ${GCC_TEST_OPTIONS}"
-      NON_GCC_TEST_OPTIONS=${GCC_TEST_OPTIONS}
-    fi
+    ## Use fink packages if available.
+    ## FIXME find a better way to do this: http://debbugs.gnu.org/11507
+##    if test -d /sw/include && test -d /sw/lib; then
+##      GCC_TEST_OPTIONS="-I/sw/include -L/sw/lib"
+##      NON_GCC_TEST_OPTIONS=${GCC_TEST_OPTIONS}
+##    fi
   ;;
 
   ## HP 9000 series 700 and 800, running HP/UX
@@ -513,16 +456,16 @@ case "${canonical}" in
 
   ## IBM machines
   rs6000-ibm-aix4.[23]* )
-    machine=ibmrs6000 opsys=aix4-2
+    opsys=aix4-2
   ;;
   powerpc-ibm-aix4.[23]*  )
-    machine=ibmrs6000 opsys=aix4-2
+    opsys=aix4-2
   ;;
   rs6000-ibm-aix[56]* )
-    machine=ibmrs6000 opsys=aix4-2
+    opsys=aix4-2
   ;;
   powerpc-ibm-aix[56]*  )
-    machine=ibmrs6000 opsys=aix4-2
+    opsys=aix4-2
   ;;
 
   ## Silicon Graphics machines
@@ -532,7 +475,6 @@ case "${canonical}" in
     # Without defining _LANGUAGE_C, things get masked out in the headers
     # so that, for instance, grepping for `free' in stdlib.h fails and
     # AC_HEADER_STD_C fails.   (MIPSPro 7.2.1.2m compilers, Irix 6.5.3m).
-    NON_GNU_CPP="/lib/cpp -D_LANGUAGE_C"
     NON_GCC_TEST_OPTIONS="-D_LANGUAGE_C"
   ;;
 
@@ -541,26 +483,23 @@ case "${canonical}" in
     | i[3456]86-*-solaris2* | i[3456]86-*-sunos5* \
     | x86_64-*-solaris2*    | x86_64-*-sunos5*)
     case "${canonical}" in
-      i[3456]86-*-* )     machine=intel386 ;;
-      amd64-*-*|x86_64-*-*)    machine=amdx86-64 ;;
-      sparc* )         machine=sparc ;;
+      i[3456]86-*-* )   ;;
+      amd64-*-*|x86_64-*-*) ;;
+      sparc* )         ;;
       * )              unported=yes ;;
     esac
     case "${canonical}" in
       *-sunos5.6* | *-solaris2.6* )
                opsys=sol2-6
-               NON_GNU_CPP=/usr/ccs/lib/cpp
                RANLIB="ar -ts"
                ;;
       *-sunos5.[7-9]* | *-solaris2.[7-9]* )
                opsys=sol2-6
                emacs_check_sunpro_c=yes
-               NON_GNU_CPP=/usr/ccs/lib/cpp
                ;;
       *-sunos5* | *-solaris* )
                opsys=sol2-10
                emacs_check_sunpro_c=yes
-               NON_GNU_CPP=/usr/ccs/lib/cpp
                ;;
     esac
     ## Watch out for a compiler that we know will not work.
@@ -578,15 +517,12 @@ case "${canonical}" in
 
   ## Intel 386 machines where we don't care about the manufacturer.
   i[3456]86-*-* )
-    machine=intel386
     case "${canonical}" in
       *-cygwin )                opsys=cygwin ;;
-      *-darwin* )               opsys=darwin
-                                CPP="${CC-cc} -E -no-cpp-precomp"
-                               ;;
-      *-sysv4.2uw* )           opsys=unixware; NON_GNU_CPP=/lib/cpp ;;
-      *-sysv5uw* )             opsys=unixware; NON_GNU_CPP=/lib/cpp ;;
-      *-sysv5OpenUNIX* )       opsys=unixware; NON_GNU_CPP=/lib/cpp ;;
+      *-darwin* )               opsys=darwin ;;
+      *-sysv4.2uw* )           opsys=unixware ;;
+      *-sysv5uw* )             opsys=unixware ;;
+      *-sysv5OpenUNIX* )       opsys=unixware ;;
       ## Otherwise, we'll fall through to the generic opsys code at the bottom.
     esac
   ;;
@@ -619,76 +555,29 @@ if test $unported = yes; then
 Check `etc/MACHINES' for recognized configuration names.])
 fi
 
-if test -n "$machine"; then
-  machfile="m/${machine}.h"
-else
-  machfile=
-fi
 opsysfile="s/${opsys}.h"
 
 
 #### Choose a compiler.
-test -n "$CC" && cc_specified=yes
-
-# Save the value of CFLAGS that the user specified.
-SPECIFIED_CFLAGS="$CFLAGS"
 
 dnl Sets GCC=yes if using gcc.
 AC_PROG_CC
 AM_PROG_CC_C_O
 
-# Initialize gnulib right after verifying that the C compiler works.
-gl_EARLY
-
-# On Suns, sometimes $CPP names a directory.
-if test -n "$CPP" && test -d "$CPP"; then
-  CPP=
-fi
-
-## If not using gcc, and on Solaris, and no CPP specified, see if
-## using a Sun compiler, which needs -Xs to prevent whitespace.
-if test x"$GCC" != xyes && test x"$emacs_check_sunpro_c" = xyes && \
- test x"$CPP" = x; then
-  AC_MSG_CHECKING([whether we are using a Sun C compiler])
-  AC_CACHE_VAL(emacs_cv_sunpro_c,
-  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
-[[#ifndef __SUNPRO_C
-fail;
-#endif
-]])], emacs_cv_sunpro_c=yes, emacs_cv_sunpro_c=no)])
-  AC_MSG_RESULT($emacs_cv_sunpro_c)
-
-  if test x"$emacs_cv_sunpro_c" = xyes; then
-    NON_GNU_CPP="$CC -E -Xs"
-  fi
-fi
-
-#### Some systems specify a CPP to use unless we are using GCC.
-#### Now that we know whether we are using GCC, we can decide whether
-#### to use that one.
-if test "x$NON_GNU_CPP" != x && test x$GCC != xyes && test "x$CPP" = x
-then
-  CPP="$NON_GNU_CPP"
-fi
-
-#### Some systems specify a CC to use unless we are using GCC.
-#### Now that we know whether we are using GCC, we can decide whether
-#### to use that one.
-if test "x$NON_GNU_CC" != x && test x$GCC != xyes &&
-  test x$cc_specified != xyes
-then
-  CC="$NON_GNU_CC"
-fi
-
 if test x$GCC = xyes; then
   test "x$GCC_TEST_OPTIONS" != x && CC="$CC $GCC_TEST_OPTIONS"
 else
   test "x$NON_GCC_TEST_OPTIONS" != x && CC="$CC $NON_GCC_TEST_OPTIONS"
 fi
 
+# Initialize gnulib right after choosing the compiler.
+gl_EARLY
+
 AC_ARG_ENABLE([gcc-warnings],
   [AS_HELP_STRING([--enable-gcc-warnings],
-                  [turn on lots of GCC warnings (for developers)])],
+                  [turn on lots of GCC warnings. This is intended for
+                  developers, and may generate false alarms when used
+                  with older or non-GNU development tools.])],
   [case $enableval in
      yes|no) ;;
      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
@@ -697,6 +586,32 @@ AC_ARG_ENABLE([gcc-warnings],
   [gl_gcc_warnings=no]
 )
 
+AC_ARG_ENABLE(link-time-optimization,
+[AS_HELP_STRING([--enable-link-time-optimization],
+                [build emacs with link-time optimization.
+                 This is supported only for GCC since 4.5.0.])],
+if test "${enableval}" != "no"; then
+   AC_MSG_CHECKING([whether link-time optimization is supported])
+   ac_lto_supported=no
+   if test x$GCC = xyes; then
+      CPUS=`getconf _NPROCESSORS_ONLN 2>/dev/null`
+      if test x$CPUS != x; then
+        LTO="-flto=$CPUS"
+      else
+        LTO="-flto"
+      fi
+      old_CFLAGS=$CFLAGS
+      CFLAGS="$CFLAGS $LTO"
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+       [ac_lto_supported=yes], [ac_lto_supported=no])
+      CFLAGS="$old_CFLAGS"
+   fi
+   AC_MSG_RESULT([$ac_lto_supported])
+   if test "$ac_lto_supported" = "yes"; then
+      CFLAGS="$CFLAGS $LTO"
+   fi
+fi)
+
 # gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found])
 # ------------------------------------------------
 # If $CPP is gcc-MAJOR.MINOR or newer, then run RUN-IF-FOUND.
@@ -747,16 +662,19 @@ else
   nw="$nw -Wsign-conversion"        # Too many warnings for now
   nw="$nw -Woverlength-strings"     # Not a problem these days
   nw="$nw -Wtraditional-conversion" # Too many warnings for now
+  nw="$nw -Wunreachable-code"       # so buggy that it's now silently ignored
   nw="$nw -Wpadded"                 # Our structs are not padded
-  nw="$nw -Wredundant-decls"        # We regularly (re)declare getenv etc.
+  nw="$nw -Wredundant-decls"        # we regularly (re)declare functions
   nw="$nw -Wlogical-op"             # any use of fwrite provokes this
-  nw="$nw -Wformat-nonliteral"      # Emacs does this a lot
+  nw="$nw -Wformat-nonliteral"      # we do this a lot
   nw="$nw -Wvla"                    # warnings in gettext.h
   nw="$nw -Wnested-externs"         # use of XARGMATCH/verify_function__
   nw="$nw -Wswitch-enum"            # Too many warnings for now
   nw="$nw -Wswitch-default"         # Too many warnings for now
-  nw="$nw -Wfloat-equal"            # e.g., ftoastr.c
-  nw="$nw -Winline"                 # e.g., dispnew.c's inlining of row_equal_p
+  nw="$nw -Wfloat-equal"            # warns about high-quality code
+  nw="$nw -Winline"                 # OK to ignore 'inline'
+  nw="$nw -Wsync-nand"              # irrelevant here, and provokes ObjC warning
+  nw="$nw -Wunsafe-loop-optimizations" # OK to suppress unsafe optimizations
 
   # Emacs doesn't care about shadowing; see
   # <http://lists.gnu.org/archive/html/emacs-diffs/2011-11/msg00265.html>.
@@ -803,34 +721,23 @@ fi
 
 
 
-#### Some other nice autoconf tests.
-
-dnl checks for programs
-AC_PROG_CPP
-AC_PROG_INSTALL
-if test "x$RANLIB" = x; then
-  AC_PROG_RANLIB
-fi
-
-## Although we're running on an amd64 kernel, we're actually compiling for
-## the x86 architecture.  The user should probably have provided an
-## explicit --build to `configure', but if everything else than the kernel
-## is running in i386 mode, we can help them out.
-if test "$machine" = "amdx86-64"; then
-  AC_CHECK_DECL([i386])
-  if test "$ac_cv_have_decl_i386" = "yes"; then
-    canonical=`echo "$canonical" | sed -e 's/^amd64/i386/' -e 's/^x86_64/i386/'`
-    machine=intel386
-    machfile="m/${machine}.h"
-  fi
-fi
+dnl Some other nice autoconf tests.
+dnl These are commented out, since gl_EARLY and/or Autoconf already does them.
+dnl AC_PROG_INSTALL
+dnl AC_PROG_MKDIR_P
+dnl if test "x$RANLIB" = x; then
+dnl   AC_PROG_RANLIB
+dnl fi
 
-AC_PATH_PROG(INSTALL_INFO, install-info)
-AC_PATH_PROG(INSTALL_INFO, install-info,, /usr/sbin)
-AC_PATH_PROG(INSTALL_INFO, install-info,:, /sbin)
+AC_PATH_PROG(INSTALL_INFO, install-info, :,
+  $PATH$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/sbin)
 dnl Don't use GZIP, which is used by gzip for additional parameters.
 AC_PATH_PROG(GZIP_PROG, gzip)
 
+if test $opsys = gnu-linux; then
+  AC_PATH_PROG(PAXCTL, paxctl,,
+    [$PATH$PATH_SEPARATOR/sbin$PATH_SEPARATOR/usr/sbin])
+fi
 
 ## Need makeinfo >= 4.7 (?) to build the manuals.
 AC_PATH_PROG(MAKEINFO, makeinfo, no)
@@ -865,6 +772,12 @@ with the `--without-makeinfo' option to build without the manuals.] )
 fi
 AC_SUBST(HAVE_MAKEINFO)
 
+dnl Just so that there is only a single place we need to edit.
+INFO_EXT=.info
+INFO_OPTS=--no-split
+AC_SUBST(INFO_EXT)
+AC_SUBST(INFO_OPTS)
+
 dnl Add our options to ac_link now, after it is set up.
 
 if test x$GCC = xyes; then
@@ -895,11 +808,6 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
   [AC_MSG_RESULT(no)])
 
 
-# The value of CPP is a quoted variable reference, so we need to do this
-# to get its actual value...
-CPP=`eval "echo $CPP"`
-
-
 dnl The function dump-emacs will not be defined and temacs will do
 dnl (load "loadup") automatically unless told otherwise.
 test "x$CANNOT_DUMP" = "x" && CANNOT_DUMP=no
@@ -951,7 +859,9 @@ case "$opsys" in
    ## Let `ld' find image libs and similar things in /usr/local/lib.
    ## The system compiler, GCC, has apparently been modified to not
    ## look there, contrary to what a stock GCC would do.
-   LD_SWITCH_SYSTEM=-L/usr/local/lib
+### It's not our place to do this.  See bug#10313#17.
+###   LD_SWITCH_SYSTEM=-L/usr/local/lib
+      :
    ;;
 
   gnu-linux)
@@ -960,7 +870,9 @@ case "$opsys" in
    ;;
 
   netbsd)
-   LD_SWITCH_SYSTEM="-Wl,-rpath,/usr/pkg/lib -L/usr/pkg/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib"
+### It's not our place to do this.  See bug#10313#17.
+###   LD_SWITCH_SYSTEM="-Wl,-rpath,/usr/pkg/lib -L/usr/pkg/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib"
+      :
    ;;
 
   openbsd)
@@ -973,7 +885,7 @@ AC_SUBST(LD_SWITCH_SYSTEM)
 
 ac_link="$ac_link $LD_SWITCH_SYSTEM"
 
-## This setting of LD_SWITCH_SYSTEM references LD_SWITCH_X_SITE_AUX_RPATH,
+## This setting of LD_SWITCH_SYSTEM references LD_SWITCH_X_SITE_RPATH,
 ## which has not been defined yet.  When this was handled with cpp,
 ## it was expanded to null when configure sourced the s/*.h file.
 ## Thus LD_SWITCH_SYSTEM had different values in configure and the Makefiles.
@@ -985,12 +897,13 @@ ac_link="$ac_link $LD_SWITCH_SYSTEM"
 ## LD_SWITCH_SYSTEM_TEMACS.
 case "$opsys" in
   netbsd|openbsd)
-   LD_SWITCH_SYSTEM="\$(LD_SWITCH_X_SITE_AUX_RPATH) $LD_SWITCH_SYSTEM" ;;
+   LD_SWITCH_SYSTEM="\$(LD_SWITCH_X_SITE_RPATH) $LD_SWITCH_SYSTEM" ;;
 esac
 
 
 C_SWITCH_MACHINE=
-if test "$machine" = "alpha"; then
+case $canonical in
+ alpha*)
   AC_CHECK_DECL([__ELF__])
   if test "$ac_cv_have_decl___ELF__" = "yes"; then
     ## With ELF, make sure that all common symbols get allocated to in the
@@ -1006,7 +919,8 @@ if test "$machine" = "alpha"; then
   else
     UNEXEC_OBJ=unexalpha.o
   fi
-fi
+  ;;
+esac
 AC_SUBST(C_SWITCH_MACHINE)
 
 AC_SUBST(UNEXEC_OBJ)
@@ -1052,13 +966,15 @@ AC_DEFUN([AC_TYPE_SIZE_T])
 # Likewise for obsolescent test for uid_t, gid_t; Emacs assumes them.
 AC_DEFUN([AC_TYPE_UID_T])
 
-dnl Do this early because it can frob feature test macros for Unix-98 &c.
-AC_SYS_LARGEFILE
-
 
 LIB_MATH=-lm
 LIB_STANDARD=
 START_FILES=
+dnl Current possibilities handled by sed (aix4-2 -> aix,
+dnl gnu-linux -> gnu/linux, etc.):
+dnl gnu, gnu/linux, gnu/kfreebsd, aix, cygwin, darwin, hpux, irix.
+dnl And special cases: berkeley-unix, usg-unix-v, ms-dos, windows-nt.
+SYSTEM_TYPE=`echo $opsys | sed -e 's/[[0-9]].*//' -e 's|-|/|'`
 
 dnl NB do not use CRT_DIR unquoted here, since it might not be set yet.
 case $opsys in
@@ -1074,6 +990,7 @@ case $opsys in
   freebsd )
     LIB_STANDARD='-lgcc -lc -lgcc $(CRT_DIR)/crtend.o $(CRT_DIR)/crtn.o'
     START_FILES='pre-crt0.o $(CRT_DIR)/crt1.o $(CRT_DIR)/crti.o $(CRT_DIR)/crtbegin.o'
+    SYSTEM_TYPE=berkeley-unix
     ;;
   gnu-linux | gnu-kfreebsd )
     LIB_STANDARD='-lgcc -lc -lgcc $(CRT_DIR)/crtn.o'
@@ -1087,11 +1004,19 @@ case $opsys in
   netbsd | openbsd )
     LIB_STANDARD='-lgcc -lc -lgcc $(CRT_DIR)/crtend.o'
     START_FILES='pre-crt0.o $(CRT_DIR)/crt0.o $(CRT_DIR)/crtbegin.o'
+    SYSTEM_TYPE=berkeley-unix
+    ;;
+
+  sol2* | unixware )
+    SYSTEM_TYPE=usg-unix-v
     ;;
+
 esac
 
 AC_SUBST(LIB_MATH)
 AC_SUBST(START_FILES)
+AC_DEFINE_UNQUOTED(SYSTEM_TYPE, "$SYSTEM_TYPE",
+  [The type of system you are compiling for; sets `system-type'.])
 
 dnl Not all platforms use crtn.o files.  Check if the current one does.
 crt_files=
@@ -1180,6 +1105,15 @@ case $opsys in
 esac
 
 
+# Configure gnulib before invoking PKG_CHECK_MODULES, as the latter might
+# for example add -lrt to RSVG_LIBS, which would then cause gnulib to
+# incorrectly conclude that -lrt is not needed to link clock_gettime.
+gl_ASSERT_NO_GNULIB_POSIXCHECK
+gl_ASSERT_NO_GNULIB_TESTS
+gl_INIT
+
+AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
+
 dnl This function definition taken from Gnome 2.0
 dnl PKG_CHECK_MODULES(GSTUFF, gtk+-2.0 >= 1.3 glib = 1.3.4, action-if, action-not)
 dnl defines GSTUFF_LIBS, GSTUFF_CFLAGS, see pkg-config man page
@@ -1187,8 +1121,6 @@ dnl also defines GSTUFF_PKG_ERRORS on error
 AC_DEFUN([PKG_CHECK_MODULES], [
   succeeded=no
 
-  AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
-
   if test "$PKG_CONFIG" = "no" ; then
      ifelse([$4], , [AC_MSG_ERROR([
       *** The pkg-config script could not be found. Make sure it is in your path, or give the full path to pkg-config with the PKG_CONFIG environment variable or --with-pkg-config-prog.  Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config.])], [$4])
@@ -1289,10 +1221,10 @@ if test "${with_sound}" != "no"; then
 fi
 
 dnl checks for header files
-AC_CHECK_HEADERS(sys/select.h sys/time.h unistd.h utime.h \
-  linux/version.h sys/systeminfo.h \
-  stdio_ext.h fcntl.h coff.h pty.h sys/mman.h \
-  sys/vlimit.h sys/resource.h locale.h sys/_mbstate_t.h \
+AC_CHECK_HEADERS_ONCE(
+  linux/version.h sys/systeminfo.h
+  stdio_ext.h fcntl.h coff.h pty.h
+  sys/vlimit.h sys/resource.h
   sys/utsname.h pwd.h utmp.h dirent.h util.h)
 
 AC_MSG_CHECKING(if personality LINUX32 can be set)
@@ -1321,26 +1253,6 @@ if test $ac_cv_have_decl_sys_siglist != yes; then
 fi
 AC_HEADER_SYS_WAIT
 
-dnl Some systems have utime.h but don't declare the struct anyplace.
-AC_CACHE_CHECK(for struct utimbuf, emacs_cv_struct_utimbuf,
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifdef TIME_WITH_SYS_TIME
-#include <sys/time.h>
-#include <time.h>
-#else
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#else
-#include <time.h>
-#endif
-#endif
-#ifdef HAVE_UTIME_H
-#include <utime.h>
-#endif]], [[static struct utimbuf x; x.actime = x.modtime;]])],
-  emacs_cv_struct_utimbuf=yes, emacs_cv_struct_utimbuf=no))
-if test $emacs_cv_struct_utimbuf = yes; then
-  AC_DEFINE(HAVE_STRUCT_UTIMBUF, 1, [Define to 1 if `struct utimbuf' is declared by <utime.h>.])
-fi
-
 dnl Check for speed_t typedef.
 AC_CACHE_CHECK(for speed_t, emacs_cv_speed_t,
   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <termios.h>]], [[speed_t x = 1;]])],
@@ -1350,23 +1262,6 @@ if test $emacs_cv_speed_t = yes; then
           [Define to 1 if `speed_t' is declared by <termios.h>.])
 fi
 
-AC_CACHE_CHECK(for struct timeval, emacs_cv_struct_timeval,
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifdef TIME_WITH_SYS_TIME
-#include <sys/time.h>
-#include <time.h>
-#else
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#else
-#include <time.h>
-#endif
-#endif]], [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
-  emacs_cv_struct_timeval=yes, emacs_cv_struct_timeval=no))
-HAVE_TIMEVAL=$emacs_cv_struct_timeval
-if test $emacs_cv_struct_timeval = yes; then
-  AC_DEFINE(HAVE_TIMEVAL, 1, [Define to 1 if `struct timeval' is declared by <sys/time.h>.])
-fi
-
 AC_CACHE_CHECK(for struct exception, emacs_cv_struct_exception,
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <math.h>]],
 [[static struct exception x; x.arg1 = x.arg2 = x.retval; x.name = ""; x.type = 1;]])],
@@ -1376,7 +1271,7 @@ if test $emacs_cv_struct_exception != yes; then
   AC_DEFINE(NO_MATHERR, 1, [Define to 1 if you don't have struct exception in math.h.])
 fi
 
-AC_CHECK_HEADERS(sys/socket.h)
+AC_CHECK_HEADERS_ONCE(sys/socket.h)
 AC_CHECK_HEADERS(net/if.h, , , [AC_INCLUDES_DEFAULT
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
@@ -1389,7 +1284,6 @@ AC_CHECK_HEADERS(net/if_dl.h, , , [AC_INCLUDES_DEFAULT
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif])
-AC_CHECK_FUNCS(getifaddrs freeifaddrs)
 
 dnl checks for structure members
 AC_CHECK_MEMBERS([struct ifreq.ifr_flags, struct ifreq.ifr_hwaddr,
@@ -1404,29 +1298,8 @@ AC_CHECK_MEMBERS([struct ifreq.ifr_flags, struct ifreq.ifr_hwaddr,
 #include <net/if.h>
 #endif])
 
-dnl checks for compiler characteristics
-
-dnl Testing __STDC__ to determine prototype support isn't good enough.
-dnl DEC C, for instance, doesn't define it with default options, and
-dnl is used on 64-bit systems (OSF Alphas).  Similarly for volatile
-dnl and void *.
-AC_C_PROTOTYPES
-AC_C_VOLATILE
-AC_C_CONST
-AC_CACHE_CHECK([for void * support], emacs_cv_void_star,
-  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[void * foo;]])],
-                   emacs_cv_void_star=yes, emacs_cv_void_star=no)])
-if test $emacs_cv_void_star = yes; then
-  AC_DEFINE(POINTER_TYPE, void)
-else
-  AC_DEFINE(POINTER_TYPE, char)
-fi
-AH_TEMPLATE(POINTER_TYPE,
-           [Define as `void' if your compiler accepts `void *'; otherwise
-            define as `char'.])dnl
-
 dnl Check for endianness.
-AC_C_BIGENDIAN
+dnl AC_C_BIGENDIAN is done by gnulib.
 
 AC_CACHE_CHECK([for  __attribute__ ((__aligned__ (expr)))],
   [emacs_cv_attribute_aligned],
@@ -1442,7 +1315,7 @@ if test $emacs_cv_attribute_aligned = yes; then
 fi
 
 dnl check for Make feature
-AC_PROG_MAKE_SET
+dnl AC_PROG_MAKE_SET is done by Automake.
 
 DEPFLAGS=
 MKDEPDIR=":"
@@ -1470,10 +1343,8 @@ if test "$GCC" = yes && test "$ac_enable_autodepend" = yes; then
    fi
    if test $ac_enable_autodepend = yes; then
       DEPFLAGS='-MMD -MF ${DEPDIR}/$*.d -MP'
-      ## In parallel builds, another make might create depdir between
-      ## the first test and mkdir, so stick another test on the end.
-      ## Or use install-sh -d?  mkdir -p is not portable.
-      MKDEPDIR='test -d ${DEPDIR} || mkdir ${DEPDIR} || test -d ${DEPDIR}'
+      ## MKDIR_P is documented (see AC_PROG_MKDIR_P) to be parallel-safe.
+      MKDEPDIR='${MKDIR_P} ${DEPDIR}'
       deps_frag=autodeps.mk
    fi
 fi
@@ -1499,11 +1370,11 @@ else
   window_system=x11
 fi
 
-LD_SWITCH_X_SITE_AUX_RPATH=
+LD_SWITCH_X_SITE_RPATH=
 if test "${x_libraries}" != NONE; then
   if test -n "${x_libraries}"; then
     LD_SWITCH_X_SITE=-L`echo ${x_libraries} | sed -e "s/:/ -L/g"`
-    LD_SWITCH_X_SITE_AUX_RPATH=-Wl,-rpath`echo ${x_libraries} | sed -e "s/:/ -Wl,-rpath/g"`
+    LD_SWITCH_X_SITE_RPATH=-Wl,-rpath,`echo ${x_libraries} | sed -e "s/:/ -Wl,-rpath,/g"`
   fi
   x_default_search_path=""
   x_search_path=${x_libraries}
@@ -1526,7 +1397,7 @@ ${x_library}/X11/%T/%N%S"
     fi
   done
 fi
-AC_SUBST(LD_SWITCH_X_SITE_AUX_RPATH)
+AC_SUBST(LD_SWITCH_X_SITE_RPATH)
 
 if test "${x_includes}" != NONE && test -n "${x_includes}"; then
   C_SWITCH_X_SITE="$isystem"`echo ${x_includes} | sed -e "s/:/ $isystem/g"`
@@ -1559,20 +1430,17 @@ CPPFLAGS="$CPPFLAGS -x objective-c"
 CFLAGS="$CFLAGS -x objective-c"
 TEMACS_LDFLAGS2="\${LDFLAGS}"
 GNU_OBJC_CFLAGS=
-dnl I don't think it's especially important, but src/Makefile.in
-dnl (now the only user of ns_appdir) used to go to the trouble of adding a
-dnl trailing "/" to it, so now we do it here.
 if test "${with_ns}" != no; then
   if test "${opsys}" = darwin; then
      NS_IMPL_COCOA=yes
      ns_appdir=`pwd`/nextstep/Emacs.app
-     ns_appbindir=${ns_appdir}/Contents/MacOS/
+     ns_appbindir=${ns_appdir}/Contents/MacOS
      ns_appresdir=${ns_appdir}/Contents/Resources
      ns_appsrc=${srcdir}/nextstep/Cocoa/Emacs.base
   elif test -f $GNUSTEP_CONFIG_FILE; then
      NS_IMPL_GNUSTEP=yes
      ns_appdir=`pwd`/nextstep/Emacs.app
-     ns_appbindir=${ns_appdir}/
+     ns_appbindir=${ns_appdir}
      ns_appresdir=${ns_appdir}/Resources
      ns_appsrc=${srcdir}/nextstep/GNUstep/Emacs.base
      dnl FIXME sourcing this several times in subshells seems inefficient.
@@ -1626,6 +1494,8 @@ fail;
 fi
 AC_SUBST(TEMACS_LDFLAGS2)
 
+INSTALL_ARCH_INDEP_EXTRA=install-etc
+ns_self_contained=no
 ns_frag=/dev/null
 NS_OBJ=
 NS_OBJC_OBJ=
@@ -1638,9 +1508,21 @@ if test "${HAVE_NS}" = yes; then
   with_xft=no
   # set up packaging dirs
   if test "${EN_NS_SELF_CONTAINED}" = yes; then
+     ns_self_contained=yes
      prefix=${ns_appresdir}
      exec_prefix=${ns_appbindir}
-     libexecdir=${ns_appbindir}/libexec
+     dnl This one isn't really used, only archlibdir is.
+     libexecdir="\${ns_appbindir}/libexec"
+     archlibdir="\${ns_appbindir}/libexec"
+     docdir="\${ns_appresdir}/etc"
+     etcdir="\${ns_appresdir}/etc"
+     dnl FIXME maybe set datarootdir instead.
+     dnl That would also get applications, icons, man.
+     infodir="\${ns_appresdir}/info"
+     mandir="\${ns_appresdir}/man"
+     lispdir="\${ns_appresdir}/lisp"
+     leimdir="\${ns_appresdir}/leim"
+     INSTALL_ARCH_INDEP_EXTRA=
   fi
   ns_frag=$srcdir/src/ns.mk
   NS_OBJ="fontset.o fringe.o image.o"
@@ -1648,6 +1530,8 @@ if test "${HAVE_NS}" = yes; then
 fi
 CFLAGS="$tmp_CFLAGS"
 CPPFLAGS="$tmp_CPPFLAGS"
+AC_SUBST(INSTALL_ARCH_INDEP_EXTRA)
+AC_SUBST(ns_self_contained)
 AC_SUBST(NS_OBJ)
 AC_SUBST(NS_OBJC_OBJ)
 AC_SUBST(LIB_STANDARD)
@@ -1701,7 +1585,7 @@ case ${HAVE_X11} in
   yes ) HAVE_MENUS=yes ;;
 esac
 
-# Do the opsystem or machine files prohibit the use of the GNU malloc?
+# Does the opsystem file prohibit the use of the GNU malloc?
 # Assume not, until told otherwise.
 GNU_MALLOC=yes
 
@@ -1787,7 +1671,7 @@ AC_CHECK_LIB(Xbsd, main, LD_SWITCH_X_SITE="$LD_SWITCH_X_SITE -lXbsd")
 
 dnl Check if pthreads is available.
 LIB_PTHREAD=
-AC_CHECK_HEADERS(pthread.h)
+AC_CHECK_HEADERS_ONCE(pthread.h)
 if test "$ac_cv_header_pthread_h"; then
   dnl gmalloc.c uses pthread_atfork, which is not available on older-style
   dnl hosts such as MirBSD 10, so test for pthread_atfork instead of merely
@@ -1854,9 +1738,9 @@ if test "${HAVE_X11}" = "yes"; then
   CPPFLAGS="$C_SWITCH_X_SITE $CPPFLAGS"
 
   # On Solaris, arrange for LD_RUN_PATH to point to the X libraries for tests.
-  # This is handled by LD_SWITCH_X_SITE_AUX_RPATH during the real build,
+  # This is handled by LD_SWITCH_X_SITE_RPATH during the real build,
   # but it's more convenient here to set LD_RUN_PATH since this
-  # also works on hosts that don't understand LD_SWITCH_X_SITE_AUX_RPATH.
+  # also works on hosts that don't understand LD_SWITCH_X_SITE_RPATH.
   if test "${x_libraries}" != NONE && test -n "${x_libraries}"; then
     LD_RUN_PATH=$x_libraries${LD_RUN_PATH+:}$LD_RUN_PATH
     export LD_RUN_PATH
@@ -1910,7 +1794,7 @@ if test "${HAVE_X11}" = "yes"; then
   fi
 
   AC_CHECK_FUNCS(XrmSetDatabase XScreenResourceString \
-XScreenNumberOfScreen XSetWMProtocols)
+XScreenNumberOfScreen)
 fi
 
 if test "${window_system}" = "x11"; then
@@ -1974,7 +1858,7 @@ if test "${HAVE_X11}" = "yes"; then
       AC_DEFINE(HAVE_IMAGEMAGICK, 1, [Define to 1 if using imagemagick.])
       CFLAGS="$CFLAGS $IMAGEMAGICK_CFLAGS"
       LIBS="$IMAGEMAGICK_LIBS $LIBS"
-      AC_CHECK_FUNCS(MagickExportImagePixels)
+      AC_CHECK_FUNCS(MagickExportImagePixels MagickMergeImageLayers)
     fi
   fi
 fi
@@ -2084,8 +1968,10 @@ if test "${with_dbus}" = "yes"; then
      LIBS="$LIBS $DBUS_LIBS"
      AC_DEFINE(HAVE_DBUS, 1, [Define to 1 if using D-Bus.])
      dnl dbus_watch_get_unix_fd has been introduced in D-Bus 1.1.1.
-     dnl dbus_validate_* have been introduced in D-Bus 1.5.12.
+     dnl dbus_type_is_valid and dbus_validate_* have been introduced in
+     dnl D-Bus 1.5.12.
      AC_CHECK_FUNCS(dbus_watch_get_unix_fd \
+                   dbus_type_is_valid \
                    dbus_validate_bus_name \
                     dbus_validate_path \
                    dbus_validate_interface \
@@ -2564,7 +2450,7 @@ if test "${HAVE_X11}" = "yes"; then
   if test "${with_png}" != "no"; then
     # Debian unstable as of July 2003 has multiple libpngs, and puts png.h
     # in /usr/include/libpng.
-    AC_CHECK_HEADERS(png.h libpng/png.h)
+    AC_CHECK_HEADERS(png.h libpng/png.h, break)
     if test "$ac_cv_header_png_h" = yes || test "$ac_cv_header_libpng_png_h" = yes ; then
       AC_CHECK_LIB(png, png_get_channels, HAVE_PNG=yes, , -lz -lm)
     fi
@@ -2573,6 +2459,19 @@ if test "${HAVE_X11}" = "yes"; then
   if test "${HAVE_PNG}" = "yes"; then
     AC_DEFINE(HAVE_PNG, 1, [Define to 1 if you have the png library (-lpng).])
     LIBPNG="-lpng -lz -lm"
+
+    AC_CHECK_DECL(png_longjmp,
+      [],
+      [AC_DEFINE(PNG_DEPRECATED, [],
+        [Define to empty to suppress deprecation warnings when building
+         with --enable-gcc-warnings and with libpng versions before 1.5,
+         which lack png_longjmp.])],
+      [[#ifdef HAVE_LIBPNG_PNG_H
+       # include <libpng/png.h>
+       #else
+       # include <png.h>
+       #endif
+      ]])
   fi
 fi
 AC_SUBST(LIBPNG)
@@ -2660,7 +2559,7 @@ fi
 AC_SUBST(LIBGPM)
 
 dnl Check for malloc/malloc.h on darwin
-AC_CHECK_HEADER(malloc/malloc.h, [AC_DEFINE(HAVE_MALLOC_MALLOC_H, 1, [Define to 1 if you have the <malloc/malloc.h> header file.])])
+AC_CHECK_HEADERS_ONCE(malloc/malloc.h)
 
 GNUSTEP_CFLAGS=
 ### Use NeXTstep API to implement GUI.
@@ -2764,8 +2663,7 @@ This probably means that movemail could lose mail.
 There may be a `development' package to install containing liblockfile.])
   fi
 fi
-AC_CHECK_FUNCS(touchlock)
-AC_CHECK_HEADERS(maillock.h)
+AC_CHECK_HEADERS_ONCE(maillock.h)
 AC_SUBST(LIBS_MAIL)
 
 ## Define MAIL_USE_FLOCK (or LOCKF) if the mailer uses flock (or lockf) to
@@ -2810,18 +2708,35 @@ esac
 AC_SUBST(BLESSMAIL_TARGET)
 
 
-AC_CHECK_FUNCS(gethostname getdomainname \
-rename closedir mkdir rmdir sysinfo getrusage get_current_dir_name \
-random lrand48 logb frexp fmod rint cbrt ftime setsid \
-strerror fpathconf select euidaccess getpagesize tzset setlocale \
-utimes getrlimit setrlimit setpgid getcwd getwd shutdown getaddrinfo \
-__fpending mblen mbrlen mbsinit strsignal setitimer ualarm \
-sendto recvfrom getsockopt setsockopt getsockname getpeername \
-gai_strerror mkstemp getline getdelim mremap fsync sync \
-difftime mempcpy mblen mbrlen posix_memalign \
+AC_CHECK_FUNCS(gethostname \
+rename closedir mkdir rmdir getrusage get_current_dir_name \
+lrand48 logb frexp fmod cbrt setsid \
+strerror fpathconf select euidaccess getpagesize setlocale \
+utimes getrlimit setrlimit setpgid getcwd shutdown getaddrinfo \
+__fpending strsignal setitimer \
+sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \
+gai_strerror mkstemp getline getdelim fsync sync \
+difftime posix_memalign \
 getpwent endpwent getgrent endgrent \
+touchlock \
 cfmakeraw cfsetspeed copysign __executable_start)
 
+dnl getwd appears to be buggy on SVR4.2, so we don't use it.
+if test $opsys != unixware; then
+  AC_CHECK_FUNCS(getwd)
+fi
+
+## Eric Backus <ericb@lsid.hp.com> says, HP-UX 9.x on HP 700 machines
+## has a broken `rint' in some library versions including math library
+## version number A.09.05.
+## You can fix the math library by installing patch number PHSS_4630.
+## But we can fix it more reliably for Emacs by just not using rint.
+## We also skip HAVE_RANDOM - see comments in src/s/hpux10-20.h.
+case $opsys in
+   hpux*) : ;;
+   *) AC_CHECK_FUNCS(random rint) ;;
+esac
+
 dnl Cannot use AC_CHECK_FUNCS
 AC_CACHE_CHECK([for __builtin_unwind_init],
               emacs_cv_func___builtin_unwind_init,
@@ -2833,7 +2748,7 @@ if test $emacs_cv_func___builtin_unwind_init = yes; then
            [Define to 1 if you have the `__builtin_unwind_init' function.])
 fi
 
-AC_CHECK_HEADERS(sys/un.h)
+AC_CHECK_HEADERS_ONCE(sys/un.h)
 
 AC_FUNC_FSEEKO
 
@@ -2868,7 +2783,7 @@ AC_DEFUN([tputs_link_source], [
 ])
 # Maybe curses should be tried earlier?
 # See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9736#35
-for tputs_library in '' ncurses terminfo termcap curses; do
+for tputs_library in '' tinfo ncurses terminfo termcap curses; do
   OLIBS=$LIBS
   if test -z "$tputs_library"; then
     LIBS_TERMCAP=
@@ -2888,41 +2803,28 @@ done
 AC_MSG_RESULT([$msg])
 if test "X$msg" = Xno; then
   AC_MSG_ERROR([The required function `tputs' was not found in any library.
-These libraries were tried: libncurses, libterminfo, libtermcap, libcurses.
+The following libraries were tried (in order):
+  libtinfo, libncurses, libterminfo, libtermcap, libcurses
 Please try installing whichever of these libraries is most appropriate
 for your system, together with its header files.
 For example, a libncurses-dev(el) or similar package.])
 fi
-# Must define this when any termcap library is found.
-AC_DEFINE(HAVE_LIBNCURSES, 1,
-          [Define to 1 if you have the `ncurses' library (-lncurses).])
-## FIXME This was the cpp logic, but I am not sure it is right.
-## The above test has not necessarily found libncurses.
-HAVE_LIBNCURSES=yes
-
-## Use terminfo instead of termcap?
-## Note only system files NOT using terminfo are:
-## freebsd < 40000, ms-w32, msdos, netbsd < 599002500, and
-## darwin|gnu without ncurses.
-TERMINFO=no
-case "$opsys" in
-  ## cygwin: Fewer environment variables to go wrong, more terminal types.
-  ## hpux10-20: Use the system provided termcap(3) library.
-  ## openbsd: David Mazieres <dm@reeducation-labor.lcs.mit.edu> says this
-  ##  is necessary.  Otherwise Emacs dumps core when run -nw.
-  aix4-2|cygwin|hpux*|irix6-5|openbsd|sol2*|unixware) TERMINFO=yes ;;
 
+## Use termcap instead of terminfo?
+## Only true for: freebsd < 40000, ms-w32, msdos, netbsd < 599002500.
+TERMINFO=yes
+## FIXME?  In the cases below where we unconditionally set
+## LIBS_TERMCAP="-lncurses", this overrides LIBS_TERMCAP = -ltinfo,
+## if that was found above to have tputs.
+## Should we use the gnu* logic everywhere?
+case "$opsys" in
   ## darwin: Prevents crashes when running Emacs in Terminal.app under 10.2.
   ##  The ncurses library has been moved out of the System framework in
   ##  Mac OS X 10.2.  So if configure detects it, set the command-line
   ##  option to use it.
-  darwin|gnu*)
-    ## (HAVE_LIBNCURSES was not always true, but is since 2010-03-18.)
-    if test "x$HAVE_LIBNCURSES" = "xyes"; then
-      TERMINFO=yes
-      LIBS_TERMCAP="-lncurses"
-    fi
-    ;;
+  darwin) LIBS_TERMCAP="-lncurses" ;;
+
+  gnu*) test -z "$LIBS_TERMCAP" && LIBS_TERMCAP="-lncurses" ;;
 
   freebsd)
     AC_MSG_CHECKING([whether FreeBSD is new enough to use terminfo])
@@ -2936,34 +2838,29 @@ fail;
     AC_MSG_RESULT($emacs_cv_freebsd_terminfo)
 
     if test $emacs_cv_freebsd_terminfo = yes; then
-      TERMINFO=yes
       LIBS_TERMCAP="-lncurses"
     else
+      TERMINFO=no
       LIBS_TERMCAP="-ltermcap"
     fi
     ;;
 
   netbsd)
-    if test $ac_cv_search_tputs = -lterminfo; then
-      TERMINFO=yes
-      LIBS_TERMCAP="-lterminfo"
-    else
+    if test "x$LIBS_TERMCAP" != "x-lterminfo"; then
+      TERMINFO=no
       LIBS_TERMCAP="-ltermcap"
     fi
     ;;
 
-esac
+  openbsd) LIBS_TERMCAP="-lncurses" ;;
 
-case "$opsys" in
   ## hpux: Make sure we get select from libc rather than from libcurses
   ##  because libcurses on HPUX 10.10 has a broken version of select.
   ##  We used to use -lc -lcurses, but this may be cleaner.
+  ## FIXME?  But TERMINFO = yes on hpux (it used to be explicitly
+  # set that way, now it uses the default).  Isn't this a contradiction?
   hpux*) LIBS_TERMCAP="-ltermcap" ;;
 
-  openbsd) LIBS_TERMCAP="-lncurses" ;;
-
-  ## Must use system termcap, if we use any termcap.  It does special things.
-  sol2*) test "$TERMINFO" != yes && LIBS_TERMCAP="-ltermcap" ;;
 esac
 
 TERMCAP_OBJ=tparam.o
@@ -2976,33 +2873,40 @@ AC_SUBST(TERMCAP_OBJ)
 
 
 # Do we have res_init, for detecting changes in /etc/resolv.conf?
+# On Darwin, res_init appears not to be useful: see bug#562 and
+# http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01467.html
 resolv=no
-AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <netinet/in.h>
+
+if test $opsys != darwin; then
+
+  AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <netinet/in.h>
 #include <arpa/nameser.h>
 #include <resolv.h>]],
     [[return res_init();]])],
     have_res_init=yes, have_res_init=no)
-if test "$have_res_init" = no; then
-  OLIBS="$LIBS"
-  LIBS="$LIBS -lresolv"
-  AC_MSG_CHECKING(for res_init with -lresolv)
-  AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <netinet/in.h>
+  if test "$have_res_init" = no; then
+    OLIBS="$LIBS"
+    LIBS="$LIBS -lresolv"
+    AC_MSG_CHECKING(for res_init with -lresolv)
+    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <netinet/in.h>
 #include <arpa/nameser.h>
 #include <resolv.h>]],
-    [[return res_init();]])],
-    have_res_init=yes, have_res_init=no)
-  AC_MSG_RESULT($have_res_init)
-  if test "$have_res_init" = yes ; then
-    resolv=yes
+      [[return res_init();]])],
+      have_res_init=yes, have_res_init=no)
+    AC_MSG_RESULT($have_res_init)
+    if test "$have_res_init" = yes ; then
+      resolv=yes
+    fi
+    LIBS="$OLIBS"
   fi
-  LIBS="$OLIBS"
-fi
 
-if test "$have_res_init" = yes; then
-  AC_DEFINE(HAVE_RES_INIT, 1, [Define to 1 if res_init is available.])
-fi
+  if test "$have_res_init" = yes; then
+    AC_DEFINE(HAVE_RES_INIT, 1, [Define to 1 if res_init is available.])
+  fi
+fi                              dnl !darwin
 
 # Do we need the Hesiod library to provide the support routines?
+dnl FIXME?  Should we be skipping this on Darwin too?
 LIBHESIOD=
 if test "$with_hesiod" != no ; then
   # Don't set $LIBS here -- see comments above.  FIXME which comments?
@@ -3026,7 +2930,7 @@ fi
 AC_SUBST(LIBHESIOD)
 
 # Do we need libresolv (due to res_init or Hesiod)?
-if test "$resolv" = yes ; then
+if test "$resolv" = yes && test $opsys != darwin; then
   AC_DEFINE(HAVE_LIBRESOLV, 1,
             [Define to 1 if you have the resolv library (-lresolv).])
   LIBRESOLV=-lresolv
@@ -3118,6 +3022,7 @@ AC_SUBST(KRB5LIB)
 AC_SUBST(DESLIB)
 AC_SUBST(KRB4LIB)
 
+AC_CHECK_FUNCS(tzset)
 AC_MSG_CHECKING(whether localtime caches TZ)
 AC_CACHE_VAL(emacs_cv_localtime_cache,
 [if test x$ac_cv_func_tzset = xyes; then
@@ -3155,33 +3060,6 @@ if test $emacs_cv_localtime_cache = yes; then
            [Define to 1 if localtime caches TZ.])
 fi
 
-if test "x$HAVE_TIMEVAL" = xyes; then
-  AC_CHECK_FUNCS(gettimeofday)
-  if test $ac_cv_func_gettimeofday = yes; then
-    AC_CACHE_CHECK(whether gettimeofday can accept two arguments,
-                  emacs_cv_gettimeofday_two_arguments,
-    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
-#ifdef TIME_WITH_SYS_TIME
-#include <sys/time.h>
-#include <time.h>
-#else
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#else
-#include <time.h>
-#endif
-#endif]],
-      [[struct timeval time;
-       gettimeofday (&time, 0);]])],
-      emacs_cv_gettimeofday_two_arguments=yes,
-      emacs_cv_gettimeofday_two_arguments=no)])
-    if test $emacs_cv_gettimeofday_two_arguments = no; then
-      AC_DEFINE(GETTIMEOFDAY_ONE_ARGUMENT, 1,
-               [Define to 1 if gettimeofday accepts only one argument.])
-    fi
-  fi
-fi
-
 ok_so_far=yes
 AC_CHECK_FUNC(socket, , ok_so_far=no)
 if test $ok_so_far = yes; then
@@ -3247,6 +3125,54 @@ dnl                                and macros for terminal control.])
 dnl    AC_DEFINE(HAVE_TCATTR, 1, [Define to 1 if you have tcgetattr and tcsetattr.])
 dnl fi
 
+case $opsys in
+  darwin | gnu | hpux* | *bsd )
+    AC_DEFINE(NO_TERMIO, 1, [Define if termio.h should not be included.])
+  ;;
+esac
+
+dnl SIGIO exists, but the feature doesn't work in the way Emacs needs.
+dnl See eg <http://article.gmane.org/gmane.os.openbsd.ports/46831>.
+case $opsys in
+  hpux* | irix6-5 | openbsd | sol2* | unixware )
+    AC_DEFINE(BROKEN_SIGIO, 1, [Define if SIGIO should not be used.])
+  ;;
+esac
+
+case $opsys in
+  gnu-* | sol2-10 )
+    dnl FIXME Can't we test if this exists (eg /proc/$$)?
+    AC_DEFINE(HAVE_PROCFS, 1, [Define if you have the /proc filesystem.])
+  ;;
+esac
+
+case $opsys in
+   gnu-kfreebsd) opsysfile="s/gnu-linux.h" ;;
+
+   hpux11)
+     dnl See comments in sysdep.c:sys_signal.
+     dnl SA_RESTART resets the timeout of `select' on hpux11.
+     dnl Defining BROKEN_SA_RESTART is not the same as undef'ing SA_RESTART.
+     AC_DEFINE(BROKEN_SA_RESTART, 1, [Define if SA_RESTART should only
+       be used in batch mode.])
+     dnl It works to open the pty's tty in the parent (Emacs), then
+     dnl close and reopen it in the child.
+     AC_DEFINE(USG_SUBTTY_WORKS, 1, [Define for USG systems where it
+       works to open a pty's tty in the parent process, then close and
+       reopen it in the child.])
+
+     opsysfile="s/hpux10-20.h"
+   ;;
+
+   openbsd) opsysfile="s/netbsd.h" ;;
+
+   sol2-10)
+     AC_DEFINE(_STRUCTURED_PROC, 1, [Needed for system_process_attributes
+       on Solaris.])
+     opsysfile="s/sol2-6.h"
+   ;;
+esac
+
 # Set up the CFLAGS for real compilation, so we can substitute it.
 CFLAGS="$REAL_CFLAGS"
 CPPFLAGS="$REAL_CPPFLAGS"
@@ -3277,6 +3203,8 @@ AC_SUBST(libexecdir)
 AC_SUBST(mandir)
 AC_SUBST(infodir)
 AC_SUBST(lispdir)
+AC_SUBST(leimdir)
+AC_SUBST(standardlisppath)
 AC_SUBST(locallisppath)
 AC_SUBST(lisppath)
 AC_SUBST(x_default_search_path)
@@ -3295,13 +3223,11 @@ AC_SUBST(GNUSTEP_CFLAGS)
 AC_SUBST(CFLAGS)
 ## Used in lwlib/Makefile.in.
 AC_SUBST(X_TOOLKIT_TYPE)
-if test -n "${machfile}"; then
-  M_FILE="\$(srcdir)/${machfile}"
+if test -n "${opsysfile}"; then
+  S_FILE="\$(srcdir)/${opsysfile}"
 else
-  M_FILE=
+  S_FILE=
 fi
-S_FILE="\$(srcdir)/${opsysfile}"
-AC_SUBST(M_FILE)
 AC_SUBST(S_FILE)
 AC_SUBST(ns_appdir)
 AC_SUBST(ns_appbindir)
@@ -3314,12 +3240,10 @@ AC_DEFINE_UNQUOTED(EMACS_CONFIGURATION,  "${canonical}",
                   [Define to the canonical Emacs configuration name.])
 AC_DEFINE_UNQUOTED(EMACS_CONFIG_OPTIONS, "${ac_configure_args}",
                   [Define to the options passed to configure.])
-if test -n "$machfile"; then
-  AC_DEFINE_UNQUOTED(config_machfile,  "${machfile}",
-                    [Define to the used machine dependent file.])
+if test -n "$opsysfile"; then
+  AC_DEFINE_UNQUOTED(config_opsysfile, "${opsysfile}",
+                    [Define to the used os dependent file.])
 fi
-AC_DEFINE_UNQUOTED(config_opsysfile, "${opsysfile}",
-                  [Define to the used os dependent file.])
 
 XMENU_OBJ=
 XOBJ=
@@ -3469,11 +3393,6 @@ AC_SUBST(CYGWIN_OBJ)
 AC_SUBST(PRE_ALLOC_OBJ)
 AC_SUBST(POST_ALLOC_OBJ)
 
-# Configure gnulib here, now that we know LIBS.
-gl_ASSERT_NO_GNULIB_POSIXCHECK
-gl_ASSERT_NO_GNULIB_TESTS
-gl_INIT
-
 case "$opsys" in
   aix4-2) LD_SWITCH_SYSTEM_TEMACS="-Wl,-bnodelcsect" ;;
 
@@ -3496,8 +3415,7 @@ case "$opsys" in
    ##   #ifndef LD_SWITCH_SYSTEM
    ##   #if !defined (__GNUC__) && ((defined (BSD_SYSTEM) && !defined (COFF)))
    ## Since all the *bsds define LD_SWITCH_SYSTEM, this simplifies to:
-   ## not using gcc, darwin system not on an alpha (ie darwin, since
-   ## darwin + alpha does not occur).
+   ## not using gcc, darwin.
    ## Because this was done in src/Makefile.in, the resulting part of
    ## LD_SWITCH_SYSTEM was not used in configure (ie, in ac_link).
    ## It therefore seems cleaner to put this in LD_SWITCH_SYSTEM_TEMACS,
@@ -3506,14 +3424,14 @@ case "$opsys" in
      LD_SWITCH_SYSTEM_TEMACS="-X $LD_SWITCH_SYSTEM_TEMACS"
    ;;
 
-  ## LD_SWITCH_X_SITE_AUX_RPATH is a -rpath option saying where to
+  ## LD_SWITCH_X_SITE_RPATH is a -rpath option saying where to
   ## find X at run-time.
   ## When handled by cpp, this was in LD_SWITCH_SYSTEM.  However, at the
-  ## point where configure sourced the s/*.h file, LD_SWITCH_X_SITE_AUX_RPATH
+  ## point where configure sourced the s/*.h file, LD_SWITCH_X_SITE_RPATH
   ## had not yet been defined and was expanded to null.  Hence LD_SWITCH_SYSTEM
   ## had different values in configure (in ac_link) and src/Makefile.in.
   ## It seems clearer therefore to put this piece in LD_SWITCH_SYSTEM_TEMACS.
-  gnu*) LD_SWITCH_SYSTEM_TEMACS="\$(LD_SWITCH_X_SITE_AUX_RPATH)" ;;
+  gnu*) LD_SWITCH_SYSTEM_TEMACS="\$(LD_SWITCH_X_SITE_RPATH)" ;;
 
   *) LD_SWITCH_SYSTEM_TEMACS= ;;
 esac
@@ -3537,12 +3455,12 @@ case "$opsys" in
   ## will also work on earlier NetBSD releases.
   netbsd|openbsd) LD_FIRSTFLAG="-nostartfiles" ;;
 
-  ## macpcc: NAKAJI Hiroyuki <nakaji@tutrp.tut.ac.jp> says
+  ## powerpc*: NAKAJI Hiroyuki <nakaji@tutrp.tut.ac.jp> says
   ##   MkLinux/LinuxPPC needs this.
-  ## ibms390x only supports opsys = gnu-linux so it can be added here.
+  ## s390x-* only supports opsys = gnu-linux so it can be added here.
   gnu-*)
-    case "$machine" in
-      macppc|ibms390x) LD_FIRSTFLAG="-nostdlib" ;;
+    case "$canonical" in
+      powerpc*|s390x-*) LD_FIRSTFLAG="-nostdlib" ;;
     esac
     ;;
 esac
@@ -3554,7 +3472,7 @@ if test "x$ORDINARY_LINK" = "xyes"; then
   AC_DEFINE(ORDINARY_LINK, 1, [Define if the C compiler is the linker.])
 
 ## The system files defining neither ORDINARY_LINK nor LD_FIRSTFLAG are:
-## freebsd, gnu-* not on macppc|ibms390x.
+## freebsd, gnu-* not on powerpc*|s390x*.
 elif test "x$GCC" = "xyes" && test "x$LD_FIRSTFLAG" = "x"; then
 
   ## Versions of GCC >= 2.0 put their library, libgcc.a, in obscure
@@ -3662,10 +3580,9 @@ AH_BOTTOM([
 
 #define subprocesses
 
-/* Include the os and machine dependent files.  */
-#include config_opsysfile
-#ifdef config_machfile
-# include config_machfile
+/* Include the os dependent file.  */
+#ifdef config_opsysfile
+# include config_opsysfile
 #endif
 
 /* GNUstep needs a bit more pure memory.  Of the existing knobs,
@@ -3690,48 +3607,9 @@ AH_BOTTOM([
 #endif
 #endif
 
-/* These default definitions are good for almost all machines.
-   Any exceptions should override them in m/MACHINE.h.
-   They must be usable in preprocessor conditionals.  */
-
-#ifndef BITS_PER_CHAR
-#define BITS_PER_CHAR 8
-#endif
-
-#ifndef BITS_PER_SHORT
-#define BITS_PER_SHORT 16
-#endif
-
-#ifndef BITS_PER_INT
-#define BITS_PER_INT 32
-#endif
-
-#ifndef BITS_PER_LONG
-#ifdef _LP64
-#define BITS_PER_LONG 64
-#else
-#define BITS_PER_LONG 32
-#endif
-#endif
-
-#if !defined BITS_PER_LONG_LONG && HAVE_LONG_LONG_INT
-#define BITS_PER_LONG_LONG 64
-#endif
-
-/* Define if the compiler supports function prototypes.  It may do so but
-   not define __STDC__ (e.g. DEC C by default) or may define it as zero.  */
-#undef PROTOTYPES
-
 #include <string.h>
 #include <stdlib.h>
 
-#if defined __GNUC__ && (__GNUC__ > 2 \
-                         || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
-#define NO_RETURN      __attribute__ ((__noreturn__))
-#else
-#define NO_RETURN      /* nothing */
-#endif
-
 #if __GNUC__ >= 3  /* On GCC 3.0 we might get a warning.  */
 #define NO_INLINE __attribute__((noinline))
 #else
@@ -3789,17 +3667,11 @@ if test "${HAVE_GTK}" = "yes"; then
   USE_X_TOOLKIT=GTK
 fi
 
-and_machfile=
-if test -n "$machfile"; then
-  and_machfile=" and \`${machfile}'"
-fi
-
 echo "
 Configured for \`${canonical}'.
 
   Where should the build process find the source code?    ${srcdir}
-  What operating system and machine description files should Emacs use?
-        \`${opsysfile}'${and_machfile}
+  What operating system file should Emacs use?            ${opsysfile-none}
   What compiler should emacs be built with?               ${CC} ${CFLAGS}
   Should Emacs use the GNU version of malloc?             ${GNU_MALLOC}${GNU_MALLOC_reason}
   Should Emacs use a relocating allocator for buffers?    ${REL_ALLOC}
@@ -3850,11 +3722,6 @@ if test -n "${EMACSDOC}"; then
    echo "  Environment variable EMACSDOC set to:                   $EMACSDOC"
 fi
 
-if test $USE_XASSERTS = yes; then
-   echo "  Compiling with asserts turned on."
-   CPPFLAGS="$CPPFLAGS -DXASSERTS=1"
-fi
-
 echo
 
 if test "$HAVE_NS" = "yes"; then
@@ -3943,7 +3810,7 @@ dnl the use of force in the `epaths-force' rule in Makefile.in.
 AC_CONFIG_COMMANDS([epaths], [
 echo creating src/epaths.h
 ${MAKE-make} epaths-force
-], [GCC="$GCC" NON_GNU_CPP="$NON_GNU_CPP" CPP="$CPP" CPPFLAGS="$CPPFLAGS"])
+], [GCC="$GCC" CPPFLAGS="$CPPFLAGS"])
 
 AC_CONFIG_COMMANDS([gdbinit], [
 if test ! -f src/.gdbinit && test -f $srcdir/src/.gdbinit; then