クロスコンパイラは https://crosstool-ng.github.io/ でダウンロードできます。
2020年4月時点での最新版 crosstool-ng-1.25.0_rc1 を展開し、フォルダ内に入ります。
$ ./bootstrap
$ ./configure –enable-local
$ make -j`nproc`
$ ./configure –enable-local
$ make -j`nproc`
PCにインストールされているパッケージが足りない場合は、その旨のエラーメッセージが表示されて、エラー終了します。
例えば、curses がない場合は、以下を追加インストールしてやり直します。
$ sudo apt install libncurses-dev
また、yacc がない場合は、以下を追加インストールしてやり直します。
$ sudo apt install bison
正常にインストールされた場合、ct-ng コマンドが使えるようになります。
以下のようにクロスコンパイラでサポートされている種類の一覧が確認できます。
$ ./ct-ng list-samples
Status Sample name
[L…] aarch64-ol7u9-linux-gnu
[L…] aarch64-rpi3-linux-gnu
[L…] aarch64-rpi4-linux-gnu
[L..X] aarch64-unknown-linux-android
[L…] aarch64-unknown-linux-gnu
[L…] aarch64-unknown-linux-uclibc
[L…] alphaev56-unknown-linux-gnu
[L…] alphaev67-unknown-linux-gnu
[L…] arc-arc700-linux-uclibc
[L…] arc-archs-linux-gnu
[L…] arc-multilib-elf32
[L…] arc-multilib-linux-gnu
[L…] arc-multilib-linux-uclibc
[L…] arm-bare_newlib_cortex_m3_nommu-eabi
[L…] arm-cortex_a15-linux-gnueabihf
[L…] arm-cortex_a8-linux-gnueabi
[L..X] arm-cortexa5-linux-uclibcgnueabihf
[L..X] arm-cortexa9_neon-linux-gnueabihf
[L..X] x86_64-w64-mingw32,arm-cortexa9_neon-linux-gnueabihf
[L…] arm-multilib-linux-uclibcgnueabi
[L…] arm-nano-eabi
[L…] arm-ol7u9-linux-gnueabi
[L…] arm-ol7u9-linux-gnueabihf
[L…] arm-picolibc-eabi
[L…] arm-unknown-eabi
[L…] arm-unknown-linux-gnueabi
[L..X] arm-unknown-linux-musleabi
[L…] arm-unknown-linux-uclibcgnueabi
[L..X] arm-unknown-linux-uclibcgnueabihf
[L…] armeb-unknown-eabi
[L…] armeb-unknown-linux-gnueabi
[L…] armeb-unknown-linux-uclibcgnueabi
[L…] armv6-nommu-linux-uclibcgnueabi
[L…] armv6-unknown-linux-gnueabi
[L…] armv6-unknown-linux-gnueabihf
[L…] armv7-rpi2-linux-gnueabihf
[L…] armv8-rpi3-linux-gnueabihf
[L…] armv8-rpi4-linux-gnueabihf
[L…] avr
[L…] i586-geode-linux-uclibc
[L…] i686-centos6-linux-gnu
[L…] i686-centos7-linux-gnu
[L…] i686-nptl-linux-gnu
[L…] i686-ubuntu14.04-linux-gnu
[L…] i686-ubuntu16.04-linux-gnu
[L..X] i686-w64-mingw32
[L…] m68k-unknown-elf
[L…] m68k-unknown-uclinux-uclibc
[L…] powerpc-unknown-linux-uclibc,m68k-unknown-uclinux-uclibc
[L…] mips-ar2315-linux-gnu
[L…] mips-malta-linux-gnu
[L…] mips-unknown-elf
[L…] mips-unknown-linux-gnu
[L…] mips-unknown-linux-uclibc
[L…] mips64-unknown-linux-gnu
[L…] mips64el-multilib-linux-uclibc
[L…] mipsel-multilib-linux-gnu
[L…] mipsel-sde-elf
[L…] mipsel-unknown-linux-gnu
[L..X] moxie-unknown-elf
[L..X] moxie-unknown-moxiebox
[L..X] x86_64-multilib-linux-uclibc,moxie-unknown-moxiebox
[L..X] msp430-unknown-elf
[L…] nios2-altera-linux-gnu
[L..X] i686-w64-mingw32,nios2-spico-elf
[L…] nios2-unknown-elf
[L…] powerpc-405-linux-gnu
[L…] powerpc-8540-linux-gnu
[L…] powerpc-860-linux-gnu
[L…] powerpc-e300c3-linux-gnu
[L…] powerpc-e500v2-linux-gnuspe
[L…] x86_64-multilib-linux-uclibc,powerpc-unknown-elf
[L…] powerpc-unknown-linux-gnu
[L…] powerpc-unknown-linux-uclibc
[L…] powerpc-unknown_nofpu-linux-gnu
[L…] powerpc64-multilib-linux-gnu
[L…] powerpc64-unknown-linux-gnu
[L…] powerpc64le-unknown-linux-gnu
[L…] pru
[L..X] riscv32-hifive1-elf
[L..X] riscv32-unknown-elf
[L..X] riscv64-unknown-elf
[L..X] riscv64-unknown-linux-gnu
[L..X] s390-ibm-linux-gnu
[L..X] s390-unknown-linux-gnu
[L…] s390x-ibm-linux-gnu
[L…] s390x-unknown-linux-gnu
[L…] sh-multilib-linux-gnu
[L…] sh-multilib-linux-uclibc
[L…] sh-unknown-elf
[L…] sparc-leon-linux-uclibc
[L…] sparc-unknown-linux-gnu
[L…] sparc64-multilib-linux-gnu
[L..X] tic6x-uclinux
[L…] x86_64-centos6-linux-gnu
[L…] x86_64-centos7-linux-gnu
[L…] x86_64-multilib-linux-gnu
[L..X] x86_64-multilib-linux-musl
[L…] x86_64-multilib-linux-uclibc
[L..X] x86_64-w64-mingw32,x86_64-pc-linux-gnu
[L…] x86_64-ubuntu14.04-linux-gnu
[L…] x86_64-ubuntu16.04-linux-gnu
[L…] x86_64-unknown-linux-gnu
[L…] x86_64-unknown-linux-uclibc
[L..X] x86_64-w64-mingw32
[L..X] xtensa-fsf-elf
[L…] xtensa-fsf-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
O (OBSOLETE) : sample needs to be upgraded
Status Sample name
[L…] aarch64-ol7u9-linux-gnu
[L…] aarch64-rpi3-linux-gnu
[L…] aarch64-rpi4-linux-gnu
[L..X] aarch64-unknown-linux-android
[L…] aarch64-unknown-linux-gnu
[L…] aarch64-unknown-linux-uclibc
[L…] alphaev56-unknown-linux-gnu
[L…] alphaev67-unknown-linux-gnu
[L…] arc-arc700-linux-uclibc
[L…] arc-archs-linux-gnu
[L…] arc-multilib-elf32
[L…] arc-multilib-linux-gnu
[L…] arc-multilib-linux-uclibc
[L…] arm-bare_newlib_cortex_m3_nommu-eabi
[L…] arm-cortex_a15-linux-gnueabihf
[L…] arm-cortex_a8-linux-gnueabi
[L..X] arm-cortexa5-linux-uclibcgnueabihf
[L..X] arm-cortexa9_neon-linux-gnueabihf
[L..X] x86_64-w64-mingw32,arm-cortexa9_neon-linux-gnueabihf
[L…] arm-multilib-linux-uclibcgnueabi
[L…] arm-nano-eabi
[L…] arm-ol7u9-linux-gnueabi
[L…] arm-ol7u9-linux-gnueabihf
[L…] arm-picolibc-eabi
[L…] arm-unknown-eabi
[L…] arm-unknown-linux-gnueabi
[L..X] arm-unknown-linux-musleabi
[L…] arm-unknown-linux-uclibcgnueabi
[L..X] arm-unknown-linux-uclibcgnueabihf
[L…] armeb-unknown-eabi
[L…] armeb-unknown-linux-gnueabi
[L…] armeb-unknown-linux-uclibcgnueabi
[L…] armv6-nommu-linux-uclibcgnueabi
[L…] armv6-unknown-linux-gnueabi
[L…] armv6-unknown-linux-gnueabihf
[L…] armv7-rpi2-linux-gnueabihf
[L…] armv8-rpi3-linux-gnueabihf
[L…] armv8-rpi4-linux-gnueabihf
[L…] avr
[L…] i586-geode-linux-uclibc
[L…] i686-centos6-linux-gnu
[L…] i686-centos7-linux-gnu
[L…] i686-nptl-linux-gnu
[L…] i686-ubuntu14.04-linux-gnu
[L…] i686-ubuntu16.04-linux-gnu
[L..X] i686-w64-mingw32
[L…] m68k-unknown-elf
[L…] m68k-unknown-uclinux-uclibc
[L…] powerpc-unknown-linux-uclibc,m68k-unknown-uclinux-uclibc
[L…] mips-ar2315-linux-gnu
[L…] mips-malta-linux-gnu
[L…] mips-unknown-elf
[L…] mips-unknown-linux-gnu
[L…] mips-unknown-linux-uclibc
[L…] mips64-unknown-linux-gnu
[L…] mips64el-multilib-linux-uclibc
[L…] mipsel-multilib-linux-gnu
[L…] mipsel-sde-elf
[L…] mipsel-unknown-linux-gnu
[L..X] moxie-unknown-elf
[L..X] moxie-unknown-moxiebox
[L..X] x86_64-multilib-linux-uclibc,moxie-unknown-moxiebox
[L..X] msp430-unknown-elf
[L…] nios2-altera-linux-gnu
[L..X] i686-w64-mingw32,nios2-spico-elf
[L…] nios2-unknown-elf
[L…] powerpc-405-linux-gnu
[L…] powerpc-8540-linux-gnu
[L…] powerpc-860-linux-gnu
[L…] powerpc-e300c3-linux-gnu
[L…] powerpc-e500v2-linux-gnuspe
[L…] x86_64-multilib-linux-uclibc,powerpc-unknown-elf
[L…] powerpc-unknown-linux-gnu
[L…] powerpc-unknown-linux-uclibc
[L…] powerpc-unknown_nofpu-linux-gnu
[L…] powerpc64-multilib-linux-gnu
[L…] powerpc64-unknown-linux-gnu
[L…] powerpc64le-unknown-linux-gnu
[L…] pru
[L..X] riscv32-hifive1-elf
[L..X] riscv32-unknown-elf
[L..X] riscv64-unknown-elf
[L..X] riscv64-unknown-linux-gnu
[L..X] s390-ibm-linux-gnu
[L..X] s390-unknown-linux-gnu
[L…] s390x-ibm-linux-gnu
[L…] s390x-unknown-linux-gnu
[L…] sh-multilib-linux-gnu
[L…] sh-multilib-linux-uclibc
[L…] sh-unknown-elf
[L…] sparc-leon-linux-uclibc
[L…] sparc-unknown-linux-gnu
[L…] sparc64-multilib-linux-gnu
[L..X] tic6x-uclinux
[L…] x86_64-centos6-linux-gnu
[L…] x86_64-centos7-linux-gnu
[L…] x86_64-multilib-linux-gnu
[L..X] x86_64-multilib-linux-musl
[L…] x86_64-multilib-linux-uclibc
[L..X] x86_64-w64-mingw32,x86_64-pc-linux-gnu
[L…] x86_64-ubuntu14.04-linux-gnu
[L…] x86_64-ubuntu16.04-linux-gnu
[L…] x86_64-unknown-linux-gnu
[L…] x86_64-unknown-linux-uclibc
[L..X] x86_64-w64-mingw32
[L..X] xtensa-fsf-elf
[L…] xtensa-fsf-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
O (OBSOLETE) : sample needs to be upgraded
対象となるプロセッサーがSuperHの場合、以下のように設定を読み込み、設定を変更します。
$ ./ct-ng sh-multilib-linux-gnu
$ ./ct-ng menuconfig
$ ./ct-ng menuconfig
バージョン3のような古いLinuxカーネルの場合、linuxカーネルとgccコンパイラが一番古いものを以下のように変更します。
$ ./ct-ng build
設定が完了したら、上記のようにビルドをします。
基本的にデフォルトの設定では上記のようにビルドが成功します。
実行ファイルは以下にインストールされますので、PATHを追加します。
$ ls ~/x-tools/sh-multilib-linux-gnu/bin
sh-multilib-linux-gnu-addr2line sh-multilib-linux-gnu-gcov-dump
sh-multilib-linux-gnu-ar sh-multilib-linux-gnu-gcov-tool
sh-multilib-linux-gnu-as sh-multilib-linux-gnu-gprof
sh-multilib-linux-gnu-c++ sh-multilib-linux-gnu-ld
sh-multilib-linux-gnu-c++filt sh-multilib-linux-gnu-ld.bfd
sh-multilib-linux-gnu-cc sh-multilib-linux-gnu-ldd
sh-multilib-linux-gnu-cpp sh-multilib-linux-gnu-nm
sh-multilib-linux-gnu-ct-ng.config sh-multilib-linux-gnu-objcopy
sh-multilib-linux-gnu-elfedit sh-multilib-linux-gnu-objdump
sh-multilib-linux-gnu-g++ sh-multilib-linux-gnu-populate
sh-multilib-linux-gnu-gcc sh-multilib-linux-gnu-ranlib
sh-multilib-linux-gnu-gcc-6.5.0 sh-multilib-linux-gnu-readelf
sh-multilib-linux-gnu-gcc-ar sh-multilib-linux-gnu-size
sh-multilib-linux-gnu-gcc-nm sh-multilib-linux-gnu-strings
sh-multilib-linux-gnu-gcc-ranlib sh-multilib-linux-gnu-strip
sh-multilib-linux-gnu-gcov
sh-multilib-linux-gnu-addr2line sh-multilib-linux-gnu-gcov-dump
sh-multilib-linux-gnu-ar sh-multilib-linux-gnu-gcov-tool
sh-multilib-linux-gnu-as sh-multilib-linux-gnu-gprof
sh-multilib-linux-gnu-c++ sh-multilib-linux-gnu-ld
sh-multilib-linux-gnu-c++filt sh-multilib-linux-gnu-ld.bfd
sh-multilib-linux-gnu-cc sh-multilib-linux-gnu-ldd
sh-multilib-linux-gnu-cpp sh-multilib-linux-gnu-nm
sh-multilib-linux-gnu-ct-ng.config sh-multilib-linux-gnu-objcopy
sh-multilib-linux-gnu-elfedit sh-multilib-linux-gnu-objdump
sh-multilib-linux-gnu-g++ sh-multilib-linux-gnu-populate
sh-multilib-linux-gnu-gcc sh-multilib-linux-gnu-ranlib
sh-multilib-linux-gnu-gcc-6.5.0 sh-multilib-linux-gnu-readelf
sh-multilib-linux-gnu-gcc-ar sh-multilib-linux-gnu-size
sh-multilib-linux-gnu-gcc-nm sh-multilib-linux-gnu-strings
sh-multilib-linux-gnu-gcc-ranlib sh-multilib-linux-gnu-strip
sh-multilib-linux-gnu-gcov
gccのバージョン確認を兼ねて、gccが使えることを確認します。
$ sh-multilib-linux-gnu-gcc -m3 -ml –version
sh-multilib-linux-gnu-gcc (crosstool-NG 1.25.0_rc1) 6.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
sh-multilib-linux-gnu-gcc (crosstool-NG 1.25.0_rc1) 6.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.