mirror of
https://github.com/torvalds/linux.git
synced 2024-12-29 06:12:08 +00:00
bc53d3d777
Without 'set -e', shell scripts continue running even after any
error occurs. The missed 'set -e' is a typical bug in shell scripting.
For example, when a disk space shortage occurs while this script is
running, it actually ends up with generating a truncated capflags.c.
Yet, mkcapflags.sh continues running and exits with 0. So, the build
system assumes it has succeeded.
It will not be re-generated in the next invocation of Make since its
timestamp is newer than that of any of the source files.
Add 'set -e' so that any error in this script is caught and propagated
to the build system.
Since 9c2af1c737
("kbuild: add .DELETE_ON_ERROR special target"),
make automatically deletes the target on any failure. So, the broken
capflags.c will be deleted automatically.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Borislav Petkov <bp@alien8.de>
Link: https://lkml.kernel.org/r/20190625072622.17679-1-yamada.masahiro@socionext.com
68 lines
1.6 KiB
Bash
68 lines
1.6 KiB
Bash
#!/bin/sh
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Generate the x86_cap/bug_flags[] arrays from include/asm/cpufeatures.h
|
|
#
|
|
|
|
set -e
|
|
|
|
IN=$1
|
|
OUT=$2
|
|
|
|
dump_array()
|
|
{
|
|
ARRAY=$1
|
|
SIZE=$2
|
|
PFX=$3
|
|
POSTFIX=$4
|
|
|
|
PFX_SZ=$(echo $PFX | wc -c)
|
|
TABS="$(printf '\t\t\t\t\t')"
|
|
|
|
echo "const char * const $ARRAY[$SIZE] = {"
|
|
|
|
# Iterate through any input lines starting with #define $PFX
|
|
sed -n -e 's/\t/ /g' -e "s/^ *# *define *$PFX//p" $IN |
|
|
while read i
|
|
do
|
|
# Name is everything up to the first whitespace
|
|
NAME="$(echo "$i" | sed 's/ .*//')"
|
|
|
|
# If the /* comment */ starts with a quote string, grab that.
|
|
VALUE="$(echo "$i" | sed -n 's@.*/\* *\("[^"]*"\).*\*/@\1@p')"
|
|
[ -z "$VALUE" ] && VALUE="\"$NAME\""
|
|
[ "$VALUE" = '""' ] && continue
|
|
|
|
# Name is uppercase, VALUE is all lowercase
|
|
VALUE="$(echo "$VALUE" | tr A-Z a-z)"
|
|
|
|
if [ -n "$POSTFIX" ]; then
|
|
T=$(( $PFX_SZ + $(echo $POSTFIX | wc -c) + 2 ))
|
|
TABS="$(printf '\t\t\t\t\t\t')"
|
|
TABCOUNT=$(( ( 6*8 - ($T + 1) - $(echo "$NAME" | wc -c) ) / 8 ))
|
|
printf "\t[%s - %s]%.*s = %s,\n" "$PFX$NAME" "$POSTFIX" "$TABCOUNT" "$TABS" "$VALUE"
|
|
else
|
|
TABCOUNT=$(( ( 5*8 - ($PFX_SZ + 1) - $(echo "$NAME" | wc -c) ) / 8 ))
|
|
printf "\t[%s]%.*s = %s,\n" "$PFX$NAME" "$TABCOUNT" "$TABS" "$VALUE"
|
|
fi
|
|
done
|
|
echo "};"
|
|
}
|
|
|
|
trap 'rm "$OUT"' EXIT
|
|
|
|
(
|
|
echo "#ifndef _ASM_X86_CPUFEATURES_H"
|
|
echo "#include <asm/cpufeatures.h>"
|
|
echo "#endif"
|
|
echo ""
|
|
|
|
dump_array "x86_cap_flags" "NCAPINTS*32" "X86_FEATURE_" ""
|
|
echo ""
|
|
|
|
dump_array "x86_bug_flags" "NBUGINTS*32" "X86_BUG_" "NCAPINTS*32"
|
|
|
|
) > $OUT
|
|
|
|
trap - EXIT
|