背景
タイトルそのままなので省略。 なお、crosstool-ngのインストールにはhomebrewを用いた。
$ brew install crosstool-ng
crosstoo-ng version
$ brew info crosstool-ng crosstool-ng: stable 1.19.0 http://crosstool-ng.org /usr/local/Cellar/crosstool-ng/1.19.0 (1446 files, 12M) * Built from source From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/crosstool-ng.rb ==> Dependencies Build: autoconf ✔, automake ✔, libtool ✔, coreutils ✔ Required: wget ✔, gnu-sed ✔, gawk ✔, binutils ✔, libelf ✔ ==> Caveats You will need to install modern gcc compiler in order to use this tool.
進捗一覧
できたこととできなかったことの一覧
できたこと
- case-sensitive問題の回避
- gsed問題の解決
- ggrep問題の解決
挫折したところ
- static linkなバイナリの生成
進捗詳細
case-sensitive問題
crosstool-ng(以下ct-ng)はcase-sensitive――つまり大文字小文字区別できる環境でないとコンパイルさせてくれない。 Macはデフォルトではnon case-sensitiveなファイルシステムになってるので、case-sensitiveなファイルシステム環境を作って、その上でコンパイルすればこの問題を回避できる。
case-sensitiveなファイルシステム環境を作る
Macのディスクユーティリティからcase-sensitiveなディスクイメージを作ってマウントして、その上で作業を行う。 詳しい手順は以下を参照。
あとはct-ngのconfigをいじって、ソースの保存先、バイナリの保存先をすべてこのディスクイメージ上で行うようにする。
gsed問題
ct-ngはGNU-sedを使うので、環境変数を設定してNon-GNUな環境ではgsedを用いるようになっている……のだけど、一部コードがこの環境変数を使ってないのでエラーとなる。 以下のコマンドで修正する。
$ chmod +w /usr/local/Cellar/crosstool-ng/1.19.0/lib/ct-ng.1.19.0/scripts/functions $ sed -i -e "s/sed /${sed} /" /usr/local/Cellar/crosstool-ng/1.19.0/lib/ct-ng.1.19.0/scripts/functions
ggrep問題
基本的にはgsedと同じ。
$ brew install homebrew/dupes/grep $ sed -i -e "s/grep/${grep} /" /usr/local/Cellar/crosstool-ng/1.19.0/lib/ct-ng.1.19.0/scripts/functions
ただしgrepは環境変数がggrepを使うようになっていないので修正する。
$ cd /usr/local/Cellar/crosstool-ng/1.19.0/lib/ct-ng.1.19.0/ $ chmod +w paths.sh paths.mk
あとはこの2ファイルの環境変数を
export grep=/usr/bin/grep
から
export grep=ggrep
のように修正する。
static linkなバイナリの生成
ct-ngは静的リンク(static link)でプログラムをコンパイルできるかをチェックしているが、最近のMacは静的リンクができない。 これの解決方法が見つからないため挫折。
以下、その時のログ。
[DEBUG] ==> Executing: 'x86_64-build_apple-darwin13.4.0-gcc' '-O2' '-g' '-pipe' '-L/usr/local/lib' '/Volumes/case-sensitive-disk/arm-gcc/.build/arm-baremetal-eabi/build/test.c' '-static' '-o' '/Volumes/case-sensitive-disk/arm-gcc/.build/arm-baremetal-eabi/build/.gccout' [DEBUG] ld: library not found for -lcrt0.o [ERROR] collect2: error: ld returned 1 exit status
おわりに
以上、挫折しました記録です。 この後を何とか出来る人は引き継いでいただけると嬉しいです。