2005-05-18 Stepan Kasal * lib/autoconf/general.m4 (_AC_INIT_DEFAULTS): Nuke ac_max_here_lines. * lib/autoconf/status.m4 (_AC_OUTPUT_HEADERS): Simplify the sed scripts created. Index: lib/autoconf/general.m4 =================================================================== RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/general.m4,v retrieving revision 1.856 diff -u -r1.856 general.m4 --- lib/autoconf/general.m4 17 May 2005 09:29:05 -0000 1.856 +++ lib/autoconf/general.m4 18 May 2005 09:27:29 -0000 @@ -401,11 +401,6 @@ AC_SUBST([SHELL], [${CONFIG_SHELL-/bin/sh}])dnl AC_SUBST([PATH_SEPARATOR])dnl -# Maximum number of lines to put in a shell here document. -# This variable seems obsolete. It should probably be removed, and -# only ac_max_sed_lines should be used. -: ${ac_max_here_lines=38} - # Identity of this package. AC_SUBST([PACKAGE_NAME], [m4_ifdef([AC_PACKAGE_NAME], ['AC_PACKAGE_NAME'])])dnl Index: lib/autoconf/status.m4 =================================================================== RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/status.m4,v retrieving revision 1.56 diff -u -r1.56 status.m4 --- lib/autoconf/status.m4 17 May 2005 09:29:05 -0000 1.56 +++ lib/autoconf/status.m4 18 May 2005 09:27:29 -0000 @@ -482,40 +482,6 @@ # itself into $CONFIG_STATUS (eg, via here documents). Upon exit, no # here document shall be opened. # -# -# The code produced used to be extremely costly: there are was a -# single sed script (n lines) handling both `#define' templates, -# `#undef' templates with trailing space, and `#undef' templates -# without trailing spaces. The full script was run on each of the m -# lines of `config.h.in', i.e., about n x m. -# -# Now there are two scripts: `conftest.defines' for the `#define' -# templates, and `conftest.undef' for the `#undef' templates. -# -# Optimization 1. It is incredibly costly to run two `#undef' -# scripts, so just remove trailing spaces first. Removes about a -# third of the cost. -# -# Optimization 2. Since `#define' are rare and obsoleted, -# `conftest.defines' is built and run only if grep says there are -# `#define'. Improves by at least a factor 2, since in addition we -# avoid the cost of *producing* the sed script. -# -# Optimization 3. In each script, first check that the current input -# line is a template. This avoids running the full sed script on -# empty lines and comments (divides the cost by about 3 since each -# template chunk is typically a comment, a template, an empty line). -# -# Optimization 4. Once a substitution performed, since there can be -# only one per line, immediately restart the script on the next input -# line (using the `t' sed instruction). Divides by about 2. -# *Note:* In the case of the AC_SUBST sed script (_AC_OUTPUT_FILES) -# this optimization cannot be applied as is, because there can be -# several substitutions per line. -# -# -# The result is about, hm, ... times blah... plus.... Ahem. The -# result is about much faster. m4_define([_AC_OUTPUT_HEADERS], [cat >>$CONFIG_STATUS <<\_ACEOF @@ -523,20 +489,22 @@ # CONFIG_HEADERS section. # -# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where -# NAME is the cpp macro being defined and VALUE is the value it is being given. -# -# ac_d sets the value in "#define NAME VALUE" lines. -dnl Double quote for the `[ ]' and `define'. -[ac_dA='s,^\([ ]*\)#\([ ]*define[ ][ ]*\)' -ac_dB='[ ].*$,\1#\2' +# These sed commands are passed to sed as "A NAME B PARAMS C VALUE D", where +# NAME is the cpp macro being defined, VALUE is the value it is being given. +# PARAMS is the parameter list in the macro definition--in most cases, it's +# just an empty string. +# +dnl Quote, for the `[ ]' and `define'. +[ac_dA='s,^\([ ]*#[ ]*\)[^ ]*\([ ][ ]*' +ac_dB='\)\([ (].*\)*$,\1define\2' ac_dC=' ' -ac_dD=',;t' -# ac_u turns "#undef NAME" without trailing blanks into "#define NAME VALUE". -ac_uA='s,^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' -ac_uB='$,\1#\2define\3' -ac_uC=' ' -ac_uD=',;t'] +ac_dD=','] +dnl ac_dD used to contain `;t' at the end. +dnl This was an optimization which was making the code both slow and incorrect. +dnl 1) Since the script has to be broken to chunks containing 100 commands, +dnl this extra command means we have to call sed more times. +dnl 2) The code was incorrect: in the strange case that a sumbol has multiple +dnl different AC_DEFINEs, we want to honour the *last* one. for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". @@ -585,91 +553,60 @@ # config.status. Protect against being in an unquoted here document # in config.status. rm -f conftest.defines conftest.undefs -# Using a here document instead of a string reduces the quoting nightmare. # Putting comments in sed scripts is not portable. # -# `end' is used to avoid that the second main sed command (meant for +# Command `t' is used to avoid that the second main sed command (meant for # 0-ary CPP macros) applies to n-ary macro definitions. # See the Autoconf documentation for `clear'. -cat >confdef2sed.sed <<\_ACEOF -dnl Double quote for `[ ]' and `define'. -[s/[\\&,]/\\&/g +dnl +dnl Quote, for `[ ]' and `define'. +echo '[s/[\\&,]/\\&/g s,[\\$`],\\&,g t clear : clear -s,^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*\)\(([^)]*)\)[ ]*\(.*\)$,${ac_dA}\1${ac_dB}\1\2${ac_dC}\3${ac_dD},gp -t end -s,^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)$,${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD},gp -: end] -_ACEOF +s,^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*\)\(([^)]*)\)[ ]*\(.*\)$,${ac_dA}\1${ac_dB}\2${ac_dC}\3${ac_dD},gp +t +s,^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)$,${ac_dA}\1${ac_dB}${ac_dC}\2${ac_dD},gp]' \ + >confdef2sed.sed + # If some macros were called several times there might be several times # the same #defines, which is useless. Nevertheless, we may not want to -# sort them, since we want the *last* AC-DEFINE to be honored. +# sort them, since we want the *last* AC_DEFINE to be honored. uniq confdefs.h | sed -n -f confdef2sed.sed >conftest.defines -sed 's/ac_d/ac_u/g' conftest.defines >conftest.undefs rm -f confdef2sed.sed # This sed command replaces #undef with comments. This is necessary, for # example, in the case of _POSIX_SOURCE, which is predefined and required # on some systems where configure will not decide to define it. -cat >>conftest.undefs <<\_ACEOF -[s,^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */,] -_ACEOF +echo '[s,^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */,]' >>conftest.defines + +# Break up conftest.defines because some old seds have a limit on number +# of cmds (HP-UX can take 100 cmds). Subtract the +# Here, there are 2 cmd per line, and three cmds at the beginning. +ac_max_sed_lines=97 -# Break up conftest.defines because some shells have a limit on the size -# of here documents, and old seds have small limits too (100 cmds). -echo ' # Handle all the #define templates only if necessary.' >>$CONFIG_STATUS -echo ' if grep ["^[ ]*#[ ]*define"] "$tmp/in" >/dev/null; then' >>$CONFIG_STATUS -echo ' # If there are no defines, we may have an empty if/fi' >>$CONFIG_STATUS -echo ' :' >>$CONFIG_STATUS rm -f conftest.tail -while grep . conftest.defines >/dev/null +while : do - # Write a limited-size here document to $tmp/defines.sed. - echo ' cat >"$tmp/defines.sed" <>$CONFIG_STATUS - # Speed up: don't consider the non `#define' lines. - echo ['/^[ ]*#[ ]*define/!b'] >>$CONFIG_STATUS - # Work around the forget-to-reset-the-flag bug. - echo 't clr' >>$CONFIG_STATUS - echo ': clr' >>$CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.defines >>$CONFIG_STATUS + # Write a here document: + dnl Quote, for the `[ ]' and `define'. + echo [' # First, check the format of the line: + cat >"$tmp/defines.sed" <>$CONFIG_STATUS + sed ${ac_max_sed_lines}q conftest.defines >>$CONFIG_STATUS echo 'CEOF - sed -f "$tmp/defines.sed" "$tmp/in" >"$tmp/out" - rm -f "$tmp/in" - mv "$tmp/out" "$tmp/in" + sed -f "$tmp/defines.sed" "$tmp/in" >"$tmp/out" + rm -f "$tmp/in" + mv "$tmp/out" "$tmp/in" ' >>$CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.defines >conftest.tail + sed 1,${ac_max_sed_lines}d conftest.defines >conftest.tail + grep . conftest.tail >/dev/null || break rm -f conftest.defines mv conftest.tail conftest.defines done -rm -f conftest.defines -echo ' fi # grep' >>$CONFIG_STATUS -echo >>$CONFIG_STATUS - -# Break up conftest.undefs because some shells have a limit on the size -# of here documents, and old seds have small limits too (100 cmds). -echo ' # Handle all the #undef templates' >>$CONFIG_STATUS -rm -f conftest.tail -while grep . conftest.undefs >/dev/null -do - # Write a limited-size here document to $tmp/undefs.sed. - echo ' cat >"$tmp/undefs.sed" <>$CONFIG_STATUS - # Speed up: don't consider the non `#undef' - echo ['/^[ ]*#[ ]*undef/!b'] >>$CONFIG_STATUS - # Work around the forget-to-reset-the-flag bug. - echo 't clr' >>$CONFIG_STATUS - echo ': clr' >>$CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.undefs >>$CONFIG_STATUS - echo 'CEOF - sed -f "$tmp/undefs.sed" "$tmp/in" >"$tmp/out" - rm -f "$tmp/in" - mv "$tmp/out" "$tmp/in" -' >>$CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.undefs >conftest.tail - rm -f conftest.undefs - mv conftest.tail conftest.undefs -done -rm -f conftest.undefs +rm -f conftest.defines conftest.tail dnl Now back to your regularly scheduled config.status. cat >>$CONFIG_STATUS <<\_ACEOF