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 13set -e 14 15if [ $# -ne 1 ] && [ $# -ne 2 ]; then 16 echo "Usage: $(basename "$0") OUTFILE" 17 echo "Usage: $(basename "$0") CC OUTFILE" 18 exit 1 19fi 20 21if [ $# -eq 2 ]; then 22 CC="$1" 23 shift 24fi 25OUTFILE="$1" 26 27# sed expression which extracts system calls that are 28# defined via asm/unistd.h. It converts them from: 29# #define __NR_read foo 30# to: 31# #ifdef __NR_read 32# { "read", __NR_read }, 33# #endif 34SED_MULTILINE='s/#define __(ARM_)?(NR_)([[:lower:]0-9_]*) (.*)$/#ifdef __\1\2\3\ 35{ "\1\3", __\1\2\3 },\ 36#endif/g p;' 37 38cat <<-EOF > "${OUTFILE}" 39/* GENERATED BY MAKEFILE */ 40#include <stddef.h> 41#include <asm/unistd.h> 42#include "libsyscalls.h" 43const struct syscall_entry syscall_table[] = { 44$(echo '#include <asm/unistd.h>' | \ 45 ${CC} -dD - -E | sed -Ene "${SED_MULTILINE}") 46 { NULL, -1 }, 47}; 48EOF 49