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+([^\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"} || "");
72 open F,$filename or confess "Open \"$filename\": $!";
74 close F or cluck "Close \"$filename\": $!";
80 my($filename,@content)=@_;
83 open F,">".$filename or confess "rewrite \"$filename\": $!";
85 close F or cluck "close \"$filename\": $!";
95 my $nameref=\$_rpmeval_cache{$name};
96 $$nameref=_readfile('rpm --eval %'.$name.'|') if !defined $$nameref;
100 return @r if wantarray();
101 confess "Scalar return for ".scalar(@r)." values" if 1!=@r;
109 system(@args) and confess join(" ",@args).": $?=".join(",",
110 (!WIFEXITED($?) ? () : ("EXITSTATUS(".WEXITSTATUS($?).")")),
111 (!WIFSIGNALED($?) ? () : ("TERMSIG(" .WTERMSIG($?) .")")),
112 (!WIFSTOPPED($?) ? () : ("STOPSIG(" .WSTOPSIG($?) .")")),
116 # Assumed wildcard pattern expansion to exactly one item if !$nocheck
121 my $nocheck=shift @files if $files[0] eq "nocheck";
123 @files==copy @files,$dest or $nocheck or confess "$!";
126 # Assumed wildcard pattern expansion to exactly one item if !$nocheck
131 my $nocheck=shift @files if $files[0] eq "nocheck";
132 my $flag=shift @files if ref $files[0];
133 @files==remove((!$flag ? () : $flag),@files) or $nocheck or confess "$!";
136 # FIXME: File::NCopy exists but File::NMove doesn't
153 my $name=$Options{"name"};
154 _remove "nocheck",\1,
155 _rpmeval("_tmppath" )."/$name-*-root",
156 _rpmeval("_builddir")."/$name-*";
157 my($specsrc)=map((-e $_ ? $_ : "$name.spec.in"),"$name.spec.m4.in");
158 my $spec=_readfile $specsrc;
160 $class->run(%Options,
162 "configure_args"=>[split /\s+/,($spec=~/^[%]configure\b[ \t]*(.*)$/m)[0]],
164 _remove "ChangeLog"; # force its rebuild by Makefile/rcs2log
165 _system "make dist $name.spec";
166 _copy "$name-*.tar.gz",_rpmeval("_sourcedir");
167 _system(join(" ","rpmbuild",
169 "--rmsource", # _remove _rpmeval("_sourcedir")."/$name-*.tar.gz";
170 "--clean", # _remove _rpmeval("_builddir")."/$name-VERSION";
171 (!$args{"sign"} ? () : "--sign"),
174 _system "make dist-tarZ" if $Options{"dist-tarZ"};
175 _move _rpmeval("_srcrpmdir")."/$name-*.src.rpm",".";
176 _move _rpmeval("_rpmdir")."/"._rpmeval("_target_cpu")."/$name-*."._rpmeval("_target_cpu").".rpm",".";
177 _system "ls -l $name-*";
178 exit 0; # should never return
181 # WARNING: doesn't respect %Options change!
182 my @_cleanfiles_cache;
185 # maintainer-clean hack is not safe, please list all files for 'rm'.
186 # When the filename doesn't contain '/', it is applied to ALL directories.
187 # Please note that files exactly in root dir MUST have ./ in the front
188 # (to not to be considered as ALL-directories files).
190 if (!@_cleanfiles_cache) {
191 @_cleanfiles_cache=map({
192 local $_=$_; # Prevent: Modification of a read-only value attempted
193 s/\Q<name>\E/$Options{"name"}/ego;
195 # "*xyzzy" basename -> "*xyzzy",".*xyzzy" for proper cleaning
196 (!m#^((?:.*/)?)([*][^/]*)$# ? ($_) : ("$1$2","$1.$2"));
199 ".#*", # Possible attempt to put comments in qw() list
207 *.[oa] *.l[oa] *.l[oa]T
212 ./configure ./configure.scan
213 ./config.guess ./config.status ./config.sub ./config.log ./config.cache
214 ./config.h ./config.h.in
215 ./confdefs.h ./conftest* ./autoh[0-9]* ./confcache
219 ./stamp-h ./stamp-h.in ./stamp-h1
222 ./autom4te.cache ./autom4te-*.cache
226 ./libtool ./ltconfig ./ltmain.sh
229 ./<name>-[0-9]* ./<name>-devel-[0-9]*
230 ./<name>.spec ./<name>.m4 ./<name>.spec.m4
232 ./po/Makefile.in.in ./po/POTFILES* ./po/cat-id-tbl.c ./po/cat-id-tbl.tmp
233 ./po/*.gmo ./po/*.mo ./po/stamp-cat-id ./po/<name>.pot ./po/ChangeLog
234 ./po/Makevars ./po/Makevars.template ./po/Rules-quot ./po/*.sed ./po/*.sin ./po/*.header
236 map((!$_ ? () : do { my $dir=$_; map("$dir/$_",qw(
246 )); }),$Options{"gtk-doc-dir"}),
247 map((!$_ ? () : do { my $dir=$_; map("$dir/$_",qw(
253 )); }),$Options{"docbook-lite-dir"}),
254 map((!$_ ? () : @$_),$Options{"clean"}),
257 for (@_cleanfiles_cache) {
258 confess "dir-specific 'clean'-pattern must start with './': $_" if m#^(?!\Q./\E).*/#;
261 return @_cleanfiles_cache;
264 sub _cleanfilesfordir
269 if (m#^\Q$dir\E/([^/]+)$#) { # this-dir: "./this-dir/file-name.c"
272 elsif (m#^[^/]+$#) { # all-dirs: "file-name.c"; the same as "./*/file-name.c"
275 elsif (do { # all-subdirs: "./parent-of-this-dir/*/file-name.c"
277 ($_=$1) && $dir=~m#^\Q$`\E(?:/|$)#;
292 my @todo=(@startdirs);
293 while (defined(my $dir=shift @todo)) {
295 my $entries_filename="$dir/CVS/Entries";
296 open ENTRIES,$entries_filename or (cluck "open \"$entries_filename\": $!" and next);
303 next if !m#^D/([^/]+)/#;
306 close ENTRIES or cluck "close \"$entries_filename\": $!";
307 if (-e (my $entries_log_filename=$dir."/CVS/Entries.Log")) {
309 if (open ENTRIES_LOG,$entries_log_filename or cluck "open \"$entries_log_filename\": $!") {
311 while (<ENTRIES_LOG>) {
313 if (m#^A D/([^/]*)/#) {
316 elsif (m#^R D/([^/]*)/#) {
320 cluck "$entries_log_filename: Unrecognized line $.: $_";
323 close ENTRIES_LOG or cluck "close \"$entries_log_filename\": $!";
326 push @todo,map(("$dir/$_"),keys(%local));
335 return $patt if $patt!~/\Q[\E(.*?)\Q]\E/;
336 my($pre,$range,$post)=($`,$1,$'); # FIXME: local($`,$1,$') doesn't work - why?
337 1 while $range=~s#(.)-(.)# join("",map(chr,(ord($1)..ord($2))));
339 return map({ _expandclass("$pre$_$post"); } split("",$range));
344 my($class,%options)=@_;
346 local %Options=%options;
347 do { require $_ if -e; } for (home()."/.".$Options{"name"}.".autogen.pl");
348 do { $$_=1 if !defined($$_) && fgrep { /^\s*AUTOMAKE_OPTIONS\s*=[^#]*\bdist-tarZ\b/m; } "Makefile.am"; }
349 for (\$Options{"dist-tarZ"});
350 Getopt::Long::Configure('noignorecase','prefix_pattern=(--|-|\+|)');
351 local @ARGV=@{$Options{"ARGV"}};
352 print _help() and confess if !GetOptions(
353 "rpm" ,sub { $class->_rpmbuild("sign"=>1); },
354 "rpmtest" ,sub { $class->_rpmbuild("sign"=>0); },
355 "dist" ,\$Options{"ARGV_dist"},
356 "copy!" ,\$Options{"ARGV_copy"},
357 "fullclean",\$Options{"ARGV_fullclean"},
358 "clean" ,\$Options{"ARGV_clean"},
359 "h|help" ,sub { print _help(); exit 0; },
360 $Options{"GetOptions_args"},
363 for my $subdir (map((!$_ ? () : @$_),$Options{"subdirs"})) {
365 _system "./autogen.pl",@{$Options{"ARGV"}},"--dist"; # use "--dist" just as fallback!
368 for my $dir (_cvsdirs(".")) {
369 my @cleanfilesfordir=_cleanfilesfordir $dir;
370 _writefile $dir."/.cvsignore",map("$_\n",@cleanfilesfordir) if !$Options{"ARGV_fullclean"};
371 _remove "nocheck",\1,map({ _expandclass("$dir/$_"); } grep({
372 $Options{"ARGV_fullclean"} or $_ ne ".cvsignore";
373 } @cleanfilesfordir));
375 return if $Options{"ARGV_clean"} || $Options{"ARGV_fullclean"};
377 $Options{"aclocal_args"}=[qw(-I macros),map((!$_ ? () : @$_),$Options{"aclocal_args"})];
378 my $configure_in=_readfile("configure.in");
379 do { $$_=1 if !defined($$_) && $configure_in=~/^AM_GNU_GETTEXT\b/m; }
380 for (\$Options{"want-gettextize"});
381 do { $$_=1 if !defined($$_) && $configure_in=~/^AM_GLIB_GNU_GETTEXT\b/m; }
382 for (\$Options{"want-glib-gettextize"});
383 do { $$_=1 if !defined($$_) && $configure_in=~/^AM_PROG_LIBTOOL\b/m; }
384 for (\$Options{"want-libtoolize"});
385 do { $$_=1 if !defined($$_) && $configure_in=~/^A[CM]_CONFIG_HEADER\b/m; }
386 for (\$Options{"want-autoheader"});
387 my @copy_arg=(!$Options{"ARGV_copy"} ? () : "--copy");
389 do { &$_ if $_; } for ($Options{"prep"});
390 touch "po/POTFILES.in" if -d "po";
391 if ($Options{"want-gettextize"}) {
392 # don't use multi-arg system() here as it would reject "</dev/null" redirection etc.
394 .'spawn gettextize --intl --no-changelog '.join(" ",@copy_arg).';'
395 .'expect -timeout -1 "Press Return to acknowledge" {send "\r";exp_continue;} eof;'
397 _system $_ and confess $_;
399 for ("configure.in","Makefile.am") {
400 STDERR->printflush("gettextize recovery rename \"$_~\"->\"$_\"... ");
401 rename "$_~","$_" or confess "$!";
402 STDERR->printflush("ok\n");
404 if (!-e "po/Makevars") {
405 my $Makevars_template="po/Makevars.template";
406 my $makevars=_readfile $Makevars_template;
407 $makevars=~s/^(COPYRIGHT_HOLDER)\b.*$/"$1=".$Options{"COPYRIGHT_HOLDER"}/meg
408 or confess "COPYRIGHT_HOLDER not found in $Makevars_template";
409 _writefile "po/Makevars",$makevars;
411 # Prevent updating of contents during touch of any source file;
412 # change the .po contents only when some data get updated
413 for my $Makefile_in_in ("po/Makefile.in.in") {
414 my $file=_readfile $Makefile_in_in;
415 $file=~s%(\$\Q(MSGMERGE_UPDATE)\E) (\$\$\Q{lang}.po \E\$\Q(DOMAIN).pot\E)$%
416 $1.q< --backup=simple --suffix="~" >.$2.q<;>
417 .q< if test `diff -u $${lang}.po~ $${lang}.po>
419 .q< -e '1,/^@@.*@@$$/d'>
420 .q< -e '/^[+-]"POT-Creation-Date:/d'>
423 .q< | wc -l` -eq 0;then>
424 .q< touch --reference=$${lang}.po $${lang}.po~;>
425 .q< mv -f $${lang}.po~ $${lang}.po;>
427 .q< rm -f $${lang}.po~;>
430 unlink $Makefile_in_in or confess "$!";
431 _writefile $Makefile_in_in,$file;
434 if ($Options{"want-glib-gettextize"}) {
435 _system "glib-gettextize",@copy_arg;
436 # "po/ChangeLog" is somehow missing at this point
437 File::Touch->new("atime_only"=>1)->touch("po/ChangeLog");
439 _system "aclocal",map((!$_ ? () : @$_),$Options{"aclocal_args"});
440 _system qw(libtoolize),@copy_arg if $Options{"want-libtoolize"};
441 _system qw(autoheader) if $Options{"want-autoheader"};
442 # "ChangeLog" is reqd by automake(1)
443 # Don't remove it afterwards as it may still be needed during automatic automake Makefile rebuilds
444 File::Touch->new("atime_only"=>1)->touch("ChangeLog");
445 _system qw(automake --add-missing),@copy_arg;
446 _system qw(autoconf);
447 # Why it is left there after RedHat autoconf-2.53-8 ?
448 _remove "nocheck",\1,"autom4te-*.cache";
450 return if $Options{"ARGV_dist"};
452 # 'configure' defaults to CFLAGS '-g -O2' but our --enable-maintainer-mode
453 # should force '-ggdb3'
455 # shared/static switching cannot be based on maintainer-mode in configure
456 _system(qw(./configure --enable-maintainer-mode),
457 (!$Options{"want-libtoolize"} ? () : qw(--enable-shared --disable-static)),
458 map((!$_ ? () : @$_),$Options{"configure_args"}),
466 RedHat autoconf-2.53-8
467 RedHat automake-1.6.3-1
468 RedHat gettext-0.11.4-3
469 RedHat libtool-1.4.2-12