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)"
12 if command -v nproc >/dev/null
17 build_dir="${project_source_dir}/build${SUBDIR:+/${SUBDIR}}"
18 install_dir="${project_source_dir}/install${SUBDIR:+/${SUBDIR}}"
35 cmake_user_opts+=" ${1}"
47 if [ -f "$(ls '/usr/local/bin/g++'* | sort | tail -n1)" ]
49 gcc_version="$(ls '/usr/local/bin/g++'* | sort | tail -n1 | sed -e 's/.*[^0-9]\([0-9][0-9]*\)$/\1/')"
50 cmake_opts+=" -DCMAKE_C_COMPILER=/usr/local/bin/gcc${gcc_version}"
51 cmake_opts+=" -DCMAKE_CXX_COMPILER=/usr/local/bin/g++${gcc_version}"
53 printf "WARNING: GCC is recommended: if build fails, install GCC and retry\n" >&2
57 if [ -f "$(ls '/usr/local/bin/g++-'* | sort | tail -n1)" ]
59 gcc_version="$(ls '/usr/local/bin/g++-'* | sort | tail -n1 | sed -e 's/.*[^0-9]\([0-9][0-9]*\)$/\1/')"
60 cmake_opts+=" -DCMAKE_C_COMPILER=/usr/local/bin/gcc-${gcc_version}"
61 cmake_opts+=" -DCMAKE_CXX_COMPILER=/usr/local/bin/g++-${gcc_version}"
63 printf "WARNING: GCC is recommended: if build fails, install GCC and retry\n" >&2
69 'CYGWIN_NT-'*|'MINGW'*'_NT-'*)
70 printf "WARNING: system is not tested: if build fails, use MSYS2 instead\n" >&2
73 printf "WARNING: system is not tested\n" >&2
77 fetch_submodules_cmd=''
78 if ! [ -f "${project_source_dir}/libs/crunch/inc/crn_decomp.h" ]
80 fetch_submodules_cmd='git submodule update --init --recursive'
85 cd "${project_source_dir}"
87 ${fetch_submodules_cmd}
93 -D'CMAKE_INSTALL_PREFIX'="${install_dir}" \
94 -D'CMAKE_BUILD_TYPE'="${build_type}" \
100 --build "${build_dir}" \