project_source_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
-job_count='4'
-if command -v nproc >/dev/null
-then
- job_count="$(nproc)"
-fi
-
build_dir="${project_source_dir}/build${SUBDIR:+/${SUBDIR}}"
install_dir="${project_source_dir}/install${SUBDIR:+/${SUBDIR}}"
+install_target='install/strip'
build_type='Release'
-cmake_user_opts=''
-while [ ! -z ${1} ]
+_job_count=4
+
+_nproc () {
+ if command -v 'nproc' >/dev/null
+ then
+ nproc
+ else
+ case "$(uname -s)" in
+ 'Linux')
+ egrep "^processor" /proc/cpuinfo | wc -l
+ ;;
+ 'FreeBSD')
+ sysctl -n hw.ncpu
+ ;;
+ 'Darwin')
+ sysctl -n hw.logicalcpu \
+ || sysctl -n hw.ncpu
+ ;;
+ 'MSYS_NT-'*|'CYGWIN_NT-'*|'MINGW'*'_NT-'*)
+ if command -v 'wmic' >/dev/null
+ then
+ wmic cpu get NumberOfLogicalProcessors/Format:List \
+ | grep -m1 '=' | cut -f2 -d'='
+ else
+ echo "${NUMBER_OF_PROCESSORS:-${_job_count}}"
+ fi
+ ;;
+ *)
+ echo "${_job_count}"
+ ;;
+ esac
+ fi
+}
+
+job_count="$(_nproc)" 2>/dev/null
+job_count="${job_count:-${_job_count}}"
+
+declare -a cmake_user_opts
+while [ ! -z "${1}" ]
do
- case "${1}" in
- '-j'*)
- job_count="${1:2}"
- shift
- ;;
- '--debug')
- build_type='Debug'
- shift
- ;;
- *)
- cmake_user_opts+=" ${1}"
+ case "${1}" in
+ '-j'*)
+ job_count="${1:2}"
+ shift
+ ;;
+ '--debug')
+ install_target='install'
+ build_type='Debug'
+ shift
+ ;;
+ *)
+ cmake_user_opts[${#cmake_user_opts[@]}]="${1}"
shift
- ;;
- esac
+ ;;
+ esac
+done
+
+declare -a fetch_submodules_cmd
+for submodule_file in 'libs/crunch/inc/crn_decomp.h' \
+ 'tools/unvanquished/daemonmap/tools/quake3/q3map2/main.c'
+do
+ if ! [ -f "${project_source_dir}/${submodule_file}" ]
+ then
+ fetch_submodules_cmd=(git -C "${project_source_dir}" submodule update --init --recursive)
+ fi
done
-cmake_opts=''
case "$(uname -s)" in
- 'Linux')
- # no tweak required
- ;;
- 'FreeBSD')
- if [ -f "$(ls '/usr/local/bin/g++'* | sort | tail -n1)" ]
- then
- gcc_version="$(ls '/usr/local/bin/g++'* | sort | tail -n1 | sed -e 's/.*[^0-9]\([0-9][0-9]*\)$/\1/')"
- cmake_opts+=" -DCMAKE_C_COMPILER=/usr/local/bin/gcc${gcc_version}"
- cmake_opts+=" -DCMAKE_CXX_COMPILER=/usr/local/bin/g++${gcc_version}"
- else
- printf "WARNING: GCC is recommended: if build fails, install GCC and retry\n" >&2
- fi
- ;;
'Darwin')
- if [ -f "$(ls '/usr/local/bin/g++-'* | sort | tail -n1)" ]
- then
- gcc_version="$(ls '/usr/local/bin/g++-'* | sort | tail -n1 | sed -e 's/.*[^0-9]\([0-9][0-9]*\)$/\1/')"
- cmake_opts+=" -DCMAKE_C_COMPILER=/usr/local/bin/gcc-${gcc_version}"
- cmake_opts+=" -DCMAKE_CXX_COMPILER=/usr/local/bin/g++-${gcc_version}"
- else
- printf "WARNING: GCC is recommended: if build fails, install GCC and retry\n" >&2
- fi
- ;;
- 'MSYS_NT-'*)
- # no tweak required
- ;;
- 'CYGWIN_NT-'*|'MINGW'*'_NT-'*)
- printf "WARNING: system is not tested: if build fails, use MSYS2 instead\n" >&2
- ;;
- *)
- printf "WARNING: system is not tested\n" >&2
+ cmake_user_opts[${#cmake_user_opts[@]}]='-DBUILTIN_GTKGLEXT=ON -DBUILTIN_GTKTHEME_MOJAVE=ON'
;;
esac
-fetch_submodules_cmd=''
-if ! [ -f "${project_source_dir}/libs/crunch/inc/crn_decomp.h" ]
-then
- fetch_submodules_cmd='git submodule update --init --recursive'
-fi
-
set -x
-cd "${project_source_dir}"
+"${fetch_submodules_cmd[@]}"
-${fetch_submodules_cmd}
+mkdir -pv "${build_dir}"
+cd "${build_dir}"
cmake \
-G'Unix Makefiles' \
- -H'.' \
- -B"${build_dir}" \
-D'CMAKE_INSTALL_PREFIX'="${install_dir}" \
-D'CMAKE_BUILD_TYPE'="${build_type}" \
- ${cmake_opts} \
- ${cmake_user_opts} \
- ${@}
+ "${cmake_user_opts[@]}" \
+ "${project_source_dir}"
+
+cmake \
+ --build "${build_dir}" \
+ -- \
+ -j"${job_count}" \
+ 'builtins'
cmake \
--build "${build_dir}" \
-- \
-j"${job_count}" \
- install
+ "${install_target}"