&_readfile and &_writefile: Fail on failed file close.
[macros.git] / AutoGen.pm
1 #! /usr/bin/perl
2
3 # $Id$
4 # Module to generate all the initial makefiles etc.
5 # Copyright (C) 2002 Jan Kratochvil <project-macros@jankratochvil.net>
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; exactly version 2 of June 1991 is required
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20
21 package AutoGen;
22 require 5.6.0;  # at least 'use warnings;' but we need some 5.6.0+ modules anyway
23 use vars qw($VERSION);
24 $VERSION=do { my @r=(q$Revision$=~/\d+/g); sprintf "%d.".("%03d"x$#r),@r; };
25 use strict;
26 use warnings;
27
28 BEGIN {
29         my @missing;
30         for (split "\n",<<'HERE') {
31                 use Carp qw(cluck confess);
32                 use Getopt::Long;       # &GetOptions, $Getopt::Long::*
33                 use File::Basename;     # &basename
34                 use File::Grep qw(fgrep);
35                 use File::HomeDir;      # &home
36                 use File::Remove qw(remove);
37                 use File::NCopy qw(copy);
38                 use File::chdir;        # $CWD
39                 use File::Touch;        # &touch
40                 use POSIX qw(WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG WIFSTOPPED WSTOPSIG);
41 HERE
42                 eval "$_\n; 1;" or push @missing,(/^\s*use\s+([^ ;]+)/)[0];
43                 }
44         die "You are missing some modules - install them by:\n"
45                                         ."\tperl -MCPAN -e 'install qw(".join(" ",@missing).")'\n"
46                         if @missing;
47         }
48
49 our %Options;
50
51 sub _help
52 {
53         return '
54 Beware: '.basename($0).' is a tool only for maintainers!
55
56 Supported parameters:
57  --rpm       Build RPM packages locally (needs /usr/src/(redhat|packages)/ access)
58  --rpmtest   Build RPM like "rpm" but w/o gpg/pgp signing
59  --clean     Standard cleanup method
60  --fullclean Like clean but even the .cvsignore files are removed
61  --copy      Behave exactly like in default mode but copy all instead of symlinks
62  -h|--help   Print this help message.
63 '.($Options{"help"} || "");
64 }
65
66 sub checkcommandversion
67 {
68 my($class,$command,$version)=@_;
69
70         local *F;
71         do { open F,$_ or confess "Open $_: $!"; } for ("$command --version|");
72         local $/;
73         undef $/;
74         my $command_out=<F>;
75         close F;
76         my $command_version=($command_out=~m#([\d.]+)#)[0];
77         confess "$command(1) version not found in its output" if !$command_version;
78         confess "'$command' version $version or higher required"
79                         # Do not take 3rd+ numbers as it would not be a number
80                         if ($command_version=~/^(\d+[.]\d+)/)[0]<$version;
81 }
82
83 sub _readfile
84 {
85 my($filename)=@_;
86
87         local $/=undef();
88         local *F;
89         open F,$filename or confess "Open \"$filename\": $!";
90         my $r=<F>;
91         close F or confess "Close \"$filename\": $!";   # Do not &cluck as it may be pipe result
92         return $r;
93 }
94
95 sub _writefile
96 {
97 my($filename,@content)=@_;
98
99         local *F;
100         open F,($filename=~/^[|]/ ? "" : ">").$filename or confess "rewrite \"$filename\": $!";
101         print F @content;
102         close F or confess "close \"$filename\": $!";   # Do not &cluck as it may be pipe result
103 }
104
105 my %_rpmeval_cache;
106 sub _rpmeval
107 {
108 my(@names)=@_;
109
110         my @r=map({
111                 my $name=$_;
112                 my $nameref=\$_rpmeval_cache{$name};
113                 $$nameref=_readfile('rpm --eval %'.$name.'|') if !defined $$nameref;
114                 chomp $$nameref;
115                 $$nameref;
116                 } @names);
117         return @r if wantarray();
118         confess "Scalar return for ".scalar(@r)." values" if 1!=@r;
119         return $r[0];
120 }
121
122 sub _system_error
123 {
124 my($code,$cmd)=@_;
125
126         confess $cmd.": $code=".join(",",
127                         (!WIFEXITED($code)   ? () : ("EXITSTATUS(".WEXITSTATUS($code).")")),
128                         (!WIFSIGNALED($code) ? () : ("TERMSIG("   .WTERMSIG($code)   .")")),
129                         (!WIFSTOPPED($code)  ? () : ("STOPSIG("   .WSTOPSIG($code)   .")")),
130                         );
131 }
132
133 sub _system
134 {
135 my(@args)=@_;
136
137         my $rc_sub=pop @args if ref $args[$#args];
138         $rc_sub||=sub { $_[0]==0; };
139         my $rc=system(@args);
140         _system_error $?,join(" ",@args) if !WIFEXITED($?) || !&{$rc_sub}(WEXITSTATUS($?));
141 }
142
143 # Assumed wildcard pattern expansion to exactly one item if !$nocheck
144 sub _copy
145 {
146 my(@files)=@_;
147
148         my $nocheck=shift @files if $files[0] eq "nocheck";
149         my $flag=shift @files if ref $files[0];
150         my $dest=pop @files;
151         # expand pattern to properly match &copy resulting filenames count
152         @files=map({ glob $_; } @files);
153         @files==copy((!$flag ? () : $flag),@files,$dest) or $nocheck or confess "$!";
154 }
155
156 # Assumed wildcard pattern expansion to exactly one item if !$nocheck
157 sub _remove
158 {
159 my(@files)=@_;
160
161         my $nocheck=shift @files if $files[0] eq "nocheck";
162         my $flag=shift @files if ref $files[0];
163         # expand pattern to properly match &remove resulting filenames count
164         @files=map({ glob $_; } @files);
165         @files==remove((!$flag ? () : $flag),@files) or $nocheck or confess "$!";
166 }
167
168 # FIXME: File::NCopy exists but File::NMove doesn't
169 sub _move
170 {
171 my(@files)=@_;
172
173         my $dest=pop @files;
174         _copy @files,$dest;
175         _remove @files;
176 }
177
178 sub _mkdir
179 {
180 my(@dirs)=@_;
181
182         for (@dirs) {
183                 mkdir $_ or confess "$!";
184                 }
185 }
186
187 sub _prepdist
188 {
189 my($class,$name)=@_;
190
191         my($specsrc)=map((-e $_ ? $_ : "$name.spec.in"),"$name.spec.m4.in");
192         my $spec=_readfile $specsrc;
193         $spec=~s/\\\n/ /gs;
194         my $configure_args=($spec=~/^[%]configure\b[ \t]*(.*)$/m)[0];
195         $configure_args=~s/--disable-gtk-doc\b/--enable-gtk-doc/g;      # optional; gtk-doc reqd for 'make dist'
196         $class->run(%Options,
197                         "ARGV"=>[qw(--copy)],
198                         "configure_args"=>[split /\s+/,$configure_args],
199                         );
200         _remove "nocheck",($Options{"ChangeLog"} || "ChangeLog");       # force its rebuild by Makefile/rcs2log
201 }
202
203 # $args{
204 #       "sign"=>bool,
205 #       },
206 sub _rpmbuild
207 {
208 my($class,%args)=@_;
209
210         my $name=$Options{"name"};
211         _remove "nocheck",\1,
212                         _rpmeval("_tmppath" )."/$name-*-root",
213                         _rpmeval("_builddir")."/$name-*";
214         $class->_prepdist($name);
215         _system "make $name.spec";
216         my $spec=_readfile "$name.spec";
217         my $patch=($spec=~/^Patch\d*:\s*(.*)$/m)[0];
218         _system "make dist";
219         if (!$patch) {
220                 _copy "$name-*.tar.gz",_rpmeval("_sourcedir");
221                 }
222         else {
223                 my @origs;
224                 for my $glob ("orig-$name-*.tar.{gz,Z}") {
225                         @origs=glob "orig-$name-*.tar.{gz,Z,bz2}";
226                         confess "Invalid glob $glob: ".join(",",@origs) if 1!=@origs;
227                         }
228                 my $base=($origs[0]=~/^orig-(.*)[.]tar[.](?:gz|Z)$/)[0];
229                 _copy $origs[0],_rpmeval("_sourcedir")."/".($origs[0]=~/^orig-(.*)$/)[0];
230                 _system "tar xzf ".$origs[0];
231                 _mkdir $base."-orig";
232                 # FIXME: Copy also dot-prefixed files!
233                 _move \1,$base."/*",$base."-orig/";
234                 _system "tar xzf $name-*.tar.gz";
235                 # Use single-argument system() as we need shell redirection.
236                 # FIXME: Use directory-independent _cleanfiles(), not root-directory '.cvsignore'.
237                 #        "-X -" does not work, it needs to be stat(2)able file.
238                 _system "diff -ruP -X .cvsignore -I '".'[$]\(Id\|RCSfile\)\>.*[$]'."'"
239                                 ." $base-orig/ $base/"
240                                 ." >"._rpmeval("_sourcedir")."/".$patch,
241                                 sub { $_[0]==0 || $_[0]==1; };  # diff(1) returns non-zero return code on any diffs.
242                 _remove \1,$base,$base."-orig";
243                 }
244         _system(join(" ","rpmbuild",
245                         "-ba",
246                         "--rmsource",   # _remove _rpmeval("_sourcedir")."/$name-*.tar.gz";
247                         "--clean",      # _remove _rpmeval("_builddir")."/$name-VERSION";
248                         (!$args{"sign"} ? () : "--sign"),
249                         "$name.spec",
250                         ));
251         _system "make dist-tarZ" if $Options{"dist-tarZ"};
252         _move _rpmeval("_srcrpmdir")."/$name-*.src.rpm",".";
253         _move _rpmeval("_rpmdir")."/"._rpmeval("_target_cpu")."/$name-*."._rpmeval("_target_cpu").".rpm",".";
254         _system "ls -l $name-*";
255         exit 0; # should never return
256 }
257
258 # $args{
259 #       "sign"=>bool,
260 #       },
261 sub _debbuild
262 {
263 my($class,%args)=@_;
264
265         my $name=$Options{"name"};
266         $class->_prepdist($name);
267         _system "make distdir";
268         _system(join(" ","cd $name-*;dpkg-buildpackage",
269                         "-rfakeroot",
270                         ($args{"sign"} ? () : ("-us","-uc")),
271                         ));
272         _remove \1,"$name-*";
273         _system "ls -l ${name}_*";
274         exit 0; # should never return
275 }
276
277 # WARNING: doesn't respect %Options change!
278 my @_cleanfiles_cache;
279 sub _cleanfiles
280 {
281         # maintainer-clean hack is not safe, please list all files for 'rm'.
282         # When the filename doesn't contain '/', it is applied to ALL directories.
283         # Please note that files exactly in root dir MUST have ./ in the front
284         #   (to not to be considered as ALL-directories files).
285
286         if (!@_cleanfiles_cache) {
287                 @_cleanfiles_cache=map({
288                                                 local $_=$_;    # Prevent: Modification of a read-only value attempted
289                                                 s/\Q<name>\E/$Options{"name"}/ego;
290                                                 s#/+#/#g;
291                                                 # "*xyzzy" basename -> "*xyzzy",".*xyzzy" for proper cleaning
292                                                 (!m#^((?:.*/)?)([*][^/]*)$# ? ($_) : ("$1$2","$1.$2"));
293                                                 }
294                                 (
295                                 ".#*",  # Possible attempt to put comments in qw() list
296                                 qw(
297                                                 *~
298                                                 *.orig *.rej
299                                                 core
300                                                 Makefile Makefile.in
301                                                 TAGS tags ID
302                                                 .deps .libs
303                                                 *.[oa] *.l[oa] *.l[oa]T
304                                                 .cvsignore
305
306                                                 ./errs*
307                                                 ./intl
308                                                 ./configure ./configure.scan
309                                                 ./config.guess ./config.status ./config.sub ./config.log ./config.cache
310                                                 ./config.h ./config.h.in
311                                                 ./confdefs.h ./conftest* ./autoh[0-9]* ./confcache
312                                                 ./config.rpath
313                                                 ./depcomp
314                                                 ./compile
315                                                 ./stamp-h ./stamp-h.in ./stamp-h1
316                                                 ./install-sh
317                                                 ./aclocal.m4
318                                                 ./autom4te.cache ./autom4te-*.cache
319                                                 ./m4
320                                                 ./missing
321                                                 ./mkinstalldirs
322                                                 ./libtool ./ltconfig ./ltmain.sh
323                                                 ./ABOUT-NLS
324                                                 ./<name>-[0-9]* ./<name>-devel-[0-9]*
325                                                 ./<name>.spec ./<name>.m4 ./<name>.spec.m4
326                                                 ./debian/tmp ./debian/<name>
327                                                 ./<name>_[0-9]*
328                                                 ./macros/macros.dep
329                                                 ./po/Makefile.in.in ./po/POTFILES* ./po/cat-id-tbl.c ./po/cat-id-tbl.tmp
330                                                 ./po/*.gmo ./po/*.mo ./po/stamp-cat-id ./po/<name>.pot ./po/ChangeLog
331                                                 ./po/Makevars ./po/Makevars.template ./po/Rules-quot ./po/*.sed ./po/*.sin ./po/*.header
332                                                 ),
333                                 map(("./$_"),($Options{"ChangeLog"} || "ChangeLog")),
334                                 map((!$_ ? () : do { my $dir=$_; map("$dir/$_",qw(
335                                                 *.stamp
336                                                 sgml*
337                                                 tmpl*
338                                                 html*
339                                                 xml
340                                                 *.txt
341                                                 *.txt.bak
342                                                 *.new
343                                                 *.sgml
344                                                 *.args
345                                                 *.hierarchy
346                                                 *.signals
347                                                 *.interfaces
348                                                 *.prerequisites
349                                                 )); }),$Options{"gtk-doc-dir"}),
350                                 map((!$_ ? () : do { my $dir=$_; map("$dir/$_",qw(
351                                                 *.html
352                                                 *.info*
353                                                 *.txt
354                                                 *.tex
355                                                 *.sgml
356                                                 )); }),$Options{"docbook-lite-dir"}),
357                                 map((!$_ ? () : @$_),$Options{"clean"}),
358                                 ));
359                 # sanity check
360                 for (@_cleanfiles_cache) {
361                                 confess "dir-specific 'clean'-pattern must start with './': $_" if m#^(?!\Q./\E).*/#;
362                                 };
363                 }
364         return @_cleanfiles_cache;
365 }
366
367 sub _cleanfilesfordir
368 {
369 my($dir)=@_;
370
371         return map({
372                            if (m#^\Q$dir\E/([^/]+)$#) { # this-dir: "./this-dir/file-name.c"
373                                         ($1);
374                                         }
375                         elsif (m#^[^/]+$#) {    # all-dirs: "file-name.c"; the same as "./*/file-name.c"
376                                         ($&);
377                                         }
378                         elsif (do {     # all-subdirs: "./parent-of-this-dir/*/file-name.c"
379                                                         m#/[*]/([^/]+)$#;
380                                                         ($_=$1) && $dir=~m#^\Q$`\E(?:/|$)#;
381                                                         }) {
382                                         ($_);
383                                         }
384                         else {
385                                         ();
386                                         }
387                         } _cleanfiles());
388 }
389
390 sub _cvsdirs
391 {
392 my(@startdirs)=@_;
393
394         my @r=();
395         my @todo=(@startdirs);
396         while (defined(my $dir=shift @todo)) {
397                 local *ENTRIES;
398                 my $entries_filename="$dir/CVS/Entries";
399                 open ENTRIES,$entries_filename or (cluck "open \"$entries_filename\": $!" and next);
400                 push @r,$dir;
401                 local $/="\n";
402                 my %local=();
403                 local $_;
404                 while (<ENTRIES>) {
405                         chomp;
406                         next if !m#^D/([^/]+)/#;
407                         $local{$1}=1;
408                         }
409                 close ENTRIES or cluck "close \"$entries_filename\": $!";
410                 if (-e (my $entries_log_filename=$dir."/CVS/Entries.Log")) {
411                         local *ENTRIES_LOG;
412                         if (open ENTRIES_LOG,$entries_log_filename or cluck "open \"$entries_log_filename\": $!") {
413                                 local $_;
414                                 while (<ENTRIES_LOG>) {
415                                         chomp;
416                                                  if (m#^A D/([^/]*)/#) {
417                                                 $local{$1}=1;
418                                                 }
419                                         elsif (m#^R D/([^/]*)/#) {
420                                                 delete $local{$1};
421                                                 }
422                                         else {
423                                                 cluck "$entries_log_filename: Unrecognized line $.: $_";
424                                                 }
425                                         }
426                                 close ENTRIES_LOG or cluck "close \"$entries_log_filename\": $!";
427                                 }
428                         }
429                 push @todo,map(("$dir/$_"),keys(%local));
430                 }
431         return @r;
432 }
433
434 sub _expandclass
435 {
436 my($patt)=@_;
437
438         return $patt if $patt!~/\Q[\E(.*?)\Q]\E/;
439         my($pre,$range,$post)=($`,$1,$');       # FIXME: local($`,$1,$') doesn't work - why?
440         1 while $range=~s#(.)-(.)# join("",map(chr,(ord($1)..ord($2))));
441                         #ge;
442         return map({ _expandclass("$pre$_$post"); } split("",$range));
443 }
444
445 sub run
446 {
447 my($class,%options)=@_;
448
449         local %Options=%options;
450         do { require $_ if -e; } for (home()."/.".$Options{"name"}.".autogen.pl");
451         do { $$_=1 if !defined($$_) && fgrep { /^\s*AUTOMAKE_OPTIONS\s*=[^#]*\bdist-tarZ\b/m; } "Makefile.am"; }
452                         for (\$Options{"dist-tarZ"});
453         Getopt::Long::Configure('noignorecase','prefix_pattern=(--|-|\+|)');
454         local @ARGV=@{$Options{"ARGV"}};
455         print _help() and confess if !GetOptions(
456                           "rpm"      ,sub { $class->_rpmbuild("sign"=>1); },
457                           "rpmtest"  ,sub { $class->_rpmbuild("sign"=>0); },
458                           "deb"      ,sub { $class->_debbuild("sign"=>1); },
459                           "debtest"  ,sub { $class->_debbuild("sign"=>0); },
460                           "dist"     ,\$Options{"ARGV_dist"},
461                           "copy!"    ,\$Options{"ARGV_copy"},
462                           "fullclean",\$Options{"ARGV_fullclean"},
463                           "clean"    ,\$Options{"ARGV_clean"},
464                         "h|help"     ,sub { print _help(); exit 0; },
465                         $Options{"GetOptions_args"},
466                         ) || @ARGV;
467
468         for my $subdir (map((!$_ ? () : @$_),$Options{"subdirs"})) {
469                 local $CWD=$subdir;
470                 _system "./autogen.pl",@{$Options{"ARGV"}},"--dist";    # use "--dist" just as fallback!
471                 }
472
473         for my $dir (_cvsdirs(".")) {
474                 my @cleanfilesfordir=_cleanfilesfordir $dir;
475                 _writefile $dir."/.cvsignore",map("$_\n",@cleanfilesfordir) if !$Options{"ARGV_fullclean"};
476                 _remove "nocheck",\1,map({ _expandclass("$dir/$_"); } grep({
477                                 $Options{"ARGV_fullclean"} or $_ ne ".cvsignore";
478                                 } @cleanfilesfordir));
479                 }
480         return if $Options{"ARGV_clean"} || $Options{"ARGV_fullclean"};
481
482         $Options{"aclocal_args"}=[qw(-I macros),map((!$_ ? () : @$_),$Options{"aclocal_args"})];
483         my $configure_in=_readfile("configure.in");
484         do { $$_=1 if !defined($$_) && $configure_in=~/^AM_GNU_GETTEXT\b/m; }
485                         for (\$Options{"want-gettextize"});
486         do { $$_=1 if !defined($$_) && $configure_in=~/^AM_GLIB_GNU_GETTEXT\b/m; }
487                         for (\$Options{"want-glib-gettextize"});
488         do { $$_=1 if !defined($$_) && $configure_in=~/^AM_PROG_LIBTOOL\b/m; }
489                         for (\$Options{"want-libtoolize"}); 
490         do { $$_=1 if !defined($$_) && $configure_in=~/^A[CM]_CONFIG_HEADER\b/m; }
491                         for (\$Options{"want-autoheader"});
492         my @copy_arg=(!$Options{"ARGV_copy"} ? () : "--copy");
493
494         do { &$_ if $_; } for ($Options{"prep"});
495         touch "po/POTFILES.in" if -d "po";
496         if ($Options{"want-gettextize"}) {
497                 # don't use multi-arg system() here as it would reject "</dev/null" redirection etc.
498                 for ("expect -c '"
499                                 .'spawn gettextize --intl --no-changelog '.join(" ",@copy_arg).';'
500                                 .'expect -timeout -1 "Press Return to acknowledge" {send "\r";exp_continue;} eof;'
501                                 ."'") {
502                         _system $_ and confess $_;
503                         }
504                 for ("configure.in","Makefile.am") {
505                         STDERR->printflush("gettextize recovery rename \"$_~\"->\"$_\"... ");
506                         rename "$_~","$_" or confess "$!";
507                         STDERR->printflush("ok\n");
508                         }
509                 if (!-e "po/Makevars") {
510                         my $Makevars_template="po/Makevars.template";
511                         my $makevars=_readfile $Makevars_template;
512                         $makevars=~s/^(COPYRIGHT_HOLDER)\b.*$/"$1=".$Options{"COPYRIGHT_HOLDER"}/meg
513                                         or confess "COPYRIGHT_HOLDER not found in $Makevars_template";
514                         _writefile "po/Makevars",$makevars;
515                         }
516                 # Prevent updating of contents during touch of any source file;
517                 # change the .po contents only when some data get updated
518                 for my $Makefile_in_in ("po/Makefile.in.in") {
519                         my $file=_readfile $Makefile_in_in;
520                         $file=~s%(\$\Q(MSGMERGE_UPDATE)\E) (\$\$\Q{lang}.po \E\$\Q(DOMAIN).pot\E)$%
521                                         $1.q< --backup=simple --suffix="~" >.$2.q<;>
522                                                         .q< if test `diff -u $${lang}.po~ $${lang}.po>
523                                                                                         .q< | sed>
524                                                                                                         .q< -e '1,/^@@.*@@$$/d'>
525                                                                                                         .q< -e '/^[+-]"POT-Creation-Date:/d'>
526                                                                                                         .q< -e '/^[^+-]/d'>
527                                                                                                         .q< -e '/^[+-]#/d'>
528                                                                                         .q< | wc -l` -eq 0;then>
529                                                                         .q< touch --reference=$${lang}.po $${lang}.po~;>
530                                                                                         .q< mv -f $${lang}.po~ $${lang}.po;>
531                                                         .q< else>
532                                                                         .q< rm -f $${lang}.po~;>
533                                                         .q< fi>
534                                         %me or confess;
535                         unlink $Makefile_in_in or confess "$!";
536                         _writefile $Makefile_in_in,$file;
537                         }
538                 }
539         if ($Options{"want-glib-gettextize"}) {
540                 _system "glib-gettextize",@copy_arg;
541                 # "po/ChangeLog" is somehow missing at this point
542                 File::Touch->new("atime_only"=>1)->touch("po/ChangeLog");
543                 }
544         _system "aclocal",map((!$_ ? () : @$_),$Options{"aclocal_args"});
545         _system qw(libtoolize),@copy_arg if $Options{"want-libtoolize"};
546         _system qw(autoheader) if $Options{"want-autoheader"};
547         # "ChangeLog" is reqd by automake(1)
548         # Don't remove it afterwards as it may still be needed during automatic automake Makefile rebuilds
549         File::Touch->new("atime_only"=>1)->touch("ChangeLog") if !$Options{"ChangeLog"};
550         _system qw(automake --add-missing),@copy_arg;
551         _system qw(autoconf);
552         _writefile "| patch configure",<<'CONFIGURE_SUBST_X_EOF';
553 --- configure-orig      Wed Aug 20 12:10:37 2003
554 +++ configure   Wed Aug 20 13:22:51 2003
555 @@ -21590,6 +21590,11 @@
556    rm -f $tmp/stdin
557    if test x"$ac_file" != x-; then
558      mv $tmp/out $ac_file
559 +    for f in $ac_file_inputs; do
560 +      if test -x $f; then
561 +        chmod +x $ac_file
562 +      fi
563 +    done
564    else
565      cat $tmp/out
566      rm -f $tmp/out
567 CONFIGURE_SUBST_X_EOF
568         # Why it is left there after RedHat autoconf-2.53-8 ?
569         _remove "nocheck",\1,"autom4te-*.cache";
570
571         return if $Options{"ARGV_dist"};
572
573         # 'configure' defaults to CFLAGS '-g -O2' but our --enable-maintainer-mode
574         # should force '-ggdb3'
575         $ENV{"CFLAGS"}||="";
576         # shared/static switching cannot be based on maintainer-mode in configure
577         _system(qw(./configure --enable-maintainer-mode),
578                         (!$Options{"want-libtoolize"} ? () : qw(--enable-shared --disable-static)),
579                         map((!$_ ? () : @$_),$Options{"configure_args"}),
580                         );
581 }
582
583 1;
584 __END__
585
586 Tested with:
587         RedHat autoconf-2.53-8
588         RedHat automake-1.6.3-1
589         RedHat gettext-0.11.4-3
590         RedHat libtool-1.4.2-12
591         RedHat perl-5.8.0-48