xref: /minix3/lib/libc/sys/makelintstub (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
12fe8fb19SBen Gras#!/bin/sh -
2*f14fb602SLionel Sambuc# $NetBSD: makelintstub,v 1.25 2012/02/12 01:46:05 martin Exp $
32fe8fb19SBen Gras#
42fe8fb19SBen Gras# Copyright (c) 1996, 1997 Christopher G. Demetriou
52fe8fb19SBen Gras# All rights reserved.
62fe8fb19SBen Gras#
72fe8fb19SBen Gras# Redistribution and use in source and binary forms, with or without
82fe8fb19SBen Gras# modification, are permitted provided that the following conditions
92fe8fb19SBen Gras# are met:
102fe8fb19SBen Gras# 1. Redistributions of source code must retain the above copyright
112fe8fb19SBen Gras#    notice, this list of conditions and the following disclaimer.
122fe8fb19SBen Gras# 2. Redistributions in binary form must reproduce the above copyright
132fe8fb19SBen Gras#    notice, this list of conditions and the following disclaimer in the
142fe8fb19SBen Gras#    documentation and/or other materials provided with the distribution.
152fe8fb19SBen Gras# 3. All advertising materials mentioning features or use of this software
162fe8fb19SBen Gras#    must display the following acknowledgement:
172fe8fb19SBen Gras#          This product includes software developed for the
182fe8fb19SBen Gras#          NetBSD Project.  See http://www.NetBSD.org/ for
192fe8fb19SBen Gras#          information about NetBSD.
202fe8fb19SBen Gras# 4. The name of the author may not be used to endorse or promote products
212fe8fb19SBen Gras#    derived from this software without specific prior written permission.
222fe8fb19SBen Gras#
232fe8fb19SBen Gras# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
242fe8fb19SBen Gras# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
252fe8fb19SBen Gras# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
262fe8fb19SBen Gras# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
272fe8fb19SBen Gras# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
282fe8fb19SBen Gras# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
292fe8fb19SBen Gras# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
302fe8fb19SBen Gras# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
312fe8fb19SBen Gras# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
322fe8fb19SBen Gras# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
332fe8fb19SBen Gras#
342fe8fb19SBen Gras# <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
352fe8fb19SBen Gras
362fe8fb19SBen Grasusage()
372fe8fb19SBen Gras{
382fe8fb19SBen Gras
392fe8fb19SBen Grascat << _EOF 1>&2
402fe8fb19SBen GrasUsage: $PROG [-n|-p] [-o filename] [-s syscall.h] object ...
412fe8fb19SBen Gras	-n		Create SYSCALL_NOERROR.
422fe8fb19SBen Gras	-p		Create PSEUDO_NOERROR.
432fe8fb19SBen Gras			(also removes leading "_" on syscall name).
442fe8fb19SBen Gras	-o filename	Output to filename.
452fe8fb19SBen Gras	-s syscall.h	Header to #include instead of <sys/syscall.h>.
462fe8fb19SBen Gras
472fe8fb19SBen Gras	The CPP environment variable must be set
482fe8fb19SBen Gras	to the path to the C preprocessor.
492fe8fb19SBen Gras_EOF
502fe8fb19SBen Gras	exit 1
512fe8fb19SBen Gras}
522fe8fb19SBen Gras
532fe8fb19SBen Grasheader()
542fe8fb19SBen Gras{
552fe8fb19SBen Gras
562fe8fb19SBen Gras	cat <<- __EOF__
572fe8fb19SBen Gras	/*
582fe8fb19SBen Gras	 * THIS IS AN AUTOMATICALLY GENERATED FILE.  DO NOT EDIT.
592fe8fb19SBen Gras	 */
602fe8fb19SBen Gras
612fe8fb19SBen Gras	#include <sys/param.h>
622fe8fb19SBen Gras	#include <sys/aio.h>
632fe8fb19SBen Gras	#include <sys/time.h>
642fe8fb19SBen Gras	#include <sys/mount.h>
652fe8fb19SBen Gras	#include <sys/stat.h>
662fe8fb19SBen Gras	#include <ufs/ufs/dinode.h>
672fe8fb19SBen Gras	#include <ufs/lfs/lfs.h>
682fe8fb19SBen Gras	#include <sys/resource.h>
692fe8fb19SBen Gras	#include <sys/poll.h>
702fe8fb19SBen Gras	#include <sys/uio.h>
712fe8fb19SBen Gras	#include <sys/ipc.h>
722fe8fb19SBen Gras	#include <sys/lwpctl.h>
732fe8fb19SBen Gras	#include <sys/mqueue.h>
742fe8fb19SBen Gras	#include <sys/msg.h>
752fe8fb19SBen Gras	#include <sys/sem.h>
762fe8fb19SBen Gras	#include <sys/shm.h>
77*f14fb602SLionel Sambuc	#include <sys/spawn.h>
782fe8fb19SBen Gras	#include <sys/sched.h>
792fe8fb19SBen Gras	#include <sys/timex.h>
802fe8fb19SBen Gras	#include <sys/socket.h>
812fe8fb19SBen Gras	#include <sys/event.h>
822fe8fb19SBen Gras	#include <sys/uuid.h>
83*f14fb602SLionel Sambuc	#include <sys/quotactl.h>
842fe8fb19SBen Gras	#ifdef __STDC__
852fe8fb19SBen Gras	#include <stdarg.h>
862fe8fb19SBen Gras	#else
872fe8fb19SBen Gras	#include <varargs.h>
882fe8fb19SBen Gras	#endif
892fe8fb19SBen Gras
902fe8fb19SBen Gras	__EOF__
912fe8fb19SBen Gras}
922fe8fb19SBen Gras
932fe8fb19SBen Grassyscall_stub()
942fe8fb19SBen Gras{
952fe8fb19SBen Gras
962fe8fb19SBen Gras	syscalldump="$1"
972fe8fb19SBen Gras	syscallname="$2"
982fe8fb19SBen Gras	funcname="$3"
992fe8fb19SBen Gras
1002fe8fb19SBen Gras    	arglist="$(
1012fe8fb19SBen Gras    	sed -e 'ta
1022fe8fb19SBen Gras		:a
1032fe8fb19SBen Gras		s,^/\* syscall: \"'"$syscallname"'\" ,,
1042fe8fb19SBen Gras	        tb
1052fe8fb19SBen Gras		d
1062fe8fb19SBen Gras		:b
1072fe8fb19SBen Gras		s, \*/$,,' $syscalldump
1082fe8fb19SBen Gras	)"
1092fe8fb19SBen Gras
1102fe8fb19SBen Gras	eval set -f -- "$arglist"
1112fe8fb19SBen Gras
1122fe8fb19SBen Gras	if [ $# -lt 3 ]; then
1132fe8fb19SBen Gras		echo syscall $syscallname not found! 1>&2
1142fe8fb19SBen Gras		exit 1
1152fe8fb19SBen Gras	fi
1162fe8fb19SBen Gras
1172fe8fb19SBen Gras	shift			# kill "ret:"
1182fe8fb19SBen Gras	returntype=$1; shift
1192fe8fb19SBen Gras	shift			# kill "args:"
1202fe8fb19SBen Gras
1212fe8fb19SBen Gras	cat <<- __EOF__
1222fe8fb19SBen Gras	/*ARGSUSED*/
1232fe8fb19SBen Gras	$returntype
1242fe8fb19SBen Gras	__EOF__
1252fe8fb19SBen Gras
1262fe8fb19SBen Gras	# do ANSI C function header
1272fe8fb19SBen Gras	echo	"#ifdef __STDC__"
1282fe8fb19SBen Gras
1292fe8fb19SBen Gras	echo "$funcname("
1302fe8fb19SBen Gras	first=true; i=1
1312fe8fb19SBen Gras	for arg; do
1322fe8fb19SBen Gras		if $first; then
1332fe8fb19SBen Gras			first=false
1342fe8fb19SBen Gras		else
1352fe8fb19SBen Gras			echo ", "
1362fe8fb19SBen Gras		fi
1372fe8fb19SBen Gras		case "$arg" in
1382fe8fb19SBen Gras		"...") echo "...";;
1392fe8fb19SBen Gras		*) echo "$arg arg$i"; i=$(($i + 1));;
1402fe8fb19SBen Gras		esac
1412fe8fb19SBen Gras	done
1422fe8fb19SBen Gras	if $first; then
1432fe8fb19SBen Gras		echo "void"
1442fe8fb19SBen Gras	fi
1452fe8fb19SBen Gras	echo	")"
1462fe8fb19SBen Gras
1472fe8fb19SBen Gras	# do K&R C function header
1482fe8fb19SBen Gras	echo	"#else"
1492fe8fb19SBen Gras
1502fe8fb19SBen Gras	echo "$funcname("
1512fe8fb19SBen Gras	first=true; i=1
1522fe8fb19SBen Gras	for arg; do
1532fe8fb19SBen Gras		if $first; then
1542fe8fb19SBen Gras			first=false
1552fe8fb19SBen Gras		else
1562fe8fb19SBen Gras			echo ", "
1572fe8fb19SBen Gras		fi
1582fe8fb19SBen Gras		case "$arg" in
1592fe8fb19SBen Gras		"...") echo "va_alist";;
1602fe8fb19SBen Gras		*) echo "arg$i"; i=$(($i + 1));;
1612fe8fb19SBen Gras		esac
1622fe8fb19SBen Gras	done
1632fe8fb19SBen Gras	echo	")"
1642fe8fb19SBen Gras	i=1
1652fe8fb19SBen Gras	for arg; do
1662fe8fb19SBen Gras		case "$arg" in
1672fe8fb19SBen Gras		"...") echo "	va_dcl";;
1682fe8fb19SBen Gras		*) echo "	$arg arg$i;"; i=$(($i + 1));;
1692fe8fb19SBen Gras		esac
1702fe8fb19SBen Gras	done
1712fe8fb19SBen Gras
1722fe8fb19SBen Gras	# do function body
1732fe8fb19SBen Gras	echo	"#endif"
1742fe8fb19SBen Gras
1752fe8fb19SBen Gras	echo	"{"
1762fe8fb19SBen Gras	if [ "$returntype" != "void" ]; then
1772fe8fb19SBen Gras		echo "        return (($returntype)0);"
1782fe8fb19SBen Gras	fi
1792fe8fb19SBen Gras	echo	"}"
1802fe8fb19SBen Gras}
1812fe8fb19SBen Gras
1822fe8fb19SBen Grastrailer()
1832fe8fb19SBen Gras{
1842fe8fb19SBen Gras
1852fe8fb19SBen Gras	cat <<- __EOF__
1862fe8fb19SBen Gras	/* END */
1872fe8fb19SBen Gras	__EOF__
1882fe8fb19SBen Gras}
1892fe8fb19SBen Gras
1902fe8fb19SBen Gras
1912fe8fb19SBen Graspflag=false
1922fe8fb19SBen Grasnflag=false
1932fe8fb19SBen Grasoarg=""
1942fe8fb19SBen Grassyscallhdr=/usr/include/sys/syscall.h
1952fe8fb19SBen Grassyscalldump=/tmp/makelintstub.$$
1962fe8fb19SBen GrasPROG="$(basename "$0")"
1972fe8fb19SBen Gras
1982fe8fb19SBen Grasif [ -z "${CPP}" ]; then
1992fe8fb19SBen Gras	usage
2002fe8fb19SBen Grasfi
2012fe8fb19SBen Gras
2022fe8fb19SBen Graswhile getopts no:ps: i
2032fe8fb19SBen Grasdo
2042fe8fb19SBen Gras	case "$i" in
2052fe8fb19SBen Gras	n)	nflag=true;;
2062fe8fb19SBen Gras	o)	oarg=$OPTARG;;
2072fe8fb19SBen Gras	p)	pflag=true;;
2082fe8fb19SBen Gras	s)	syscallhdr=$OPTARG;;
2092fe8fb19SBen Gras	*)	usage;;
2102fe8fb19SBen Gras	esac
2112fe8fb19SBen Grasdone
2122fe8fb19SBen Gras
2132fe8fb19SBen Grasshift $(expr $OPTIND - 1)
2142fe8fb19SBen Gras
2152fe8fb19SBen Grasif $pflag && $nflag
2162fe8fb19SBen Grasthen
2172fe8fb19SBen Gras	echo "$PROG: -n flag and -p flag may not be used together" 1>&2
2182fe8fb19SBen Gras	usage
2192fe8fb19SBen Grasfi
2202fe8fb19SBen Gras
2212fe8fb19SBen Grasif [ -n "$oarg" ]; then
2222fe8fb19SBen Gras	exec > $oarg
2232fe8fb19SBen Grasfi
2242fe8fb19SBen Gras
2252fe8fb19SBen Grastrap "rm -f $syscalldump" 0 1 2 3 15
2262fe8fb19SBen Gras
2272fe8fb19SBen Grasheader
2282fe8fb19SBen Gras
2292fe8fb19SBen Grasecho "#include \"$syscallhdr\"" | ${CPP} -D_LIBC -C > $syscalldump
2302fe8fb19SBen Gras
2312fe8fb19SBen Grasfor syscall; do
2322fe8fb19SBen Gras	fnname=${syscall%.S}
2332fe8fb19SBen Gras	if $pflag; then
2342fe8fb19SBen Gras		scname=${fnname#_}
2352fe8fb19SBen Gras	else
2362fe8fb19SBen Gras		scname=$fnname
2372fe8fb19SBen Gras	fi
2382fe8fb19SBen Gras	syscall_stub $syscalldump $scname $fnname
2392fe8fb19SBen Gras	echo ""
2402fe8fb19SBen Grasdone
2412fe8fb19SBen Gras
2422fe8fb19SBen Grastrailer
2432fe8fb19SBen Gras
2442fe8fb19SBen Grasexit 0
245