Update.
[glibc.git] / scripts / versions.awk
blob64ac2d981bf1aeefd4105581e13114a99dff6ae9
1 # Combine version map fragments into version scripts for our shared objects.
2 # Copyright (C) 1998,99,2000 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 sort = "sort -n > " tmpfile;
32 # Remove comment lines.
33 /^ *#/ {
34 next;
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;
44 next;
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\n", $1) > "/dev/stderr";
53 exit 1;
55 else
56 actver = $1;
57 next;
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 printf("%s %s %s\n", actlib, actver, $0) | sort;
68 function closeversion(name, oldname) {
69 if (firstinfile) {
70 printf(" local:\n *;\n") > outfile;
71 firstinfile = 0;
73 printf("}%s;\n", oldname) > outfile;
76 function close_and_move(name, real_name) {
77 close(name);
78 system(move_if_change " " name " " real_name " >&2");
81 # Now print the accumulated information.
82 END {
83 close(sort);
84 oldlib = "";
85 oldver = "";
86 printf("version-maps =");
87 while(getline < tmpfile) {
88 if ($1 != oldlib) {
89 if (oldlib != "") {
90 closeversion(oldver, veryoldver);
91 oldver = "";
92 close_and_move(outfile, real_outfile);
94 oldlib = $1;
95 real_outfile = buildroot oldlib ".map";
96 outfile = real_outfile "T";
97 firstinfile = 1;
98 veryoldver = "";
99 printf(" %s.map", oldlib);
101 if ($2 != oldver) {
102 if (oldver != "") {
103 closeversion(oldver, veryoldver);
104 veryoldver = oldver;
106 printf("%s {\n global:\n", $2) > outfile;
107 oldver = $2;
109 printf(" ") > outfile;
110 for (n = 3; n <= NF; ++n) {
111 printf(" %s", $n) > outfile;
113 printf("\n") > outfile;
115 printf("\n");
116 closeversion(oldver, veryoldver);
117 close_and_move(outfile, real_outfile);
118 system("rm -f " tmpfile);