2008-05-21 Roland McGrath <roland@redhat.com>
[platform/upstream/glibc.git] / scripts / soversions.awk
1 # awk script for shlib-versions.v -> soversions.i; see Makeconfig.
2
3 BEGIN {
4   config = cpu "-" vendor "-" os;
5   configs[config] = "DEFAULT";
6 }
7
8 { thiscf = $1 }
9
10 $2 ~ /WORDSIZE[3264]/ {
11   if ((config ~ thiscf) && !othercf) {
12     othercf = $3;
13     sub(/@CPU@/, cpu, othercf);
14     sub(/@VENDOR@/, vendor, othercf);
15     sub(/@OS@/, os, othercf);
16     configs[othercf] = $2;
17   }
18   next;
19 }
20
21 $2 == "ABI" {
22   if ((config ~ thiscf) && !abiname) {
23     abiname = $3;
24     sub(/@CPU@/, cpu, abiname);
25     sub(/@VENDOR@/, vendor, abiname);
26     sub(/@OS@/, os, abiname);
27   }
28   next;
29 }
30
31 # Obey the first matching DEFAULT line.
32 $2 == "DEFAULT" {
33   $1 = $2 = "";
34   default_set[++ndefault_set] = thiscf "\n" $0;
35   next
36 }
37
38 # Collect all lib lines before emitting anything, so DEFAULT
39 # can be interspersed.
40 {
41   lib = number = $2;
42   sub(/=.*$/, "", lib);
43   sub(/^.*=/, "", number);
44   if ((thiscf FS lib) in numbers) next;
45   numbers[thiscf FS lib] = number;
46   order[thiscf FS lib] = ++order_n;
47   if (NF > 2) {
48     $1 = $2 = "";
49     versions[thiscf FS lib] = $0
50   }
51 }
52
53 END {
54   for (elt in numbers) {
55     split(elt, x);
56     cf = x[1];
57     lib = x[2];
58     for (c in configs)
59       if (c ~ cf) {
60         if (elt in versions)
61           set = versions[elt];
62         else {
63           set = (c == config) ? default_setname : "";
64           for (i = 1; i <= ndefault_set; ++i) {
65             split(default_set[i], x, "\n");
66             if (c ~ x[1]) {
67               set = x[2];
68               break;
69             }
70           }
71         }
72         line = set ? (lib FS numbers[elt] FS set) : (lib FS numbers[elt]);
73         if (!((c FS lib) in lineorder) || order[elt] < lineorder[c FS lib]) {
74           lineorder[c FS lib] = order[elt];
75           lines[c FS lib] = configs[c] FS line;
76         }
77       }
78   }
79   if (abiname) {
80     print "ABI", abiname
81   }
82   for (c in lines) {
83     print lines[c]
84   }
85 }