commit 8a5c53c2b2075e7c5572485aba2c648462be6ac6
Author: Scott Kostyshak <[email protected]>
Date:   Thu Jul 31 11:06:08 2025 +0200

    lyx-tester: fn to register GCC and Clang versions
    
    The new function 'update-alternatives-add-new-gcc-and-clang' makes
    it easy to register all available GCC and Clang versions.
    
    This makes it possible to use 'switch-gcc-to' and 'switch-clang-to',
    which are defined in the 'switches' file.
---
 development/lyx-tester/convenience-functions.sh | 40 +++++++++++++++++++++++++
 development/lyx-tester/switches                 |  1 +
 2 files changed, 41 insertions(+)

diff --git a/development/lyx-tester/convenience-functions.sh 
b/development/lyx-tester/convenience-functions.sh
index 1f7684fa66..63dd8bbba4 100644
--- a/development/lyx-tester/convenience-functions.sh
+++ b/development/lyx-tester/convenience-functions.sh
@@ -10,3 +10,43 @@ function git-grep-accel-robust ()
   search_str="$( echo "$1" | sed 's/.\{1\}/&\&\\\?/g')"
   git grep -i "${search_str}"
 }
+
+
+function update-alternatives-add-new-gcc-and-clang ()
+{
+
+  # It is in theory fine to run this multiple times. i.e., shouldn't affect
+  # anything if it's already installed.
+
+  # todo: should we clear previous ones?
+  #
+  # These will give errors (and exit) the first time, i.e., when there are no
+  # alternatives set:
+  #
+  #   update-alternatives: error: no alternatives for clang++
+  #
+  #sudo update-alternatives --remove-all gcc
+  #sudo update-alternatives --remove-all g++
+  #sudo update-alternatives --remove-all gfortran
+  #
+  #sudo update-alternatives --remove-all clang
+  #sudo update-alternatives --remove-all clang++
+
+  # Order is important. The last one will be the default.
+  gcc_versions=( $(ls /usr/bin/gcc-* | grep -o -P '(?<=gcc-)\d+(?=$)') )
+  for v in "${gcc_versions[@]}"; do
+    echo "${v}"
+    sudo update-alternatives --install "/usr/bin/gcc" "gcc" 
"/usr/bin/gcc-${v}" "${v}"
+    sudo update-alternatives --install "/usr/bin/g++" "g++" 
"/usr/bin/g++-${v}" "${v}"
+    sudo update-alternatives --install "/usr/bin/gfortran" "gfortran" 
"/usr/bin/gfortran-${v}" "${v}"
+  done
+
+  clang_versions=( $(ls /usr/bin/clang-* | grep -o -P '(?<=clang-)\d+(?=$)') )
+  for v in "${clang_versions[@]}"; do
+    echo "${v}"
+    sudo update-alternatives --install "/usr/bin/clang" "clang" 
"/usr/bin/clang-${v}" "${v}"
+    sudo update-alternatives --install "/usr/bin/clang++" "clang++" 
"/usr/bin/clang++-${v}" "${v}"
+  done
+
+  echo -e "now you can use 'switch-gcc-to' and 'switch-clang-to' (from 
lyx-tester switches)"
+}
diff --git a/development/lyx-tester/switches b/development/lyx-tester/switches
index 3e0786f8b1..b2e0e0f47f 100644
--- a/development/lyx-tester/switches
+++ b/development/lyx-tester/switches
@@ -159,6 +159,7 @@ function switch-latex-to-tl-stable ()
 }
 
 
+# see also 'update-alternatives-add-new-gcc-and-clang' in 
'convenience-functions.sh'
 function switch-gcc-to ()
 {
   sudo update-alternatives --set gcc "/usr/bin/gcc-$1"
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to