4 # Module to generate all the initial makefiles etc.
5 # Copyright (C) 2002 Jan Kratochvil <project-macros@jankratochvil.net>
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
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.
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
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; };
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);
42 eval "$_\n; 1;" or push @missing,(/^\s*use\s+([^ ;]+)/)[0];
44 die "You are missing some modules - install them by:\n"
45 ."\tperl -MCPAN -e 'install qw(".join(" ",@missing).")'\n"
54 Beware: '.basename($0).' is a tool only for maintainers!
57 --rpm Build RPM packages locally (needs /usr/src/(redhat|packages)/ access)
58 --rpmtest Build RPM like "rpm" but w/o gpg/pgp signing
59 --clean Standard cleanup method
60 --fullclean Like clean but even the .cvsignore files are removed
61 --copy Behave exactly like in default mode but copy all instead of symlinks
62 -h|--help Print this help message.
63 '.($Options{"help"} || "");
66 sub checkcommandversion
68 my($class,$command,$version)=@_;
71 do { open F,$_ or confess "Open $_: $!"; } for ("$command --version|");
76 my $command_version=($command_out=~m#([\d.]+)#)[0];
77 confess "$command(1) version not found in its output" if !$command_version;
78 confess "'$command' version $version or higher required"
79 # Do not take 3rd+ numbers as it would not be a number
80 if ($command_version=~/^(\d+[.]\d+)/)[0]<$version;
89 open F,$filename or confess "Open \"$filename\": $!";
91 close F or cluck "Close \"$filename\": $!";
97 my($filename,@content)=@_;
100 open F,">".$filename or confess "rewrite \"$filename\": $!";
102 close F or cluck "close \"$filename\": $!";
112 my $nameref=\$_rpmeval_cache{$name};
113 $$nameref=_readfile('rpm --eval %'.$name.'|') if !defined $$nameref;
117 return @r if wantarray();
118 confess "Scalar return for ".scalar(@r)." values" if 1!=@r;
126 system(@args) and confess join(" ",@args).": $?=".join(",",
127 (!WIFEXITED($?) ? () : ("EXITSTATUS(".WEXITSTATUS($?).")")),
128 (!WIFSIGNALED($?) ? () : ("TERMSIG(" .WTERMSIG($?) .")")),
129 (!WIFSTOPPED($?) ? () : ("STOPSIG(" .WSTOPSIG($?) .")")),
133 # Assumed wildcard pattern expansion to exactly one item if !$nocheck
138 my $nocheck=shift @files if $files[0] eq "nocheck";
140 # expand pattern to properly match © resulting filenames count
141 @files=map({ glob $_; } @files);
142 @files==copy @files,$dest or $nocheck or confess "$!";
145 # Assumed wildcard pattern expansion to exactly one item if !$nocheck
150 my $nocheck=shift @files if $files[0] eq "nocheck";
151 my $flag=shift @files if ref $files[0];
152 # expand pattern to properly match &remove resulting filenames count
153 @files=map({ glob $_; } @files);
154 @files==remove((!$flag ? () : $flag),@files) or $nocheck or confess "$!";
157 # FIXME: File::NCopy exists but File::NMove doesn't
171 my($specsrc)=map((-e $_ ? $_ : "$name.spec.in"),"$name.spec.m4.in");
172 my $spec=_readfile $specsrc;
174 my $configure_args=($spec=~/^[%]configure\b[ \t]*(.*)$/m)[0];
175 $configure_args=~s/--disable-gtk-doc\b/--enable-gtk-doc/g; # optional; gtk-doc reqd for 'make dist'
176 $class->run(%Options,
177 "ARGV"=>[qw(--copy)],
178 "configure_args"=>[split /\s+/,$configure_args],
180 _remove $Options{"ChangeLog"} || "ChangeLog"; # force its rebuild by Makefile/rcs2log
181 _system "make dist $name.spec";
191 my $name=$Options{"name"};
192 _remove "nocheck",\1,
193 _rpmeval("_tmppath" )."/$name-*-root",
194 _rpmeval("_builddir")."/$name-*";
195 $class->_prepdist($name);
196 _copy "$name-*.tar.gz",_rpmeval("_sourcedir");
197 _system(join(" ","rpmbuild",
199 "--rmsource", # _remove _rpmeval("_sourcedir")."/$name-*.tar.gz";
200 "--clean", # _remove _rpmeval("_builddir")."/$name-VERSION";
201 (!$args{"sign"} ? () : "--sign"),
204 _system "make dist-tarZ" if $Options{"dist-tarZ"};
205 _move _rpmeval("_srcrpmdir")."/$name-*.src.rpm",".";
206 _move _rpmeval("_rpmdir")."/"._rpmeval("_target_cpu")."/$name-*."._rpmeval("_target_cpu").".rpm",".";
207 _system "ls -l $name-*";
208 exit 0; # should never return
218 my $name=$Options{"name"};
219 $class->_prepdist($name);
220 _system "tar xzf $name-*.tar.gz";
221 _remove "$name-*.tar.gz"; # permit "cd $name-*" below
222 _system(join(" ","cd $name-*;dpkg-buildpackage",
224 ($args{"sign"} ? () : ("-us","-uc")),
226 _remove \1,"$name-*";
227 _system "ls -l ${name}_*";
228 exit 0; # should never return
231 # WARNING: doesn't respect %Options change!
232 my @_cleanfiles_cache;
235 # maintainer-clean hack is not safe, please list all files for 'rm'.
236 # When the filename doesn't contain '/', it is applied to ALL directories.
237 # Please note that files exactly in root dir MUST have ./ in the front
238 # (to not to be considered as ALL-directories files).
240 if (!@_cleanfiles_cache) {
241 @_cleanfiles_cache=map({
242 local $_=$_; # Prevent: Modification of a read-only value attempted
243 s/\Q<name>\E/$Options{"name"}/ego;
245 # "*xyzzy" basename -> "*xyzzy",".*xyzzy" for proper cleaning
246 (!m#^((?:.*/)?)([*][^/]*)$# ? ($_) : ("$1$2","$1.$2"));
249 ".#*", # Possible attempt to put comments in qw() list
257 *.[oa] *.l[oa] *.l[oa]T
262 ./configure ./configure.scan
263 ./config.guess ./config.status ./config.sub ./config.log ./config.cache
264 ./config.h ./config.h.in
265 ./confdefs.h ./conftest* ./autoh[0-9]* ./confcache
269 ./stamp-h ./stamp-h.in ./stamp-h1
272 ./autom4te.cache ./autom4te-*.cache
276 ./libtool ./ltconfig ./ltmain.sh
278 ./<name>-[0-9]* ./<name>-devel-[0-9]*
279 ./<name>.spec ./<name>.m4 ./<name>.spec.m4
280 ./debian/tmp ./debian/<name>
283 ./po/Makefile.in.in ./po/POTFILES* ./po/cat-id-tbl.c ./po/cat-id-tbl.tmp
284 ./po/*.gmo ./po/*.mo ./po/stamp-cat-id ./po/<name>.pot ./po/ChangeLog
285 ./po/Makevars ./po/Makevars.template ./po/Rules-quot ./po/*.sed ./po/*.sin ./po/*.header
287 map(("./$_"),($Options{"ChangeLog"} || "ChangeLog")),
288 map((!$_ ? () : do { my $dir=$_; map("$dir/$_",qw(
303 )); }),$Options{"gtk-doc-dir"}),
304 map((!$_ ? () : do { my $dir=$_; map("$dir/$_",qw(
310 )); }),$Options{"docbook-lite-dir"}),
311 map((!$_ ? () : @$_),$Options{"clean"}),
314 for (@_cleanfiles_cache) {
315 confess "dir-specific 'clean'-pattern must start with './': $_" if m#^(?!\Q./\E).*/#;
318 return @_cleanfiles_cache;
321 sub _cleanfilesfordir
326 if (m#^\Q$dir\E/([^/]+)$#) { # this-dir: "./this-dir/file-name.c"
329 elsif (m#^[^/]+$#) { # all-dirs: "file-name.c"; the same as "./*/file-name.c"
332 elsif (do { # all-subdirs: "./parent-of-this-dir/*/file-name.c"
334 ($_=$1) && $dir=~m#^\Q$`\E(?:/|$)#;
349 my @todo=(@startdirs);
350 while (defined(my $dir=shift @todo)) {
352 my $entries_filename="$dir/CVS/Entries";
353 open ENTRIES,$entries_filename or (cluck "open \"$entries_filename\": $!" and next);
360 next if !m#^D/([^/]+)/#;
363 close ENTRIES or cluck "close \"$entries_filename\": $!";
364 if (-e (my $entries_log_filename=$dir."/CVS/Entries.Log")) {
366 if (open ENTRIES_LOG,$entries_log_filename or cluck "open \"$entries_log_filename\": $!") {
368 while (<ENTRIES_LOG>) {
370 if (m#^A D/([^/]*)/#) {
373 elsif (m#^R D/([^/]*)/#) {
377 cluck "$entries_log_filename: Unrecognized line $.: $_";
380 close ENTRIES_LOG or cluck "close \"$entries_log_filename\": $!";
383 push @todo,map(("$dir/$_"),keys(%local));
392 return $patt if $patt!~/\Q[\E(.*?)\Q]\E/;
393 my($pre,$range,$post)=($`,$1,$'); # FIXME: local($`,$1,$') doesn't work - why?
394 1 while $range=~s#(.)-(.)# join("",map(chr,(ord($1)..ord($2))));
396 return map({ _expandclass("$pre$_$post"); } split("",$range));
401 my($class,%options)=@_;
403 local %Options=%options;
404 do { require $_ if -e; } for (home()."/.".$Options{"name"}.".autogen.pl");
405 do { $$_=1 if !defined($$_) && fgrep { /^\s*AUTOMAKE_OPTIONS\s*=[^#]*\bdist-tarZ\b/m; } "Makefile.am"; }
406 for (\$Options{"dist-tarZ"});
407 Getopt::Long::Configure('noignorecase','prefix_pattern=(--|-|\+|)');
408 local @ARGV=@{$Options{"ARGV"}};
409 print _help() and confess if !GetOptions(
410 "rpm" ,sub { $class->_rpmbuild("sign"=>1); },
411 "rpmtest" ,sub { $class->_rpmbuild("sign"=>0); },
412 "deb" ,sub { $class->_debbuild("sign"=>1); },
413 "debtest" ,sub { $class->_debbuild("sign"=>0); },
414 "dist" ,\$Options{"ARGV_dist"},
415 "copy!" ,\$Options{"ARGV_copy"},
416 "fullclean",\$Options{"ARGV_fullclean"},
417 "clean" ,\$Options{"ARGV_clean"},
418 "h|help" ,sub { print _help(); exit 0; },
419 $Options{"GetOptions_args"},
422 for my $subdir (map((!$_ ? () : @$_),$Options{"subdirs"})) {
424 _system "./autogen.pl",@{$Options{"ARGV"}},"--dist"; # use "--dist" just as fallback!
427 for my $dir (_cvsdirs(".")) {
428 my @cleanfilesfordir=_cleanfilesfordir $dir;
429 _writefile $dir."/.cvsignore",map("$_\n",@cleanfilesfordir) if !$Options{"ARGV_fullclean"};
430 _remove "nocheck",\1,map({ _expandclass("$dir/$_"); } grep({
431 $Options{"ARGV_fullclean"} or $_ ne ".cvsignore";
432 } @cleanfilesfordir));
434 return if $Options{"ARGV_clean"} || $Options{"ARGV_fullclean"};
436 $Options{"aclocal_args"}=[qw(-I macros),map((!$_ ? () : @$_),$Options{"aclocal_args"})];
437 my $configure_in=_readfile("configure.in");
438 do { $$_=1 if !defined($$_) && $configure_in=~/^AM_GNU_GETTEXT\b/m; }
439 for (\$Options{"want-gettextize"});
440 do { $$_=1 if !defined($$_) && $configure_in=~/^AM_GLIB_GNU_GETTEXT\b/m; }
441 for (\$Options{"want-glib-gettextize"});
442 do { $$_=1 if !defined($$_) && $configure_in=~/^AM_PROG_LIBTOOL\b/m; }
443 for (\$Options{"want-libtoolize"});
444 do { $$_=1 if !defined($$_) && $configure_in=~/^A[CM]_CONFIG_HEADER\b/m; }
445 for (\$Options{"want-autoheader"});
446 my @copy_arg=(!$Options{"ARGV_copy"} ? () : "--copy");
448 do { &$_ if $_; } for ($Options{"prep"});
449 touch "po/POTFILES.in" if -d "po";
450 if ($Options{"want-gettextize"}) {
451 # don't use multi-arg system() here as it would reject "</dev/null" redirection etc.
453 .'spawn gettextize --intl --no-changelog '.join(" ",@copy_arg).';'
454 .'expect -timeout -1 "Press Return to acknowledge" {send "\r";exp_continue;} eof;'
456 _system $_ and confess $_;
458 for ("configure.in","Makefile.am") {
459 STDERR->printflush("gettextize recovery rename \"$_~\"->\"$_\"... ");
460 rename "$_~","$_" or confess "$!";
461 STDERR->printflush("ok\n");
463 if (!-e "po/Makevars") {
464 my $Makevars_template="po/Makevars.template";
465 my $makevars=_readfile $Makevars_template;
466 $makevars=~s/^(COPYRIGHT_HOLDER)\b.*$/"$1=".$Options{"COPYRIGHT_HOLDER"}/meg
467 or confess "COPYRIGHT_HOLDER not found in $Makevars_template";
468 _writefile "po/Makevars",$makevars;
470 # Prevent updating of contents during touch of any source file;
471 # change the .po contents only when some data get updated
472 for my $Makefile_in_in ("po/Makefile.in.in") {
473 my $file=_readfile $Makefile_in_in;
474 $file=~s%(\$\Q(MSGMERGE_UPDATE)\E) (\$\$\Q{lang}.po \E\$\Q(DOMAIN).pot\E)$%
475 $1.q< --backup=simple --suffix="~" >.$2.q<;>
476 .q< if test `diff -u $${lang}.po~ $${lang}.po>
478 .q< -e '1,/^@@.*@@$$/d'>
479 .q< -e '/^[+-]"POT-Creation-Date:/d'>
482 .q< | wc -l` -eq 0;then>
483 .q< touch --reference=$${lang}.po $${lang}.po~;>
484 .q< mv -f $${lang}.po~ $${lang}.po;>
486 .q< rm -f $${lang}.po~;>
489 unlink $Makefile_in_in or confess "$!";
490 _writefile $Makefile_in_in,$file;
493 if ($Options{"want-glib-gettextize"}) {
494 _system "glib-gettextize",@copy_arg;
495 # "po/ChangeLog" is somehow missing at this point
496 File::Touch->new("atime_only"=>1)->touch("po/ChangeLog");
498 _system "aclocal",map((!$_ ? () : @$_),$Options{"aclocal_args"});
499 _system qw(libtoolize),@copy_arg if $Options{"want-libtoolize"};
500 _system qw(autoheader) if $Options{"want-autoheader"};
501 # "ChangeLog" is reqd by automake(1)
502 # Don't remove it afterwards as it may still be needed during automatic automake Makefile rebuilds
503 File::Touch->new("atime_only"=>1)->touch("ChangeLog") if !$Options{"ChangeLog"};
504 _system qw(automake --add-missing),@copy_arg;
505 _system qw(autoconf);
506 # Why it is left there after RedHat autoconf-2.53-8 ?
507 _remove "nocheck",\1,"autom4te-*.cache";
509 return if $Options{"ARGV_dist"};
511 # 'configure' defaults to CFLAGS '-g -O2' but our --enable-maintainer-mode
512 # should force '-ggdb3'
514 # shared/static switching cannot be based on maintainer-mode in configure
515 _system(qw(./configure --enable-maintainer-mode),
516 (!$Options{"want-libtoolize"} ? () : qw(--enable-shared --disable-static)),
517 map((!$_ ? () : @$_),$Options{"configure_args"}),
525 RedHat autoconf-2.53-8
526 RedHat automake-1.6.3-1
527 RedHat gettext-0.11.4-3
528 RedHat libtool-1.4.2-12