1#!/usr/bin/awk
2/^[^#]/ {
3	gsub(/^\./,"", $1)
4	uname = gname = mode = flags = tags = type = ""
5	for (i=2; i<=NF; i++) {
6		if ($i ~ /^uname=/) {
7			uname=$i
8			gsub(/uname=/, "", uname)
9		} else if ($i ~ /^gname=/) {
10			gname=$i
11			gsub(/gname=/, "", gname)
12		} else if ($i ~ /^mode=/) {
13			mode=$i
14			gsub(/mode=/,"", mode)
15		} else if ($i ~ /^flags=/) {
16			flags=$i
17			gsub(/flags=/, "", flags)
18		} else if ($i ~ /^tags=/) {
19			tags=$i
20			gsub(/tags=/, "", tags)
21		} else if ($i ~ /^type=dir/) {
22			type="dir"
23		}
24	}
25	if (kernel != "") {
26		tags="package=kernel"
27		if (_kernconf != "") {
28			tags=tags""_kernconf
29		}
30	}
31	if (length(tags) == 0)
32		next
33	if (tags ~ /package=/) {
34		ext = pkgname = pkgend = ""
35		split(tags, a, ",");
36		for (i in a) {
37			if (a[i] ~ /^package=/) {
38				pkgname=a[i]
39				gsub(/package=/, "", pkgname)
40			} else if (a[i] == "config") {
41				type="config"
42			} else if (a[i] == "development" || a[i] == "profile" || a[i] == "debug" || a[i] == "docs") {
43				pkgend=a[i]
44			} else {
45				if (ext != "")
46					ext=ext"-"a[i]
47				else
48					ext=a[i]
49			}
50		}
51		if (ext != "") {
52			pkgname=pkgname"-"ext
53		}
54		if (pkgend != "") {
55			if (pkgend == "docs") {
56				pkgname=pkgend
57			} else {
58				pkgname=pkgname"-"pkgend
59			}
60		}
61	} else {
62		print "No packages specified in line: $0"
63		next
64	}
65	if (kernel != "") {
66		output="kernel"
67		if (_kernconf != "") {
68			output=output"."_kernconf
69		}
70		if ($1 ~ /^\/usr\/lib\/debug\/boot/) {
71			output=output"-debug.plist"
72		} else {
73			output=output".plist"
74		}
75	} else {
76		output=pkgname".plist"
77	}
78
79	print "@"type"("uname","gname","mode","flags") " $1 > output
80}
81