diff options
author | Justin Davis <jrcd83@gmail.com> | 2011-10-21 22:46:21 +0200 |
---|---|---|
committer | Justin Davis <jrcd83@gmail.com> | 2011-10-21 22:46:21 +0200 |
commit | 879bbf01560e348d93c6903786fabae0607a59e6 (patch) | |
tree | dddf7f119a44d9754a1600edb42dfdcb4f1a21ff /bin | |
parent | 623989ed692a74f40a162bb7a198ac8ffaf8215e (diff) | |
download | genpkg-879bbf01560e348d93c6903786fabae0607a59e6.tar.gz genpkg-879bbf01560e348d93c6903786fabae0607a59e6.tar.xz |
Create lib/ directory for meta generator and template scripts.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/metas/perl | 94 | ||||
-rwxr-xr-x | bin/metas/perl.d/cpandists | 66 | ||||
-rwxr-xr-x | bin/metas/perl.d/perl-dist | 561 | ||||
-rwxr-xr-x | bin/templ/pbfields | 91 | ||||
-rwxr-xr-x | bin/templ/perl-pkg | 120 |
5 files changed, 0 insertions, 932 deletions
diff --git a/bin/metas/perl b/bin/metas/perl deleted file mode 100755 index 2f341e5..0000000 --- a/bin/metas/perl +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env perl - -use warnings 'FATAL' => 'all'; -use strict; - -use File::Fetch; -use IO::Handle; # for autoflush -use Cwd; - -my $PROG = 'perl'; - -sub err -{ - print STDERR @_, "\n"; - exit 2; -} - -sub matchdist -{ - my ($dist) = @_; - - # Refresh our local list of distributions if needed. - my $var = $ENV{'PKGVAR'} - or err("$PROG: PKGVAR env variable is unset\n"); - - if(!-f "$var/cpandists" || -M "$var/cpandists" > 1) { - print STDERR "Refreshing local CPAN distribution list..."; - my $cwd = getcwd(); - chdir($var) or die "chdir: $!"; - system('cpandists'); - err("FAILED") unless($? == 0); - print STDERR "OK\n"; - chdir($cwd) or die "chdir: $!"; - } - - open(DISTS, '<', "$var/cpandists") or err("$PROG: open: $!"); - while(<DISTS>) { - my @f = split; - next unless(lc($f[0]) eq lc($dist)); - close(DISTS); - return ($f[0], $f[2]); - } - close(DISTS); - return (); -} - -sub fetchdist -{ - my ($cpath) = @_; - my $file = $cpath; $file =~ s{^.*/}{}; - if(-f $file) { - print STDERR "$file already downloaded.\n"; - return; - } - - my $mirror = $ENV{'CPANMIRROR'} || 'ftp://cpan.pair.com'; - my $url = "${mirror}/authors/id/${cpath}"; - - print STDERR "Downloading $file... "; - my $ff = File::Fetch->new('uri' => $url); - err("FAILED") unless($ff->fetch()); - print STDERR "OK\n"; -} - -sub main -{ - my $pkg = shift or die "Usage: $PROG [package name]\n"; - my $dist = $pkg; - - $dist = "app-$dist" if($dist =~ s/^perl-// == 0); - - STDERR->autoflush(1); - my ($realname, $cpath) = matchdist($dist); - unless($realname){ - print STDERR "$PROG: failed to find perl dist similar to $dist\n"; - exit 1; - } - fetchdist($cpath); - - print <<"END_META"; -url -https://metacpan.org/release/$realname - -source -http://search.cpan.org/CPAN/authors/id/$cpath - -END_META - - my $file = $cpath; $file =~ s{^.*/}{}; - system('perl-dist', $file); - return $?; -} - -exit main(@ARGV); diff --git a/bin/metas/perl.d/cpandists b/bin/metas/perl.d/cpandists deleted file mode 100755 index 040db77..0000000 --- a/bin/metas/perl.d/cpandists +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/sh - -mirror=${CPANMIRROR:-ftp://cpan.pair.com} -path=/modules/02packages.details.txt.gz - -curl --silent "$mirror$path" | gzip -dc | awk ' -NR < 10 { next } -{ - file = a[split($3, a, "/")] - len = split(file, a, ".") - - if (!match(a[1], /[-_][vV]?[0-9]+$/)) { - #print "error: failed to grok " $3 | "cat 1>&2" - next - } - ver = substr(file, RSTART+1, RLENGTH-1) - dist = substr(file, 1, RSTART-1) - for (i=2; i<=len; i++) { - if (a[i] !~ /^[0-9]/) break - ver = ver "." a[i] - } - sub(/^[vV]/, "", ver) - - # For some reason the newest version of perl had no modules in 02packages - # so I cant just use modules from the newest version of perl. - if(dist == "perl") - coremods = coremods $1 " " $2 "\n" - else - mods[dist,ver] = mods[dist,ver] $1 " " $2 "\n" - - if (lessthan(dists[dist], ver)) { - dists[dist] = ver - paths[dist] = $3 - } -} - -END { - for (dist in dists) { - ver = dists[dist] - print dist, ver, paths[dist] | "sort >cpandists" - } - close("sort >cpandists") - - # Prints modules out in sorted order, too! - while(getline<"cpandists" > 0) { - print $1 "\n" ($1 == "perl" ? coremods : mods[$1,$2]) >"cpanmods" - } -} - -function lessthan (l, r) -{ - return decver(l) < decver(r) -} - -function decver (vs) -{ - pcnt = gsub(/[.]/, ".", vs) - if (pcnt < 2) return vs - - len = split(vs, vc, ".") - dec = vc[1] - for (i=2; i<=len; i++) dec += (10 ^ (-i * 3)) * vc[i] - return dec -} - -' diff --git a/bin/metas/perl.d/perl-dist b/bin/metas/perl.d/perl-dist deleted file mode 100755 index 57b468b..0000000 --- a/bin/metas/perl.d/perl-dist +++ /dev/null @@ -1,561 +0,0 @@ -#!/usr/bin/env perl - -use warnings 'FATAL' => 'all'; -use strict; - -my $PROG = 'perl-dist'; - -package Convert; - -use Module::CoreList; -use LWP::UserAgent qw(); -use YAML::XS qw(); -use version qw(); - -# Match unpredictible package names . -my %OVERRIDE = - ('libwww-perl' => 'perl-libwww', - 'aceperl' => 'perl-ace', - 'mod_perl' => 'mod_perl', - 'glade-perl-two' => 'perl-glade-two', - 'Gnome2-GConf' => 'gconf-perl', - 'Gtk2-GladeXML' => 'glade-perl', - 'Glib' => 'glib-perl', - 'Gnome2' => 'gnome-perl', - 'Gnome2-VFS' => 'gnome-vfs-perl', - 'Gnome2-Canvas' => 'gnomecanvas-perl', - 'Gnome2-GConf' => 'gconf-perl', - 'Gtk2' => 'gtk2-perl', - 'Cairo' => 'cairo-perl', - 'Pango' => 'pango-perl', - 'Perl-Critic' => 'perl-critic', - 'Perl-Tidy' => 'perl-tidy', - 'App-Ack' => 'ack', - 'TermReadKey' => 'perl-term-readkey'); - -sub dist2pkg -{ - my ($name, $ver) = @_; - return dist_pkgname($name), dist_pkgver($ver); -} - -# Copied from CPANPLUS::Dist::Arch -sub dist_pkgname -{ - my ($distname) = @_; - - return $OVERRIDE{$distname} if(exists($OVERRIDE{$distname})); - - # Package names should be lowercase and consist of alphanumeric - # characters only (and hyphens!)... - $distname = lc($distname); - $distname =~ tr/_+/--/; - $distname =~ tr/-a-z0-9//cd; # Delete all other chars - $distname =~ tr/-/-/s; - - # Delete leading or trailing hyphens... - $distname =~ s/\A-//; - $distname =~ s/-\z//; - - die qq{Dist name '$distname' completely violates packaging standards} - if(length($distname) == 0); - - # Don't prefix the package with perl- if it IS perl... - $distname = "perl-$distname" unless($distname eq 'perl'); - - return $distname; -} - -sub dist_pkgver -{ - my ($version) = @_; - - # Remove developer versions because pacman has no special logic - # to handle comparing them to regular versions such as perl uses. - $version =~ s/_[^_]+\z//; - - # Package versions should be numbers and decimal points only... - $version =~ tr/-_/../; - $version =~ tr/0-9.//cd; - - $version =~ tr/././s; - $version =~ s/^[.]|[.]$//g; - - return $version; -} - -#---HELPER FUNCTION--- -# Decide if the dist. is named after the module. -sub _ismainmod -{ - my ($mod_name, $dist_name) = @_; - - $mod_name =~ tr/:/-/s; - return lc($mod_name) eq lc($dist_name); -} - -#---HELPER FUNCTION--- -# Merges the right-hand deps into the left-hand deps. -sub _merge -{ - my ($left_deps, $right_deps) = @_; - - MERGE_LOOP: - while(my ($pkg, $ver) = each(%$right_deps)) { - if($left_deps->{$pkg}) { - my $leftver = version->parse($left_deps->{$pkg}); - my $rightver = version->parse($ver); - next MERGE_LOOP if $leftver > $rightver; - } - $left_deps->{$pkg} = $ver; - } - - return; -} - -#---HELPER FUNCTION--- -# Merge duplicate deps into $left always storing the greatest version there. -sub _mergedups -{ - my ($left, $right) = @_; - - for my $name (keys %$left) { - my $rver = delete($right->{$name}) or next; - my $lver = $left->{$name}; - my $lvo = ($lver ? version->parse($lver) : 0); - my $rvo = ($rver ? version->parse($rver) : 0); - $left->{$name} = ($lvo > $rvo ? $lvo : $rvo); - } - - return; -} - -sub _filterdeps(&$) -{ - my ($fsub, $deps) = @_; - my %fed; - - my @pkgs = keys(%$deps); - for my $dname (grep { $fsub->() } @pkgs){ - my $dver = delete($deps->{$dname}); - $fed{$dname} = $dver if(defined $dver); - } - - return \%fed; -} - -#---HELPER FUNCTION--- -sub _yankcheckers -{ - _filterdeps { /^perl-pod-coverage$|^perl-test-/ } $_[0] -} - -#---HELPER FUNCTION--- -# Converts a decimal perl version (like $]) into the dotted decimal -# form that the official ArchLinux perl package uses. -sub _perldepver -{ - my ($perlver) = @_; - - # Fix perl-style vstrings which have a leading "v". - return $perlver if($perlver =~ s/\Av//); - return $perlver unless($perlver =~ /\A(\d+)[.](\d{3})(\d{1,3})\z/); - - # Re-apply the missing trailing zeroes. - my $patch = $3; - $patch .= q{0} x (3 - length($patch)); - return sprintf('%d.%d.%d', $1, $2, $patch); -} - -#---PUBLIC FUNCNTION--- -# Translates CPAN module dependencies into ArchLinux package dependencies. -sub _reqs2deps -{ - my ($prereqs) = @_; - my (@mods, %pkgdeps); - - CPAN_DEP_LOOP: - while(my ($name, $ver) = each(%$prereqs)) { - # Sometimes a perl version is given as a prerequisite - if($name eq 'perl') { - $pkgdeps{'perl'} = _perldepver($ver); - next CPAN_DEP_LOOP; - } - push @mods, $name; - } - - my %dists = _distsofmods(@mods); - while(my ($mod, $dist) = each %dists) { - my $pkgname = dist_pkgname($dist); - my $ver = $prereqs->{$mod}; - - # If the module is not named after the distribution, ignore its - # version which might not match the distribution. - undef $ver unless(_ismainmod($mod, $dist)); - - # If two module prereqs are in the same CPAN distribution then - # the version required for the main module will override. - # (because versions specified for other modules in the dist - # are 0) - $pkgdeps{$pkgname} ||= ($ver ? dist_pkgver($ver) : 0); - } - - return \%pkgdeps; -} - -sub prereqs -{ - my ($pkgname, $prereqs) = @_; - - # maps perl names for different dependencies to ArchLinux's names - my %namemap = ('configure' => 'makedepends', - 'build' => 'makedepends', - 'test' => 'checkdepends', - 'runtime' => 'depends'); - - my %pkgdeps; - while (my ($perl, $arch) = each(%namemap)) { - my $reqs = $prereqs->{$perl}{'requires'}; - my $deps; $deps = _reqs2deps($reqs) if($reqs); - - next unless(keys(%$deps)); - if($pkgdeps{$arch}) { _merge($pkgdeps{$arch}, $deps); } - else { $pkgdeps{$arch} = $deps; } - } - - # ArchLinux now has a separate array for dependencies that we only - # need for checking (aka "testing"). Older perl METAs do not - # have this separated. Force any test modules to be checkdepends. - if(!$pkgdeps{'checkdepends'} && $pkgname !~ /\Aperl-test-/) { - my $checkdeps = {}; - _merge($checkdeps, _yankcheckers($pkgdeps{$_})) for(qw/makedepends depends/); - $pkgdeps{'checkdepends'} = $checkdeps; - } - - # We at least require perl, if nothing else. - unless(grep { scalar(keys(%$_)) > 0 } values(%pkgdeps)) { - $pkgdeps{'depends'}{'perl'} = 0; - } - - _mergedups(@pkgdeps{'makedepends', 'checkdepends'}); - _mergedups(@pkgdeps{'depends', 'makedepends'}); - - # Convert all deps into arrays of strings. - for my $deptype (keys(%pkgdeps)) { - $pkgdeps{$deptype} = _stringify($pkgdeps{$deptype}); - } - - return \%pkgdeps; -} - -#---HELPER FUNCTION--- -sub _stringify -{ - my ($deps) = @_; - - my @depstrs; - for my $pkg (sort(keys(%$deps))) { - my $ver = $deps->{$pkg}; - my $str = ($ver eq '0' ? $pkg : "$pkg>=$ver"); - push(@depstrs, $str); - } - - return \@depstrs; -} - -sub _distsofmods -{ - my (@mods) = @_; - - return () if(@mods == 0); - - use Time::HiRes qw(time); - my $beg = time; - - my $var = $ENV{'PKGVAR'} - or die "$PROG: PKGVAR env variable is unset\n"; - open(my $fh, '<', "$var/cpanmods") - or die "$PROG: failed to open $var/cpanmods: $!"; - - my (@hunted, %dists) = @mods; - local $/ = ''; - - RECLOOP: - while(my $rec = <$fh>) { - my ($dist, @modvers) = split(/\n/, $rec); - for (@modvers) { - my ($m) = split; - - CMPLOOP: - for my $i (0 .. $#hunted) { - next CMPLOOP unless($hunted[$i] eq $m); - $dists{$m} = $dist; - splice @hunted, $i, 1; - last RECLOOP if(@hunted == 0); - last CMPLOOP; - } - } - } - - if (@hunted) { - for my $lost (@hunted) { - print STDERR "$PROG: failed to find module $lost\n"; - } - exit 2; - } - - return %dists; -} - -#----------------------------------------------------------------------------- - -package main; - -use File::Basename qw(basename dirname); -use File::Spec::Functions qw(catfile catdir); -use File::Find qw(find); - -use JSON::XS qw(decode_json); # for META.json -use YAML::XS (); # for META.yml -use Pod::Select (); # search POD for description - -use Digest::MD5 (); # for md5sums & sha512sums -use Digest::SHA (); - -sub main -{ - my $distpath = shift() or die "Usage: $PROG [path to cpan dist file]\n"; - my $dir = dirname($distpath); - my $file = basename($distpath); - my $info = distinfo($file); - - chsrcdir(catdir($dir, 'src'), $file); - $dir = extractdist($file); - - my $meta = loadmeta($dir); - my $desc = $meta->{'abstract'}; - if(!$desc || $desc eq '~') { - $meta->{'abstract'} = distdesc($dir, $info->{'mod'}); - } - - my ($name, $ver) = Convert::dist2pkg(@{$info}{'name', 'ver'}); - my $deps = Convert::prereqs($name, $meta->{'prereqs'}); - - my %pbvars = - ('pkgver' => $ver, - 'pkgdesc' => $meta->{'abstract'}, - 'arch' => (xsdist($dir) ? ['i686', 'x86_64'] : 'any'), - 'md5sums' => md5sums($file), - 'sha512sums' => sha512sums($file), - 'distdir' => $dir, - %$deps, - ); - - # Since this is a perl distribution, use the perl-pkg template. - printf("template\nperl-pkg %s\n\n", (-f "$dir/Build.PL" ? "MB" : "MM")); - print("options\n!emptydirs\n\n"); - - printmeta(\%pbvars); - return 0; -} - -# Create the src/ directory and tarball symlink. Then chdir into it. - -sub chsrcdir -{ - my ($srcdir, $distfile) = @_; - - if (-e $srcdir) { - system("rm", "-fr", $srcdir) == 0 or die "failed to rm $srcdir\n"; - } - mkdir $srcdir or die "mkdir $srcdir: $!"; - chdir($srcdir) or die "chdir $srcdir: $!"; - unless(-f $distfile) { - symlink(catfile('..', $distfile), $distfile) or die "symlink $distfile: $!"; - } - - return $srcdir; -} - -sub distinfo -{ - my ($distfile) = @_; - - my @c = split(/-/, $distfile); - my $ver = pop(@c); - my $name = join(q{-}, @c); - my $mod = $name; - $mod =~ s/-/::/g; - return { 'name' => $name, 'ver' => $ver, 'mod' => $mod }; -} - -sub extractdist -{ - my ($file) = @_; - - system("bsdtar -xf $file"); - die "$PROG: bsdtar failed to extract $file\n" unless($? == 0); - - opendir(my $srcdir, '.') or die "opendir: $!"; - my @dirs = grep { -d $_ && !/\A[.]/ } readdir($srcdir); - closedir($srcdir); - - die("$PROG: many dirs (@dirs) inside the tarball $file\n") - if(@dirs > 1); - die("$PROG: no dirs found in tarball $file\n") if(@dirs == 0); - return $dirs[0]; -} - -sub printmeta -{ - my ($pbvars) = @_; - while(my ($name, $val) = each(%$pbvars)) { - if(!defined($val) || $val eq q{}) { - warn("$PROG: warning: $name is undefined\n"); - $val = q{}; - } - print($name, "\n"); - print("$_\n") for (ref $val ? @$val : $val); - print("\n"); - } - - # TODO: autodetect license type - printf("license\n%s\n\n", join("\n", qw/PerlArtistic GPL/)); -} - -sub loadmeta -{ - my ($distdir) = @_; - - for my $metaext (qw/json yml/) { - my $path = "$distdir/META.$metaext"; - next unless -f $path; - - open(my $metafh, '<', $path) or die "open: $!"; - my $meta = do { local $/; <$metafh> }; - close($metafh); - - $meta = ($metaext eq 'json' ? decode_json($meta) : - $metaext eq 'yml' ? YAML::XS::Load($meta) : - die "internal error: unknown \$metaext: $metaext"); - - upgrademeta($meta); - return $meta; - } - - return undef; -} - -sub upgrademeta -{ - my ($meta) = @_; - - return if(exists($meta->{'prereqs'})); - - my $prereqs; - $prereqs->{'configure'}{'requires'} = delete($meta->{'configure_requires'}); - $prereqs->{'build'}{'requires'} = delete($meta->{'build_requires'}); - $prereqs->{'runtime'}{'requires'} = delete($meta->{'requires'}); - - $meta->{'prereqs'} = $prereqs; - return; -} - -sub xsdist -{ - my ($dir) = @_; - my $isxs; - find({ 'wanted' => sub { $isxs = 1 if(/[.]xs$/) }, 'no_chdir' => 1 }, $dir); - return $isxs; -} - -#----------------------------------------------------------------------------- - -sub distdesc -{ - my ($dir, $modname) = @_; - return _poddesc($dir, $modname) || _readmedesc($dir, $modname); -} - -sub _poddesc -{ - my ($dir, $modname) = @_; - - my $podselect = Pod::Select->new; - $podselect->select('NAME'); - - my $modpath = $modname; $modpath =~ s{::}{/}g; - my $moddir = dirname($modpath); - my $modfile = basename($modpath); - - # First check under lib/ for a "properly" pathed module, with - # nested directories. Then search desperately for a .pm file that - # matches the module's last name component. - - my @possible = glob("$dir/{lib/,}{$moddir/,}$modfile.{pod,pm}"); - - PODSEARCH: - for my $podpath (@possible) { - next PODSEARCH unless(-f $podpath); - - # Read the NAME section of the POD into a scalar. - my $namesect = q{}; - open(my $podfile, '<', $podpath) or next PODSEARCH; - open(my $podout, '>', \$namesect) or die "open: $!"; - - $podselect->parse_from_filehandle($podfile, $podout); - - close($podfile); - close($podout) or die "close: $!"; - - next PODSEARCH unless($namesect); - - # Remove formatting codes. - $namesect =~ s{ [IBCLEFSXZ] <(.*?)> }{$1}gxms; - $namesect =~ s{ [IBCLEFSXZ] <<(.*?)>> }{$1}gxms; - - # The short desc is on a line beginning with 'Module::Name - ' - return $1 if($namesect =~ / ^ \s* $modname [ -]+ ([^\n]+) /xms); - } - - return undef; -} - -#---HELPER FUNCTION--- -sub _readmedesc -{ - my ($dir, $modname) = @_; - - my $path = catfile($dir, 'README'); - return undef unless(-f $path); - open(my $fh, '<', $path) or die "open: $!"; - - while (<$fh>) { - chomp; - next unless((/\ANAME/ ... /\A[A-Z]+/) - && / \A \s* ${modname} [\s\-]+ (.+) \z /x); - return $1; - } - - close $fh; - return undef; -} - -#----------------------------------------------------------------------------- - -sub md5sums -{ - return [ map { - open(my $fh, '<', $_) or die "open: $!"; - my $md5 = Digest::MD5->new()->addfile($fh)->hexdigest; - } @_ ] -} - -sub sha512sums -{ - return [ map { - my $sha = Digest::SHA->new(512)->addfile($_)->hexdigest; - } @_ ] -} - -exit main(@ARGV); diff --git a/bin/templ/pbfields b/bin/templ/pbfields deleted file mode 100755 index 247b18c..0000000 --- a/bin/templ/pbfields +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/awk -f - -BEGIN { - fieldstr = "pkgname pkgver pkgrel pkgdesc epoch" \ - " *arch *license *options" \ - " install changelog" \ - " *depends *makedepends *checkdepends *optdepends" \ - " *conflicts *provides" \ - " url *source *noextract *md5sums *sha512sums" - max = split(fieldstr, fields) - for(i=1; i<=max; i++) { - if(sub(/^[*]/, "", fields[i])) arrfield[fields[i]] = 1; - else strfield[fields[i]] = 1; - } - - COLS = 78; FS = "\n"; RS = "" -} - -NF < 2 { next } - -$1 == "packager" { packager = $2 } - -$1 == "maintainer" { maintainer = $2 } - -$1 ~ /depends$|conflicts|provides|source/ { quotevals() } - -$1 == "pkgdesc" { - gsub(/[$"`]/, "\\\\&", $2) - $2 = sprintf("\"%s\"", $2) -} - -strfield[$1] { output[$1] = $2 } - -arrfield[$1] { - output[$1] = wraparray(length($1) + 2) -} - -END { - if(!maintainer && !packager) { packager = "Anonymous" } - if(maintainer) print "# Maintainer: " maintainer - else if(packager) print "# Packager: " packager - print "" - - OFS = "="; ORS = "\n"; - for(i=1; i<=max; i++) { - name = fields[i] - if(name in output) print name, output[name] - } -} - -function wraparray (indent) -{ - if(NF == 1) return "()" # this shouldn't happen but just in case. - - line = "" - delete lines - linecount = 0 - - i = 2 - while(i <= NF) { - linelen = length(line) - - if((indent + linelen + 1 + length($i) > COLS) && linelen > 0) { - lines[++linecount] = line - line = "" - } else { - if(linelen == 0) line = $(i++) - else line = line " " $(i++) - } - } - - if(length(line) > 0) lines[++linecount] = line - - indtxt = sprintf("%" indent "s", "") - txt = "(" lines[1] - for(i=2; i<=linecount; i++) txt = txt "\n" indtxt lines[i] - txt = txt ")" - - return txt -} - -function quotevals () -{ - for(i=2; i<=NF; i++) $i = bashquote($i) -} - -function bashquote (val) -{ - if(val ~ /[$]/) return sprintf("\"%s\"", val) - return sprintf("'%s'", val) -} diff --git a/bin/templ/perl-pkg b/bin/templ/perl-pkg deleted file mode 100755 index e29ba05..0000000 --- a/bin/templ/perl-pkg +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env perl - -use warnings 'FATAL' => 'all'; -use strict; - -my %ACTIONS_OF = - ('MM', { - 'build' => [ q{/usr/bin/perl Makefile.PL}, q{make} ], - 'check' => [ q{make test} ], - 'package' => [ q{make DESTDIR="$pkgdir" install} ] - }, - 'MB', { - 'build' => [ q{/usr/bin/perl Build.PL}, q{./Build} ], - 'check' => [ q{./Build test} ], - 'package' => [ q{./Build install} ] - }); - -my %FUNCFMTS; -$FUNCFMTS{'build'} = <<'END_FMT'; -build() { - ( export PERL_MM_USE_DEFAULT=1 PERL5LIB="" \ - PERL_AUTOINSTALL=--skipdeps \ - PERL_MM_OPT="INSTALLDIRS=vendor DESTDIR='$pkgdir'" \ - PERL_MB_OPT="--installdirs vendor --destdir '$pkgdir'" \ - MODULEBUILDRC=/dev/null - - cd "$_distdir" -%s - ) -} -END_FMT - -$FUNCFMTS{'check'} = <<'END_FMT'; -check() { - ( export PERL_MM_USE_DEFAULT=1 PERL5LIB="" - cd "$_distdir" -%s - ) -} -END_FMT - -$FUNCFMTS{'package'} = <<'END_FMT'; -package() { - cd "$_distdir" -%s - find "$pkgdir" -name .packlist -o -name perllocal.pod -delete -} -END_FMT - -my $PBEND = <<'END_END'; -# Local Variables: -# mode: shell-script -# sh-basic-offset: 2 -# End: -# vim:set ts=2 sw=2 et: -END_END - -# Convert actions array into lines of bash to insert into template. -sub bashify -{ - my (@lines) = @_; - my $txt = join qq{\n}, map { s/^/ /gm; $_ } @lines; - return $txt -} - -sub mungevars -{ - my ($vars) = @_; - $vars->{'options'} = [ '!emptydirs' ]; - - # Replace version string in 'source' entry & 'distdir' with - # $pkgver parameter. - for my $v (qw/pkgver distdir/) { - die "$0: $v is undefined" unless defined $vars->{$v}[0]; - } - my $ver = $vars->{'pkgver'}[0]; - s/\Q$ver\E/\${pkgver}/g for ($vars->{'source'}[0], $vars->{'distdir'}[0]); - - return; -} - -sub printpb -{ - my ($btype, $pbvars) = @_; - my $acts = $ACTIONS_OF{$btype} - or die "$0: unknown build type ($btype)\n"; - - my $distdir = $pbvars->{'distdir'}[0]; - print qq{_distdir="\${srcdir}/$distdir"\n}; - print "\n"; - - for my $func (qw/build check package/) { - my $funclines = $acts->{$func}; - printf $FUNCFMTS{$func}, bashify(@$funclines); - print "\n"; - } - print $PBEND; -} - -sub readvars -{ - local $/ = ""; # split records on empty lines - my (%pbvars); - while (<STDIN>) { - my ($name, @vals) = split /\n/; - $pbvars{$name} = [ @vals ]; - } - return \%pbvars; -} - -sub main -{ - my ($type) = @_; - my $vars = readvars(); - mungevars($vars); - printpb($type, $vars); -} - -my $type = shift or die qq{$0: please provide "MM" or "MB" as argument\n}; -main($type); |