]> git.ipfire.org Git - thirdparty/glibc.git/blob - scripts/gen-tunables.awk
Restore clock_* librt exports for MicroBlaze (bug 21061).
[thirdparty/glibc.git] / scripts / gen-tunables.awk
1 # Generate dl-tunable-list.h from dl-tunables.list
2
3 BEGIN {
4 tunable=""
5 ns=""
6 top_ns=""
7 }
8
9 # Skip over blank lines and comments.
10 /^#/ {
11 next
12 }
13
14 /^[ \t]*$/ {
15 next
16 }
17
18 # Beginning of either a top namespace, tunable namespace or a tunable, decided
19 # on the current value of TUNABLE, NS or TOP_NS.
20 $2 == "{" {
21 if (top_ns == "") {
22 top_ns = $1
23 }
24 else if (ns == "") {
25 ns = $1
26 }
27 else if (tunable == "") {
28 tunable = $1
29 }
30 else {
31 printf ("Unexpected occurrence of '{': %s:%d\n", FILENAME, FNR)
32 exit 1
33 }
34
35 next
36 }
37
38 # End of either a top namespace, tunable namespace or a tunable.
39 $1 == "}" {
40 if (tunable != "") {
41 # Tunables definition ended, now fill in default attributes.
42 if (!types[top_ns][ns][tunable]) {
43 types[top_ns][ns][tunable] = "STRING"
44 }
45 if (!minvals[top_ns][ns][tunable]) {
46 minvals[top_ns][ns][tunable] = "0"
47 }
48 if (!maxvals[top_ns][ns][tunable]) {
49 maxvals[top_ns][ns][tunable] = "0"
50 }
51 if (!env_alias[top_ns][ns][tunable]) {
52 env_alias[top_ns][ns][tunable] = "NULL"
53 }
54 if (!is_secure[top_ns][ns][tunable]) {
55 is_secure[top_ns][ns][tunable] = "false"
56 }
57
58 tunable = ""
59 }
60 else if (ns != "") {
61 ns = ""
62 }
63 else if (top_ns != "") {
64 top_ns = ""
65 }
66 else {
67 printf ("syntax error: extra }: %s:%d\n", FILENAME, FNR)
68 exit 1
69 }
70 next
71 }
72
73 # Everything else, which could either be a tunable without any attributes or a
74 # tunable attribute.
75 {
76 if (ns == "") {
77 printf("Line %d: Invalid tunable outside a namespace: %s\n", NR, $0)
78 exit 1
79 }
80
81 if (tunable == "") {
82 # We encountered a tunable without any attributes, so note it with a
83 # default.
84 types[top_ns][ns][$1] = "STRING"
85 next
86 }
87
88 # Otherwise, we have encountered a tunable attribute.
89 split($0, arr, ":")
90 attr = gensub(/^[ \t]+|[ \t]+$/, "", "g", arr[1])
91 val = gensub(/^[ \t]+|[ \t]+$/, "", "g", arr[2])
92
93 if (attr == "type") {
94 types[top_ns][ns][tunable] = val
95 }
96 else if (attr == "minval") {
97 minvals[top_ns][ns][tunable] = val
98 }
99 else if (attr == "maxval") {
100 maxvals[top_ns][ns][tunable] = val
101 }
102 else if (attr == "env_alias") {
103 env_alias[top_ns][ns][tunable] = sprintf("\"%s\"", val)
104 }
105 else if (attr == "is_secure") {
106 if (val == "true" || val == "false") {
107 is_secure[top_ns][ns][tunable] = val
108 }
109 else {
110 printf("Line %d: Invalid value (%s) for is_secure: %s, ", NR, val,
111 $0)
112 print("Allowed values are 'true' or 'false'")
113 exit 1
114 }
115 }
116 }
117
118 END {
119 if (ns != "") {
120 print "Unterminated namespace. Is a closing brace missing?"
121 exit 1
122 }
123
124 print "/* AUTOGENERATED by gen-tunables.awk. */"
125 print "#ifndef _TUNABLES_H_"
126 print "# error \"Do not include this file directly.\""
127 print "# error \"Include tunables.h instead.\""
128 print "#endif"
129
130 # Now, the enum names
131 print "\ntypedef enum"
132 print "{"
133 for (t in types) {
134 for (n in types[t]) {
135 for (m in types[t][n]) {
136 printf (" TUNABLE_ENUM_NAME(%s, %s, %s),\n", t, n, m);
137 }
138 }
139 }
140 print "} tunable_id_t;\n"
141
142 # Finally, the tunable list.
143 print "\n#ifdef TUNABLES_INTERNAL"
144 print "static tunable_t tunable_list[] = {"
145 for (t in types) {
146 for (n in types[t]) {
147 for (m in types[t][n]) {
148 printf (" {TUNABLE_NAME_S(%s, %s, %s)", t, n, m)
149 printf (", {TUNABLE_TYPE_%s, %s, %s}, {.numval = 0}, NULL, %s, %s},\n",
150 types[t][n][m], minvals[t][n][m], maxvals[t][n][m],
151 is_secure[t][n][m], env_alias[t][n][m]);
152 }
153 }
154 }
155 print "};"
156 print "#endif"
157 }