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