]> git.xonotic.org Git - xonotic/netradiant.git/blob - easy-builder
q3map2: pad with zero, not with null pointers, ref #160
[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 job_count='4'
12 if command -v nproc >/dev/null
13 then
14         job_count="$(nproc)"
15 fi
16
17 build_dir="${project_source_dir}/build${SUBDIR:+/${SUBDIR}}"
18 install_dir="${project_source_dir}/install${SUBDIR:+/${SUBDIR}}"
19
20 build_type='Release'
21
22 cmake_user_opts=''
23 while [ ! -z ${1} ]
24 do
25     case "${1}" in
26     '-j'*)
27         job_count="${1:2}"
28         shift
29         ;;
30     '--debug')
31         build_type='Debug'
32         shift
33         ;;
34     *)
35         cmake_user_opts+=" ${1}"
36         shift
37         ;;
38     esac
39 done
40
41 cmake_opts=''
42 case "$(uname -s)" in
43         'Linux')
44                 # no tweak required
45                 ;;
46         'FreeBSD')
47                 if [ -f "$(ls '/usr/local/bin/g++'* | sort | tail -n1)" ]
48                 then
49                         gcc_version="$(ls '/usr/local/bin/g++'* | sort | tail -n1 | sed -e 's/.*[^0-9]\([0-9][0-9]*\)$/\1/')"
50                         cmake_opts+=" -DCMAKE_C_COMPILER=/usr/local/bin/gcc${gcc_version}"
51                         cmake_opts+=" -DCMAKE_CXX_COMPILER=/usr/local/bin/g++${gcc_version}"
52                 else
53                         printf "WARNING: GCC is recommended: if build fails, install GCC and retry\n" >&2
54                 fi
55                 ;;
56         'Darwin')
57                 if [ -f "$(ls '/usr/local/bin/g++-'* | sort | tail -n1)" ]
58                 then
59                         gcc_version="$(ls '/usr/local/bin/g++-'* | sort | tail -n1 | sed -e 's/.*[^0-9]\([0-9][0-9]*\)$/\1/')"
60                         cmake_opts+=" -DCMAKE_C_COMPILER=/usr/local/bin/gcc-${gcc_version}"
61                         cmake_opts+=" -DCMAKE_CXX_COMPILER=/usr/local/bin/g++-${gcc_version}"
62                 else
63                         printf "WARNING: GCC is recommended: if build fails, install GCC and retry\n" >&2
64                 fi
65                 ;;
66         'MSYS_NT-'*)
67                 # no tweak required
68                 ;;
69         'CYGWIN_NT-'*|'MINGW'*'_NT-'*)
70                 printf "WARNING: system is not tested: if build fails, use MSYS2 instead\n" >&2
71                 ;;
72         *)
73                 printf "WARNING: system is not tested\n" >&2
74                 ;;
75 esac
76
77 fetch_submodules_cmd=''
78 if ! [ -f "${project_source_dir}/libs/crunch/inc/crn_decomp.h" ]
79 then
80         fetch_submodules_cmd='git submodule update --init --recursive'
81 fi
82
83 set -x
84
85 cd "${project_source_dir}"
86
87 ${fetch_submodules_cmd}
88
89 cmake \
90         -G'Unix Makefiles' \
91         -H'.' \
92         -B"${build_dir}" \
93         -D'CMAKE_INSTALL_PREFIX'="${install_dir}" \
94         -D'CMAKE_BUILD_TYPE'="${build_type}" \
95         ${cmake_opts} \
96         ${cmake_user_opts} \
97         ${@}
98
99 cmake \
100         --build "${build_dir}" \
101         -- \
102         -j"${job_count}" \
103         install