]> granicus.if.org Git - strace/blob - maint/ioctls_gen.sh
maint: harmonize use of ioctls_sym.sh
[strace] / maint / ioctls_gen.sh
1 #!/bin/sh
2 # Copyright (c) 2004-2015 Dmitry V. Levin <ldv@altlinux.org>
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
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.
15 #
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.
26
27 set -efu
28
29 me="${0##*/}"
30 mydir="${0%/*}"
31 msg()
32 {
33         printf >&2 '%s\n' "$me: $*"
34 }
35
36 case $# in
37         1)
38                 inc_dir="$1"
39                 arch_dir=
40                 ;;
41         2)
42                 inc_dir="$1"
43                 arch_dir="$2"
44                 ;;
45         *)
46                 echo >&2 "usage: $me include-directory [arch-include-directory]"
47                 exit 1
48                 ;;
49 esac
50
51 # Check and canonicalize include-directory and arch-include-directory.
52 abs_inc_dir="$(cd "$inc_dir" && pwd -P)"
53 INCLUDES_inc="-I$abs_inc_dir/uapi -I$abs_inc_dir"
54 abs_arch_dir=
55 INCLUDES_arch=
56 [ -z "$arch_dir" ] || {
57         abs_arch_dir="$(cd "$arch_dir" && pwd -P)"
58         INCLUDES_arch="-I$abs_arch_dir/uapi -I$abs_arch_dir"
59 }
60
61 cleanup()
62 {
63         trap - EXIT
64         rm -f ioctls_hex.h ioctls_sym.h
65         exit "$@"
66 }
67 trap 'cleanup $?' EXIT
68 trap 'cleanup 1' HUP PIPE INT QUIT TERM
69
70 # Fetch ioctl commands defined in hex form.
71 {
72         "$mydir"/ioctls_hex.sh "$inc_dir" 03 linux/hdreg.h
73         "$mydir"/ioctls_hex.sh "$inc_dir" 22 scsi/sg.h
74         "$mydir"/ioctls_hex.sh "$inc_dir" 46 linux/fb.h
75         "$mydir"/ioctls_hex.sh "$inc_dir" 4B linux/kd.h
76         "$mydir"/ioctls_hex.sh "$inc_dir" 4C linux/loop.h
77         "$mydir"/ioctls_hex.sh "$inc_dir" 53 linux/cdrom.h scsi/scsi.h scsi/scsi_ioctl.h
78         "$mydir"/ioctls_hex.sh "$inc_dir" '\(46\|54\|66\|74\)' asm/ioctls.h asm-generic/ioctls.h
79         "$mydir"/ioctls_hex.sh "$inc_dir" 56 linux/vt.h
80         "$mydir"/ioctls_hex.sh "$inc_dir" '7[12]' linux/videotext.h
81         "$mydir"/ioctls_hex.sh "$inc_dir" 89 asm/sockios.h asm-generic/sockios.h linux/sockios.h
82         "$mydir"/ioctls_hex.sh "$inc_dir" 8B linux/wireless.h
83 } > ioctls_hex.h
84 msg "generated $(grep -c '^{' ioctls_hex.h) hex ioctls from $inc_dir"
85
86 # Fetch ioctl commands defined in symbolic form.
87 INCLUDES="$INCLUDES_arch ${INCLUDES-}" \
88         "$mydir"/ioctls_sym.sh "$inc_dir" > ioctls_sym.h
89
90 # Part of android ioctl commands are defined elsewhere.
91 android_dir="$inc_dir/../drivers/staging/android"
92 if [ -d "$android_dir/uapi" ]; then
93         INCLUDES="$INCLUDES_inc $INCLUDES_arch ${INCLUDES-}" \
94         "$mydir"/ioctls_sym.sh "$android_dir" staging/android >> ioctls_sym.h
95 fi
96 msg "generated $(grep -c '^{' ioctls_sym.h) symbolic ioctls from $inc_dir"
97
98 # Output all ioctl definitions fetched from include-directory.
99 echo "/* Generated by $me from definitions found in ${inc_dir%%/}/ tree. */" > ioctls_inc.h
100 LC_COLLATE=C sort -u ioctls_hex.h ioctls_sym.h >> ioctls_inc.h
101 msg "generated $(grep -c '^{' ioctls_inc.h) ioctls from $inc_dir"
102
103 [ -n "$arch_dir" ] || exit 0
104
105 # Fetch ioctl commands defined in hex form.
106 {
107         "$mydir"/ioctls_hex.sh "$arch_dir" 54 asm/ioctls.h
108         "$mydir"/ioctls_hex.sh "$arch_dir" '\(46\|54\|66\|74\)' asm/ioctls.h
109         "$mydir"/ioctls_hex.sh "$arch_dir" 89 asm/sockios.h
110 } > ioctls_hex.h
111 msg "generated $(grep -c '^{' ioctls_hex.h) hex ioctls from $arch_dir"
112
113 # Fetch ioctl commands defined in symbolic form.
114 INCLUDES="$INCLUDES_inc ${INCLUDES-}" \
115         "$mydir"/ioctls_sym.sh "$arch_dir" > ioctls_sym.h
116 msg "generated $(grep -c '^{' ioctls_sym.h) symbolic ioctls from $arch_dir"
117
118 # Output all ioctl definitions fetched from arch-include-directory.
119 echo "/* Generated by $me from definitions found in ${arch_dir%%/}/ tree. */" > ioctls_arch.h
120 LC_COLLATE=C sort -u ioctls_hex.h ioctls_sym.h >> ioctls_arch.h
121 msg "generated $(grep -c '^{' ioctls_arch.h) ioctls from $arch_dir"