blob: 51b583854845ec5ae9444132a5aa928101814ee7 [file] [log] [blame]
Lei Zhangeee31552012-10-17 21:27:10 -07001#!/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
13set -e
14
Samuel Tanc0e60a22015-10-09 12:30:21 -070015if [ $# -ne 1 ] && [ $# -ne 2 ]; then
16 echo "Usage: $(basename "$0") OUTFILE"
Jorge Lucangeli Obesa21c8fc2015-07-15 16:22:34 -070017 echo "Usage: $(basename "$0") CC OUTFILE"
Lei Zhangeee31552012-10-17 21:27:10 -070018 exit 1
19fi
20
Samuel Tanc0e60a22015-10-09 12:30:21 -070021if [ $# -eq 2 ]; then
22 CC="$1"
23 shift
24fi
Lei Zhangeee31552012-10-17 21:27:10 -070025OUTFILE="$1"
26
Shinichiro Hamaji286e2892016-05-10 17:33:08 +090027# Generate a dependency file which helps the build tool to see when it
28# should regenerate ${OUTFILE}.
29echo '#include <asm/unistd.h>' | ${CC} - -E -M -MF ${OUTFILE}.d.tmp
30# Correct the output filename.
31(echo "${OUTFILE}: \\" ; sed 's/^-\.o://' ${OUTFILE}.d.tmp) > ${OUTFILE}.d
32rm ${OUTFILE}.d.tmp
33
Lei Zhangeee31552012-10-17 21:27:10 -070034# sed expression which extracts system calls that are
35# defined via asm/unistd.h. It converts them from:
36# #define __NR_read foo
37# to:
38# #ifdef __NR_read
39# { "read", __NR_read },
40# #endif
Mike Frysingerb962e7e2015-10-16 13:50:31 -040041SED_MULTILINE='s/#define __(ARM_)?(NR_)([[:lower:]0-9_]*) (.*)$/#ifdef __\1\2\3\
Scott James Remnantae2aed82015-09-24 14:35:31 -070042{ "\1\3", __\1\2\3 },\
43#endif/g p;'
Lei Zhangeee31552012-10-17 21:27:10 -070044
45cat <<-EOF > "${OUTFILE}"
46/* GENERATED BY MAKEFILE */
47#include <stddef.h>
48#include <asm/unistd.h>
49#include "libsyscalls.h"
50const struct syscall_entry syscall_table[] = {
51$(echo '#include <asm/unistd.h>' | \
Scott James Remnantae2aed82015-09-24 14:35:31 -070052 ${CC} -dD - -E | sed -Ene "${SED_MULTILINE}")
Lei Zhangeee31552012-10-17 21:27:10 -070053 { NULL, -1 },
54};
55EOF