autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

multiline output variables.


From: Dan Manthey
Subject: multiline output variables.
Date: Thu, 13 Jan 2005 17:49:36 -0500

I first used autoconf some years ago and remember being vexed by the
inability to substitute output variables containing newlines.  I recently
again started using autoconf and have again found this an irrirating
limitation.

I've made an attempt to fix the problem, and I'd like comments as to
whether my fix is acceptible.  This solution does noticably slow down the
creation of config.status, which I assume is pretty bad, but also should
slightly speed up the execution of config.status.

Note that this is not final code, so try not to gripe too much about it.

Previously, a single file with all the sed substitution commands was
generated, and then these had their internal separaters (the characters
used to delimite the s/// commands (commas, at the moment)) and
metacharacters (only ampersand and backslash) quoted (with backslashes).

My first thought was to simply also quote newlines.  This proved
inpracticable due to the inability to guanantee that a substituted value
of an output variable wouldn't confuse this quoting.  Therefore, I changed
the way that the command lines were generated, so that the right-hand side
of the substitution was quoted by a separate call to sed for each
variable, allowing me to avoid applying that sed command to the parts that
must not be quoted.  This use of many separates calls to sed is what slows
down my solution.

However, I then discovered that the shell code inside of config.status
that breaks the one file of sed substitutions up into multiple small files
had the potential to break multi-line substitutions in the middle.  It
appears to me that since the set of substitutions is fixed at the time of
running autoconf, then this breakup can be done in m4, which I did.  I
assumed that the 100-command limit for sed was indeed 100-command and not
100-line.  This latter change could be made regardless of multi-line
substitutions.

Does anyone know of any portabilities issues with what I have done?  Does
anyone have a strong opinion as to the benefits of multi-line output
variable as compared to the detriment of a slow-to-execute configure
script?

Find below a patch of _AC_OUTPUT_FILES.

-Dan Manthey


--- status.m4.old       2005-01-13 15:03:43.702862400 -0500
+++ status.m4   2005-01-13 16:53:33.338292800 -0500
@@ -852,6 +852,20 @@
 m4_define([AC_LIST_FILES_COMMANDS])


+m4_define([_AC_CONFIG_STATUS_SED_CMD],
+[m4_if($#,0,
+[m4_if([_AC_CONFIG_STATUS_SED_CMDS],0,[[ac_sed_cmds=cat]],[[CEOF]])],
+0,m4_eval(_AC_CONFIG_STATUS_SED_CMDS % 48),
+m4_if(0,_AC_CONFIG_STATUS_SED_CMDS,[],
+[[CEOF
+]])dnl
+[[ac_sed_cmds="]m4_if(0,_AC_CONFIG_STATUS_SED_CMDS,[],[[\$ac_sed_cmds | ]])dnl
+[sed -f \$tmp/subs-]m4_eval((_AC_CONFIG_STATUS_SED_CMDS / 48)+1)[.sed"
+cat >\$tmp/subs-]m4_eval((_AC_CONFIG_STATUS_SED_CMDS / 48)+1)[.sed <<\CEOF
+:t; /@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+]])dnl
+m4_define([_AC_CONFIG_STATUS_SED_CMDS],m4_incr(_AC_CONFIG_STATUS_SED_CMDS))dnl
+$1])

 # _AC_OUTPUT_FILES
 # ----------------
@@ -870,67 +884,23 @@
 # No need to generate the scripts if there are no CONFIG_FILES.
 # This happens for instance when ./config.status config.h
 if test -n "\$CONFIG_FILES"; then
-  # Protect against being on the right side of a sed subst in config.status.
-dnl Please, pay attention that this sed code depends a lot on the shape
-dnl of the sed commands issued by AC_SUBST.  So if you change one, change
-dnl the other too.
-[  sed 's/,@/@@/; s/@,/@@/; s/,;t t\$/@;t t/; /@;t t\$/s/[\\\\&,]/\\\\&/g;
-   s/@@/,@/; s/@@/@,/; s/@;t t\$/,;t t/' >\$tmp/subs.sed <<\\CEOF]
-dnl These here document variables are unquoted when configure runs
-dnl but quoted when config.status runs, so variables are expanded once.
-dnl Insert the sed substitutions of variables.
+  # Split the substitutions into bite-sized pieces for seds with
+  # small command number limits, like on Digital OSF/1 and HP-UX.
+  # One cannot portably go further than 100 commands because of HP-UX.
+  # Here, there are 2 cmd per line.
+m4_pushdef([_AC_CONFIG_STATUS_SED_CMDS],0)dnl
 m4_ifdef([_AC_SUBST_VARS],
         [AC_FOREACH([AC_Var], m4_defn([_AC_SUBST_VARS]),
-[s,@AC_Var@,$AC_Var,;t t
+[_AC_CONFIG_STATUS_SED_CMD(
+[[s,@]AC_Var[@,`echo "$]AC_Var[]dnl
+[" | sed 's/[\\\\&,]/\\\\&/g; $!s/$/\\\\/'`,;t t]])
 ])])dnl
 m4_ifdef([_AC_SUBST_FILES],
         [AC_FOREACH([AC_Var], m4_defn([_AC_SUBST_FILES]),
-[/@AC_Var@/r $AC_Var
-s,@AC_Var@,,;t t
+[_AC_CONFIG_STATUS_SED_CMD([[/@]AC_Var[@/r $]AC_Var[;s,@]AC_Var[@,,;t t]])
 ])])dnl
-CEOF
-
-_ACEOF
-
-  cat >>$CONFIG_STATUS <<\_ACEOF
-  # Split the substitutions into bite-sized pieces for seds with
-  # small command number limits, like on Digital OSF/1 and HP-UX.
-dnl One cannot portably go further than 100 commands because of HP-UX.
-dnl Here, there are 2 cmd per line, and two cmd are added later.
-  ac_max_sed_lines=48
-  ac_sed_frag=1 # Number of current file.
-  ac_beg=1 # First line for current file.
-  ac_end=$ac_max_sed_lines # Line after last line for current file.
-  ac_more_lines=:
-  ac_sed_cmds=
-  while $ac_more_lines; do
-    if test $ac_beg -gt 1; then
-      sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
-    else
-      sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
-    fi
-    if test ! -s $tmp/subs.frag; then
-      ac_more_lines=false
-    else
-      # The purpose of the label and of the branching condition is to
-      # speed up the sed processing (if there are no `@' at all, there
-      # is no need to browse any of the substitutions).
-      # These are the two extra sed commands mentioned above.
-      (echo [':t
-  /@[a-zA-Z_][a-zA-Z_0-9]*@/!b'] && cat $tmp/subs.frag) 
>$tmp/subs-$ac_sed_frag.sed
-      if test -z "$ac_sed_cmds"; then
-       ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed"
-      else
-       ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed"
-      fi
-      ac_sed_frag=`expr $ac_sed_frag + 1`
-      ac_beg=$ac_end
-      ac_end=`expr $ac_end + $ac_max_sed_lines`
-    fi
-  done
-  if test -z "$ac_sed_cmds"; then
-    ac_sed_cmds=cat
-  fi
+_AC_CONFIG_STATUS_SED_CMD
+m4_popdef([_AC_CONFIG_STATUS_SED_CMDS])dnl
 fi # test -n "$CONFIG_FILES"

 _ACEOF






reply via email to

[Prev in Thread] Current Thread [Next in Thread]