about summary refs log tree commit diff
path: root/scripts/gen-posix-conf-vars.awk
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/gen-posix-conf-vars.awk')
-rw-r--r--scripts/gen-posix-conf-vars.awk28
1 files changed, 28 insertions, 0 deletions
diff --git a/scripts/gen-posix-conf-vars.awk b/scripts/gen-posix-conf-vars.awk
index 16e20fc100..0eca55d536 100644
--- a/scripts/gen-posix-conf-vars.awk
+++ b/scripts/gen-posix-conf-vars.awk
@@ -15,12 +15,19 @@ $1 ~ /^#/ || $0 ~ /^\s*$/ {
 $NF == "{" {
   type = $1
   prefix = $2
+
+  if (NF == 4)
+    sc_prefix = $3
+  else
+    sc_prefix = "_SC"
+
   next
 }
 
 $1 == "}" {
   prefix = ""
   type = ""
+  sc_prefix = ""
   next
 }
 
@@ -35,6 +42,7 @@ $1 == "}" {
   # CONFSTR: A configuration string
   # SYSCONF: A numeric value
   # SPEC: A specification
+  sc_prefixes[prefix][$1] = sc_prefix
   conf[prefix][$1] = type
 }
 
@@ -56,6 +64,26 @@ END {
 	printf "# endif\n"
       }
       printf "#endif\n\n"
+
+      # Build a name -> sysconf number associative array to print a C array at
+      # the end.
+      if (conf[p][c] == "SPEC") {
+	name = sprintf ("%s_%s", p, c)
+	num = sprintf ("%s_%s", sc_prefixes[p][c], c)
+	spec[name] = num
+      }
     }
   }
+
+  # Print the specification array.  Define the macro NEED_SPEC_ARRAY before
+  # including posix-conf-vars.h to make it available in the compilation unit.
+  print "#if NEED_SPEC_ARRAY"
+  print "static const struct { const char *name; int num; } specs[] ="
+  print "  {"
+  for (s in spec) {
+    printf "    { \"%s\", %s },\n", s, spec[s]
+  }
+  print "  };"
+  print "static const int nspecs = sizeof (specs) / sizeof (specs[0]);"
+  print "#endif"
 }