mkioctls revision 226344
1#!/bin/sh 2# 3# $FreeBSD: head/usr.bin/kdump/mkioctls 226344 2011-10-13 16:29:24Z des $ 4 5set -e 6 7if [ -z "$1" ]; then 8 echo "usage: sh $0 include-dir" 9 exit 1 10fi 11 12LC_ALL=C; export LC_ALL 13 14# Build a list of headers that have ioctls in them. 15# XXX should we use an ANSI cpp? 16ioctl_includes=$( 17 cd $1 18 find -H -s * -name '*.h' | grep -v '.*disk.*\.h' | \ 19 xargs egrep -l \ 20'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | 21 awk '{printf("#include <%s>\\n", $1)}' 22) 23 24: ${MACHINE=$(uname -m)} 25case "${MACHINE}" in 26*pc98*) 27 ioctl_includes="$ioctl_includes#include <sys/diskpc98.h>\\n" 28 ;; 29*) 30 ioctl_includes="$ioctl_includes#include <sys/diskmbr.h>\\n" 31 ;; 32esac 33 34awk -v x="$ioctl_includes" 'BEGIN {print x}' | 35 gcc -E -I$1 -dM -DCOMPAT_43TTY - | 36 awk -v ioctl_includes="$ioctl_includes" ' 37BEGIN { 38 print "/* XXX obnoxious prerequisites. */" 39 print "#define COMPAT_43" 40 print "#define COMPAT_43TTY" 41 print "#include <sys/param.h>" 42 print "#include <sys/devicestat.h>" 43 print "#include <sys/disklabel.h>" 44 print "#include <sys/socket.h>" 45 print "#include <sys/time.h>" 46 print "#include <sys/tty.h>" 47 print "#include <bsm/audit.h>" 48 print "#include <net/ethernet.h>" 49 print "#include <net/if.h>" 50 print "#include <net/if_var.h>" 51 print "#include <net/pfvar.h>" 52 print "#include <net/route.h>" 53 print "#include <netinet/in.h>" 54 print "#include <netinet/ip_mroute.h>" 55 print "#include <netinet6/in6_var.h>" 56 print "#include <netinet6/nd6.h>" 57 print "#include <netinet6/ip6_mroute.h>" 58 print "#include <stdio.h>" 59 print "#include <cam/cam.h>" 60 print "" 61 print "void ioctlname(unsigned long val, int decimal);" 62 print "" 63 print ioctl_includes 64 print "" 65 print "void" 66 print "ioctlname(unsigned long val, int decimal)" 67 print "{" 68 print "\tconst char *str = NULL;" 69 print "" 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 print("\t"); 81 if (n++ > 0) 82 print("else "); 83 printf("if (val == %s)\n", $i); 84 printf("\t\tstr = \"%s\";\n", $i); 85} 86END { 87 print "\n" 88 print "\tif (str != NULL)\n" 89 print "\t\tprintf(\"%s\", str);\n" 90 print "\telse if (decimal)\n" 91 print "\t\tprintf(\"%lu\", val);\n" 92 print "\telse\n" 93 print "\t\tprintf(\"%#lx\", val);\n" 94 print "}" 95} 96' 97