]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - easy-builder
Merge branch 'NateEag-master-patch-12920' into 'master'
[xonotic/netradiant.git] / easy-builder
index b360b2dba4d67630f3a6d43b4a4f1c109f0885fd..47020d2d2d4892c4c0c8151beea9765bc4eccdbb 100755 (executable)
@@ -14,56 +14,64 @@ install_dir="${project_source_dir}/install${SUBDIR:+/${SUBDIR}}"
 install_target='install/strip'
 build_type='Release'
 
-declare -a cmake_opts
 case "$(uname -s)" in
+       # Stripping is known to make non-PIE Linux netradiant binary unusable.
+       # Maybe that's related to the way we patch rpath?
+       #
+       # Building NetRadiant as non-PIE is required because of
+       # a mistake in the mimetype-library that prevents users
+       # to run the application from file managers on Linux.
+       #
+       # See: https://gitlab.freedesktop.org/xdg/shared-mime-info/-/issues/11
+       #
+       # After installation it's possible to strip manually all binaries except
+       # the netradiant one.
        'Linux')
-               nproc='egrep "^processor" /proc/cpuinfo | wc -l'
+               install_target='install'
                ;;
+       # Stripping is known to make FreeBSD binaries unusable.
+       # Maybe that's related to the way we patch rpath?
        'FreeBSD')
-               nproc='sysctl -n hw.ncpu'
-
-               if [ -f "$(ls '/usr/local/bin/g++'* | sort | tail -n1)" ]
-               then
-                       gcc_version="$(ls '/usr/local/bin/g++'* | sort | tail -n1 | sed -e 's/.*[^0-9]\([0-9][0-9]*\)$/\1/')"
-                       cmake_opts[${#cmake_opts[@]}]="-DCMAKE_C_COMPILER=/usr/local/bin/gcc${gcc_version}"
-                       cmake_opts[${#cmake_opts[@]}]="-DCMAKE_CXX_COMPILER=/usr/local/bin/g++${gcc_version}"
-               else
-                       printf "WARNING: GCC is recommended: if build fails, install GCC and retry\n" >&2
-               fi
-               ;;
-       'Darwin')
-               nproc='sysctl -n hw.ncpu'
-
-               if [ -f "$(ls '/usr/local/bin/g++-'* | sort | tail -n1)" ]
-               then
-                       gcc_version="$(ls '/usr/local/bin/g++-'* | sort | tail -n1 | sed -e 's/.*[^0-9]\([0-9][0-9]*\)$/\1/')"
-                       cmake_opts[${#cmake_opts[@]}]="-DCMAKE_C_COMPILER=/usr/local/bin/gcc-${gcc_version}"
-                       cmake_opts[${#cmake_opts[@]}]="-DCMAKE_CXX_COMPILER=/usr/local/bin/g++-${gcc_version}"
-               else
-                       printf "WARNING: GCC is recommended: if build fails, install GCC and retry\n" >&2
-               fi
-               ;;
-       'MSYS_NT-'*)
-               nproc='echo "${NUMBER_OF_PROCESSORS}"'
-               ;;
-       'CYGWIN_NT-'*|'MINGW'*'_NT-'*)
-               nproc='echo "${NUMBER_OF_PROCESSORS}"'
-               printf "WARNING: system is not tested: if build fails, use MSYS2 instead\n" >&2
-               ;;
-       *)
-               nproc='true'
-               printf "WARNING: system is not tested\n" >&2
+               install_target='install'
                ;;
 esac
 
-if command -v 'nproc' >/dev/null
-then
-       job_count="$(nproc)"
-else
-       job_count="$(sh -c "${nproc}")"
-fi
-
-job_count="${job_count:-4}"
+_job_count=4
+
+_nproc () {
+       if command -v 'nproc' >/dev/null
+       then
+               nproc
+       else
+               case "$(uname -s)" in
+                       'Linux')
+                               egrep "^processor" /proc/cpuinfo | wc -l
+                               ;;
+                       'FreeBSD')
+                               sysctl -n hw.ncpu
+                               ;;
+                       'Darwin')
+                               sysctl -n hw.logicalcpu \
+                               || sysctl -n hw.ncpu
+                               ;;
+                       'MSYS_NT-'*|'CYGWIN_NT-'*|'MINGW'*'_NT-'*)
+                               if command -v 'wmic' >/dev/null
+                               then
+                                       wmic cpu get NumberOfLogicalProcessors/Format:List \
+                                               | grep -m1 '=' | cut -f2 -d'='
+                               else
+                                       echo "${NUMBER_OF_PROCESSORS:-${_job_count}}"
+                               fi
+                               ;;
+                       *)
+                               echo "${_job_count}"
+                               ;;
+               esac
+       fi
+}
+
+job_count="$(_nproc)" 2>/dev/null
+job_count="${job_count:-${_job_count}}"
 
 declare -a cmake_user_opts
 while [ ! -z "${1}" ]
@@ -86,27 +94,73 @@ do
 done
 
 declare -a fetch_submodules_cmd
-if ! [ -f "${project_source_dir}/libs/crunch/inc/crn_decomp.h" ]
-then
-       fetch_submodules_cmd=(git -C "${project_source_dir}" submodule update --init --recursive)
-fi
+for submodule_file in 'libs/crunch/inc/crn_decomp.h'
+do
+       if ! [ -f "${project_source_dir}/${submodule_file}" ]
+       then
+               fetch_submodules_cmd=(git -C "${project_source_dir}" submodule update --init --recursive)
+       fi
+done
+
+case "$(uname -s)" in
+       'Darwin')
+               cmake_user_opts[${#cmake_user_opts[@]}]='-DBUILTIN_GTKGLEXT=ON -DBUILTIN_GTKTHEME_MOJAVE=ON'
+               ;;
+esac
+
+task_enter_build_dir () {
+       sync
+       mkdir -pv "${build_dir}"
+       cd "${build_dir}"
+}
+
+task_fetch_submodules () {
+       sync
+       "${fetch_submodules_cmd[@]}"
+}
+
+task_configure () {
+       sync
+       cmake \
+               -G'Unix Makefiles' \
+               -D'CMAKE_INSTALL_PREFIX'="${install_dir}" \
+               -D'CMAKE_BUILD_TYPE'="${build_type}" \
+               "${cmake_user_opts[@]}" \
+               "${project_source_dir}"
+}
+
+task_build_builtins () {
+       sync
+       make -j"${job_count}" builtins
+}
+
+task_discover_builtins () {
+       sync
+       cmake "${project_source_dir}"
+}
+
+task_build () {
+       sync
+       make -j"${job_count}"
+}
+
+task_install () {
+       sync
+       make "${install_target}"
+}
 
 set -x
 
-"${fetch_submodules_cmd[@]}"
-
-cmake \
-       -G'Unix Makefiles' \
-       -S"${project_source_dir}" \
-       -B"${build_dir}" \
-       -D'CMAKE_INSTALL_PREFIX'="${install_dir}" \
-       -D'CMAKE_BUILD_TYPE'="${build_type}" \
-       "${cmake_opts[@]}" \
-       "${cmake_user_opts[@]}" \
-       "${project_source_dir}"
-
-cmake \
-       --build "${build_dir}" \
-       -- \
-       -j"${job_count}" \
-       "${install_target}"
+task_enter_build_dir
+
+task_fetch_submodules
+
+task_configure
+
+task_build_builtins
+
+task_discover_builtins
+
+task_build
+
+task_install