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