From: Nicolas Boulenguez <nicolas@debian.org>
Date: Sun, 22 Jan 2023 20:52:35 +0100
Subject: pass settings to recursive Makes via the MAKE special variable

For example, the counter for '-jN' is global,
and assignments like CFLAGS=-g is passed to subprocesses.
---
 Makefile                | 10 +++++-----
 contrib/Makefile        |  8 ++++----
 contrib/norman/Makefile |  8 ++++----
 src/Makefile            | 29 +++++++++++++++--------------
 4 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/Makefile b/Makefile
index f2fd575..deb41cc 100644
--- a/Makefile
+++ b/Makefile
@@ -12,14 +12,14 @@ CIMSG=-f -m'standard checkin preparing to export version $(VERSION)'
 all:
 	@echo "You have no business running 'make' here; please look at the README file"
 	@exit 1
-source: ;	for i in src; do (cd $$i; make source); done
-www: ;		for i in src/xdoc examples; do (cd $$i; make www); done
+source: ;	$(MAKE) -C src $@
+www: ;		for i in src/xdoc examples; do $(MAKE) -C $$i $@; done
 
 clean:
-	for i in src examples contrib; do (cd $$i; make clean); done
+	for i in src examples contrib; do $(MAKE) -C $$i $@; done
 	rm -f nwsrcfilter *~ */*~
 clobber: clean
-	for i in src examples contrib; do (cd $$i; make clobber); done
+	for i in src examples contrib; do $(MAKE) -C $$i $@; done
 
 DATE:
 	(./echo -n "Version $(VERSION) of "; date) > DATE
@@ -61,6 +61,6 @@ emacscheck:
 	diff src/elisp/noweb-mode.el $(HOME)/emacs/noweb-mode.el
 
 checkin:
-	(cd src; make "CINAME=$(CINAME)" "CIMSG=$(CIMSG)" checkin)
+	$(MAKE) -C src "CINAME=$(CINAME)" "CIMSG=$(CIMSG)" $@
 
 
diff --git a/contrib/Makefile b/contrib/Makefile
index 0e048da..2e15bad 100644
--- a/contrib/Makefile
+++ b/contrib/Makefile
@@ -5,9 +5,9 @@ DIRS=davelove jonkrom leew norman
 
 # don't do kostas; it requires gnu make (ugh)
 
-all: ;	for i in $(DIRS); do (cd $$i; make ICONC=$(ICONC) all); done
-install: ;	for i in $(DIRS); do (cd $$i; make LIB=$(LIB) BIN=$(BIN) install); done
-source: ;	for i in $(DIRS); do (cd $$i; make source); done
-clean: ;	for i in $(DIRS); do (cd $$i; make clean); done
+all: ;	for i in $(DIRS); do $(MAKE) -C $$i ICONC=$(ICONC) $@; done
+install: ;	for i in $(DIRS); do $(MAKE) -C $$i LIB=$(LIB) BIN=$(BIN) $@; done
+source: ;	for i in $(DIRS); do $(MAKE) -C $$i $@; done
+clean: ;	for i in $(DIRS); do $(MAKE) -C $$i $@; done
 clobber: clean
 
diff --git a/contrib/norman/Makefile b/contrib/norman/Makefile
index 471f71e..c4f058a 100644
--- a/contrib/norman/Makefile
+++ b/contrib/norman/Makefile
@@ -1,10 +1,10 @@
 LIB=/dev/null	# to be overridden
 DIRS=numarkup
 
-all: ;	for i in $(DIRS); do (cd $$i; make ICONC=$(ICONC) ICONT=$(ICONT) all); done
-install: ;	for i in $(DIRS); do (cd $$i; make LIB=$(LIB) BIN=$(BIN) install); done
-source: ;	for i in $(DIRS); do (cd $$i; make source); done
-clean: ;	for i in $(DIRS); do (cd $$i; make clean); done
+all: ;	for i in $(DIRS); do $(MAKE) -C $$i ICONC=$(ICONC) ICONT=$(ICONT) $@; done
+install: ;	for i in $(DIRS); do $(MAKE) -C $$i LIB=$(LIB) BIN=$(BIN) $@; done
+source: ;	for i in $(DIRS); do $(MAKE) -C $$i $@; done
+clean: ;	for i in $(DIRS); do $(MAKE) -C $$i $@; done
 iconlib:	# cheap hack for slackmake
 	true
 
diff --git a/src/Makefile b/src/Makefile
index d3d6e10..609b82a 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -45,9 +45,9 @@ LIBNAME=$(LIB)
 TEXNAME=$(TEXINPUTS)
 
 all: 
-	cd c; make "CC=$(CC)" "CFLAGS=$(CFLAGS)" all 
-	for i in shell lib xdoc tex; do (cd $$i; make all); done
-	cd $(LIBSRC); make "ICONT=$(ICONT)" "ICONC=$(ICONC)" all
+	$(MAKE) -C c "CC=$(CC)" "CFLAGS=$(CFLAGS)" $@
+	for i in shell lib xdoc tex; do $(MAKE) -C $$i $@; done
+	$(MAKE) -C $(LIBSRC) "ICONT=$(ICONT)" "ICONC=$(ICONC)" $@
 
 FAQ: FAQ.html
 	sleep 1; html2ascii FAQ.html > FAQ
@@ -104,13 +104,13 @@ uninstall-shell:
 install-code: install-shell
 	mkdir -p $(DESTDIR)$(BIN) $(DESTDIR)$(LIB)
 	$(INSTALL_PROGRAM) -s c/nt c/markup c/mnt c/finduses c/nwmktemp $(DESTDIR)$(LIB)
-	cd $(LIBSRC); make ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) install
-	cd lib; make LIB=$(LIB) install
+	$(MAKE) -C $(LIBSRC) ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) install
+	$(MAKE) -C lib LIB=$(LIB) install
 
 uninstall-code: uninstall-shell
 	rm -f $(LIB)/nt $(LIB)/markup $(LIB)/mnt $(LIB)/finduses 
-	cd $(LIBSRC); make ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) uninstall
-	cd lib; make LIB=$(LIB) uninstall
+	$(MAKE) -C $(LIBSRC) ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) uninstall
+	$(MAKE) -C lib LIB=$(LIB) uninstall
 install-man:
 	mkdir -p $(DESTDIR)$(MAN) $(DESTDIR)$(MANDIR) $(DESTDIR)$(MAN7DIR)
 	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/cpif.1 > $(DESTDIR)$(MANDIR)/cpif.$(MANEXT)
@@ -192,26 +192,27 @@ install-elisp:
 uninstall-elisp:
 	rm -f $(ELISP)/noweb-mode.el || true
 checkin:
-	for i in lib tex xdoc; do (cd $$i; make "CINAME=$(CINAME)" "CIMSG=$(CIMSG)" checkin); done
+	for i in lib tex xdoc; do $(MAKE) -C $$i "CINAME=$(CINAME)" "CIMSG=$(CIMSG)" $@; done
 	for i in c icon awk; do (cd $$i; ci -l $(CINAME) $(CIMSG) *.nw Makefile); done
 	(cd elisp; ci -l $(CINAME) $(CIMSG) *.el)
 	ci -l $(CINAME) $(CIMSG) Makefile.nw INSTALL INSTALL.DOS README FAQ COPYRIGHT nwmake *.nw
 
 source: FAQ
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make CPIF=">" source); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i CPIF=">" $@; done
 	sleep 1
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make touch); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i touch; done
+
 touch:
 	touch FAQ
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make touch); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i $@; done
 boot:
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make boot); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i boot; done
 clean:
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make clean); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i $@; done
 	rm -f nwsrcfilter *~ */*~
 
 clobber: clean
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make clobber); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) $@ -C $$i; done
 
 Makefile: Makefile.nw
 	chmod +w Makefile
