autoconf: 1999-10-01 Akim Demaille <akim@epita.fr>

From e92b805c22b6d0a74e70568ca6e253952d668bf3 Mon Sep 17 00:00:00 2001
From: Akim Demaille <[EMAIL REDACTED]>
Date: Mon, 4 Oct 1999 08:19:04 +0000
Subject: [PATCH] 1999-10-01  Akim Demaille  <akim@epita.fr>

	Moving most of the task of creating config.h.in from sh to m4.
	Getting rid of acconfig.h by supply a major new family of macros:
	AH_* which make it possible to insert arbitrary text into
	config.h.in.

	* autoheader.m4: Major rewrite: introduction of a set of macros
 	AH_ that produce code into config.h.in.  There are two sets of
 	macros: generic macros, or specialized, documented below.  The
 	basic idea is that an AC_FOO macro which needs an entry in
 	config.h.in should have a sibling AH_FOO which expands into that
 	entry.  In a near future, these macros will be moved next to their
	siblings.

	* autoheader.m4 (AH_VERBATIM, AH_DEFINE, AH_DEFINE, AH_NEED_DECLS,
 	AH_CHECK_SIZEOF, AH_CHECK_FUNCS, AH_CHECK_HEADERS,
 	AH_CHECK_HEADERS, AH_CHECK_LIB, AH_PROG_LEX, AH_FUNC_ALLOCA,
 	AH_C_CHAR_UNSIGNED, AH_AIX, AH_F77_WRAPPERS): New macros.

	* autoheader.m4 (End section): Bind AC_ macros to their
	AH_siblings.

	* autoheader.sh: Remove the sections in charge of SYMS, TYPES,
	FUNCS, HEADERS, LIBS and DECLS: autoheader.m4 is now in charge of
	these.

	* autoheader.sh (options): Added -d, --debug, which does not
	remove the temporary files.

	* autoheader.sh: Instead of redirecting stdout to the output
	stream, always output to a temporary file.  This allows to change
	slightly the consistency check: before autoheader would check that
	each non documented AC_DEFINE is templated in an acconfig.  Now it
	just checks whether the template is in the output file.

	* acconfig.h: Completely emptied, the remaining templates
	(_ALL_SOURCE, __CHAR_UNSIGNED__, F77_FUNC, F77_FUNC_,
 	HAVE_STRINGIZE, and STACK_DIRECTION) are now either associated to
 	their AC_DEFINE, or to one of the new AH_ macros.

	* acgeneral.m4: Reordering of the m4 macros which are not specific
 	to Autoconf.

	* acgeneral.m4 (AC_HAVE_LIB): Promoted from obsolete to hasbeen.

	* acgeneral.m4 (AC_TR_CPP): Fixed quoting problem, and missing ^
	in patsubst.
	(AC_TR_SH): Fixed quoting problem.
---
 ChangeLog                |  50 +++++++++
 acconfig.h               |  60 -----------
 acgeneral.m4             | 137 ++++++++++++++++---------
 acspecific.m4            |  25 +++--
 autoheader.m4            | 214 +++++++++++++++++++++++++--------------
 autoheader.sh            | 113 +++++++--------------
 lib/autoconf/general.m4  | 137 ++++++++++++++++---------
 lib/autoconf/specific.m4 |  25 +++--
 8 files changed, 428 insertions(+), 333 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 901e5203..048a7f58 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,53 @@
+1999-10-01  Akim Demaille  <akim@epita.fr>
+
+	Moving most of the task of creating config.h.in from sh to m4.
+	Getting rid of acconfig.h by supply a major new family of macros:
+	AH_* which make it possible to insert arbitrary text into
+	config.h.in.
+
+	* autoheader.m4: Major rewrite: introduction of a set of macros
+ 	AH_ that produce code into config.h.in.  There are two sets of
+ 	macros: generic macros, or specialized, documented below.  The
+ 	basic idea is that an AC_FOO macro which needs an entry in
+ 	config.h.in should have a sibling AH_FOO which expands into that
+ 	entry.  In a near future, these macros will be moved next to their
+	siblings.
+
+	* autoheader.m4 (AH_VERBATIM, AH_DEFINE, AH_DEFINE, AH_NEED_DECLS,
+ 	AH_CHECK_SIZEOF, AH_CHECK_FUNCS, AH_CHECK_HEADERS,
+ 	AH_CHECK_HEADERS, AH_CHECK_LIB, AH_PROG_LEX, AH_FUNC_ALLOCA,
+ 	AH_C_CHAR_UNSIGNED, AH_AIX, AH_F77_WRAPPERS): New macros.
+
+	* autoheader.m4 (End section): Bind AC_ macros to their
+	AH_siblings.
+
+	* autoheader.sh: Remove the sections in charge of SYMS, TYPES,
+	FUNCS, HEADERS, LIBS and DECLS: autoheader.m4 is now in charge of
+	these.
+
+	* autoheader.sh (options): Added -d, --debug, which does not
+	remove the temporary files.
+
+	* autoheader.sh: Instead of redirecting stdout to the output
+	stream, always output to a temporary file.  This allows to change
+	slightly the consistency check: before autoheader would check that
+	each non documented AC_DEFINE is templated in an acconfig.  Now it
+	just checks whether the template is in the output file.
+
+	* acconfig.h: Completely emptied, the remaining templates
+	(_ALL_SOURCE, __CHAR_UNSIGNED__, F77_FUNC, F77_FUNC_,
+ 	HAVE_STRINGIZE, and STACK_DIRECTION) are now either associated to
+ 	their AC_DEFINE, or to one of the new AH_ macros.
+
+	* acgeneral.m4: Reordering of the m4 macros which are not specific
+ 	to Autoconf.
+
+	* acgeneral.m4 (AC_HAVE_LIB): Promoted from obsolete to hasbeen.
+
+	* acgeneral.m4 (AC_TR_CPP): Fixed quoting problem, and missing ^
+	in patsubst.
+	(AC_TR_SH): Fixed quoting problem.
+
 1999-09-29  Akim Demaille  <akim@epita.fr>
 
 	* acgeneral.m4 (AC_WRAP): Don't output an extra space after the
diff --git a/acconfig.h b/acconfig.h
index e8c1ea75..e69de29b 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -1,60 +0,0 @@
-/* acconfig.h
-   This file is in the public domain.
-
-   Descriptive text for the C preprocessor macros that
-   the distributed Autoconf macros can define.
-   No software package will use all of them; autoheader copies the ones
-   your configure.in uses into your configuration header file templates.
-
-   The entries are in sort -df order: alphabetical, case insensitive,
-   ignoring punctuation (such as underscores).  Although this order
-   can split up related entries, it makes it easier to check whether
-   a given entry is in the file.
-
-   Leave the following blank line there!!  Autoheader needs it.  */
-
-
-/* Define if on AIX 3.
-   System headers sometimes define this.
-   We just want to avoid a redefinition error message.  */
-#ifndef _ALL_SOURCE
-#undef _ALL_SOURCE
-#endif
-
-/* Define if type char is unsigned and you are not using gcc.  */
-#ifndef __CHAR_UNSIGNED__
-#undef __CHAR_UNSIGNED__
-#endif
-
-/*
- * Define to a macro that performs the appropriate name mangling on its
- * argument to make the C identifier, which *does not* contain
- * underscores, match the name mangling scheme of the Fortran 77
- * compiler.
- */
-#undef F77_FUNC
-
-/*
- * Define to a macro that performs the appropriate name mangling on its
- * argument to make the C identifier, which *does* contain underscores,
- * match the name mangling scheme of the Fortran 77 compiler.
- */
-#undef F77_FUNC_
-
-/* Define if you have the ANSI # stringizing operator in cpp. */
-#undef HAVE_STRINGIZE
-
-/* If using the C implementation of alloca, define if you know the
-   direction of stack growth for your system; otherwise it will be
-   automatically deduced at run-time.
-	STACK_DIRECTION > 0 => grows toward higher addresses
-	STACK_DIRECTION < 0 => grows toward lower addresses
-	STACK_DIRECTION = 0 => direction of growth unknown
- */
-#undef STACK_DIRECTION
-
-
-/* Leave that blank line there!!  Autoheader needs it.
-   If you're adding to this file, keep in mind:
-   The entries are in sort -df order: alphabetical, case insensitive,
-   ignoring punctuation (such as underscores).  */
diff --git a/acgeneral.m4 b/acgeneral.m4
index 279d851a..2140e9e0 100644
--- a/acgeneral.m4
+++ b/acgeneral.m4
@@ -73,16 +73,21 @@ m4_prefix([include])
 m4_prefix([shift])
 m4_prefix([format])
 
-dnl ifset(COND, IF-TRUE[, IF-FALSE])
-dnl --------------------------------
-dnl If COND is not the empty string, expand IF-TRUE, otherwise IF-FALSE.
-dnl Comparable to ifdef.
-define([ifset], [ifelse([$1],,[$3],[$2])])
 
-dnl m4_default(EXP1, EXP2)
-dnl ----------------------
-dnl Returns EXP1 if non empty, otherwise EXP2.
-define([m4_default], [ifset([$1], [$1], [$2])])
+dnl ------------------------------------------------------------
+dnl Text processing in m4.
+dnl ------------------------------------------------------------
+
+dnl m4_quote(STRING)
+dnl ----------------
+dnl Return STRING quoted.
+dnl
+dnl It is important to realize the difference between `quote(exp)' and
+dnl `[exp]': in the first case you obtain the quoted *result* of the
+dnl expansion of EXP, while in the latter you just obtain the string
+dnl `exp'.
+define([m4_quote], [[$@]])
+
 
 dnl m4_split(STRING)
 dnl ----------------
@@ -156,9 +161,26 @@ define([m4_strip],
           [ \(.\)$], [\1])])
 
 
-dnl ### Implementing m4 loops
+dnl ------------------------------------------------------------
+dnl Some additional m4 structural control.
+dnl ------------------------------------------------------------
+
+
+dnl ifset(COND, IF-TRUE[, IF-FALSE])
+dnl --------------------------------
+dnl If COND is not the empty string, expand IF-TRUE, otherwise IF-FALSE.
+dnl Comparable to ifdef.
+define([ifset], [ifelse([$1],,[$3],[$2])])
+
+
+dnl m4_default(EXP1, EXP2)
+dnl ----------------------
+dnl Returns EXP1 if non empty, otherwise EXP2.
+define([m4_default], [ifset([$1], [$1], [$2])])
 
 
+dnl ### Implementing m4 loops
+
 dnl Implementing loops (`foreach' loops) in m4 is much more tricky than it
 dnl may seem.  Actually, the example of a `foreach' loop in the m4
 dnl documentation is wrong: it does not quote the arguments properly,
@@ -207,6 +229,7 @@ dnl  => echo c)
 dnl
 dnl Bingo!
 
+
 dnl M4_FOREACH(VARIABLE, LIST, EXPRESSION)
 dnl --------------------------------------
 dnl Expand EXPRESSION assigning to VARIABLE each value of the LIST
@@ -226,8 +249,45 @@ define(_m4_car, [[$1]])
 define(_m4_foreach,
 [ifelse($2, [()], ,
         [define([$1], [_m4_car$2])$3[]_m4_foreach([$1],
-                                                [(m4_shift$2)],
-                                                [$3])])])
+                                                  [(m4_shift$2)],
+                                                  [$3])])])
+
+
+dnl m4_list_append(LIST, ELEMENT)
+dnl -----------------------------
+dnl Insert ELEMENT at the end of LIST.
+dnl
+dnl This macro is picky on its input, especially for the empty list: it
+dnl must be either the empty string, or exactly `()' (no spaces allowed).
+dnl This macro is actually purely textual: it basically replaces the
+dnl closing paren of LIST with `, ELEMENT)'.  The hair is to preserve
+dnl quotation: this macro is robust to active symbols.
+dnl
+dnl   | define(active, ACTIVE)
+dnl   | m4_list_append(m4_list_append(m4_list_append((), [1 active]),
+dnl   |                               [2 active]),
+dnl   |                [3 active])end
+dnl   =>(1 active, 2 active, 3 active)end
+dnl
+dnl The combination of this macro and m4_quote is extremely useful to
+dnl build and store lists:
+dnl
+dnl   | define(active, ACTIVE)
+dnl   | define(list, ())
+dnl   | define([list], m4_quote(m4_list_append(list, [1 active])))
+dnl   | define([list], m4_quote(m4_list_append(list, [2 active])))
+dnl   | define([list], m4_quote(m4_list_append(list, [3 active])))
+dnl   | list
+dnl   =>(1 active, 2 active, 3 active)
+dnl
+define([m4_list_append],
+[ifelse([$1], [],   [([$2])],
+        [$1], [()], [([$2])],
+        [patsubst([[$1]], [^..\(.*\)..$], [[(\1, $2)]])])])
+
+
+define([m4_list_add],
+[define([$1], m4_quote(m4_list_append($1, [$2])))])
 
 
 dnl ### Defining macros
@@ -491,10 +551,10 @@ dnl of `$ac_tr_cpp' if you change this.
 define(AC_TR_CPP,
 [AC_VAR_IF_INDIR([$1],
   [`echo "$1" | $ac_tr_cpp`],
-  [patsubst(translit([$1],
+  [patsubst(translit([[$1]],
                      [*abcdefghijklmnopqrstuvwxyz],
                      [PABCDEFGHIJKLMNOPQRSTUVWXYZ]),
-            [A-Z0-9_], [_])])])
+            [[^A-Z0-9_]], [_])])])
 
 
 dnl AC_TR_SH(EXPRESSION)
@@ -507,7 +567,7 @@ dnl Make sure to update the definition of `$ac_tr_cpp' if you change this.
 define(AC_TR_SH,
 [AC_VAR_IF_INDIR([$1],
   [`echo "$1" | $ac_tr_sh`],
-  [patsubst(translit([$1], [*+], [pp]),
+  [patsubst(translit([[$1]], [*+], [pp]),
             [[^a-zA-Z0-9_]], [_])])])
 
 
@@ -1740,6 +1800,8 @@ define(AC_DEFINE,
 EOF
 ])
 
+
+
 dnl AC_DEFINE_UNQUOTED(VARIABLE [, VALUE[, DESCRIPTION]])
 dnl -----------------------------------------------------
 dnl Similar, but perform shell substitutions $ ` \ once on VALUE.
@@ -1750,6 +1812,7 @@ EOF
 ])
 
 
+
 dnl ### Setting output variables
 
 
@@ -2236,6 +2299,10 @@ dnl Use a cache variable name containing both the library and function name,
 dnl because the test really is for library $1 defining function $2, not
 dnl just for library $1.  Separate tests with the same $1 and different $2s
 dnl may have different results.
+dnl
+dnl FIXME: This macro is extremely suspicious.  It DEFINE unconditionnally,
+dnl whatever the FUNCTION, in addition to not being a *S macro.  Note
+dnl that the cache does depend upon the function with look for.
 AC_DEFUN(AC_CHECK_LIB,
 [AC_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$2])dnl
 AC_CACHE_CHECK([for $2 in -l$1], ac_Lib,
@@ -2265,36 +2332,12 @@ AC_SHELL_IFELSE(test AC_VAR_GET(ac_Lib) = yes,
 AC_VAR_POPDEF([ac_Lib])dnl
 ])dnl AC_CHECK_LIB
 
+
+
 dnl AC_HAVE_LIBRARY(LIBRARY, [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND
 dnl                 [, OTHER-LIBRARIES]]])
-dnl FIXME: Remove
 AC_DEFUN(AC_HAVE_LIBRARY,
-[AC_OBSOLETE([$0], [; instead use AC_CHECK_LIB])dnl
-changequote(<<, >>)dnl
-define(<<AC_LIB_NAME>>, dnl
-patsubst(patsubst($1, <<lib\([^\.]*\)\.a>>, <<\1>>), <<-l>>, <<>>))dnl
-define(<<AC_CV_NAME>>, ac_cv_lib_<<>>AC_LIB_NAME)dnl
-changequote([, ])dnl
-AC_MSG_CHECKING([for -l[]AC_LIB_NAME])
-AC_CACHE_VAL(AC_CV_NAME,
-[ac_save_LIBS="$LIBS"
-LIBS="-l[]AC_LIB_NAME[] $4 $LIBS"
-AC_TRY_LINK( , [main()], AC_CV_NAME=yes, AC_CV_NAME=no)
-LIBS="$ac_save_LIBS"
-])dnl
-AC_MSG_RESULT($AC_CV_NAME)
-if test "$AC_CV_NAME" = yes; then
-  ifelse([$2], ,
-[AC_DEFINE([HAVE_LIB]AC_TR_CPP(AC_LIB_NAME))
-  LIBS="-l[]AC_LIB_NAME[] $LIBS"
-], [$2])
-ifelse([$3], , , [else
-  $3
-])dnl
-fi
-undefine([AC_LIB_NAME])dnl
-undefine([AC_CV_NAME])dnl
-])
+[AC_HASBEEN([$0], [; instead use AC_CHECK_LIB])])
 
 
 dnl ### Examining declarations
@@ -2612,14 +2655,7 @@ $2],
                  [$4])])
 ])dnl AC_NEED_DECLS
 
-dnl This is the pure sh version of the macro above.
-dnl [for ac_sym in [$1]
-dnl do
-dnl AC_NEED_DECL($ac_sym,
-dnl 		 [$2],
-dnl 		 [AC_DEFINE_UNQUOTED(AC_TR_CPP(${ac_sym}_DECLARED)) $3],
-dnl 		 [$4])dnl
-dnl done
+
 
 dnl ### Checking for library functions
 
@@ -2670,6 +2706,7 @@ AC_CHECK_FUNC($ac_func,
 done
 ])
 
+
 dnl AC_REPLACE_FUNCS(FUNCTION...)
 AC_DEFUN(AC_REPLACE_FUNCS,
 [AC_CHECK_FUNCS([$1], , [LIBOBJS="$LIBOBJS ${ac_func}.${ac_objext}"])
diff --git a/acspecific.m4 b/acspecific.m4
index 4a25caf5..33f4adc0 100644
--- a/acspecific.m4
+++ b/acspecific.m4
@@ -651,7 +651,7 @@ if test $ac_cv_prog_lex_yytext_pointer = yes; then
             [Define if `lex' declares `yytext' as a `char *' by default,
              not a `char[]'.])
 fi
-])
+])dnl AC_DECL_YYTEXT
 
 AC_DEFUN(AC_PROG_INSTALL,
 [AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
@@ -1582,7 +1582,7 @@ main ()
 AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction)
 fi
 AC_SUBST(ALLOCA)dnl
-])
+])dnl AC_FUNC_ALLOCA
 
 AC_DEFUN(AC_FUNC_GETLOADAVG,
 [ac_have_func=no # yes means we've found a way to get the load average.
@@ -2112,7 +2112,7 @@ fi])
 if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
   AC_DEFINE(__CHAR_UNSIGNED__)
 fi
-])
+])dnl AC_C_CHAR_UNSIGNED
 
 AC_DEFUN(AC_C_LONG_DOUBLE,
 [AC_CACHE_CHECK(for long double, ac_cv_c_long_double,
@@ -2271,8 +2271,12 @@ if test $ac_cv_c_volatile = no; then
 fi
 ])
 
-AC_DEFUN(AC_C_STRINGIZE, [
-AC_REQUIRE([AC_PROG_CPP])
+dnl AC_C_STRINGIZE
+dnl --------------
+dnl Checks if `#' can be used to glue strings together at the CPP level.
+dnl Defines HAVE_STRINGIZE if positive.
+AC_DEFUN(AC_C_STRINGIZE,
+[AC_REQUIRE([AC_PROG_CPP])
 AC_MSG_CHECKING([for preprocessor stringizing operator])
 AC_CACHE_VAL(ac_cv_c_stringize,
 AC_EGREP_CPP([#teststring],[
@@ -2281,7 +2285,8 @@ AC_EGREP_CPP([#teststring],[
 char *s = x(teststring);
 ], ac_cv_c_stringize=no, ac_cv_c_stringize=yes))
 if test "${ac_cv_c_stringize}" = yes; then
-  AC_DEFINE(HAVE_STRINGIZE)
+  AC_DEFINE(HAVE_STRINGIZE, 1,
+            [Define if you have the ANSI # stringizing operator in cpp.])
 fi
 AC_MSG_RESULT([${ac_cv_c_stringize}])
 ])dnl
@@ -3157,7 +3162,7 @@ AC_EGREP_CPP(yes,
 [AC_MSG_RESULT(yes)
 AC_DEFINE(_ALL_SOURCE)],
 AC_MSG_RESULT(no))
-])
+])dnl AC_AIX
 
 AC_DEFUN(AC_MINIX,
 [AC_BEFORE([$0], [AC_TRY_COMPILE])dnl
@@ -3173,7 +3178,7 @@ if test "$MINIX" = yes; then
   AC_DEFINE(_MINIX, 1,
             [Define if on MINIX.])
 fi
-])
+])dnl AC_MINIX
 
 AC_DEFUN(AC_ISC_POSIX,
 [AC_REQUIRE([AC_PROG_CC])dnl
@@ -3197,7 +3202,7 @@ else
   AC_MSG_RESULT(no)
   ISC=
 fi
-])
+])dnl AC_ISC_POSIX
 
 AC_DEFUN(AC_XENIX_DIR,
 [AC_OBSOLETE([$0], [; instead use AC_HEADER_DIRENT])dnl
@@ -3213,7 +3218,7 @@ if test "$XENIX" = yes; then
   test $ac_header_dirent = dirent.h && LIBS="-ldir $LIBS"
   LIBS="$LIBS -lx"
 fi
-])
+])dnl AC_XENIX_DIR
 
 AC_DEFUN(AC_DYNIX_SEQ,
 [AC_OBSOLETE([$0], [; instead use AC_FUNC_GETMNTENT])dnl
diff --git a/autoheader.m4 b/autoheader.m4
index 5662a7b6..0b4a99aa 100644
--- a/autoheader.m4
+++ b/autoheader.m4
@@ -23,6 +23,12 @@ include(acgeneral.m4)dnl
 m4_include(acspecific.m4)dnl
 m4_include(acoldnames.m4)dnl
 
+dnl Autoheader is not the right program to complain about cross-compiling.
+define([AC_TRY_RUN], [
+$2
+$3
+$4])
+
 dnl These are alternate definitions of some macros, which produce
 dnl strings in the output marked with "@@@" so we can easily extract
 dnl the information we want.  The `#' at the end of the first line of
@@ -30,94 +36,152 @@ dnl each definition seems to be necessary to prevent m4 from eating
 dnl the newline, which makes the @@@ not always be at the beginning of
 dnl a line.
 
-define([AC_CHECK_FUNCS], [#
-@@@funcs="$funcs $1"@@@
-ifelse([$2], , , [
-# If it was found, we do:
-$2
-# If it was not found, we do:
-$3
-])
-])
+dnl AH_DEFINE(VARIABLE [, VALUE[, DESCRIPTION]])
+dnl --------------------------------------------
+dnl When running autoheader, this macro replaces AC_DEFINE and
+dnl AC_DEFINE_UNQUOTED.
+dnl
+dnl We remember the symbols we already defined to avoid to define
+dnl them twice.  In the future we may want to use another program
+dnl than sh to issue the templates.  For instance with AWK, we
+dnl may fill an associative array (key is $1, value is the template).
+dnl This garantees that there is a unique prototype issued, and also
+dnl that it will be sorted!
+define([AH_DEFINE],
+[ifset([$3],
+       [AH_TEMPLATE([$1], [$3])],
+       [#
+dnl Ignore CPP macro arguments.
+@@@syms="$syms patsubst($1, [(.*$])"@@@
+])])
 
-define([AC_CHECK_HEADERS], [#
-@@@headers="$headers $1"@@@
-ifelse([$2], , , [
-# If it was found, we do:
-$2
-# If it was not found, we do:
-$3
-])
-])
+dnl AC_VERBATIM
+define([AC_VERBATIM], [])
 
-define([AC_CHECK_HEADER], [AC_CHECK_HEADERS($1,$2,$3)])
+dnl AH_TEMPLATE(KEY, DESCRIPTION)
+dnl Issue an autoheader template for KEY, i.e., a comment composed
+dnl of DESCRIPTION (properly wrapped), and then #undef KEY.
+define([AH_TEMPLATE],
+[AH_VERBATIM([$1],
+             AC_WRAP(_AC_SH_QUOTE([[$2 */]]), [   ], [/* ])[
+#undef $1])])
 
-define([AC_CHECK_HEADERS_DIRENT], [#
-@@@headers="$headers $1"@@@
-])
+dnl AH_VERBATIM(KEY, TEMPLATE)
+dnl --------------------------
+dnl If KEY is direct (i.e., no indirection such as in KEY=$my_func which may
+dnl occur if there is AC_CHECK_FUNCS($my_func)), issue an autoheader TEMPLATE
+dnl associated to the KEY.  Otherwise, do nothing.
+dnl TEMPLATE is output as is, with no formating.
+define([AH_VERBATIM],
+[AC_VAR_IF_INDIR([$1],,
+[#
+@@@
+ac_verbatim_$1="\
+[$2]"
+@@@
+])])
 
-define([AC_CHECK_LIB], [#
-  ifelse([$3], , [
-@@@libs="$libs $1"@@@
-], [
-# If it was found, we do:
+define([AH_CHECK_LIB],
+[AH_TEMPLATE(AC_TR_CPP(HAVE_$1),
+             [Define if you have the `]$1[' library (-l]$1[).])
+# Success
 $3
-# If it was not found, we do:
-$4
-])
-])
+# Failure
+$4])
 
-define([AC_NEED_DECLS], [#
-  ifelse([$2], , [
-@@@decls="$decls $1"@@@
-], [
-# If it was found, we do:
+define([AH_CHECK_HEADERS],
+[AC_FOREACH([AC_Header], [$1],
+  [AH_TEMPLATE(AC_TR_CPP(HAVE_[]AC_Header),
+               [Define if you have the <]AC_Header[> header file.])
+# Success
 $2
-# If it was not found, we do:
-$3
-])
-])
+# Failure
+$3])])
 
-define([AC_HAVE_LIBRARY], [#
-changequote(<<, >>)dnl
-define(<<AC_LIB_NAME>>, dnl
-patsubst(patsubst($1, <<lib\([^\.]*\)\.a>>, <<\1>>), <<-l>>, <<>>))dnl
-changequote([, ])dnl
-  ifelse([$2], , [
-@@@libs="$libs AC_LIB_NAME"@@@
-], [
-# If it was found, we do:
+define([AH_NEED_DECLS],
+[AC_FOREACH([AC_Symbol], [$1],
+  [AH_TEMPLATE(AC_TR_CPP(NEED_DECL_[]AC_Symbol),
+               [Define if you need the declaration of `]AC_Symbol['.])
+# Success
 $2
-# If it was not found, we do:
-$3
-])
-])
+# Failure
+$3])])
+
+define([AH_CHECK_FUNCS],
+[AC_FOREACH([AC_Func], [$1],
+  [AH_TEMPLATE(AC_TR_CPP(HAVE_[]AC_Func),
+               [Define if you have the `]AC_Func[' function.])
+# Success
+$2
+# Failure
+$3])])
+
+
+define([AH_CHECK_SIZEOF],
+[AH_TEMPLATE(AC_TR_CPP(SIZEOF_$1),
+             [The number of bytes in a `]$1['.])])
+
+define([AH_PROG_LEX],
+[AH_CHECK_LIB(fl)
+AH_CHECK_LIB(l)])
+
+define([AC_FUNC_ALLOCA],
+[AH_VERBATIM([STACK_DIRECTION],
+[/* If using the C implementation of alloca, define if you know the
+   direction of stack growth for your system; otherwise it will be
+   automatically deduced at run-time.
+	STACK_DIRECTION > 0 => grows toward higher addresses
+	STACK_DIRECTION < 0 => grows toward lower addresses
+	STACK_DIRECTION = 0 => direction of growth unknown */
+#undef STACK_DIRECTION
+])])
+
+define([AC_C_CHAR_UNSIGNED],
+[AH_VERBATIM([__CHAR_UNSIGNED__],
+[/* Define if type `char' is unsigned and you are not using gcc.  */
+#ifndef __CHAR_UNSIGNED__
+# undef __CHAR_UNSIGNED__
+#endif])])
+
+define([AH_AIX],
+[AH_VERBATIM([_ALL_SOURCE],
+[/* Define if on AIX 3.
+   System headers sometimes define this.
+   We just want to avoid a redefinition error message.  */
+#ifndef _ALL_SOURCE
+# undef _ALL_SOURCE
+#endif])])
+
+
+define([AH_F77_WRAPPERS],
+[AH_TEMPLATE([F77_FUNC],
+             [Define to a macro that performs the appropriate name
+              mangling on its argument to make the C identifier, which
+              *does not* contain underscores, match the name mangling
+              scheme of the Fortran 77 compiler.])
+AH_TEMPLATE([F77_FUNC],
+             [Define to a macro that performs the appropriate name
+              mangling on its argument to make the C identifier, which
+              *does* contain underscores, match the name mangling
+              scheme of the Fortran 77 compiler.])])
 
-define([AC_CHECK_SIZEOF], [#
-@@@types="$types,$1"@@@
-])
 
 define([AC_CONFIG_HEADER], [#
 define([AC_CONFIG_H], patsubst($1, [ .*$], []))dnl
 @@@config_h=AC_CONFIG_H@@@
 ])
 
-define([AC_DEFINE], [#
-ifelse([$3],,[#
-dnl Ignore CPP macro arguments.
-@@@syms="$syms patsubst($1, [(.*$])"@@@
-], [#
-@@@verbatim="$verbatim
-dnl Quoted twice because there are two applications.
-AC_WRAP(_AC_SH_QUOTE([[$3 */]]), [   ], [/* ])
-#undef $1
-"@@@
-])])
-
-define([AC_DEFINE_UNQUOTED], [AC_DEFINE($@)])
-
-dnl Autoheader is not the right program to complain about cross-compiling
-define([AC_TRY_RUN], [
-$2
-$3
-$4])
+define([AC_VERBATIM], [AH_VERBATIM($@)])
+define([AC_DEFINE], [AH_DEFINE($@)])
+define([AC_DEFINE_UNQUOTED], [AH_DEFINE($@)])
+define([AC_NEED_DECLS], [AH_NEED_DECLS($@)])
+define([AC_CHECK_SIZEOF], [AH_CHECK_SIZEOF($@)])
+define([AC_CHECK_FUNCS], [AH_CHECK_FUNCS($@)])
+define([AC_CHECK_HEADERS], [AH_CHECK_HEADERS($@)])
+define([AC_CHECK_HEADERS_DIRENT], [AH_CHECK_HEADERS($@)])
+define([AC_CHECK_LIB], [AH_CHECK_LIB($@)])
+define([AC_PROG_LEX], [AH_PROG_LEX($@)])
+define([AC_FUNC_ALLOCA], [AH_FUNC_ALLOCA($@)])
+define([AC_C_CHAR_UNSIGNED], [AH_C_CHAR_UNSIGNED($@)])
+define([AC_AIX], [AH_AIX($@)])
+define([AC_F77_WRAPPERS], [AH_F77_WRAPPERS($@)])
diff --git a/autoheader.sh b/autoheader.sh
index 9534d227..01256f47 100644
--- a/autoheader.sh
+++ b/autoheader.sh
@@ -69,6 +69,8 @@ ac_LF_and_DOT="`echo; echo .`"
 localdir=.
 show_version=no
 debug=false
+# Basename for temporary files.
+ah_base=autoh$$
 
 while test $# -gt 0 ; do
    case "${1}" in
@@ -112,8 +114,8 @@ if test $show_version = yes; then
   exit 0
 fi
 
-TEMPLATES="${AC_MACRODIR}/acconfig.h"
-test -r $localdir/acconfig.h && TEMPLATES="${TEMPLATES} $localdir/acconfig.h"
+acconfigs="${AC_MACRODIR}/acconfig.h"
+test -r $localdir/acconfig.h && acconfigs="${acconfigs} $localdir/acconfig.h"
 
 case $# in
   0) infile=configure.in ;;
@@ -144,9 +146,9 @@ case `$M4 --help < /dev/null 2>&1` in
 *) echo Autoconf requires GNU m4 1.1 or later >&2; exit 1 ;;
 esac
 
-# Extract assignments of SYMS, TYPES, FUNCS, HEADERS, LIBS and DECLS
-# from the modified autoconf processing of the input file.  The sed
-# hair is necessary to win for multi-line macro invocations.
+# Extract assignments of `ah_verbatim_SYMBOL' and `syms' from the
+# modified autoconf processing of the input file.  The sed hair is
+# necessary to win for multi-line macro invocations.
 $M4 -I$AC_MACRODIR $use_localdir $r autoheader.m4$f $infile |
  sed -n -e '
 	: again
@@ -156,9 +158,9 @@ $M4 -I$AC_MACRODIR $use_localdir $r autoheader.m4$f $infile |
 		n
 		s/^/@@@/
 		b again
-	}' >autoheader.decls
-. ./autoheader.decls
-$debug || rm ./autoheader.decls
+	}' >$ah_base.decls
+. ./$ah_base.decls
+$debug || rm ./$ah_base.decls
 
 # Make SYMS newline-separated rather than blank-separated, and remove dups.
 # Start each symbol with a blank (to match the blank after "#undef")
@@ -174,22 +176,19 @@ undefined) echo "error: AC_CONFIG_HEADER not found in $infile" >&2; exit 1 ;;
 *) config_h_in="${config_h}.in" ;;
 esac
 
-if test $# -eq 0; then
-  tmpout=autoh$$
-  trap "rm -f $tmpout; exit 1" 1 2 15
-  exec > $tmpout
-fi
+tmpout=$ah_base.out
+$debug || trap "rm -f $ah_base*; exit 1" 1 2 15
 
 # Don't write "do not edit" -- it will get copied into the
 # config.h, which it's ok to edit.
-cat <<EOF
-/* ${config_h_in}.  Generated automatically from $infile by autoheader.  */
+cat <<EOF >$tmpout
+/* ${config_h_in}.  Generated automatically from $infile by aheader.  */
 EOF
 
-test -r ${config_h}.top && cat ${config_h}.top
+test -r ${config_h}.top && cat ${config_h}.top  >>$tmpout
 test -r $localdir/acconfig.h &&
   grep @TOP@ $localdir/acconfig.h >/dev/null &&
-  sed '/@TOP@/,$d' $localdir/acconfig.h
+  sed '/@TOP@/,$d' $localdir/acconfig.h >>$tmpout
 
 # This puts each template paragraph on its own line, separated by @s.
 if test -n "$syms"; then
@@ -198,7 +197,7 @@ if test -n "$syms"; then
   # be removed.
   # Undocumented useless feature: stuff outside of @TOP@ and @BOTTOM@
   # is ignored in the systemwide acconfig.h too.
-  for t in $TEMPLATES; do
+  for t in $acconfigs; do
     sedscript=""
     grep @TOP@ $t >/dev/null && sedscript="1,/@TOP@/d;"
     grep @BOTTOM@ $t >/dev/null && sedscript="$sedscript /@BOTTOM@/,\$d;"
@@ -222,97 +221,55 @@ if test -n "$syms"; then
   # Some fgrep's have limits on the number of lines that can be in the
   # pattern on the command line, so use a temporary file containing the
   # pattern.
-  (fgrep_tmp=${TMPDIR-/tmp}/autoh$$
+  (fgrep_tmp=$ah_base.fgrep
    trap "rm -f $fgrep_tmp; exit 1" 1 2 15
    cat > $fgrep_tmp <<EOF
 $syms
 EOF
    fgrep -f $fgrep_tmp
    rm -f $fgrep_tmp) |
-  tr @. "$ac_LF_and_DOT"
+  tr @. "$ac_LF_and_DOT" >>$tmpout
 fi
 
-echo "$types" | tr ,. "$ac_LF_and_DOT" | sort | uniq | while read ctype; do
-  test -z "$ctype" && continue
-  sym="`echo "${ctype}" | tr 'abcdefghijklmnopqrstuvwxyz *' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_P'`"
-  echo "
-/* The number of bytes in a \`${ctype}'.  */
-#undef SIZEOF_${sym}"
+for verb in `(set) 2>&1 | sed -n -e '/^ac_verbatim/s/^\([^=]*\)=.*$/\1/p'`; do
+  echo >>$tmpout
+  eval echo >>$tmpout '"${'$verb'}"'
 done
 
-# /bin/sh on the Alpha gives `for' a random value if $funcs is empty.
-if test -n "$funcs"; then
-  for func in `for x in $funcs; do echo $x; done | sort | uniq`; do
-    sym="`echo ${func} | sed 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
-    echo "
-/* Define if you have the \`${func}' function.  */
-#undef HAVE_${sym}"
-  done
-fi
-
-if test -n "$headers"; then
-  for header in `for x in $headers; do echo $x; done | sort | uniq`; do
-
-    sym="`echo ${header} | sed 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
-    echo "
-/* Define if you have the <${header}> header file.  */
-#undef HAVE_${sym}"
-  done
-fi
-
-if test -n "$libs"; then
-  for lib in `for x in $libs; do echo $x; done | sort | uniq`; do
-   sym="`echo ${lib} | sed 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
-    echo "
-/* Define if you have the \`${lib}' library (-l${lib}).  */
-#undef HAVE_LIB${sym}"
-  done
-fi
-
-if test -n "$decls"; then
-  for decl in `for x in $decls; do echo $x; done | sort | uniq`; do
-   sym="`echo ${decl} | sed 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
-    echo "
-/* Define if you need the declaration of \`${decl}'.  */
-#undef NEED_DECL_${sym}"
-  done
-fi
-
-if test -n "$verbatim"; then
-  echo "$verbatim"
-fi
-
 # Handle the case where @BOTTOM@ is the first line of acconfig.h.
 test -r $localdir/acconfig.h &&
   grep @BOTTOM@ $localdir/acconfig.h >/dev/null &&
-  sed -n '/@BOTTOM@/,${/@BOTTOM@/!p;}' $localdir/acconfig.h
-test -f ${config_h}.bot && cat ${config_h}.bot
+  sed -n '/@BOTTOM@/,${/@BOTTOM@/!p;}' $localdir/acconfig.h >>$tmpout
+test -f ${config_h}.bot && cat ${config_h}.bot >>$tmpout
 
+# Check that all the symbols have a template
 status=0
 
 if test -n "$syms"; then
   for sym in $syms; do
-    if grep "^#[a-z]*[ 	][ 	]*$sym[ 	]*$" $TEMPLATES >/dev/null; then
+    if grep "^#[a-z]*[ 	][ 	]*$sym[ 	]*$" $tmpout >/dev/null; then
       : # All is well.
     else
-      echo "$0: Symbol \`${sym}' is not covered by $TEMPLATES" >&2
+      echo "$0: No template for symbol \`${sym}'" >&2
       status=1
     fi
   done
 fi
 
-if test $# -eq 0; then
-  # Force $tmpout to close to avoid Windows file sharing conflicts.
-  exec 1>&2
-  if test $status -eq 0; then
+# If the run was successful, output the result.
+if test $status -eq 0; then
+  if test $# -eq 0; then
+    # Output is a file
     if test -f ${config_h_in} && cmp -s $tmpout ${config_h_in}; then
-      rm -f $tmpout # File didn't change, so don't update its mod time.
+      : # File didn't change, so don't update its mod time.
     else
       mv -f $tmpout ${config_h_in}
     fi
   else
-    rm -f $tmpout
+    # Output is stdout
+    cat $tmpout
   fi
 fi
 
+rm -f $tmpout
 exit $status
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index 279d851a..2140e9e0 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -73,16 +73,21 @@ m4_prefix([include])
 m4_prefix([shift])
 m4_prefix([format])
 
-dnl ifset(COND, IF-TRUE[, IF-FALSE])
-dnl --------------------------------
-dnl If COND is not the empty string, expand IF-TRUE, otherwise IF-FALSE.
-dnl Comparable to ifdef.
-define([ifset], [ifelse([$1],,[$3],[$2])])
 
-dnl m4_default(EXP1, EXP2)
-dnl ----------------------
-dnl Returns EXP1 if non empty, otherwise EXP2.
-define([m4_default], [ifset([$1], [$1], [$2])])
+dnl ------------------------------------------------------------
+dnl Text processing in m4.
+dnl ------------------------------------------------------------
+
+dnl m4_quote(STRING)
+dnl ----------------
+dnl Return STRING quoted.
+dnl
+dnl It is important to realize the difference between `quote(exp)' and
+dnl `[exp]': in the first case you obtain the quoted *result* of the
+dnl expansion of EXP, while in the latter you just

(Patch may be truncated, please check the link at the top of this post.)