yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
4721b6ef2
master
1#!/usr/bin/env bash 2 3set -e 4 5help () { 6me =$( basename " $ 0" ) 7cat <<EOF 8$ me : Fetch, build and install LLVM for Slang 9 10Options: 11--repo: The source git repo, default: $ repo 12--branch: The branch (or tag) to fetch, default: $ branch 13--source-dir: Unpack and build in this directory: default $ source_dir 14--config: The configuration to build, default $ config 15--install-prefix: Install under this prefix 16--: Any following arguments will be passed to the CMake configuration command 17EOF 18} 19 20# 21# Some helper functions 22# 23msg () { 24printf "%s\n" " $ 1 " >&2 25} 26 27fail () { 28msg " $ 1 " 29exit 1 30} 31 32for prog in "cmake" "ninja" "git" ;do 33if !command -v " $ prog " &>/dev/null;then 34msg "This script needs $ prog , but it isn't in \$PATH" 35missing_bin =1 36fi 37done 38if [" $ missing_bin " ];then 39exit 1 40fi 41 42# 43# Temp dir with cleanup on exit 44# 45temp_dir =$( mktemp -d ) 46cleanup () { 47 localexit_status =$ ? 48rm -rf " $ temp_dir " 49exit $ exit_status 50} 51trap cleanup EXIT SIGHUP SIGINT SIGTERM 52 53# 54# Options and parsing 55# 56repo =https://github.com/llvm/llvm-project 57branch =llvmorg-14.0.6 58source_dir =$ temp_dir 59install_prefix = 60config =Release 61extra_arguments =() 62 63while [[" $ #" -gt 0 ]];do 64case $ 1 in 65 -h| --help) 66help 67exit 68 ;; 69 --repo) 70repo =$ 2 71shift 72 ;; 73 --branch) 74branch =$ 2 75shift 76 ;; 77 --source-dir) 78source_dir =$ 2 79shift 80 ;; 81 --config) 82config =$ 2 83shift 84 ;; 85 --install-prefix) 86install_prefix =$ 2 87shift 88 ;; 89 --) 90shift 91extra_arguments +=(" $ @" ) 92break 93 ;; 94 *) 95msg "Unknown parameter passed: $ 1 " 96help >&2 97exit 1 98 ;; 99esac 100shift 101done 102 103[ -n" $ repo " ] ||fail "please set --repo" 104[ -n" $ branch " ] ||fail "please set --branch" 105[ -n" $ source_dir " ] ||fail "please set --source-dir" 106[ -n" $ config " ] ||fail "please set --config" 107[ -n" $ install_prefix " ] ||fail "please set --install-prefix" 108 109msg "##########################################################" 110msg "# Fetching LLVM from $ repo at $ branch " 111msg "##########################################################" 112git -c advice.detachedHead=false clone" $ repo " --branch " $ branch " " $ source_dir " --depth 1 113 114msg "##########################################################" 115msg "# Configuring LLVM in $ source_dir " 116msg "##########################################################" 117cmake_arguments_for_slang =( 118# Don't build unnecessary things 119 -DLLVM_BUILD_LLVM_C_DYLIB=0 120 -DLLVM_INCLUDE_BENCHMARKS=0 121 -DLLVM_INCLUDE_DOCS=0 122 -DLLVM_INCLUDE_EXAMPLES=0 123 -DLLVM_INCLUDE_TESTS=0 124 -DLLVM_ENABLE_TERMINFO=0 125 -DCLANG_BUILD_TOOLS=0 126 -DCLANG_ENABLE_STATIC_ANALYZER=0 127 -DCLANG_ENABLE_ARCMT=0 128 -DCLANG_INCLUDE_DOCS=0 129 -DCLANG_INCLUDE_TESTS=0 130# Requirements for Slang 131 -DLLVM_ENABLE_PROJECTS=clang 132"-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64" 133 -DLLVM_BUILD_TOOLS=0 134# Get LLVM to use the static linked version of the msvc runtime 135"-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded $ < $ <CONFIG:Debug>:Debug>" 136"-DLLVM_USE_CRT_RELEASE=MT" 137"-DLLVM_USE_CRT_DEBUG=MTd" 138) 139build_dir =$ source_dir /build 140mkdir -p " $ build_dir " 141cmake \ 142-S " $ source_dir /llvm" -B " $ build_dir " \ 143-G "Ninja Multi-Config" \ 144" ${ cmake_arguments_for_slang [@]} " \ 145" ${ extra_arguments [@]} " 146 147msg "##########################################################" 148msg "# Building LLVM in $ build_dir " 149msg "##########################################################" 150cmake --build " $ build_dir " -j --config " $ config " 151 152msg "##########################################################" 153msg "# Installing LLVM to $ install_prefix " 154msg "##########################################################" 155cmake --install " $ build_dir " --prefix " $ install_prefix " --config " $ config " 156 157msg "##########################################################" 158msg "LLVM installed in $ install_prefix " 159msg "Please add $ install_prefix to CMAKE_PREFIX_PATH" 160msg "##########################################################"