xref: /openbsd/distrib/miniroot/list2sh.awk (revision 5af055cd)
1#	$OpenBSD: list2sh.awk,v 1.21 2014/02/21 19:14:23 deraadt Exp $
2
3BEGIN {
4	printf("cd ${OBJDIR}\n");
5	printf("\n");
6}
7/^$/ || /^#/ {
8	print $0;
9	next;
10}
11$1 == "COPY" {
12	printf("echo '%s'\n", $0);
13	printf("test -f ${TARGDIR}/%s && rm -fr ${TARGDIR}/%s\n", $3, $3);
14	printf("cp %s ${TARGDIR}/%s\n", $2, $3);
15	next;
16}
17$1 == "REMOVE" {
18	printf("echo '%s'\n", $0);
19	printf("rm -f ${TARGDIR}/%s\n", $2);
20	next;
21}
22$1 == "STRIP" {
23	printf("echo '%s'\n", $0);
24	printf("test -f ${TARGDIR}/%s && rm -fr ${TARGDIR}/%s\n", $3, $3);
25	printf("cp %s ${TARGDIR}/%s\n", $2, $3);
26	printf("strip ${TARGDIR}/%s\n", $3);
27	next;
28}
29$1 == "LINK" {
30	printf("echo '%s'\n", $0);
31	for (i = 3; i <= NF; i++) {
32		printf("test -f ${TARGDIR}/%s && rm -f ${TARGDIR}/%s\n", $i, $i);
33		printf("(cd ${TARGDIR}; ln %s %s)\n", $2, $i);
34	}
35	next;
36}
37$1 == "SYMLINK" {
38	printf("echo '%s'\n", $0);
39	for (i = 3; i <= NF; i++) {
40		printf("test -f ${TARGDIR}/%s && rm -f ${TARGDIR}/%s\n", $i, $i);
41		printf("(cd ${TARGDIR}; ln -s %s %s)\n", $2, $i);
42	}
43	next;
44}
45$1 == "ARGVLINK" {
46	# crunchgen directive; ignored here
47	next;
48}
49$1 == "SRCDIRS" {
50	# crunchgen directive; ignored here
51	next;
52}
53$1 == "LIBS" {
54	# crunchgen directive; ignored here
55	next;
56}
57$1 == "CRUNCHSPECIAL" {
58	# crunchgen directive; ignored here
59	next;
60}
61$1 == "TZ" {
62	printf("echo '%s'\n", $0);
63	printf("(cd ${TARGDIR}; sh $UTILS/maketz.sh $DESTDIR)\n");
64	next;
65}
66$1 == "COPYDIR" {
67	printf("echo '%s'\n", $0);
68	printf("(cd ${TARGDIR}/%s && find . ! -name . | xargs /bin/rm -rf)\n",
69	    $3);
70	printf("(cd %s && pax -pe -rw . ${TARGDIR}/%s)\n", $2, $3);
71	next;
72}
73$1 == "SPECIAL" {
74# escaping shell quotation is ugly whether you use " or ', use cat <<'!' ...
75	work=$0;
76	gsub("[\\\\]", "\\\\", work);
77	gsub("[\"]", "\\\"", work);
78	gsub("[$]", "\\$", work);
79	gsub("[`]", "\\`", work);
80	printf("echo \"%s\"\n", work);
81	work=$0;
82	sub("^[ 	]*" $1 "[ 	]*", "", work);
83	printf("(cd ${TARGDIR}; %s)\n", work);
84	next;
85}
86$1 == "TERMCAP" {
87# tic -r flag may generate harmless warning about pccon+base:
88#     "terminal 'pccon+base': enter_reverse_mode but no exit_attribute_mode"
89	printf("echo '%s'\n", $0);
90	printf("(cd ${TARGDIR}; tic -C -x -r -e %s ${UTILS}/../../share/termtypes/termtypes.master | sed -e '/^#.*/d' -e '/^$$/d' > %s)\n",
91	    $2, $3);
92	next;
93}
94$1 == "SCRIPT" {
95	printf("echo '%s'\n", $0);
96	printf("sed -e '/^[ 	]*#[ 	].*$/d' -e '/^[ 	]*#$/d' < %s > ${TARGDIR}/%s\n",
97	    $2, $3);
98	next;
99}
100{
101	printf("echo '%s'\n", $0);
102	printf("echo 'Unknown keyword \"%s\" at line %d of input.'\n", $1, NR);
103	printf("exit 1\n");
104	exit 1;
105}
106END {
107	printf("\n");
108	printf("exit 0\n");
109	exit 0;
110}
111