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 | |
Samuel Tan | c0e60a2 | 2015-10-09 12:30:21 -0700 | [diff] [blame] | 15 | if [ $# -ne 1 ] && [ $# -ne 2 ]; then |
| 16 | echo "Usage: $(basename "$0") OUTFILE" |
Dan Willemsen | 2acbec5 | 2017-09-14 17:28:36 -0700 | [diff] [blame] | 17 | echo "Usage: $(basename "$0") INFILE OUTFILE" |
Lei Zhang | eee3155 | 2012-10-17 21:27:10 -0700 | [diff] [blame] | 18 | exit 1 |
| 19 | fi |
| 20 | |
Dan Willemsen | 2acbec5 | 2017-09-14 17:28:36 -0700 | [diff] [blame] | 21 | BUILD="${CC} -dD gen_syscalls.c -E" |
| 22 | GEN_DEPS=1 |
| 23 | |
Samuel Tan | c0e60a2 | 2015-10-09 12:30:21 -0700 | [diff] [blame] | 24 | if [ $# -eq 2 ]; then |
Dan Willemsen | 2acbec5 | 2017-09-14 17:28:36 -0700 | [diff] [blame] | 25 | BUILD="cat $1" |
| 26 | GEN_DEPS=0 |
Samuel Tan | c0e60a2 | 2015-10-09 12:30:21 -0700 | [diff] [blame] | 27 | shift |
| 28 | fi |
Lei Zhang | eee3155 | 2012-10-17 21:27:10 -0700 | [diff] [blame] | 29 | OUTFILE="$1" |
| 30 | |
Dan Willemsen | 2acbec5 | 2017-09-14 17:28:36 -0700 | [diff] [blame] | 31 | if [ ${GEN_DEPS} -eq 1 ]; then |
| 32 | # Generate a dependency file which helps the build tool to see when it |
| 33 | # should regenerate ${OUTFILE}. |
| 34 | ${BUILD} -M -MF "${OUTFILE}.d" |
| 35 | fi |
Shinichiro Hamaji | 286e289 | 2016-05-10 17:33:08 +0900 | [diff] [blame] | 36 | |
Lei Zhang | eee3155 | 2012-10-17 21:27:10 -0700 | [diff] [blame] | 37 | # sed expression which extracts system calls that are |
| 38 | # defined via asm/unistd.h. It converts them from: |
| 39 | # #define __NR_read foo |
| 40 | # to: |
| 41 | # #ifdef __NR_read |
| 42 | # { "read", __NR_read }, |
| 43 | # #endif |
Mike Frysinger | b962e7e | 2015-10-16 13:50:31 -0400 | [diff] [blame] | 44 | SED_MULTILINE='s/#define __(ARM_)?(NR_)([[:lower:]0-9_]*) (.*)$/#ifdef __\1\2\3\ |
Scott James Remnant | ae2aed8 | 2015-09-24 14:35:31 -0700 | [diff] [blame] | 45 | { "\1\3", __\1\2\3 },\ |
| 46 | #endif/g p;' |
Lei Zhang | eee3155 | 2012-10-17 21:27:10 -0700 | [diff] [blame] | 47 | |
| 48 | cat <<-EOF > "${OUTFILE}" |
| 49 | /* GENERATED BY MAKEFILE */ |
| 50 | #include <stddef.h> |
| 51 | #include <asm/unistd.h> |
| 52 | #include "libsyscalls.h" |
| 53 | const struct syscall_entry syscall_table[] = { |
Dan Willemsen | 2acbec5 | 2017-09-14 17:28:36 -0700 | [diff] [blame] | 54 | $(${BUILD} | sed -Ene "${SED_MULTILINE}") |
Lei Zhang | eee3155 | 2012-10-17 21:27:10 -0700 | [diff] [blame] | 55 | { NULL, -1 }, |
| 56 | }; |
| 57 | EOF |