Link to this script
#
# Willus.com MSYS2 script to build gcc for Windows
#
# This install base development tools including vim
# Note:  Type "alias vi=vim" at the command line for "vi" to work
#
cd /
pacman --noconfirm -S vim base-devel git
alias vi=vim
rm -rf MINGW-packages
git clone https://github.com/msys2/MINGW-packages.git
cd /MINGW-packages/mingw-w64-gcc
#
# Stop here and fix /MINGW-packages/mingw-w64-gcc/PKGBUILD
# 1. Change line 10 to: _enable_jit=no
# 2. (In 12.2) Add 'staticlibs' to option=(...) line.
#    options=('staticlibs' '!emptydirs') # '!strip' 'debug')]
#
# Other past edits I've had to do to PKGBUILD (but have not had to do lately):
#      1. Remove patch files with jit in the name (10.3.0) (look for apply_patch_with_msg)
#           a. 0022-jit-port-libgccjit-to-Windows.patch
#           b. 0023-gcc-jit-Rename-libgccjit.dll-to-libgccjit-0.dll.patch
#      2. Change --enable-sjlj-exceptions to --disable-sjlj-exceptions (<-preferred)
#      3. make sure options line does not have 'debug' enabled:
#          options=('staticlibs' '!emptydirs') # '!strip' 'debug')]
#
# 32-bit support files
#
pacman --noconfirm -S mingw-w64-i686-toolchain
pacman --noconfirm -S mingw-w64-i686-autotools
pacman --noconfirm -S mingw-w64-i686-gperf
#
# 64-bit support files
#
pacman --noconfirm -S mingw-w64-x86_64-toolchain
pacman --noconfirm -S mingw-w64-x86_64-autotools
pacman --noconfirm -S mingw-w64-x86_64-gperf
#
# Build 64-bit chain
# Takes ~2 hours on core i9-9900 with SSD
#
# If "unmet dependencies", just use pacman -S to install them.
#
export MINGW_ARCH=mingw64
makepkg-mingw --skippgpcheck
#
# Build 32-bit chain
#
# NOTE1  For 12.2.0, the rm command below was successful.
#
# NOTE2  For the 11.3.0 build the "rm -rf src pkg" was not enough to reset
#        the build process.  I ended up re-installing MSYS2 and starting over
#        but skipping the 32-bit makepkg-mingw command.  You still need to
#        get both support sets (32-bit and 64-bit) with pacman, though.
#
rm -rf src pkg gcc-12*.xz*
#
# 32-bit build
#
export MINGW_ARCH=mingw32
makepkg-mingw --skippgpcheck
#
# Decompress .zst tar files and copy to D: drive
#
zstd -d *.zst
mkdir /d/mingw64
cp -p *.pkg.tar /d/mingw64
#
# Clean up
#
rm -rf *.pkg.tar