Skip to content

Instantly share code, notes, and snippets.

@henry0312
Created November 27, 2011 06:19
Show Gist options
  • Save henry0312/1397083 to your computer and use it in GitHub Desktop.
Save henry0312/1397083 to your computer and use it in GitHub Desktop.
Build MinGW Cross Compiler on Mac OS X Lion
#!/bin/sh
# 初期設定
WORK=$HOME/Builds/GCC
PREFIX=$HOME/mingw
export PATH="$HOME/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"
# ソースコードのダウンロード
if [ ! -d $WORK/src ] ; then
mkdir src
fi
cd $WORK/src
curl -O ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.6.3/gcc-4.6.3.tar.bz2
curl -O ftp://ftp.gnu.org/gnu/binutils/binutils-2.22.tar.bz2
wget -O mingw-w64-v2.0.1.tar.gz "http://downloads.sourceforge.net/project/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v2.0.1.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmingw-w64%2Ffiles%2Fmingw-w64%2Fmingw-w64-release%2F&ts=1322327118&use_mirror=jaist"
# パッチのダウンロード
if [ ! -d $WORK/patch ] ; then
mkdir patch
fi
cd $WORK/patch
## Pthreadsのコンパイル&インストール お気に入りの動画を携帯で見よう
## http://blog.k-tai-douga.com/article/39079027.html
curl -O http://abechin.sakura.ne.jp/sblo_files/k-tai-douga/ffmpeg/pthreads-20110706.diff
# pthreads リポジトリを更新
cd $WORK/src/pthreads
if [ -d pthreads ] ; then
rm -fr pthreads
fi
cvs update -dP
## リリース用のディレクトリを作る
cvs export -D tomorrow pthreads
mv pthreads $WORK
## パッチを当てる
cd $WORK/pthreads
patch -p1 < $WORK/patch/pthreads-20110706.diff
# ソースの展開
## gcc
cd $WORK
tar xjf src/gcc-*
cd gcc-*
mkdir build
## binutils
cd $WORK
tar xjf src/binutils-*
cd binutils-*
mkdir build
## mingw-w64
cd $WORK
tar xzf src/mingw-w64-*
cd mingw-w64-*
mkdir build-headers
mkdir build-crt
for tg in i686-w64-mingw32 x86_64-w64-mingw32
do
export PATH=$PATH:$PREFIX/bin
# pthreds
cd $WORK/pthreads
make CROSS=${tg}- clean GC-static
cp -f libpthreadGC2.a $PREFIX/$tg/lib/libpthread.a
cp -f pthread.h sched.h semaphore.h $PREFIX/$tg/include/
# binutils
cd $WORK/binutils-*/build
../configure\
--target=$tg\
--disable-multilib\
--with-sysroot=$PREFIX\
--prefix=$PREFIX\
--with-windres\
--disable-shared
make -j4 && make install
rm -fr *
# mingw-w64-headers
cd $WORK/mingw-w64-*/build-headers
../mingw-w64-headers/configure\
--host=$tg\
--prefix=$PREFIX
make -j4 && make install
rm -fr *
cd $PREFIX
ln -s $tg mingw
# GCC 1回目
## Installing GCC: Configuration
## http://gcc.gnu.org/install/configure.html
cd $WORK/gcc-*/build
../configure\
--with-pkgversion="henry - GCC 4.6.3 $tg"\
--prefix=$PREFIX\
--target=$tg\
--with-sysroot=$PREFIX\
--disable-debug\
--disable-multilib\
--enable-threads\
--enable-libgomp\
--enable-languages=c,c++,objc,obj-c++\
--enable-stage1-checking\
--disable-nls\
--enable-lto\
--with-system-zlib\
--with-gmp=$HOME/local\
--with-mpfr=$HOME/local\
--with-mpc=$HOME/local\
--enable-fully-dynamic-string\
--disable-shared
make all-gcc -j4 && make install-gcc
# mingw-w64-crt
cd $WORK/mingw-w64-*/build-crt
../mingw-w64-crt/configure\
--host=$tg\
--prefix=$PREFIX\
--with-sysroot=$PREFIX
make -j4 && make install
rm -fr *
# GCC 2回目
cd $WORK/gcc-*/build
make -j4 && make install
rm -fr *
rm $PREFIX/mingw
done
cd $WORK
rm -fr binutils-* gcc-* pthreads mingw-w64-v*
@henry0312
Copy link
Author

Update for gcc-4.6.3

@huashizhenhua
Copy link

good job

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