1 # Download and install the windows toolchain
2 AC_DEFUN([FP_INSTALL_WINDOWS_TOOLCHAIN],[
3 # Find the mingw-w64 archive file to extract.
4 if test "$HostArch" = "x86_64"
7 tarball_dest_dir="mingw-w64/x86_64"
8 tarball_mingw_dir="clang64"
12 AC_MSG_NOTICE([Checking for Windows toolchain tarballs...])
14 if test "$TarballsAutodownload" = "NO"
20 $PYTHON mk/get-win32-tarballs.py $action $mingw_arch > missing-win32-tarballs
23 rm missing-win32-tarballs
28 echo "Needed msys2 tarballs are missing. You have a few options to get them,"
30 echo " * run configure with the --enable-tarballs-autodownload option"
32 echo " * run mk/get-win32-tarballs.py download $mingw_arch"
34 echo " * manually download the files listed in ./missing-win32-tarballs and place"
35 echo " them in the ghc-tarballs directory."
41 echo "Error fetching msys2 tarballs; see errors above."
46 # Extract all the tarballs in one go
47 if ! test -d inplace/mingw
49 AC_MSG_NOTICE([Extracting Windows toolchain from archives (may take a while)...])
51 local base_dir="../ghc-tarballs/${tarball_dest_dir}"
53 find "${base_dir}" -name "*.tar.xz" -exec tar --xz -xf {} \; &&
54 find "${base_dir}" -name "*.tar.zst" -exec tar --zstd -xf {} \; &&
57 cd .. ) || AC_MSG_ERROR([Could not extract Windows toolchains.])
59 mv "inplace/${tarball_mingw_dir}" inplace/mingw &&
61 AC_MSG_NOTICE([In-tree MingW-w64 tree created])
65 # See Note [How we configure the bundled windows toolchain]
66 # and Note [tooldir: How GHC finds mingw on Windows]
67 test -d inplace || mkdir inplace
69 # NB. Download and extract the MingW-w64 distribution if required
74 # Set up the environment variables
75 # $1 The actual location of the windows toolchain (before install)
76 # $2 the location that the windows toolchain will be installed in relative to the libdir
77 AC_DEFUN([FP_SETUP_WINDOWS_TOOLCHAIN],[
79 # N.B. The parameters which get plopped in the `settings` file used by the
80 # resulting compiler are computed in `FP_SETTINGS`. Specifically, we use
81 # $$topdir-relative paths instead of fullpaths to the toolchain, by replacing
82 # occurrences of $hardtop/inplace/mingw with $$tooldir/mingw
85 mingw_install_prefix="$2"
87 # Our Windows toolchain is based around Clang and LLD. We use compiler-rt
88 # for the runtime, libc++ and libc++abi for the C++ standard library
89 # implementation, and libunwind for C++ unwinding.
90 mingwbin="$mingw_prefix/bin/"
91 mingwlib="$mingw_prefix/lib"
92 mingwinclude="$mingw_prefix/include"
93 mingw_mingw32_lib="$mingw_prefix/x86_64-w64-mingw32/lib"
95 CC="${mingwbin}clang.exe"
96 CXX="${mingwbin}clang++.exe"
98 # Signal that we are linking against UCRT with the _UCRT macro. This is
99 # necessary to ensure correct behavior when MinGW-w64 headers are in the
100 # header include path (#22159).
101 cflags="--rtlib=compiler-rt -D_UCRT"
102 CFLAGS="$cflags -I$mingwinclude"
103 CONF_CC_OPTS_STAGE1="$cflags -I$mingwinclude"
104 CONF_CC_OPTS_STAGE2="$cflags -I$mingwinclude"
107 CXXFLAGS="$cxxflags -I$mingwinclude"
108 CONF_CXX_OPTS_STAGE1="$cxxflags -I$mingwinclude"
109 CONF_CXX_OPTS_STAGE2="$cxxflags -I$mingwinclude"
111 CONF_CPP_OPTS_STAGE1="$CONF_CPP_OPTS_STAGE1 -I$mingwinclude"
112 CONF_CPP_OPTS_STAGE2="$CONF_CPP_OPTS_STAGE2 -I$mingwinclude"
114 HaskellCPPArgs="$HaskellCPPArgs -I$mingwinclude"
115 JavaScriptCPPCmd="$JavaScriptCPPCmd -I$mingwinclude"
116 CmmCPPArgs="$CmmCPPArgs -I$mingwinclude"
118 CONF_GCC_LINKER_OPTS_STAGE1="-fuse-ld=lld $cflags -L$mingwlib -L$mingw_mingw32_lib"
119 CONF_GCC_LINKER_OPTS_STAGE2="-fuse-ld=lld $cflags -L$mingwlib -L$mingw_mingw32_lib"
121 # N.BOn Windows we can't easily dynamically-link against libc++ since there is
122 # no RPATH support, meaning that the loader will have no way of finding our
124 CXX_STD_LIB_LIBS=":libc++.a :libc++abi.a"
125 CXX_STD_LIB_LIB_DIRS="\$topdir"
127 LD="${mingwbin}ld.lld.exe"
128 NM="${mingwbin}llvm-nm.exe"
129 AR="${mingwbin}llvm-ar.exe"
130 RANLIB="${mingwbin}llvm-ranlib.exe"
131 OBJDUMP="${mingwbin}llvm-objdump.exe"
132 DLLTOOL="${mingwbin}llvm-dlltool.exe"
133 WindresCmd="${mingwbin}llvm-windres.exe"
134 LLC="${mingwbin}llc.exe"
135 OPT="${mingwbin}opt.exe"
136 LLVMAS="${mingwbin}clang.exe"
138 # N.B. LLD does not support -r
141 AC_PATH_PROG([Genlib],[genlib])
144 dnl We override the USER_* flags here since the user delegated
145 dnl configuration to the bundled windows toolchain, and these are the
146 dnl options required by the bundled windows toolchain.
147 USER_CFLAGS="$CFLAGS"
148 USER_CPP_ARGS="$CONF_CPP_OPTS_STAGE2"
149 USER_CXXFLAGS="$CXXFLAGS"
150 USER_HS_CPP_ARGS="$HaskellCPPArgs"
151 USER_LDFLAGS="$CONF_GCC_LINKER_OPTS_STAGE2"
152 USER_JS_CPP_ARGS="$JavaScriptCPPArgs"
153 USER_CMM_CPP_ARGS="$CmmCPPArgs"