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