summaryrefslogtreecommitdiffstats
path: root/bin/makepkgbuild
blob: 33b22169d355798760f2a0a4d08e69922523ba38 (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
#!/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
' | tee dbg | 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: failed to append to the ${func}() function in PKGBUILD" 1>&2
		exit 2
	fi
done