| 1 | #! /usr/bin/envscip-shell filesystem . . `/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 "$(dirnamescip-shell system . . dirname. "${BASH_SOURCE[0]}")" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 && pwdscip-shell system . . 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 | case "$(unamescip-shell system . . uname. -s)" in |
| 18 | # Stripping is known to make non-PIE Linux netradiant binary unusable. |
| 19 | # Maybe that's related to the way we patch rpath? |
| 20 | # |
| 21 | # Building NetRadiant as non-PIE is required because of |
| 22 | # a mistake in the mimetype-library that prevents users |
| 23 | # to run the application from file managers on Linux. |
| 24 | # |
| 25 | # See: https://gitlab.freedesktop.org/xdg/shared-mime-info/-/issues/11 |
| 26 | # |
| 27 | # After installation it's possible to strip manually all binaries except |
| 28 | # the netradiant one. |
| 29 | 'Linux') |
| 30 | install_target='install' |
| 31 | ;; |
| 32 | # Stripping is known to make FreeBSD binaries unusable. |
| 33 | # Maybe that's related to the way we patch rpath? |
| 34 | 'FreeBSD') |
| 35 | install_target='install' |
| 36 | ;; |
| 37 | esac |
| 38 | |
| 39 | _job_count=4 |
| 40 | |
| 41 | _nprocscip-shell shell shell-project 0.0.0 _nproc(). () { |
| 42 | if command -v 'nproc' >/dev/nullscip-shell filesystem . . `/dev/null`. |
| 43 | then |
| 44 | nprocscip-shell system . . nproc. |
| 45 | else |
| 46 | case "$(unamescip-shell system . . uname. -s)" in |
| 47 | 'Linux') |
| 48 | egrepscip-shell system . . egrep. "^processor" /proc/cpuinfoscip-shell filesystem . . `/proc/cpuinfo`. | wcscip-shell system . . wc. -l |
| 49 | ;; |
| 50 | 'FreeBSD') |
| 51 | sysctlscip-shell system . . sysctl. -n hw.ncpu |
| 52 | ;; |
| 53 | 'Darwin') |
| 54 | sysctlscip-shell system . . sysctl. -n hw.logicalcpu \ |
| 55 | || sysctlscip-shell system . . sysctl. -n hw.ncpu |
| 56 | ;; |
| 57 | 'MSYS_NT-'*|'CYGWIN_NT-'*|'MINGW'*'_NT-'*) |
| 58 | if command -v 'wmic' >/dev/nullscip-shell filesystem . . `/dev/null`. |
| 59 | then |
| 60 | wmic cpu get NumberOfLogicalProcessors/Format:List \ |
| 61 | | grepscip-shell system . . grep. -m1 '=' | cutscip-shell system . . cut. -f2 -d'=' |
| 62 | else |
| 63 | echoscip-shell system . . echo. "${NUMBER_OF_PROCESSORS:-${_job_count}}" |
| 64 | fi |
| 65 | ;; |
| 66 | *) |
| 67 | echoscip-shell system . . echo. "${_job_count}" |
| 68 | ;; |
| 69 | esac |
| 70 | fi |
| 71 | } |
| 72 | |
| 73 | job_count="$(_nprocscip-shell shell shell-project 0.0.0 _nproc().)" 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 74 | job_count="${job_count:-${_job_count}}" |
| 75 | |
| 76 | declare -a cmake_user_opts |
| 77 | while [scip-shell system . . `[`. ! -z "${1}" ] |
| 78 | do |
| 79 | case "${1}" in |
| 80 | '-j'*) |
| 81 | job_count="${1:2}" |
| 82 | shift |
| 83 | ;; |
| 84 | '--debug') |
| 85 | install_target='install' |
| 86 | build_type='Debug' |
| 87 | shift |
| 88 | ;; |
| 89 | *) |
| 90 | cmake_user_opts[${#cmake_user_opts[@]}]="${1}" |
| 91 | shift |
| 92 | ;; |
| 93 | esac |
| 94 | done |
| 95 | |
| 96 | case "$(unamescip-shell system . . uname. -s)" in |
| 97 | 'Darwin') |
| 98 | cmake_user_opts[${#cmake_user_opts[@]}]='-DBUILTIN_GTKGLEXT=ON -DBUILTIN_GTKTHEME_MOJAVE=ON' |
| 99 | ;; |
| 100 | esac |
| 101 | |
| 102 | task_enter_build_dirscip-shell shell shell-project 0.0.0 task_enter_build_dir(). () { |
| 103 | syncscip-shell system . . sync. |
| 104 | mkdirscip-shell system . . mkdir. -pv "${build_dir}" |
| 105 | cd "${build_dir}" |
| 106 | } |
| 107 | |
| 108 | task_configurescip-shell shell shell-project 0.0.0 task_configure(). () { |
| 109 | syncscip-shell system . . sync. |
| 110 | cmakescip-shell system . . cmake. \ |
| 111 | -G'Unix Makefiles' \ |
| 112 | -D'CMAKE_INSTALL_PREFIX'="${install_dir}" \ |
| 113 | -D'CMAKE_BUILD_TYPE'="${build_type}" \ |
| 114 | "${cmake_user_opts[@]}" \ |
| 115 | "${project_source_dir}" |
| 116 | } |
| 117 | |
| 118 | task_build_builtinsscip-shell shell shell-project 0.0.0 task_build_builtins(). () { |
| 119 | syncscip-shell system . . sync. |
| 120 | makescip-shell system . . make. -j"${job_count}" builtins |
| 121 | } |
| 122 | |
| 123 | task_discover_builtinsscip-shell shell shell-project 0.0.0 task_discover_builtins(). () { |
| 124 | syncscip-shell system . . sync. |
| 125 | cmakescip-shell system . . cmake. "${project_source_dir}" |
| 126 | } |
| 127 | |
| 128 | task_buildscip-shell shell shell-project 0.0.0 task_build(). () { |
| 129 | syncscip-shell system . . sync. |
| 130 | makescip-shell system . . make. -j"${job_count}" |
| 131 | } |
| 132 | |
| 133 | task_installscip-shell shell shell-project 0.0.0 task_install(). () { |
| 134 | syncscip-shell system . . sync. |
| 135 | makescip-shell system . . make. "${install_target}" |
| 136 | } |
| 137 | |
| 138 | set -x |
| 139 | |
| 140 | task_enter_build_dirscip-shell shell shell-project 0.0.0 task_enter_build_dir(). |
| 141 | |
| 142 | task_configurescip-shell shell shell-project 0.0.0 task_configure(). |
| 143 | |
| 144 | task_build_builtinsscip-shell shell shell-project 0.0.0 task_build_builtins(). |
| 145 | |
| 146 | task_discover_builtinsscip-shell shell shell-project 0.0.0 task_discover_builtins(). |
| 147 | |
| 148 | task_buildscip-shell shell shell-project 0.0.0 task_build(). |
| 149 | |
| 150 | task_installscip-shell shell shell-project 0.0.0 task_install(). |