makelintstub revision 1.22
11.1Scgd#!/bin/sh -
21.22Slukem# $NetBSD: makelintstub,v 1.22 2008/08/05 01:54:47 lukem Exp $
31.1Scgd#
41.7Scgd# Copyright (c) 1996, 1997 Christopher G. Demetriou
51.7Scgd# All rights reserved.
61.7Scgd# 
71.1Scgd# Redistribution and use in source and binary forms, with or without
81.1Scgd# modification, are permitted provided that the following conditions
91.1Scgd# are met:
101.1Scgd# 1. Redistributions of source code must retain the above copyright
111.1Scgd#    notice, this list of conditions and the following disclaimer.
121.1Scgd# 2. Redistributions in binary form must reproduce the above copyright
131.1Scgd#    notice, this list of conditions and the following disclaimer in the
141.1Scgd#    documentation and/or other materials provided with the distribution.
151.1Scgd# 3. All advertising materials mentioning features or use of this software
161.1Scgd#    must display the following acknowledgement:
171.7Scgd#          This product includes software developed for the
181.14Ssalo#          NetBSD Project.  See http://www.NetBSD.org/ for
191.7Scgd#          information about NetBSD.
201.1Scgd# 4. The name of the author may not be used to endorse or promote products
211.7Scgd#    derived from this software without specific prior written permission.
221.7Scgd# 
231.1Scgd# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
241.1Scgd# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
251.1Scgd# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
261.1Scgd# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
271.1Scgd# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
281.1Scgd# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
291.1Scgd# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
301.1Scgd# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
311.1Scgd# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
321.1Scgd# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
331.7Scgd# 
341.7Scgd# <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
351.1Scgd
361.2Sthorpejusage()
371.2Sthorpej{
381.2Sthorpej
391.17Schristoscat << _EOF 1>&2
401.22SlukemUsage: $PROG [-n|-p] [-e sedcmd] [-o filename] [-s syscall.h] object ...
411.22Slukem	-e sedcmd	sed(1) command to translate filename to syscall name.
421.22Slukem			The ".S" suffix is always removed.
431.22Slukem			Multiple sed commands may be supplied.
441.22Slukem	-n		Create SYSCALL_NOERROR.
451.22Slukem	-p		Create PSEUDO_NOERROR.
461.22Slukem			(also removes leading "_" on syscall name).
471.22Slukem	-o filename	Output to filename.
481.22Slukem	-s syscall.h	Header to #include instead of <sys/syscall.h>.
491.22Slukem
501.17Schristos	The CPP environment variable must be set
511.17Schristos	to the path to the C preprocessor.
521.17Schristos_EOF
531.1Scgd	exit 1
541.2Sthorpej}
551.1Scgd
561.2Sthorpejheader()
571.2Sthorpej{
581.1Scgd
591.2Sthorpej	cat <<- __EOF__
601.2Sthorpej	/*
611.2Sthorpej	 * THIS IS AN AUTOMATICALLY GENERATED FILE.  DO NOT EDIT.
621.2Sthorpej	 */
631.2Sthorpej
641.2Sthorpej	#include <sys/param.h>
651.19Srmind	#include <sys/aio.h>
661.2Sthorpej	#include <sys/time.h>
671.2Sthorpej	#include <sys/mount.h>
681.2Sthorpej	#include <sys/stat.h>
691.3Sfvdl	#include <ufs/ufs/dinode.h>
701.2Sthorpej	#include <ufs/lfs/lfs.h>
711.2Sthorpej	#include <sys/resource.h>
721.2Sthorpej	#include <sys/poll.h>
731.2Sthorpej	#include <sys/uio.h>
741.2Sthorpej	#include <sys/ipc.h>
751.20She	#include <sys/lwpctl.h>
761.19Srmind	#include <sys/mqueue.h>
771.2Sthorpej	#include <sys/msg.h>
781.2Sthorpej	#include <sys/sem.h>
791.2Sthorpej	#include <sys/shm.h>
801.21Srmind	#include <sys/sched.h>
811.2Sthorpej	#include <sys/timex.h>
821.2Sthorpej	#include <sys/socket.h>
831.10Sjdolecek	#include <sys/event.h>
841.16Stsarna	#include <sys/uuid.h>
851.2Sthorpej	#ifdef __STDC__
861.2Sthorpej	#include <stdarg.h>
871.2Sthorpej	#else
881.2Sthorpej	#include <varargs.h>
891.2Sthorpej	#endif
901.2Sthorpej
911.2Sthorpej	__EOF__
921.2Sthorpej}
931.2Sthorpej
941.2Sthorpejsyscall_stub()
951.2Sthorpej{
961.2Sthorpej
971.4Smycroft	syscalldump="$1"
981.2Sthorpej	syscallname="$2"
991.2Sthorpej	funcname="$3"
1001.2Sthorpej
1011.17Schristos    	arglist="$(
1021.4Smycroft    	sed -e 'ta
1031.4Smycroft		:a
1041.9Sthorpej		s,^/\* syscall: \"'"$syscallname"'\" ,,
1051.4Smycroft	        tb
1061.4Smycroft		d
1071.4Smycroft		:b
1081.4Smycroft		s, \*/$,,' $syscalldump
1091.17Schristos	)"
1101.2Sthorpej
1111.2Sthorpej	eval set -f -- "$arglist"
1121.2Sthorpej
1131.4Smycroft	if [ $# -lt 3 ]; then
1141.2Sthorpej		echo syscall $syscallname not found! 1>&2
1151.2Sthorpej		exit 1
1161.2Sthorpej	fi
1171.1Scgd
1181.4Smycroft	shift			# kill "ret:"
1191.4Smycroft	returntype=$1; shift
1201.4Smycroft	shift			# kill "args:"
1211.2Sthorpej
1221.2Sthorpej	cat <<- __EOF__
1231.2Sthorpej	/*ARGSUSED*/
1241.2Sthorpej	$returntype
1251.2Sthorpej	__EOF__
1261.2Sthorpej
1271.2Sthorpej	# do ANSI C function header
1281.5Smycroft	echo	"#ifdef __STDC__"
1291.2Sthorpej
1301.9Sthorpej	echo "$funcname("
1311.17Schristos	first=true; i=1
1321.5Smycroft	for arg; do
1331.17Schristos		if $first; then
1341.17Schristos			first=false
1351.5Smycroft		else
1361.9Sthorpej			echo ", "
1371.2Sthorpej		fi
1381.5Smycroft		case "$arg" in
1391.9Sthorpej		"...") echo "...";;
1401.9Sthorpej		*) echo "$arg arg$i"; i=$(($i + 1));;
1411.5Smycroft		esac
1421.5Smycroft	done
1431.17Schristos	if $first; then
1441.9Sthorpej		echo "void"
1451.9Sthorpej	fi
1461.5Smycroft	echo	")"
1471.1Scgd
1481.5Smycroft	# do K&R C function header
1491.5Smycroft	echo	"#else"
1501.1Scgd
1511.9Sthorpej	echo "$funcname("
1521.17Schristos	first=true; i=1
1531.5Smycroft	for arg; do
1541.17Schristos		if $first; then
1551.17Schristos			first=false
1561.5Smycroft		else
1571.9Sthorpej			echo ", "
1581.2Sthorpej		fi
1591.5Smycroft		case "$arg" in
1601.9Sthorpej		"...") echo "va_alist";;
1611.9Sthorpej		*) echo "arg$i"; i=$(($i + 1));;
1621.5Smycroft		esac
1631.2Sthorpej	done
1641.2Sthorpej	echo	")"
1651.2Sthorpej	i=1
1661.5Smycroft	for arg; do
1671.5Smycroft		case "$arg" in
1681.5Smycroft		"...") echo "	va_dcl";;
1691.5Smycroft		*) echo "	$arg arg$i;"; i=$(($i + 1));;
1701.5Smycroft		esac
1711.2Sthorpej	done
1721.1Scgd
1731.2Sthorpej	# do function body
1741.5Smycroft	echo	"#endif"
1751.5Smycroft
1761.2Sthorpej	echo	"{"
1771.2Sthorpej	if [ "$returntype" != "void" ]; then
1781.2Sthorpej		echo "        return (($returntype)0);"
1791.2Sthorpej	fi
1801.2Sthorpej	echo	"}"
1811.2Sthorpej}
1821.2Sthorpej
1831.2Sthorpejtrailer()
1841.2Sthorpej{
1851.2Sthorpej
1861.2Sthorpej	cat <<- __EOF__
1871.2Sthorpej	/* END */
1881.2Sthorpej	__EOF__
1891.2Sthorpej}
1901.2Sthorpej
1911.2Sthorpej
1921.17Schristospflag=false
1931.17Schristosnflag=false
1941.2Sthorpejoarg=""
1951.22Slukemfnsedcmd=""
1961.2Sthorpejsyscallhdr=/usr/include/sys/syscall.h
1971.4Smycroftsyscalldump=/tmp/makelintstub.$$
1981.17SchristosPROG="$(basename "$0")"
1991.2Sthorpej
2001.17Schristosif [ -z "${CPP}" ]; then
2011.9Sthorpej	usage
2021.9Sthorpejfi
2031.9Sthorpej
2041.22Slukemwhile getopts e:no:ps: i
2051.17Schristosdo
2061.2Sthorpej	case "$i" in
2071.22Slukem	e)	fnsedcmd="$fnsedcmd -e $OPTARG";;
2081.17Schristos	n)	nflag=true;;
2091.17Schristos	o)	oarg=$OPTARG;;
2101.17Schristos	p)	pflag=true;;
2111.17Schristos	s)	syscallhdr=$OPTARG;;
2121.17Schristos	*)	usage;;
2131.2Sthorpej	esac
2141.1Scgddone
2151.1Scgd
2161.17Schristosshift $(expr $OPTIND - 1)
2171.17Schristos
2181.17Schristosif $pflag && $nflag
2191.17Schristosthen
2201.17Schristos	echo "$PROG: -n flag and -p flag may not be used together" 1>&2
2211.2Sthorpej	usage
2221.2Sthorpejfi
2231.2Sthorpej
2241.17Schristosif [ -n "$oarg" ]; then
2251.2Sthorpej	exec > $oarg
2261.2Sthorpejfi
2271.2Sthorpej
2281.17Schristostrap "rm -f $syscalldump" 0 1 2 3 15
2291.4Smycroft
2301.2Sthorpejheader
2311.17Schristos
2321.17Schristosecho "#include \"$syscallhdr\"" | ${CPP} -D_LIBC -C > $syscalldump
2331.17Schristos
2341.2Sthorpejfor syscall; do
2351.8Stv	fnname=${syscall%.S}
2361.22Slukem	if [ -n "$fnsedcmd" ]; then
2371.22Slukem		fnname=$(echo "$fnname" | sed $fnsedcmd)
2381.22Slukem	fi
2391.17Schristos	if $pflag; then
2401.4Smycroft		scname=${fnname#_}
2411.2Sthorpej	else
2421.2Sthorpej		scname=$fnname
2431.1Scgd	fi
2441.4Smycroft	syscall_stub $syscalldump $scname $fnname
2451.2Sthorpej	echo ""
2461.1Scgddone
2471.17Schristos
2481.2Sthorpejtrailer
2491.1Scgd
2501.1Scgdexit 0
251