1ebee4386c7d143741e3d269065a0a0202daa229
[macros.git] / AutoGen.pm
1 #! /usr/bin/perl
2
3 # $Id$
4 # autoautotools aware of CVS and rpm/deb.
5 # Copyright (C) 2002-2003 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  --copy      Behave exactly like in default mode but copy all instead of symlinks
66  --clean     Standard cleanup method
67  --fullclean Like clean but even the .cvsignore files are removed
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($origbase,$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 $origbase."-orig";
238                 # FIXME: Copy also dot-prefixed files!
239                 _move \1,$origbase."/*",$origbase."-orig/";
240                 rmdir $origbase or confess "rmdir $origbase: $!";
241                 my @ours;
242                 for my $glob ("$name-*.tar.gz") {
243                         @ours=glob $glob;
244                         confess "Invalid glob $glob: ".join(",",@ours) if 1!=@ours;
245                         }
246                 my($ourbase)=($ours[0]=~/^(.*)[.]tar[.]gz$/);
247                 _system "tar xzf ".$ours[0];
248                 # Use single-argument system() as we need shell redirection.
249                 # FIXME: Use directory-independent _cleanfiles(), not root-directory '.cvsignore'.
250                 #        "-X -" does not work, it needs to be stat(2)able file.
251                 _system "diff -ruP -X .cvsignore -I '".'[$]\(Id\|RCSfile\)\>.*[$]'."'"
252                                 ." $origbase-orig/ $ourbase/"
253                                 ." >"._rpmeval("_sourcedir")."/".$patch,
254                                 sub { $_[0]==0 || $_[0]==1; };  # diff(1) returns non-zero return code on any diffs.
255                 _remove \1,$ourbase,$origbase."-orig";
256                 }
257         _system(join(" ","rpmbuild",
258                         "-ba",
259                         "--rmsource",   # _remove _rpmeval("_sourcedir")."/$name-*.tar.gz";
260                         "--clean",      # _remove _rpmeval("_builddir")."/$name-VERSION";
261                         (!$args{"sign"} ? () : "--sign"),
262                         "$name.spec",
263                         ));
264         _system "make dist-tarZ" if $Options{"dist-tarZ"};
265         _move _rpmeval("_srcrpmdir")."/$name-*.src.rpm",".";
266         _move _rpmeval("_rpmdir")."/"._rpmeval("_target_cpu")."/$name-*."._rpmeval("_target_cpu").".rpm",".";
267         _system "ls -l $name-*";
268         exit 0; # should never return
269 }
270
271 # $args{
272 #       "sign"=>bool,
273 #       },
274 sub _debbuild
275 {
276 my($class,%args)=@_;
277
278         my $name=$Options{"name"};
279         $class->_prepdist($name);
280         _system "make distdir";
281         # Copy 'orig' archive after &_prepdist which would delete it.
282         my @origs;
283         my $base;
284         for my $glob ("orig-$name-*.tar.{gz,Z,bz2}") {
285                 @origs=glob $glob;
286                 if (@origs) {
287                         confess "Invalid glob $glob: ".join(",",@origs) if 1!=@origs;
288                         $origs[0]=~/^orig-([^-]+)-(.*)([.]tar[.][^.]+)$/;
289                         my $deborig="$1_$2.orig$3";
290                         $base="$1-$2";
291                         _copy $origs[0],$deborig;
292                         }
293                 }
294         my @subdirs;
295         for my $glob ("$name-*") {
296                 @subdirs=glob $glob;
297                 confess "Invalid glob $glob: ".join(",",@subdirs) if 1!=@subdirs;
298                 }
299         rename $subdirs[0],$base or confess "$!";
300         _system(join(" ","cd ".$base.";dpkg-buildpackage",
301                         "-rfakeroot",
302                         ($args{"sign"} ? () : ("-us","-uc")),
303                         ));
304         _remove \1,$base;
305         _system "ls -l ${name}*_[0-9]*";
306         exit 0; # should never return
307 }
308
309 # WARNING: doesn't respect %Options change!
310 my @_cleanfiles_cache;
311 sub _cleanfiles
312 {
313         # maintainer-clean hack is not safe, please list all files for 'rm'.
314         # When the filename doesn't contain '/', it is applied to ALL directories.
315         # Please note that files exactly in root dir MUST have ./ in the front
316         #   (to not to be considered as ALL-directories files).
317
318         if (!@_cleanfiles_cache) {
319                 @_cleanfiles_cache=map({
320                                                 local $_=$_;    # Prevent: Modification of a read-only value attempted
321                                                 s/\Q<name>\E/$Options{"name"}/ego;
322                                                 s#/+#/#g;
323                                                 # "*xyzzy" basename -> "*xyzzy",".*xyzzy" for proper cleaning
324                                                 (!m#^((?:.*/)?)([*][^/]*)$# ? ($_) : ("$1$2","$1.$2"));
325                                                 }
326                                 (
327                                 ".#*",  # Possible attempt to put comments in qw() list
328                                 qw(
329                                                 *~
330                                                 *.orig *.rej
331                                                 core
332                                                 Makefile Makefile.in
333                                                 TAGS tags ID
334                                                 .deps .libs
335                                                 *.[oa] *.l[oa] *.l[oa]T
336                                                 .cvsignore
337
338                                                 ./errs*
339                                                 ./intl
340                                                 ./configure ./configure.scan
341                                                 ./config.guess ./config.status ./config.sub ./config.log ./config.cache
342                                                 ./config.h ./config.h.in
343                                                 ./confdefs.h ./conftest* ./autoh[0-9]* ./confcache
344                                                 ./config.rpath
345                                                 ./depcomp
346                                                 ./compile
347                                                 ./stamp-h ./stamp-h.in ./stamp-h1
348                                                 ./install-sh
349                                                 ./aclocal.m4
350                                                 ./autom4te.cache ./autom4te-*.cache
351                                                 ./m4
352                                                 ./missing
353                                                 ./mkinstalldirs
354                                                 ./libtool ./ltconfig ./ltmain.sh
355                                                 ./ABOUT-NLS
356                                                 ./<name>-[0-9]* ./<name>-*-[0-9]*
357                                                 ./<name>.spec ./<name>.m4 ./<name>.spec.m4
358                                                 ./debian/tmp ./debian/<name>
359                                                 ./<name>*_[0-9]*
360                                                 ./macros/macros.dep
361                                                 ./macros/glade-w.sh
362                                                 ./po/Makefile.in.in ./po/POTFILES* ./po/cat-id-tbl.c ./po/cat-id-tbl.tmp
363                                                 ./po/*.gmo ./po/*.mo ./po/stamp-cat-id ./po/<name>.pot ./po/ChangeLog
364                                                 ./po/Makevars ./po/Makevars.template ./po/Rules-quot ./po/*.sed ./po/*.sin ./po/*.header
365                                                 ),
366                                 map(("./$_"),($Options{"ChangeLog"} || "ChangeLog")),
367                                 map((!$_ ? () : do { my $dir=$_; map("$dir/$_",qw(
368                                                 *.stamp
369                                                 sgml*
370                                                 tmpl*
371                                                 html*
372                                                 xml
373                                                 *.txt
374                                                 *.txt.bak
375                                                 *.new
376                                                 *.sgml
377                                                 *.args
378                                                 *.hierarchy
379                                                 *.signals
380                                                 *.interfaces
381                                                 *.prerequisites
382                                                 )); }),$Options{"gtk-doc-dir"}),
383                                 map((!$_ ? () : do { my $dir=$_; map("$dir/$_",qw(
384                                                 *.html
385                                                 *.info*
386                                                 *.txt
387                                                 *.tex
388                                                 *.sgml
389                                                 )); }),$Options{"docbook-lite-dir"}),
390                                 map((!$_ ? () : @$_),$Options{"clean"}),
391                                 ));
392                 # sanity check
393                 for (@_cleanfiles_cache) {
394                                 confess "dir-specific 'clean'-pattern must start with './': $_" if m#^(?!\Q./\E).*/#;
395                                 };
396                 }
397         return @_cleanfiles_cache;
398 }
399
400 sub _cleanfilesfordir
401 {
402 my($dir)=@_;
403
404         return map({
405                            if (m#^\Q$dir\E/([^/]+)$#) { # this-dir: "./this-dir/file-name.c"
406                                         ($1);
407                                         }
408                         elsif (m#^[^/]+$#) {    # all-dirs: "file-name.c"; the same as "./*/file-name.c"
409                                         ($&);
410                                         }
411                         elsif (do {     # all-subdirs: "./parent-of-this-dir/*/file-name.c"
412                                                         m#/[*]/([^/]+)$#;
413                                                         ($_=$1) && $dir=~m#^\Q$`\E(?:/|$)#;
414                                                         }) {
415                                         ($_);
416                                         }
417                         else {
418                                         ();
419                                         }
420                         } _cleanfiles());
421 }
422
423 sub _cvsdirs
424 {
425 my(@startdirs)=@_;
426
427         my @r=();
428         my @todo=(@startdirs);
429         while (defined(my $dir=shift @todo)) {
430                 local *ENTRIES;
431                 my $entries_filename="$dir/CVS/Entries";
432                 open ENTRIES,$entries_filename or (cluck "open \"$entries_filename\": $!" and next);
433                 push @r,$dir;
434                 local $/="\n";
435                 my %local=();
436                 local $_;
437                 while (<ENTRIES>) {
438                         chomp;
439                         next if !m#^D/([^/]+)/#;
440                         $local{$1}=1;
441                         }
442                 close ENTRIES or cluck "close \"$entries_filename\": $!";
443                 if (-e (my $entries_log_filename=$dir."/CVS/Entries.Log")) {
444                         local *ENTRIES_LOG;
445                         if (open ENTRIES_LOG,$entries_log_filename or cluck "open \"$entries_log_filename\": $!") {
446                                 local $_;
447                                 while (<ENTRIES_LOG>) {
448                                         chomp;
449                                                  if (m#^A D/([^/]*)/#) {
450                                                 $local{$1}=1;
451                                                 }
452                                         elsif (m#^R D/([^/]*)/#) {
453                                                 delete $local{$1};
454                                                 }
455                                         else {
456                                                 cluck "$entries_log_filename: Unrecognized line $.: $_";
457                                                 }
458                                         }
459                                 close ENTRIES_LOG or cluck "close \"$entries_log_filename\": $!";
460                                 }
461                         }
462                 push @todo,map(("$dir/$_"),keys(%local));
463                 }
464         return @r;
465 }
466
467 sub _expandclass
468 {
469 my($patt)=@_;
470
471         return $patt if $patt!~/\Q[\E(.*?)\Q]\E/;
472         my($pre,$range,$post)=($`,$1,$');       # FIXME: local($`,$1,$') doesn't work - why?
473         1 while $range=~s#(.)-(.)# join("",map(chr,(ord($1)..ord($2))));
474                         #ge;
475         return map({ _expandclass("$pre$_$post"); } split("",$range));
476 }
477
478 sub run
479 {
480 my($class,%options)=@_;
481
482         local %Options=%options;
483         do { require $_ if -e; } for (home()."/.".$Options{"name"}.".autogen.pl");
484         do { $$_=1 if !defined($$_) && fgrep { /^\s*AUTOMAKE_OPTIONS\s*=[^#]*\bdist-tarZ\b/m; } "Makefile.am"; }
485                         for (\$Options{"dist-tarZ"});
486         Getopt::Long::Configure('noignorecase','prefix_pattern=(--|-|\+|)');
487         local @ARGV=@{$Options{"ARGV"}};
488         print _help() and confess if !GetOptions(
489                           "rpm"      ,sub { $class->_rpmbuild("sign"=>1); },
490                           "rpmtest"  ,sub { $class->_rpmbuild("sign"=>0); },
491                           "deb"      ,sub { $class->_debbuild("sign"=>1); },
492                           "debtest"  ,sub { $class->_debbuild("sign"=>0); },
493                           "cleanfilesfordir=s",sub { print "$_\n" for (_cleanfilesfordir $_[1]); exit 0; },
494                           "dist"     ,\$Options{"ARGV_dist"},
495                           "copy!"    ,\$Options{"ARGV_copy"},
496                           "clean"    ,\$Options{"ARGV_clean"},
497                           "fullclean",\$Options{"ARGV_fullclean"},
498                         "h|help"     ,sub { print _help(); exit 0; },
499                         $Options{"GetOptions_args"},
500                         ) || @ARGV;
501
502         for my $subdir (map((!$_ ? () : @$_),$Options{"subdirs"})) {
503                 local $CWD=$subdir;
504                 _system "./autogen.pl",@{$Options{"ARGV"}},"--dist";    # use "--dist" just as fallback!
505                 }
506
507         for my $dir (_cvsdirs(".")) {
508                 my @cleanfilesfordir=_cleanfilesfordir $dir;
509                 _writefile $dir."/.cvsignore",map("$_\n",@cleanfilesfordir) if !$Options{"ARGV_fullclean"};
510                 _remove "nocheck",\1,map({ _expandclass("$dir/$_"); } grep({
511                                 $Options{"ARGV_fullclean"} or $_ ne ".cvsignore";
512                                 } @cleanfilesfordir));
513                 }
514         return if $Options{"ARGV_clean"} || $Options{"ARGV_fullclean"};
515
516         $Options{"aclocal_args"}=[qw(-I macros),map((!$_ ? () : @$_),$Options{"aclocal_args"})];
517         my $configure_name;
518         do { $configure_name||=$_ if -f $_ } for ("configure.in");
519         do { $configure_name||=$_ if -f $_ } for ("configure.ac");
520         $configure_name or confess "Cannot find configure.{in,ac}";
521         my $configure_in=_readfile($configure_name);
522         do { $$_=1 if !defined($$_) && $configure_in=~/^\s*AM_GNU_GETTEXT\b/m; }
523                         for (\$Options{"want-gettextize"});
524         do { $$_=1 if !defined($$_) && $configure_in=~/^\s*AM_GLIB_GNU_GETTEXT\b/m; }
525                         for (\$Options{"want-glib-gettextize"});
526         do { $$_=1 if !defined($$_) && $configure_in=~/^\s*AM_PROG_LIBTOOL\b/m; }
527                         for (\$Options{"want-libtoolize"}); 
528         do { $$_=1 if !defined($$_) && $configure_in=~/^\s*A[CM]_CONFIG_HEADER\b/m; }
529                         for (\$Options{"want-autoheader"});
530         my @copy_arg=(!$Options{"ARGV_copy"} ? () : "--copy");
531
532         do { &$_ if $_; } for ($Options{"prep"});
533         touch "po/POTFILES.in" if -d "po";
534         if ($Options{"want-gettextize"}) {
535                 # don't use multi-arg system() here as it would reject "</dev/null" redirection etc.
536                 for ("expect -c '"
537                                 .'spawn gettextize --intl --no-changelog '.join(" ",@copy_arg).';'
538                                 .'expect -timeout -1 "Press Return to acknowledge" {send "\r";exp_continue;} eof;'
539                                 ."'") {
540                         _system $_ and confess $_;
541                         }
542                 for ($configure_name,"Makefile.am") {
543                         STDERR->printflush("gettextize recovery rename \"$_~\"->\"$_\"... ");
544                         rename "$_~","$_" or confess "$!";
545                         STDERR->printflush("ok\n");
546                         }
547                 if (!-e "po/Makevars") {
548                         my $Makevars_template="po/Makevars.template";
549                         my $makevars=_readfile $Makevars_template;
550                         $makevars=~s/^(COPYRIGHT_HOLDER)\b.*$/"$1=".$Options{"COPYRIGHT_HOLDER"}/meg
551                                         or confess "COPYRIGHT_HOLDER not found in $Makevars_template";
552                         _writefile "po/Makevars",$makevars;
553                         }
554                 # Prevent updating of contents during touch of any source file;
555                 # change the .po contents only when some data get updated
556                 for my $Makefile_in_in ("po/Makefile.in.in") {
557                         my $file=_readfile $Makefile_in_in;
558                         $file=~s%(\$\Q(MSGMERGE_UPDATE)\E) (\$\$\Q{lang}.po \E\$\Q(DOMAIN).pot\E)$%
559                                         $1.q< --backup=simple --suffix="~" >.$2.q<;>
560                                                         .q< if test `diff -u $${lang}.po~ $${lang}.po>
561                                                                                         .q< | sed>
562                                                                                                         .q< -e '1,/^@@.*@@$$/d'>
563                                                                                                         .q< -e '/^[+-]"POT-Creation-Date:/d'>
564                                                                                                         .q< -e '/^[^+-]/d'>
565                                                                                                         .q< -e '/^[+-]#/d'>
566                                                                                         .q< | wc -l` -eq 0;then>
567                                                                         .q< touch --reference=$${lang}.po $${lang}.po~;>
568                                                                                         .q< mv -f $${lang}.po~ $${lang}.po;>
569                                                         .q< else>
570                                                                         .q< rm -f $${lang}.po~;>
571                                                         .q< fi>
572                                         %me or confess;
573                         unlink $Makefile_in_in or confess "$!";
574                         _writefile $Makefile_in_in,$file;
575                         }
576                 }
577         if ($Options{"want-glib-gettextize"}) {
578                 _system "glib-gettextize",@copy_arg;
579                 # "po/ChangeLog" is somehow missing at this point
580                 File::Touch->new("atime_only"=>1)->touch("po/ChangeLog");
581                 }
582         _system "aclocal",map((!$_ ? () : @$_),$Options{"aclocal_args"});
583         _system qw(libtoolize),@copy_arg if $Options{"want-libtoolize"};
584         _system qw(autoheader) if $Options{"want-autoheader"};
585         # "ChangeLog" is reqd by automake(1)
586         # Don't remove it afterwards as it may still be needed during automatic automake Makefile rebuilds
587         File::Touch->new("atime_only"=>1)->touch("ChangeLog") if !$Options{"ChangeLog"};
588         _system qw(automake --add-missing),@copy_arg;
589         _system qw(autoconf);
590         _writefile "| patch configure",<<'CONFIGURE_SUBST_X_EOF';
591 --- configure-orig      Wed Aug 20 12:10:37 2003
592 +++ configure   Wed Aug 20 13:22:51 2003
593 @@ -21590,6 +21590,11 @@
594    rm -f $tmp/stdin
595    if test x"$ac_file" != x-; then
596      mv $tmp/out $ac_file
597 +    for f in $ac_file_inputs; do
598 +      if test -x $f; then
599 +        chmod +x $ac_file
600 +      fi
601 +    done
602    else
603      cat $tmp/out
604      rm -f $tmp/out
605 CONFIGURE_SUBST_X_EOF
606         _remove "nocheck","./configure.orig";   # It is usually produced by 'CONFIGURE_SUBST_X'.
607         # Why it is left there after RedHat autoconf-2.53-8 ?
608         _remove "nocheck",\1,"autom4te-*.cache";
609
610         return if $Options{"ARGV_dist"};
611
612         # 'configure' defaults to CFLAGS '-g -O2' but our --enable-maintainer-mode
613         # should force '-ggdb3'
614         $ENV{"CFLAGS"}||="";
615         # shared/static switching cannot be based on maintainer-mode in configure
616         _system(qw(./configure --enable-maintainer-mode),
617                         (!$Options{"want-libtoolize"} ? () : qw(--enable-shared --disable-static)),
618                         map((!$_ ? () : @$_),$Options{"configure_args"}),
619                         );
620 }
621
622 1;
623 __END__
624
625 =head1 NAME
626
627 AutoGen - autoautotools aware of CVS and rpm/deb
628
629
630 =head1 SYNOPSIS
631
632  use lib "./macros/";
633  use AutoGen;
634  AutoGen->run(
635                 "name"=>"fooproject",
636                 "COPYRIGHT_HOLDER"=>'Joe <joe@com>',
637                 "ARGV"=>\@ARGV,
638                 );
639
640
641 =head1 ABSTRACT
642
643 Projects usually have their B<autogen.sh> script files to run B<autoconf>(1),
644 B<automake>(1) and similiar tools. This project has some additional features:
645
646 =over
647
648 =item
649
650 Clean the checkout directory without B<Makefile>s for 'make clean'.
651
652 =item
653
654 Maintain B<.cvsignore> files containing the files being cleaned.
655
656 =item
657
658 Single-command package building of B<.rpm>/B<.deb> out of CVS checkout.
659
660 =item
661
662 Supports: B<gettext>, B<glib-gettext>, B<libtool>, B<autoconf>, B<automake>.
663
664 =back
665
666
667 =head1 OPTIONS
668
669 B<AutoGen> module itself parses its command-line arguments from B<"ARGV"> field
670 of the hash passed to B<&AutoGen->run>. Its initial double-dash ('B<-->')
671 prefixes can be omitted.
672
673 B<AutoGen> will build the sources for development purposes in the current
674 directory if no other packaging options were given.
675
676 =over
677
678 =item B<--rpm>
679
680 Build B<.rpm> packages. Either you need access to directory B</usr/src/redhat/>
681 (or B</usr/src/packages/> etc.) or you should set B<%_usrsrc> (default
682 B</usr/src/>) elsewhere in your B<$HOME/.rpmmacros>:
683         %_usrsrc /home/joe/src
684
685 As the resulting package will be digitally signed you should also set signing
686 properties in your B<$HOME/.rpmmacros>:
687         %_signature gpg
688         %_gpg_name  Joe <joe@com>
689
690 =item B<--rpmtest>
691
692 The same as B<--rpm> but the resulting package will not be I<GnuPG> digitally
693 signed. I<GnuPG> passphrase is requested in the middle of package building
694 which would be very discomfortable during project development.
695
696 =item B<--deb>
697
698 Build B<.deb> packages.
699
700 =item B<--debtest>
701
702 The same as B<--deb> but the resulting package will not be I<GnuPG> digitally
703 signed. I<GnuPG> passphrase is requested in the middle of package building
704 which would be very discomfortable during project development.
705
706 =item B<--dist>
707
708 Prepare all build files but do not run the final B<./configure>. The resulting
709 directory is similiar to the one produced by B<make dist> but DO NOT
710 INTERCHANGE THEM!
711
712 =item B<--copy>
713
714 Some distribution files are created just as symlinks to the system ones by
715 default. This option forces their copy such as B<make dist> does.
716
717 =item B<--clean>
718
719 Clean all files not belonging to the CVS repository. You SHOULD backup your
720 directory first during B<AutoGen> bootstrap. Only B<.cvsignore> files are
721 left in our directory tree.
722
723 =item B<--fullclean>
724
725 Similiar to B<--clean> option but even B<.cvsignore> files get deleted.
726
727 =item B<-h|--help>
728
729 Print short help message describing these I<OPTIONS>.
730
731 =back
732
733
734 =head1 CONFIGURATION
735
736 B<&AutoGen->run> method is passed configuration hash by your B<autogen.pl>.
737 Its possible fields:
738
739 =over
740
741 =item B<name>
742
743 Project basename - it should contain no special characters.
744
745
746 =item B<ARGV>
747
748 Pass here B<\@ARGV> from the user.
749
750
751 =item B<clean>
752
753 Array specifying files to be cleaned during B<./autogen.pl clean> and put into
754 B<.cvsignore> files. You still should add these entries also to B<CLEANFILES>,
755 B<DISTCLEANFILES> or B<MAINTAINERCLEANFILES> variables of B<Makefile.am>s.
756
757 There are several formats of B<clean> field possible entries:
758
759 =over
760
761 =item B<./path/to/file.c>
762
763 Full project-basedir relative path to the deleted file. Rule applies only to
764 the one specified directory. Although B<path/to/file.c> would be also possible
765 it is not recommended to have unified format with B<./only_basedir.c> entries
766 to delete file just in the root directory (as B<only_basedir.c> would delete
767 it in ALL subdirectories incl. the root one).
768
769 =item B<basename.c>
770
771 Delete B<basename_generated.c> found in any subdirectory of the project.
772 It has the same effect as B<./*/basename_generated.c> entry.
773
774 =item B<./subdir/*/name.c>
775
776 Delete B<name.c> in B<./subdir> and all of its subdirector descendants.
777 Entry B<subdir/*/name.c> would have the same effect.
778
779 =back
780
781
782 =item B<prep>
783
784 B<CODE> reference run to prepare the sources being built in the current
785 directory (if no packaging options given). Check for needed B<autotools>
786 versions required to build B<configure> script by
787 B<AutoGen->checkcommandversion>. Other version checks belong to B<configure.ac>
788 instead.
789
790 Referenced B<CODE> must return true value.
791
792
793 =item B<ChangeLog>
794
795 Alternative name of B<ChangeLog>, defaults to "B<ChangeLog>". You should define
796 alternative name if patching existing package with its own B<ChangeLog>.
797
798
799 =item B<gtk-doc-dir>
800
801 Optional directory name where B<gtkdocize>(1) generated files reside.
802
803
804 =back
805
806
807 =head1 FUNCTIONS
808
809 =over
810
811 =item B<AutoGen->checkcommandversion>(B<$command>,B<$minimal_version>)
812
813 Functions runs B<$command --version> and checks the resulting version number
814 against given B<$minimal_version>. Currently only the first 2 version numbers
815 are parsed.
816
817
818 =back
819
820
821 =head1 PATCHED PACKAGES
822
823 This section applies to projects where you patch foreign existing packages.
824
825 =over
826
827 =item
828
829 Use the following alternate B<autogen.pl> prolog if your branch does not belong
830 to the B<MAIN> CVS branch:
831  BEGIN {
832         # 'macros' could got checked out empty by our '-r captive' tag.
833         if (!-f "./macros/AutoGen.pm") {
834                 do { system $_ and die "$_: $!"; } for ("cvs co -A macros");
835                 }
836         }
837  use lib "./macros/";
838  use AutoGen;
839
840 =item
841
842 Put B<fooproject-1.2.3.tar.gz> archive to the project root directory
843 as B<orig-fooproject-1.2.3.tar.gz>.
844
845 =item
846
847 Set B<$VERSION> in B<configure.ac> file with you vendor prefix such as
848 B<1.2.3joe1>. Set B<$VERSION_BASE> to B<1.2.3> and B<$VERSION_EXT> to B<joe1>.
849 B<AC_SUBST>() them both.
850
851 =item B<.spec> file changes
852
853 =over
854
855 =item
856
857 Change B<Version: @VERSION@> to B<Version: @VERSION_BASE@>.
858
859 =item
860
861 Change (expected) line B<Release: 1> to B<Release: 1@VERSION_EXT@>.
862
863 =item
864
865 Change B<Source: ...@VERSION@.tar.gz> to B<Source: ...@VERSION_BASE@.tar.gz>.
866
867 =item
868
869 Add line B<Patch1: @PACKAGE@-@VERSION_BASE@-@VERSION_EXT@.patch>.
870 This patch file name is not mandatory.
871
872 =item
873
874 Remember to call B<autotools> commands manually in the B<%build>
875 section if their source files were modified in your vendor branch.
876
877 =back
878
879 =item B<debian>-specific changes
880
881 =over
882
883 =item
884
885 Include both B<debian/changelog.in> and B<debian/changelog> to B<Makefile.am>.
886
887 =item
888
889 Use B<@VERSION_BASE@> in B<debian/changelog.in>.
890
891 =back
892
893 =back
894
895 =head1 AUTHOR
896
897 Jan Kratochvil <B<project-macros@jankratochvil.net>>,
898                 I<http://www.jankratochvil.net/>