Skip to content

Instantly share code, notes, and snippets.

@kofuk
Last active September 20, 2022 03:36
Show Gist options
  • Save kofuk/8ea8961381e2b488ccbc2db5ff011210 to your computer and use it in GitHub Desktop.
Save kofuk/8ea8961381e2b488ccbc2db5ff011210 to your computer and use it in GitHub Desktop.
Build LLVM 15 on CentOS 7
#!/usr/bin/env bash
set -eu
_build_dir="${HOME}/build"
_build_dir_small=/dev/shm
_build_dir_medium=/tmp
PREFIX="${HOME}/.local"
function build_gmp() {
cd "${_build_dir_small}"
curl -L https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2 | tar -xj
cd gmp-6.2.1
./configure --prefix="${PREFIX}"
make -j$(nproc)
make install
cd ..
rm -rf gmp-6.2.1
}
function build_mpfr() {
cd "${_build_dir_small}"
curl -L https://gcc.gnu.org/pub/gcc/infrastructure/mpfr-4.1.0.tar.bz2 | tar -xj
cd mpfr-4.1.0
./configure --prefix="${PREFIX}"
make -j$(nproc)
make install
cd ..
rm -rf mpfr-4.1.0
}
function build_mpc() {
cd "${_build_dir_small}"
curl -L https://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.2.1.tar.gz | tar -xz
cd mpc-1.2.1
./configure --prefix="${PREFIX}" --with-mpfr="${PREFIX}"
make -j$(nproc)
make install
cd ..
rm -rf mpc-1.2.1
}
function build_gcc() {
cd "${_build_dir_medium}"
curl -L https://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-12.2.0/gcc-12.2.0.tar.xz | tar -xJ
cd gcc-12.2.0
mkdir _build
cd _build
../configure --prefix="${PREFIX}" --with-gmp="${PREFIX}" --with-mpfr="${PREFIX}" --with-mpc="${PREFIX}" \
--libdir="${PREFIX}/lib" --libexecdir="${PREFIX}/lib" --enable-languages=c,c++
make -j$(nproc)
make install
cd ../..
rm -rf gcc-12.2.0
}
function build_llvm() {
cd "${_build_dir}"
curl -L https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.0/llvm-project-15.0.0.src.tar.xz | tar -xJ
cd llvm-project-15.0.0.src
mkdir _build
cd _build
CC="${PREFIX}/bin/gcc" CXX="${PREFIX}/bin/g++" \
cmake ../llvm -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="${PREFIX}" -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra'
# parallel build may run out of memory.
make -j$(nproc) || make
make install
cd ../..
rm -rf llvm-project-15.0.0.src
}
function build_all() {
export LD_LIBRARY_PATH="${PREFIX}/lib"
export PATH="${PREFIX}/bin:${PATH}"
build_gmp
build_mpfr
# MPC depends on MPFR
export LDFLAGS="-L${PREFIX}/lib64 -Wl,-rpath=${PREFIX}/lib64 -L${PREFIX}/lib -Wl,-rpath=${PREFIX}/lib"
export LD_RUN_PATH="${PREFIX}/lib64:${PREFIX}/lib"
build_mpc
build_gcc
build_llvm
}
function __main() {
mkdir -p "${_build_dir}" "${_build_dir_small}" "${_build_dir_medium}"
build_all
post_build
exit
} && __main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment