3 # This script is meant to be kept small and simple
4 # If you think about adding features, it's probably a bad idea
6 set -e # exit if a command fails
7 set -o pipefail # Will return the exit status of make if it fails
9 project_source_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
11 build_dir="${project_source_dir}/build${SUBDIR:+/${SUBDIR}}"
12 install_dir="${project_source_dir}/install${SUBDIR:+/${SUBDIR}}"
19 nproc='egrep "^processor" /proc/cpuinfo | wc -l'
22 nproc='sysctl -n hw.ncpu'
24 if [ -f "$(ls '/usr/local/bin/g++'* | sort | tail -n1)" ]
26 gcc_version="$(ls '/usr/local/bin/g++'* | sort | tail -n1 | sed -e 's/.*[^0-9]\([0-9][0-9]*\)$/\1/')"
27 cmake_opts[${#cmake_opts[@]}]="-DCMAKE_C_COMPILER=/usr/local/bin/gcc${gcc_version}"
28 cmake_opts[${#cmake_opts[@]}]="-DCMAKE_CXX_COMPILER=/usr/local/bin/g++${gcc_version}"
30 printf "WARNING: GCC is recommended: if build fails, install GCC and retry\n" >&2
34 nproc='sysctl -n hw.ncpu'
36 if [ -f "$(ls '/usr/local/bin/g++-'* | sort | tail -n1)" ]
38 gcc_version="$(ls '/usr/local/bin/g++-'* | sort | tail -n1 | sed -e 's/.*[^0-9]\([0-9][0-9]*\)$/\1/')"
39 cmake_opts[${#cmake_opts[@]}]="-DCMAKE_C_COMPILER=/usr/local/bin/gcc-${gcc_version}"
40 cmake_opts[${#cmake_opts[@]}]="-DCMAKE_CXX_COMPILER=/usr/local/bin/g++-${gcc_version}"
42 printf "WARNING: GCC is recommended: if build fails, install GCC and retry\n" >&2
46 nproc='echo "${NUMBER_OF_PROCESSORS}"'
48 'CYGWIN_NT-'*|'MINGW'*'_NT-'*)
49 nproc='echo "${NUMBER_OF_PROCESSORS}"'
50 printf "WARNING: system is not tested: if build fails, use MSYS2 instead\n" >&2
54 printf "WARNING: system is not tested\n" >&2
58 if command -v 'nproc' >/dev/null
62 job_count="$(sh -c "${nproc}")"
65 job_count="${job_count:-4}"
67 declare -a cmake_user_opts
80 cmake_user_opts[${#cmake_user_opts[@]}]="${1}"
86 declare -a fetch_submodules_cmd
87 if ! [ -f "${project_source_dir}/libs/crunch/inc/crn_decomp.h" ]
89 fetch_submodules_cmd=(git -C "${project_source_dir}" submodule update --init --recursive)
94 "${fetch_submodules_cmd[@]}"
98 -S"${project_source_dir}" \
100 -D'CMAKE_INSTALL_PREFIX'="${install_dir}" \
101 -D'CMAKE_BUILD_TYPE'="${build_type}" \
103 "${cmake_user_opts[@]}"
106 --build "${build_dir}" \