File fix2343a.patch of Package rpm
diff --git a/build/build.c b/build/build.c
index 44794477c..88ad2d48a 100644
--- a/build/build.c
+++ b/build/build.c
@@ -11,6 +11,9 @@
#include <sys/socket.h>
#include <netdb.h>
#include <time.h>
+#ifdef ENABLE_OPENMP
+#include <omp.h>
+#endif
#include <rpm/rpmlog.h>
#include <rpm/rpmfileutil.h>
@@ -302,6 +305,28 @@ static rpmRC buildSpec(rpmts ts, BTA_t buildArgs, rpmSpec spec, int what)
StringBuf sink = NULL;
StringBuf *sbp = rpmIsVerbose() ? NULL : &sink;
+#ifdef ENABLE_OPENMP
+ /* Set number of OMP threads centrally */
+ int prev_threads = omp_get_num_threads();
+ int nthreads = rpmExpandNumeric("%{?_smp_build_nthreads}");
+ int nthreads_max = rpmExpandNumeric("%{?_smp_nthreads_max}");
+ if (nthreads <= 0)
+ nthreads = omp_get_max_threads();
+ if (nthreads_max > 0 && nthreads > nthreads_max)
+ nthreads = nthreads_max;
+#if __WORDSIZE == 32
+ /* On 32bit platforms, address space shortage is an issue. Play safe. */
+ int platlimit = 4;
+ if (nthreads > platlimit) {
+ nthreads = platlimit;
+ rpmlog(RPMLOG_DEBUG,
+ "limiting number of threads to %d due to platform\n", platlimit);
+ }
+#endif
+ if (nthreads > 0)
+ omp_set_num_threads(nthreads);
+#endif
+
if (rpmExpandNumeric("%{?source_date_epoch_from_changelog}") &&
getenv("SOURCE_DATE_EPOCH") == NULL) {
/* Use date of first (== latest) changelog entry */
@@ -443,6 +468,9 @@ static rpmRC buildSpec(rpmts ts, BTA_t buildArgs, rpmSpec spec, int what)
(void) unlink(spec->specFile);
exit:
+#if WITH_OPENMP
+ omp_set_num_threads(prev_threads);
+#endif
freeStringBuf(sink);
free(cookie);
spec->rootDir = NULL;
diff --git a/build/parseSpec.c b/build/parseSpec.c
index 18c480d6e..7a0c383ca 100644
--- a/build/parseSpec.c
+++ b/build/parseSpec.c
@@ -6,9 +6,6 @@
#include "system.h"
#include <errno.h>
-#ifdef ENABLE_OPENMP
-#include <omp.h>
-#endif
#ifdef HAVE_ICONV
#include <iconv.h>
#endif
@@ -1056,27 +1053,6 @@ static rpmSpec parseSpec(const char *specFile, rpmSpecFlags flags,
}
}
-#ifdef ENABLE_OPENMP
- /* Set number of OMP threads centrally */
- int nthreads = rpmExpandNumeric("%{?_smp_build_nthreads}");
- int nthreads_max = rpmExpandNumeric("%{?_smp_nthreads_max}");
- if (nthreads <= 0)
- nthreads = omp_get_max_threads();
- if (nthreads_max > 0 && nthreads > nthreads_max)
- nthreads = nthreads_max;
-#if __WORDSIZE == 32
- /* On 32bit platforms, address space shortage is an issue. Play safe. */
- int platlimit = 4;
- if (nthreads > platlimit) {
- nthreads = platlimit;
- rpmlog(RPMLOG_DEBUG,
- "limiting number of threads to %d due to platform\n", platlimit);
- }
-#endif
- if (nthreads > 0)
- omp_set_num_threads(nthreads);
-#endif
-
if (spec->clean == NULL) {
char *body = rpmExpand("%{?buildroot: %{__rm} -rf %{buildroot}}", NULL);
spec->clean = newStringBuf();
diff --git a/macros.in b/macros.in
index 0e801ff29..045156d9f 100644
--- a/macros.in
+++ b/macros.in
@@ -699,6 +699,22 @@ package or when debugging this package.\
# Macro to fix broken permissions in sources
%_fixperms %{__chmod} -Rf a+rX,u+w,g-w,o-w
+# Maximum number of CPU's to use when building, 0 for unlimited.
+#%_smp_ncpus_max 0
+
+%_smp_build_ncpus %([ -z "$RPM_BUILD_NCPUS" ] \\\
+ && RPM_BUILD_NCPUS="%{getncpus}"; \\\
+ ncpus_max=%{?_smp_ncpus_max}; \\\
+ if [ -n "$ncpus_max" ] && [ "$ncpus_max" -gt 0 ] && [ "$RPM_BUILD_NCPUS" -gt "$ncpus_max" ]; then RPM_BUILD_NCPUS="$ncpus_max"; fi; \\\
+ echo "$RPM_BUILD_NCPUS";)
+
+%_smp_mflags -j${RPM_BUILD_NCPUS}
+
+# Maximum number of threads to use when building, 0 for unlimited
+#%_smp_nthreads_max 0
+
+%_smp_build_nthreads %{_smp_build_ncpus}
+
#==============================================================================
# ---- Scriptlet template templates.
# Global defaults used for building scriptlet templates.
diff --git a/platform.in b/platform.in
index 71496b8a6..65410807f 100644
--- a/platform.in
+++ b/platform.in
@@ -48,22 +48,6 @@
%_defaultdocdir %{_datadir}/doc
-# Maximum number of CPU's to use when building, 0 for unlimited.
-#%_smp_ncpus_max 0
-
-%_smp_build_ncpus %([ -z "$RPM_BUILD_NCPUS" ] \\\
- && RPM_BUILD_NCPUS="%{getncpus}"; \\\
- ncpus_max=%{?_smp_ncpus_max}; \\\
- if [ -n "$ncpus_max" ] && [ "$ncpus_max" -gt 0 ] && [ "$RPM_BUILD_NCPUS" -gt "$ncpus_max" ]; then RPM_BUILD_NCPUS="$ncpus_max"; fi; \\\
- echo "$RPM_BUILD_NCPUS";)
-
-%_smp_mflags -j%{_smp_build_ncpus}
-
-# Maximum number of threads to use when building, 0 for unlimited
-#%_smp_nthreads_max 0
-
-%_smp_build_nthreads %{_smp_build_ncpus}
-
#==============================================================================
# ---- Build policy macros.
#