18c2ecf20Sopenharmony_ci#
28c2ecf20Sopenharmony_ci# Small script that refreshes the kernel feature support status in place.
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_cifor F_FILE in Documentation/features/*/*/arch-support.txt; do
68c2ecf20Sopenharmony_ci	F=$(grep "^#         Kconfig:" "$F_FILE" | cut -c26-)
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci	#
98c2ecf20Sopenharmony_ci	# Each feature F is identified by a pair (O, K), where 'O' can
108c2ecf20Sopenharmony_ci	# be either the empty string (for 'nop') or "not" (the logical
118c2ecf20Sopenharmony_ci	# negation operator '!'); other operators are not supported.
128c2ecf20Sopenharmony_ci	#
138c2ecf20Sopenharmony_ci	O=""
148c2ecf20Sopenharmony_ci	K=$F
158c2ecf20Sopenharmony_ci	if [[ "$F" == !* ]]; then
168c2ecf20Sopenharmony_ci		O="not"
178c2ecf20Sopenharmony_ci		K=$(echo $F | sed -e 's/^!//g')
188c2ecf20Sopenharmony_ci	fi
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci	#
218c2ecf20Sopenharmony_ci	# F := (O, K) is 'valid' iff there is a Kconfig file (for some
228c2ecf20Sopenharmony_ci	# arch) which contains K.
238c2ecf20Sopenharmony_ci	#
248c2ecf20Sopenharmony_ci	# Notice that this definition entails an 'asymmetry' between
258c2ecf20Sopenharmony_ci	# the case 'O = ""' and the case 'O = "not"'. E.g., F may be
268c2ecf20Sopenharmony_ci	# _invalid_ if:
278c2ecf20Sopenharmony_ci	#
288c2ecf20Sopenharmony_ci	# [case 'O = ""']
298c2ecf20Sopenharmony_ci	#   1) no arch provides support for F,
308c2ecf20Sopenharmony_ci	#   2) K does not exist (e.g., it was renamed/mis-typed);
318c2ecf20Sopenharmony_ci	#
328c2ecf20Sopenharmony_ci	# [case 'O = "not"']
338c2ecf20Sopenharmony_ci	#   3) all archs provide support for F,
348c2ecf20Sopenharmony_ci	#   4) as in (2).
358c2ecf20Sopenharmony_ci	#
368c2ecf20Sopenharmony_ci	# The rationale for adopting this definition (and, thus, for
378c2ecf20Sopenharmony_ci	# keeping the asymmetry) is:
388c2ecf20Sopenharmony_ci	#
398c2ecf20Sopenharmony_ci	#       We want to be able to 'detect' (2) (or (4)).
408c2ecf20Sopenharmony_ci	#
418c2ecf20Sopenharmony_ci	# (1) and (3) may further warn the developers about the fact
428c2ecf20Sopenharmony_ci	# that K can be removed.
438c2ecf20Sopenharmony_ci	#
448c2ecf20Sopenharmony_ci	F_VALID="false"
458c2ecf20Sopenharmony_ci	for ARCH_DIR in arch/*/; do
468c2ecf20Sopenharmony_ci		K_FILES=$(find $ARCH_DIR -name "Kconfig*")
478c2ecf20Sopenharmony_ci		K_GREP=$(grep "$K" $K_FILES)
488c2ecf20Sopenharmony_ci		if [ ! -z "$K_GREP" ]; then
498c2ecf20Sopenharmony_ci			F_VALID="true"
508c2ecf20Sopenharmony_ci			break
518c2ecf20Sopenharmony_ci		fi
528c2ecf20Sopenharmony_ci	done
538c2ecf20Sopenharmony_ci	if [ "$F_VALID" = "false" ]; then
548c2ecf20Sopenharmony_ci		printf "WARNING: '%s' is not a valid Kconfig\n" "$F"
558c2ecf20Sopenharmony_ci	fi
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	T_FILE="$F_FILE.tmp"
588c2ecf20Sopenharmony_ci	grep "^#" $F_FILE > $T_FILE
598c2ecf20Sopenharmony_ci	echo "    -----------------------" >> $T_FILE
608c2ecf20Sopenharmony_ci	echo "    |         arch |status|" >> $T_FILE
618c2ecf20Sopenharmony_ci	echo "    -----------------------" >> $T_FILE
628c2ecf20Sopenharmony_ci	for ARCH_DIR in arch/*/; do
638c2ecf20Sopenharmony_ci		ARCH=$(echo $ARCH_DIR | sed -e 's/arch//g' | sed -e 's/\///g')
648c2ecf20Sopenharmony_ci		K_FILES=$(find $ARCH_DIR -name "Kconfig*")
658c2ecf20Sopenharmony_ci		K_GREP=$(grep "$K" $K_FILES)
668c2ecf20Sopenharmony_ci		#
678c2ecf20Sopenharmony_ci		# Arch support status values for (O, K) are updated according
688c2ecf20Sopenharmony_ci		# to the following rules.
698c2ecf20Sopenharmony_ci		#
708c2ecf20Sopenharmony_ci		#   - ("", K) is 'supported by a given arch', if there is a
718c2ecf20Sopenharmony_ci		#     Kconfig file for that arch which contains K;
728c2ecf20Sopenharmony_ci		#
738c2ecf20Sopenharmony_ci		#   - ("not", K) is 'supported by a given arch', if there is
748c2ecf20Sopenharmony_ci		#     no Kconfig file for that arch which contains K;
758c2ecf20Sopenharmony_ci		#
768c2ecf20Sopenharmony_ci		#   - otherwise: preserve the previous status value (if any),
778c2ecf20Sopenharmony_ci		#                default to 'not yet supported'.
788c2ecf20Sopenharmony_ci		#
798c2ecf20Sopenharmony_ci		# Notice that, according these rules, invalid features may be
808c2ecf20Sopenharmony_ci		# updated/modified.
818c2ecf20Sopenharmony_ci		#
828c2ecf20Sopenharmony_ci		if [ "$O" = "" ] && [ ! -z "$K_GREP" ]; then
838c2ecf20Sopenharmony_ci			printf "    |%12s: |  ok  |\n" "$ARCH" >> $T_FILE
848c2ecf20Sopenharmony_ci		elif [ "$O" = "not" ] && [ -z "$K_GREP" ]; then
858c2ecf20Sopenharmony_ci			printf "    |%12s: |  ok  |\n" "$ARCH" >> $T_FILE
868c2ecf20Sopenharmony_ci		else
878c2ecf20Sopenharmony_ci			S=$(grep -v "^#" "$F_FILE" | grep " $ARCH:")
888c2ecf20Sopenharmony_ci			if [ ! -z "$S" ]; then
898c2ecf20Sopenharmony_ci				echo "$S" >> $T_FILE
908c2ecf20Sopenharmony_ci			else
918c2ecf20Sopenharmony_ci				printf "    |%12s: | TODO |\n" "$ARCH" \
928c2ecf20Sopenharmony_ci					>> $T_FILE
938c2ecf20Sopenharmony_ci			fi
948c2ecf20Sopenharmony_ci		fi
958c2ecf20Sopenharmony_ci	done
968c2ecf20Sopenharmony_ci	echo "    -----------------------" >> $T_FILE
978c2ecf20Sopenharmony_ci	mv $T_FILE $F_FILE
988c2ecf20Sopenharmony_cidone
99