[devel] perl packages

Michael Shigorin =?iso-8859-1?q?mike_=CE=C1_osdn=2Eorg=2Eua?=
Вт Дек 16 13:20:40 MSK 2008


On Tue, Dec 16, 2008 at 10:19:56AM +0300, Alexey Tourbin wrote:
> > - в каком состоянии сейчас cpan2rpm (в курсе ли он про свежие
> > изменения при упаковки перловых модулей)?
> Не следует использовать cpan2rpm.

1) почему, или "вообще"?
2) а cpan2spec?

-- 
 ---- WBR, Michael Shigorin <mike на altlinux.ru>
  ------ Linux.Kiev http://www.linux.kiev.ua/
----------- следующая часть -----------
#!/usr/bin/perl
# $Id$

use Switch;
use Cwd qw(realpath);
use ExtUtils::MakeMaker;
use File::Find qw(find);
use File::Temp qw(tempdir);
use sigtrap qw(die normal-signals);
use strict;

my %spec = (
	Name => 'perl-%dist',
	Release => 'alt1',
	License => 'GPL or Artistic',
	Group => 'Development/Perl',
	URL => '%CPAN %dist',
	Source => '%dist-%version.tar.bz2',
	BuildArch => 'noarch',
	prep => '%setup -q -n %dist-%version',
	build => '%perl_vendor_build',
	install => '%perl_vendor_install',
);

my @order = (
# name, type, optional
	[qw[ dist macro ]],
	[qw[ Name tag ]],
	[qw[ Version tag ]],
	[qw[ Release tag ]],
	[qw[ ]],
	[qw[ Summary tag ]],
	[qw[ License tag ]],
	[qw[ Group tag ]],
	[qw[ ]],
	[qw[ URL tag ]],
	[qw[ Source tag ]],
	[qw[ ]],
	[qw[ BuildArch tag 1 ]],
	[qw[ ]],
	[qw[ description section ]],
	[qw[ ]],
	[qw[ prep section ]],
	[qw[ ]],
	[qw[ build section ]],
	[qw[ ]],
	[qw[ install section ]],
	[qw[ ]],
	[qw[ files section ]],
);

@ARGV == 1 or print STDERR <<EOF and exit(1);
Usage:
1) go get your module at http://search.cpan.org/
2) zme <module>.tar.gz
3) $0 <module>.tar.*z* > ~/RPM/SOURES/perl-<module>.spec
4) vim ~/RPM/SOURES/perl-<module>.spec
5) buildreq ~/RPM/SOURES/perl-<module>.spec
6) add_changelog -e 'initial revision' ~/RPM/SOURES/perl-<module>.spec
7) rpm -ba ~/RPM/SOURES/perl-<module>.spec
EOF

{
	my $tarball = realpath $ARGV[0];
	my $dir = tempdir "cpan2spec.XXXXXXXXXX", TMPDIR => 1, CLEANUP => 1;
	chdir $dir;
	my $z	=	$tarball =~ /\.tar.bz2$/	&&	'j'
		||	$tarball =~ /\.tar.gz$/		&&	'z'
		||	do {	my $exhort = q(shpx gneonyy);
				$exhort =~ tr/A-Za-z/N-ZA-Mn-za-m/;
				die "$exhort $tarball\n";
			};
	system "tar", "xf$z", $tarball;
	chdir <*>;

	my $makefile;
	system $^X, qw(-pi -e s/\bexit\b/return/g Makefile.PL);
	*ExtUtils::MakeMaker::WriteMakefile = 
		sub { $makefile = { @_ }; bless $makefile, 'MM' }
		and do './Makefile.PL';
	$$makefile{DISTNAME} ||= $$makefile{NAME} and $$makefile{DISTNAME} =~ s/::/-/g;
	$spec{dist} ||= $$makefile{DISTNAME};

	find { wanted => sub { $$makefile{VERSION_FROM} ||= $_ if /\.pm$/ } 
		=> no_chdir => 1 } => ".";
		
	$spec{Version} ||= $$makefile{VERSION} ||
		$makefile->parse_version($$makefile{VERSION_FROM});
	$spec{Summary} ||= $$makefile{ABSTRACT}	|| 
		$makefile->parse_abstract($$makefile{ABSTRACT_FROM} || $$makefile{VERSION_FROM});
	$spec{Summary} ||= do {
		open my $fh, ($$makefile{ABSTRACT_FROM} || $$makefile{VERSION_FROM});
		my @lines = <$fh>;
		shift @lines while grep { /^=head1\s+name/i } @lines;
		shift @lines; local $_ = shift @lines;
		s/^[\w:-]+\s+[^\w\s]+\s+//;
		$_;
	};
	$spec{description} ||= do {
		open my $fh, ($$makefile{ABSTRACT_FROM} || $$makefile{VERSION_FROM});
		my @lines = <$fh>;
		shift @lines while grep { /^=head1\s+descr/i } @lines;
		shift @lines; local $_ = shift @lines;
		for my $line (@lines) {
			last unless $line =~ /\S/;
			$_ .= $line;
		}
		$_;
	};
	
	my $xs;
	find sub { ++$xs if /\.(xs|c)$/ } => ".";
	delete $spec{BuildArch} if $xs;
	
	my @doc = (<README*>, <Change*>);
	$spec{files} .= "\%doc @doc\n" if @doc;
	
	my %glob;
	find sub { /\.pm$/ and do {
			open my $fh, $_; 
			map { /^package\s+(\w+)/ && ++$glob{$1} } <$fh>; 
		}} => ".";
	foreach my $glob (sort keys %glob) {
		$spec{files} .= $xs
		? "\%perl_vendor_archlib/$glob*\n\%perl_vendor_autolib/$glob*\n"
		: "\%perl_vendor_privlib/$glob*\n";
		$spec{files} .= "\%perl_vendor_man3dir/$glob*\n";
	}
}

for (@order) {
	print "\n" and next unless @$_;
	next if not $spec{$$_[0]} and $$_[2];
	switch ($$_[1]) {
		case 'macro'	{ print "\%define $$_[0] " }
		case 'tag'	{ print "$$_[0]: " }
		case 'section'	{ print "\%$$_[0]\n" }
		else 		{ die "$$_[1] \n" }
	}
	print $spec{$$_[0]} . "\n";
}


Подробная информация о списке рассылки Devel