blob: a01d500689eb73c8728d7ec235b32e16fe156a27 [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
Jorge Lucangeli Obesa21c8fc2015-07-15 16:22:34 -070015if [ $# -ne 2 ]; then
16 echo "Usage: $(basename "$0") CC OUTFILE"
Lei Zhangeee31552012-10-17 21:27:10 -070017 exit 1
18fi
19
Jorge Lucangeli Obesa21c8fc2015-07-15 16:22:34 -070020CC="$1"
21shift
Lei Zhangeee31552012-10-17 21:27:10 -070022OUTFILE="$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
31SED_MULTILINE='s/#define __(ARM_)?(NR_)([a-z0-9_]*) (.*)$/#ifdef __\1\2\3\
32{ "\1\3", __\1\2\3 },\n#endif/g p;'
33
34cat <<-EOF > "${OUTFILE}"
35/* GENERATED BY MAKEFILE */
36#include <stddef.h>
37#include <asm/unistd.h>
38#include "libsyscalls.h"
39const struct syscall_entry syscall_table[] = {
40$(echo '#include <asm/unistd.h>' | \
Jorge Lucangeli Obesa21c8fc2015-07-15 16:22:34 -070041 ${CC} -dD - -E | sed -rne "${SED_MULTILINE}")
Lei Zhangeee31552012-10-17 21:27:10 -070042 { NULL, -1 },
43};
44EOF