]> granicus.if.org Git - strace/blob - maint/ioctls_gen.sh
Update copyright headers
[strace] / maint / ioctls_gen.sh
1 #!/bin/sh
2 # Copyright (c) 2004-2015 Dmitry V. Levin <ldv@altlinux.org>
3 # Copyright (c) 2015-2018 The strace developers.
4 # All rights reserved.
5 #
6 # SPDX-License-Identifier: LGPL-2.1-or-later
7
8 set -efu
9
10 me="${0##*/}"
11 mydir="${0%/*}"
12 msg()
13 {
14         printf >&2 '%s\n' "$me: $*"
15 }
16
17 case $# in
18         1)
19                 inc_dir="$1"
20                 arch_dir=
21                 ;;
22         2)
23                 inc_dir="$1"
24                 arch_dir="$2"
25                 ;;
26         *)
27                 echo >&2 "usage: $me include-directory [arch-include-directory]"
28                 exit 1
29                 ;;
30 esac
31
32 # Check and canonicalize include-directory and arch-include-directory.
33 abs_inc_dir="$(cd "$inc_dir" && pwd -P)"
34 INCLUDES_inc="-I$abs_inc_dir/uapi -I$abs_inc_dir"
35 abs_arch_dir=
36 INCLUDES_arch=
37 [ -z "$arch_dir" ] || {
38         abs_arch_dir="$(cd "$arch_dir" && pwd -P)"
39         INCLUDES_arch="-I$abs_arch_dir/uapi -I$abs_arch_dir"
40 }
41
42 cleanup()
43 {
44         trap - EXIT
45         rm -f ioctls_hex.h ioctls_sym.h
46         exit "$@"
47 }
48 trap 'cleanup $?' EXIT
49 trap 'cleanup 1' HUP PIPE INT QUIT TERM
50
51 # Fetch ioctl commands defined in hex form.
52 {
53         "$mydir"/ioctls_hex.sh "$inc_dir" 03 linux/hdreg.h
54         "$mydir"/ioctls_hex.sh "$inc_dir" 22 scsi/sg.h
55         "$mydir"/ioctls_hex.sh "$inc_dir" 46 linux/fb.h
56         "$mydir"/ioctls_hex.sh "$inc_dir" 4B linux/kd.h
57         "$mydir"/ioctls_hex.sh "$inc_dir" 4C linux/loop.h
58         "$mydir"/ioctls_hex.sh "$inc_dir" 53 linux/cdrom.h scsi/scsi.h scsi/scsi_ioctl.h
59         "$mydir"/ioctls_hex.sh "$inc_dir" '\(46\|54\|66\|74\)' asm/ioctls.h asm-generic/ioctls.h
60         "$mydir"/ioctls_hex.sh "$inc_dir" 56 linux/vt.h
61         "$mydir"/ioctls_hex.sh "$inc_dir" '7[12]' linux/videotext.h
62         "$mydir"/ioctls_hex.sh "$inc_dir" 89 asm/sockios.h asm-generic/sockios.h linux/sockios.h
63         "$mydir"/ioctls_hex.sh "$inc_dir" 8B linux/wireless.h
64 } > ioctls_hex.h
65 msg "generated $(grep -c '^{' ioctls_hex.h) hex ioctls from $inc_dir"
66
67 # Fetch ioctl commands defined in symbolic form.
68 INCLUDES="$INCLUDES_arch ${INCLUDES-}" \
69         "$mydir"/ioctls_sym.sh "$inc_dir" > ioctls_sym.h
70
71 # Move KVM_* constants from ioctls_inc.h to ioctls_arch.h.
72 grep -F 'linux/kvm.h' < ioctls_sym.h > ioctls_kvm.h ||:
73 grep -Fv 'linux/kvm.h' < ioctls_sym.h > ioctls_unkvm.h
74 mv ioctls_unkvm.h ioctls_sym.h
75
76 # Part of android ioctl commands are defined elsewhere.
77 android_dir="$inc_dir/../drivers/staging/android"
78 if [ -d "$android_dir/uapi" ]; then
79         INCLUDES="$INCLUDES_inc $INCLUDES_arch ${INCLUDES-}" \
80         "$mydir"/ioctls_sym.sh "$android_dir" staging/android >> ioctls_sym.h
81 fi
82 msg "generated $(grep -c '^{' ioctls_sym.h) symbolic ioctls from $inc_dir"
83
84 # Output all ioctl definitions fetched from include-directory.
85 echo "/* Generated by $me from definitions found in ${inc_dir%%/}/ tree. */" > ioctls_inc.h
86 LC_COLLATE=C sort -u ioctls_hex.h ioctls_sym.h >> ioctls_inc.h
87 msg "generated $(grep -c '^{' ioctls_inc.h) ioctls from $inc_dir"
88
89 [ -n "$arch_dir" ] || exit 0
90
91 # Fetch ioctl commands defined in hex form.
92 {
93         "$mydir"/ioctls_hex.sh "$arch_dir" 54 asm/ioctls.h
94         "$mydir"/ioctls_hex.sh "$arch_dir" '\(46\|54\|66\|74\)' asm/ioctls.h
95         "$mydir"/ioctls_hex.sh "$arch_dir" 89 asm/sockios.h
96 } > ioctls_hex.h
97 msg "generated $(grep -c '^{' ioctls_hex.h) hex ioctls from $arch_dir"
98
99 # Fetch ioctl commands defined in symbolic form.
100 INCLUDES="$INCLUDES_inc ${INCLUDES-}" \
101         "$mydir"/ioctls_sym.sh "$arch_dir" > ioctls_sym.h
102 msg "generated $(grep -c '^{' ioctls_sym.h) symbolic ioctls from $arch_dir"
103
104 # Output all ioctl definitions fetched from arch-include-directory.
105 echo "/* Generated by $me from definitions found in ${arch_dir%%/}/ tree. */" > ioctls_arch.h
106 LC_COLLATE=C sort -u ioctls_hex.h ioctls_kvm.h ioctls_sym.h >> ioctls_arch.h
107 msg "generated $(grep -c '^{' ioctls_arch.h) ioctls from $arch_dir"