aboutsummaryrefslogtreecommitdiff
path: root/scripts/soversions.awk
blob: dbc90590e85e22548078216a1f152901f85451b8 (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
# awk script for shlib-versions.v -> soversions.i; see Makeconfig.

# Obey the first matching DEFAULT line.
$1 == "DEFAULT" {
  $1 = "";
  default_set[++ndefault_set] = $0;
  next
}

# Collect all lib lines before emitting anything, so DEFAULT
# can be interspersed.
{
  lib = number = $1;
  sub(/=.*$/, "", lib);
  sub(/^.*=/, "", number);
  if (lib in numbers) next;
  numbers[lib] = number;
  order[lib] = ++order_n;
  if (NF > 1) {
    $1 = "";
    versions[lib] = $0
  }
}

END {
  for (lib in numbers) {
    if (lib in versions)
      set = versions[lib];
    else {
      set = default_setname;
      if (ndefault_set >= 1)
	set = default_set[1];
    }
    line = set ? (lib FS numbers[lib] FS set) : (lib FS numbers[lib]);
    if (!(lib in lineorder) || order[lib] < lineorder[lib]) {
      lineorder[lib] = order[lib];
      lines[lib] = "DEFAULT" FS line;
    }
  }
  for (c in lines) {
    print lines[c]
  }
}