xref: /dragonfly/usr.bin/kdump/mkioctls (revision 73610d44)
1#!/bin/sh
2#
3# $FreeBSD: src/usr.bin/kdump/mkioctls,v 1.15.2.5 2002/11/15 18:22:31 ru Exp $
4
5set -e
6
7if [ "x$1" = "x-s" ]; then
8	use_switch=1
9	shift
10else
11	use_switch=0
12fi
13
14if [ -z "$1" -o -z "$2" ]; then
15	echo "usage: sh $0 [-s] include-dir current-dir"
16	exit 1
17fi
18
19LC_ALL=C; export LC_ALL
20
21# Build a list of headers that have ioctls in them.
22# Leave out fake softlinks.
23ioctl_includes=`
24	cd $1
25	find -s * -name '*.h' -follow |
26		egrep -v '^(cam/)|^(compat/)|^(fs/)|^(isofs/)|^(mfs/)|^(msdosfs/)|^(netipsec/)|^(netkey/)|^(netsmb/)|^(nfs/)|^(ntfs/)|^(pccard/)|^(ufs/)' |
27		xargs egrep -l \
28'^#[ 	]*define[ 	]+[A-Za-z_][A-Za-z0-9_]*[ 	]+_IO[^a-z0-9_]' |
29		awk '{printf("#include <%s>\\\\n", $1)}'
30	printf '#undef loff_t /* XXX ext2_fs.h defines it */\\\\n'
31	printf '#include <dev/drm/include/uapi_drm/drm.h>\\\\n'
32	printf '#include <dev/drm/include/uapi_drm/i915_drm.h>\\\\n'
33	printf '#include <dev/drm/include/uapi_drm/radeon_drm.h>\\\\n'
34`
35
36awk -v x="$ioctl_includes" 'BEGIN {print x}' |
37	gcc -D_KERNEL_STRUCTURES -E -I$1 -I$2/../../sys -I$2/../../sys/dev/drm/include -dM - |
38	awk -v ioctl_includes="$ioctl_includes" -v use_switch="$use_switch" '
39BEGIN {
40	print "/* XXX obnoxious prerequisites. */"
41	print "#define COMPAT_43"
42	print "#define _KERNEL_STRUCTURES"
43	print "#include <sys/tty.h>"
44	print "#include <net/if_arp.h>"
45	print "#include <net/route.h>"
46	print "#include <netinet/in.h>"
47	print "#include <net/ip_mroute/ip_mroute.h>"
48	print "#include <netinet6/nd6.h>"
49	print "#include <netinet6/ip6_mroute.h>"
50	print "#include <stdio.h>"
51	print "#include <cam/cam.h>"
52	print "#define ACPI_DEBUG_OUTPUT"
53	print "#define ACPI_APPLICATION"
54	print "#include <contrib/dev/acpica/source/include/acpi.h>"
55	print "#undef ACPI_APPLICATION"
56	print "#undef ACPI_DEBUG_OUTPUT"
57	print ""
58	print ioctl_includes
59	print "const char *ioctlname(u_long);"
60	print ""
61	print "const char *"
62	print "ioctlname(u_long val)"
63	print "{"
64	if (use_switch)
65		print "\tswitch(val) {"
66}
67
68/^#[ 	]*define[ 	]+[A-Za-z_][A-Za-z0-9_]*[ 	]+_IO/ {
69
70	# find where the name starts
71	for (i = 1; i <= NF; i++)
72		if ($i ~ /define/)
73			break;
74	++i;
75	#
76	if (use_switch)
77		printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i);
78	else
79		printf("\tif (val ==  %s)\n\t\treturn(\"%s\");\n", $i, $i);
80
81}
82
83/^#[ 	]*define[ 	]+[^ 	]+[ 	]+DRM_IO/ {
84	if (use_switch)
85		printf("\tcase %s:\n\t\treturn(\"%s\");\n", $2, $2);
86	else
87		printf("\tif (val ==  %s)\n\t\treturn(\"%s\");\n", $2, $2);
88}
89
90/^#[ 	]*define[ 	]+[^ 	]+[ 	]+MIXER_(READ|WRITE)/ {
91	if (use_switch)
92		printf("\tcase %s:\n\t\treturn(\"%s\");\n", $2, $2);
93	else
94		printf("\tif (val ==  %s)\n\t\treturn(\"%s\");\n", $2, $2);
95}
96
97END {
98	if (use_switch)
99		print "\t}"
100	print "\n\treturn(NULL);"
101	print "}"
102}
103'
104