Update.
[glibc.git] / scripts / versions.awk
blob7e33387d41a304b79b3ad65ac7c168ba3e373794
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.
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
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;
21 else
22 versions[$1] = 1;
26 close(defsfile);
28 tmpfile = buildroot "Versions.tmp";
29 # Note this sorting presumes only single digits between dots for proper
30 # numeric ordering. sort -n doesn't do quite the right thing either,
31 # and in some non-GNU sort implementations does not sort at all.
32 sort = "sort > " tmpfile;
35 # Remove comment lines.
36 /^ *#/ {
37 next;
40 # This matches the beginning of the version information for a new library.
41 /^[a-zA-Z0-9_.]+/ {
42 actlib = $1;
43 if (!libs[$1]) {
44 printf("no versions defined for %s\n", $1) > "/dev/stderr";
45 exit 1;
47 next;
50 # This matches the beginning of a new version for the current library.
51 /^ [A-Za-z_]/ {
52 if (renamed[actlib "::" $1])
53 actver = renamed[actlib "::" $1];
54 else if (!versions[$1]) {
55 printf("version %s not defined for %s\n", $1, actlib) > "/dev/stderr";
56 exit 1;
58 else
59 actver = $1;
60 next;
63 # This matches lines with names to be added to the current version in the
64 # current library. This is the only place where we print something to
65 # the intermediate file.
66 /^ / {
67 sortver=actver
68 # Ensure GLIBC_ versions come always first
69 sub(/^GLIBC_/," GLIBC_",sortver)
70 printf("%s %s %s\n", actlib, sortver, $0) | sort;
74 function closeversion(name, oldname) {
75 if (firstinfile) {
76 printf(" local:\n *;\n") > outfile;
77 firstinfile = 0;
79 # This version inherits from the last one only if they
80 # have the same nonnumeric prefix, i.e. GLIBC_x.y and GLIBC_x.z
81 # or FOO_x and FOO_y but not GLIBC_x and FOO_y.
82 pfx = oldname;
83 sub(/[0-9.]+/,".+",pfx);
84 if (oldname == "" || name !~ pfx) print "};" > outfile;
85 else printf("} %s;\n", oldname) > outfile;
88 function close_and_move(name, real_name) {
89 close(name);
90 system(move_if_change " " name " " real_name " >&2");
93 # Now print the accumulated information.
94 END {
95 close(sort);
96 oldlib = "";
97 oldver = "";
98 printf("version-maps =");
99 while (getline < tmpfile) {
100 if ($1 != oldlib) {
101 if (oldlib != "") {
102 closeversion(oldver, veryoldver);
103 oldver = "";
104 close_and_move(outfile, real_outfile);
106 oldlib = $1;
107 real_outfile = buildroot oldlib ".map";
108 outfile = real_outfile "T";
109 firstinfile = 1;
110 veryoldver = "";
111 printf(" %s.map", oldlib);
113 if ($2 != oldver) {
114 if (oldver != "") {
115 closeversion(oldver, veryoldver);
116 veryoldver = oldver;
118 printf("%s {\n global:\n", $2) > outfile;
119 oldver = $2;
121 printf(" ") > outfile;
122 for (n = 3; n <= NF; ++n) {
123 printf(" %s", $n) > outfile;
125 printf("\n") > outfile;
127 printf("\n");
128 closeversion(oldver, veryoldver);
129 close_and_move(outfile, real_outfile);
130 system("rm -f " tmpfile);