1#	$MirOS: src/distrib/common/makeconf.awk,v 1.2 2010/08/14 20:53:09 tg Exp $
2#	$OpenBSD: makeconf.awk,v 1.14 2003/12/16 22:41:40 henning Exp $
3#	$NetBSD: makeconf.awk,v 1.3 1996/05/04 15:45:32 pk Exp $
4
5#
6# generate crunchgen(1) configuration file from `list' spec.
7#
8
9BEGIN {
10	printf("#\n# This file is automatically generated by `makeconf'\n#\n\n");
11	libs = "libs -lutil -locurses -lm -lkvm -lz -lmbfun";
12}
13
14$1 == "LIBS" {
15	$1 = tolower($1);
16	libs = $0;
17}
18
19$1 == "SRCDIRS" {
20	$1 = tolower($1);
21	print;
22}
23
24($1 == "LINK" || $1 == "SYMLINK") && index($2,CBIN) {
25	# find basenames for inclusion in crunchgen's `prog' and `ln' directives
26	n = split($3, x, "/");
27	p = x[n];
28	progs[p] = NF - 3;
29	for (i = 4; i <= NF; i++) {
30		n = split($i, x, "/");
31		l = x[n];
32		links[i - 3, p] = l;
33	}
34}
35
36$1 == "ARGVLINK" {
37	# add extra `ln' entries (these don't appear in the filesystem)
38	n = progs[$2];
39	progs[$2] = ++n;
40	links[n, $2] = $3;
41}
42
43$1 == "CRUNCHSPECIAL" {
44	# collect crunchgen `special' directives
45	$1 = "";
46	specials[$0] = 1;
47}
48
49END {
50	# write crunchgen configuration
51
52	# `prog' directives; print 8 to a line
53	column = 0;
54	for (p in progs) {
55		if ((column++ % 8) == 0)
56			printf("\nprogs");
57		printf(" %s", p);
58	}
59	printf("\n\n");
60
61	# `ln' directives
62	for (p in progs) {
63		n = progs[p];
64		for (i = 1; i <= n; i++)
65			printf("ln %s %s\n", p, links[i,p]);
66	}
67	printf("\n%s\n\n", libs);
68
69	# `special' directives
70	for (s in specials) {
71		printf("special %s\n", s);
72	}
73}
74