Skip to content

Instantly share code, notes, and snippets.

@Drakulix
Last active January 9, 2020 11:49
Show Gist options
  • Save Drakulix/9881160 to your computer and use it in GitHub Desktop.
Save Drakulix/9881160 to your computer and use it in GitHub Desktop.
Script to install a Mingw-w64 Cross-Compiler Suite on Mac OS X 10.9
#!/bin/sh
# dependencies
echo "Installing dependencies via Homebrew (http://brew.sh)"
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
brew update
brew install gcc48
brew install wget
# mingw
PREFIX="/usr/local/mingw"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR
mkdir source
mkdir $PREFIX
echo "Downloading binutils\n"
cd ./source
curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.24.tar.bz2
tar xjf binutils-2.24.tar.bz2
echo "Building binutils\n"
echo "1/2 32-bit\n"
cd binutils-2.24
mkdir build
cd build
CC=gcc-4.8 CXX=g++-4.8 CPP=cpp-4.8 LD=gcc-4.8 ../configure --target=i686-w64-mingw32 --disable-werror --disable-multilib --prefix=$PREFIX --with-sysroot=$PREFIX
make -j4
make install-strip
echo "2/2 64-bit\n"
cd ..
rm -rf build
mkdir build
cd build
CC=gcc-4.8 CXX=g++-4.8 CPP=cpp-4.8 LD=gcc-4.8 ../configure --target=x86_64-w64-mingw32 --disable-werror --disable-multilib --prefix=$PREFIX --with-sysroot=$PREFIX --enable-64-bit-bfd
make -j4
make install-strip
cd ..
cd ..
echo "Downloading mingw-w64\n"
wget -O mingw-w64-v3.1.0.tar.bz2 "http://downloads.sourceforge.net/project/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v3.1.0.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmingw-w64%2Ffiles%2Fmingw-w64%2Fmingw-w64-release%2F&ts=1396199899&use_mirror=kent"
tar xjf mingw-w64-v3.1.0.tar.bz2
echo "Building mingw-headers\n"
echo "1/2 32-bit\n"
cd mingw-w64-v3.1.0
mkdir build-headers
cd build-headers
../mingw-w64-headers/configure --host=i686-w64-mingw32 --prefix=$PREFIX/i686-w64-mingw32
make -j4
make install-strip
cd $PREFIX/i686-w64-mingw32
ln -s lib lib32
cd $DIR/source/mingw-w64-v3.1.0
echo "2/2 64-bit\n"
rm -rf build-headers
mkdir build-headers
cd build-headers
../mingw-w64-headers/configure --host=x86_64-w64-mingw32 --prefix=$PREFIX/x86_64-w64-mingw32
make -j4
make install-strip
cd $PREFIX/x86_64-w64-mingw32
ln -s lib lib64
cd $DIR/source/
echo "Downloading gcc\n"
curl -O ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.8.2/gcc-4.8.2.tar.bz2
tar xjf gcc-4.8.2.tar.bz2
echo "Building core gcc\n"
echo "1/2 32-bit\n"
cd $PREFIX
ln -s i686-w64-mingw32 mingw
cd $DIR/source/gcc-4.8.2
mkdir build32
cd build32
CC=gcc-4.8 CXX=g++-4.8 CPP=cpp-4.8 LD=gcc-4.8 PATH=/usr/local/mingw/bin/:$PATH ../configure --target=i686-w64-mingw32 --disable-multilib --enable-languages=c,c++,objc,obj-c++ --with-gmp=/usr/local/Cellar/gmp4/4.3.2/ --with-mpfr=/usr/local/Cellar/mpfr2/2.4.2/ --with-mpc=/usr/local/Cellar/libmpc08/0.8.1/ --with-cloog=/usr/local/Cellar/cloog018/0.18.0/ --with-isl=/usr/local/Cellar/isl011/0.11.1/ --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --enable-threads=win32 --disable-sjlj-exceptions --prefix=$PREFIX --with-sysroot=$PREFIX
PATH=/usr/local/mingw/bin/:$PATH make all-gcc -j4
PATH=/usr/local/mingw/bin/:$PATH make install-gcc
echo "2/2 64-bit\n"
cd $PREFIX
rm mingw
ln -s x86_64-w64-mingw32 mingw
cd $DIR/source/gcc-4.8.2
mkdir build64
cd build64
CC=gcc-4.8 CXX=g++-4.8 CPP=cpp-4.8 LD=gcc-4.8 PATH=/usr/local/mingw/bin/:$PATH ../configure --target=x86_64-w64-mingw32 --disable-multilib --enable-languages=c,c++,objc,obj-c++ --with-gmp=/usr/local/Cellar/gmp4/4.3.2/ --with-mpfr=/usr/local/Cellar/mpfr2/2.4.2/ --with-mpc=/usr/local/Cellar/libmpc08/0.8.1/ --with-cloog=/usr/local/Cellar/cloog018/0.18.0/ --with-isl=/usr/local/Cellar/isl011/0.11.1/ --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --enable-threads=win32 --prefix=$PREFIX --with-sysroot=$PREFIX
PATH=/usr/local/mingw/bin/:$PATH make all-gcc -j4
PATH=/usr/local/mingw/bin/:$PATH make install-gcc
echo "Building mingw runtime\n"
cd $PREFIX
rm mingw
ln -s i686-w64-mingw32 mingw
cd $DIR/source/mingw-w64-v3.1.0
mkdir build-crt
cd build-crt
echo "1/2 32-Bit\n"
PATH=/usr/local/mingw/bin/:$PATH ../mingw-w64-crt/configure --host=i686-w64-mingw32 --prefix=$PREFIX/i686-w64-mingw32 --with-sysroot=$PREFIX
PATH=/usr/local/mingw/bin/:$PATH make
PATH=/usr/local/mingw/bin/:$PATH make install-strip
echo "2/2 64-Bit\n"
cd $PREFIX
rm mingw
ln -s x86_64-w64-mingw32 mingw
cd $DIR/source/mingw-w64-v3.1.0
rm -rf build-crt
mkdir build-crt
cd build-crt
PATH=/usr/local/mingw/bin/:$PATH ../mingw-w64-crt/configure --host=x86_64-w64-mingw32 --prefix=$PREFIX/x86_64-w64-mingw32 --with-sysroot=$PREFIX
PATH=/usr/local/mingw/bin/:$PATH make
PATH=/usr/local/mingw/bin/:$PATH make install-strip
echo "Building all gcc\n"
echo "1/2 32-Bit\n"
cd $PREFIX
rm mingw
ln -s i686-w64-mingw32 mingw
cd $DIR/source/gcc-4.8.2/build32
PATH=/usr/local/mingw/bin/:$PATH make
PATH=/usr/local/mingw/bin/:$PATH make install-strip
echo "2/2 64-Bit\n"
cd $PREFIX
rm mingw
ln -s x86_64-w64-mingw32 mingw
cd $DIR/source/gcc-4.8.2/build64
PATH=/usr/local/mingw/bin/:$PATH make
PATH=/usr/local/mingw/bin/:$PATH make install-strip
echo "Linking libgcc\n"
cd $PREFIX/i686-w64-mingw32/lib
ln -s ../../lib/gcc/i686-w64-mingw32/lib/libgcc_s.a ./
cd $PREFIX/x86_64-w64-mingw32/lib
ln -s ../../lib/gcc/x86_64-w64-mingw32/lib/libgcc_s.a ./
echo "Building winpthreads\n"
cd $DIR/source/mingw-w64-v3.1.0/mingw-w64-libraries/winpthreads
echo "1/2 32-Bit\n"
mkdir build
cd build
../configure --host=i686-w64-mingw32 --prefix=$PREFIX/i686-w64-mingw32
make
make install-strip
cd ..
rm -rf build
echo "2/2 64-Bit\n"
mkdir build
cd build
../configure --host=x86_64-w64-mingw32 --prefix=$PREFIX/x86_64-w64-mingw32
make
make install-strip
echo "Cleaning up\n"
cd $DIR
rm -rf source
echo "Done"
@maelvls
Copy link

maelvls commented Mar 15, 2015

And at the end, I did:

ln -s /usr/local/mingw/bin/* /usr/local/bin/

And I checked if echo $PATH had /usr/local/bin in it:

echo $PATH
/opt/local/bin:/opt/local/sbin:/Users/maelv/.opam/system/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin:.:.

@stavinsky
Copy link

Thanks a lot! I compiled all of this staff with newest versions of packages (except gcc ). And it works. Only one remark: to compile last lib winpthreads I added PATH before run configure to prevent include errors.

PATH=/usr/local/mingw/bin/:$PATH \
 ../configure --host=i686-w64-mingw32 --prefix=$PREFIX/i686-w64-mingw32

Also I was looking for possibility to use std::thread. I found the solution. If you prefer to use this instead of win32 you need to change --enable-threads=win32 to --enable-threads=posix and recompile gcc-core, mingw, gcc all.

@JoshuaPettus
Copy link

Great script! I played with maelvalals version to make a macports version, learning a lot of new things about bash in the process. :) (the macports port of mingw is quite a bit out of date and doesn't have a 64 bit version) Also updated it to gcc-4.9.3,MinGW-4.0.4 and Binutils-2.25.1, because why not? Also fixed a few typos with the zip check.
There is some sort of bug with macports gmp version so I had to make it use the the built-in apple one.

#!/bin/sh

# check_error my_cmd --param ...
check_error() {
  $* # we execute everything
  if [ $? -ne 0 ]; then
    echo "check_error(): Error in the last command:"
    echo "check_error(): $*"
    echo "check_error(): Continue? y/n"
    read a
    if [ $a != "y" ]; then
      exit
    fi
    echo "check_error(): Yes continue..."
  else
    echo "check_error(): OK: $*"
  fi
}
# check_download "file_maybe_existing" download_cmd...
check_download() {
  file=$1
  shift
  if [ ! -f "$file" ]; then
    echo "check_download(): download of $file must be done"
    $*
  else
    echo "check_download(): $file already downloaded"
  fi
}
# check_unzip "dir_unzipped" unzip_cmd...
check_unzip() {
  unzipped=$1
  shift
  if [ ! -d "$unzipped" ]; then
    echo "check_unzip(): unzip is needed"
    $*
  else
    echo "check_unzip(): unzip not needed, the $unzipped dir already exists"
  fi
}

#  dependencies 

#echo "installing dependencies"
#check_error sudo port install gcc49 gmp mpfr libmpc
#check_error 

#  mingw

PREFIX="/usr/local/mingw"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
check_error cd $DIR

check_error mkdir source
check_error mkdir $PREFIX

echo "Downloading binutils\n"

check_error cd ./source
check_error check_download "binutils-2.25.1.tar.bz2" curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.25.1.tar.bz2
check_error check_unzip "binutils-2.25.1" tar xjf binutils-2.25.1.tar.bz2

echo "Building binutils\n"
echo "1/2 32-bit\n"

check_error cd binutils-2.25.1
check_error mkdir build
check_error cd build

CC=/opt/local/gcc-mp-4.9 CXX=/opt/local/g++-mp-4.9 CPP=/opt/local/cpp-mp-4.9 LD=/opt/local/gcc-mp-4.9

check_error ../configure --target=i686-w64-mingw32 --disable-werror --disable-multilib --prefix=$PREFIX --with-sysroot=$PREFIX
check_error make -j4
check_error make install-strip

echo "2/2 64-bit\n"
cd ..
#check_error rm -rf build
check_error mkdir build64
cd build64

CC=/opt/local/gcc-mp-4.9 CXX=/opt/local/g++-mp-4.9 CPP=/opt/local/cpp-mp-4.9 LD=/opt/local/gcc-mp-4.9
check_error ../configure --target=x86_64-w64-mingw32 --disable-werror --disable-multilib --prefix=$PREFIX --with-sysroot=$PREFIX --enable-64-bit-bfd
check_error make -j4
check_error make install-strip

check_error cd ..
check_error cd ..

echo "Downloading mingw-w64\n"

check_error check_download "mingw-w64-v4.0.4.tar.bz2" wget -O mingw-w64-v4.0.4.tar.bz2 "http://downloads.sourceforge.net/project/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v4.0.4.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmingw-w64%2Ffiles%2Fmingw-w64%2Fmingw-w64-release%2F&ts=1396199899&use_mirror=kent"

check_error check_unzip "mingw-w64-v4.0.4" tar xjf mingw-w64-v4.0.4.tar.bz2

echo "Building mingw-headers\n"

echo "1/2 32-bit\n"

check_error cd mingw-w64-v4.0.4
check_error mkdir build-headers32
check_error cd build-headers32

check_error ../mingw-w64-headers/configure --host=i686-w64-mingw32 --prefix=$PREFIX/i686-w64-mingw32
check_error make -j4
check_error make install-strip

check_error cd $PREFIX/i686-w64-mingw32
check_error ln -s lib lib32
check_error cd $DIR/source/mingw-w64-v4.0.4

echo "2/2 64-bit\n"
#check_error rm -rf build-headers
check_error mkdir build-headers64
check_error cd build-headers64

check_error ../mingw-w64-headers/configure --host=x86_64-w64-mingw32 --prefix=$PREFIX/x86_64-w64-mingw32
check_error make -j4
check_error make install-strip


check_error cd $PREFIX/x86_64-w64-mingw32
check_error ln -s lib lib64
check_error cd $DIR/source/

echo "Downloading gcc\n"

check_error check_download "gcc-4.9.3.tar.bz2" curl -O ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.9.3/gcc-4.9.3.tar.bz2

check_error check_unzip "gcc-4.9.3" tar xjf gcc-4.9.3.tar.bz2

echo "Building core gcc\n"

echo "1/2 32-bit\n"


check_error cd $PREFIX
check_error ln -s i686-w64-mingw32 mingw

check_error cd $DIR/source/gcc-4.9.3
check_error mkdir build32
check_error cd build32

echo "Something is wrong with the macports gmp. Using the built-in one instead\n"

CC=/opt/local/gcc-mp-4.9 CXX=/opt/local/g++-mp-4.9 CPP=/opt/local/cpp-mp-4.9 LD=/opt/local/gcc-mp-4.9 PATH=/usr/local/mingw/bin/:$PATH

check_error ../configure --target=i686-w64-mingw32 --disable-multilib --enable-languages=c,c++,objc,obj-c++ --with-gmp=/usr --with-mpfr=/opt/local --with-mpc=/opt/local --with-cloog=/opt/local --with-isl=/opt/local --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --enable-threads=win32 --disable-sjlj-exceptions --prefix=$PREFIX --with-sysroot=$PREFIX LDFLAGS='-I/opt/local/include'

PATH=/usr/local/mingw/bin/:$PATH
check_error make all-gcc -j4
PATH=/usr/local/mingw/bin/:$PATH
check_error make install-gcc

echo "2/2 64-bit\n"

check_error cd $PREFIX
check_error rm mingw
check_error ln -s x86_64-w64-mingw32 mingw

check_error cd $DIR/source/gcc-4.9.3
check_error mkdir build64
check_error cd build64

CC=/opt/local/gcc-mp-4.9 CXX=/opt/local/g++-mp-4.9 CPP=/opt/local/cpp-mp-4.9 LD=/opt/local/gcc-mp-4.9 PATH=/usr/local/mingw/bin/:$PATH

check_error ../configure --target=x86_64-w64-mingw32 --disable-multilib --enable-languages=c,c++,objc,obj-c++ --with-gmp=/usr --with-mpfr=/opt/local --with-mpc=/opt/local --with-cloog=/opt/local --with-isl=/opt/local --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --enable-threads=win32 --prefix=$PREFIX --with-sysroot=$PREFIX LDFLAGS='-I/opt/local/include'

PATH=/usr/local/mingw/bin/:$PATH
check_error make all-gcc -j4
PATH=/usr/local/mingw/bin/:$PATH
check_error make install-gcc

echo "Building mingw runtime\n"

check_error cd $PREFIX
check_error rm mingw
check_error ln -s i686-w64-mingw32 mingw

check_error cd $DIR/source/mingw-w64-v4.0.4
check_error mkdir build-crt32
check_error cd build-crt32

echo "1/2 32-Bit\n"

PATH=/usr/local/mingw/bin/:$PATH
check_error ../mingw-w64-crt/configure --host=i686-w64-mingw32 --prefix=$PREFIX/i686-w64-mingw32 --with-sysroot=$PREFIX

PATH=/usr/local/mingw/bin/:$PATH
check_error make
PATH=/usr/local/mingw/bin/:$PATH
check_error make install-strip

echo "2/2 64-Bit\n"

check_error cd $PREFIX
check_error rm mingw
check_error ln -s x86_64-w64-mingw32 mingw

check_error cd $DIR/source/mingw-w64-v4.0.4
#check_error rm -rf build-crt
check_error mkdir build-crt64
check_error cd build-crt64

PATH=/usr/local/mingw/bin/:$PATH

check_error ../mingw-w64-crt/configure --host=x86_64-w64-mingw32 --prefix=$PREFIX/x86_64-w64-mingw32 --with-sysroot=$PREFIX

PATH=/usr/local/mingw/bin/:$PATH
check_error make
PATH=/usr/local/mingw/bin/:$PATH
check_error make install-strip

echo "Building all gcc\n"

echo "1/2 32-Bit\n"

check_error cd $PREFIX
check_error rm mingw
check_error ln -s i686-w64-mingw32 mingw

check_error cd $DIR/source/gcc-4.9.3/build32

PATH=/usr/local/mingw/bin/:$PATH
check_error make
PATH=/usr/local/mingw/bin/:$PATH
check_error make install-strip

echo "2/2 64-Bit\n"

check_error cd $PREFIX
check_error rm mingw
check_error ln -s x86_64-w64-mingw32 mingw

check_error cd $DIR/source/gcc-4.9.3/build64

PATH=/usr/local/mingw/bin/:$PATH
check_error make
PATH=/usr/local/mingw/bin/:$PATH
check_error make install-strip

echo "Linking libgcc\n"

check_error cd $PREFIX/i686-w64-mingw32/lib
check_error ln -s ../../lib/gcc/i686-w64-mingw32/lib/libgcc_s.a ./

check_error cd $PREFIX/x86_64-w64-mingw32/lib
check_error ln -s ../../lib/gcc/x86_64-w64-mingw32/lib/libgcc_s.a ./

echo "Building winpthreads\n"
check_error cd $DIR/source/mingw-w64-v4.0.4/mingw-w64-libraries/winpthreads

echo "1/2 32-Bit\n"

check_error mkdir build32
check_error cd build32

PATH=/usr/local/mingw/bin/:$PATH \
check_error ../configure --host=i686-w64-mingw32 --prefix=$PREFIX/i686-w64-mingw32
check_error make
check_error make install-strip

check_error cd ..
#check_error rm -rf build

echo "2/2 64-Bit\n"

check_error mkdir build64
check_error cd build64

PATH=/usr/local/mingw/bin/:$PATH \
check_error ../configure --host=x86_64-w64-mingw32 --prefix=$PREFIX/x86_64-w64-mingw32
check_error make
check_error make install-strip

echo "Cleaning up\n"

check_error cd $DIR
#check_error rm -rf source

echo "Done"

@rdp
Copy link

rdp commented Sep 2, 2015

now if only homebrew had a real formula for it...

@vic3t3chn0
Copy link

!/bin/sh

check_error my_cmd --param ...

check_error() {
$* # we execute everything
if [ $? -ne 0 ]; then
echo "check_error(): Error in the last command:"
echo "check_error(): $"
echo "check_error(): Continue? y/n"
read a
if [ $a != "y" ]; then
exit
fi
echo "check_error(): Yes continue..."
else
echo "check_error(): OK: $
"
fi
}

check_download "file_maybe_existing" download_cmd...

check_download() {
file=$1
shift
if [ ! -f "$file" ]; then
echo "check_download(): download of $file must be done"
$*
else
echo "check_download(): $file already downloaded"
fi
}

check_unzip "dir_unzipped" unzip_cmd...

check_unzip() {
unzipped=$1
shift
if [ ! -d "$unzipped" ]; then
echo "check_unzip(): unzip is needed"
$*
else
echo "check_unzip(): unzip not needed, the $unzipped dir already exists"
fi
}

dependencies

sudo port select --set gcc mp-gcc48
hash gcc

echo "installing dependencies"
sudo port install gmp mpfr libmpc
check_error

mingw

PREFIX="/usr/local/mingw"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
check_error cd $DIR

check_error mkdir source
check_error mkdir $PREFIX

echo "Downloading binutils\n"

check_error cd ./source
check_error check_download "binutils-2.25.1.tar.bz2" curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.25.1.tar.bz2
check_error check_unzip "binutils-2.25.1" tar xjf binutils-2.25.1.tar.bz2

echo "Building binutils\n"
echo "1/2 32-bit\n"

check_error cd binutils-2.25.1
check_error mkdir build
check_error cd build

CC=/opt/local/gcc-mp-4.9 CXX=/opt/local/g++-mp-4.9 CPP=/opt/local/cpp-mp-4.9 LD=/opt/local/gcc-mp-4.9

check_error ../configure --target=i686-w64-mingw32 --disable-werror --disable-multilib --prefix=$PREFIX --with-sysroot=$PREFIX
check_error make -j4
check_error make install-strip

echo "2/2 64-bit\n"
cd ..

check_error rm -rf build

check_error mkdir build64
cd build64

CC=/opt/local/gcc-mp-4.9 CXX=/opt/local/g++-mp-4.9 CPP=/opt/local/cpp-mp-4.9 LD=/opt/local/gcc-mp-4.9
check_error ../configure --target=x86_64-w64-mingw32 --disable-werror --disable-multilib --prefix=$PREFIX --with-sysroot=$PREFIX --enable-64-bit-bfd
check_error make -j4
check_error make install-strip

check_error cd ..
check_error cd ..

echo "Downloading mingw-w64\n"

check_error check_download "mingw-w64-v4.0.4.tar.bz2" wget -O mingw-w64-v4.0.4.tar.bz2 "http://downloads.sourceforge.net/project/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v4.0.4.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmingw-w64%2Ffiles%2Fmingw-w64%2Fmingw-w64-release%2F&ts=1396199899&use_mirror=kent"

check_error check_unzip "mingw-w64-v4.0.4" tar xjf mingw-w64-v4.0.4.tar.bz2

echo "Building mingw-headers\n"

echo "1/2 32-bit\n"

check_error cd mingw-w64-v4.0.4
check_error mkdir build-headers32
check_error cd build-headers32

check_error ../mingw-w64-headers/configure --host=i686-w64-mingw32 --prefix=$PREFIX/i686-w64-mingw32
check_error make -j4
check_error make install-strip

check_error cd $PREFIX/i686-w64-mingw32
check_error ln -s lib lib32
check_error cd $DIR/source/mingw-w64-v4.0.4

echo "2/2 64-bit\n"

check_error rm -rf build-headers

check_error mkdir build-headers64
check_error cd build-headers64

check_error ../mingw-w64-headers/configure --host=x86_64-w64-mingw32 --prefix=$PREFIX/x86_64-w64-mingw32
check_error make -j4
check_error make install-strip

check_error cd $PREFIX/x86_64-w64-mingw32
check_error ln -s lib lib64
check_error cd $DIR/source/

echo "Downloading gcc\n"

check_error check_download "gcc-4.9.3.tar.bz2" curl -O ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.9.3/gcc-4.9.3.tar.bz2

check_error check_unzip "gcc-4.9.3" tar xjf gcc-4.9.3.tar.bz2

echo "Building core gcc\n"

echo "1/2 32-bit\n"

check_error cd $PREFIX
check_error ln -s i686-w64-mingw32 mingw

check_error cd $DIR/source/gcc-4.9.3
check_error mkdir build32
check_error cd build32

echo "Something is wrong with the macports gmp. Using the built-in one instead\n"

CC=/opt/local/gcc-mp-4.9 CXX=/opt/local/g++-mp-4.9 CPP=/opt/local/cpp-mp-4.9 LD=/opt/local/gcc-mp-4.9 PATH=/usr/local/mingw/bin/:$PATH

check_error ../configure --target=i686-w64-mingw32 --disable-multilib --enable-languages=c,c++,objc,obj-c++ --with-gmp=/usr --with-mpfr=/opt/local --with-mpc=/opt/local --with-cloog=/opt/local --with-isl=/opt/local --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --enable-threads=win32 --disable-sjlj-exceptions --prefix=$PREFIX --with-sysroot=$PREFIX LDFLAGS='-I/opt/local/include'

PATH=/usr/local/mingw/bin/:$PATH
check_error make all-gcc -j4
PATH=/usr/local/mingw/bin/:$PATH
check_error make install-gcc

echo "2/2 64-bit\n"

check_error cd $PREFIX
check_error rm mingw
check_error ln -s x86_64-w64-mingw32 mingw

check_error cd $DIR/source/gcc-4.9.3
check_error mkdir build64
check_error cd build64

CC=/opt/local/gcc-mp-4.9 CXX=/opt/local/g++-mp-4.9 CPP=/opt/local/cpp-mp-4.9 LD=/opt/local/gcc-mp-4.9 PATH=/usr/local/mingw/bin/:$PATH

check_error ../configure --target=x86_64-w64-mingw32 --disable-multilib --enable-languages=c,c++,objc,obj-c++ --with-gmp=/usr --with-mpfr=/opt/local --with-mpc=/opt/local --with-cloog=/opt/local --with-isl=/opt/local --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --enable-threads=win32 --prefix=$PREFIX --with-sysroot=$PREFIX LDFLAGS='-I/opt/local/include'

PATH=/usr/local/mingw/bin/:$PATH
check_error make all-gcc -j4
PATH=/usr/local/mingw/bin/:$PATH
check_error make install-gcc

echo "Building mingw runtime\n"

check_error cd $PREFIX
check_error rm mingw
check_error ln -s i686-w64-mingw32 mingw

check_error cd $DIR/source/mingw-w64-v4.0.4
check_error mkdir build-crt32
check_error cd build-crt32

echo "1/2 32-Bit\n"

PATH=/usr/local/mingw/bin/:$PATH
check_error ../mingw-w64-crt/configure --host=i686-w64-mingw32 --prefix=$PREFIX/i686-w64-mingw32 --with-sysroot=$PREFIX

PATH=/usr/local/mingw/bin/:$PATH
check_error make
PATH=/usr/local/mingw/bin/:$PATH
check_error make install-strip

echo "2/2 64-Bit\n"

check_error cd $PREFIX
check_error rm mingw
check_error ln -s x86_64-w64-mingw32 mingw

check_error cd $DIR/source/mingw-w64-v4.0.4

check_error rm -rf build-crt

check_error mkdir build-crt64
check_error cd build-crt64

PATH=/usr/local/mingw/bin/:$PATH

check_error ../mingw-w64-crt/configure --host=x86_64-w64-mingw32 --prefix=$PREFIX/x86_64-w64-mingw32 --with-sysroot=$PREFIX

PATH=/usr/local/mingw/bin/:$PATH
check_error make
PATH=/usr/local/mingw/bin/:$PATH
check_error make install-strip

echo "Building all gcc\n"

echo "1/2 32-Bit\n"

check_error cd $PREFIX
check_error rm mingw
check_error ln -s i686-w64-mingw32 mingw

check_error cd $DIR/source/gcc-4.9.3/build32

PATH=/usr/local/mingw/bin/:$PATH
check_error make
PATH=/usr/local/mingw/bin/:$PATH
check_error make install-strip

echo "2/2 64-Bit\n"

check_error cd $PREFIX
check_error rm mingw
check_error ln -s x86_64-w64-mingw32 mingw

check_error cd $DIR/source/gcc-4.9.3/build64

PATH=/usr/local/mingw/bin/:$PATH
check_error make
PATH=/usr/local/mingw/bin/:$PATH
check_error make install-strip

echo "Linking libgcc\n"

check_error cd $PREFIX/i686-w64-mingw32/lib
check_error ln -s ../../lib/gcc/i686-w64-mingw32/lib/libgcc_s.a ./

check_error cd $PREFIX/x86_64-w64-mingw32/lib
check_error ln -s ../../lib/gcc/x86_64-w64-mingw32/lib/libgcc_s.a ./

echo "Building winpthreads\n"
check_error cd $DIR/source/mingw-w64-v4.0.4/mingw-w64-libraries/winpthreads

echo "1/2 32-Bit\n"

check_error mkdir build32
check_error cd build32

PATH=/usr/local/mingw/bin/:$PATH
check_error ../configure --host=i686-w64-mingw32 --prefix=$PREFIX/i686-w64-mingw32
check_error make
check_error make install-strip

check_error cd ..

check_error rm -rf build

echo "2/2 64-Bit\n"

check_error mkdir build64
check_error cd build64

PATH=/usr/local/mingw/bin/:$PATH
check_error ../configure --host=x86_64-w64-mingw32 --prefix=$PREFIX/x86_64-w64-mingw32
check_error make
check_error make install-strip

echo "Cleaning up\n"

check_error cd $DIR

check_error rm -rf source

echo "Done"


I've made a few changes for yosemite. Those changes I could build successful.

@drewwells
Copy link

These scripts specifically target an older version of ISL. To install it brew install isl011 isl012 cloog018

@maelvls
Copy link

maelvls commented Feb 22, 2016

I am working on a homebrew version of this script.
EDIT: I just noticed that cosmo0920 (https://github.com/cosmo0920/homebrew-mingw_w64) has already begun to work on a brew version of this script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment