x86 NCG: fix regUsageOfInstr for VMOVU & friends
[ghc.git] / m4 / fp_setup_windows_toolchain.m4
blob79230c4d9995d0069ebe0cda8fdf78b93414e857
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"
5     then
6         mingw_arch="x86_64"
7         tarball_dest_dir="mingw-w64/x86_64"
8         tarball_mingw_dir="clang64"
9     fi
11     set_up_tarballs() {
12         AC_MSG_NOTICE([Checking for Windows toolchain tarballs...])
13         local action
14         if test "$TarballsAutodownload" = "NO"
15         then
16             action="verify"
17         else
18             action="download"
19         fi
20         $PYTHON mk/get-win32-tarballs.py $action $mingw_arch > missing-win32-tarballs
21         case $? in
22             0)
23             rm missing-win32-tarballs
24             ;;
25             2)
26             echo
27             echo "Error:"
28             echo "Needed msys2 tarballs are missing. You have a few options to get them,"
29             echo
30             echo "  * run configure with the --enable-tarballs-autodownload option"
31             echo
32             echo "  * run mk/get-win32-tarballs.py download $mingw_arch"
33             echo
34             echo "  * manually download the files listed in ./missing-win32-tarballs and place"
35             echo "    them in the ghc-tarballs directory."
36             echo
37             exit 1
38             ;;
39             *)
40             echo
41             echo "Error fetching msys2 tarballs; see errors above."
42             exit 1
43             ;;
44         esac
46         # Extract all the tarballs in one go
47         if ! test -d inplace/mingw
48         then
49             AC_MSG_NOTICE([Extracting Windows toolchain from archives (may take a while)...])
50             rm -rf inplace/mingw
51             local base_dir="../ghc-tarballs/${tarball_dest_dir}"
52             ( cd inplace &&
53             find "${base_dir}" -name "*.tar.xz" -exec tar --xz -xf {} \; &&
54             find "${base_dir}" -name "*.tar.zst" -exec tar --zstd -xf {} \; &&
55             rm ".MTREE" &&
56             rm ".PKGINFO" &&
57             cd .. ) || AC_MSG_ERROR([Could not extract Windows toolchains.])
59             mv "inplace/${tarball_mingw_dir}" inplace/mingw &&
60             touch inplace/mingw
61             AC_MSG_NOTICE([In-tree MingW-w64 tree created])
62         fi
63     }
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
70     set_up_tarballs
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
84     mingw_prefix="$1"
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"
106     cxxflags=""
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
123     # libc++.dll
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
139     MergeObjsCmd=""
140     MergeObjsArgs=""
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"