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'
18 # Stripping is known to make non-PIE Linux netradiant binary unusable.
19 # Maybe that's related to the way we patch rpath?
20 # Building NetRadiant as non-PIE is required because of
21 # a mistake in the mimetype-library that prevents users
22 # to run the application from file managers on Linux.
23 # See: https://gitlab.freedesktop.org/xdg/shared-mime-info/-/issues/11
25 install_target='install'
27 # Stripping is known to make FreeBSD binaries unusable.
28 # Maybe that's related to the way we patch rpath?
30 install_target='install'
37 if command -v 'nproc' >/dev/null
43 egrep "^processor" /proc/cpuinfo | wc -l
49 sysctl -n hw.logicalcpu \
52 'MSYS_NT-'*|'CYGWIN_NT-'*|'MINGW'*'_NT-'*)
53 if command -v 'wmic' >/dev/null
55 wmic cpu get NumberOfLogicalProcessors/Format:List \
56 | grep -m1 '=' | cut -f2 -d'='
58 echo "${NUMBER_OF_PROCESSORS:-${_job_count}}"
68 job_count="$(_nproc)" 2>/dev/null
69 job_count="${job_count:-${_job_count}}"
71 declare -a cmake_user_opts
80 install_target='install'
85 cmake_user_opts[${#cmake_user_opts[@]}]="${1}"
91 declare -a fetch_submodules_cmd
92 for submodule_file in 'libs/crunch/inc/crn_decomp.h' \
93 'tools/unvanquished/daemonmap/tools/quake3/q3map2/main.c'
95 if ! [ -f "${project_source_dir}/${submodule_file}" ]
97 fetch_submodules_cmd=(git -C "${project_source_dir}" submodule update --init --recursive)
101 case "$(uname -s)" in
103 cmake_user_opts[${#cmake_user_opts[@]}]='-DBUILTIN_GTKGLEXT=ON -DBUILTIN_GTKTHEME_MOJAVE=ON'
107 task_enter_build_dir () {
109 mkdir -pv "${build_dir}"
113 task_fetch_submodules () {
115 "${fetch_submodules_cmd[@]}"
122 -D'CMAKE_INSTALL_PREFIX'="${install_dir}" \
123 -D'CMAKE_BUILD_TYPE'="${build_type}" \
124 "${cmake_user_opts[@]}" \
125 "${project_source_dir}"
128 task_build_builtins () {
130 make -j"${job_count}" builtins
135 make -j"${job_count}"
140 make "${install_target}"
147 task_fetch_submodules