&_rpmbuild: Support also .tar.bz2 orig source packages.
[macros.git] / AutoGen.pm
index 64dbad3..8519a75 100644 (file)
@@ -88,7 +88,7 @@ my($filename)=@_;
        local *F;
        open F,$filename or confess "Open \"$filename\": $!";
        my $r=<F>;
-       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;
@@ -214,20 +214,20 @@ my($class,%args)=@_;
        $class->_prepdist($name);
        _system "make $name.spec";
        my $spec=_readfile "$name.spec";
-       my $patch=($spec=~/^Patch\d*:\s*(.*)$/m)[0];
+       my $patch=($spec=~/^Patch\d*\s*:\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 "orig-$name-*.tar.{gz,Z,bz2}";
+               for my $glob ("orig-$name-*.tar.{gz,Z,bz2}") {
+                       @origs=glob $glob;
                        confess "Invalid glob $glob: ".join(",",@origs) if 1!=@origs;
                        }
-               my $base=($origs[0]=~/^orig-(.*)[.]tar[.](?:gz|Z)$/)[0];
+               my($base,$ext)=($origs[0]=~/^orig-(.*)[.]tar[.](gz|Z|bz2)$/);
                _copy $origs[0],_rpmeval("_sourcedir")."/".($origs[0]=~/^orig-(.*)$/)[0];
-               _system "tar xzf ".$origs[0];
+               _system "tar x".($ext eq "bz2" ? "j" : "z")."f ".$origs[0];
                _mkdir $base."-orig";
                # FIXME: Copy also dot-prefixed files!
                _move \1,$base."/*",$base."-orig/";
@@ -265,12 +265,27 @@ my($class,%args)=@_;
        my $name=$Options{"name"};
        $class->_prepdist($name);
        _system "make distdir";
-       _system(join(" ","cd $name-*;dpkg-buildpackage",
+       # 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
 }
 
@@ -321,10 +336,10 @@ sub _cleanfiles
                                                ./mkinstalldirs
                                                ./libtool ./ltconfig ./ltmain.sh
                                                ./ABOUT-NLS
-                                               ./<name>-[0-9]* ./<name>-devel-[0-9]*
+                                               ./<name>-[0-9]* ./<name>-*-[0-9]*
                                                ./<name>.spec ./<name>.m4 ./<name>.spec.m4
                                                ./debian/tmp ./debian/<name>
-                                               ./<name>_[0-9]*
+                                               ./<name>*_[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/<name>.pot ./po/ChangeLog
@@ -457,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"},
@@ -480,14 +496,18 @@ my($class,%options)=@_;
        return if $Options{"ARGV_clean"} || $Options{"ARGV_fullclean"};
 
        $Options{"aclocal_args"}=[qw(-I macros),map((!$_ ? () : @$_),$Options{"aclocal_args"})];
-       my $configure_in=_readfile("configure.in");
-       do { $$_=1 if !defined($$_) && $configure_in=~/^AM_GNU_GETTEXT\b/m; }
+       my $configure_name;
+       do { $configure_name||=$_ if -f $_ } for ("configure.in");
+       do { $configure_name||=$_ if -f $_ } for ("configure.ac");
+       $configure_name or confess "Cannot find configure.{in,ac}";
+       my $configure_in=_readfile($configure_name);
+       do { $$_=1 if !defined($$_) && $configure_in=~/^\s*AM_GNU_GETTEXT\b/m; }
                        for (\$Options{"want-gettextize"});
-       do { $$_=1 if !defined($$_) && $configure_in=~/^AM_GLIB_GNU_GETTEXT\b/m; }
+       do { $$_=1 if !defined($$_) && $configure_in=~/^\s*AM_GLIB_GNU_GETTEXT\b/m; }
                        for (\$Options{"want-glib-gettextize"});
-       do { $$_=1 if !defined($$_) && $configure_in=~/^AM_PROG_LIBTOOL\b/m; }
+       do { $$_=1 if !defined($$_) && $configure_in=~/^\s*AM_PROG_LIBTOOL\b/m; }
                        for (\$Options{"want-libtoolize"}); 
-       do { $$_=1 if !defined($$_) && $configure_in=~/^A[CM]_CONFIG_HEADER\b/m; }
+       do { $$_=1 if !defined($$_) && $configure_in=~/^\s*A[CM]_CONFIG_HEADER\b/m; }
                        for (\$Options{"want-autoheader"});
        my @copy_arg=(!$Options{"ARGV_copy"} ? () : "--copy");
 
@@ -501,7 +521,7 @@ my($class,%options)=@_;
                                ."'") {
                        _system $_ and confess $_;
                        }
-               for ("configure.in","Makefile.am") {
+               for ($configure_name,"Makefile.am") {
                        STDERR->printflush("gettextize recovery rename \"$_~\"->\"$_\"... ");
                        rename "$_~","$_" or confess "$!";
                        STDERR->printflush("ok\n");
@@ -549,6 +569,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";