summaryrefslogtreecommitdiffstats
path: root/bin/makepkgbuild
blob: f2469bf42381df4eff03f89210939cbea286e372 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh

prog=makepkgbuild

appendpb()
{
	txt=$(awk -v f=$1 'BEGIN { FS = "\n"; RS = "" }
		$1 ~ "^" f "[(][)]<?$" { for (i = 2; i <= NF; i++) print $i }' \
		PKGMETA | sed 's/^/	   /')

	case "$txt" in
	'')	return 0 ;;
	*)	echo "/^ *${func}()[ \\n]*{
/^}
i
$txt
.
wq
" | ed PKGBUILD >/dev/null 2>&1
		return $? ;;
	esac
}

prependpb()
{
	txt=$(awk -v f=$1 'BEGIN { FS = "\n"; RS = "" }
		$1 == ">" f "()" { for (i = 2; i <= NF; i++) print $i }' \
        PKGMETA | sed 's/^/    /')

	case "$txt" in
	'')	return 0 ;;
	*)	echo "/^ *${func}()[ \\n]*{
/^[ \t]*cd/
a
$txt
.
wq
" | ed PKGBUILD >/dev/null 2>&1
		return $? ;;
	esac
}

if ! [ -r PKGMETA ]
then
	echo "$prog: PKGMETA could not be read." 1>&2
	exit 1
fi

case "$TDIR" in
'')	echo "$prog: TDIR env variable is not set." 1>&2
	exit 1
esac

tcmd=$(awk '
	BEGIN { FS = "\n"; RS = "" }
	$1 == "template" { for (i = 2; i <= NF; i++) print $i }' PKGMETA \
	| while read line
	do
		set -- $line
		cmd="$TDIR/$1"
		if ! [ -x $cmd ]
		then
			echo "$prog: Unknown template command: $cmd" 1>&2
			exit 2
		fi
		echo "$TDIR/$*"
	done \
	| tr '\n' '|' | sed 's/[|]$//')

"$TDIR/pbfields" <PKGMETA >PKGBUILD
$tcmd <PKGMETA >>PKGBUILD

for func in package check build
do
	if ! appendpb $func
	then
		echo "$prog: error when trying to append to ${func}()" 1>&2
		exit 2
	fi
	if ! prependpb $func
	then
		echo "$prog: error when trying to prepend to ${func}()" 1>&2
		exit 2
	fi
done