summarylogtreecommitdiffstats
path: root/configure
blob: a54e08dc246df08c568c671965f86cb0b1d5c503 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/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