Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ARM cross compile toolchain #1063

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Library/Formula/arm-none-eabi-binutils.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class ArmNoneEabiBinutils < Formula
desc "GNU Binutils for arm-none-eabi cross development"
homepage "https://www.gnu.org/software/binutils/"
url "https://ftp.gnu.org/gnu/binutils/binutils-2.41.tar.bz2"
mirror "https://ftpmirror.gnu.org/binutils/binutils-2.41.tar.bz2"
sha256 "a4c4bec052f7b8370024e60389e194377f3f48b56618418ea51067f67aaab30b"
license "GPL-3.0-or-later"

bottle do
end

depends_on "pkg-config" => :build
depends_on "zlib"

def install
target = "arm-none-eabi"
system "./configure", "--target=#{target}",
"--prefix=#{prefix}",
"--libdir=#{lib}/#{target}",
"--infodir=#{info}/#{target}-binutils",
"--with-system-zlib",
"--disable-nls"
system "make"
system "make", "install"
end

test do
(testpath/"test-s.s").write <<~EOS
.section .text
.globl _start
_start:
mov r1, #0
mov r2, #1
svc #0x80
EOS
system "#{bin}/arm-none-eabi-as", "-o", "test-s.o", "test-s.s"
assert_match "file format elf32-littlearm",
shell_output("#{bin}/arm-none-eabi-objdump -a test-s.o")
assert_match "f()", shell_output("#{bin}/arm-none-eabi-c++filt _Z1fv")
end
end
65 changes: 65 additions & 0 deletions Library/Formula/arm-none-eabi-gcc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
class ArmNoneEabiGcc < Formula
desc "GNU compiler collection for arm-none-eabi"
homepage "https://gcc.gnu.org"
url "https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.xz"
mirror "https://ftpmirror.gnu.org/gcc/gcc-13.2.0/gcc-13.2.0.tar.xz"
sha256 "e275e76442a6067341a27f04c5c6b83d8613144004c0413528863dc6b5c743da"
license "GPL-3.0-or-later" => { with: "GCC-exception-3.1" }

bottle do
end

depends_on "arm-none-eabi-binutils"
depends_on "gmp"
depends_on "libmpc"
depends_on "mpfr"
depends_on "zlib"
depends_on "ld64" => :build if MacOS.version < :leopard
depends_on "texinfo" => :build

# Need a compiler with C++11 support
needs :cxx11

def install
# Build breaks with optimisation enabled.
ENV.no_optimization if Hardware::CPU.type == :ppc

target = "arm-none-eabi"
mkdir "arm-none-eabi-gcc-build" do
system "../configure", "--target=#{target}",
"--prefix=#{prefix}",
"--infodir=#{info}/#{target}-gcc",
"--disable-nls",
"--without-isl",
"--without-headers",
"--with-system-zlib",
"--with-pkgversion=Tigerbrew #{name} #{pkg_version} #{build.used_options*" "}".strip,
"--with-bugurl=https://github.com/mistydemeo/tigerbrew/issues",
"--with-as=#{Formula["arm-none-eabi-binutils"].bin}/arm-none-eabi-as",
"--with-ld=#{Formula["arm-none-eabi-binutils"].bin}/arm-none-eabi-ld",
"--enable-languages=c,c++"

system "make", "all-gcc"
system "make", "install-gcc"
system "make", "all-target-libgcc"
system "make", "install-target-libgcc"

# FSF-related man pages may conflict with native gcc
(share/"man/man7").rmtree
end
end

test do
(testpath/"test-c.c").write <<~EOS
int main(void)
{
int i=0;
while(i<10) i++;
return i;
}
EOS
system "#{bin}/arm-none-eabi-gcc", "-c", "-o", "test-c.o", "test-c.c"
assert_match "file format elf32-littlearm",
shell_output("#{Formula["arm-none-eabi-binutils"].bin}/arm-none-eabi-objdump -a test-c.o")
end
end
55 changes: 55 additions & 0 deletions Library/Formula/arm-none-eabi-gdb.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class ArmNoneEabiGdb < Formula
desc "GNU debugger for arm-none-eabi cross development"
homepage "https://www.gnu.org/software/gdb/"
url "https://ftp.gnu.org/gnu/gdb/gdb-14.1.tar.xz"
mirror "https://ftpmirror.gnu.org/gdb/gdb-14.1.tar.xz"
sha256 "d66df51276143451fcbff464cc8723d68f1e9df45a6a2d5635a54e71643edb80"
license "GPL-3.0-or-later"
head "https://sourceware.org/git/binutils-gdb.git", branch: "master"
revision 1

bottle do
end

depends_on "gmp"
depends_on "mpfr"
depends_on "xz" # required for lzma support
depends_on "zlib"
depends_on "texinfo" => :build

# Need compiler with C++11 support
needs :cxx11

def install
target = "arm-none-eabi"
args = %W[
--target=#{target}
--prefix=#{prefix}
--datarootdir=#{share}/#{target}
--includedir=#{include}/#{target}
--infodir=#{info}/#{target}-gdb
--mandir=#{man}
--disable-debug
--disable-dependency-tracking
--with-lzma
--with-system-zlib
--disable-binutils
]

mkdir "build" do
system "../configure", *args
ENV.deparallelize # Error: common/version.c-stamp.tmp: No such file or directory
system "make"

# Don't install bfd or opcodes, as they are provided by binutils
system "make", "install-gdb"
end
end

test do
(testpath/"test.c").write "void _start(void) {}"
system "#{Formula["arm-none-eabi-gcc"].bin}/arm-none-eabi-gcc", "-g", "-nostdlib", "test.c"
assert_match "Symbol \"_start\" is a function at address 0x",
shell_output("#{bin}/arm-none-eabi-gdb -batch -ex 'info address _start' a.out")
end
end