Hello Benoit,

Ooops.  It seems my memory was messed up, thinking it was your turn
of work with this patch and not mine ... apologies for the long delay,
and thanks for the revised patch.

* Benoit Sigoure wrote on Mon, Jun 25, 2007 at 12:05:31AM CEST:
>
> Alright so here is the new (hopefully final) patch for autoconf.

Famous last words... ;-)

>  It addresses the problems raised so far and provides autom4te with a
>  --clean flag (documented in the .texi) that removes the cache
>  directory (unless it is an absolute path).

Good, thanks.

>  I have carefully reviewed the ChangeLog entry and I 
> think I didn't omit anything this time.  Sorry for getting this wrong last 
> time, I'm used to have this all automated but for SVN only (btw, are you 
> guys ever going to migrate?  CVS is getting a bit old these days :D)

Well I personally don't care much, but if anything then we should
probably go to git or so: savannah supports it, gnulib uses it partly,
and IIRC Paul is getting used to it, too.  So I guess I should look into
it... ;-)

But for writing ChangeLog entries, you can try out (shameless plug!)
vc-chlog, comes with vc-dwim, which is agnostic to the VCS used,
<http://www.mail-archive.com/[EMAIL PROTECTED]/msg04401.html>.

> About the change in autom4te, since I'm not a Perl-portability expert I 
> don't know whether it was a good idea to use 
> `File::Spec->file_name_is_absolute ($cache)'.  If this is a problem we can 
> probably do something similar with a regexp such as the one described in 
> the Autoconf manual.

Looks ok to me.

> I'm going to send the revised patch for Automake just after this email.

Yeah, and I have that (and the Libtool one) still lying around...

Anyway, this looks better and better all the time.  However, "better"
doesn't mean "good enough" yet.  ;-)

I went through the code, keeping some notes and this time fixing issues
along the way.  At the end is an updated patch showing where I am now,
and notes what still needs to be done.

Please note that the lib/Autom4te/FileUtils.pm file is shared by
Autoconf and Automake, the latter being the upstream.  So once we're
through with this patch, let's split that off and apply it to Automake
right away, only to reimport it in Autoconf right away.

> --- bin/autoheader.in 4 Jan 2007 16:43:06 -0000       1.147
> +++ bin/autoheader.in 24 Jun 2007 21:41:31 -0000
[...]
> @@ -195,6 +196,16 @@
>  ($config_h, $config_h_in) = split (':', $config_h, 2);
>  $config_h_in ||= "$config_h.in";
>  
> +if ($clean)
> +  {
> +    foreach my $f ($config_h, $config_h_in . $SIMPLE_BACKUP_SUFFIX)

I suppose you want to remove $config_h_in (without suffix) instead of
$config_h here, no?  (The latter is generated by config.status, not
autoheader, and cleaned by 'make distclean'.)  This error is reflected
in the test also.

> +    {
> +      unlink $f or error "error: Cannot remove `$f': $!"
> +        unless not -f $f;

FWIW, this kind of code leaves me wondering about perl operator
precedence.  Is `unless' an operator (it's not listed in `perldoc
perlop') and what's the binding here?  (I did test it to ensure it's
right here, and left it this way.)

> --- bin/autom4te.in   17 May 2007 08:20:31 -0000      1.107
> +++ bin/autom4te.in   24 Jun 2007 21:41:31 -0000

> @@ -386,6 +389,14 @@
>    $tcache = "$cache/traces.";
>    $ocache = "$cache/output.";
>  
> +  if ($clean)
> +    {
> +      xsystem ("rm -rf '$cache'")
> +        if -e $cache

Let's make this '-d $cache' to be sure.

> +        and not File::Spec->file_name_is_absolute ($cache);
> +      exit 0;
> +    }
> +

> --- bin/autoreconf.in 4 Jan 2007 16:43:06 -0000       1.137
> +++ bin/autoreconf.in 24 Jun 2007 21:41:31 -0000

> +  error 'Cannot install and clean at the same time'
> +    if ($install && $clean);

Let's make that 'fatal' instead of 'error', we really don't want to go
beyond this point here, it leads to weird followup errors.

> @@ -196,6 +203,15 @@
>        $automake   .= ' --copy' unless $symlink;
>        $libtoolize .= ' --copy' unless $symlink;
>      }
> +  elsif ($clean)
> +    {
> +      # Don't tell autoconf and aclocal to --clean: we need them to do their
> +      # work before we can actually remove their files.
> +      $autoheader .= ' --clean';
> +      $automake   .= ' --clean';
> +      $autopoint  .= ' --clean';
> +      $libtoolize .= ' --clean';

What if any of those tools are only available in older versions, such
that they do not accept --clean?  (You mentioned this issue in the mail
for the Automake patch.)

I think the nicest solution would be: if anyone does not understand
--clean, try to cope without as far as possible, but ensure to return
failure.  What we do now is try to run the program with --clean, and the
user will see the error.  Not the nicest, but at least the user gets a
meaningful error.

> @@ -610,31 +666,24 @@
>        xsystem ($automake);
>      }
>  
> +  # ---------------------- #
> +  # Finalize the cleanup.  #
> +  # ---------------------- #
> +
> +  if ($clean)
> +    {
> +      xsystem ($libtoolize) if ($uses_libtool);
> +      xsystem ($autoheader) if ($uses_autoheader);
> +      run_aclocal ($aclocal, '--clean ' . $aclocal_flags);
> +      return;

This isn't right.  If the project uses a hand-written aclocal.m4 file,
then aclocal should not be run here.  That needs testing, too; see
below.

> --- doc/autoconf.texi 13 Jun 2007 16:52:24 -0000      1.1161
> +++ doc/autoconf.texi 24 Jun 2007 21:41:38 -0000

> @@ -1578,6 +1581,12 @@
>  commands it runs.  If given two or more times, pass @option{--verbose}
>  to subordinate tools that support it.
>  
> [EMAIL PROTECTED] --clean
> [EMAIL PROTECTED] -c
> +Remove the auxiliary files in the package that would be installed by
> [EMAIL PROTECTED]  This option can be used to undo the work of
> [EMAIL PROTECTED] --install}.

I added a sentence about other required autotools versions.

> @@ -3092,6 +3101,9 @@
>  @itemx -v
>  Report processing steps.
>  
> [EMAIL PROTECTED] --clean
> +Remove the output file.

and an eventual backup file (this is for autoheader).
I suppose this section should mention the backup file.

> @@ -9527,6 +9539,9 @@
>  @itemx -v
>  Report processing steps.
>  
> [EMAIL PROTECTED] --clean
> +Remove the cache directory unless it is an absolut path.

s/absolut/absolute/
and GCS likes us to speak of "file names" not paths.

> +
>  @item --debug
>  @itemx -d
>  Don't remove the temporary files and be even more verbose.

> --- lib/Autom4te/General.pm   25 Aug 2006 21:21:19 -0000      1.37
> +++ lib/Autom4te/General.pm   24 Jun 2007 21:41:38 -0000

> @@ -50,7 +51,7 @@
>  
>  # Variables we define and export.
>  my @export_vars =
> -  qw ($debug $force $help $me $tmp $verbose $version);
> +  qw ($debug $force $clean $help $me $tmp $verbose $version);

Through the patch to General.pm, autoupdate and autoscan (and ifnames)
will all support --clean (but not -c).  While I don't mind for ifnames,
as it does not generate anything, let's add proper -c|--clean support to
General.pm, this simplifies things in the tools, and let's add support
to autoupdate and autoscan, too.  And test it.  ;-)

> --- tests/torture.at  12 Jun 2007 11:36:57 -0000      1.82
> +++ tests/torture.at  24 Jun 2007 21:41:39 -0000
> @@ -1179,3 +1179,39 @@
[...]
> +AT_DATA([configure.ac],
> +[[AC_INIT
> +AC_CONFIG_HEADERS(config.h:config.hin)
> +AC_OUTPUT
> +]])
> +
> +
> +AT_DATA([config.hin], [])

This isn't necessary: autoheader will generate this file, and
'autoreconf --clean' should remove it.

FWIW, I added another test that tries autoupdate, autoscan, and that
tries all this without relying on aclocal (you use a hand-written
aclocal.m4 file for that), and that a partially autotooled tree can be
cleaned by autoreconf as well.

Also I added documentation for autoupdate and autoscan.  And each tool
shipping with Autoconf should now eat both -c and --clean.

Below's where I'm at now.

This test is still broken: none of the clean commands take care of
autom4te.cache, and I made it pass only by force-removing the cache
manually.  IOW, all those
  rm -rf autom4te.cache   # FIXME
in the new test should go away.

How can we fix the cache issue nicely, do we need to manually invoke
autom4te from each of autoscan, autoupdate, autoreconf (the latter only
if not using aclocal) or does anyone see a better way?  (I have a vague
feeling I'm just missing some nice factorization here, but I simply
don't see how to avoid that `autoheader --clean && autoconf --clean &&
aclocal --clean' takes three times as long as the respective non-clean
commands.)

Cheers,
Ralf

Autoconf:
2007-09-30  Benoit Sigoure  <[EMAIL PROTECTED]>
            Ralf Wildenhues  <[EMAIL PROTECTED]>

        * bin/autoconf.as, bin/autoheader.in, bin/autoreconf.in,
        bin/autom4te.in, bin/autoscan.in, bin/autoupdate.in: New option
        `--clean', short `-c'.
        * NEWS: Mention it.
        * bin/autoreconf.in (&run_make): New, factored out.
        (&autoreconf_current_directory): Use it.  Honor the $clean
        variable.
        * lib/Autom4te/General.pm ($clean): New boolean value.
        (getopt): Handle aliases `-c' and `--clean'.
        * doc/autoconf.texi (autoscan Invocation, autoconf Invocation)
        (autoreconf Invocation, autoheader Invocation)
        (autom4te Invocation, autoupdate Invocation): Document the new
        option.
        * tests/torture.at (Unbootstrap, Unbootstrap with aclocal): New
        tests.

        * lib/Autom4te/FileUtils.pm: Sync from Automake.  Exports...
        ($SIMPLE_BACKUP_SUFFIX): ...this.

Automake:
2007-09-30  Benoit Sigoure  <[EMAIL PROTECTED]>
        * lib/Automake/FileUtils.pm ($SIMPLE_BACKUP_SUFFIX): Export it.

Index: NEWS
===================================================================
RCS file: /srv/git/autoconf.git/HEAD/NEWS,v
retrieving revision 1.439
diff -u NEWS
--- NEWS revision 1.439
+++ NEWS working copy
@@ -8,6 +8,9 @@
    generated by autoconf under the license of your own program.
  FIXME - revisit this line once exception clause is finalized.
 
+** It is now possible to undo the work of autoconf, autoheader, autoscan,
+   autoupdate, and autoreconf with the --clean option.
+
 ** New Autoconf macros AC_OPENMP, AC_PATH_PROGS_FEATURE_CHECK, AC_VERSION.
 
 ** AC_C_BIGENDIAN now supports universal binaries a la Mac OS X.
Index: bin/autoconf.as
===================================================================
RCS file: /srv/git/autoconf.git/HEAD/bin/autoconf.as,v
retrieving revision 1.28
diff -u bin/autoconf.as
--- bin/autoconf.as revision 1.28
+++ bin/autoconf.as working copy
@@ -29,6 +29,7 @@
   -h, --help                print this help, then exit
   -V, --version             print version number, then exit
   -v, --verbose             verbosely report processing
+  -c, --clean               remove files installed by autoconf
   -d, --debug               don't remove temporary files
   -f, --force               consider all files obsolete
   -o, --output=FILE         save output in FILE (stdout is the default)
@@ -80,6 +81,7 @@
 autom4te_options=
 outfile=
 verbose=false
+clean=false
 
 # Parse command line.
 while test $# -gt 0 ; do
@@ -97,6 +99,10 @@
        verbose=:
        autom4te_options="$autom4te_options $1"; shift ;;
 
+    --clean | -c )
+       clean=:
+       autom4te_options="$autom4te_options $1"; shift ;;
+
     # Arguments passed as is to autom4te.
     --debug      | -d   | \
     --force      | -f   | \
@@ -161,7 +167,11 @@
       AS_ECHO(["$as_me: no input file"]) >&2
       exit 1
     fi
-    test -z "$traces" && test -z "$outfile" && outfile=configure;;
+    test -z "$traces" && test -z "$outfile" && outfile=configure
+    if $clean && test x"$outfile" != x; then
+      rm -f "$outfile"
+    fi
+    ;;
   1)
     infile=$1 ;;
   *) exec >&2
Index: bin/autoheader.in
===================================================================
RCS file: /srv/git/autoconf.git/HEAD/bin/autoheader.in,v
retrieving revision 1.150
diff -u bin/autoheader.in
--- bin/autoheader.in revision 1.150
+++ bin/autoheader.in working copy
@@ -68,6 +68,7 @@
   -h, --help               print this help, then exit
   -V, --version            print version number, then exit
   -v, --verbose            verbosely report processing
+  -c, --clean              remove files installed by autoheader
   -d, --debug              don\'t remove temporary files
   -f, --force              consider all files obsolete
   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY
@@ -193,6 +194,16 @@
 ($config_h, $config_h_in) = split (':', $config_h, 2);
 $config_h_in ||= "$config_h.in";
 
+if ($clean)
+  {
+    foreach my $f ($config_h_in, $config_h_in . $SIMPLE_BACKUP_SUFFIX)
+      {
+       unlink $f or error "error: Cannot remove `$f': $!"
+         unless not -f $f;
+      }
+    exit 0;
+  }
+
 # %SYMBOL might contain things like `F77_FUNC(name,NAME)', but we keep
 # only the name of the macro.
 %symbol = map { s/\(.*//; $_ => 1 } keys %symbol;
Index: bin/autom4te.in
===================================================================
RCS file: /srv/git/autoconf.git/HEAD/bin/autom4te.in,v
retrieving revision 1.110
diff -u bin/autom4te.in
--- bin/autom4te.in revision 1.110
+++ bin/autom4te.in working copy
@@ -172,6 +172,7 @@
   -h, --help               print this help, then exit
   -V, --version            print version number, then exit
   -v, --verbose            verbosely report processing
+  -c, --clean              remove the cache
   -d, --debug              don\'t remove temporary files
   -o, --output=FILE        save output in FILE (defaults to \`-\', stdout)
   -f, --force              don\'t rely on cached values
@@ -362,7 +363,7 @@
 
   fatal "too few arguments
 Try `$me --help' for more information."
-    unless @ARGV;
+    unless @ARGV or $clean;
 
   # Freezing:
   # We cannot trace at the same time (well, we can, but it sounds insane).
@@ -384,6 +385,14 @@
   $tcache = "$cache/traces.";
   $ocache = "$cache/output.";
 
+  if ($clean)
+    {
+      xsystem ("rm -rf '$cache'")
+        if -d $cache
+        and not File::Spec->file_name_is_absolute ($cache);
+      exit 0;
+    }
+
   # Normalize the includes: the first occurrence is enough, several is
   # a pain since it introduces a useless difference in the path which
   # invalidates the cache.  And strip `.' which is implicit and always
Index: bin/autoreconf.in
===================================================================
RCS file: /srv/git/autoconf.git/HEAD/bin/autoreconf.in,v
retrieving revision 1.140
diff -u bin/autoreconf.in
--- bin/autoreconf.in revision 1.140
+++ bin/autoreconf.in working copy
@@ -69,6 +69,7 @@
   -h, --help               print this help, then exit
   -V, --version            print version number, then exit
   -v, --verbose            verbosely report processing
+  -c, --clean              remove auxiliary files
   -d, --debug              don't remove temporary files
   -f, --force              consider all files obsolete
   -i, --install            copy missing auxiliary files
@@ -152,6 +153,9 @@
          'm|make'               => \$make,
          'recursive!'           => \$recursive);
 
+  fatal 'Cannot install and clean at the same time'
+    if ($install && $clean);
+
   # Split the warnings as a list of elements instead of a list of
   # lists.
   @warning = map { split /,/ } @warning;
@@ -194,6 +198,15 @@
       $automake   .= ' --copy' unless $symlink;
       $libtoolize .= ' --copy' unless $symlink;
     }
+  elsif ($clean)
+    {
+      # Don't tell autoconf and aclocal to --clean: we need them to do their
+      # work before we can actually remove their files.
+      $autoheader .= ' --clean';
+      $automake   .= ' --clean';
+      $autopoint  .= ' --clean';
+      $libtoolize .= ' --clean';
+    }
   # --force;
   if ($force)
     {
@@ -302,12 +315,50 @@
     }
 }
 
+# &run_make ([TARGET])
+# --------------------
+# Run make in the current directory.  config.status is run first
+# in order to recreate the Makefile unless we're in --clean mode.
+# Return true on success, false if something went wrong.
+sub run_make (;$)
+{
+  my ($target) = @_;
+  $target = '' if not defined $target;
+
+  # Regenerate the Makefile first (unless we're in --clean mode).
+  if (!$clean)
+    {
+      if (!-f 'config.status')
+       {
+         verb 'no config.status: cannot re-make';
+         return 0;
+       }
+      else
+       {
+         xsystem ('./config.status --recheck');
+         xsystem ('./config.status');
+       }
+    }
+  if (!-f 'Makefile')
+    {
+      verb 'no Makefile: cannot re-make' unless $clean;
+      return 0;
+    }
+  else
+    {
+      xsystem ("make $target");
+    }
+  return 1;
+}
+
 # &autoreconf_current_directory
 # -----------------------------
 sub autoreconf_current_directory ()
 {
   my $configure_ac = find_configure_ac;
 
+  run_make ('maintainer-clean') if ($make && $clean);
+
   # ---------------------- #
   # Is it using Autoconf?  #
   # ---------------------- #
@@ -343,7 +394,7 @@
   # will fail: the Gettext macros are missing.
   #
   # Therefore, we can't use the traces to decide if we use Gettext or
-  # not.  I guess that once Gettext move to 2.5x we will be able to,
+  # not.  I guess that once Gettext moves to 2.5x we will be able to,
   # but in the meanwhile forget it.
   #
   # We can only grep for AM_GNU_GETTEXT_VERSION in configure.ac.  You
@@ -357,7 +408,7 @@
     {
       verb "$configure_ac: not using Gettext";
     }
-  elsif (!$install)
+  elsif (!$install && !$clean)
     {
       verb "$configure_ac: not running autopoint: --install not given";
     }
@@ -517,20 +568,21 @@
   # Running libtoolize.  #
   # -------------------- #
 
+  if ($uses_libltdl)
+    {
+      $libtoolize .= " --ltdl";
+    }
+
   if (!$uses_libtool)
     {
       verb "$configure_ac: not using Libtool";
     }
   elsif ($install)
     {
-      if ($uses_libltdl)
-       {
-         $libtoolize .= " --ltdl";
-       }
       xsystem ($libtoolize);
       $rerun_aclocal = 1;
     }
-  else
+  elsif (!$clean)
     {
       verb "$configure_ac: not running libtoolize: --install not given";
     }
@@ -567,6 +619,7 @@
   # latter runs the former, and (ii) autoconf is stricter than
   # autoheader.  So all in all, autoconf should give better error
   # messages.
+  $autoconf .= ' --clean' if $clean;
   xsystem ($autoconf);
 
 
@@ -586,7 +639,7 @@
     {
       verb "$configure_ac: not using Autoheader";
     }
-  else
+  elsif (!$clean)
     {
       xsystem ($autoheader);
     }
@@ -608,31 +661,32 @@
       xsystem ($automake);
     }
 
+  # ---------------------- #
+  # Finalize the cleanup.  #
+  # ---------------------- #
 
-  # -------------- #
-  # Running make.  #
-  # -------------- #
-
-  if ($make)
+  if ($clean)
     {
-      if (!-f "config.status")
+      xsystem ($libtoolize) if ($uses_libtool);
+      xsystem ($autoheader) if ($uses_autoheader);
+      if (!$uses_aclocal)
        {
-         verb "no config.status: cannot re-make";
+         verb "$configure_ac: not using aclocal";
+         # TODO: We need to take care of the cache ourselves.
        }
       else
-       {
-         xsystem ("./config.status --recheck");
-         xsystem ("./config.status");
-         if (!-f "Makefile")
-           {
-             verb "no Makefile: cannot re-make";
-           }
-         else
-           {
-             xsystem ("make");
-           }
+        {
+         run_aclocal ($aclocal, '--clean ' . $aclocal_flags);
        }
+      return;
     }
+
+
+  # -------------- #
+  # Running make.  #
+  # -------------- #
+
+  run_make () if ($make);
 }
 
 
Index: bin/autoscan.in
===================================================================
RCS file: /srv/git/autoconf.git/HEAD/bin/autoscan.in,v
retrieving revision 1.110
diff -u bin/autoscan.in
--- bin/autoscan.in revision 1.110
+++ bin/autoscan.in working copy
@@ -110,6 +110,7 @@
   -h, --help          print this help, then exit
   -V, --version       print version number, then exit
   -v, --verbose       verbosely report processing
+  -c, --clean         remove `$configure_scan'
   -d, --debug         don't remove temporary files
 
 Library directories:
@@ -635,7 +636,18 @@
 ## Main program.  ##
 ## -------------- ##
 
+my $output = 'configure.scan';
 parse_args;
+
+if ($clean)
+  {
+    foreach my $f ($output, "$me.log")
+      {
+        unlink $f or error "error: Cannot remove `$f': $!"
+         unless not -f $f;
+      }
+    exit 0;
+  }
 $log = new Autom4te::XFile ">$me.log";
 
 $autoconf .= " --debug" if $debug;
@@ -646,7 +658,7 @@
 my $configure_ac = find_configure_ac;
 init_tables;
 scan_files;
-output ('configure.scan');
+output ($output);
 if (-f $configure_ac)
   {
     check_configure_ac ($configure_ac);
Index: bin/autoupdate.in
===================================================================
RCS file: /srv/git/autoconf.git/HEAD/bin/autoupdate.in,v
retrieving revision 1.66
diff -u bin/autoupdate.in
--- bin/autoupdate.in revision 1.66
+++ bin/autoupdate.in working copy
@@ -69,6 +69,7 @@
   -h, --help                 print this help, then exit
   -V, --version              print version number, then exit
   -v, --verbose              verbosely report processing
+  -c, --clean                remove backup files
   -d, --debug                don't remove temporary files
   -f, --force                consider all files obsolete
 
@@ -241,6 +242,17 @@
 ## Process the files.  ##
 ## ------------------- ##
 
+if ($clean)
+  {
+    foreach my $file (@ARGV)
+      {
+       my $f = "$file$SIMPLE_BACKUP_SUFFIX";
+       unlink $f or error "error: Cannot remove `$f': $!"
+         unless not -f $f;
+      }
+    exit 0;
+  }
+
 foreach my $file (@ARGV)
   {
     # We need an actual file.
Index: doc/autoconf.texi
===================================================================
RCS file: /srv/git/autoconf.git/HEAD/doc/autoconf.texi,v
retrieving revision 1.1179
diff -u doc/autoconf.texi
--- doc/autoconf.texi revision 1.1179
+++ doc/autoconf.texi working copy
@@ -1303,6 +1303,11 @@
 Print the names of the files it examines and the potentially interesting
 symbols it finds in them.  This output can be voluminous.
 
[EMAIL PROTECTED] --clean
[EMAIL PROTECTED] -c
+Remove the output file @file{configure.scan} and the log file
[EMAIL PROTECTED]
+
 @item [EMAIL PROTECTED]
 @itemx -I @var{dir}
 Append @var{dir} to the include path.  Multiple invocations accumulate.
@@ -1383,6 +1388,10 @@
 @itemx -v
 Report processing steps.
 
[EMAIL PROTECTED] --clean
[EMAIL PROTECTED] -c
+Remove the output file.
+
 @item --debug
 @itemx -d
 Don't remove the temporary files.
@@ -1580,6 +1589,13 @@
 commands it runs.  If given two or more times, pass @option{--verbose}
 to subordinate tools that support it.
 
[EMAIL PROTECTED] --clean
[EMAIL PROTECTED] -c
+Remove the auxiliary files in the package that would be installed by
[EMAIL PROTECTED]  This option can be used to undo the work of
[EMAIL PROTECTED] --install}.  Cleaning will fail if the other commands
+used do not support the option @option{--clean} yet.
+
 @item --debug
 @itemx -d
 Don't remove the temporary files.
@@ -3123,6 +3139,10 @@
 @itemx -v
 Report processing steps.
 
[EMAIL PROTECTED] --clean
[EMAIL PROTECTED] -c
+Remove the output file and an eventual backup file.
+
 @item --debug
 @itemx -d
 Don't remove the temporary files.
@@ -9739,6 +9759,10 @@
 @itemx -v
 Report processing steps.
 
[EMAIL PROTECTED] --clean
[EMAIL PROTECTED] -c
+Remove the cache directory unless it has an absolute file name.
+
 @item --debug
 @itemx -d
 Don't remove the temporary files and be even more verbose.
@@ -17122,6 +17146,10 @@
 @itemx -v
 Report processing steps.
 
[EMAIL PROTECTED] --clean
[EMAIL PROTECTED] -c
+Remove the backup file.
+
 @item --debug
 @itemx -d
 Don't remove the temporary files.
Index: lib/Autom4te/FileUtils.pm
===================================================================
RCS file: /srv/git/autoconf.git/HEAD/lib/Autom4te/FileUtils.pm,v
retrieving revision 1.14
diff -u lib/Autom4te/FileUtils.pm
--- lib/Autom4te/FileUtils.pm revision 1.14
+++ lib/Autom4te/FileUtils.pm working copy
@@ -1,4 +1,4 @@
-# Copyright (C) 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
+# Copyright (C) 2003, 2004, 2005, 2006, 2007  Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -47,7 +47,8 @@
 @EXPORT = qw (&contents
              &find_file &mtime
              &update_file &up_to_date_p
-             &xsystem &xqx &dir_has_case_matching_file &reset_dir_cache);
+             &xsystem &xqx &dir_has_case_matching_file &reset_dir_cache
+             $SIMPLE_BACKUP_SUFFIX);
 
 
 =item C<find_file ($file_name, @include)>
@@ -117,6 +118,17 @@
 }
 
 
+=item C<$SIMPLE_BACKUP_SUFFIX>
+
+Suffix to use for files backed up.  Defaults to `~'.  Can be overridden
+with the environment variable SIMPLE_BACKUP_SUFFIX.
+
+=cut
+
+use vars qw ($SIMPLE_BACKUP_SUFFIX);
+$SIMPLE_BACKUP_SUFFIX = $ENV{'SIMPLE_BACKUP_SUFFIX'} || '~';
+
+
 =item C<update_file ($from, $to, [$force])>
 
 Rename C<$from> as C<$to>, preserving C<$to> timestamp if it has not
@@ -133,7 +145,6 @@
   my ($from, $to, $force) = @_;
   $force = 0
     unless defined $force;
-  my $SIMPLE_BACKUP_SUFFIX = $ENV{'SIMPLE_BACKUP_SUFFIX'} || '~';
   use File::Compare;
   use File::Copy;
 
Index: lib/Autom4te/General.pm
===================================================================
RCS file: /srv/git/autoconf.git/HEAD/lib/Autom4te/General.pm,v
retrieving revision 1.39
diff -u lib/Autom4te/General.pm
--- lib/Autom4te/General.pm revision 1.39
+++ lib/Autom4te/General.pm working copy
@@ -1,5 +1,6 @@
 # autoconf -- create `configure' using m4 macros
-# Copyright (C) 2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007  Free Software
+# Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -48,7 +49,7 @@
 
 # Variables we define and export.
 my @export_vars =
-  qw ($debug $force $help $me $tmp $verbose $version);
+  qw ($debug $force $clean $help $me $tmp $verbose $version);
 
 # Functions we define and export.
 my @export_subs =
@@ -92,6 +93,16 @@
 use vars qw ($force);
 $force = undef;
 
+=item C<$clean>
+
+Set this variable to 1 to remove all files that would otherwise be
+created.
+
+=cut
+
+use vars qw ($clean);
+$clean = undef;
+
 =item C<$help>
 
 Set to the help message associated to the option C<--help>.
@@ -259,6 +270,7 @@
             "v|verbose"  => sub { ++$verbose },
             "d|debug"    => sub { ++$debug },
             'f|force'    => \$force,
+            'c|clean'    => \$clean,
 
             # User options last, so that they have precedence.
             %option);
Index: tests/torture.at
===================================================================
RCS file: /srv/git/autoconf.git/HEAD/tests/torture.at,v
retrieving revision 1.86
diff -u tests/torture.at
--- tests/torture.at revision 1.86
+++ tests/torture.at working copy
@@ -1211,3 +1211,134 @@
 AT_CHECK([test -f HeeHee.in])
 
 AT_CLEANUP
+
+## ----------- ##
+## Unbootstrap ##
+## ----------- ##
+
+AT_SETUP([Unbootstrap])
+AT_KEYWORDS([autoreconf])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_CONFIG_HEADERS([config.h:config.hin])
+# a macro modified by autoupdate:
+AC_OUTPUT([Foo])
+]])
+
+AT_DATA([aclocal.m4],
+[[# written manually, not by aclocal.
+]])
+
+AT_DATA([Foo.in], [])
+
+AT_DATA([foo.c],
+[[#include <stdint.h>
+int foo (int x)
+{
+  return x;
+}
+]])
+
+# Save the result of `find' to see whether we properly cleaned everything.
+AT_DATA([list.after], [])
+AT_DATA([list.before], [])
+
+# Save the list of files in the current directory.
+find . | sort >list.before
+
+# Check that this works even in a tree where autotools have not yet ...
+AT_CHECK([autoreconf --clean], [0], [ignore], [ignore])
+rm -rf autom4te.cache   # FIXME
+find . | sort >list.after
+AT_CMP([list.before], [list.after])
+
+# ... or only partially been used.
+AT_CHECK([autoconf], [0], [ignore], [ignore])
+AT_CHECK([autoreconf --clean], [0], [ignore], [ignore])
+rm -rf autom4te.cache   # FIXME
+find . | sort >list.after
+AT_CMP([list.before], [list.after])
+
+AT_CHECK([autoheader], [0], [ignore], [ignore])
+AT_CHECK([autoreconf --clean], [0], [ignore], [ignore])
+rm -rf autom4te.cache   # FIXME
+find . | sort >list.after
+AT_CMP([list.before], [list.after])
+
+AT_CHECK([autoreconf], [0], [ignore], [ignore])
+AT_CHECK([autoreconf --clean], [0], [ignore], [ignore])
+rm -rf autom4te.cache   # FIXME
+find . | sort >list.after
+AT_CMP([list.before], [list.after])
+
+# Check that we fail with an invalid option combination
+AT_CHECK([autoreconf --install --clean], [1], [ignore], [ignore])
+
+AT_CHECK([autoscan], [0], [ignore], [ignore])
+AT_CHECK([autoscan --clean], [0], [ignore], [ignore])
+rm -rf autom4te.cache   # FIXME
+find . | sort >list.after
+AT_CMP([list.before], [list.after])
+
+AT_CHECK([autoupdate], [0], [ignore], [ignore])
+AT_CHECK([autoupdate --clean], [0], [ignore], [ignore])
+rm -rf autom4te.cache   # FIXME
+find . | sort >list.after
+AT_CMP([list.before], [list.after])
+
+AT_CLEANUP
+
+## ------------------------ ##
+## Unbootstrap with aclocal ##
+## ------------------------ ##
+
+AT_SETUP([Unbootstrap with aclocal])
+AT_KEYWORDS([autoreconf])
+
+# We use aclocal (via autoreconf).
+AT_CHECK([aclocal --version || exit 77], [], [ignore], [ignore])
+# We need a version of aclocal that is recent enough to support --clean
+AT_CHECK([aclocal --help | grep ' --clean' || exit 77], [], [ignore], [ignore])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_CONFIG_HEADERS(config.h:config.hin)
+AC_OUTPUT
+]])
+
+# Save the result of `find' to see whether we properly cleaned everything.
+AT_DATA([list.after], [])
+AT_DATA([list.before], [])
+# Save the list of files in the current directory.
+find . | sort >list.before
+
+AT_CHECK([autoreconf --clean], [0], [ignore], [ignore])
+find . | sort >list.after
+AT_CMP([list.before], [list.after])
+
+AT_CHECK([aclocal], [0], [ignore], [ignore])
+AT_CHECK([autoreconf --clean], [0], [ignore], [ignore])
+find . | sort >list.after
+AT_CMP([list.before], [list.after])
+
+AT_CHECK([aclocal], [0], [ignore], [ignore])
+AT_CHECK([autoheader], [0], [ignore], [ignore])
+AT_CHECK([autoreconf --clean], [0], [ignore], [ignore])
+find . | sort >list.after
+AT_CMP([list.before], [list.after])
+
+AT_CHECK([aclocal], [0], [ignore], [ignore])
+AT_CHECK([autoconf], [0], [ignore], [ignore])
+AT_CHECK([autoreconf --clean], [0], [ignore], [ignore])
+find . | sort >list.after
+AT_CMP([list.before], [list.after])
+
+AT_CHECK([autoreconf], [0], [ignore], [ignore])
+AT_CHECK([autoreconf --clean], [0], [ignore], [ignore])
+find . | sort >list.after
+AT_CMP([list.before], [list.after])
+
+AT_CLEANUP
+
+# TODO: unbootstrap recursive packages


Reply via email to