@@ -49,7 +49,7 @@ GetOptions(\%options, "outdir=s", "tmpdir=s", "email=s", "name|n=s", "create",
"test|t", "epoch|e=n", "version|v=s", "release|r=s", "perlver=s", "patch=s@",
"noarch", "arch|a=s", "noperlreqs", "usage", "buildall|b", "installdirs=s",
"descfile=s", "help", "requires=s@", "buildrequires=s@", "sign", "post=s",
- "pre=s", "preun=s", "postun=s") or die_usage();
+ "pre=s", "preun=s", "postun=s", 'use-usr-local') or die_usage();
my $fullname = shift;
my $content;
@@ -91,6 +91,7 @@ my $noarch = $options{noarch} || '';
my $plat_perl_reqs = $options{'noperlreqs'} ? 0 : 1;
my $release = $options{'release'} || $defaults{'release'};
my $build_switch = 's';
+my $use_module_build = 0;
my @docs = ();
$tmpdir = tempdir(CLEANUP => 1, DIR => $tmpdir);
@@ -119,6 +120,7 @@ $build_switch = 'a' if(defined($options{'buildall'}));
$tarball =~ /^(.+)\-([^-]+)\.t(ar\.)?gz$/;
my $name = $options{name} || $1;
my $ver = $options{version} || $2;
+my $tarball_top_dir = "$name-%{version}";
die "Module name/version not parsable from $tarball" unless $name and $ver;
@@ -129,12 +131,19 @@ copy($fullname, $tmpdir)
utime((stat($fullname))[8,9], "$tmpdir/$tarball");
if (my @files = Archive::Tar->list_archive("$tmpdir/$tarball")) {
+ $use_module_build = 1 if grep { /Build\.PL$/ } @files;
+
if (not exists $options{noarch}) {
$noarch = 1;
$noarch = 0 if grep { /\.(xs|c|cc|C)$/ } @files;
}
- # find docs
+
+ my %prefixes;
foreach (@files) {
+ my @path_components = split m[/], $_;
+ $prefixes{$path_components[0]}++;
+
+ # find docs
if (m,^${name}-${ver}/(
authors?|
change(log|s)|
@@ -147,6 +156,11 @@ if (my @files = Archive::Tar->list_archive("$tmpdir/$tarball")) {
push(@docs, $1);
}
}
+
+ if (scalar keys %prefixes == 1) {
+ ($tarball_top_dir) = keys %prefixes;
+ $tarball_top_dir =~ s/$ver/%{version}/;
+ }
}
#
@@ -245,7 +259,7 @@ $spec->url(sprintf('http://search.cpan.org/dist/%s/', uri_escape($name)));
# now we get into the multiline tags. stolen mostly verbatim from
# cpanflute1
-$spec->prep("%setup -q -n $name-%{version} $create\n");
+$spec->prep("%setup -q -n $tarball_top_dir $create\n");
$spec->file_param('-f %{name}-%{version}-%{release}-filelist');
$spec->push_file('%defattr(-,root,root,-)');
$spec->push_file('%doc ' . join(' ', sort @docs)) if @docs;
@@ -265,8 +279,13 @@ if ($options{'installdirs'}) {
my $makefile_pl = qq{CFLAGS="\$RPM_OPT_FLAGS" perl Makefile.PL < /dev/null};
my $make_install = qq{%makeinstall PREFIX=\$RPM_BUILD_ROOT%{_prefix} $installdirs};
-if ($perlver =~ /5.8.0/) {
- $makefile_pl = qq{CFLAGS="\$RPM_OPT_FLAGS" perl Makefile.PL PREFIX=\$RPM_BUILD_ROOT%{_prefix} $installdirs < /dev/null};
+if ($perlver =~ /^[\d+]:5.[89]/) {
+ if ($use_module_build) {
+ $makefile_pl = qq{CFLAGS="\$RPM_OPT_FLAGS" perl Makefile.PL destdir=\$RPM_BUILD_ROOT $installdirs < /dev/null};
+ }
+ else {
+ $makefile_pl = qq{CFLAGS="\$RPM_OPT_FLAGS" perl Makefile.PL PREFIX=\$RPM_BUILD_ROOT%{_prefix} $installdirs < /dev/null};
+ }
$make_install = qq{%makeinstall};
}
@@ -291,6 +310,16 @@ chmod -R u+w $RPM_BUILD_ROOT/*
[ -x /usr/lib/rpm/brp-compress ] && /usr/lib/rpm/brp-compress
+[ -n "$options{'use-usr-local'}" ] && {
+ for dir in bin share/doc share/man; do
+ if [ -d $RPM_BUILD_ROOT/usr/$dir ]; then
+ mkdir -p $RPM_BUILD_ROOT/usr/local/$dir
+ mv $RPM_BUILD_ROOT/usr/$dir/* $RPM_BUILD_ROOT/usr/local/$dir/
+ rm -Rf $RPM_BUILD_ROOT/usr/$dir
+ fi
+ done
+}
+
find $RPM_BUILD_ROOT -type f \
| sed "s@^$RPM_BUILD_ROOT@@g" \
> %{name}-%{version}-%{release}-filelist
@@ -311,6 +340,7 @@ fi
};
$inst =~ s/\$make_install/$make_install/g;
+$inst =~ s/\$options{'?(.*?)'?}/$options{$1} || ''/ge;
$spec->install($inst);
@@ -437,6 +467,7 @@ cpanflute2 --usage
--version= Version of CPAN module. Defaults to parsing this
from the tarball filename.
--installdirs= Specify which INSTALLDIRS setting to use (see MakeMaker)
+ --use-usr-local Place some files in /usr/local instead of /usr (i.e., bin and manpages)
(archive) Name of gzipped tarball containing CPAN source.
EOF