]>
Commit | Line | Data |
---|---|---|
4022d8ed | 1 | # awk script to generate errlist-compat.c |
4b359a27 | 2 | # Copyright (C) 2002, 2004 Free Software Foundation, Inc. |
4022d8ed RM |
3 | # This file is part of the GNU C Library. |
4 | ||
5 | # The GNU C Library is free software; you can redistribute it and/or | |
6 | # modify it under the terms of the GNU Lesser General Public | |
7 | # License as published by the Free Software Foundation; either | |
8 | # version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | # The GNU C Library is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | # Lesser General Public License for more details. | |
14 | ||
15 | # You should have received a copy of the GNU Lesser General Public | |
16 | # License along with the GNU C Library; if not, write to the Free | |
17 | # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
18 | # 02111-1307 USA. | |
19 | ||
20 | # | |
21 | # This script takes the Versions file as input and looks for #errlist-compat | |
22 | # magic comments, which have the form: | |
23 | # #errlist-compat NNN | |
24 | # where NNN is the number of elements in the sys_errlist for that version set. | |
25 | # We need the awk variable `maxerr' defined to the current size of sys_errlist. | |
26 | # | |
27 | # If there is no magic comment matching the current size, we barf. | |
28 | # Otherwise we generate code (errlist-compat.c) to define all the | |
29 | # necessary compatibility symbols for older, smaller versions of sys_errlist. | |
30 | # | |
31 | ||
4022d8ed RM |
32 | # These two rules catch the Versions file contents. |
33 | NF == 2 && $2 == "{" { last_version = $1; next } | |
34 | $1 == "#errlist-compat" { | |
5fe14d96 UD |
35 | # Don't process any further Versions files |
36 | ARGC = ARGIND + 1; | |
37 | cnt = $2 + 0; | |
0ecb606c | 38 | if (cnt < 80) { |
4022d8ed RM |
39 | print "*** this line seems bogus:", $0 > "/dev/stderr"; |
40 | exit 1; | |
41 | } | |
5fe14d96 UD |
42 | version[pos + 0] = cnt SUBSEP last_version; |
43 | pos++; | |
44 | if (cnt < highest) { | |
45 | printf "*** %s #errlist-compat counts are not sorted\n", ARGV[ARGIND]; | |
46 | exit 1; | |
47 | } | |
48 | if (cnt > highest) | |
49 | highest = cnt; | |
50 | highest_version = last_version; | |
4022d8ed RM |
51 | next; |
52 | } | |
53 | ||
54 | END { | |
7a9ce79a RM |
55 | if (! highest_version) { |
56 | print "/* No sys_errlist/sys_nerr symbols defined on this platform. */"; | |
57 | exit 0; | |
58 | } | |
59 | ||
4022d8ed RM |
60 | count = maxerr + 1; |
61 | ||
4b359a27 | 62 | if (highest < count) { |
4022d8ed | 63 | printf "*** errlist.c count %d vs Versions sys_errlist@%s count %d\n", \ |
5fe14d96 | 64 | count, highest_version, highest > "/dev/stderr"; |
4022d8ed RM |
65 | exit 1; |
66 | } | |
67 | ||
68 | lastv = ""; | |
5fe14d96 UD |
69 | for (n = 0; n < pos; ++n) { |
70 | split(version[n], t, SUBSEP) | |
71 | v = t[2]; | |
72 | gsub(/[^A-Z0-9_]/, "_", v); | |
73 | if (lastv != "") | |
74 | compat[lastv] = v; | |
75 | lastv = v; | |
76 | vcount[v] = t[1]; | |
77 | } | |
4022d8ed RM |
78 | |
79 | print "/* This file was generated by errlist-compat.awk; DO NOT EDIT! */\n"; | |
80 | print "#include <shlib-compat.h>\n"; | |
81 | ||
4b359a27 RM |
82 | if (highest > count) { |
83 | printf "*** errlist.c count %d inflated to %s count %d (old errno.h?)\n", \ | |
84 | count, highest_version, highest > "/dev/stderr"; | |
85 | printf "#define ERR_MAX %d\n\n", highest; | |
86 | } | |
87 | ||
4022d8ed RM |
88 | for (old in compat) { |
89 | new = compat[old]; | |
90 | n = vcount[old]; | |
91 | printf "#if SHLIB_COMPAT (libc, %s, %s)\n", old, new; | |
a7b8a17b | 92 | printf "# include <bits/wordsize.h>\n"; |
0ecb606c | 93 | printf "extern const char *const __sys_errlist_%s[NERR];\n", old; |
4022d8ed RM |
94 | printf "const int __sys_nerr_%s = %d;\n", old, n; |
95 | printf "strong_alias (_sys_errlist_internal, __sys_errlist_%s)\n", old; | |
96 | printf "declare_symbol (__sys_errlist_%s, object, __WORDSIZE/8*%d)\n", \ | |
97 | old, n; | |
98 | printf "compat_symbol (libc, __sys_errlist_%s, sys_errlist, %s);\n", \ | |
99 | old, old; | |
100 | printf "compat_symbol (libc, __sys_nerr_%s, sys_nerr, %s);\n", old, old; | |
101 | ||
0ecb606c | 102 | printf "extern const char *const ___sys_errlist_%s[NERR];\n", old; |
4022d8ed RM |
103 | printf "extern const int __sys_nerr_%s;\n", old; |
104 | printf "strong_alias (__sys_errlist_%s, ___sys_errlist_%s)\n", old, old; | |
105 | printf "strong_alias (__sys_nerr_%s, ___sys_nerr_%s)\n", old, old; | |
106 | printf "compat_symbol (libc, ___sys_errlist_%s, _sys_errlist, %s);\n", \ | |
107 | old, old; | |
108 | printf "compat_symbol (libc, ___sys_nerr_%s, _sys_nerr, %s);\n", old, old; | |
109 | printf "#endif\n\n"; | |
110 | } | |
111 | ||
112 | printf "\ | |
0ecb606c | 113 | extern const char *const __sys_errlist_internal[NERR];\n\ |
4022d8ed RM |
114 | extern const int __sys_nerr_internal;\n\ |
115 | strong_alias (_sys_errlist_internal, __sys_errlist_internal)\n\ | |
116 | strong_alias (_sys_nerr_internal, __sys_nerr_internal)\n\ | |
0ecb606c | 117 | extern const char *const sys_errlist[NERR];\n\ |
4022d8ed RM |
118 | versioned_symbol (libc, _sys_errlist_internal, sys_errlist, %s);\n\ |
119 | versioned_symbol (libc, __sys_errlist_internal, _sys_errlist, %s);\n\ | |
120 | versioned_symbol (libc, _sys_nerr_internal, sys_nerr, %s);\n\ | |
121 | versioned_symbol (libc, __sys_nerr_internal, _sys_nerr, %s);\n", \ | |
122 | lastv, lastv, lastv, lastv; | |
1ce8aaae RM |
123 | |
124 | print "\n\ | |
125 | link_warning (sys_errlist, \"\ | |
126 | `sys_errlist' is deprecated; use `strerror' or `strerror_r' instead\")\n\ | |
127 | link_warning (sys_nerr, \"\ | |
128 | `sys_nerr' is deprecated; use `strerror' or `strerror_r' instead\")"; | |
4022d8ed | 129 | } |