Published On: 1970-01-01|Last Updated: 1970-01-01|Categories: Uncategorized|
古い情報ばかりなので書いとく。Ruby のクロスコンパイル環境を構築している人が複数いるので、その辺が参考になる。

Fedora-12-i686-Live-KDE.iso を入手。

仮想マシンに CD をマウントして起動、HDD にインストールする。HDD 容量は 6-8 GiB 見ておけばよい。

ログインしているユーザーを wheel グループに追加、/etc/sudoers をいじって wheel から sudo できるようにする。

ビルドに必要らしいパッケージをインストール。

$ sudo yum install gcc getext gettext-devel texinfo flex bison bison-devel zlib-devel

インストールするディレクトリを設定する。多分なくても良い。

$ prefix=$HOME/cygwin

binutils をビルド

http://www.gnu.org/software/binutils/

$ cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src login
{enter "anoncvs" as the password}
$ cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src co binutils
$ mv src binutils
$ cd binutils
$ mkdir build
$ cd build
$ ../configure --prefix=$prefix --target=i686-pc-cygwin
$ make all install

gcc をビルド

http://gcc.gnu.org/ からソースを取得する。

Prerequisites for GCC とかあるけど他にも色々こけた。

cygwin の gcc のビルドオプションを確認(するだけ)。

$ gcc -v
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: /managed/gcc-build/final-v3-bootstrap/gcc-3.4.4-999/configure --verbose --program-suffix=-3 --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,d,f77,pascal,java,objc --enable-nls --without-included-gettext --enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptions --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: posix
gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)

まず http://x.cygwin.com/docs/cg/prog-build-cross.html を参考にして、cygwin-lib.tgz と cygwin-include.tgz を作る。

つまり Windows Cygwin 環境が必要になる。行ったり来たり。

以下のようにビルド環境に展開する。

$ cd $prefix/i686-pc-cygwin
$ tar xzf cygwin-lib.tgz
$ tar xzf cygwin-include.tgz

w32api のヘッダとライブラリの場所を指定してビルド。

stdio.h がないというので /usr/include も指定。

sudo yum install gmp-devel mpfr mpfr-devel libmpc libmpc-devel libgcc
wget ftp://ftp.dti.ad.jp/pub/lang/gcc/releases/gcc-4.5.0/gcc-core-4.5.0.tar.bz2
tar xvf gcc-core-4.5.0.tar.bz2
cd gcc-4.5.0
mkdir build
cd build
../configure --prefix=$prefix --enable-languages=c --target=i686-pc-cygwin --disable-libssp CFLAGS='-g -O2 -I/usr/include -I$prefix/i686-pc-cygwin/include/w32api' LDFLAGS='-L$prefix/i686-pc-cygwin/lib/w32api'
make all install

psignal が重複してるとか言うので gcc-4.5.0/libiberty/strsignal.c の psignal() をコメントアウトする。

HAVE_PSIGNAL は真なので何かがおかしい。

../../../libiberty/strsignal.c:554:1: error: conflicting types for ‘psignal’
/usr/include/signal.h:150:13: note: previous declaration of ‘psignal’ was here

テスト

test.c

#include <stdio.h>
int main(){ printf("Hello world!\n"); }

ビルドする。

$ $prefix/i686-pc-cygwin-gcc test.c -o test.exe

test.exe を Windows 環境で実行する。cygwin1.dll が必要。

newlib はどうすればいいんだろうか。

関連