#!/bin/bash _undefine() { for _config_name in "$@"; do scripts/config -k --undefine "${_config_name}" done } _enable() { for _config_name in "$@"; do scripts/config -k --enable "${_config_name}" done } _disable() { for _config_name in "$@"; do scripts/config -k --disable "${_config_name}" done } _module() { for _config_name in "$@"; do scripts/config -k --module "${_config_name}" done } _prompt_from_array() { # Prompts from array, selects default index on empty user input # Set the _default_index variable to enable default index selection if [ $# = "0" ]; then warning "Prompting on an empty array, please report this issue." exit 1 fi _N=$(($#-1)) _index=0 for _value in "$@"; do if [ "$_index" = "$_default_index" ]; then plain " > ${_index}) ${_value}" else plain " ${_index}) ${_value}" fi _index=$(($_index + 1)) done while true; do read -rp "[0-${_N}]: "; if [[ -z "$REPLY" && -n "$_default_index" ]]; then _selected_index="$_default_index" break elif [[ "$REPLY" =~ ^[0-9]+$ && 0 -le "$REPLY" && "$REPLY" -le $_N ]]; then _selected_index="$REPLY" break else echo "Wrong selection: select any number in 0-$_N" fi done _natural_index=$(($_selected_index + 1)) _selected_value="${!_natural_index}" plain "Selected: ${_selected_value}" unset _natural_index unset _default_index } # cpu opt _cpu_marchs=("native_amd" "native_intel" "generic_cpu" "generic_cpu2" "generic_cpu3" "generic_cpu4") _cpu_marchs+=("k8" "k8sse3" "k10" "barcelona" "bobcat" "jaguar" "bulldozer" "piledriver") _cpu_marchs+=("steamroller" "excavator" "zen" "zen2" "zen3" "mpsc" "atom" "core2" "nehalem" "westmere") _cpu_marchs+=("bonnell" "silvermont" "sandybridge" "ivybridge" "haswell" "broadwell" "skylake") _cpu_marchs+=("skylakex" "cannonlake" "icelake" "goldmont" "goldmontplus" "cascadelake") _cpu_marchs+=("cooperlake" "tigerlake" "sapphirerapids" "rocketlake" "alderlake") typeset -A _generic_march_map _generic_march_map=( ["generic"]="generic_cpu" ["generic_v2"]="generic_cpu2" ["generic_v3"]="generic_cpu3" ["generic_v4"]="generic_cpu4" ) if [ -n "$_processor_opt" ]; then # Replace customization.cfg convention with .config convention for generic if [[ "${!_generic_march_map[@]}" =~ "$_processor_opt" ]]; then _processor_opt="${_generic_march_map[$_processor_opt]}" fi if ! [[ "${_cpu_marchs[@]}" =~ "$_processor_opt" ]]; then warning "the setup _processor_opt=\"${_processor_opt}\" not recognized. Prompting..." _processor_opt="" fi fi if [ -z "$_processor_opt" ]; then msg2 "Please select the desired CPU micro-architecture" _default_index="2" _prompt_from_array "${_cpu_marchs[@]}" _processor_opt="${_selected_value}" fi for _march in "${_cpu_marchs[@]}" do _march_upper=`echo "$_march" | tr '[a-z]' '[A-Z]'` if [ "$_processor_opt" = "$_march" ]; then if [[ "$_march" = "generic"* ]]; then _enable "${_march_upper}" else _enable "M${_march_upper}" fi else if [[ "$_march" = "generic"* ]]; then _disable "${_march_upper}" else _disable "M${_march_upper}" fi fi done