summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/emitpkgtree58
-rwxr-xr-xbin/genpkg27
-rw-r--r--bin/mergepbfields0
-rwxr-xr-xbin/mkpkgbuild71
-rwxr-xr-xbin/mkpkgdata84
-rwxr-xr-xbin/mkpkgmeta67
-rw-r--r--bin/modpkgmeta0
-rwxr-xr-xbin/pbfields99
-rwxr-xr-xbin/tweakmeta118
9 files changed, 231 insertions, 293 deletions
diff --git a/bin/emitpkgtree b/bin/emitpkgtree
new file mode 100755
index 0000000..ca12c59
--- /dev/null
+++ b/bin/emitpkgtree
@@ -0,0 +1,58 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+
+my $PROG = 'flatlntree';
+
+sub parsetree
+{
+ my($name) = @_;
+ my($txt, $ln, @tree) = (q{}, $., $name);
+ while(<STDIN>){
+ if(/^BEGNODE (\S+)$/){
+ push @tree, $txt if($txt);
+ push @tree, parsetree($1);
+ $txt = q{};
+ }elsif(/^ENDNODE (\S+)$/){
+ if($1 ne $name){
+ print STDERR "$PROG: wrong ENDNODE:"
+ . qq{ '$1' at line $.}
+ . qq{ (in '$name' started at line $ln)\n};
+ exit 101;
+ }else{
+ last;
+ }
+ }else{
+ $txt .= $_;
+ }
+ }
+
+ push @tree, $txt if($txt);
+ return \@tree;
+}
+
+sub flatten
+{
+ my($tree) = @_;
+ if(ref $tree){
+ # skip name
+ return join q{}, map { flatten($tree->[$_]) } 1 .. $#$tree;
+ }else{
+ return $tree;
+ }
+}
+
+sub main
+{
+ my $top = parsetree('TOP');
+ @$top = grep { ref } @$top; # only keep sub-nodes
+ for my $n (@$top){
+ my $name = $n->[0];
+ print ">>> $name\n";
+ print flatten($n);
+ }
+ return 0;
+}
+
+exit main();
diff --git a/bin/genpkg b/bin/genpkg
index c88dd84..513fa9e 100755
--- a/bin/genpkg
+++ b/bin/genpkg
@@ -39,33 +39,20 @@ do
[ -d "$pkgd/$pkg" ] || mkdir "$pkgd/$pkg"
cd "$pkgd/$pkg"
- echo "$pkgd/$pkg"
- if METABIN="$metad" PKGVAR="$vard" mkpkgdata "$pkg" > PKGDATA
+ if METABIN="$metad" PKGVAR="$vard" mkpkgmeta "$pkg"
then
- echo PKGDATA
+ echo "$pkgd/$pkg"
+ echo "Generated PKGDATA and PKGTREE." 1>&2
else
exit $?
fi
twk="$tweakd/$pkg"
- if [ -f "$twk" -a -r "$twk" ]
+ if [ -f "$twk" -a -r "$twk" ] && modpkgmeta
then
- if ! tweakmeta < "$twk" > PKGDATA.new
- then
- echo "$prog: tweakmeta returned error: $?" 1>&2
- rm PKGDATA.new
- exit 1
- fi
- mv PKGDATA.new PKGDATA
- echo "Tweaked PKGDATA with $twk." 1>&2
+ echo "Modified metapackage." 1>&2
fi
- if TDIR="$templd" mkpkgbuild
- then
- echo PKGBUILD
- else
- exit $?
- fi
-
- echo
+ mergepbfields | emitpkgtree || exit $?
done
+
diff --git a/bin/mergepbfields b/bin/mergepbfields
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bin/mergepbfields
diff --git a/bin/mkpkgbuild b/bin/mkpkgbuild
deleted file mode 100755
index 490a27a..0000000
--- a/bin/mkpkgbuild
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/bin/sh
-
-prog=mkpkgbuild
-
-die()
-{
- rc=$1; shift
- echo "$prog: $*" 1>&2
- exit $rc
-}
-
-editpb()
-{
- op=$1 func=$2
-
- case "$op" in
- append)
- regexp="^${func}[(][)]<?$"
- edin="/^ *$func() *{
-/^}
-i" ;;
- prepend)
- regexp=">${func}()"
- edin="/^ *$func() *{
-/^[ \t]*cd/
-a" ;;
- *) die 1 "unknown editpb operation: $op"
- esac
-
- txt=$(awk -v r="$regexp" 'BEGIN { FS = "\n"; RS = "" }
- $1 ~ r { for (i = 2; i <= NF; i++) print $i }' PKGDATA |\
- sed 's/^/ /')
- [ "$txt" ] || return 0
-
- cat << END | ed -s PKGBUILD >/dev/null
-$edin
-$txt
-.
-wq
-END
- return $?
-}
-
-[ -r PKGDATA ] || die 1 "PKGDATA could not be read."
-
-[ "$TDIR" ] || die 1 "TDIR env. var is unset."
-[ -d "$TDIR" ] || die 1 "template dir ($TDIR) not found."
-
-tcmd=$(awk 'BEGIN { FS="\n"; RS="" } $1 == "template" { print $2 }' PKGDATA)
-[ "$tcmd" ] || die 1 "PKGDATA is missing 'template' entry."
-
-set -- $tcmd
-cmd="$TDIR/$1"
-[ -f "$cmd" -a -x "$cmd" ] \
- || die 2 "template command ($1) not in template dir ($TDIR)"
-
-# Generate the PKGBUILD using basic pbfields script plus custom template.
-"$TDIR/pbfields" < PKGDATA > PKGBUILD || die 1 "pbfields returned error ${?}."
-"$TDIR"/$tcmd < PKGDATA >> PKGBUILD || die 1 "template pipeline ($tcmd) failed"
-
-# Prepand/append text to the package, check, or build functions.
-for func in package check build
-do
- for op in append prepend
- do
- editpb $op $func \
- || die 2 "error $? when trying to $op to ${func}()"
- done
-done
-
-exit 0
diff --git a/bin/mkpkgdata b/bin/mkpkgdata
deleted file mode 100755
index f330894..0000000
--- a/bin/mkpkgdata
+++ /dev/null
@@ -1,84 +0,0 @@
-#!/bin/sh
-
-prog=mkpkgdata
-
-lazysource()
-{
- awk -v prog="$prog" '
-BEGIN { FS = "\n"; RS = ""; OFS = ORS = "\n\n" }
-$1 == "pkgver" { ver = $2 }
-$1 == "source" {
- len = NF - 1
- for(i = 2; i <= NF; i++) sources[i - 1] = $i
- next
-}
-1 # print everything but sources
-
-END {
- # remember that metas emit no output when they cant match
- # a package.
- if(NR == 0 || !ver) exit 2
-
- ORS="\n"
-
- # Replace any version strings in the source file with ${pkgver}.
- gsub(/[.]/, "\\\\&", ver)
-
- print "source"
- for(i = 1; i <= len; i++){
- gsub(ver, "${pkgver}", sources[i])
- print sources[i]
- }
- print ""
-}'
- return $?
-} # end of lazysource()
-
-basicmeta()
-{
- printf "pkgname\n%s\n\n" "$1"
- printf "pkgrel\n%d\n\n" "${PKGREL:-1}"
- printf "packager\n%s\n\n" "${PACKAGER:-Anonymous}"
-
- if [ "$MAINTAINER" ]
- then
- printf "maintainer\n%s\n\n" "$MAINTAINER"
- fi
-}
-
-case $# in
-0) echo "usage: $prog [package name]" 1>&2
- exit 1
-esac
-
-case "$METABIN" in
-'') echo "$prog: set METABIN before calling $prog" 1>&2
- exit 1
-esac
-
-tmp="/tmp/$prog.$$"
-for flav in "$METABIN"/*
-do
- [ -f "$flav" -a -x "$flav" ] || continue
- trap 'rm "$tmp"' 1 2 15
- PATH="$PATH:$flav.d" "$flav" "$1" > "$tmp"
- metaret=$?
- case "$metaret" in
- 0) basicmeta "$1"
- lazysource < "$tmp"
- esac
-
- rm "$tmp"
- trap '' 1 2 5
- case "$metaret" in
- 0) exit 0 ;;
- 1) echo "$prog: $flav encountered an error" 1>&2
- exit 1 ;;
- 2) ;; # loop
- *) echo "$prog: $flav returned error code $metaret" 1>&2
- exit 1 ;;
- esac
-done
-
-echo "$prog: no matching meta generator found for '$1'" 1>&2
-exit 1
diff --git a/bin/mkpkgmeta b/bin/mkpkgmeta
new file mode 100755
index 0000000..2296a28
--- /dev/null
+++ b/bin/mkpkgmeta
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+prog=mkpkgmeta
+
+err()
+{
+ echo "$prog: $*" 1>&2
+ exit 1
+}
+
+basicmeta()
+{
+ printf "pkgname\n%s\n\n" "$pkgname"
+ printf "pkgrel\n%d\n\n" "${PKGREL:-1}"
+ printf "packager\n%s\n\n" "${PACKAGER:-Anonymous}"
+
+ if [ "$MAINTAINER" ]
+ then
+ printf "maintainer\n%s\n\n" "$MAINTAINER"
+ fi
+
+ return 0
+}
+
+prependmeta()
+{
+ if basicmeta | cat - "$1" > "$1.new"
+ then
+ mv "$1.new" "$1"
+ return 0
+ else
+ rm "$1.new"
+ return 1
+ fi
+}
+
+case $# in
+0) echo "usage: $prog [package name]" 1>&2
+ exit 1
+esac
+
+case "$METABIN" in
+'') err "set METABIN before calling $prog"
+esac
+
+tmp="/tmp/$prog.$$"
+for flav in "$METABIN"/*
+do
+ pkgname="$1"
+ [ -f "$flav" -a -x "$flav" ] || continue
+ PATH="$PATH:$flav.d" "$flav" "$pkgname"
+ metaret=$?
+
+ case "$metaret" in
+ 0) if prependmeta PKGDATA
+ then
+ exit 0
+ else
+ err "failed to prepend to PKGDATA"
+ fi ;;
+ 1) err "$flav encountered an error" ;;
+ 2) ;; # loop
+ *) err "$flav returned error code $metaret" ;;
+ esac
+done
+
+err "no matching meta generator found for '$1'"
diff --git a/bin/modpkgmeta b/bin/modpkgmeta
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bin/modpkgmeta
diff --git a/bin/pbfields b/bin/pbfields
new file mode 100755
index 0000000..5e7844c
--- /dev/null
+++ b/bin/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/bin/tweakmeta b/bin/tweakmeta
deleted file mode 100755
index 75198a2..0000000
--- a/bin/tweakmeta
+++ /dev/null
@@ -1,118 +0,0 @@
-#!/usr/bin/awk -f
-##
-# tweakmeta
-#
-# First read a PKGDATA file in the current directory, loading its values.
-# Next read a PKGTWEAK file from standard input.
-# The PKGTWEAK file tells us how to modify the PKGDATA data.
-# The modified PKGDATA is printed to standard output.
-#
-# Justin Davis <jrcd83@gmail.com>
-
-BEGIN {
- PROG = "tweakmeta"
- if (system("test -r PKGDATA") != 0) {
- print PROG ": PKGDATA file could not be read." | "cat 1>&2"
- exit(errcode = 2)
- }
-
- FS = "\n"; RS = ""
- while (getline<"PKGDATA" > 0)
- for (i = 2; i <= NF; i++) pushval($1, $i)
- close("PKGDATA")
- FS = " "; RS = "\n"
-}
-
-{ sub(/#.*/, "") }
-
-$1 == "+" { pushval($2, joinfields(3)); next }
-
-$1 == "-" { remval($2, $3); next }
-
-$1 == "<" {
- i = findval($2, $3)
- stack[++stacklen] = pbvars[$2, i]
- remelem($2, i)
- next
-}
-
-$1 == ">" {
- if (stacklen < 1)
- die("No values on the stack. Make sure you use '<' first.")
- pushval($2, stack[stacklen--])
- next
-}
-
-$1 == "=" {
- if ($2 == "optdepends") die("cannot use '=' with optdepends.")
- remall($2)
- for (i=3; i<=NF; i++) pushval($2, $i)
- next
-}
-
-# ignore lines of whitespace
-$1 !~ /^[ \t]*$/ { die("invalid input: " $0) }
-
-END {
- if (errcode) exit(errcode)
-
- OFS = "\n"
-
- for (name in pbcount) {
- len = pbcount[name]
- if (len == 0) continue
-
- print name
- for (i=1; i<=len; i++) print pbvars[name, i]
- print ""
- }
-}
-
-function die (msg)
-{
- printf "%s: error line %d: %s\n", PROG, FNR, msg | "cat 1>&2"
- exit(errcode = 1)
-}
-
-function joinfields (start, msg)
-{
- msg = $(start++)
- while (start <= NF) msg = msg " " $(start++)
- return msg
-}
-
-function remall (field)
-{
- pbcount[field] = 0
-}
-
-function pushval (field, val)
-{
- pbvars[field, ++pbcount[field]] = val
-}
-
-function remval (field, prefix)
-{
- remelem(field, findval(field, prefix))
-}
-
-function remelem (field, i, len)
-{
- # TODO: error check if "i" is in bounds?
- len = pbcount[field]
- for (len = pbcount[field]; i < len; i++)
- pbvars[field, i] = pbvars[field, i+1]
- delete pbvars[field, i]
- pbcount[field]--
-}
-
-function findval (field, prefix, i, len)
-{
- len = pbcount[field]
- if (len == 0) die(field " is empty!")
-
- for (i = 1; i <= len; i++)
- if (index(pbvars[field,i], prefix) == 1) break
- if (i > len) die("could not find " prefix " in " field "'s values")
- return i
-}