CygwinでH8のクロスコンパイル環境を作る



Cygwin1.7になり、以前のバージョンとは少々仕様が変更となりました。
Windows上でH8のクロスコンパイル環境を作る解説サイトがありますが、少々やり方が異なるのでメモとして残しておきます。


まずはCygwinのインストーラで以下のパッケージを追加してインストールして下さい。
依存性は自動的に解決されるため、省略しましたが自動選択されたパッケージもインストールして下さい。

開発に必要な基本パッケージ
 Devel/autoconf
 Devel/automake
 Devel/binutils
 Devel/bison
 Devel/flex
 Devel/gcc4
 Devel/make
 Devel/patchutils
 Web/wget
以下binutlsのコンパイルに必要
 Devel/libiconv
以下gccのコンパイルに必要
 Devel/libelf0-devel
 Math/gmp
 Math/libgmp-devel
 Math/mpfr
 Math/libmpfr-devel
 Math/libmpc1
 Math/mpclib
 Math/libmpc-devel

以下から最新のbinutl、gcc、newlibのtar.gzをダウンロードします。
binutls:ftp://ftp.gnu.org/gnu/binutils/
gcc:ftp://ftp.gnu.org/gnu/gcc/
newlib:ftp://sources.redhat.com/pub/newlib/
そして「cygwinのインストールディレクトリ/usr/local/bin/」に保存しておきます。

cygwinを立ち上げ、以下のコマンドを実行してパッケージを解凍します。
$cd /usr/local/bin
$tar zxfv binutl*
$tar zxfv gcc*
$tar zxfv newlib*

解凍できたら、まずbinutlをmakeしてインストールします。configureはCC=gcc-4としないとコンパイラが見つからないと怒られます。
$cd binutl*
$mkdir build
$cd build
$mkdir /usr/local/h8
$ ../configure CC=gcc-4 --target=h8300-elf --prefix=/usr/local/h8
$make
$make install

–target=h8300-hmsにすると以下のように失敗します→–target=h8300-elfにする
checking whether to build static libraries... yes
Setting warning flags = -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Werro
r
checking whether byte ordering is bigendian... no
This target is no longer supported in gas
make[1]: *** [configure-gas] Error 1
make[1]: Leaving directory `/usr/local/bin/binutils-2.20/build'
make: *** [all] Error 2

gccのコンパイル ※注:10時間ぐらいかかります
–with-headersを「先ほど解凍したnewlibの絶対パス/newlib/libc/include」に変更してください。
今回はnewlib-1.18.0を使用したため以下のようにしています。
$cd /usr/local/bin/gcc*
$mkdir build
$cd build
$ ../configure --target=h8300-elf --enable-languages=c --with-newlib
 --with-headers=/usr/local/bin/newlib-1.18.0/newlib/libc/include --prefix=/usr/
local/h8
$make LANGUAGES=c


gmp, mpfr, mpcがないとこうなる。→上記のパッケージをインストールして再実行する
checking for the correct version of gmp.h... no
configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/.  See also
http://gcc.gnu.org/install/prerequisites.html for additional info.  If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.  They may be located in separate packages.

/usr/local/h8/binにパスを通す
(/etc/profileのPATH=に/usr/local/h8/binを追加)
通っていないとh8300-elf-cc: command not foundになる

newlibのコンパイル
$ ../configure --target=h8300-elf --prefix=/usr/local/h8

参考サイト:
http://www.geocities.jp/chako_ratta/micon/h8gcc_install.html
http://www.db.is.kyushu-u.ac.jp/rinkou/cygwin/gcc44cygwin.html
http://hijiri3.s65.xrea.com/sorekore/develop/h8/01_redboot.htm


追記:
・この方法では、C++のコンパイルが出来ません(=redbootなどの構築ができません)
・gcc4系ではredbootのコンパイルが通りませんでした。





コメント: