mkioctls revision 261797
10Sduke#!/bin/sh 2553Sohair# 30Sduke# $FreeBSD: head/usr.bin/kdump/mkioctls 261797 2014-02-12 09:59:48Z glebius $ 40Sduke# 50Sduke# When editing this script, keep in mind that truss also uses it. 60Sduke# 70Sduke 80Sdukeset -e 90Sduke 100Sdukeif [ $# -ne 2 -o \( $1 != "print" -a $1 != "return" \) ]; then 110Sduke echo "usage: sh $0 print|return include-dir" 120Sduke exit 1 130Sdukefi 140Sduke 150Sdukestyle="$1" 160Sdukeincludedir="$2" 170Sduke 180SdukeLC_ALL=C; export LC_ALL 19553Sohair 20553Sohair# Build a list of headers that have ioctls in them. 21553Sohair# XXX should we use an ANSI cpp? 220Sdukeioctl_includes=$( 230Sduke cd $includedir 240Sduke find -H -s * -name '*.h' | \ 250Sduke egrep -v '(.*disk.*|net/pfvar|net/if_pfsync)\.h' | \ 260Sduke xargs egrep -l \ 27'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | 28 awk '{printf("#include <%s>\\n", $1)}' 29) 30 31: ${MACHINE=$(uname -m)} 32case "${MACHINE}" in 33*pc98*) 34 ioctl_includes="$ioctl_includes#include <sys/diskpc98.h>\\n" 35 ;; 36*) 37 ioctl_includes="$ioctl_includes#include <sys/diskmbr.h>\\n" 38 ;; 39esac 40 41awk -v x="$ioctl_includes" 'BEGIN {print x}' | 42 $CPP -I$1 -dM -DCOMPAT_43TTY - | 43 awk -v ioctl_includes="$ioctl_includes" -v style="$style" ' 44BEGIN { 45 print "/* XXX obnoxious prerequisites. */" 46 print "#define COMPAT_43" 47 print "#define COMPAT_43TTY" 48 print "#include <sys/param.h>" 49 print "#include <sys/devicestat.h>" 50 print "#include <sys/disklabel.h>" 51 print "#include <sys/socket.h>" 52 print "#include <sys/time.h>" 53 print "#include <sys/tty.h>" 54 print "#include <bsm/audit.h>" 55 print "#include <net/ethernet.h>" 56 print "#include <net/if.h>" 57 print "#include <net/if_var.h>" 58 print "#ifdef PF" 59 print "#include <net/pfvar.h>" 60 print "#include <net/if_pfsync.h>" 61 print "#endif" 62 print "#include <net/route.h>" 63 print "#include <netinet/in.h>" 64 print "#include <netinet/ip_mroute.h>" 65 print "#include <netinet6/in6_var.h>" 66 print "#include <netinet6/nd6.h>" 67 print "#include <netinet6/ip6_mroute.h>" 68 print "#include <stdio.h>" 69 print "#include <cam/cam.h>" 70 print "#include <stddef.h>" 71 print "#include <stdint.h>" 72 print "" 73 print ioctl_includes 74 print "" 75 if (style == "print") { 76 print "void ioctlname(unsigned long val, int decimal);" 77 print "" 78 print "void" 79 print "ioctlname(unsigned long val, int decimal)" 80 } else { 81 print "const char *ioctlname(unsigned long val);" 82 print "" 83 print "const char *" 84 print "ioctlname(unsigned long val)" 85 } 86 print "{" 87 print "\tconst char *str = NULL;" 88 print "" 89} 90 91/^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO/ { 92 93 # find where the name starts 94 for (i = 1; i <= NF; i++) 95 if ($i ~ /define/) 96 break; 97 ++i; 98 # 99 printf("\t"); 100 if (n++ > 0) 101 printf("else "); 102 printf("if (val == %s)\n", $i); 103 printf("\t\tstr = \"%s\";\n", $i); 104} 105END { 106 print "" 107 if (style == "print") { 108 print "\tif (str != NULL)" 109 print "\t\tprintf(\"%s\", str);" 110 print "\telse if (decimal)" 111 print "\t\tprintf(\"%lu\", val);" 112 print "\telse" 113 print "\t\tprintf(\"%#lx\", val);" 114 } else { 115 print "\treturn (str);" 116 } 117 print "}" 118} 119' 120