mkcapflags.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. #
  3. # Generate the x86_cap_flags[] array from include/asm/cpufeature.h
  4. #
  5. IN=$1
  6. OUT=$2
  7. TABS="$(printf '\t\t\t\t\t')"
  8. trap 'rm "$OUT"' EXIT
  9. (
  10. echo "#ifndef _ASM_X86_CPUFEATURE_H"
  11. echo "#include <asm/cpufeature.h>"
  12. echo "#endif"
  13. echo ""
  14. echo "const char * const x86_cap_flags[NCAPINTS*32] = {"
  15. # Iterate through any input lines starting with #define X86_FEATURE_
  16. sed -n -e 's/\t/ /g' -e 's/^ *# *define *X86_FEATURE_//p' $IN |
  17. while read i
  18. do
  19. # Name is everything up to the first whitespace
  20. NAME="$(echo "$i" | sed 's/ .*//')"
  21. # If the /* comment */ starts with a quote string, grab that.
  22. VALUE="$(echo "$i" | sed -n 's@.*/\* *\("[^"]*"\).*\*/@\1@p')"
  23. [ -z "$VALUE" ] && VALUE="\"$NAME\""
  24. [ "$VALUE" == '""' ] && continue
  25. # Name is uppercase, VALUE is all lowercase
  26. VALUE="$(echo "$VALUE" | tr A-Z a-z)"
  27. TABCOUNT=$(( ( 5*8 - 14 - $(echo "$NAME" | wc -c) ) / 8 ))
  28. printf "\t[%s]%.*s = %s,\n" \
  29. "X86_FEATURE_$NAME" "$TABCOUNT" "$TABS" "$VALUE"
  30. done
  31. echo "};"
  32. ) > $OUT
  33. trap - EXIT