radiant: add entries to increase and decrease FOV in camera menu
[xonotic/netradiant.git] / easy-builder
1 #! /usr/bin/env bash
2
3 # This script is meant to be kept small and simple
4 # If you think about adding features, it's probably a bad idea
5
6 set -e # exit if a command fails
7 set -o pipefail # Will return the exit status of make if it fails
8
9 project_source_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
10
11 build_dir="${project_source_dir}/build${SUBDIR:+/${SUBDIR}}"
12 install_dir="${project_source_dir}/install${SUBDIR:+/${SUBDIR}}"
13
14 install_target='install/strip'
15 build_type='Release'
16
17 _job_count=4
18
19 _nproc () {
20         if command -v 'nproc' >/dev/null
21         then
22                 nproc
23         else
24                 case "$(uname -s)" in
25                         'Linux')
26                                 egrep "^processor" /proc/cpuinfo | wc -l
27                                 ;;
28                         'FreeBSD'|'Darwin')
29                                 sysctl -n hw.ncpu
30                                 ;;
31                         'MSYS_NT-'*|'CYGWIN_NT-'*|'MINGW'*'_NT-'*)
32                                 if command -v 'wmic' >/dev/null
33                                 then
34                                         wmic cpu get NumberOfLogicalProcessors/Format:List \
35                                                 | grep -m1 '=' | cut -f2 -d'='
36                                 else
37                                         echo "${NUMBER_OF_PROCESSORS:-${_job_count}}"
38                                 fi
39                                 ;;
40                         *)
41                                 echo "${_job_count}"
42                                 ;;
43                 esac
44         fi
45 }
46
47 job_count="$(_nproc)" 2>/dev/null
48 job_count="${job_count:-${_job_count}}"
49
50 declare -a cmake_user_opts
51 while [ ! -z "${1}" ]
52 do
53         case "${1}" in
54         '-j'*)
55                 job_count="${1:2}"
56                 shift
57                 ;;
58         '--debug')
59                 install_target='install'
60                 build_type='Debug'
61                 shift
62                 ;;
63         *)
64         cmake_user_opts[${#cmake_user_opts[@]}]="${1}"
65         shift
66                 ;;
67         esac
68 done
69
70 declare -a fetch_submodules_cmd
71 for submodule_file in 'libs/crunch/inc/crn_decomp.h' \
72         'tools/unvanquished/daemonmap/tools/quake3/q3map2/main.c'
73 do
74         if ! [ -f "${project_source_dir}/${submodule_file}" ]
75         then
76                 fetch_submodules_cmd=(git -C "${project_source_dir}" submodule update --init --recursive)
77         fi
78 done
79
80 set -x
81
82 "${fetch_submodules_cmd[@]}"
83
84 mkdir -pv "${build_dir}"
85 cd "${build_dir}"
86
87 cmake \
88         -G'Unix Makefiles' \
89         -D'CMAKE_INSTALL_PREFIX'="${install_dir}" \
90         -D'CMAKE_BUILD_TYPE'="${build_type}" \
91         "${cmake_user_opts[@]}" \
92         "${project_source_dir}"
93
94 cmake \
95         --build "${build_dir}" \
96         -- \
97         -j"${job_count}" \
98         "${install_target}"