1141858Sgshapiro#	$OpenBSD: makeconf.awk,v 1.28 2019/06/07 14:38:42 deraadt Exp $
2141858Sgshapiro
3261363Sgshapiro#
4141858Sgshapiro# generate crunchgen(1) configuration file from `list' spec.
5141858Sgshapiro#
6141858Sgshapiro
7141858SgshapiroBEGIN {
8141858Sgshapiro	printf("#\n# This file is automatically generated by `makeconf'\n#\n\n");
9141858Sgshapiro	libs = "libs -lstubs -lutil -lm -ltls -lssl -lcrypto -levent -lc -lz";
10141858Sgshapiro}
11141858Sgshapiro
12141858Sgshapiro$1 == "LIBS" {
13266692Sgshapiro	$1 = tolower($1);
14141858Sgshapiro	libs = $0;
15141858Sgshapiro}
16141858Sgshapiro
17141858Sgshapiro$1 == "SRCDIRS" {
18141858Sgshapiro	$1 = tolower($1);
19141858Sgshapiro	print;
20141858Sgshapiro}
21
22($1 == "LINK" || $1 == "SYMLINK") && $2 == "instbin" {
23	# find basenames for inclusion in crunchgen's `prog' and `ln' directives
24	n = split($3, x, "/");
25	p = x[n];
26	progs[p] = NF - 3;
27	for (i = 4; i <= NF; i++) {
28		n = split($i, x, "/");
29		l = x[n];
30		links[i - 3, p] = l;
31	}
32}
33
34$1 == "ARGVLINK" {
35	# add extra `ln' entries (these don't appear in the filesystem)
36	n = progs[$2];
37	progs[$2] = ++n;
38	links[n, $2] = $3;
39}
40
41$1 == "CRUNCHSPECIAL" {
42	# collect crunchgen `special' directives
43	$1 = "";
44	specials[$0] = 1;
45}
46
47END {
48	# write crunchgen configuration
49
50	# `prog' directives; print 8 to a line
51	column = 0;
52	for (p in progs) {
53		if ((column++ % 8) == 0)
54			printf("\nprogs");
55		printf(" %s", p);
56	}
57	printf("\n\n");
58
59	# `ln' directives
60	for (p in progs) {
61		n = progs[p];
62		for (i = 1; i <= n; i++)
63			printf("ln %s %s\n", p, links[i,p]);
64	}
65	printf("\n%s\n\n", libs);
66	printf("libdirs distrib/special/libstubs\n");
67
68	# `special' directives
69	for (s in specials) {
70		printf("special %s\n", s);
71	}
72}
73