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