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 | |
Jorge Lucangeli Obes | a21c8fc | 2015-07-15 16:22:34 -0700 | [diff] [blame] | 15 | if [ $# -ne 2 ]; then |
| 16 | echo "Usage: $(basename "$0") CC OUTFILE" |
Lei Zhang | eee3155 | 2012-10-17 21:27:10 -0700 | [diff] [blame] | 17 | exit 1 |
| 18 | fi |
| 19 | |
Jorge Lucangeli Obes | a21c8fc | 2015-07-15 16:22:34 -0700 | [diff] [blame] | 20 | CC="$1" |
| 21 | shift |
Lei Zhang | eee3155 | 2012-10-17 21:27:10 -0700 | [diff] [blame] | 22 | OUTFILE="$1" |
| 23 | |
| 24 | # sed expression which extracts system calls that are |
| 25 | # defined via asm/unistd.h. It converts them from: |
| 26 | # #define __NR_read foo |
| 27 | # to: |
| 28 | # #ifdef __NR_read |
| 29 | # { "read", __NR_read }, |
| 30 | # #endif |
| 31 | SED_MULTILINE='s/#define __(ARM_)?(NR_)([a-z0-9_]*) (.*)$/#ifdef __\1\2\3\ |
| 32 | { "\1\3", __\1\2\3 },\n#endif/g p;' |
| 33 | |
| 34 | cat <<-EOF > "${OUTFILE}" |
| 35 | /* GENERATED BY MAKEFILE */ |
| 36 | #include <stddef.h> |
| 37 | #include <asm/unistd.h> |
| 38 | #include "libsyscalls.h" |
| 39 | const struct syscall_entry syscall_table[] = { |
| 40 | $(echo '#include <asm/unistd.h>' | \ |
Jorge Lucangeli Obes | a21c8fc | 2015-07-15 16:22:34 -0700 | [diff] [blame] | 41 | ${CC} -dD - -E | sed -rne "${SED_MULTILINE}") |
Lei Zhang | eee3155 | 2012-10-17 21:27:10 -0700 | [diff] [blame] | 42 | { NULL, -1 }, |
| 43 | }; |
| 44 | EOF |