summaryrefslogtreecommitdiff
path: root/scripts/gen-conf.awk
blob: 45a4d443334df45cc3d1741a5c11823d9fd1be73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Generate confdefs-defs.h with definitions for {CONF}_DEF for each
# configuration variable that getconf or sysconf may use.  Currently it is
# equipped only to generate such macros for specification macros and for
# SYSCONF macros in the _POSIX namespace.

BEGIN {
  PROCINFO["sorted_in"] = "@val_type_asc"
  prefix = ""
}

$1 ~ /^#/ || $0 ~ /^\s*$/ {
  next
}

# Begin a new prefix.
$2 == "{" {
  split ($1, arr, ":")
  type = arr[1]
  prefix = arr[2]
  next
}

$1 == "}" {
  prefix = ""
  type = ""
  next
}

{
  if (prefix == "" && type == "" && sc_prefix == "") {
    print "Syntax error" > "/dev/stderr"
    exit 1
  }

  # The prefix and variable names are indices and the value indicates what type
  # of variable it is.  The possible options are:
  # CONFSTR: A configuration string
  # SYSCONF: A numeric value
  # SPEC: A specification
  conf[prefix][$1] = type
}

ENDFILE {
  print "/* Autogenerated by gen-conf.awk.  */\n"

  # Generate macros that specify if a sysconf macro is defined and/or set.
  for (p in conf) {
    for (c in conf[p]) {
      printf "#ifndef _%s_%s\n", p, c
      printf "# define _%s_%s_DEF CONF_DEF_UNDEFINED\n", p, c
      # CONFSTR have string values and they are not set or unset.
      if (conf[p][c] != "CONFSTR") {
	printf "#else\n"
	printf "# if _%s_%s > 0\n", p, c
	printf "#  define _%s_%s_DEF CONF_DEF_DEFINED_SET\n", p, c
	printf "# else\n"
	printf "#  define _%s_%s_DEF CONF_DEF_DEFINED_UNSET\n", p, c
	printf "# endif\n"
      }
      printf "#endif\n\n"
    }
  }
}