17c80b32221fb9165c0409124b43d5f4548661c1
[dragonfly.git] / usr.bin / kdump / mkioctls
1 set -e
2
3 # $FreeBSD: src/usr.bin/kdump/mkioctls,v 1.15.2.5 2002/11/15 18:22:31 ru Exp $
4 # $DragonFly: src/usr.bin/kdump/mkioctls,v 1.5 2004/03/21 02:09:15 dillon Exp $
5
6 if [ "x$1" = "x-s" ]; then
7         use_switch=1
8         shift
9 else
10         use_switch=0
11 fi
12
13 if [ -z "$1" ]; then
14         echo "usage: sh $0 [-s] include-dir"
15         exit 1
16 fi
17
18 LC_ALL=C; export LC_ALL
19
20 # Build a list of headers that have ioctls in them.
21 # XXX should we use an ANSI cpp?
22 # XXX netipx conflicts with netns (leave out netns).
23 # XXX leave out cam/, isa/ pccard/, pci/, and usb/ because they
24 #     are fake softlinks and handled by bus/
25 ioctl_includes=`
26         cd $1
27         find -s * -name '*.h' -follow |
28                 egrep -v '^(netns/)|^(cam/)|^(isa/)|^(pccard/)|^(pci/)|^(usb/)|^(netproto/natm/)' |
29                 xargs egrep -l \
30 '^#[    ]*define[       ]+[A-Za-z_][A-Za-z0-9_]*[       ]+_IO[^a-z0-9_]' |
31                 awk '{printf("#include <%s>\\\\n", $1)}'
32 `
33
34 awk -v x="$ioctl_includes" 'BEGIN {print x}' |
35         gcc -E -I$1 -dM - |
36         awk -v ioctl_includes="$ioctl_includes" -v use_switch="$use_switch" '
37 BEGIN {
38         print "/* XXX obnoxious prerequisites. */"
39         print "#define COMPAT_43"
40         print "#include <sys/param.h>"
41         print "#include <sys/devicestat.h>"
42         print "#include <sys/disklabel.h>"
43         print "#include <sys/socket.h>"
44         print "#include <sys/time.h>"
45         print "#include <sys/tty.h>"
46         print "#include <net/ethernet.h>"
47         print "#include <net/if.h>"
48         print "#include <net/if_var.h>"
49         print "#include <net/route.h>"
50         print "#include <netatm/atm.h>"
51         print "#include <netatm/atm_if.h>"
52         print "#include <netatm/atm_sap.h>"
53         print "#include <netatm/atm_sys.h>"
54         print "#include <netinet/in.h>"
55         print "#include <net/ip_mroute/ip_mroute.h>"
56         print "#include <netinet6/in6_var.h>"
57         print "#include <netinet6/nd6.h>"
58         print "#include <netinet6/ip6_mroute.h>"
59         print "#include <cam/cam.h>"
60         print "#include <stdio.h>"
61         print ""
62         print ioctl_includes
63         print ""
64         print "char *"
65         print "ioctlname(register_t val)"
66         print "{"
67         print ""
68         if (use_switch)
69                 print "\tswitch(val) {"
70 }
71
72 /^#[    ]*define[       ]+[A-Za-z_][A-Za-z0-9_]*[       ]+_IO/ {
73         
74         # find where the name starts
75         for (i = 1; i <= NF; i++)
76                 if ($i ~ /define/)
77                         break;
78         ++i;
79         # 
80         if (use_switch)
81                 printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i);
82         else
83                 printf("\tif (val ==  %s)\n\t\treturn(\"%s\");\n", $i, $i);
84
85 }
86 END {
87         if (use_switch)
88                 print "\t}"
89         print "\n\treturn(NULL);"
90         print "}"
91 }
92 '