summaryrefslogtreecommitdiffstats
path: root/templ
diff options
context:
space:
mode:
authorJustin Davis <jrcd83@gmail.com>2012-01-16 00:30:11 +0100
committerJustin Davis <jrcd83@gmail.com>2012-01-16 00:30:11 +0100
commit44f4b5d167f9efef47786e60d1153ad2c58b4319 (patch)
tree3e7e30f87123c48629faa73d29e0c20af869c43c /templ
parentf6cbce0d137f44554a233b4adf9022df6dc7fde9 (diff)
downloadgenpkg-44f4b5d167f9efef47786e60d1153ad2c58b4319.tar.gz
genpkg-44f4b5d167f9efef47786e60d1153ad2c58b4319.tar.xz
Move metas/ and templ/ under ~/.genpkg.
Diffstat (limited to 'templ')
-rwxr-xr-xtempl/pbfields99
-rwxr-xr-xtempl/perl-pkg121
2 files changed, 220 insertions, 0 deletions
diff --git a/templ/pbfields b/templ/pbfields
new file mode 100755
index 0000000..5e7844c
--- /dev/null
+++ b/templ/pbfields
@@ -0,0 +1,99 @@
+#!/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)
+}
+
+$1 == "pkgverfmt" { pkgverfmt = $2 }
+
+strfield[$1] { output[$1] = $2 }
+
+arrfield[$1] {
+ output[$1] = wraparray(length($1) + 2)
+}
+
+END {
+ if(pkgverfmt){
+ output["pkgver"] = sprintf(pkgverfmt, output["pkgver"])
+ }
+
+ 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/templ/perl-pkg b/templ/perl-pkg
new file mode 100755
index 0000000..47cc682
--- /dev/null
+++ b/templ/perl-pkg
@@ -0,0 +1,121 @@
+#!/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);
+ return 0;
+}
+
+my $type = shift or die qq{$0: please provide "MM" or "MB" as argument\n};
+exit main($type);