Tue Nov 24 15:46:33 1998 Michael Snyder <msnyder@cleaver.cygnus.com>
[deliverable/binutils-gdb.git] / gdb / merge-syscalls.sh
1 #!/bin/sh
2
3 # Copyright 1998 Free Software Foundation, Inc.
4 #
5 # This file is part of GDB.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21 ################
22 # Usage: merge-syscalls syscall.tab [HEADER-FILE ...]
23 #
24 # This will scan every HEADER-FILE
25 # (default is /usr/include/sys/syscall.h)
26 # for #define SYS_xxx directives,
27 # recursively scanning #included files.
28 #
29 # Then it updates "syscall.tab", which is a file that has a
30 # C fragment to initialize a table of known syscall names.
31 # Any syscalls already in "syscall.tab" will be kept.
32 #
33 # In principle, you don't need to run this unless you're
34 # porting gdb to a new host that uses procfs.c.
35 #
36 # FIXME: perhaps use gcc -E -dM instead.
37 # FIXME: perhaps track which hosts have which syscalls.
38
39 DEST=$1; shift
40
41 WS=`printf "[\t ]*" 2>/dev/null || echo '[ ]*'`
42
43
44 scan_all () {
45 for file
46 do
47 scan_one $file
48 done
49 }
50
51 scan_one () {
52 echo >&2 "scanning $1..."
53 <$1 sed -n -e "
54 /^#${WS}define${WS}SYS_[_a-zA-Z0-9]${WS}/ {
55 s/^${WS}#${WS}define${WS}\(SYS_[_a-zA-Z0-9]*\)${WS}.*/\1/
56 p
57 }
58 /${WS}syscall_table${WS}\[SYS_[_a-zA-Z0-9]*\]/ {
59 s/^.*${WS}syscall_table${WS}\[\(SYS_[_a-zA-Z0-9]*\)\].*/\1/
60 p
61 }
62 " $1 &&
63
64 includes=`
65 <$1 sed -n -e "
66 /^${WS}#${WS}include${WS}</{
67 s/^${WS}#${WS}include${WS}<\([^>]*\)>.*/\1/
68 p
69 }
70 " |
71 while read inc; do
72 for dir in /usr/include; do
73 if [ -f "$dir/$inc" ]; then
74 echo $dir/$inc
75 fi
76 done
77 done
78 ` &&
79
80 scan_all $includes
81 }
82
83 case $# in
84 0)
85 set -- /usr/include/sys/syscall.h
86 ;;
87 esac
88
89 scan_all $DEST "$@" |
90 sort -u |
91 (
92 echo "/* This file is semi-automatically updated by `basename $0` */"
93 while read sys; do
94 tail=`echo "$sys" | sed 's/^SYS_//'`
95 echo "#if defined ($sys)"
96 echo " syscall_table[$sys] = "\""$tail"\"";"
97 echo "#endif"
98 done
99 ) > tmp$$ || exit 1
100
101 if cmp -s $DEST tmp$$; then
102 echo "$DEST unchanged"
103 rm -f tmp$$
104
105 else
106 echo "creating new $DEST..."
107 if [ -f $DEST ]; then
108 mv $DEST $DEST.orig || exit 1
109 echo " (original moved to $DEST.orig)"
110 fi
111 mv tmp$$ $DEST
112 fi
113
114
This page took 0.031415 seconds and 4 git commands to generate.