• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
27set -efu
28
29me="${0##*/}"
30mydir="${0%/*}"
31msg()
32{
33	printf >&2 '%s\n' "$me: $*"
34}
35
36case $# 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		;;
49esac
50
51# Check and canonicalize include-directory and arch-include-directory.
52abs_inc_dir="$(cd "$inc_dir" && pwd -P)"
53INCLUDES_inc="-I$abs_inc_dir/uapi -I$abs_inc_dir"
54abs_arch_dir=
55INCLUDES_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
61cleanup()
62{
63	trap - EXIT
64	rm -f ioctls_hex.h ioctls_sym.h
65	exit "$@"
66}
67trap 'cleanup $?' EXIT
68trap '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
84msg "generated $(grep -c '^{' ioctls_hex.h) hex ioctls from $inc_dir"
85
86# Fetch ioctl commands defined in symbolic form.
87INCLUDES="$INCLUDES_arch ${INCLUDES-}" \
88	"$mydir"/ioctls_sym.sh "$inc_dir" > ioctls_sym.h
89
90# Move KVM_* constants from ioctls_inc.h to ioctls_arch.h.
91grep -F 'linux/kvm.h' < ioctls_sym.h > ioctls_kvm.h ||:
92grep -Fv 'linux/kvm.h' < ioctls_sym.h > ioctls_unkvm.h
93mv ioctls_unkvm.h ioctls_sym.h
94
95# Part of android ioctl commands are defined elsewhere.
96android_dir="$inc_dir/../drivers/staging/android"
97if [ -d "$android_dir/uapi" ]; then
98	INCLUDES="$INCLUDES_inc $INCLUDES_arch ${INCLUDES-}" \
99	"$mydir"/ioctls_sym.sh "$android_dir" staging/android >> ioctls_sym.h
100fi
101msg "generated $(grep -c '^{' ioctls_sym.h) symbolic ioctls from $inc_dir"
102
103# Output all ioctl definitions fetched from include-directory.
104echo "/* Generated by $me from definitions found in ${inc_dir%%/}/ tree. */" > ioctls_inc.h
105LC_COLLATE=C sort -u ioctls_hex.h ioctls_sym.h >> ioctls_inc.h
106msg "generated $(grep -c '^{' ioctls_inc.h) ioctls from $inc_dir"
107
108[ -n "$arch_dir" ] || exit 0
109
110# Fetch ioctl commands defined in hex form.
111{
112	"$mydir"/ioctls_hex.sh "$arch_dir" 54 asm/ioctls.h
113	"$mydir"/ioctls_hex.sh "$arch_dir" '\(46\|54\|66\|74\)' asm/ioctls.h
114	"$mydir"/ioctls_hex.sh "$arch_dir" 89 asm/sockios.h
115} > ioctls_hex.h
116msg "generated $(grep -c '^{' ioctls_hex.h) hex ioctls from $arch_dir"
117
118# Fetch ioctl commands defined in symbolic form.
119INCLUDES="$INCLUDES_inc ${INCLUDES-}" \
120	"$mydir"/ioctls_sym.sh "$arch_dir" > ioctls_sym.h
121msg "generated $(grep -c '^{' ioctls_sym.h) symbolic ioctls from $arch_dir"
122
123# Output all ioctl definitions fetched from arch-include-directory.
124echo "/* Generated by $me from definitions found in ${arch_dir%%/}/ tree. */" > ioctls_arch.h
125LC_COLLATE=C sort -u ioctls_hex.h ioctls_kvm.h ioctls_sym.h >> ioctls_arch.h
126msg "generated $(grep -c '^{' ioctls_arch.h) ioctls from $arch_dir"
127