diff options
author | jbj <devnull@localhost> | 2002-02-09 22:39:29 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2002-02-09 22:39:29 +0000 |
commit | d83891c743e83ced7e6773f37d5e524840702835 (patch) | |
tree | 50386574a8908700103ac2cc53679c10b8d1d950 /scripts | |
parent | 1cf6127e8194d154f1e7e28c40761901531c2229 (diff) | |
download | librpm-tizen-d83891c743e83ced7e6773f37d5e524840702835.tar.gz librpm-tizen-d83891c743e83ced7e6773f37d5e524840702835.tar.bz2 librpm-tizen-d83891c743e83ced7e6773f37d5e524840702835.zip |
Sync with 4.0.4, splint clean.
CVS patchset: 5309
CVS date: 2002/02/09 22:39:29
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/Makefile.am | 6 | ||||
-rw-r--r-- | scripts/Specfile.pm | 193 | ||||
-rwxr-xr-x | scripts/cpanflute2 | 160 | ||||
-rwxr-xr-x | scripts/perl.req | 11 |
4 files changed, 366 insertions, 4 deletions
diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 721090539..7ab18694f 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -6,7 +6,8 @@ EXTRA_DIST = \ brp-compress brp-redhat brp-strip brp-strip-comment-note \ brp-strip-shared \ brp-sparc64-linux check-prereqs convertrpmrc.sh cross-build \ - find-lang.sh find-prov.pl find-req.pl cpanflute find-provides.perl \ + find-lang.sh find-prov.pl find-req.pl \ + cpanflute cpanflute2 Specfile.pm find-provides.perl \ find-requires.perl get_magic.pl getpo.sh http.req \ magic.prov magic.req perl.prov perl.req rpmdiff rpmdiff.cgi \ rpm.daily rpm.log rpm.xinetd rpm2cpio.sh \ @@ -22,7 +23,8 @@ config_SCRIPTS = \ brp-compress brp-redhat brp-strip brp-strip-comment-note \ brp-strip-shared \ brp-sparc64-linux check-prereqs convertrpmrc.sh cross-build \ - find-lang.sh find-prov.pl find-req.pl cpanflute find-provides.perl \ + find-lang.sh find-prov.pl find-req.pl \ + cpanflute cpanflute2 Specfile.pm find-provides.perl \ find-requires.perl get_magic.pl getpo.sh http.req \ magic.prov magic.req perl.prov perl.req rpmdiff rpmdiff.cgi \ rpm.daily rpm.log rpm.xinetd rpm2cpio.sh \ diff --git a/scripts/Specfile.pm b/scripts/Specfile.pm new file mode 100644 index 000000000..f04c68b8c --- /dev/null +++ b/scripts/Specfile.pm @@ -0,0 +1,193 @@ +package RPM::Specfile; + +use POSIX; + +use strict; + +use vars qw/$VERSION/; + +$VERSION = '1.02'; + +sub new { + my $class = shift; + + my $self = bless { }, $class; + + return $self; +} + +my @simple_accessors = qw/name version release epoch license group url description prep build clean install summary buildroot buildrequires file_param packager vendor distribution buildarch/; + +foreach my $field (@simple_accessors) { + my $sub = q { + sub RPM::Specfile::[[field]] { + my $self = shift; + if (@_) { + my $value = shift; + $self->{__[[field]]__} = $value; + } + return $self->{__[[field]]__}; + } + }; + + $sub =~ s/\[\[field\]\]/$field/g; + eval $sub; + + if ($@) { + die $@; + } +} + +my @array_accessors = qw/source patch changelog provide require file/; + +foreach my $field (@array_accessors) { + my $sub = q { + sub RPM::Specfile::[[field]] { + my $self = shift; + $self->{__[[field]]__} ||= [ ]; + + if (@_) { + my $index = shift; + if (@_) { + my $value = shift; + $self->{__[[field]]__}->[$index] = $value; + } + return $self->{__[[field]]__}->[$index]; + } + else { + return @{$self->{__[[field]]__}}; + } + } + + sub RPM::Specfile::push_[[field]] { + my $self = shift; + my $entry = shift; + + $self->{__[[field]]__} ||= [ ]; + push @{$self->{__[[field]]__}}, $entry; + } + + sub RPM::Specfile::clear_[[field]] { + my $self = shift; + my $entry = shift; + + $self->{__[[field]]__} = [ ]; + } + + }; + + $sub =~ s/\[\[field\]\]/$field/g; + eval $sub; + + if ($@) { + die $@; + } +} + +sub add_changelog_entry { + my $self = shift; + my $who = shift; + my $entry = shift; + + my $output; + $output .= strftime("* %a %b %d %Y $who\n", localtime time); + $output .= "- $entry\n"; + + $self->push_changelog($output); +} + +sub generate_specfile { + my $self = shift; + + my $output; + + my %defaults = ( buildroot => "%{_tmppath}/%{name}-root" ); + $self->$_($self->$_() || $defaults{$_}) foreach keys %defaults; + + my %proper_names = ( url => "URL", buildroot => "BuildRoot", "buildrequires" => "BuildRequires" ); + + foreach my $tag (qw/name version release epoch packager vendor distribution summary license group url buildroot buildrequires buildarch/) { + my $proper = $proper_names{$tag} || ucfirst $tag; + + next unless defined $self->$tag(); + $output .= "$proper: " . $self->$tag() . "\n"; + } + + my @reqs = $self->require; + for my $i (0 .. $#reqs) { + $output .= "Requires: $reqs[$i]\n"; + } + + my @sources = $self->source; + for my $i (0 .. $#sources) { + $output .= "Source$i: $sources[$i]\n"; + } + + my @patches = $self->patch; + for my $i (0 .. $#patches) { + $output .= "Patch$i: $patches[$i]\n"; + } + + $output .= "\n"; + + foreach my $sect (qw/description prep build clean install/) { + $output .= "%$sect\n"; + $output .= $self->$sect() . "\n"; + } + + if ($self->file_param) { + $output .= "%files " . $self->file_param . "\n"; + } + else { + $output .= "%files\n"; + } + $output .= "$_\n" foreach $self->file; + + $output .= "\n%changelog\n"; + $output .= "$_\n" foreach $self->changelog; + + return $output; +} + +sub write_specfile { + my $self = shift; + my $dest = shift; + + open FH, ">$dest" + or die "Can't open $dest: $!"; + + print FH $self->generate_specfile; + + close FH; +} + +1; + +__END__ +# Below is stub documentation for your module. You better edit it! + +=head1 NAME + +RPM::Specfile - Perl extension for creating RPM Specfiles + +=head1 SYNOPSIS + + use RPM::Specfile; + +=head1 DESCRIPTION + +Simple module for creation of RPM Spec files + +=head2 EXPORT + +None by default. + +=head1 AUTHOR + +Chip Turner <cturner@redhat.com> + +=head1 SEE ALSO + +L<perl>. + +=cut diff --git a/scripts/cpanflute2 b/scripts/cpanflute2 new file mode 100755 index 000000000..23d6bed9a --- /dev/null +++ b/scripts/cpanflute2 @@ -0,0 +1,160 @@ +#!/usr/bin/perl -w +use strict; + +use Getopt::Long; +use File::Basename; +use File::Copy; +use Archive::Tar; + +use lib '/usr/lib/rpm'; +use Specfile; + +my %options; + +GetOptions(\%options, "outdir=s", "tmpdir=s", "email=s", "name=s", "create", "test", "epoch=n", "version=s", "release=s", "perlver=s", "patch=s", "noarch=s") or die_usage(); + +my $fullname = shift; + +die_usage() unless $fullname; + +my $tarball = basename($fullname); +my $create = $options{create} || ''; +my $email = $options{email} || (getpwuid($<))[0] . '@redhat.com'; +my $outdir = $options{outdir} || './'; +my $tmpdir = $options{tmpdir} || '/tmp'; +my $noarch = $options{noarch}; + +$tarball =~ /^(.+)\-([^-]+)\.tar\.gz$/; +my $name = $options{name} || $1; +my $ver = $options{version} || $2; + +die "Module name/version not parsable from $tarball" unless $name and $ver; + +$name =~ s/::/-/g; + +copy($fullname, $tmpdir) + or die "copy: $!"; + +$noarch = $options{noarch}; + +my $patchfile = ''; +if ($options{patch}) { + copy($options{patch}, $tmpdir); + $patchfile = $options{patch}; +} + +my $spec = new RPM::Specfile; + +my $perlver = "0:5.00503"; +if ($options{perlver} and $options{perlver} eq '5.6.1') { + $perlver = "1:5.6.1"; +} + +# some basic spec fields +$spec->name("perl-$name"); +$spec->version($ver); +$spec->release($options{release} || "8"); +$spec->epoch($options{epoch}); +$spec->summary("$name Perl module"); +$spec->description($spec->summary); +$spec->group("Development/Libraries"); +$spec->license("distributable"); +$spec->buildrequires("perl >= $perlver"); +$spec->packager($email); +$spec->add_changelog_entry($email, 'Specfile autogenerated'); + +$spec->buildarch('noarch') if $noarch; + +# $spec->push_require(q|%(perl -MConfig -le 'if (defined $Config{useithreads}) { print "perl(:WITH_ITHREADS)" } else { print "perl(:WITHOUT_ITHREADS)" }')|); +# $spec->push_require(q|%(perl -MConfig -le 'if (defined $Config{usethreads}) { print "perl(:WITH_THREADS)" } else { print "perl(:WITHOUT_THREADS)" }')|); +# $spec->push_require(q|%(perl -MConfig -le 'if (defined $Config{uselargefiles}) { print "perl(:WITH_LARGEFILES)" } else { print "perl(:WITHOUT_LARGEFILES)" }')|); + +$spec->push_source($tarball); +$spec->push_patch(basename($patchfile)) + if $patchfile; + +# make a URL that can actually possibly take you to the right place +my $url_name = $name; +$url_name =~ s/-/::/g; +$url_name =~ s/([^a-zA-Z0-9])/sprintf "%%%x", ord $1/ge; +$spec->url("http://search.cpan.org/search?mode=module&query=$url_name"); + +# now we get into the multiline tags. stolen mostly verbatim from +# cpanflute1 + +my $patch = ''; +if ($patchfile) { + $patch = "%patch0 -p1\n"; +} + +$spec->prep("%setup -q -n $name-%{version} $create\n$patch"); +$spec->file_param("-f $name-$ver-filelist"); +$spec->push_file("%defattr(-,root,root)"); + +my $test_clause = ''; +$test_clause = "make test" if $options{test}; + +$spec->build(<<EOB); +CFLAGS="\$RPM_OPT_FLAGS" perl Makefile.PL +make +$test_clause +EOB + +$spec->clean('rm -rf $RPM_BUILD_ROOT'); +my $inst = q{ +rm -rf $RPM_BUILD_ROOT +eval `perl '-V:installarchlib'` +mkdir -p $RPM_BUILD_ROOT/$installarchlib +make PREFIX=$RPM_BUILD_ROOT/usr install + +[ -x /usr/lib/rpm/brp-compress ] && /usr/lib/rpm/brp-compress + +find $RPM_BUILD_ROOT/usr -type f -print | \ + sed "s@^$RPM_BUILD_ROOT@@g" | \ + grep -v perllocal.pod | \ + grep -v "\.packlist" > $name-$ver-filelist +if [ "$(cat $name-$ver-filelist)X" = "X" ] ; then + echo "ERROR: EMPTY FILE LIST" + exit -1 +fi +}; + +$inst =~ s/\$name/$name/g; +$inst =~ s/\$ver/$ver/g; + +$spec->install($inst); + +# write the spec file. create some macros. +$spec->write_specfile("$tmpdir/perl-$name.spec"); + +open FH, ">$tmpdir/macros" + or die "Can't create $tmpdir/macros: $!"; + +print FH qq{ +%_topdir $tmpdir +%_builddir %{_topdir} +%_rpmdir %{_topdir} +%_sourcedir %{_topdir} +%_specdir %{_topdir} +%_srcrpmdir $outdir +}; + +close FH; + +open FH, ">$tmpdir/rpmrc" + or die "Can't create $tmpdir/rpmrc: $!"; + +print FH qq{ +include: /usr/lib/rpm/rpmrc +macrofiles: /usr/lib/rpm/macros:$tmpdir/macros +}; +close FH; + +# perform the build, die on error +my $retval = system "rpm --rcfile $tmpdir/rpmrc -bs --rmsource --rmspec --clean $tmpdir/perl-$name.spec"; +$retval = $? >> 8; +if ($retval != 0) { + die "RPM building failed!\n"; +} + +unlink "$tmpdir/rpmrc", "$tmpdir/macros"; diff --git a/scripts/perl.req b/scripts/perl.req index df3a1649b..5ffe6e210 100755 --- a/scripts/perl.req +++ b/scripts/perl.req @@ -185,8 +185,15 @@ sub process_file { # if module is a number then both require and use interpret that # to mean that a particular version of perl is specified - print "perl > $module\n"; - next; + if ($module =~ /5.00/) { + print "perl >= 0:$module\n"; + next; + } + else { + print "perl >= 1:$module\n"; + next; + } + }; # ph files do not use the package name inside the file. |