Sync usage with man page.
[netbsd-mini2440.git] / sys / rump / librump / makerumpif.sh
blobbe617feeee0e87616fe52ead99c046113d45eedd
1 #!/bin/sh
3 # $NetBSD: makerumpif.sh,v 1.3 2009/10/14 18:14:48 pooka Exp $
5 # Copyright (c) 2009 Antti Kantee. All rights reserved.
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.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # This reads a rump component interface description and creates:
30 # 1: rump private prototypes for internal calls
31 # 2: public prototypes for calls outside of rump
32 # 3: public interface implementations which run the rump scheduler
33 # and call the private interface
36 usage ()
39 echo "usage: $0 spec"
40 exit 1
43 boom ()
46 echo $*
47 exit 1
50 [ $# != 1 ] && usage
52 MYDIR=`pwd`
53 while [ ! -f Makefile.rump ]; do
54 [ `pwd` = '/' ] && boom Could not find rump topdir.
55 cd ..
56 done
57 RUMPTOP="`pwd`"
58 cd ${MYDIR}
60 sed -e '
61 :again
62 /\\$/{
64 s/[ ]*\\\n[ ]*/ /
65 b again
67 ' ${1} | awk -F\| -v rumptop=${RUMPTOP} '
68 function fileheaders(file, srcstr)
70 printf("/*\t$NetBSD: makerumpif.sh,v 1.3 2009/10/14 18:14:48 pooka Exp $\t*/\n\n") > file
71 printf("/*\n * Automatically generated. DO NOT EDIT.\n") > file
72 genstr = "$NetBSD: makerumpif.sh,v 1.3 2009/10/14 18:14:48 pooka Exp $"
73 gsub("\\$", "", genstr)
74 printf(" * from: %s\n", srcstr) > file
75 printf(" * by: %s\n", genstr) > file
76 printf(" */\n") > file
79 function die(str)
82 print str
83 exit(1)
86 NR == 1 {
87 sub(";[^\\$]*\\$", "")
88 sub("\\$", "")
89 fromstr = $0
90 next
93 $1 == "NAME"{myname = $2;next}
94 $1 == "PUBHDR"{pubhdr = rumptop "/" $2;next}
95 $1 == "PRIVHDR"{privhdr = rumptop "/" $2;next}
96 $1 == "WRAPPERS"{gencalls = rumptop "/" $2;next}
98 /^;/{next}
99 /\\$/{sub("\\\n", "");getline nextline;$0 = $0 nextline}
100 /^[ \t]*$/{next}
102 if (NF != 3 && NF != 4) {
103 die("error: unexpected number of fields\n")
105 if (NF == 4) {
106 if ($4 == "WEAK")
107 isweak = 1
108 else
109 die("error: unexpected fourth field");
110 } else {
111 isweak = 0
113 if (!myname)
114 die("name not specified");
115 if (!pubhdr)
116 die("public header not specified");
117 if (!privhdr)
118 die("private header not specified");
119 if (!gencalls)
120 die("wrapper file not specified");
122 if (!once) {
123 fileheaders(pubhdr, fromstr)
124 fileheaders(privhdr, fromstr)
125 fileheaders(gencalls, fromstr)
126 once = 1
128 pubfile = pubhdr
129 sub(".*/", "", pubfile)
131 privfile = privhdr
132 sub(".*/", "", privfile)
134 printf("\n") > pubhdr
135 printf("\n") > privhdr
137 printf("\n#include <sys/cdefs.h>\n") > gencalls
138 printf("#include <sys/systm.h>\n") > gencalls
139 printf("\n#include <rump/rump.h>\n") > gencalls
140 printf("#include <rump/%s>\n\n", pubfile) > gencalls
141 printf("#include \"rump_private.h\"\n", privfile) > gencalls
142 printf("#include \"%s\"\n\n", privfile) > gencalls
143 printf("void __dead rump_%s_unavailable(void);\n", \
144 myname) > gencalls
145 printf("void __dead\nrump_%s_unavailable(void)\n{\n", \
146 myname) > gencalls
147 printf("\n\tpanic(\"%s interface unavailable\");\n}\n", \
148 myname) > gencalls
151 funtype = $1
152 sub("[ \t]*$", "", funtype)
153 funname = $2
154 sub("[ \t]*$", "", funname)
155 funargs = $3
156 sub("[ \t]*$", "", funargs)
158 printf("%s rump_pub_%s(%s);\n", funtype, funname, funargs) > pubhdr
159 printf("%s rump_%s(%s);\n", funtype, funname, funargs) > privhdr
161 if (funtype == "void")
162 voidret = 1
163 else
164 voidret = 0
165 if (funargs == "void")
166 voidarg = 1
167 else
168 voidarg = 0
170 printf("\n%s\nrump_pub_%s(", funtype, funname) > gencalls
171 if (!voidarg) {
172 narg = split(funargs, argv, ",")
173 for (i = 1; i <= narg; i++) {
174 sub(" *", "", argv[i])
175 if (match(argv[i], "\\*$") != 0)
176 printf("%sarg%d", argv[i], i) > gencalls
177 else
178 printf("%s arg%d", argv[i], i) > gencalls
179 if (i != narg)
180 printf(", ") > gencalls
182 } else {
183 narg = 0
184 printf("void") > gencalls
186 printf(")\n{\n") > gencalls
188 if (!voidret) {
189 printf("\t%s rv;\n", funtype) > gencalls
191 printf("\n\trump_schedule();\n\t") > gencalls
192 if (!voidret)
193 printf("rv = ") > gencalls
194 printf("rump_%s(", funname) > gencalls
195 for (i = 1; i <= narg; i++) {
196 printf("arg%i", i) > gencalls
197 if (i < narg)
198 printf(", ") > gencalls
200 printf(");\n\trump_unschedule();\n") > gencalls
201 if (!voidret)
202 printf("\n\treturn rv;\n") > gencalls
203 printf("}\n") > gencalls
204 if (isweak)
205 printf("__weak_alias(rump_%s,rump_%s_unavailable);\n", \
206 funname, myname) > gencalls