[m-rev.] for review: Defer SHARED_LIBS assignment in ml script.

Peter Wang novalazy at gmail.com
Thu Dec 14 14:27:16 AEDT 2023


scripts/ml.in:
    Assign SHARED_LIBS only when it will actually be used,
    as the default value of SHARED_LIBS set by configure
    may invoke "gcc -print-libgcc-file-name" in a command substitution.

diff --git a/scripts/ml.in b/scripts/ml.in
index 6f0427fbd..730c70dba 100644
--- a/scripts/ml.in
+++ b/scripts/ml.in
@@ -61,9 +61,11 @@ LDFLAGS_FOR_SANITIZERS="@LDFLAGS_FOR_SANITIZERS@"
 
 TMPDIR=${TMPDIR=/tmp}
 MATH_LIB=${MERCURY_MATH_LIB="@MATH_LIB@"}
-# Note: the setting of SHARED_LIBS needs to come after the setting of MATH_LIB,
-# since @SHARED_LIBS_SH@ may refer to ${MATH_LIB}.
-SHARED_LIBS=${MERCURY_SHARED_LIBS="@SHARED_LIBS_SH@"}
+# Defer assigning SHARED_LIBS until it is actually required,
+# as SHARED_LIBS_SH may invoke gcc in a command substitution.
+set_shared_libs() {
+    SHARED_LIBS=${MERCURY_SHARED_LIBS="@SHARED_LIBS_SH@"}
+}
 
 # Set the MACOSX_DEPLOYMENT_TARGET environment variable if needed.
 @SET_MACOSX_DEPLOYMENT_TARGET@
@@ -424,6 +426,7 @@ case "${make_shared_lib}" in
         esac
         RPATH_OPT="${SHLIB_RPATH_OPT}"
         RPATH_SEP="${SHLIB_RPATH_SEP}"
+        set_shared_libs
         STDLIBS="${SHARED_LIBS} ${THREAD_LIBS}"
         case "${trace}" in
             true)
-- 
2.42.0



More information about the reviews mailing list