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