]>
Commit | Line | Data |
---|---|---|
2dba5ce7 | 1 | # Generate SYS_* macros from a list in a text file. |
04277e02 | 2 | # Copyright (C) 2017-2019 Free Software Foundation, Inc. |
2dba5ce7 FW |
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, see | |
5a82c748 | 17 | # <https://www.gnu.org/licenses/>. |
2dba5ce7 FW |
18 | |
19 | # Emit a conditional definition for SYS_NAME. | |
20 | function emit(name) { | |
21 | print "#ifdef __NR_" name; | |
22 | print "# define SYS_" name " __NR_" name; | |
23 | print "#endif"; | |
24 | print ""; | |
25 | } | |
26 | ||
27 | # Bail out with an error. | |
28 | function fatal(message) { | |
29 | print FILENAME ":" FNR ": " message > "/dev/stderr"; | |
30 | exit 1; | |
31 | } | |
32 | ||
33 | BEGIN { | |
34 | name = ""; | |
35 | kernel = ""; | |
36 | } | |
37 | ||
38 | # Skip empty lines and comments. | |
39 | /^\s*(|#.*)$/ { | |
40 | next; | |
41 | } | |
42 | ||
43 | # Kernel version. Used for documentation purposes only. | |
44 | /^kernel [0-9.]+$/ { | |
45 | if (kernel != "") { | |
46 | fatal("duplicate kernel directive"); | |
47 | } | |
48 | kernel = $2; | |
49 | print "/* Generated at libc build time from syscall list. */"; | |
50 | print "/* The system call list corresponds to kernel " kernel ". */"; | |
51 | print ""; | |
52 | print "#ifndef _SYSCALL_H" | |
53 | print "# error \"Never use <bits/syscall.h> directly; include <sys/syscall.h> instead.\""; | |
54 | print "#endif"; | |
55 | print ""; | |
56 | split($2, kernel_version, "."); | |
57 | kernel_major = kernel_version[1]; | |
58 | kernel_minor = kernel_version[2]; | |
59 | kernel_version_code = kernel_major * 65536 + kernel_minor * 256; | |
60 | print "#define __GLIBC_LINUX_VERSION_CODE " kernel_version_code; | |
61 | print ""; | |
62 | next; | |
63 | } | |
64 | ||
65 | # If there is just one word, it is a system call. | |
66 | /^[a-zA-Z_][a-zA-Z0-9_]+$/ { | |
67 | if (kernel == "") { | |
68 | fatal("expected kernel directive before this line"); | |
69 | } | |
70 | if ($1 <= name) { | |
71 | fatal("name " name " violates ordering"); | |
72 | } | |
73 | emit($1); | |
74 | name = $1; | |
75 | next; | |
76 | } | |
77 | ||
78 | # The rest has to be syntax errors. | |
79 | // { | |
80 | fatal("unrecognized syntax"); | |
81 | } |