gen-posix-conf-vars.awk 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Generate posix-conf-vars-def.h with definitions for CONF_DEF{CONF} for each
  2. # configuration variable that getconf or sysconf may use. Currently it is
  3. # equipped only to generate such macros for specification macros and for
  4. # SYSCONF macros in the _POSIX namespace.
  5. BEGIN {
  6. prefix = ""
  7. }
  8. $1 ~ /^#/ || $0 ~ /^\s*$/ {
  9. next
  10. }
  11. # Begin a new prefix.
  12. $NF == "{" {
  13. type = $1
  14. prefix = $2
  15. if (NF == 4)
  16. sc_prefix = $3
  17. else
  18. sc_prefix = "_SC"
  19. next
  20. }
  21. $1 == "}" {
  22. prefix = ""
  23. type = ""
  24. sc_prefix = ""
  25. next
  26. }
  27. {
  28. if (prefix == "" && type == "" && sc_prefix == "") {
  29. printf ("Syntax error at %s:%d\n", FILENAME, FNR) > "/dev/stderr"
  30. exit 1
  31. }
  32. # The prefix and variable names are indices and the value indicates what type
  33. # of variable it is. The possible options are:
  34. # CONFSTR: A configuration string
  35. # SYSCONF: A numeric value
  36. # SPEC: A specification
  37. c = prefix "_" $1
  38. sc_prefixes[c] = sc_prefix
  39. prefix_conf[c] = type
  40. conf[c] = $1
  41. }
  42. END {
  43. print "/* AUTOGENERATED by gen-posix-conf-vars.awk. DO NOT EDIT. */\n"
  44. # Generate macros that specify if a sysconf macro is defined and/or set.
  45. for (c in prefix_conf) {
  46. printf "#ifndef _%s\n", c
  47. printf "# define CONF_DEF_%s CONF_DEF_UNDEFINED\n", c
  48. # CONFSTR have string values and they are not set or unset.
  49. if (prefix_conf[c] != "CONFSTR") {
  50. printf "#else\n"
  51. printf "# if _%s > 0\n", c
  52. printf "# define CONF_DEF_%s CONF_DEF_DEFINED_SET\n", c
  53. printf "# else\n"
  54. printf "# define CONF_DEF_%s CONF_DEF_DEFINED_UNSET\n", c
  55. printf "# endif\n"
  56. }
  57. printf "#endif\n\n"
  58. # Build a name -> sysconf number associative array to print a C array at
  59. # the end.
  60. if (prefix_conf[c] == "SPEC")
  61. spec[c] = sc_prefixes[c] "_" conf[c]
  62. }
  63. # Print the specification array. Define the macro NEED_SPEC_ARRAY before
  64. # including posix-conf-vars.h to make it available in the compilation unit.
  65. print "#if NEED_SPEC_ARRAY"
  66. print "static const struct { const char *name; int num; } specs[] ="
  67. print " {"
  68. for (s in spec) {
  69. printf " { \"%s\", %s },\n", s, spec[s]
  70. }
  71. print " };"
  72. print "static const size_t nspecs = sizeof (specs) / sizeof (specs[0]);"
  73. print "#endif"
  74. }