mkdir toolchain
cd toolchain
mkdir build-gcc # gcc 临时构建目录
mkdir build-binutils # binutils 临时构建目录
mkdir build-gdb # gdb 临时构建目录
mkdir i686-elf-tools-windows # 工具链最终构建的目录
这一步可以使得构建出的 .exe 工具链是静态的
git clone https://github.com/mxe/mxe
cd mxe
make gcc
make gmp # 构建 gdb 可能需要
cd ..
export TARGET=i686-elf # 目标平台,另外可以用 x86_64-elf
export PREFIX="$PWD/i686-elf-tools-windows"
export PATH="$PWD/mxe/bin:$PATH"
wget https://ftp.gnu.org/gnu/binutils/binutils-2.38.tar.xz
tar xvf ./binutils-2.38.tar.xz
wget https://ftp.gnu.org/gnu/gcc/gcc-11.3.0/gcc-11.3.0.tar.xz
tar xvf ./gcc-11.3.0.tar.xz
wget https://ftp.gnu.org/gnu/gdb/gdb-11.2.tar.xz
tar xvf ./gdb-11.2.tar.xz
运行 gcc 源代码目录中自带的脚本
gcc-11.3.0/contrib/download_prerequisites
cd build-binutils
../binutils-2.38/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror --host=i686-w64-mingw32.static
make
make install
cd ..
cd build-gcc
../gcc-11.3.0/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers --host=i686-w64-mingw32.static
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc
cd ..
cd build-gdb
../gdb-11.2/configure --target=$TARGET --disable-nls --disable-werror --prefix="$PREFIX" --host=i686-w64-mingw32.static --disable-source-highlight
make
make install
cd ..
zip -r i686-elf-tools-windows.zip ./i686-elf-tools-windows
现在可以分发/拷贝 zip 包到 Windows 系统解压使用了
Just enjoy it! :)
如果要构建目标是 x86_64-elf 的工具链,那么就需要考虑 red-zone 问题,所以需要额外修改 gcc 源代码的一些配置,具体可以参考以下文章
https://wiki.osdev.org/Libgcc_without_red_zone#Preparations
或者以下脚本
https://github.com/lordmilko/i686-elf-tools/blob/master/i686-elf-tools.sh
🖊️ 本文由 Alone Café 创作,如果您觉得本文让您有所收获,请随意赞赏 🥺
⚖️ 本文以 CC BY-NC-SA 4.0,即《署名-非商业性使用-相同方式共享 4.0 国际许可协议》进行许可
👨⚖️ 本站所发表的文章除注明转载或出处外,均为本站作者原创或翻译,转载前请务必署名并遵守上述协议
🔗 原文链接:https://alone.cafe/2022/05/i686-cross-mingw-elf-gcc-build-on-linux
📅 最后更新:2022年05月01日 Sunday 15:59
Update your browser to view this website correctly. Update my browser now