X-Git-Url: http://git.jankratochvil.net/?p=macros.git;a=blobdiff_plain;f=AutoGen.pm;h=aa4bb647bc1fbfac7c81eb70bb6da10d265cb2a5;hp=343d463e238e60b0d4a501f2c8ceb063e0a4fb4f;hb=6cf1604c42c41f1b95fae2d07e3b4725a1f99f90;hpb=411490cfbe666e73eaf42fa064b358e838269579 diff --git a/AutoGen.pm b/AutoGen.pm index 343d463..aa4bb64 100644 --- a/AutoGen.pm +++ b/AutoGen.pm @@ -88,7 +88,7 @@ my($filename)=@_; local *F; open F,$filename or confess "Open \"$filename\": $!"; my $r=; - close F or cluck "Close \"$filename\": $!"; + close F or confess "Close \"$filename\": $!"; # Do not &cluck as it may be pipe result return $r; } @@ -97,9 +97,9 @@ sub _writefile my($filename,@content)=@_; local *F; - open F,">".$filename or confess "rewrite \"$filename\": $!"; + open F,($filename=~/^[|]/ ? "" : ">").$filename or confess "rewrite \"$filename\": $!"; print F @content; - close F or cluck "close \"$filename\": $!"; + close F or confess "close \"$filename\": $!"; # Do not &cluck as it may be pipe result } my %_rpmeval_cache; @@ -119,15 +119,25 @@ my(@names)=@_; return $r[0]; } +sub _system_error +{ +my($code,$cmd)=@_; + + confess $cmd.": $code=".join(",", + (!WIFEXITED($code) ? () : ("EXITSTATUS(".WEXITSTATUS($code).")")), + (!WIFSIGNALED($code) ? () : ("TERMSIG(" .WTERMSIG($code) .")")), + (!WIFSTOPPED($code) ? () : ("STOPSIG(" .WSTOPSIG($code) .")")), + ); +} + sub _system { my(@args)=@_; - system(@args) and confess join(" ",@args).": $?=".join(",", - (!WIFEXITED($?) ? () : ("EXITSTATUS(".WEXITSTATUS($?).")")), - (!WIFSIGNALED($?) ? () : ("TERMSIG(" .WTERMSIG($?) .")")), - (!WIFSTOPPED($?) ? () : ("STOPSIG(" .WSTOPSIG($?) .")")), - ); + my $rc_sub=pop @args if ref $args[$#args]; + $rc_sub||=sub { $_[0]==0; }; + my $rc=system(@args); + _system_error $?,join(" ",@args) if !WIFEXITED($?) || !&{$rc_sub}(WEXITSTATUS($?)); } # Assumed wildcard pattern expansion to exactly one item if !$nocheck @@ -136,10 +146,11 @@ sub _copy my(@files)=@_; my $nocheck=shift @files if $files[0] eq "nocheck"; + my $flag=shift @files if ref $files[0]; my $dest=pop @files; # expand pattern to properly match © resulting filenames count @files=map({ glob $_; } @files); - @files==copy @files,$dest or $nocheck or confess "$!"; + @files==copy((!$flag ? () : $flag),@files,$dest) or $nocheck or confess "$!"; } # Assumed wildcard pattern expansion to exactly one item if !$nocheck @@ -164,6 +175,15 @@ my(@files)=@_; _remove @files; } +sub _mkdir +{ +my(@dirs)=@_; + + for (@dirs) { + mkdir $_ or confess "$!"; + } +} + sub _prepdist { my($class,$name)=@_; @@ -177,8 +197,7 @@ my($class,$name)=@_; "ARGV"=>[qw(--copy)], "configure_args"=>[split /\s+/,$configure_args], ); - _remove $Options{"ChangeLog"} || "ChangeLog"; # force its rebuild by Makefile/rcs2log - _system "make dist $name.spec"; + _remove "nocheck",($Options{"ChangeLog"} || "ChangeLog"); # force its rebuild by Makefile/rcs2log } # $args{ @@ -193,7 +212,35 @@ my($class,%args)=@_; _rpmeval("_tmppath" )."/$name-*-root", _rpmeval("_builddir")."/$name-*"; $class->_prepdist($name); - _copy "$name-*.tar.gz",_rpmeval("_sourcedir"); + _system "make $name.spec"; + my $spec=_readfile "$name.spec"; + my $patch=($spec=~/^Patch\d*:\s*(.*)$/m)[0]; + _system "make dist"; + if (!$patch) { + _copy "$name-*.tar.gz",_rpmeval("_sourcedir"); + } + else { + my @origs; + for my $glob ("orig-$name-*.tar.{gz,Z}") { + @origs=glob $glob; + confess "Invalid glob $glob: ".join(",",@origs) if 1!=@origs; + } + my $base=($origs[0]=~/^orig-(.*)[.]tar[.](?:gz|Z)$/)[0]; + _copy $origs[0],_rpmeval("_sourcedir")."/".($origs[0]=~/^orig-(.*)$/)[0]; + _system "tar xzf ".$origs[0]; + _mkdir $base."-orig"; + # FIXME: Copy also dot-prefixed files! + _move \1,$base."/*",$base."-orig/"; + _system "tar xzf $name-*.tar.gz"; + # Use single-argument system() as we need shell redirection. + # FIXME: Use directory-independent _cleanfiles(), not root-directory '.cvsignore'. + # "-X -" does not work, it needs to be stat(2)able file. + _system "diff -ruP -X .cvsignore -I '".'[$]\(Id\|RCSfile\)\>.*[$]'."'" + ." $base-orig/ $base/" + ." >"._rpmeval("_sourcedir")."/".$patch, + sub { $_[0]==0 || $_[0]==1; }; # diff(1) returns non-zero return code on any diffs. + _remove \1,$base,$base."-orig"; + } _system(join(" ","rpmbuild", "-ba", "--rmsource", # _remove _rpmeval("_sourcedir")."/$name-*.tar.gz"; @@ -217,14 +264,28 @@ my($class,%args)=@_; my $name=$Options{"name"}; $class->_prepdist($name); - _system "tar xzf $name-*.tar.gz"; - _remove "$name-*.tar.gz"; # permit "cd $name-*" below - _system(join(" ","cd $name-*;dpkg-buildpackage", + _system "make distdir"; + # Copy 'orig' archive after &_prepdist which would delete it. + my @origs; + for my $glob ("orig-$name-*.tar.{gz,Z}") { + @origs=glob $glob; + if (@origs) { + confess "Invalid glob $glob: ".join(",",@origs) if 1!=@origs; + (my $deborig=$origs[0])=~s/^orig-([^-]+)-(.*)([.]tar[.][^.]+)$/$1_$2.orig$3/; + _copy $origs[0],$deborig; + } + } + my @subdirs; + for my $glob ("$name-*") { + @subdirs=glob $glob; + confess "Invalid glob $glob: ".join(",",@subdirs) if 1!=@subdirs; + } + _system(join(" ","cd ".$subdirs[0].";dpkg-buildpackage", "-rfakeroot", ($args{"sign"} ? () : ("-us","-uc")), )); - _remove \1,"$name-*"; - _system "ls -l ${name}_*"; + _remove \1,$subdirs[0]; + _system "ls -l ${name}*_[0-9]*"; exit 0; # should never return } @@ -278,7 +339,7 @@ sub _cleanfiles ./-[0-9]* ./-devel-[0-9]* ./.spec ./.m4 ./.spec.m4 ./debian/tmp ./debian/ - ./_[0-9]* + ./*_[0-9]* ./macros/macros.dep ./po/Makefile.in.in ./po/POTFILES* ./po/cat-id-tbl.c ./po/cat-id-tbl.tmp ./po/*.gmo ./po/*.mo ./po/stamp-cat-id ./po/.pot ./po/ChangeLog @@ -411,6 +472,7 @@ my($class,%options)=@_; "rpmtest" ,sub { $class->_rpmbuild("sign"=>0); }, "deb" ,sub { $class->_debbuild("sign"=>1); }, "debtest" ,sub { $class->_debbuild("sign"=>0); }, + "cleanfilesfordir=s",sub { print "$_\n" for (_cleanfilesfordir $_[1]); exit 0; }, "dist" ,\$Options{"ARGV_dist"}, "copy!" ,\$Options{"ARGV_copy"}, "fullclean",\$Options{"ARGV_fullclean"}, @@ -503,6 +565,22 @@ my($class,%options)=@_; File::Touch->new("atime_only"=>1)->touch("ChangeLog") if !$Options{"ChangeLog"}; _system qw(automake --add-missing),@copy_arg; _system qw(autoconf); + _writefile "| patch configure",<<'CONFIGURE_SUBST_X_EOF'; +--- configure-orig Wed Aug 20 12:10:37 2003 ++++ configure Wed Aug 20 13:22:51 2003 +@@ -21590,6 +21590,11 @@ + rm -f $tmp/stdin + if test x"$ac_file" != x-; then + mv $tmp/out $ac_file ++ for f in $ac_file_inputs; do ++ if test -x $f; then ++ chmod +x $ac_file ++ fi ++ done + else + cat $tmp/out + rm -f $tmp/out +CONFIGURE_SUBST_X_EOF # Why it is left there after RedHat autoconf-2.53-8 ? _remove "nocheck",\1,"autom4te-*.cache";