diff --git a/configure.ac b/configure.ac
index 0da063ccde78b4455830173efa5406e4d4a97611..45a693d2a0b54ec4befc3c3a1f77a2b75b6275e1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -346,7 +346,8 @@ FP_FIND_ROOT
 
 # Extract and configure the Windows toolchain
 if test "$HostOS" = "mingw32" -a "$EnableDistroToolchain" = "NO"; then
-    FP_SETUP_WINDOWS_TOOLCHAIN
+    FP_INSTALL_WINDOWS_TOOLCHAIN
+    FP_SETUP_WINDOWS_TOOLCHAIN([$hardtop/inplace/mingw], [$hardtop/inplace/mingw])
 else
     AC_PATH_TOOL([CC],[gcc], [clang])
     AC_PATH_TOOL([CXX],[g++], [clang++])
diff --git a/m4/fp_settings.m4 b/m4/fp_settings.m4
index 7e5cb05a312f006df0c77351843103e4b42f3e5d..719a991d2718f1ea96e8c5bb0f81d120c7ac0e09 100644
--- a/m4/fp_settings.m4
+++ b/m4/fp_settings.m4
@@ -36,14 +36,15 @@ dnl ghc-toolchain.
 # SUBST_TOOLDIR
 # ----------------------------------
 # $1 - the variable where to search for occurrences of the path to the
-# distributed mingw, and update by substituting said occurrences by
-# the literal '$tooldir/mingw'
+#      inplace mingw, and update by substituting said occurrences by
+#      the value of $mingw_install_prefix, where the mingw toolchain will be at
+#      install time
 #
 # See Note [How we configure the bundled windows toolchain]
 AC_DEFUN([SUBST_TOOLDIR],
 [
     dnl and Note [How we configure the bundled windows toolchain]
-    $1=`echo $$1 | sed 's%'"$mingwpath"'%$$tooldir/mingw%'`
+    $1=`echo "$$1" | sed 's%'"$mingw_prefix"'%'"$mingw_install_prefix"'%g'`
 ])
 
 # FP_SETTINGS
diff --git a/m4/fp_setup_windows_toolchain.m4 b/m4/fp_setup_windows_toolchain.m4
index 44e0eeb32e1c090490a8b03e3f3478345540022f..ac79f2977dd48ddff8e192054d4f253f52a67a05 100644
--- a/m4/fp_setup_windows_toolchain.m4
+++ b/m4/fp_setup_windows_toolchain.m4
@@ -1,4 +1,5 @@
-AC_DEFUN([FP_SETUP_WINDOWS_TOOLCHAIN],[
+# Download and install the windows toolchain
+AC_DEFUN([FP_INSTALL_WINDOWS_TOOLCHAIN],[
     # Find the mingw-w64 archive file to extract.
     if test "$HostArch" = "i386"
     then
@@ -72,18 +73,28 @@ AC_DEFUN([FP_SETUP_WINDOWS_TOOLCHAIN],[
     # NB. Download and extract the MingW-w64 distribution if required
     set_up_tarballs
 
+])
+
+# Set up the environment variables
+# $1 The actual location of the windows toolchain (before install)
+# $2 the location that the windows toolchain will be installed in relative to the libdir
+AC_DEFUN([FP_SETUP_WINDOWS_TOOLCHAIN],[
+
     # N.B. The parameters which get plopped in the `settings` file used by the
     # resulting compiler are computed in `FP_SETTINGS`. Specifically, we use
     # $$topdir-relative paths instead of fullpaths to the toolchain, by replacing
     # occurrences of $hardtop/inplace/mingw with $$tooldir/mingw
 
+    mingw_prefix="$1"
+    mingw_install_prefix="$2"
+
     # Our Windows toolchain is based around Clang and LLD. We use compiler-rt
     # for the runtime, libc++ and libc++abi for the C++ standard library
     # implementation, and libunwind for C++ unwinding.
-    mingwbin="$hardtop/inplace/mingw/bin/"
-    mingwlib="$hardtop/inplace/mingw/lib"
-    mingwinclude="$hardtop/inplace/mingw/include"
-    mingwpath="$hardtop/inplace/mingw"
+    mingwbin="$mingw_prefix/bin/"
+    mingwlib="$mingw_prefix/lib"
+    mingwinclude="$mingw_prefix/include"
+    mingw_mingw32_lib="$mingw_prefix/x86_64-w64-mingw32/lib"
 
     CC="${mingwbin}clang.exe"
     CXX="${mingwbin}clang++.exe"
@@ -106,8 +117,8 @@ AC_DEFUN([FP_SETUP_WINDOWS_TOOLCHAIN],[
 
     HaskellCPPArgs="$HaskellCPPArgs -I$mingwinclude"
 
-    CONF_GCC_LINKER_OPTS_STAGE1="-fuse-ld=lld $cflags -L$mingwlib -L$hardtop/inplace/mingw/x86_64-w64-mingw32/lib"
-    CONF_GCC_LINKER_OPTS_STAGE2="-fuse-ld=lld $cflags -L$mingwlib -L$hardtop/inplace/mingw/x86_64-w64-mingw32/lib"
+    CONF_GCC_LINKER_OPTS_STAGE1="-fuse-ld=lld $cflags -L$mingwlib -L$mingw_mingw32_lib"
+    CONF_GCC_LINKER_OPTS_STAGE2="-fuse-ld=lld $cflags -L$mingwlib -L$mingw_mingw32_lib"
 
     # N.BOn Windows we can't easily dynamically-link against libc++ since there is
     # no RPATH support, meaning that the loader will have no way of finding our