[m-rev.] for review: cross-compiling with mingw

Peter Wang novalazy at gmail.com
Mon Dec 19 16:14:45 AEDT 2011


Branches: main

Let Mercury be built with a MinGW cross-compiler.

tools/configure_mingw_cross:
	Add shell script to prepare for cross-compilation.

README.MinGW-cross:
	Document how to use the shell script.

configure.in:
Mmake.common.in:
	Set a new variable CROSS_COMPILING.

	Set FULLARCH and BUILD_C_PROGS_FOR_BUILD_SYSTEM variables
	to be passed to the Boehm GC build system.

	Use $host-ar for AR when cross-compiling.

m4/mercury.m4:
	Determine gcc version with gcc -dumpversion instead of building
	a program and running it.

	Don't run test for mercury_cv_cc_type if set explicitly.

Mmake.workspace:
	Use the default c2init and mkinit when cross-compiling.
	The copies in the util directory would not be usable then.

boehm_gc/Mmakefile:
	Pass configured values of AR, RANLIB down to sub-make.

boehm_gc/Makefile.direct:
boehm_gc/build_atomic_ops.sh:
	Use configured value from Mmake.common for HOSTCC. 

	Pass --host when configuring libatomic_ops.

util/Mmakefile:
	Make tools with .exe suffixes on Windows.

Mmakefile:
	Use the bootstrap compiler to build libgrades when cross-compiling.

	Conform to changed target names in the util directory.

compiler/Mmakefile:
deep_profiler/Mmakefile:
profiler/Mmakefile:
slice/Mmakefile:
	Conform to changed target names in the util directory.

Makefile:
	Clean .exe files on Windows.

diff --git a/Makefile b/Makefile
index eeb434f..1032b10 100644
--- a/Makefile
+++ b/Makefile
@@ -45,8 +45,11 @@ install:
 clean:
 	-rm -f */*.o */*.pic_o */*.a */*.so */*.dylib
 	-rm -rf */Mercury/os */Mercury/pic_os */Mercury/libs
-	-rm -f compiler/mercury_compile profiler/mercury_profile 
-	-rm -f util/mdemangle util/mfiltercc util/mkinit
+	-rm -f compiler/mercury_compile$(EXT_FOR_EXE)
+	-rm -f profiler/mercury_profile$(EXT_FOR_EXE)
+	-rm -f util/mdemangle$(EXT_FOR_EXE)
+	-rm -f util/mfiltercc$(EXT_FOR_EXE)
+	-rm -f util/mkinit$(EXT_FOR_EXE)
 	cd boehm_gc; $(MMAKE_SUBDIR) clean
 
 .PHONY: distclean
diff --git a/Mmake.common.in b/Mmake.common.in
index 633f7af..5cd17ef 100644
--- a/Mmake.common.in
+++ b/Mmake.common.in
@@ -23,11 +23,25 @@ include $(MERCURY_DIR)/VERSION
 # directory, not $(MERCURY_DIR)/runtime etc.
 SET_RPATH=no
 
+# This affects the tools set in Mmake.workspace so must be set first.
+CROSS_COMPILING=@CROSS_COMPILING@
+
 WORKSPACE=$(MERCURY_DIR)
 include $(MERCURY_DIR)/Mmake.workspace
 
 #-----------------------------------------------------------------------------#
 
+# The host triplet is used to configure libatomic_ops.
+FULLARCH=@FULLARCH@
+
+# Specify a C compiler to build executables that can be executed on the build
+# system itself, as part of the Boehm GC build process. The name is confusing
+# because it conflicts with the autoconf meaning of "host", but it comes from
+# upstream.
+HOSTCC=@BUILD_C_PROGS_FOR_BUILD_SYSTEM@
+
+#-----------------------------------------------------------------------------#
+
 # Specify the Mercury compiler to use for bootstrapping.
 MC		= @BOOTSTRAP_MC_COMPILER@
 
diff --git a/Mmake.workspace b/Mmake.workspace
index 3c40951..7228cd2 100644
--- a/Mmake.workspace
+++ b/Mmake.workspace
@@ -95,8 +95,12 @@ export SO_LOCATIONS_DIR
 MC =		$(SCRIPTS_DIR)/mmc
 MGNUC =		$(SCRIPTS_DIR)/mgnuc
 ML =		$(SCRIPTS_DIR)/ml
+ifneq ($(CROSS_COMPILING),yes)
+# We cannot use these binaries in util when cross-compiling.
+# Just assume that the default c2init and mkinit are usable.
 C2INIT =	MERCURY_MKINIT=$(UTIL_DIR)/mkinit $(SCRIPTS_DIR)/c2init
 MKLIBINIT =	$(UTIL_DIR)/mkinit -k
+endif
 MTAGS =		$(SCRIPTS_DIR)/mtags
 MTAGSFLAGS +=	$(EXTRA_MTAGSFLAGS)
 
diff --git a/Mmakefile b/Mmakefile
index 74b4ba2..d639190 100644
--- a/Mmakefile
+++ b/Mmakefile
@@ -230,7 +230,7 @@ all: 	$(GENERATED_DOCS) mercury-compiler.spec util_no_rt $(SUBDIRS)
 
 .PHONY: util_no_rt
 util_no_rt: scripts
-	+cd util && $(SUBDIR_MMAKE) mfiltercc
+	+cd util && $(SUBDIR_MMAKE) mfiltercc$(EXT_FOR_EXE)
 
 .PHONY: util
 util: 	scripts runtime
@@ -644,12 +644,18 @@ install_deep_profiler: deep_profiler
 # LIBGRADE_SUFFIXES = .m .int3 .date3 .int2 .int .date .opt .optdate \
 #	.trans_opt .trans_opt_date .d .mh .mih .c_date  .c .o .pic_o
 
+ifeq ($(CROSS_COMPILING),yes)
+OVERRIDE_MC_FOR_LIBGRADE =
+else
+OVERRIDE_MC_FOR_LIBGRADE = MC=mmc
+endif
+
 .PHONY: install_grades
-install_grades: install_main
+install_grades:  # install_main
 	# Use the newly installed compiler to build the libraries in various
-	# different grades. We need to override MC=mmc so that we use the mmc
-	# from the scripts directory, which runs the newly installed compiler,
-	# rather than using the bootstrap compiler.
+	# different grades. Except when cross-compiling, we override MC=mmc so
+	# that we use the mmc from the scripts directory, which runs the newly
+	# installed compiler, rather than using the bootstrap compiler.
 	#
 	# Compile different grades in different directories, so that we can
 	# optionally preserve all the directories, and include them in
@@ -668,33 +674,44 @@ install_grades: install_main
 		esac;                                                         \
 		scripts/prepare_install_dir $${IWS} &&                        \
 		( cd $${IWS}/boehm_gc &&                                      \
-		  $(SUBDIR_MMAKE) MC=mmc GRADE=$${grade} WORKSPACE=$${IWS}    \
+		  $(SUBDIR_MMAKE) $(OVERRIDE_MC_FOR_LIBGRADE)                 \
+			GRADE=$${grade} WORKSPACE=$${IWS}                     \
 			GC_GRADE=$${gc_grade} install_lib ) &&                \
 		( cd $${IWS}/runtime &&                                       \
-		  $(SUBDIR_MMAKE) MC=mmc GRADE=$${grade} WORKSPACE=$${IWS}    \
+		  $(SUBDIR_MMAKE) $(OVERRIDE_MC_FOR_LIBGRADE)                 \
+			GRADE=$${grade} WORKSPACE=$${IWS}                     \
 			install_lib ) &&                                      \
 		( cd $${IWS}/library &&                                       \
-		  $(SUBDIR_MMAKE) MC=mmc GRADE=$${grade} WORKSPACE=$${IWS}    \
+		  $(SUBDIR_MMAKE) $(OVERRIDE_MC_FOR_LIBGRADE)                 \
+			GRADE=$${grade} WORKSPACE=$${IWS}                     \
 			depend &&                                             \
-		  $(SUBDIR_MMAKE) MC=mmc GRADE=$${grade} WORKSPACE=$${IWS}    \
+		  $(SUBDIR_MMAKE) $(OVERRIDE_MC_FOR_LIBGRADE)                 \
+			GRADE=$${grade} WORKSPACE=$${IWS}                     \
 			install_library ) &&                                  \
 		( cd $${IWS}/mdbcomp &&                                       \
-		  $(SUBDIR_MMAKE) MC=mmc GRADE=$${grade} WORKSPACE=$${IWS}    \
+		  $(SUBDIR_MMAKE) $(OVERRIDE_MC_FOR_LIBGRADE)                 \
+			GRADE=$${grade} WORKSPACE=$${IWS}                     \
 			depend &&                                             \
-		  $(SUBDIR_MMAKE) MC=mmc GRADE=$${grade} WORKSPACE=$${IWS}    \
+		  $(SUBDIR_MMAKE) $(OVERRIDE_MC_FOR_LIBGRADE)                 \
+			GRADE=$${grade} WORKSPACE=$${IWS}                     \
 			install_library ) &&                                  \
 		( cd $${IWS}/browser &&                                       \
-		  $(SUBDIR_MMAKE) MC=mmc GRADE=$${grade} WORKSPACE=$${IWS}    \
+		  $(SUBDIR_MMAKE) $(OVERRIDE_MC_FOR_LIBGRADE)                 \
+			GRADE=$${grade} WORKSPACE=$${IWS}                     \
 			depend &&                                             \
-		  $(SUBDIR_MMAKE) MC=mmc GRADE=$${grade} WORKSPACE=$${IWS}    \
+		  $(SUBDIR_MMAKE) $(OVERRIDE_MC_FOR_LIBGRADE)                 \
+			GRADE=$${grade} WORKSPACE=$${IWS}                     \
 			install_library ) &&                                  \
 		( cd $${IWS}/ssdb &&                                          \
-		  $(SUBDIR_MMAKE) MC=mmc GRADE=$${grade} WORKSPACE=$${IWS}    \
+		  $(SUBDIR_MMAKE) $(OVERRIDE_MC_FOR_LIBGRADE)                 \
+			GRADE=$${grade} WORKSPACE=$${IWS}                     \
 			depend &&                                             \
-		  $(SUBDIR_MMAKE) MC=mmc GRADE=$${grade} WORKSPACE=$${IWS}    \
+		  $(SUBDIR_MMAKE) $(OVERRIDE_MC_FOR_LIBGRADE)                 \
+			GRADE=$${grade} WORKSPACE=$${IWS}                     \
 			install_library ) &&                                  \
 		( cd $${IWS}/trace &&                                         \
-		  $(SUBDIR_MMAKE) MC=mmc GRADE=$${grade} WORKSPACE=$${IWS}    \
+		  $(SUBDIR_MMAKE) $(OVERRIDE_MC_FOR_LIBGRADE)                 \
+			GRADE=$${grade} WORKSPACE=$${IWS}                     \
 			install_lib ) &&                                      \
 		true                                                          \
 	    ) ||                                                              \
diff --git a/README.MinGW-cross b/README.MinGW-cross
new file mode 100644
index 0000000..a4c26e2
--- /dev/null
+++ b/README.MinGW-cross
@@ -0,0 +1,69 @@
+-----------------------------------------------------------------------------
+
+COMPILING MERCURY WITH A MINGW CROSS-COMPILER
+
+You can cross-compile Mercury on Linux with a MinGW cross-compiler.  After
+copying and adjusting some paths, the Mercury installation should be usable
+on Windows.  Alternatively, when combined with a native Mercury compiler,
+it could be used to cross-compile Mercury applications for Windows.
+
+-----------------------------------------------------------------------------
+
+PREREQUISITES
+
+We assume you are on Linux.  You will need a native Mercury installation
+installed in the normal way.  Unless you know what you are doing, we
+recommend that the native Mercury version matches the version of Mercury
+you intend to cross-compile, or at least are very close.
+
+Obviously you need a MinGW cross-compiler.
+I used <http://mingw-cross-env.nongnu.org/>
+
+-----------------------------------------------------------------------------
+
+INSTALLATION
+
+Ensure that the MinGW cross-compiler i686-pc-mingw-gcc (or whatever) is on your
+PATH.  In a fresh Mercury directory, run this script instead of configure:
+
+    tools/configure_mingw_cross
+
+If your MinGW uses a host triplet other than "i686-pc-mingw32" then you must
+pass that using the --host= option.  You may pass other options through to
+configure as well, e.g.
+
+    tools/configure_mingw_cross \
+        --host=i686-pc-mingw32 \
+        --prefix=/usr/local/mercury-mingw
+
+Then install Mercury as usual:
+
+    mmake install PARALLEL=-j6 LIBGRADES=...
+
+-----------------------------------------------------------------------------
+
+USING THE CROSS-COMPILER ON LINUX
+
+You can substitute the Windows version of the Mercury compiler binary
+(mercury_compile.exe) with a Linux version.  Again, this should be from
+the same or similar version of Mercury.
+
+The 'mmc' shell script will have been set up to look for a binary named
+'mercury_compile' so you just need to place the Linux binary into the bin
+directory, e.g.
+
+    % ln -s /usr/local/mercury/bin/mercury_compile /usr/local/mercury-mingw/bin
+
+Now you can run the 'mmc' script from the cross-compiled installation:
+
+    % /usr/local/mercury-mingw/bin/mmc -m hello --cross-compiling
+    Making Mercury/int3s/hello.int3
+    Making Mercury/ints/hello.int
+    Making Mercury/cs/hello.c
+    Making Mercury/os/hello.o
+    Making hello.exe
+
+You should definitely pass `--cross-compiling' if mercury_compile was
+compiled for 64-bit Linux.
+
+-----------------------------------------------------------------------------
diff --git a/boehm_gc/Makefile.direct b/boehm_gc/Makefile.direct
index 84ee0f5..be4f7b8 100644
--- a/boehm_gc/Makefile.direct
+++ b/boehm_gc/Makefile.direct
@@ -107,7 +107,11 @@ endif
 # part of the build process, i.e. on the build machine.  These will usually
 # be the same as CC and CFLAGS, except in a cross-compilation environment.
 # Note that HOSTCFLAGS should include any -D flags that affect thread support.
+#
+# Mercury-specific: we set HOSTCC in Mmake.common
+ifndef HOSTCC
 HOSTCC=$(CC)
+endif
 HOSTCFLAGS=$(CFLAGS)
 
 # For dynamic library builds, it may be necessary to add flags to generate
@@ -226,8 +230,9 @@ all: gc.a gctest
 
 # if AO_INSTALL_DIR doesn't exist, we assume that it is pointing to
 # the default location, and we need to build
+# Mercury-specific: pass FULLARCH for cross-compilation
 $(AO_INSTALL_DIR):
-	CC="$(CC)" MAKE=$(MAKE) $(srcdir)/build_atomic_ops.sh
+	CC="$(CC)" MAKE=$(MAKE) $(srcdir)/build_atomic_ops.sh --host=$(FULLARCH)
 
 LEAKFLAGS=$(CFLAGS) -DFIND_LEAK
 
diff --git a/boehm_gc/Mmakefile b/boehm_gc/Mmakefile
index 3e49c58..8f4e71e 100644
--- a/boehm_gc/Mmakefile
+++ b/boehm_gc/Mmakefile
@@ -94,6 +94,7 @@ else
 submake: Makefile force 
 	MAKEFLAGS=""; export MAKEFLAGS; \
 	$(MAKE) $(MMAKEFLAGS) -j1 GRADE=$(GRADE) GC_GRADE=$(GC_GRADE) \
+		AR=$(AR) RANLIB=$(RANLIB) \
 		lib$(GC_GRADE).$A lib$(GC_GRADE).$(EXT_FOR_SHARED_LIB) \
 		FINAL_INSTALL_MERC_GC_LIB_DIR=$(FINAL_INSTALL_MERC_GC_LIB_DIR) \
 		$(EXT_FOR_SHARED_LIB)
diff --git a/boehm_gc/build_atomic_ops.sh b/boehm_gc/build_atomic_ops.sh
index b8ef586..faf19d0 100755
--- a/boehm_gc/build_atomic_ops.sh
+++ b/boehm_gc/build_atomic_ops.sh
@@ -1,5 +1,6 @@
 #!/bin/sh
 P=`pwd`/libatomic_ops-install
 cd libatomic_ops
-./configure --prefix=$P
+# Mercury-specific: allow additional arguments.
+./configure --prefix=$P "$@"
 $MAKE CC="$CC" install
diff --git a/compiler/Mmakefile b/compiler/Mmakefile
index 2371ce2..4555d33 100644
--- a/compiler/Mmakefile
+++ b/compiler/Mmakefile
@@ -282,7 +282,7 @@ $(MC_PROG): $(GCC_MAIN_LIBS)
 endif
 endif
 
-$(MC_PROG)_init.c: $(UTIL_DIR)/mkinit
+$(MC_PROG)_init.c: $(UTIL_DIR)/mkinit$(EXT_FOR_EXE)
 
 #-----------------------------------------------------------------------------#
 
diff --git a/configure.in b/configure.in
index bb2513e..9993374 100644
--- a/configure.in
+++ b/configure.in
@@ -144,7 +144,7 @@ esac
 AC_PROG_CC
 AC_SUBST([CC])
 
-# Ensure that AC_CANONICAl_HOST uses the value of CC we just determined.
+# Ensure that AC_CANONICAL_HOST uses the value of CC we just determined.
 #
 export CC
 
@@ -227,6 +227,26 @@ case "$PREFIX" in
         ;;
 esac
 
+#-----------------------------------------------------------------------------#
+
+case "$cross_compiling" in
+    yes)
+        CROSS_COMPILING=yes
+        BUILD_C_PROGS_FOR_BUILD_SYSTEM=cc
+        HOST_TOOL_PREFIX="$host-"
+        ;;
+    *)
+        CROSS_COMPILING=no
+        BUILD_C_PROGS_FOR_BUILD_SYSTEM="$CC"
+        HOST_TOOL_PREFIX=
+        ;;
+esac
+
+AC_SUBST(CROSS_COMPILING)
+AC_SUBST(BUILD_C_PROGS_FOR_BUILD_SYSTEM)
+
+#-----------------------------------------------------------------------------#
+
 # Using `cygpath -m' gives a path that works under both Cygwin and native
 # Windows, without causing quoting problems in shell scripts.
 # (`cygpath -m' converts the path to Windows format, with '/' as the directory
@@ -1061,7 +1081,7 @@ else
 
     OBJFILE_OPT="-o "
     EXEFILE_OPT="-o "
-    AR="ar"
+    AR="${HOST_TOOL_PREFIX}ar"
     ARFLAGS="cr"
     AR_LIBFILE_OPT=""
 
diff --git a/deep_profiler/Mmakefile b/deep_profiler/Mmakefile
index f075c53..e0679e4 100644
--- a/deep_profiler/Mmakefile
+++ b/deep_profiler/Mmakefile
@@ -146,12 +146,12 @@ mdprof_procrep:		$(LIBRARY_DIR)/lib$(STD_LIB_NAME).$A
 # if in .gc(.prof) grade.
 endif
 
-$(cs_subdir)mdprof_cgi_init.c:			$(UTIL_DIR)/mkinit
-$(cs_subdir)mdprof_test_init.c:			$(UTIL_DIR)/mkinit
-$(cs_subdir)mdprof_dump_init.c:			$(UTIL_DIR)/mkinit
-$(cs_subdir)mdprof_create_feedback_init.c: 	$(UTIL_DIR)/mkinit
-$(cs_subdir)mdprof_report_feedback_init.c: 	$(UTIL_DIR)/mkinit
-$(cs_subdir)mdprof_procrep_init.c:		$(UTIL_DIR)/mkinit
+$(cs_subdir)mdprof_cgi_init.c:			$(UTIL_DIR)/mkinit$(EXT_FOR_EXE)
+$(cs_subdir)mdprof_test_init.c:			$(UTIL_DIR)/mkinit$(EXT_FOR_EXE)
+$(cs_subdir)mdprof_dump_init.c:			$(UTIL_DIR)/mkinit$(EXT_FOR_EXE)
+$(cs_subdir)mdprof_create_feedback_init.c: 	$(UTIL_DIR)/mkinit$(EXT_FOR_EXE)
+$(cs_subdir)mdprof_report_feedback_init.c: 	$(UTIL_DIR)/mkinit$(EXT_FOR_EXE)
+$(cs_subdir)mdprof_procrep_init.c:		$(UTIL_DIR)/mkinit$(EXT_FOR_EXE)
 
 #-----------------------------------------------------------------------------#
 
diff --git a/m4/mercury.m4 b/m4/mercury.m4
index 2d226ca..5fbce96 100644
--- a/m4/mercury.m4
+++ b/m4/mercury.m4
@@ -483,44 +483,15 @@ AC_SUBST(ERL)
 #-----------------------------------------------------------------------------#
 
 # NOTE: updates to this macro may need to be reflected in compiler/globals.m.
+# Generating an executable and running it does not work when cross-compiling.
 
 AC_DEFUN([MERCURY_GCC_VERSION], [
 AC_REQUIRE([AC_PROG_CC])
 
-cat > conftest.c << EOF
-
-#include <stdio.h>
-
-int main(int argc, char **argv)
-{
-
-#if defined(__GNUC__)
-    printf("%d_", __GNUC__);
-    #if defined(__GNUC_MINOR__)
-        printf("%d_", __GNUC_MINOR__);
-    #else
-        printf("u_");
-    #endif /* ! __GNUC_MINOR__ */
-    #if defined(__GNUC_PATCHLEVEL__)
-    	printf("%d", __GNUC_PATCHLEVEL__);
-    #else
-        printf("u");
-    #endif /* ! __GNUC_PATCHLEVEL__ */
-#endif /* __GNUC__ */
-
-	return 0;
-}
-EOF
-
-echo "$CC -o conftest contest.c" >&AC_FD_CC 2>&1
-if
-    $CC -o conftest conftest.c
-then
-    mercury_cv_gcc_version=`./conftest`
-else
-    # This shouldn't happen as we have already checked for this.
-    AC_MSG_ERROR([unexpected: $CC cannot create executable])
-fi
+mercury_cv_gcc_version=`$CC -dumpversion | tr . ' ' | {
+    read major minor patchlevel ignore
+    echo ${major:-u}_${minor:-u}_${patchlevel:-u}
+    }`
 ])
 
 #-----------------------------------------------------------------------------#
@@ -572,7 +543,8 @@ if
     # only way to shut some C compilers up.
     $CC $nologo_opt ${cc_out_opt}conftest conftest.c 2>&1 > /dev/null
 then
-    mercury_cv_cc_type=`./conftest`
+    AC_CACHE_VAL(mercury_cv_cc_type,
+    mercury_cv_cc_type=`./conftest`)
 else
     # This shouldn't happen as we have already checked for this.
     AC_MSG_ERROR([unexpected: $CC cannot create executable])
diff --git a/profiler/Mmakefile b/profiler/Mmakefile
index 2c7a8a0..f1a2649 100644
--- a/profiler/Mmakefile
+++ b/profiler/Mmakefile
@@ -46,7 +46,7 @@ mercury_profile: $(LIBRARY_DIR)/lib$(STD_LIB_NAME).$A
 # if in .gc(.prof) grade.
 endif
 
-$(cs_subdir)mercury_profile_init.c: $(UTIL_DIR)/mkinit
+$(cs_subdir)mercury_profile_init.c: $(UTIL_DIR)/mkinit$(EXT_FOR_EXE)
 
 ifneq ("$(filter il% csharp% java% erlang%,$(GRADE))","")
 MLOBJS =
diff --git a/slice/Mmakefile b/slice/Mmakefile
index 6a053c7..c2d84c2 100644
--- a/slice/Mmakefile
+++ b/slice/Mmakefile
@@ -129,11 +129,11 @@ mtc_diff: $(LIBRARY_DIR)/lib$(STD_LIB_NAME).$A
 mtc_diff: $(BROWSER_DIR)/lib$(BROWSER_LIB_NAME).$A
 endif
 
-$(cs_subdir)mslice_init.c: $(UTIL_DIR)/mkinit
-$(cs_subdir)mdice_init.c: $(UTIL_DIR)/mkinit
-$(cs_subdir)mtc_union.c: $(UTIL_DIR)/mkinit
-$(cs_subdir)mcov.c: $(UTIL_DIR)/mkinit
-$(cs_subdir)mtc_diff.c: $(UTIL_DIR)/mkinit
+$(cs_subdir)mslice_init.c: $(UTIL_DIR)/mkinit$(EXT_FOR_EXE)
+$(cs_subdir)mdice_init.c: $(UTIL_DIR)/mkinit$(EXT_FOR_EXE)
+$(cs_subdir)mtc_union.c: $(UTIL_DIR)/mkinit$(EXT_FOR_EXE)
+$(cs_subdir)mcov.c: $(UTIL_DIR)/mkinit$(EXT_FOR_EXE)
+$(cs_subdir)mtc_diff.c: $(UTIL_DIR)/mkinit$(EXT_FOR_EXE)
 
 #-----------------------------------------------------------------------------#
 
diff --git a/tools/configure_mingw_cross b/tools/configure_mingw_cross
new file mode 100755
index 0000000..4aed07c
--- /dev/null
+++ b/tools/configure_mingw_cross
@@ -0,0 +1,85 @@
+#!/bin/sh -e
+# This script prepares the Mercury directory for a MinGW cross-compiler.
+# Please see README.MinGW-cross for details.
+
+for arg
+do
+    case $arg in
+        --host=*)
+            host=${arg/--host=}
+            break
+            ;;
+    esac
+done
+
+host=${host:-i686-pc-mingw32}
+hostcc=$host-gcc
+
+echo "Configuring for host $host"
+
+if which $hostcc >/dev/null
+then
+    true
+else
+    echo "You need $hostcc in your PATH."
+    exit 1
+fi
+
+if which mmc >/dev/null && mmc -v 2>&1 | grep -q Mercury
+then
+    true
+else
+    echo "You need a working native mmc in your PATH."
+    exit 2
+fi
+
+if test configure -ot configure.in
+then
+    aclocal -I m4 && autoconf
+fi
+
+if ! test -f configure.in
+then
+    echo "You need to run this script at the top of the Mercury tree."
+    exit 3
+fi
+
+# Set values which would otherwise be determined with AC_TRY_RUN.
+# Taken from the config.cache file after running configure -C in msys.
+
+mercury_cv_cc_type=gcc \
+mercury_cv_sigaction_field=no \
+mercury_cv_sigcontext_struct_2arg=no \
+mercury_cv_sigcontext_struct_3arg=no \
+mercury_cv_siginfo_t=no \
+mercury_cv_word_type=int \
+mercury_cv_int_least64_type='long long' \
+mercury_cv_int_least32_type=int \
+mercury_cv_int_least16_type=short \
+mercury_cv_low_tag_bits=2 \
+mercury_cv_bytes_per_word=4 \
+mercury_cv_sync_term_size=3 \
+mercury_cv_bits_per_word=32 \
+mercury_cv_unboxed_floats=no \
+mercury_cv_float_is_64_bit=no \
+mercury_cv_double_is_64_bit=yes \
+mercury_cv_long_double_is_64_bit=no \
+mercury_cv_is_bigender=no \
+mercury_cv_is_littleender=yes \
+mercury_cv_normal_system_retval=no \
+mercury_cv_can_do_pending_io=no \
+mercury_cv_gcc_labels=yes \
+mercury_cv_asm_labels=yes \
+mercury_cv_gcc_model_fast=yes \
+mercury_cv_gcc_model_reg=yes \
+mercury_cv_cannot_use_structure_assignment=yes \
+sh configure "$@" \
+    --host=$host \
+    --with-cc=$hostcc
+
+echo
+echo "If you wish to run mmake in the subdirectories, you will need to set"
+echo "MMAKE_DIR=`pwd`/scripts"
+echo
+
+exit
diff --git a/util/Mmakefile b/util/Mmakefile
index e76d30d..c60d30c 100644
--- a/util/Mmakefile
+++ b/util/Mmakefile
@@ -46,33 +46,33 @@ MGNUCFLAGS-mfiltercc = --no-filter-cc
 
 #-----------------------------------------------------------------------------#
 
-all:	$(PROGS) $(TAGS_FILE_EXISTS)
+all:	$(PROGFILENAMES) $(TAGS_FILE_EXISTS)
 
 ifeq ($(USING_MICROSOFT_CL_COMPILER),yes)
-.c:
+.c$(EXT_FOR_EXE):
 	$(MGNUC) --no-mercury-stdlib-dir \
 		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) -Fe$@ $< $(GETOPT_SRC)
 
-mkinit: mkinit.c mkinit_common.c mkinit_common.h
+mkinit$(EXT_FOR_EXE): mkinit.c mkinit_common.c mkinit_common.h
 	$(MGNUC) --no-mercury-stdlib-dir \
 		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) -Fe$@ \
 			mkinit.c mkinit_common.c $(GETOPT_SRC)
 
-mkinit_erl: mkinit_erl.c mkinit_common.c mkinit_common.h
+mkinit_erl$(EXT_FOR_EXE): mkinit_erl.c mkinit_common.c mkinit_common.h
 	$(MGNUC) --no-mercury-stdlib-dir \
 		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) -Fe$@ \
 			mkinit_erl.c mkinit_common.c $(GETOPT_SRC)
 else
-.c:
+.c$(EXT_FOR_EXE):
 	$(MGNUC) --no-mercury-stdlib-dir \
 		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) -o $@ $< $(GETOPT_SRC)
 
-mkinit: mkinit.c mkinit_common.c mkinit_common.h
+mkinit$(EXT_FOR_EXE): mkinit.c mkinit_common.c mkinit_common.h
 	$(MGNUC) --no-mercury-stdlib-dir \
 		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) -o $@ \
 			mkinit.c mkinit_common.c $(GETOPT_SRC)
 
-mkinit_erl: mkinit_erl.c mkinit_common.c mkinit_common.h
+mkinit_erl$(EXT_FOR_EXE): mkinit_erl.c mkinit_common.c mkinit_common.h
 	$(MGNUC) --no-mercury-stdlib-dir \
 		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) -o $@ \
 			mkinit_erl.c mkinit_common.c $(GETOPT_SRC)
@@ -90,7 +90,7 @@ tags_file_exists:
 #-----------------------------------------------------------------------------#
 
 .PHONY: install
-install: $(PROGS)
+install: $(PROGFILENAMES)
 	[ -d $(INSTALL_BINDIR) ] || mkdir -p $(INSTALL_BINDIR)
 	cp `vpath_find $(PROGFILENAMES)` $(INSTALL_BINDIR)
 

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list