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}}"
14 install_target='install/strip'
20 nproc='egrep "^processor" /proc/cpuinfo | wc -l'
23 nproc='sysctl -n hw.ncpu'
25 if [ -f "$(ls '/usr/local/bin/g++'* | sort | tail -n1)" ]
27 gcc_version="$(ls '/usr/local/bin/g++'* | sort | tail -n1 | sed -e 's/.*[^0-9]\([0-9][0-9]*\)$/\1/')"
28 cmake_opts[${#cmake_opts[@]}]="-DCMAKE_C_COMPILER=/usr/local/bin/gcc${gcc_version}"
29 cmake_opts[${#cmake_opts[@]}]="-DCMAKE_CXX_COMPILER=/usr/local/bin/g++${gcc_version}"
31 printf "WARNING: GCC is recommended: if build fails, install GCC and retry\n" >&2
35 nproc='sysctl -n hw.ncpu'
37 if [ -f "$(ls '/usr/local/bin/g++-'* | sort | tail -n1)" ]
39 gcc_version="$(ls '/usr/local/bin/g++-'* | sort | tail -n1 | sed -e 's/.*[^0-9]\([0-9][0-9]*\)$/\1/')"
40 cmake_opts[${#cmake_opts[@]}]="-DCMAKE_C_COMPILER=/usr/local/bin/gcc-${gcc_version}"
41 cmake_opts[${#cmake_opts[@]}]="-DCMAKE_CXX_COMPILER=/usr/local/bin/g++-${gcc_version}"
43 printf "WARNING: GCC is recommended: if build fails, install GCC and retry\n" >&2
47 nproc='echo "${NUMBER_OF_PROCESSORS}"'
49 'CYGWIN_NT-'*|'MINGW'*'_NT-'*)
50 nproc='echo "${NUMBER_OF_PROCESSORS}"'
51 printf "WARNING: system is not tested: if build fails, use MSYS2 instead\n" >&2
55 printf "WARNING: system is not tested\n" >&2
59 if command -v 'nproc' >/dev/null
63 job_count="$(sh -c "${nproc}")"
66 job_count="${job_count:-4}"
68 declare -a cmake_user_opts
77 install_target='install'
82 cmake_user_opts[${#cmake_user_opts[@]}]="${1}"
88 declare -a fetch_submodules_cmd
89 for submodule_file in 'libs/crunch/inc/crn_decomp.h' \
90 'tools/unvanquished/daemonmap/tools/quake3/q3map2/main.c'
92 if ! [ -f "${project_source_dir}/${submodule_file}" ]
94 fetch_submodules_cmd=(git -C "${project_source_dir}" submodule update --init --recursive)
100 "${fetch_submodules_cmd[@]}"
104 -S"${project_source_dir}" \
106 -D'CMAKE_INSTALL_PREFIX'="${install_dir}" \
107 -D'CMAKE_BUILD_TYPE'="${build_type}" \
109 "${cmake_user_opts[@]}" \
110 "${project_source_dir}"
113 --build "${build_dir}" \