2.5-18.1
[jlayton/glibc.git] / scripts / versions.awk
1 # Combine version map fragments into version scripts for our shared objects.
2 # Copyright (C) 1998,99,2000,2002,2005 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   lossage = 0;
13
14   nlibs=0;
15   while (getline < defsfile) {
16     if (/^[a-zA-Z0-9_.]+ \{/) {
17       libs[$1] = 1;
18       curlib = $1;
19       while (getline < defsfile && ! /^}/) {
20         if ($2 == "=") {
21           renamed[curlib "::" $1] = $3;
22         }
23         else
24           versions[curlib "::" $1] = 1;
25       }
26     }
27   }
28   close(defsfile);
29
30   tmpfile = buildroot "Versions.tmp";
31   # Note this sorting presumes only single digits between dots for proper
32   # numeric ordering.  sort -n doesn't do quite the right thing either,
33   # and in some non-GNU sort implementations does not sort at all.
34   sort = "sort > " tmpfile;
35 }
36
37 # Remove comment lines.
38 /^ *#/ {
39   next;
40 }
41
42 # This matches the beginning of the version information for a new library.
43 /^[a-zA-Z0-9_.]+/ {
44   actlib = $1;
45   if (!libs[$1]) {
46     printf("no versions defined for %s\n", $1) > "/dev/stderr";
47     ++lossage;
48   }
49   next;
50 }
51
52 # This matches the beginning of a new version for the current library.
53 /^  [A-Za-z_]/ {
54   if (renamed[actlib "::" $1])
55     actver = renamed[actlib "::" $1];
56   else if (!versions[actlib "::" $1] && $1 != "GLIBC_PRIVATE") {
57     printf("version %s not defined for %s\n", $1, actlib) > "/dev/stderr";
58     ++lossage;
59   }
60   else
61     actver = $1;
62   next;
63 }
64
65 # This matches lines with names to be added to the current version in the
66 # current library.  This is the only place where we print something to
67 # the intermediate file.
68 /^   / {
69   sortver=actver
70   # Ensure GLIBC_ versions come always first
71   sub(/^GLIBC_/," GLIBC_",sortver)
72   printf("%s %s %s\n", actlib, sortver, $0) | sort;
73 }
74
75
76 function closeversion(name, oldname) {
77   if (firstinfile) {
78     printf("  local:\n    *;\n") > outfile;
79     firstinfile = 0;
80   }
81   # This version inherits from the last one only if they
82   # have the same nonnumeric prefix, i.e. GLIBC_x.y and GLIBC_x.z
83   # or FOO_x and FOO_y but not GLIBC_x and FOO_y.
84   pfx = oldname;
85   sub(/[0-9.]+/,".+",pfx);
86   if (oldname == "" || name !~ pfx) print "};" > outfile;
87   else printf("} %s;\n", oldname) > outfile;
88 }
89
90 function close_and_move(name, real_name) {
91   close(name);
92   system(move_if_change " " name " " real_name " >&2");
93 }
94
95 # Now print the accumulated information.
96 END {
97   close(sort);
98
99   if (lossage) {
100     system("rm -f " tmpfile);
101     exit 1;
102   }
103
104   oldlib = "";
105   oldver = "";
106   printf("version-maps =");
107   while (getline < tmpfile) {
108     if ($1 != oldlib) {
109       if (oldlib != "") {
110         closeversion(oldver, veryoldver);
111         oldver = "";
112         close_and_move(outfile, real_outfile);
113       }
114       oldlib = $1;
115       real_outfile = buildroot oldlib ".map";
116       outfile = real_outfile "T";
117       firstinfile = 1;
118       veryoldver = "";
119       printf(" %s.map", oldlib);
120     }
121     if ($2 != oldver) {
122       if (oldver != "") {
123         closeversion(oldver, veryoldver);
124         veryoldver = oldver;
125       }
126       printf("%s {\n  global:\n", $2) > outfile;
127       oldver = $2;
128     }
129     printf("   ") > outfile;
130     for (n = 3; n <= NF; ++n) {
131       printf(" %s", $n) > outfile;
132     }
133     printf("\n") > outfile;
134   }
135   printf("\n");
136   closeversion(oldver, veryoldver);
137   close_and_move(outfile, real_outfile);
138   system("rm -f " tmpfile);
139 }