]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - easy-builder
q3map2: accept -bsp stage option name without complaining
[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')
29                                 sysctl -n hw.ncpu
30                                 ;;
31                         'Darwin')
32                                 sysctl -n hw.logicalcpu \
33                                 || sysctl -n hw.ncpu
34                                 ;;
35                         'MSYS_NT-'*|'CYGWIN_NT-'*|'MINGW'*'_NT-'*)
36                                 if command -v 'wmic' >/dev/null
37                                 then
38                                         wmic cpu get NumberOfLogicalProcessors/Format:List \
39                                                 | grep -m1 '=' | cut -f2 -d'='
40                                 else
41                                         echo "${NUMBER_OF_PROCESSORS:-${_job_count}}"
42                                 fi
43                                 ;;
44                         *)
45                                 echo "${_job_count}"
46                                 ;;
47                 esac
48         fi
49 }
50
51 job_count="$(_nproc)" 2>/dev/null
52 job_count="${job_count:-${_job_count}}"
53
54 declare -a cmake_user_opts
55 while [ ! -z "${1}" ]
56 do
57         case "${1}" in
58         '-j'*)
59                 job_count="${1:2}"
60                 shift
61                 ;;
62         '--debug')
63                 install_target='install'
64                 build_type='Debug'
65                 shift
66                 ;;
67         *)
68         cmake_user_opts[${#cmake_user_opts[@]}]="${1}"
69         shift
70                 ;;
71         esac
72 done
73
74 declare -a fetch_submodules_cmd
75 for submodule_file in 'libs/crunch/inc/crn_decomp.h' \
76         'tools/unvanquished/daemonmap/tools/quake3/q3map2/main.c'
77 do
78         if ! [ -f "${project_source_dir}/${submodule_file}" ]
79         then
80                 fetch_submodules_cmd=(git -C "${project_source_dir}" submodule update --init --recursive)
81         fi
82 done
83
84 case "$(uname -s)" in
85         'Darwin')
86                 cmake_user_opts[${#cmake_user_opts[@]}]='-DBUILTIN_GTKGLEXT=ON -DBUILTIN_GTKTHEME_MOJAVE=ON'
87                 ;;
88 esac
89
90 set -x
91
92 "${fetch_submodules_cmd[@]}"
93
94 mkdir -pv "${build_dir}"
95 cd "${build_dir}"
96
97 cmake \
98         -G'Unix Makefiles' \
99         -D'CMAKE_INSTALL_PREFIX'="${install_dir}" \
100         -D'CMAKE_BUILD_TYPE'="${build_type}" \
101         "${cmake_user_opts[@]}" \
102         "${project_source_dir}"
103
104 cmake \
105         --build "${build_dir}" \
106         -- \
107         -j"${job_count}" \
108         'builtins'
109
110 cmake \
111         --build "${build_dir}" \
112         -- \
113         -j"${job_count}" \
114         "${install_target}"