Skip to content

Instantly share code, notes, and snippets.

@hey-jude
Created November 24, 2023 06:11
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 hey-jude/dbb9f39f8bb85b25d927133d2733f849 to your computer and use it in GitHub Desktop.
Save hey-jude/dbb9f39f8bb85b25d927133d2733f849 to your computer and use it in GitHub Desktop.
x86_64-elf-gcc 11 version for cross-compiling - pintos
class X8664ElfGccAT11 < Formula
desc "GNU compiler collection for x86_64-elf"
homepage "https://gcc.gnu.org"
url "https://ftp.gnu.org/gnu/gcc/gcc-11.4.0/gcc-11.4.0.tar.xz"
mirror "https://ftpmirror.gnu.org/gcc/gcc-11.4.0/gcc-11.4.0.tar.xz"
sha256 "3f2db222b007e8a4a23cd5ba56726ef08e8b1f1eb2055ee72c1402cea73a8dd9"
license "GPL-3.0-or-later" => { with: "GCC-exception-3.1" }
livecheck do
formula "gcc"
end
depends_on "gmp"
depends_on "libmpc"
depends_on "mpfr"
depends_on "x86_64-elf-binutils"
depends_on "zstd"
uses_from_macos "zlib"
cxxstdlib_check :skip
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/c233b1a8d81b9c9f5827510d8d285080ee11de2e/gcc/gcc-11.4.0.diff"
sha256 "440f6e965966c86a7925506e63eb06f7f54c00b1d146db8d0c567bdb8820072f"
end
def install
target = "x86_64-elf"
sdk = MacOS.sdk_path_if_needed
mkdir "x86_64-elf-gcc-11-build" do
system "../configure", "--target=#{target}",
"--prefix=#{prefix}",
"--infodir=#{info}/#{target}",
"--disable-nls",
"--without-isl",
"--without-headers",
"--with-as=#{Formula["x86_64-elf-binutils"].bin}/x86_64-elf-as",
"--with-ld=#{Formula["x86_64-elf-binutils"].bin}/x86_64-elf-ld",
"--with-zstd=#{Formula["zstd"].opt_prefix}",
"--program-prefix=#{target}-",
"--program-suffix=-#{version.major}",
"--with-system-zlib",
"--with-sysroot=#{sdk}",
"--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}/x86_64-elf-gcc-#{version.major}", "-c", "-o", "test-c.o", "test-c.c"
assert_match "file format elf64-x86-64",
shell_output("#{Formula["x86_64-elf-binutils"].bin}/x86_64-elf-objdump -a test-c.o")
end
end
@hey-jude
Copy link
Author

I made this one for porting pintos execution environment to apple silicon mac.
Use only at your own risk.

@hey-jude
Copy link
Author

$ brew install -v --build-from-source x86_64-elf-gcc@11.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment