summaryrefslogtreecommitdiffstats
path: root/bin/pbj
blob: ac926b6a9a50f46a936eb7d7e9868298814b0887 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh

VERSION=0.01

die() {
    echo "error: $1"
    exit 1
}

if [ -z "$1" ] ; then
    die "Usage: $0 [package name]"
fi

if [ "$PBJROOT" ] ; then
    cd "$PBJROOT"
fi

bindir="$(pwd)/bin"
if [ ! -d "$bindir" ] ; then
    die "$bindir does not exist"
fi
PATH="$PATH:$bindir"

pkgroot="$(pwd)/pkg"
if [ ! -d "$pkgroot" ] ; then
    die "$pkgroot does not exist"
fi

jamdir="$(pwd)/pbj"
if [ ! -d "$jamdir" ] ; then
    die "$jamdir does not exist"
fi

jamfile="$jamdir/$1.pbj"
if [ ! -f "$jamfile" ] ; then
    die "$jamfile is missing"
fi

pkg=$1
rm -rf "$pkgroot/$pkg"
mkdir "$pkgroot/$pkg"
cd "$pkgroot/$pkg"

export PATH="$PATH:$bindir/macros:$bindir/templ"

# Provide values for things macros won't be able to.
printf "+ pbjver $VERSION\n+ pkgrel ${PKGREL:-1}\n" \
    | cat - "$jamfile" \
    | awk -v packager="$PACKAGER" -f "$bindir/pbjparse.awk" \
    > PKGBUILD

if [ $? -ne 0 ] ; then
    echo "Failed to write $pkgroot/$pkg/PKGBUILD"
    exit $?
fi

echo "Wrote $pkgroot/$pkg/PKGBUILD."
exit 0