Skip to content

Instantly share code, notes, and snippets.

@austintraver
Created March 22, 2021 00:47
Show Gist options
  • Save austintraver/6dd0a1412d04cc4e8f943086563e8db2 to your computer and use it in GitHub Desktop.
Save austintraver/6dd0a1412d04cc4e8f943086563e8db2 to your computer and use it in GitHub Desktop.
Configure LLVM & Clang as the default C/C++ developer toolchain
function cling {
if (( ${#} != 1 )); then
echo "usage: \`cling VERSION\` " >&2
return 1
fi
typeset version=${1}
typeset priority=$(( ${version} * 10 ))
update-alternatives \
--install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-${version} ${priority} \
--slave /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-${version} \
--slave /usr/bin/llvm-as llvm-as /usr/bin/llvm-as-${version} \
--slave /usr/bin/llvm-bcanalyzer llvm-bcanalyzer /usr/bin/llvm-bcanalyzer-${version} \
--slave /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-${version} \
--slave /usr/bin/llvm-diff llvm-diff /usr/bin/llvm-diff-${version} \
--slave /usr/bin/llvm-dis llvm-dis /usr/bin/llvm-dis-${version} \
--slave /usr/bin/llvm-dwarfdump llvm-dwarfdump /usr/bin/llvm-dwarfdump-${version} \
--slave /usr/bin/llvm-extract llvm-extract /usr/bin/llvm-extract-${version} \
--slave /usr/bin/llvm-link llvm-link /usr/bin/llvm-ink-${version} \
--slave /usr/bin/llvm-mc llvm-mc /usr/bin/llvm-mc-${version} \
--slave /usr/bin/llvm-mcmarkup llvm-mcmarkup /usr/bin/llvm-mcmarkup-${version} \
--slave /usr/bin/llvm-nm llvm-nm /usr/bin/llvm-nm-${version} \
--slave /usr/bin/llvm-objdump llvm-objdump /usr/bin/llvm-objdump-${version} \
--slave /usr/bin/llvm-ranlib llvm-ranlib /usr/bin/llvm-ranlib-${version} \
--slave /usr/bin/llvm-readobj llvm-readobj /usr/bin/llvm-readobj-${version} \
--slave /usr/bin/llvm-rtdyld llvm-rtdyld /usr/bin/llvm-rtdyld-${version} \
--slave /usr/bin/llvm-size llvm-size /usr/bin/llvm-size-${version} \
--slave /usr/bin/llvm-stress llvm-stress /usr/bin/llvm-stress-${version} \
--slave /usr/bin/llvm-symbolizer llvm-symbolizer /usr/bin/llvm-symbolizer-${version} \
--slave /usr/bin/llvm-tblgen llvm-tblgen /usr/bin/llvm-tblgen-${version}
update-alternatives \
--install /usr/bin/clang clang /usr/bin/clang-${version} ${priority} \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${version} \
--slave /usr/bin/asan_symbolize asan_symbolize /usr/bin/asan_symbolize-${version} \
--slave /usr/bin/c-index-test c-index-test /usr/bin/c-index-test-${version} \
--slave /usr/bin/clang-check clang-check /usr/bin/clang-check-${version} \
--slave /usr/bin/clang-cl clang-cl /usr/bin/clang-cl-${version} \
--slave /usr/bin/clang-cpp clang-cpp /usr/bin/clang-cpp-${version} \
--slave /usr/bin/clang-format clang-format /usr/bin/clang-format-${version} \
--slave /usr/bin/clang-format-diff clang-format-diff /usr/bin/clang-format-diff-${version} \
--slave /usr/bin/clang-import-test clang-import-test /usr/bin/clang-import-test-${version} \
--slave /usr/bin/clang-include-fixer clang-include-fixer /usr/bin/clang-include-fixer-${version} \
--slave /usr/bin/clang-offload-bundler clang-offload-bundler /usr/bin/clang-offload-bundler-${version} \
--slave /usr/bin/clang-query clang-query /usr/bin/clang-query-${version} \
--slave /usr/bin/clang-rename clang-rename /usr/bin/clang-rename-${version} \
--slave /usr/bin/clang-reorder-fields clang-reorder-fields /usr/bin/clang-reorder-fields-${version} \
--slave /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-${version} \
--slave /usr/bin/lldb lldb /usr/bin/lldb-${version} \
--slave /usr/bin/lldb-server lldb-server /usr/bin/lldb-server-${version}
}
# Example usage:
# $ cling 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment