* scripts/abilist.awk: Grok function descriptor symbols.
[platform/upstream/glibc.git] / scripts / versions.awk
1 # Combine version map fragments into version scripts for our shared objects.
2 # Copyright (C) 1998,99,2000,02 Free Software Foundation, Inc.
3 # Written by Ulrich Drepper <drepper@cygnus.com>, 1998.
4
5 # This script expects the following variables to be defined:
6 # defsfile              name of Versions.def file
7 # buildroot             name of build directory with trailing slash
8 # move_if_change        move-if-change command
9
10 # Read definitions for the versions.
11 BEGIN {
12   nlibs=0;
13   while (getline < defsfile) {
14     if (/^[a-zA-Z0-9_.]+ \{/) {
15       libs[$1] = 1;
16       curlib = $1;
17       while (getline < defsfile && ! /^}/) {
18       if ($2 == "=") {
19           renamed[curlib "::" $1] = $3;
20       }
21         else
22           versions[$1] = 1;
23       }
24     }
25   }
26   close(defsfile);
27
28   tmpfile = buildroot "Versions.tmp";
29   sort = "sort -n > " tmpfile;
30 }
31
32 # Remove comment lines.
33 /^ *#/ {
34   next;
35 }
36
37 # This matches the beginning of the version information for a new library.
38 /^[a-zA-Z0-9_.]+/ {
39   actlib = $1;
40   if (!libs[$1]) {
41     printf("no versions defined for %s\n", $1) > "/dev/stderr";
42     exit 1;
43   }
44   next;
45 }
46
47 # This matches the beginning of a new version for the current library.
48 /^  [A-Za-z_]/ {
49   if (renamed[actlib "::" $1])
50     actver = renamed[actlib "::" $1];
51   else if (!versions[$1]) {
52     printf("version %s not defined for %s\n", $1, actlib) > "/dev/stderr";
53     exit 1;
54   }
55   else
56     actver = $1;
57   next;
58 }
59
60 # This matches lines with names to be added to the current version in the
61 # current library.  This is the only place where we print something to
62 # the intermediate file.
63 /^   / {
64   sortver=actver
65   # Ensure GLIBC_ versions come always first
66   sub(/^GLIBC_/," GLIBC_",sortver)
67   printf("%s %s %s\n", actlib, sortver, $0) | sort;
68 }
69
70
71 function closeversion(name, oldname) {
72   if (firstinfile) {
73     printf("  local:\n    *;\n") > outfile;
74     firstinfile = 0;
75   }
76   # This version inherits from the last one only if they
77   # have the same nonnumeric prefix, i.e. GLIBC_x.y and GLIBC_x.z
78   # or FOO_x and FOO_y but not GLIBC_x and FOO_y.
79   pfx = oldname;
80   sub(/[0-9.]+/,".+",pfx);
81   if (oldname == "" || name !~ pfx) print "};" > outfile;
82   else printf("} %s;\n", oldname) > outfile;
83 }
84
85 function close_and_move(name, real_name) {
86   close(name);
87   system(move_if_change " " name " " real_name " >&2");
88 }
89
90 # Now print the accumulated information.
91 END {
92   close(sort);
93   oldlib = "";
94   oldver = "";
95   printf("version-maps =");
96   while (getline < tmpfile) {
97     if ($1 != oldlib) {
98       if (oldlib != "") {
99         closeversion(oldver, veryoldver);
100         oldver = "";
101         close_and_move(outfile, real_outfile);
102       }
103       oldlib = $1;
104       real_outfile = buildroot oldlib ".map";
105       outfile = real_outfile "T";
106       firstinfile = 1;
107       veryoldver = "";
108       printf(" %s.map", oldlib);
109     }
110     if ($2 != oldver) {
111       if (oldver != "") {
112         closeversion(oldver, veryoldver);
113         veryoldver = oldver;
114       }
115       printf("%s {\n  global:\n", $2) > outfile;
116       oldver = $2;
117     }
118     printf("   ") > outfile;
119     for (n = 3; n <= NF; ++n) {
120       printf(" %s", $n) > outfile;
121     }
122     printf("\n") > outfile;
123   }
124   printf("\n");
125   closeversion(oldver, veryoldver);
126   close_and_move(outfile, real_outfile);
127   system("rm -f " tmpfile);
128 }