no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | blog:2017:0924_build_native_mingw64_compiler [2021/09/02 13:38] (current) – Discussion status changed manu | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Cross-compile native mingw compilers for windows ====== | ||
+ | |||
+ | {{tag> | ||
+ | |||
+ | Now that I successfully [[0918_buillding_mingw64_compiler_on_linux|built the linux version of the mingw compilers]] for win64 and win32, I figured out the next logical step would be to try to build the native version of those compilers to run on windows. So here we go! | ||
+ | |||
+ | ====== ====== | ||
+ | |||
+ | ====== Gathering informations ====== | ||
+ | |||
+ | Starting from those official (but old ?) instructions from mingw wiki pages: https:// | ||
+ | |||
+ | It makes sense: we should just be able to use the same compiler from the same sources, but to run on a different host... | ||
+ | |||
+ | ====== First iteration | ||
+ | |||
+ | * Building binutils: **OK** | ||
+ | * The instructions mention creating a ' | ||
+ | * Installing the headers: **OK** | ||
+ | * Building gcc stage 1: **getting error**: < | ||
+ | / | ||
+ | make[1]: * [stmp-fixinc] Error 1</ | ||
+ | * This error could be related to the previous step we just skipped... let's reconsider that. Adding this section in our build script just before gcc stage 1: <sxh bash> | ||
+ | if [ " | ||
+ | mkdir -p $__gcc/ | ||
+ | ln -s $idir/ | ||
+ | fi</ | ||
+ | * => **same error** | ||
+ | * Trying instead to provide the cross-compiler include and lib paths when building gcc and building it completely instead of only stage 1: **same error**, but keeping this change. | ||
+ | * Now trying to simply add the missing required folder **/ | ||
+ | |||
+ | => So it turns out that when building the native compilers we use the libs created for the cross compilers. Thus, gcc canbe compiled in a **single stage**. | ||
+ | |||
+ | => Also, we don't bother compiler the CRT libraries for the native compilers, instead we simply **copy them from the cross-compiler folder**. | ||
+ | |||
+ | Now testing our new native win64 compiler on windows: **Error**: pthreads headers are not found, so we should build pthread too for the native compiler: **OK** after this change everything is fine :-) | ||
+ | |||
+ | Also testing building the win32 native compiler and testing on windows: **OK** ! (which is nice because the precompiled win32 compiler I tried before was not working !) | ||
+ | |||
+ | ====== Conclusion ====== | ||
+ | |||
+ | So, this was far less complicated than the cross-compiler build described in [[0918_buillding_mingw64_compiler_on_linux|my previous post]]: in the process I updated my build script to support building both linux and windows versions of the mingw32 and mingw64 compilers. The only important requirement one should keep in mind if trying to use those scripts is that the **linux** version of the compilers should be built before trying to build the native version, because in the native build pipeline we will simply copy some files that where previously generated in the linux hosted version. | ||
+ | |||
+ | The current scripts I use are: | ||
+ | |||
+ | <sxh bash># Helper method used to build a compiler from sources given its target architecture (either ' | ||
+ | #arg1: target architecture | ||
+ | #arg2: host version to build: " | ||
+ | nv_build_mingw_compiler() | ||
+ | { | ||
+ | local arch=" | ||
+ | local flavor=" | ||
+ | |||
+ | local sdir="/ | ||
+ | local bdir="/ | ||
+ | local compdir="/ | ||
+ | local idir=" | ||
+ | | ||
+ | local tgt=" | ||
+ | if [ " | ||
+ | tgt=" | ||
+ | fi | ||
+ | |||
+ | local build=" | ||
+ | local host=" | ||
+ | if [ " | ||
+ | host=" | ||
+ | fi | ||
+ | |||
+ | local srcfile=" | ||
+ | local __binutils=" | ||
+ | local __gmp=" | ||
+ | local __headers=" | ||
+ | local __crt=" | ||
+ | local __pthreads=" | ||
+ | local __mpfr=" | ||
+ | local __mpc=" | ||
+ | local __isl=" | ||
+ | local __gcc=" | ||
+ | |||
+ | local cpus=$(grep -c processor / | ||
+ | echo "Using $cpus CPUs" | ||
+ | |||
+ | # Remove previous stuff: | ||
+ | echo " | ||
+ | rm -Rf " | ||
+ | |||
+ | echo " | ||
+ | rm -Rf " | ||
+ | |||
+ | echo " | ||
+ | mkdir -p " | ||
+ | cd " | ||
+ | 7za x " | ||
+ | |||
+ | # Setup the directories: | ||
+ | local srcdir=" | ||
+ | | ||
+ | cd " | ||
+ | |||
+ | # Build the binutils: | ||
+ | nv_std_build $__binutils " | ||
+ | |||
+ | # We should ensure here our path contains our new compiler location: | ||
+ | # (this is the case for me so I don't need this) | ||
+ | # if [[ `echo $PATH | grep $idir/bin` == "" | ||
+ | # echo " | ||
+ | # export PATH=" | ||
+ | # fi | ||
+ | |||
+ | # Install the headers: | ||
+ | nv_std_build $__headers " | ||
+ | |||
+ | # Create the symlinks: | ||
+ | cd $idir | ||
+ | ln -s $tgt mingw | ||
+ | |||
+ | cd " | ||
+ | |||
+ | # Move dependencies into GCC folder: | ||
+ | mv $__gmp $__gcc/gmp | ||
+ | mv $__mpfr $__gcc/mpfr | ||
+ | mv $__mpc $__gcc/mpc | ||
+ | mv $__isl $__gcc/isl | ||
+ | |||
+ | # Check if we can build gcc completely: | ||
+ | local gccstage=" | ||
+ | if [ " | ||
+ | local cdir=" | ||
+ | export CFLAGS=" | ||
+ | gccstage="" | ||
+ | fi | ||
+ | |||
+ | # Build GCC, pass 1 | ||
+ | nv_std_build $__gcc " | ||
+ | |||
+ | # Reset the CFLAGS | ||
+ | export CFLAGS="" | ||
+ | |||
+ | if [ " | ||
+ | # We should be done building gcc, and we can retrieve the CRT previously compiled with the cross compiler: | ||
+ | local cdir=" | ||
+ | mkdir -p $idir/ | ||
+ | cp $cdir/ | ||
+ | else | ||
+ | # Build the crt | ||
+ | nv_std_build $__crt " | ||
+ | fi | ||
+ | |||
+ | # Build the winpthread library: | ||
+ | cd " | ||
+ | nv_std_build $__pthreads " | ||
+ | |||
+ | if [ " | ||
+ | # Finish building GCC: | ||
+ | cd " | ||
+ | make || { echo " | ||
+ | make install || { echo " | ||
+ | cd .. | ||
+ | rm -Rf build | ||
+ | fi | ||
+ | |||
+ | # Go into the compiler folder and remove the build folder: | ||
+ | cd " | ||
+ | rm -Rf " | ||
+ | |||
+ | echo "=> Compiler build SUCCESSFUL." | ||
+ | } | ||
+ | |||
+ | nv_build_linux_mingw64_compiler() | ||
+ | { | ||
+ | # nv_build_mingw_compiler " | ||
+ | nv_build_mingw_compiler " | ||
+ | } | ||
+ | |||
+ | nv_build_linux_mingw32_compiler() | ||
+ | { | ||
+ | # nv_build_mingw_compiler " | ||
+ | nv_build_mingw_compiler " | ||
+ | } | ||
+ | |||
+ | nv_build_win_mingw64_compiler() | ||
+ | { | ||
+ | nv_build_mingw_compiler " | ||
+ | } | ||
+ | |||
+ | nv_build_win_mingw32_compiler() | ||
+ | { | ||
+ | nv_build_mingw_compiler " | ||
+ | }</ | ||
+ | |||
+ | < | ||
+ | |||
+ | |||
+ | |||
+ | ~~DISCUSSION: | ||