2 # Copyright (c) 2004-2015 Dmitry V. Levin <ldv@altlinux.org>
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # 3. The name of the author may not be used to endorse or promote products
14 # derived from this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 printf >&2 '%s\n' "$me: $*"
46 echo >&2 "usage: $me include-directory [arch-include-directory]"
51 # Check and canonicalize include-directory and arch-include-directory.
52 abs_inc_dir="$(cd "$inc_dir" && pwd -P)"
54 abs_arch_dir="$(cd "$arch_dir" && pwd -P)"
59 rm -f ioctls_hex.h ioctls_sym.h
62 trap 'cleanup $?' EXIT
63 trap 'cleanup 1' HUP PIPE INT QUIT TERM
65 # Fetch ioctl commands defined in hex form.
67 "$mydir"/ioctls_hex.sh "$inc_dir" 03 linux/hdreg.h
68 "$mydir"/ioctls_hex.sh "$inc_dir" 22 scsi/sg.h
69 "$mydir"/ioctls_hex.sh "$inc_dir" 46 linux/fb.h
70 "$mydir"/ioctls_hex.sh "$inc_dir" 4B linux/kd.h
71 "$mydir"/ioctls_hex.sh "$inc_dir" 4C linux/loop.h
72 "$mydir"/ioctls_hex.sh "$inc_dir" 53 linux/cdrom.h scsi/scsi.h scsi/scsi_ioctl.h
73 "$mydir"/ioctls_hex.sh "$inc_dir" '\(46\|54\|66\|74\)' asm/ioctls.h asm-generic/ioctls.h
74 "$mydir"/ioctls_hex.sh "$inc_dir" 56 linux/vt.h
75 "$mydir"/ioctls_hex.sh "$inc_dir" '7[12]' linux/videotext.h
76 "$mydir"/ioctls_hex.sh "$inc_dir" 89 asm/sockios.h asm-generic/sockios.h linux/sockios.h
77 "$mydir"/ioctls_hex.sh "$inc_dir" 8B linux/wireless.h
79 msg "generated $(grep -c '^{' ioctls_hex.h) hex ioctls from $inc_dir"
81 # Fetch ioctl commands defined in symbolic form.
82 "$mydir"/ioctls_sym.sh "$inc_dir" > ioctls_sym.h
84 # Part of android ioctl commands are defined elsewhere.
85 android_dir="$inc_dir/../drivers/staging/android"
86 if [ -d "$android_dir/uapi" ]; then
87 "$mydir"/ioctls_sym.sh "$android_dir" staging/android >> ioctls_sym.h
89 msg "generated $(grep -c '^{' ioctls_sym.h) symbolic ioctls from $inc_dir"
91 # Output all ioctl definitions fetched from include-directory.
92 echo "/* Generated by $me from definitions found in ${inc_dir%%/}/ tree. */" > ioctls_inc.h
93 LC_COLLATE=C sort -u ioctls_hex.h ioctls_sym.h >> ioctls_inc.h
94 msg "generated $(grep -c '^{' ioctls_inc.h) ioctls from $inc_dir"
96 [ -n "$arch_dir" ] || exit 0
98 # Fetch ioctl commands defined in hex form.
100 "$mydir"/ioctls_hex.sh "$arch_dir" 54 asm/ioctls.h
101 "$mydir"/ioctls_hex.sh "$arch_dir" '\(46\|54\|66\|74\)' asm/ioctls.h
102 "$mydir"/ioctls_hex.sh "$arch_dir" 89 asm/sockios.h
104 msg "generated $(grep -c '^{' ioctls_hex.h) hex ioctls from $arch_dir"
106 # Fetch ioctl commands defined in symbolic form.
107 INCLUDES="-I$abs_inc_dir/uapi -I$abs_inc_dir ${INCLUDES-}" \
108 "${0%/*}"/ioctls_sym.sh "$arch_dir" > ioctls_sym.h
109 msg "generated $(grep -c '^{' ioctls_sym.h) symbolic ioctls from $arch_dir"
111 # Output all ioctl definitions fetched from arch-include-directory.
112 echo "/* Generated by $me from definitions found in ${arch_dir%%/}/ tree. */" > ioctls_arch.h
113 LC_COLLATE=C sort -u ioctls_hex.h ioctls_sym.h >> ioctls_arch.h
114 msg "generated $(grep -c '^{' ioctls_arch.h) ioctls from $arch_dir"