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