1.ダウンロード&インストール
crosstool-ngの公式サイトのダウンロードページからソースアーカイブを落とします。
tarで展開して ./configure –> make –> make install の決まり文句でインストールします。
ct-ngコマンドのtab補完を使えるようにするために、makeのディレクトリで
sudo cp ct-ng.comp /etc/bash_completion.d/ct-ng
を実行します。
2.準備
crosstool-ng がクロスコンパイラをコンパイルするのに以下のパッケージが必要です。先にインストールしておく。
sudo yum install gperf bison flex help2man libtool ncurses-devel glibc-static python-devel
crosstool-ngのデータベースを更新する。
ct-ng update-samples
3.クロスコンパイラを作る
最初にct-ngの作業ディレクトリーを作ります。
mkdir gcc-arm cd gcc-arm
ct-ngの使い方を見てみます。
[gcc-arm]$ ct-ng This is crosstool-NG version crosstool-ng-1.22.0 Copyright (C) 2008 Yann E. MORIN <yann.morin.1998@free.fr> This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See below for a list of available actions, listed by category: Configuration actions: menuconfig - Update current config using a menu based program nconfig - Update current config using a menu based program oldconfig - Update current config using a provided .config as base extractconfig - Extract to stdout the configuration items from a build.log file piped to stdin savedefconfig - Save current config as a mini-defconfig to ${DEFCONFIG} defconfig - Update config from a mini-defconfig ${DEFCONFIG} (default: ${DEFCONFIG}=./defconfig) saveconfig - Save current config as a preconfigured target show-tuple - Print the tuple of the currently configured toolchain Preconfigured toolchains (#: force number of // jobs): list-samples - prints the list of all samples (for scripting) show-<sample> - show a brief overview of <sample> (list with list-samples) <sample> - preconfigure crosstool-NG with <sample> (list with list-samples) build-all[.#] - Build *all* samples (list with list-samples) and install in ${CT_PREFIX} (which you must set) Build actions (#: force number of // jobs): source - Download sources for currently configured toolchain build[.#] - Build the currently configured toolchain list-steps - List all build steps Clean actions: clean - Remove generated files distclean - Remove generated files, configuration and build directories Distribution actions: check-samples - Verify if samples need updates due to Kconfig changes update-samples - Regenerate sample configurations using the current Kconfig wiki-samples - Print a DokuWiki table of samples updatetools - Update the config tools Environment variables (see /usr/local/share/doc/crosstool-ng/crosstool-ng-1.22.0/0 - Table of content.txt): STOP=step - Stop the build just after this step (list with list-steps) RESTART=step - Restart the build just before this step (list with list-steps) CT_PREFIX=dir - install samples in dir (see action "build-all", above). V=0|1|2|<unset> - <unset> show only human-readable messages (default) 0 => do not show commands or human-readable message 1 => show only the commands being executed 2 => show both Use action "menuconfig" to configure your toolchain Use action "build" to build your toolchain Use action "version" to see the version See "man 1 ct-ng" for some help as well
list-samplesでインストールできるクロスコンパイラを見てみます。
[gcc-arm]$ ct-ng list-samples Status Sample name LN config MKDIR config.gen IN config.gen/arch.in IN config.gen/kernel.in IN config.gen/cc.in IN config.gen/binutils.in IN config.gen/libc.in IN config.gen/debug.in [G..] alphaev56-unknown-linux-gnu [G..] alphaev67-unknown-linux-gnu [G..] arm-bare_newlib_cortex_m3_nommu-eabi [G..] arm-cortex_a15-linux-gnueabi [G.X] arm-cortexa5-linux-uclibcgnueabihf [G..] arm-cortex_a8-linux-gnueabi [G.X] arm-cortexa9_neon-linux-gnueabihf [G..] armeb-unknown-eabi [G..] armeb-unknown-linux-gnueabi [G..] armeb-unknown-linux-uclibcgnueabi [G..] arm-unknown-eabi [G..] arm-unknown-linux-gnueabi [G.X] arm-unknown-linux-musleabi [G..] arm-unknown-linux-uclibcgnueabi [G.X] arm-unknown-linux-uclibcgnueabihf [G..] armv6-rpi-linux-gnueabi [G..] armv7-rpi2-linux-gnueabihf [G..] avr [G..] i586-geode-linux-uclibc [G..] i586-mingw32msvc,i686-none-linux-gnu [G..] i686-nptl-linux-gnu [G.X] i686-w64-mingw32 [G..] m68k-unknown-elf [G..] m68k-unknown-uclinux-uclibc [G..] mips64el-n32-linux-uclibc [G..] mips64el-n64-linux-uclibc [G..] mips-ar2315-linux-gnu [G..] mipsel-sde-elf [G..] mipsel-unknown-linux-gnu [G..] mips-malta-linux-gnu [G..] mips-unknown-elf [G..] mips-unknown-linux-uclibc [G.X] i686-w64-mingw32,nios2-spico-elf [G..] powerpc-405-linux-gnu [G..] powerpc64-unknown-linux-gnu [G..] powerpc-860-linux-gnu [G..] powerpc-e300c3-linux-gnu [G..] powerpc-e500v2-linux-gnuspe [G..] powerpc-unknown-linux-gnu [G..] powerpc-unknown-linux-uclibc [G..] powerpc-unknown_nofpu-linux-gnu [G.X] s390-ibm-linux-gnu [G..] s390x-ibm-linux-gnu [G..] sh4-unknown-linux-gnu [G..] sparc-unknown-linux-gnu [G.X] x86_64-w64-mingw32,x86_64-pc-linux-gnu [G..] x86_64-unknown-linux-gnu [G..] x86_64-unknown-linux-uclibc [G.X] x86_64-w64-mingw32 [G..] xtensa-unknown-linux-uclibc L (Local) : sample was found in current directory G (Global) : sample was installed with crosstool-NG X (EXPERIMENTAL): sample may use EXPERIMENTAL features B (BROKEN) : sample is currently broken
Raspberry Pi2用のものを作るのでarmv7-rpi2-linux-gnueabihfを選択します。
[gcc-arm]$ ct-ng armv7-rpi2-linux-gnueabihf CONF config/config.in # # configuration written to .config # *********************************************************** Initially reported by: Frederick Zhang <frederick888@tsundere.moe> URL: https://blog.onee3.org Comment: crosstool-NG configuration for Raspberry Pi 2 (Raspbian Jessie). Adjust the settings as you need. *********************************************************** Now configured for "armv7-rpi2-linux-gnueabihf" [gcc-arm]$
選んだサンプルをセッティングします
[gcc-arm]$ ct-ng menuconfig
メインメニュー (方向キーで移動、Enterで選択、Esc 2回押しで戻る)
デフォルトではホームディレクトリ下のx-toolsにインストールする。/opt/gcc-arm にインストールしたいのでPaths and misc optionsの設定を変えます。
ちなみに、ct-ngはroot権限で実行できない。ユーザー権限では/optに書き込めないので、ここで直接に/optにインストールするためchownで一時的/optのownerを変えました。
ほかにいろいろ設定があるので、必要に応じて設定できます。
設定が終わったら、Saveを選択して保存してメニューを終了します。 ct-ng build を打ち込んでクロスコンパイラのインストール作業を始めます
[gcc-arm]$ ct-ng build
手順は以上で全部です。あとはBuildが終わるのを待つだけ。Core i5のノートパソコンでのBuildは1時間位かかりました。
Buildが終わったあと、/opt/gcc-arm/binをPathに追加する。
cd /etc/profile.d echo "# GCC-ARM" >> opt-path.sh echo "export PATH=$PATH:/opt/gcc-arm/bin" >> opt-path.sh
これでARM のクロスコンパイラが使えるようになりました
テストにプログラムをコンパイルしてみる。
#include <stdio.h> int main(void) { printf("Hello ARM.\n"); return 0; }
クロスコンパイラでコンパイルする
armv7-rpi2-linux-gnueabihf-gcc -Wall -O2 -o arm-test arm-test.c
Raspberry Pi2で問題なく実行できました
pi@s03 $~ ./arm-test Hello ARM.