CPAN-RPM
view release on metacpan or search on metacpan
# assemble other info
$info->{summary} = "$info->{name} - " . ($meta{ABSTRACT} || "Perl module");
$info->{description} ||= $meta{DESCRIPTION} || "None.";
if (!@{ $info->{source}||=[] }) {
push @{$info->{source}}, $info->{tarball};
$info->{"source-list"} = optagg($info, "source");
}
$info->{changelog} = changelog();
$info->{"find-provides"}
&&= qq/%define __find_provides $info->{"find-provides"}/;
$info->{"find-requires"} &&= qq/
%define __find_requires $info->{"find-requires"}\n
%define __perl_requires $info->{"find-requires"}
/;
# section handlers
my $prologue = $info->{prologue};
delete $info->{prologue};
for (@$prologue) {
/^(\w+):(.*)$/ || next;
my ($sec, $v) = ($1, $2);
$info->{prologue}{$sec} = $v . $/;
}
my $epilogue = $info->{epilogue};
delete $info->{epilogue};
for (@$epilogue) {
/^(\w+):(.*)$/ || next;
my ($sec, $v) = ($1, $2);
$info->{epilogue}{$sec} = $v . $/;
}
for (@{$info->{"opts-secs"}}) {
$info->{prologue}{$_} ||= "";
$info->{epilogue}{$_} ||= "";
}
# special situations
if ($info->{"no-requires"}) {
my $noreqs = "";
for (@{$info->{"no-requires"}}) {
$noreqs .= qq/-e '$_' / for split /\s*,\s*/;
}
delete $info->{"no-requires"};
$info->{"no-requires"}{"define"}
= "%define custom_find_req %{_tmppath}/%{NVR}-find-requires";
$info->{"find-requires"}
= "%define _use_internal_dependency_generator 0";
$info->{"find-requires"}
.= "\n%define __find_requires %{custom_find_req}";
$info->{"find-requires"}
.= "\n%define __perl_requires %{custom_find_req}";
local $_ = qq[cat <<EOF > %{custom_find_req}
#!/bin/sh
/usr/lib/rpm/find-requires |grep -v $noreqs
EOF
chmod 755 %{custom_find_req}
];
s/^\s+//mg;
$info->{"no-requires"}{"install"} = $_;
$info->{"no-requires"}{"clean"} = "rm -f %{custom_find_req}";
}
$info->{"no-requires"}{"define"} ||= "";
$info->{"no-requires"}{"install"} ||= "";
$info->{"no-requires"}{"clean"} ||= "";
if ($info->{"no-provides"}) {
my $noprovs = "";
for (@{$info->{"no-provides"}}) {
$noprovs .= qq/-e '$_' / for split /\s*,\s*/;
}
delete $info->{"no-provides"};
$info->{"no-provides"}{"define"}
= "%define custom_find_prov %{_tmppath}/%{NVR}-find-provides";
$info->{"find-provides"}
= "%define _use_internal_dependency_generator 0";
$info->{"find-provides"}
.= "\n%define __find_provides %{custom_find_prov}";
$info->{"find-provides"}
.= "\n%define __perl_provides %{custom_find_prov}";
local $_ = qq[cat <<EOF > %{custom_find_prov}
#!/bin/sh
/usr/lib/rpm/find-provides |grep -v $noprovs
EOF
chmod 755 %{custom_find_prov}
];
s/^\s+//mg;
$info->{"no-provides"}{"install"} = $_;
$info->{"no-provides"}{"clean"} = "rm -f %{custom_find_prov}";
}
$info->{"no-provides"}{"define"} ||= "";
$info->{"no-provides"}{"install"} ||= "";
$info->{"no-provides"}{"clean"} ||= "";
# fix patch info
my $i = 0;
$info->{"patch-files"} = "";
$info->{"patch-apply"} = "";
for (split $/, $info->{"prepatch-list"}) {
s/.*:\s+//;
$info->{"patch-files"}
.= sprintf("%-*s %s\n", $SPECCOL, "Patch$i:", $_);
$info->{"patch-apply"} .= "%patch$i -p1\n";
# put patches in RPM dir if needed
cp($_, $RPMDIR{SOURCES})
|| die "Unable to copy patch [$_]: $!";
$i++;
}
for (split $/, $info->{"patch-list"}) {
s/.*:\s+//;
$info->{"patch-files"}
.= sprintf("%-*s %s\n", $SPECCOL, "Patch$i:", $_);
$info->{"patch-apply"} .= "%patch$i -p1\n";
# put patches in RPM dir if needed
cp($_, $RPMDIR{SOURCES})
|| die "Unable to copy patch [$_]: $!";
$i++;
}
# return to user's directory
chdir $CWD;
}
#
# generate s spec file
#
sub mk_spec {
my $info = shift || $_; local $_;
print "Generating spec file\n";
# clean warnings about missing keys
$info->{$_} ||= "" for keys(%info), @{$info->{"opts-simple"}};
$info->{$_} ||= "" for qw/make fixin/; # extra tags
$info->{"$_-list"} ||= "" for @{$info->{"opts-agg"}};
# strip ctrl-M's from Windoze files
$spec .= <<ZZ;
# For more information on cpan2rpm please visit: http://perl.arix.com/
#
%define pkgname $pkgname
%define filelist %{pkgname}-%{version}-filelist
%define NVR %{pkgname}-%{version}-%{release}
%define maketest $info->{maketest}
ZZ
$spec .= <<ZZ if $info->{"define-list"};
# user definitions
$info->{"define-list"}
ZZ
$spec =~ s/^[^\S\n]+//mg;
$spec .= $info->{"no-requires"}{"define"} . $/
if $info->{"no-requires"}{"define"};
$spec .= $info->{"no-provides"}{"define"} . $/
if $info->{"no-provides"}{"define"};
$spec .= $info->{"find-provides"} . $/
if $info->{"find-provides"};
$spec .= $info->{"find-requires"} . $/
if $info->{"find-requires"};
# add simple tags
$spec .= "\n";
for (@{$info->{"opts-simple"}}) {
$spec .= sprintf("%-*s %s\n", $SPECCOL, "$_:", $info->{$_})
if $info->{$_};
}
$spec .= sprintf("%-*s %s\n", $SPECCOL, "prefix:", "%(echo %{_prefix})");
# add lists
$spec .= $info->{"provides-list"};
$spec .= $info->{"requires-list"};
$spec .= $info->{"buildrequires-list"};
$spec .= $info->{"source-list"};
$spec .= $info->{"patch-files"};
$spec .= $info->{epilogue}{tag};
$spec .= "\n" . q/%description/ . "\n$info->{description}\n";
$_ = <<ZZ;
#
# This package was generated automatically with the cpan2rpm
# utility. To get this software or for more information
# please visit: http://perl.arix.com/
#
ZZ
s/^[^\S\n]+//mg; $spec .= $_;
# handle sections
$_ = "%setup -q -n $info->{tardir} $info->{create}";
$_ .= $/ . $info->{'patch-apply'}
if $info->{"patch-apply"};
$_ .= $/ . "chmod -R u+w %{_builddir}/$info->{tardir}" . $/;
$spec .= mksec($info, "prep" => $_);
$_ = ($info->{PL} =~ /^Make/)
? qq/
$info->{fixin}
CFLAGS="\$RPM_OPT_FLAGS"
%{__perl} Makefile.PL $info->{"make-maker"}
%{__make} $info->{"make"}
%if %maketest
%{__make} test
%endif
/ : qq/
$info->{fixin}
%{__perl} Build.PL
%{__perl} Build
%if %maketest
%{__perl} Build test
%endif
/;
s/^\s+//mg;
$spec .= mksec($info, "build" => $_);
my $install = ($info->{PL} =~ /^Make/)
? qq/%{makeinstall} /
: qq/%{__perl} Build install /
;
$install .= $info->{"make-install"};
$_ = <<ZZ;
[ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
$info->{"no-requires"}{"install"}
$info->{"no-provides"}{"install"}
$install
cmd=/usr/share/spec-helper/compress_files
[ -x \$cmd ] || cmd=/usr/lib/rpm/brp-compress
[ -x \$cmd ] && \$cmd
# SuSE Linux
if [ -e /etc/SuSE-release -o -e /etc/UnitedLinux-release ]
then
%{__mkdir_p} %{buildroot}/var/adm/perl-modules
fname=`find %{buildroot} -name "perllocal.pod" | head -1`
if [ -f "\$fname" ] \; then \\
%{__cat} `find %{buildroot} -name "perllocal.pod"` \\
| %{__sed} -e s+%{buildroot}++g \\
< /dev/null \\
> %{buildroot}/var/adm/perl-modules/%{name} \; \\
fi
fi
# remove special files
find %{buildroot} -name "perllocal.pod" \\
-o -name ".packlist" \\
-o -name "*.bs" \\
|xargs -i rm -f {}
# no empty directories
find %{buildroot}%{_prefix} \\
unless $2;
#$url = "$base/$2";
$url = $2;
my ($loc, $fn) = $url =~ m|(.*)/(.*)|;
print "Found: $fn\nAt: $loc\n";
unlink($cache) if -l $cache;
symlink($url, $cache);
}
$info->{f} = $url;
# bail if tarball already there (unless we're being --force'd)
my $tarball = $info->{f}; $tarball =~ s|.*/||;
if (-s "$RPMDIR{SOURCES}/$tarball" && -r _ && ! defined $info->{force}) {
print "Tarball found - not fetching\n";
return $tarball;
}
push @{$info->{source}}, $info->{f};
$info->{tarball} = write_url($RPMDIR{SOURCES}, $info->{f})
|| die "Unable to retrieve tarball";
}
# --- tar handling functions --------------------------------------------------
#
# determines whether given filename represents a tarball
# optionally dies it file doesn't exist or is not readable
#
sub istarball {
my ($fn, $fschk) = @_;
my $is = $fn =~ /$tarRE/i;
return $is unless $fschk && $is;
-r $fn || die "tarball: $!";
}
sub ls {
my $d = shift || $_;
opendir(DIR, $d) || die "ls(): $!";
my @f = grep { !/^\.\.?$/ } readdir(DIR);
closedir(DIR);
($d, @f);
}
#
# extracts a tarball
#
sub untar($) {
local $_ = shift;
my $dst = shift || $TMPDIR;
my $zip = /\.zip$/i;
my $z = /\.tar\.bz2$/i ? "j" : "z";
my @cmd = (qw/tar -x --directory/, $dst, "-$z", "-f", $_);
@cmd = (qw/unzip -d/, $dst, $_) if $zip;
system(@cmd) == 0 || die "system @cmd failed: $?";
system("chmod", "-R", "u+w", $dst);
my $cmd = $zip
? "unzip -l $_ | grep -P -o '\\S+/\$' |tail -1"
: "tar -t${z}f $_ |head -n 1"
;
chomp($_ = qx/$cmd/);
$_ = (split)[0] unless $zip;
if ($_ =~ m|/|) {
$_ =~ s|(.*?)/.*|$1|;
}
$dst .= "/$1" if m|^(\S+)/?|;
$dst =~ s|/*$||; # path shouldn't end in / or tardir gets wiped
$dst =~ s|\./||; # paths in tarballs shouldn't be relative
return $dst;
}
# --- file handling functions -------------------------------------------------
#
# returns the contents of a given file or undef if the
# file does not exist. if no filename is passed $_ is used.
# when called in void context, sets $_
#
sub readfile {
my $f = shift || $_;
local $_ if defined wantarray();
return $_ = "" unless -r $f;
local $/ = undef;
open(F, $f) || die "$! [$f]. Stopped ";
$_ = <F>;
close(F);
$_;
}
#
# writes a file, from a string
#
sub writefile($@) {
my $fn = shift;
local $_ = shift || $_;
my $op = shift || ">";
open (FILE, "$op $fn") || die "writefile('$fn'): $!. Stopped";
binmode(FILE);
print FILE;
close FILE || die "writefile('$fn'): $!. Stopped";
$fn;
}
sub cp {
my ($f, $d, $ff) = @_;
$f =~ s/~/$ENV{HOME}/;
return 1 unless -r $f;
($ff = $f) =~ s|.*/||;
return 1 if finode($f) eq finode("$d/$ff");
( run in 1.224 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )