On Tue, 23 Apr 2019, Kacvinsky, Tom wrote:
HI
-----Original Message-----
From: Liu Hao <[email protected]>
Sent: Monday, April 22, 2019 10:18 PM
To: [email protected]
Subject: Re: [Mingw-w64-public] PKGBUILD script for toolchain, still having
GCC compile errors
在 2019/4/23 上午5:12, Martin Storsjö 写道:
I haven't looked into how exactly that PKGBUILD file works and how it
behaves wrt compiling new runtime files with the new compiler, new
headers and libs from the new sysroot etc, so I can't comment on that
unfortunately.
// Martin
PKGBUILD scripts are nothing but a shell script containing a few functions and
variables, whose names are hardcoded such that 'makepkg'
recognizes them.
I did change the PKGBUILD script for mingw-w64-crt-git to use
--with-default-msvcrt=ucrt
but it did not take like it does when building the CRT outside of makepkg, so I
still think
there is something wrong. Not sure if the right branch is being checked out
from the repo,
or exactly what it is.
I can try building the CRT outside of makepkg and see how I fare.
I tried bootstrapping a new separate install of gcc into a new sysroot all
within msys, in the same way as I bootstrap cross toolchains on linux. It
almost works, except for building some of the ADA tools. I tried just
copying in gnatmake/gnatbind/gnatlink from the existing msys environment
though, and that works, even if it is very ugly...
You can have a look at the full toolchain at
https://martin.st/temp/mingw-native.zip. My instructions/notes for how I
tried to build it are attached, and also available at
https://martin.st/temp/gcc-ucrt.txt in case the mailing list eats the
attachment. I haven't rerun/rechecked the instructions properly yet, but
they're just notes from what I'm trying to run while building this.
The gist of it is: Build new binutils and the host part of gcc into a new
sysroot. Install the mingw crt into the same sysroot. Build the runtime
parts of gcc using that same crt and install into the sysroot. Done.
All of this works splendidly, except for the ada parts, which I'm woefully
unfamiliar with.
With this toolchain, I'm able to do "gnatmake hello.adb", which produces a
hello.exe that links against the UCRT DLLs.
But like I said, the bin/gnatmake.exe, bin/gnatlink.exe and
bin/gnatbind.exe are just hacked around from my msys2 executables so far.
// Martin
# In a msys2/mingw64 command prompt:
mkdir -p /c/code/gcc-bootstrap
cd /c/code/gcc-bootstrap
# Building the new gcc and its sysroot using the existing msys2/mingw64
# gcc installation:
# $ which gcc
# /mingw64/bin/gcc
# $ gcc --version
# gcc.exe (Rev2, Built by MSYS2 project) 7.3.0
export TOOLCHAIN_PREFIX=/c/code/mingw-native
export TARGET_TRIPLET=x86_64-w64-mingw32
# Build libraries that GCC needs. These can also potentially be found
# from the msys2/mingw64 installation, and that should probably also
# work just as well.
export DEPENDS_PREFIX=/c/code/gcc-depends
wget http://ftp.funet.fi/pub/gnu/gnu/gmp/gmp-6.1.2.tar.bz2
tar -jxvf gmp-6.1.2.tar.bz2
cd gmp-6.1.2
./configure --prefix=$DEPENDS_PREFIX --disable-shared
make -j$(nproc)
make install
cd ..
wget http://ftp.funet.fi/pub/gnu/gnu/mpfr/mpfr-4.0.2.tar.bz2
tar -jxvf mpfr-4.0.2.tar.bz2
cd mpfr-4.0.2
./configure --prefix=$DEPENDS_PREFIX --with-gmp=$DEPENDS_PREFIX --disable-shared
make -j$(nproc)
make install
cd ..
wget http://www.multiprecision.org/downloads/mpc-1.1.0.tar.gz
tar -zxvf mpc-1.1.0.tar.gz
cd mpc-1.1.0
./configure --prefix=$DEPENDS_PREFIX --with-gmp=$DEPENDS_PREFIX --disable-shared
make -j$(nproc)
make install
cd ..
# End of optional section.
wget http://ftp.funet.fi/pub/gnu/gnu/binutils/binutils-2.32.tar.bz2
tar -jxvf binutils-2.32.tar.bz2
cd binutils-2.32
mkdir build
cd build
../configure --prefix=$TOOLCHAIN_PREFIX --target=$TARGET_TRIPLET
--disable-werror --disable-multilib
make -j$(nproc)
make install-strip
cd ../..
# Clone mingw-w64; using a recent known-good version from the master branch.
# The v6.x branch should also probably be good for ucrt, but the master branch
# is certainly good at least.
git clone git://git.code.sf.net/p/mingw-w64/mingw-w64
cd mingw-w64
git checkout 69af6ee195e65a29acc02a49119a833606424a1b
cd mingw-w64-headers
mkdir build
cd build
../configure --prefix=$TOOLCHAIN_PREFIX/$TARGET_TRIPLET
--with-default-msvcrt=ucrt
make install
cd ../../..
# Build GCC; build the compiler itself and all tools, using the existing
# msys2/mingw64 compiler, having that compiler itself link against the
# CRT that it defaults to. This compiler will be set up that the code
# it produces uses UCRT though.
# Using GCC 7.3 to match the msys2/mingw64 gnat compiler. This might not
# be necessary; when building a cross compiler it seemed like it was
# necessary at least.
wget http://ftp.funet.fi/pub/gnu/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.xz
tar -Jxvf gcc-7.3.0.tar.xz
cd gcc-7.3.0 && \
mkdir build
cd build
../configure --prefix=$TOOLCHAIN_PREFIX --target=$TARGET_TRIPLET
--enable-languages=c,c++,ada --disable-multilib --with-gmp=$DEPENDS_PREFIX
--with-native-system-header-dir=$TOOLCHAIN_PREFIX/$TARGET_TRIPLET/include
# Maybe this could be all-host/install-strip-host instead?
make -j$(nproc) all-gcc
make install-strip-gcc
cd ../..
# Now build the CRT runtimes using the newly built C/C++ compiler.
# Add the new toolchain/compiler to the PATH.
export PATH=$TOOLCHAIN_PREFIX/bin:$PATH
# $ which gcc
# /c/code/mingw-native/bin/gcc
# $ gcc --version
# gcc.exe (GCC) 7.3.0
cd mingw-w64/mingw-w64-crt
mkdir build
cd build
../configure --prefix=$TOOLCHAIN_PREFIX/$TARGET_TRIPLET --disable-lib32
--enable-lib64 --with-default-msvcrt=ucrt
make -j$(nproc)
make install
cd ../../..
# Build the libgcc/libstdc++ runtimes, with the new toolchain and its
# new sysroot (defaulting to UCRT).
cd gcc-7.3.0/build
make -j$(nproc) all-target
make install-target
cd ../..
# TODO: Build the gnattools. This currently fails, with linker errors,
# unable to find crt2.o, -lintl and other libs. Parts of it can be
# fixed by tweaking the install prefix of binutils to not use a msys2
# style absolute path (like /c/code...), but that doesn't fix all of it.
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public