redhat-rpm-config/macros.build-constraints
Michel Alexandre Salim dbb1278523 Add macros.build-constraints
Keep the misc macros in alphabetical order

Signed-off-by: Michel Alexandre Salim <salimma@fedoraproject.org>
2021-07-24 14:58:08 -07:00

11 lines
552 B
Plaintext

# Macros to constrain resource use during the build process
# m: memory limit in MBs per core; default is 1024
%limit_build(m:) \
_mem_per_process="%{-m:%{-m*}}%{!-m:1024}" \
_max_mem=$(awk '/MemTotal/ { print $2 }' /proc/meminfo) \
_max_jobs="$(($_max_mem / ($_mem_per_process * 1024)))" \
_cur_max_jobs="%{_smp_build_ncpus}" \
test "${_cur_max_jobs}" -gt "${_max_jobs}" && _cur_max_jobs="${_max_jobs}" && echo "Warning: Reducing build parallelism to -j${_max_jobs} because of memory limits" \
%global _smp_build_ncpus "${_cur_max_jobs}"