[m-rev.] for review: Ensure make does not try to run cross-compiled binaries.

Peter Wang novalazy at gmail.com
Thu Oct 28 13:29:33 AEDT 2021


When cross-compiling, `make' must not find cross-compiled binaries in
the workspace and try to execute them. For example, the problem arises
when cross-compiling for Linux/aarch64 from Linux/x86-64. `make' would
find e.g. util/mkinit (for an incompatible platform) and try to run it.

The problem did not arise in the special (but common) case of
cross-compiling for Windows on a Linux host: the Windows binaries would
be given a .exe extension, and `make' on Linux would not try to run
<foo>.exe anyway.

Mmakefile:
    Exclude util and mfilterjavac from the PATH when cross-compiling.

diff --git a/Mmakefile b/Mmakefile
index fe554cbc2..06038f510 100644
--- a/Mmakefile
+++ b/Mmakefile
@@ -53,18 +53,28 @@ SUBDIRS = \
 
 MMAKEFLAGS =
 
-# We include ../../mfilterjavac in this path because $(SUBDIR_MMAKE) is used
-# from the grade install directories, and we need mfilterjavac in our path
-# when executing in install_grade_dir.java/library and others.
+ifneq ($(CROSS_COMPILING),yes)
+	# We include ../../mfilterjavac in this path because $(SUBDIR_MMAKE) is
+	# used from the grade install directories, and we need mfilterjavac in
+	# our path when executing in install_grade_dir.java/library and others.
+	SUBDIR_MMAKE_PATH=../scripts:../util:../mfilterjavac:../../mfilterjavac:$$PATH
+	SUBSUBDIR_MMAKE_PATH=../../scripts:../../util:../../mfilterjavac:$$PATH
+else
+	# When cross-compiling, exclude util and mfilterjavac from the PATH so
+	# mmake does not try to execute binaries from those directories.
+	SUBDIR_MMAKE_PATH=../scripts:$$PATH
+	SUBSUBDIR_MMAKE_PATH=../../scripts:$$PATH
+endif
+
 SUBDIR_MMAKE = \
-	PATH=../scripts:../util:../mfilterjavac:../../mfilterjavac:$$PATH \
+	PATH=$(SUBDIR_MMAKE_PATH) \
 	MMAKE_VPATH=. \
 	MMAKE_DIR=../scripts \
 	DESTDIR=$(DESTDIR) \
 	../scripts/mmake $(MMAKEFLAGS)
 
 SUBSUBDIR_MMAKE = \
-	PATH=../../scripts:../../util:../../mfilterjavac:$$PATH \
+	PATH=$(SUBDIR_MMAKE_PATH) \
 	MMAKE_VPATH=. \
 	MMAKE_DIR=../../scripts \
 	DESTDIR=$(DESTDIR) \
-- 
2.33.1



More information about the reviews mailing list