Skip to content

Instantly share code, notes, and snippets.

@kuvaldini
Created December 8, 2021 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuvaldini/52d5273613e73900d9efa88d97e406f8 to your computer and use it in GitHub Desktop.
Save kuvaldini/52d5273613e73900d9efa88d97e406f8 to your computer and use it in GitHub Desktop.
Build Linaro toolchain for Mac

Build Linaro toolchain on Mac

Prepare env

Abe requires Bash version 4+.

brew install bash
brew install autogen dejagnu coreutils gcc gawk git-new-workdir 

gcc 7 doesn’t compile with guile 2.2, so you have to downgrade it:

brew uninstall --ignore-dependencies guile
brew install guile@2.0

Be aware that guile will live /usr/local/opt/guile@2.0 and you need additional actions to move it to /usr/local

export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
==> Caveats
guile@2.0 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have guile@2.0 first in your PATH run:
  echo 'export PATH="/usr/local/opt/guile@2.0/bin:$PATH"' >> ~/.bash_profile

For compilers to find guile@2.0 you may need to set:
  export LDFLAGS="-L/usr/local/opt/guile@2.0/lib"
  export CPPFLAGS="-I/usr/local/opt/guile@2.0/include"

For pkg-config to find guile@2.0 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/guile@2.0/lib/pkgconfi

If met date: illegal option -- -

ln -s gdate /usr/local/bin/date

Get ABE

git clone https://git.linaro.org/toolchain/abe.git --depth 1 --single-branch -b master
cd abe

Make sure /bin/sh and /bin/bash are pointing to /usr/local/bin/bash or modify shebangs in scripts.
On MacOS /bin/bash is very old version 3.2.57 (2007).
Modify shebangs in Abe's Bash scripts:

find . -name '*.sh' -type f -print0 | xargs -0 sed -i '' -e 's|#!/bin/bash|#!/usr/bin/env bash|g' -e 's|#!/bin/sh|#!/usr/bin/env bash|g'

Prepare build

$ cd ..
$ mkdir build
$ cd build
$ ../abe/configure

If you met error about epsond git-new-workdir fix it with

curl -L https://raw.githubusercontent.com/git/git/master/contrib/workdir/git-new-workdir >/usr/local/bin/git-new-workdir && chmod +x /usr/local/bin/git-new-workdir 

For 5.2:

Open /abe/config/sources.conf and change gcc url to ‘http://snapshots.linaro.org/components/toolchain/gcc-linaro/5.2-2015.11’

Build

# look at this link or the similar one for other version
# you’re interested in xxx_revision and xxx_filespec values, replace then in following command if needed 
$ ../abe/abe.sh --target arm-linux-gnueabihf gcc=gcc.git@5104f2473987407575bfc63ee965394252433bb5 binutils=binutils-gdb.git@e0f59b0a7b5a2d879b0afc665ca0f28fb5b3d54e glibc=glibc.git@02aaa3c749bf18a3dbafff4c1f0180f135cad7ed --release 2017.08 --tarbin --build all

#  we probably should replace --build all with --checkout all in previous command:
$ ../abe/abe.sh --target arm-linux-gnueabihf gcc=gcc.git@5104f2473987407575bfc63ee965394252433bb5 binutils=binutils-gdb.git@e0f59b0a7b5a2d879b0afc665ca0f28fb5b3d54e glibc=glibc.git@02aaa3c749bf18a3dbafff4c1f0180f135cad7ed --release 2017.08 --tarbin --checkout all

For 5.2:

../abe/abe.sh --target arm-linux-gnueabihf gcc=gcc-linaro-snapshot-5.2-2015.11.tar.xz binutils=binutils-gdb.git@ef90a4718f535cbe6345b4e7168baea7b1972abf glibc=glibc.git@dbcaca73cb0a19698ea1b424087e8997a9b7c3c4 --release 2015.11 --tarbin --checkout all

# you should fail :D
# patch ./snapshots/glibc.git~master_rev_<revision>/sunrpc/Makefile: add “BUILD_LDFLAGS += -L/usr/local/lib -lintl” near BUILD_ CPPFLAGS
# restart build without downloading
$ ../abe/abe.sh --disable update --target arm-linux-gnueabihf gcc=gcc.git@5104f2473987407575bfc63ee965394252433bb5 binutils=binutils-gdb.git@e0f59b0a7b5a2d879b0afc665ca0f28fb5b3d54e glibc=glibc.git@02aaa3c749bf18a3dbafff4c1f0180f135cad7ed --release 2017.08 --tarbin --build all

For 5.2

../abe/abe.sh --disable update --target arm-linux-gnueabihf gcc=gcc-linaro-snapshot-5.2-2015.11.tar.xz binutils=binutils-gdb.git@ef90a4718f535cbe6345b4e7168baea7b1972abf glibc=glibc.git@dbcaca73cb0a19698ea1b424087e8997a9b7c3c4 --release 2015.11 --tarbin --build all

For 5.2

You should fail

Open ‘builds/<host_arch>/binutils<revision>/gold/Makefile’ or `/snapshots/binutils-gdb.git~master_rev_<revision>/gold/Makefile.in` and add ‘diststuff: $(EXTRA_DIST) info’ to line ~1331

For 5.2

Goto makefiles and replace this:

gperf -o -C -E -k '1-6,$$' -j1 -D -N 'libc_name_p' -L ANSI-C

to this:

gperf -o -C -E -k '1-6,$$' -j1 -D -N 'libc_name_p' -L C++

LINKS

  1. https://vivinuthappa.wordpress.com/articles/build-from-source-an-official-release-of-linaro-toolchain/
  2. https://wiki.linaro.org/ABE
  3. https://wiki.osdev.org/GCC_Cross-Compiler
  4. https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
  5. https://solarianprogrammer.com/2018/05/06/building-gcc-cross-compiler-raspberry-pi/
  6. https://www.linux.com/blog/cross-compiling-arm
  7. https://solarianprogrammer.com/2017/05/21/compiling-gcc-macos/
  8. https://wiki.linaro.org/WorkingGroups/ToolChain/FAQ
  9. http://www.linuxfromscratch.org/lfs/view/development/index.html
  10. https://releases.linaro.org/components/toolchain/gcc-linaro/
  11. https://wiki.linaro.org/Toolchain
  12. https://docs.google.com/document/d/1CL6u_NXTDDEXnie64JDKkjcKCTyNDh_3IFTg06bpACY/edit# by Max Lepekh
  13. https://git.linaro.org
  14. https://releases.linaro.org/components/toolchain/gcc-linaro/
  15. https://developer.arm.com/open-source/gnu-toolchain/gnu-a/downloads
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment