Skip to content

Instantly share code, notes, and snippets.

@YakoYakoYokuYoku
Created September 25, 2019 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YakoYakoYokuYoku/2c3b0228a04bad9c65ea5a92a6475dff to your computer and use it in GitHub Desktop.
Save YakoYakoYokuYoku/2c3b0228a04bad9c65ea5a92a6475dff to your computer and use it in GitHub Desktop.
A shell script for building MinGW-w64 in Solus
# Pretty neaty mingw-w64 shell script for Solus
# It works in other Linux distros (?)
# Set envars
DEST=/opt/mingw-solus # You can change it to whatever you want
TARGET=x86_64-w64-mingw32
PREFIX=$DEST/$TARGET
PCS=`nproc`
# Make the sys-root and build directories
mkdir $DEST
mkdir ~/Builds && cd ~/Builds
# Get the sources
wget -q ftp://gcc.gnu.org/pub/binutils/releases/binutils-2.32.tar.xz -O - | tar xJ && mv binutils-* binutils
wget -q ftp://gcc.gnu.org/pub/gcc/releases/gcc-9.2.0/gcc-9.2.0.tar.xz -O - | tar xJ && mv gcc-* gcc-9
wget -q https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/mingw-w64-v6.0.0.tar.bz2 -O - | \
tar -xj && mv mingw-* mingw
# Create a script that will help us in the Cross Toolchain and WinPThreads installation
cat >> buildhelper.sh << EOF
#!/bin/sh
export PATH=\$PATH:$DEST/bin
make install
EOF
chmod +x buildhelper.sh
# Compile, install and add Binutils to path
mkdir binutils/mgwdir && cd binutils/mgwdir
../binutils/configure --target=$TARGET --enable-targets=$TARGET,i686-w64-mingw32 --with-sysroot=$DEST --prefix=$DEST
make -j $PCS -l 95
make install
echo "export PATH=\$PATH:${DEST}/bin" >> .bashrc && source ~/.bashrc # In bash
# echo "export PATH=\$PATH:${DEST}/bin" >> .profile && source ~/.profile # In sh, ksh, zsh
# echo "setenv PATH = $PATH:$DEST/bin" >> .cshrc && source ~/.cshrc # In csh, tcsh
# echo "set PATH '$PATH' $DEST/bin" >> ~/.config/fish/config.fish && exec fish # In fish
# Compile and install the headers
mkdir ../../mingw/headdir && cd ../../mingw/headdir
../mingw-w64/mingw-w64-headers/configure --build=$TARGET --host=$TARGET --prefix=$PREFIX
make install -j $PCS -l 95
ln -s $PREFIX $DEST/mingw
mkdir -p $PREFIX/lib
ln -s $PREFIX/lib $PREFIX/lib64
# Compile and install the GCC Core
mkdir ../../gcc-9/mingw-gcc && cd ../../gcc-9/mingw-gcc
../gcc/configure --target=$TARGET --enable-targets=all --prefix=$DEST --with-sysroot=$DEST
make all-gcc -j $PCS -l 95
make install-gcc -j $PCS -l 95
# Compile and install the Cross Toolchain
mkdir ../../mingw/crtdir && cd ../../mingw/crtdir
../mingw-w64/mingw-w64-crt/configure --host=$TARGET --enable-lib32 --prefix=$PREFIX --with-sysroot=$DEST
make -j $PCS -l 95
~/Builds/buildhelper.sh
# Compile and install WinPThreads
mkdir ../pthrdir && cd ../pthrdir
../mingw-w64/mingw-w64-libraries/winpthreads/configure --prefix=$PREFIX --with-sysroot=$DEST --host=$TARGET --enable-static
make -j $PCS -l 95
make install
~/Builds/buildhelper.sh
# Compile and finish GCC
cd ../../gcc-git/mingw-gcc/
make -j $PCS -l 95
make install -j $PCS -l 95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment