# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../make/make-3.82-0008-parallel-remake.patch
# Copyright (C) 2012 The OpenSDE Project
#
# More information can be found in the files COPYING and README.
#
# This patch file is dual-licensed. It is available under the license the
# patched project is licensed under, as long as it is an OpenSource license
# as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
# of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# --- SDE-COPYRIGHT-NOTE-END ---

From 4c7a70c558579d5b42d54fde1397c121d3df31c4 Mon Sep 17 00:00:00 2001
From: Christian Wiese <chris@opensde.org>
Date: Mon, 22 Oct 2012 18:06:56 +0200
Subject: [PATCH] parallel remake

ChangeLog:

2011-09-18  Paul Smith  <psmith@gnu.org>

       * main.c (main): If we're re-exec'ing and we're the master make,
       then restore the job_slots value so it goes back into MAKEFLAGS
       properly.  See Savannah bug #33873.

test/ChangeLog:

2011-09-18  Paul Smith  <psmith@gnu.org>

       * scripts/features/parallelism: On re-exec make sure we preserve
       the value of MAKEFLAGS when necessary.  See Savannah bug #33873.
---
 main.c                             |    8 +++++---
 tests/scripts/features/parallelism |   17 +++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/main.c b/main.c
index 782b0de..68587ae 100644
--- a/main.c
+++ b/main.c
@@ -2088,6 +2088,11 @@ main (int argc, char **argv, char **envp)
 
           ++restarts;
 
+          /* If we're re-exec'ing the first make, put back the number of
+             job slots so define_makefiles() will get it right.  */
+          if (master_job_slots)
+            job_slots = master_job_slots;
+
           /* Reset makeflags in case they were changed.  */
           {
             const char *pv = define_makeflags (1, 1);
@@ -2824,9 +2829,6 @@ define_makeflags (int all, int makefile)
 		       && (*(unsigned int *) cs->value_ptr ==
 			   *(unsigned int *) cs->noarg_value))
 		ADD_FLAG ("", 0); /* Optional value omitted; see below.  */
-	      else if (cs->c == 'j')
-		/* Special case for `-j'.  */
-		ADD_FLAG ("1", 1);
 	      else
 		{
 		  char *buf = alloca (30);
diff --git a/tests/scripts/features/parallelism b/tests/scripts/features/parallelism
index cc0f84f..6122412 100644
--- a/tests/scripts/features/parallelism
+++ b/tests/scripts/features/parallelism
@@ -164,6 +164,23 @@ inc.mk:
 
 rmfiles('inc.mk');
 
+# TEST #11: Make sure -jN from MAKEFLAGS is processed even when we re-exec
+# See Savannah bug #33873
+
+$extraENV{MAKEFLAGS} = '-j4';
+
+run_make_test(q!
+things = thing1 thing2
+all: $(things)
+$(things):; @echo '$@ start'; sleep 1; echo '$@ end'
+-include inc.mk
+inc.mk: ; @touch $@
+!,
+              '', "thing1 start\nthing2 start\nthing1 end\nthing2 end\n");
+
+delete $extraENV{MAKEFLAGS};
+rmfiles('inc.mk');
+
 if ($all_tests) {
     # Implicit files aren't properly recreated during parallel builds
     # Savannah bug #26864
-- 
1.7.2.3