[m-rev.] for review: improve support for MSYS2 builds

Julien Fischer jfischer at opturion.com
Fri Jan 24 13:58:33 AEDT 2020


For review by Peter.

This replaces my diff from yesterday; it preserves the possibility
of using MinGW-w64 cross-compiler.

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

Improve support for MSYS2 builds.

MSYS2 provides a POSIX like environment and package manager for Windows.
It packages up the MinGW-w64 port of GCC.  (MSYS2 is separate from the
original MSYS.)

Make it possible to build Mercury under MSYS2 with the MinGW-w64 GCC
without having to resort to cross compilation.

configure.ac:
     Recognise the x86_64-pc-mingw* architecture returned by config.guess
     under MSYS2.

     If we are building the MSVC port under MSYS2, set up the flags for
     threads appropriately.

scripts/ml.in:
     Pass libraries to the linker correctly for static linking on all the
     different MinGW configurations.

Julien.

diff --git a/README.MinGW b/README.MinGW
index 57df999..d6a5387 100644
--- a/README.MinGW
+++ b/README.MinGW
@@ -98,16 +98,22 @@ To build the source distribution under MSYS follow these steps:
      path with a drive letter (except use `/' instead of `\').
      Do not use a path like `/mercury', because that
      will be interpreted differently by the MSYS shell than by the generated
-    executables, resulting in a broken installation. 
+    executables, resulting in a broken installation.

-    If you are using the MSYS or MSYS2 shell with MinGW-w64 then you must also
-    invoke configure with the following option:
+    If you are using the MSYS shell with MinGW-w64 then you must also invoke
+    configure with the following option:

         --host=x86_64-w64-mingw32

      This will cause mmake to use the MinGW-w64 tool chain.  Ensure that the
      MinGW-w64 tools are in your PATH before running configure.

+    If you are using the MSYS2 shell then you need to launch it in either
+    the "MSYS2 MinGW 32-bit" mode or the "MSYS2 MinGW 63-bit mode" to build
+    a 32- or 64-bit Mercury system respectively.  You do *not* need to pass
+    the --host=x86_64-w64-mingw32 option to configure on MSYS2; if you do
+    you will get a 64-bit compiler.
+
  5.  run: `make' and then `make install'.

  Add /c/mercury/bin (or whatever path you installed Mercury to) to the MSYS
diff --git a/configure.ac b/configure.ac
index 281baef..3e7e10c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3277,12 +3277,22 @@ case "$host" in
          esac
          ;;

-    *-w64-mingw*)
-        CFLAGS_FOR_THREADS="$WIN32_GC_THREADLIB"
-        BOEHM_CFLAGS_FOR_THREADS="-DGC_THREADS $WIN32_GC_THREADLIB"
-        THREAD_LIBS="-lpthread"
-        ENABLE_BOEHM_THREAD_LOCAL_ALLOC="-DTHREAD_LOCAL_ALLOC"
-        ENABLE_BOEHM_PARALLEL_MARK="-DPARALLEL_MARK"
+    *-w64-mingw*|x86_64-pc-mingw*)
+        THREAD_LIBS=""
+        case "$mercury_cv_cc_type" in
+            msvc)
+                CFLAGS_FOR_THREADS="-DGC_THREADS -MD"
+                LDFLAGS_FOR_THREADS="-MD"
+                LD_LIBFLAGS_FOR_THREADS="-MD"
+                ;;
+            *)
+                CFLAGS_FOR_THREADS="$WIN32_GC_THREADLIB"
+                BOEHM_CFLAGS_FOR_THREADS="-DGC_THREADS $WIN32_GC_THREADLIB"
+                THREAD_LIBS="-lpthread"
+                ENABLE_BOEHM_THREAD_LOCAL_ALLOC="-DTHREAD_LOCAL_ALLOC"
+                ENABLE_BOEHM_PARALLEL_MARK="-DPARALLEL_MARK"
+                ;;
+        esac
          ;;

      *apple*darwin*)
diff --git a/scripts/ml.in b/scripts/ml.in
index c77432e..d7dab10 100644
--- a/scripts/ml.in
+++ b/scripts/ml.in
@@ -134,7 +134,7 @@ case $mercury_libs in
  	default)
  		mercury_libs=shared
  		case $FULLARCH in
-			*-cygwin*|i*86-*-solaris*)
+			*-cygwin*|*-mingw*|i*86-*-solaris*)
  				# Shared libraries are not the default on the above systems.
  				# See configure.ac for details.
  				case $make_shared_lib in
@@ -161,7 +161,7 @@ case $all_libs in
  	default)
  		all_libs=shared
  		case $FULLARCH in
-			*-cygwin*)
+			*-cygwin*|*-mingw*)
  				# Shared libraries are not the default on the above systems.
  				# See configure.ac for details.
  				#


More information about the reviews mailing list