Add fcntl sealing interfaces from Linux 3.17 to bits/fcntl-linux.h.
[glibc.git] / scripts / versions.awk
blob5d4768c99263ac4da11d46c4db8463d327e08a75
1 # Combine version map fragments into version scripts for our shared objects.
2 # Copyright (C) 1998-2017 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 lossage = 0;
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;
23 else
24 versions[curlib "::" $1] = 1;
28 close(defsfile);
30 tmpfile = buildroot "Versions.tmp";
31 # POSIX sort needed.
32 sort = "sort -t. -k 1,1 -k 2n,2n -k 3 > " 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 ++lossage;
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[actlib "::" $1] && $1 != "GLIBC_PRIVATE") {
55 printf("version %s not defined for %s\n", $1, actlib) > "/dev/stderr";
56 ++lossage;
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);
97 if (lossage) {
98 system("rm -f " tmpfile);
99 exit 1;
102 oldlib = "";
103 oldver = "";
104 real_first_ver_header = buildroot "first-versions.h"
105 first_ver_header = real_first_ver_header "T"
106 printf("#ifndef _FIRST_VERSIONS_H\n") > first_ver_header;
107 printf("#define _FIRST_VERSIONS_H\n") > first_ver_header;
108 real_ldbl_compat_header = buildroot "ldbl-compat-choose.h"
109 ldbl_compat_header = real_ldbl_compat_header "T"
110 printf("#ifndef _LDBL_COMPAT_CHOOSE_H\n") > ldbl_compat_header;
111 printf("#define _LDBL_COMPAT_CHOOSE_H\n") > ldbl_compat_header;
112 printf("#ifndef LONG_DOUBLE_COMPAT\n") > ldbl_compat_header;
113 printf("# error LONG_DOUBLE_COMPAT not defined\n") > ldbl_compat_header;
114 printf("#endif\n") > ldbl_compat_header;
115 printf("version-maps =");
116 while (getline < tmpfile) {
117 if ($1 != oldlib) {
118 if (oldlib != "") {
119 closeversion(oldver, veryoldver);
120 oldver = "";
121 close_and_move(outfile, real_outfile);
123 oldlib = $1;
124 real_outfile = buildroot oldlib ".map";
125 outfile = real_outfile "T";
126 firstinfile = 1;
127 veryoldver = "";
128 printf(" %s.map", oldlib);
130 if ($2 != oldver) {
131 if (oldver != "") {
132 closeversion(oldver, veryoldver);
133 veryoldver = oldver;
135 printf("%s {\n global:\n", $2) > outfile;
136 oldver = $2;
138 printf(" ") > outfile;
139 for (n = 3; n <= NF; ++n) {
140 printf(" %s", $n) > outfile;
141 sym = $n;
142 sub(";", "", sym);
143 first_ver_macro = "FIRST_VERSION_" oldlib "_" sym;
144 if (!(first_ver_macro in first_ver_seen) \
145 && oldver ~ "^GLIBC_[0-9]" \
146 && sym ~ "^[A-Za-z0-9_]*$") {
147 ver_val = oldver;
148 gsub("\\.", "_", ver_val);
149 printf("#define %s %s\n", first_ver_macro, ver_val) > first_ver_header;
150 first_ver_seen[first_ver_macro] = 1;
151 if (oldlib == "libc" || oldlib == "libm") {
152 printf("#if LONG_DOUBLE_COMPAT (%s, %s)\n",
153 oldlib, ver_val) > ldbl_compat_header;
154 printf("# define LONG_DOUBLE_COMPAT_CHOOSE_%s_%s(a, b) a\n",
155 oldlib, sym) > ldbl_compat_header;
156 printf("#else\n") > ldbl_compat_header;
157 printf("# define LONG_DOUBLE_COMPAT_CHOOSE_%s_%s(a, b) b\n",
158 oldlib, sym) > ldbl_compat_header;
159 printf("#endif\n") > ldbl_compat_header;
163 printf("\n") > outfile;
165 printf("\n");
166 printf("#endif /* first-versions.h */\n") > first_ver_header;
167 printf("#endif /* ldbl-compat-choose.h */\n") > ldbl_compat_header;
168 closeversion(oldver, veryoldver);
169 close_and_move(outfile, real_outfile);
170 close_and_move(first_ver_header, real_first_ver_header);
171 close_and_move(ldbl_compat_header, real_ldbl_compat_header);
172 #system("rm -f " tmpfile);