Lei Zhang | eee3155 | 2012-10-17 21:27:10 -0700 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | # Generates a header file with a system call table made up of "name", |
| 8 | # syscall_nr entries by including the build target <asm/unistd.h> and |
| 9 | # emitting the list of defines. Use of the compiler is needed to |
| 10 | # dereference the actual provider of syscall definitions. |
| 11 | # E.g., asm/unistd_32.h or asm/unistd_64.h, etc. |
| 12 | |
| 13 | set -e |
| 14 | |
| 15 | if [ $# -ne 1 ] && [ $# -ne 3 ]; then |
| 16 | echo "Usage: $(basename "$0") OUTFILE" |
| 17 | echo "Usage: $(basename "$0") CC CFLAGS OUTFILE" |
| 18 | exit 1 |
| 19 | fi |
| 20 | |
| 21 | if [ $# -eq 3 ]; then |
| 22 | CC="$1" |
| 23 | shift |
| 24 | CFLAGS="$1" |
| 25 | shift |
| 26 | fi |
| 27 | OUTFILE="$1" |
| 28 | |
| 29 | # sed expression which extracts system calls that are |
| 30 | # defined via asm/unistd.h. It converts them from: |
| 31 | # #define __NR_read foo |
| 32 | # to: |
| 33 | # #ifdef __NR_read |
| 34 | # { "read", __NR_read }, |
| 35 | # #endif |
| 36 | SED_MULTILINE='s/#define __(ARM_)?(NR_)([a-z0-9_]*) (.*)$/#ifdef __\1\2\3\ |
| 37 | { "\1\3", __\1\2\3 },\n#endif/g p;' |
| 38 | |
| 39 | cat <<-EOF > "${OUTFILE}" |
| 40 | /* GENERATED BY MAKEFILE */ |
| 41 | #include <stddef.h> |
| 42 | #include <asm/unistd.h> |
| 43 | #include "libsyscalls.h" |
| 44 | const struct syscall_entry syscall_table[] = { |
| 45 | $(echo '#include <asm/unistd.h>' | \ |
| 46 | ${CC} ${CFLAGS} -dD - -E | sed -rne "${SED_MULTILINE}") |
| 47 | { NULL, -1 }, |
| 48 | }; |
| 49 | EOF |