Skip to content

Instantly share code, notes, and snippets.

@exoosh
Created February 15, 2023 16:21
Show Gist options
  • Save exoosh/c734665e6f53a81d23cae8677f834dc9 to your computer and use it in GitHub Desktop.
Save exoosh/c734665e6f53a81d23cae8677f834dc9 to your computer and use it in GitHub Desktop.
Detecting most recent Clang tools (Bash)
function detect_newest # Function to detect newest clang-based tool (they have a numeric suffix -<version>)
{
local PFX=${1:-clang++}
for v in "" -{32..1}; do test -n "$(which -- $PFX$v)" && { echo "$PFX$v"; break; }; done
}
[[ -z "$CXX" ]] && CXX=$(detect_newest clang++)
[[ -z "$CC" ]] && CC=$(detect_newest clang)
[[ -n "$CXX" ]] || { echo -e "${cR}FATAL:${cZ} ${cW}CXX${cZ} not detected."; }
[[ -n "$CC" ]] || { echo -e "${cR}FATAL:${cZ} ${cW}CC${cZ} not detected."; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment