tools/llvm: Do not build with symbols
[minix3.git] / lib / libc / sys / makelintstub
blob84b02d0e88f034fc3cd29336b3c5e18edf803c57
1 #!/bin/sh -
2 # $NetBSD: makelintstub,v 1.25 2012/02/12 01:46:05 martin Exp $
4 # Copyright (c) 1996, 1997 Christopher G. Demetriou
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # 3. All advertising materials mentioning features or use of this software
16 # must display the following acknowledgement:
17 # This product includes software developed for the
18 # NetBSD Project. See http://www.NetBSD.org/ for
19 # information about NetBSD.
20 # 4. The name of the author may not be used to endorse or promote products
21 # derived from this software without specific prior written permission.
23 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 # <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
36 usage()
39 cat << _EOF 1>&2
40 Usage: $PROG [-n|-p] [-o filename] [-s syscall.h] object ...
41 -n Create SYSCALL_NOERROR.
42 -p Create PSEUDO_NOERROR.
43 (also removes leading "_" on syscall name).
44 -o filename Output to filename.
45 -s syscall.h Header to #include instead of <sys/syscall.h>.
47 The CPP environment variable must be set
48 to the path to the C preprocessor.
49 _EOF
50 exit 1
53 header()
56 cat <<- __EOF__
58 * THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT.
61 #include <sys/param.h>
62 #include <sys/aio.h>
63 #include <sys/time.h>
64 #include <sys/mount.h>
65 #include <sys/stat.h>
66 #include <ufs/ufs/dinode.h>
67 #include <ufs/lfs/lfs.h>
68 #include <sys/resource.h>
69 #include <sys/poll.h>
70 #include <sys/uio.h>
71 #include <sys/ipc.h>
72 #include <sys/lwpctl.h>
73 #include <sys/mqueue.h>
74 #include <sys/msg.h>
75 #include <sys/sem.h>
76 #include <sys/shm.h>
77 #include <sys/spawn.h>
78 #include <sys/sched.h>
79 #include <sys/timex.h>
80 #include <sys/socket.h>
81 #include <sys/event.h>
82 #include <sys/uuid.h>
83 #include <sys/quotactl.h>
84 #ifdef __STDC__
85 #include <stdarg.h>
86 #else
87 #include <varargs.h>
88 #endif
90 __EOF__
93 syscall_stub()
96 syscalldump="$1"
97 syscallname="$2"
98 funcname="$3"
100 arglist="$(
101 sed -e 'ta
103 s,^/\* syscall: \"'"$syscallname"'\" ,,
107 s, \*/$,,' $syscalldump
110 eval set -f -- "$arglist"
112 if [ $# -lt 3 ]; then
113 echo syscall $syscallname not found! 1>&2
114 exit 1
117 shift # kill "ret:"
118 returntype=$1; shift
119 shift # kill "args:"
121 cat <<- __EOF__
122 /*ARGSUSED*/
123 $returntype
124 __EOF__
126 # do ANSI C function header
127 echo "#ifdef __STDC__"
129 echo "$funcname("
130 first=true; i=1
131 for arg; do
132 if $first; then
133 first=false
134 else
135 echo ", "
137 case "$arg" in
138 "...") echo "...";;
139 *) echo "$arg arg$i"; i=$(($i + 1));;
140 esac
141 done
142 if $first; then
143 echo "void"
145 echo ")"
147 # do K&R C function header
148 echo "#else"
150 echo "$funcname("
151 first=true; i=1
152 for arg; do
153 if $first; then
154 first=false
155 else
156 echo ", "
158 case "$arg" in
159 "...") echo "va_alist";;
160 *) echo "arg$i"; i=$(($i + 1));;
161 esac
162 done
163 echo ")"
165 for arg; do
166 case "$arg" in
167 "...") echo " va_dcl";;
168 *) echo " $arg arg$i;"; i=$(($i + 1));;
169 esac
170 done
172 # do function body
173 echo "#endif"
175 echo "{"
176 if [ "$returntype" != "void" ]; then
177 echo " return (($returntype)0);"
179 echo "}"
182 trailer()
185 cat <<- __EOF__
186 /* END */
187 __EOF__
191 pflag=false
192 nflag=false
193 oarg=""
194 syscallhdr=/usr/include/sys/syscall.h
195 syscalldump=/tmp/makelintstub.$$
196 PROG="$(basename "$0")"
198 if [ -z "${CPP}" ]; then
199 usage
202 while getopts no:ps: i
204 case "$i" in
205 n) nflag=true;;
206 o) oarg=$OPTARG;;
207 p) pflag=true;;
208 s) syscallhdr=$OPTARG;;
209 *) usage;;
210 esac
211 done
213 shift $(expr $OPTIND - 1)
215 if $pflag && $nflag
216 then
217 echo "$PROG: -n flag and -p flag may not be used together" 1>&2
218 usage
221 if [ -n "$oarg" ]; then
222 exec > $oarg
225 trap "rm -f $syscalldump" 0 1 2 3 15
227 header
229 echo "#include \"$syscallhdr\"" | ${CPP} -D_LIBC -C > $syscalldump
231 for syscall; do
232 fnname=${syscall%.S}
233 if $pflag; then
234 scname=${fnname#_}
235 else
236 scname=$fnname
238 syscall_stub $syscalldump $scname $fnname
239 echo ""
240 done
242 trailer
244 exit 0