[m-rev.] for review: fix library installation with mmake and no symlinks

Julien Fischer jfischer at opturion.com
Mon Dec 29 00:58:33 AEDT 2025


For review by Zoltan.

I'm not sure if the proposed library method you were working on requires
a similar fix.

------------------------------

Fix library installation with mmake and no symlinks.

When installing various kinds of files (e.g .int*, .opt, .mh etc.) for
a library, mmake needs to account for the possibility that a user
of the library may enable --use-subdirs. The legacy library installation
method does this by creating symlinks from within the Mercury directory
back to the locations where the files actually are. On systems that do
not support symlinks (chiefly, non-Cygwin environments on Windows), we copy
the files in question into the appropriate spot under the Mercury
subdirectory.

For .mh files, copying into the Mercury subdirectory is done by the
.install_ints target. This is wrong, as the .mh files are not actually
installed by that target, but are instead installed by the .install_hdrs
target. In non-parallel builds this causes the installation to abort
because there are no .mh files to copy into the Mercury subdirectory.
In parallel builds, the effect is more insidious as some .mh files *can*
be installed by the time .install_ints gets around to copying them and
the copy operation will *not* fail; however, this can result in not
all of the .mh files being copied into the Mercury subdirectory.

The fix is to copy .mh files as part of the .install_hdrs target, not as
part of the .install_ints target.

compiler/generate_mmakefile_fragments.m:
    Do not attempt to symlink the Mercury/mhs directory or copy .mh files
    as part of the .install_ints target. Instead, do it as part of the
    .install_hdrs target.

Julien.

diff --git a/compiler/generate_mmakefile_fragments.m
b/compiler/generate_mmakefile_fragments.m
index 38769b91d..467899ea0 100644
--- a/compiler/generate_mmakefile_fragments.m
+++ b/compiler/generate_mmakefile_fragments.m
@@ -2045,7 +2045,7 @@
generate_dep_file_install_targets_legacy(ModuleName, DepsMap,
         "# The following is needed to support the `--use-subdirs' option.",
         "# We try using `$(LN_S)', but if that fails, then we just use",
         "# `$(INSTALL)'.",
-        "for ext in mh int int2 int3" ++
+        "for ext in int int2 int3" ++
             SpaceInt0Str ++ MaybeSpaceOptStr ++ MaybeSpaceTransOptStr ++
             MaybeSpaceDepStr ++ "; do \\",
         "\tdir=""$(INSTALL_INT_DIR)/Mercury/$${ext}s""; \\",
@@ -2129,7 +2129,19 @@
generate_dep_file_install_targets_legacy(ModuleName, DepsMap,
         ["for hdr in " ++ ModuleMakeVarNameMhs ++ "; do \\",
         "\t$(INSTALL) $$hdr $(INSTALL_INT_DIR); \\",
         "\t$(INSTALL) $$hdr $(INSTALL_INC_DIR); \\",
-        "done"],
+        "done",
+        "# The following is needed to support the `--use-subdirs' option.",
+        "# We try using `$(LN_S)', but if that fails, then we just use",
+        "# `$(INSTALL)'.",
+        "rm -rf $(INSTALL_INT_DIR)/Mercury/mhs",
+        "$(LN_S) .. $(INSTALL_INT_DIR)/Mercury/mhs || { \\",
+        "\t{ test -d $(INSTALL_INT_DIR)/Mercury/mhs || \\",
+        "\t\t$(INSTALL_MKDIR) \\",
+        "\t\t$(INSTALL_INT_DIR)/Mercury/mhs; \\",
+        "\t} && \\",
+        "\t$(INSTALL) $(INSTALL_INT_DIR)/*.mh \\",
+        "\t\t$(INSTALL_INT_DIR)/Mercury/mhs; \\",
+        "} || exit 1"],
     LibInstallHdrsMhsActions = LibInstallHdrsMhsActionsLegacy,
     MmakeRuleLibInstallHdrsMhs = mmake_simple_rule("install_lib_hdrs_mhs",
         mmake_rule_is_phony,


More information about the reviews mailing list