xref: /OK3568_Linux_fs/kernel/Documentation/features/scripts/features-refresh.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#
2*4882a593Smuzhiyun# Small script that refreshes the kernel feature support status in place.
3*4882a593Smuzhiyun#
4*4882a593Smuzhiyun
5*4882a593Smuzhiyunfor F_FILE in Documentation/features/*/*/arch-support.txt; do
6*4882a593Smuzhiyun	F=$(grep "^#         Kconfig:" "$F_FILE" | cut -c26-)
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun	#
9*4882a593Smuzhiyun	# Each feature F is identified by a pair (O, K), where 'O' can
10*4882a593Smuzhiyun	# be either the empty string (for 'nop') or "not" (the logical
11*4882a593Smuzhiyun	# negation operator '!'); other operators are not supported.
12*4882a593Smuzhiyun	#
13*4882a593Smuzhiyun	O=""
14*4882a593Smuzhiyun	K=$F
15*4882a593Smuzhiyun	if [[ "$F" == !* ]]; then
16*4882a593Smuzhiyun		O="not"
17*4882a593Smuzhiyun		K=$(echo $F | sed -e 's/^!//g')
18*4882a593Smuzhiyun	fi
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun	#
21*4882a593Smuzhiyun	# F := (O, K) is 'valid' iff there is a Kconfig file (for some
22*4882a593Smuzhiyun	# arch) which contains K.
23*4882a593Smuzhiyun	#
24*4882a593Smuzhiyun	# Notice that this definition entails an 'asymmetry' between
25*4882a593Smuzhiyun	# the case 'O = ""' and the case 'O = "not"'. E.g., F may be
26*4882a593Smuzhiyun	# _invalid_ if:
27*4882a593Smuzhiyun	#
28*4882a593Smuzhiyun	# [case 'O = ""']
29*4882a593Smuzhiyun	#   1) no arch provides support for F,
30*4882a593Smuzhiyun	#   2) K does not exist (e.g., it was renamed/mis-typed);
31*4882a593Smuzhiyun	#
32*4882a593Smuzhiyun	# [case 'O = "not"']
33*4882a593Smuzhiyun	#   3) all archs provide support for F,
34*4882a593Smuzhiyun	#   4) as in (2).
35*4882a593Smuzhiyun	#
36*4882a593Smuzhiyun	# The rationale for adopting this definition (and, thus, for
37*4882a593Smuzhiyun	# keeping the asymmetry) is:
38*4882a593Smuzhiyun	#
39*4882a593Smuzhiyun	#       We want to be able to 'detect' (2) (or (4)).
40*4882a593Smuzhiyun	#
41*4882a593Smuzhiyun	# (1) and (3) may further warn the developers about the fact
42*4882a593Smuzhiyun	# that K can be removed.
43*4882a593Smuzhiyun	#
44*4882a593Smuzhiyun	F_VALID="false"
45*4882a593Smuzhiyun	for ARCH_DIR in arch/*/; do
46*4882a593Smuzhiyun		K_FILES=$(find $ARCH_DIR -name "Kconfig*")
47*4882a593Smuzhiyun		K_GREP=$(grep "$K" $K_FILES)
48*4882a593Smuzhiyun		if [ ! -z "$K_GREP" ]; then
49*4882a593Smuzhiyun			F_VALID="true"
50*4882a593Smuzhiyun			break
51*4882a593Smuzhiyun		fi
52*4882a593Smuzhiyun	done
53*4882a593Smuzhiyun	if [ "$F_VALID" = "false" ]; then
54*4882a593Smuzhiyun		printf "WARNING: '%s' is not a valid Kconfig\n" "$F"
55*4882a593Smuzhiyun	fi
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun	T_FILE="$F_FILE.tmp"
58*4882a593Smuzhiyun	grep "^#" $F_FILE > $T_FILE
59*4882a593Smuzhiyun	echo "    -----------------------" >> $T_FILE
60*4882a593Smuzhiyun	echo "    |         arch |status|" >> $T_FILE
61*4882a593Smuzhiyun	echo "    -----------------------" >> $T_FILE
62*4882a593Smuzhiyun	for ARCH_DIR in arch/*/; do
63*4882a593Smuzhiyun		ARCH=$(echo $ARCH_DIR | sed -e 's/arch//g' | sed -e 's/\///g')
64*4882a593Smuzhiyun		K_FILES=$(find $ARCH_DIR -name "Kconfig*")
65*4882a593Smuzhiyun		K_GREP=$(grep "$K" $K_FILES)
66*4882a593Smuzhiyun		#
67*4882a593Smuzhiyun		# Arch support status values for (O, K) are updated according
68*4882a593Smuzhiyun		# to the following rules.
69*4882a593Smuzhiyun		#
70*4882a593Smuzhiyun		#   - ("", K) is 'supported by a given arch', if there is a
71*4882a593Smuzhiyun		#     Kconfig file for that arch which contains K;
72*4882a593Smuzhiyun		#
73*4882a593Smuzhiyun		#   - ("not", K) is 'supported by a given arch', if there is
74*4882a593Smuzhiyun		#     no Kconfig file for that arch which contains K;
75*4882a593Smuzhiyun		#
76*4882a593Smuzhiyun		#   - otherwise: preserve the previous status value (if any),
77*4882a593Smuzhiyun		#                default to 'not yet supported'.
78*4882a593Smuzhiyun		#
79*4882a593Smuzhiyun		# Notice that, according these rules, invalid features may be
80*4882a593Smuzhiyun		# updated/modified.
81*4882a593Smuzhiyun		#
82*4882a593Smuzhiyun		if [ "$O" = "" ] && [ ! -z "$K_GREP" ]; then
83*4882a593Smuzhiyun			printf "    |%12s: |  ok  |\n" "$ARCH" >> $T_FILE
84*4882a593Smuzhiyun		elif [ "$O" = "not" ] && [ -z "$K_GREP" ]; then
85*4882a593Smuzhiyun			printf "    |%12s: |  ok  |\n" "$ARCH" >> $T_FILE
86*4882a593Smuzhiyun		else
87*4882a593Smuzhiyun			S=$(grep -v "^#" "$F_FILE" | grep " $ARCH:")
88*4882a593Smuzhiyun			if [ ! -z "$S" ]; then
89*4882a593Smuzhiyun				echo "$S" >> $T_FILE
90*4882a593Smuzhiyun			else
91*4882a593Smuzhiyun				printf "    |%12s: | TODO |\n" "$ARCH" \
92*4882a593Smuzhiyun					>> $T_FILE
93*4882a593Smuzhiyun			fi
94*4882a593Smuzhiyun		fi
95*4882a593Smuzhiyun	done
96*4882a593Smuzhiyun	echo "    -----------------------" >> $T_FILE
97*4882a593Smuzhiyun	mv $T_FILE $F_FILE
98*4882a593Smuzhiyundone
99