Avoid hardcoding any paths and variables. The include directory must

now be specified on the command line. Accept a '-s' option which
controls whether a switch-statement is to be used instead of a series
of if-statements.

Replace cpp with gcc -E.

Discussed with: bde
This commit is contained in:
Marcel Moolenaar 1999-12-03 12:50:02 +00:00
parent 82a9a36d9f
commit e2366ecc70
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=54081
2 changed files with 19 additions and 8 deletions

View file

@ -8,6 +8,6 @@ SRCS= kdump.c ioctl.c subr.c
CLEANFILES+=ioctl.c
ioctl.c: mkioctls
DESTDIR=${DESTDIR} /bin/sh ${.CURDIR}/mkioctls > ioctl.c
sh ${.CURDIR}/mkioctls ${DESTDIR}/usr/include > ioctl.c
.include <bsd.prog.mk>

View file

@ -2,11 +2,23 @@ set -e
# $FreeBSD$
if [ "x$1" = "x-s" ]; then
use_switch=1
shift
else
use_switch=0
fi
if [ -z "$1" ]; then
echo "usage: sh $0 [-s] include-dir"
exit 1
fi
# Build a list of headers that have ioctls in them.
# XXX should we use an ANSI cpp?
# XXX netipx conflicts with netns (leave out netns).
ioctl_includes=`
cd $DESTDIR/usr/include
cd $1
find * -name '*.h' -follow |
egrep -v '^(netns)/' |
xargs egrep -l \
@ -15,8 +27,8 @@ ioctl_includes=`
`
echo "$ioctl_includes" |
cpp -I$DESTDIR/usr/include -dM |
awk -v ioctl_includes="$ioctl_includes" '
gcc -E -I$1 -dM - |
awk -v ioctl_includes="$ioctl_includes" -v use_switch="$use_switch" '
BEGIN {
print "/* XXX obnoxious prerequisites. */"
print "#define COMPAT_43"
@ -51,8 +63,7 @@ BEGIN {
print "ioctlname(register_t val)"
print "{"
print ""
generate_case_statement = 0
if (generate_case_statement)
if (use_switch)
print "\tswitch(val) {"
}
@ -64,14 +75,14 @@ BEGIN {
break;
++i;
#
if (generate_case_statement)
if (use_switch)
printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i);
else
printf("\tif (val == %s)\n\t\treturn(\"%s\");\n", $i, $i);
}
END {
if (generate_case_statement)
if (use_switch)
print "\t}"
print "\n\treturn(NULL);"
print "}"