xref: /freebsd/lib/libsysdecode/mkioctls (revision 1f4bcc459a76b7aa664f3fd557684cd0ba6da352)
1#!/bin/sh
2#
3# $FreeBSD$
4
5set -e
6
7if [ $# -ne 1 ]; then
8	echo "usage: sh $0 include-dir"
9	exit 1
10fi
11
12includedir="$1"
13
14LC_ALL=C; export LC_ALL
15
16# Build a list of headers that have ioctls in them.
17# XXX should we use an ANSI cpp?
18ioctl_includes=$(
19	cd $includedir
20	find -H -s * -name '*.h' | \
21	egrep -v '(.*disk.*|net/pfvar|net/if_pfsync)\.h' | \
22		xargs egrep -l \
23'^#[ 	]*define[ 	]+[A-Za-z_][A-Za-z0-9_]*[ 	]+_IO[^a-z0-9_]' |
24		awk '{printf("#include <%s>\\n", $1)}'
25)
26
27: ${MACHINE=$(uname -m)}
28case "${MACHINE}" in
29*pc98*)
30	ioctl_includes="$ioctl_includes#include <sys/diskpc98.h>\\n"
31	;;
32*)
33	ioctl_includes="$ioctl_includes#include <sys/diskmbr.h>\\n"
34	;;
35esac
36
37awk -v x="$ioctl_includes" 'BEGIN {print x}' |
38	$CPP -nostdinc -I$includedir -dM -DCOMPAT_43TTY - |
39	awk -v ioctl_includes="$ioctl_includes" '
40BEGIN {
41	print "/* XXX obnoxious prerequisites. */"
42	print "#define COMPAT_43"
43	print "#define COMPAT_43TTY"
44	print "#include <sys/param.h>"
45	print "#include <sys/devicestat.h>"
46	print "#include <sys/disklabel.h>"
47	print "#include <sys/socket.h>"
48	print "#include <sys/time.h>"
49	print "#include <sys/tty.h>"
50	print "#include <bsm/audit.h>"
51	print "#include <net/ethernet.h>"
52	print "#include <net/if.h>"
53	print "#ifdef PF"
54	print "#include <net/pfvar.h>"
55	print "#include <net/if_pfsync.h>"
56	print "#endif"
57	print "#include <net/route.h>"
58	print "#include <netinet/in.h>"
59	print "#include <netinet/ip_mroute.h>"
60	print "#include <netinet6/in6_var.h>"
61	print "#include <netinet6/nd6.h>"
62	print "#include <netinet6/ip6_mroute.h>"
63	print "#include <stdio.h>"
64	print "#include <cam/cam.h>"
65	print "#include <stddef.h>"
66	print "#include <stdint.h>"
67	print "#include <sysdecode.h>"
68	print ""
69	print ioctl_includes
70	print ""
71	print "const char *"
72	print "sysdecode_ioctlname(unsigned long val)"
73	print "{"
74	print "\tconst char *str = NULL;"
75	print ""
76}
77
78/^#[ 	]*define[ 	]+[A-Za-z_][A-Za-z0-9_]*[ 	]+_IO/ {
79
80	# find where the name starts
81	for (i = 1; i <= NF; i++)
82		if ($i ~ /define/)
83			break;
84	++i;
85	#
86	printf("\t");
87	if (n++ > 0)
88		printf("else ");
89	printf("if (val == %s)\n", $i);
90	printf("\t\tstr = \"%s\";\n", $i);
91}
92END {
93	print ""
94	print "\treturn (str);"
95	print "}"
96}
97'
98