Add arm-nacl port.
[glibc.git] / sysdeps / nacl / errnos.awk
blob65fa19bd0612d97184017fbd9e7a80424408052a
1 # Script to produce bits/errno.h for NaCl.
3 # Copyright (C) 2015 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <http://www.gnu.org/licenses/>.
20 BEGIN { maxerrno = 0 }
22 $1 == "#define" && $2 ~ /NACL_ABI_E[A-Z0-9_]+/ && $3 ~ /[0-9]+/ {
23 ename = $2;
24 sub(/NACL_ABI_/, "", ename);
25 errno = $3 + 0;
26 if (errno > maxerrno) maxerrno = errno;
27 errnos[errno] = ename;
28 errnos_by_name[ename] = errno;
29 if ($4 == "/*" && !(ename in errno_text)) {
30 etext = $5;
31 for (i = 6; i <= NF && $i != "*/"; ++i)
32 etext = etext " " $i;
33 errno_text[ename] = etext;
35 next;
38 $1 == "@comment" && $2 == "errno.h" { errnoh=1; next }
39 errnoh == 1 && $1 == "@comment" {
40 ++errnoh;
41 etext = $3;
42 for (i = 4; i <= NF; ++i)
43 etext = etext " " $i;
44 next;
46 errnoh == 2 && $1 == "@deftypevr" && $2 == "Macro" && $3 == "int" {
47 ename = $4;
48 errno_text[ename] = etext;
49 next;
52 function define_errno(errno, ename) {
53 etext = errno_text[ename];
54 if (length(ename) < 8) ename = ename "\t";
55 printf "#define\t%s\t%d\t/* %s */\n", ename, errno, etext;
58 END {
59 print "\
60 /* This file generated by errnos.awk. */\n\
61 \n\
62 #if !defined __Emath_defined && (defined _ERRNO_H || defined __need_Emath)\n\
63 #undef __need_Emath\n\
64 #define __Emath_defined 1";
65 emath["EDOM"] = emath["EILSEQ"] = emath["ERANGE"] = 1;
66 for (ename in emath) {
67 errno = errnos_by_name[ename];
68 define_errno(errno, ename);
69 delete errnos[errno];
71 print "\
72 #endif\n\
73 \n\
74 #ifdef _ERRNO_H\n";
76 for (i = 1; i <= maxerrno; ++i)
77 if (i in errnos) define_errno(i, errnos[i]);
79 print "\n\
80 #define EWOULDBLOCK EAGAIN\n\
81 #define ENOTSUP EOPNOTSUPP\n\
82 \n\
83 extern __thread int errno __attribute__ ((__tls_model__ (\"initial-exec\")));\n\
84 #define errno errno\n\
85 \n\
86 #endif";