Skip to content

Commit 1b6911d

Browse files
committed
gcc14 14.2.0
1 parent a51ebac commit 1b6911d

File tree

1 file changed

+234
-0
lines changed

1 file changed

+234
-0
lines changed

Library/Formula/gcc14.rb

+234
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
class Gcc14 < Formula
2+
def arch
3+
if Hardware::CPU.type == :intel
4+
if MacOS.prefer_64_bit?
5+
"x86_64"
6+
else
7+
"i686"
8+
end
9+
elsif Hardware::CPU.type == :ppc
10+
if MacOS.prefer_64_bit?
11+
"powerpc64"
12+
else
13+
"powerpc"
14+
end
15+
end
16+
end
17+
18+
def osmajor
19+
`uname -r`.chomp
20+
end
21+
22+
desc "GNU compiler collection"
23+
homepage "https://gcc.gnu.org"
24+
url "https://ftp.gnu.org/gnu/gcc/gcc-14.2.0/gcc-14.2.0.tar.xz"
25+
mirror "https://ftpmirror.gnu.org/gcc/gcc-14.2.0/gcc-14.2.0.tar.xz"
26+
sha256 "a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9"
27+
28+
bottle do
29+
end
30+
31+
option "with-nls", "Build with native language support (localization)"
32+
# enabling multilib on a host that can't run 64-bit results in build failures
33+
option "without-multilib", "Build without multilib support" if MacOS.prefer_64_bit?
34+
# JIT fails to build on i386, or any platform for Tiger
35+
if !(Hardware::CPU.type == :intel && !MacOS.prefer_64_bit?) || MacOS.version > :leopard
36+
option "with-jit", "Build just-in-time compiler"
37+
end
38+
39+
depends_on :ld64
40+
# System texinfo is too old
41+
depends_on "texinfo" => :build
42+
depends_on "gmp"
43+
depends_on "libmpc"
44+
depends_on "mpfr"
45+
depends_on "isl"
46+
# System zlib is too old
47+
depends_on "zlib"
48+
depends_on "zstd"
49+
50+
if MacOS.version < :leopard
51+
# The as that comes with Tiger isn't capable of dealing with the
52+
# PPC asm that comes in libitm
53+
depends_on "cctools" => :build
54+
end
55+
56+
# Needs a newer tigerbrew-provided GCC to build
57+
fails_with :gcc_4_0
58+
fails_with :gcc
59+
fails_with :llvm
60+
61+
# GCC bootstraps itself, so it is OK to have an incompatible C++ stdlib
62+
cxxstdlib_check :skip
63+
64+
# Applied upstream: https://github.com/gcc-mirror/gcc/commit/1cfe4a4d0d4447b364815d5e5c889deb2e533669
65+
# Can remove in a later version.
66+
patch :p0 do
67+
url "https://github.com/macports/macports-ports/raw/b5a5b6679f59dcad1b21f66bb01e3f8a3a377b4b/lang/gcc14/files/darwin-ppc-fpu.patch"
68+
sha256 "7f14356f2e9efdf46503ca1156302c9b294db52569f4d56073267142b6d2ee71"
69+
end
70+
71+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117834
72+
patch :p0 do
73+
url "https://github.com/macports/macports-ports/raw/b5a5b6679f59dcad1b21f66bb01e3f8a3a377b4b/lang/gcc14/files/darwin8-define-PTHREAD_RWLOCK_INITIALIZER.patch"
74+
sha256 "57ffac38f4d5eb4d92634d9e7c339f961e3eb908d13a944d622bfc6915a4f435"
75+
end
76+
77+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117857
78+
patch :p0 do
79+
url "https://github.com/macports/macports-ports/raw/b5a5b6679f59dcad1b21f66bb01e3f8a3a377b4b/lang/gcc14/files/darwin8-ttyname_r.patch"
80+
sha256 "b81cbbe43e07a8575c1f626e76db18f4ca9e11772077b71fc5caacbfb8e24dbf"
81+
end
82+
83+
# The bottles are built on systems with the CLT installed, and do not work
84+
# out of the box on Xcode-only systems due to an incorrect sysroot.
85+
def pour_bottle?
86+
MacOS::CLT.installed?
87+
end
88+
89+
def version_suffix
90+
version.to_s.slice(/\d\d/)
91+
end
92+
93+
def install
94+
# GCC Bug 25127 for PowerPC
95+
# https://gcc.gnu.org/bugzilla//show_bug.cgi?id=25127
96+
# ../../../libgcc/unwind.inc: In function '_Unwind_RaiseException':
97+
# ../../../libgcc/unwind.inc:136:1: internal compiler error: in rs6000_emit_prologue, at config/rs6000/rs6000.c:26535
98+
# GCC 7 fails to install on 10.6 x86_64 at stage3
99+
# https://github.com/mistydemeo/tigerbrew/issues/554
100+
ENV.no_optimization
101+
102+
# Otherwise libstdc++ will be incorrectly tagged with cpusubtype 10 (G4e)
103+
# https://github.com/mistydemeo/tigerbrew/issues/538
104+
if Hardware::CPU.family == :g3 || ARGV.bottle_arch == :g3
105+
ENV.append_to_cflags "-force_cpusubtype_ALL"
106+
end
107+
108+
if MacOS.version < :leopard
109+
ENV["AS"] = ENV["AS_FOR_TARGET"] = "#{Formula["cctools"].bin}/as"
110+
end
111+
112+
# We avoiding building:
113+
# - Ada, which requires a pre-existing GCC Ada compiler to bootstrap
114+
# - Go, currently not supported on macOS
115+
# - BRIG
116+
languages = %w[c c++ objc obj-c++ fortran]
117+
118+
# JIT compiler is off by default, enabling it has performance cost
119+
languages << "jit" if build.with? "jit"
120+
121+
args = [
122+
"--build=#{arch}-apple-darwin#{osmajor}",
123+
"--prefix=#{prefix}",
124+
"--libdir=#{lib}/gcc/#{version_suffix}",
125+
"--enable-languages=#{languages.join(",")}",
126+
# Make most executables versioned to avoid conflicts.
127+
"--program-suffix=-#{version_suffix}",
128+
"--with-gmp=#{Formula["gmp"].opt_prefix}",
129+
"--with-mpfr=#{Formula["mpfr"].opt_prefix}",
130+
"--with-mpc=#{Formula["libmpc"].opt_prefix}",
131+
"--with-isl=#{Formula["isl"].opt_prefix}",
132+
"--with-zstd=#{Formula["zstd"].opt_prefix}",
133+
"--with-system-zlib",
134+
"--enable-checking=release",
135+
"--with-pkgversion=Tigerbrew #{name} #{pkg_version} #{build.used_options*" "}".strip,
136+
"--with-bugurl=https://github.com/mistydemeo/tigerbrew/issues",
137+
]
138+
139+
# "Building GCC with plugin support requires a host that supports
140+
# -fPIC, -shared, -ldl and -rdynamic."
141+
args << "--enable-plugin" if MacOS.version > :leopard
142+
143+
# Otherwise make fails during comparison at stage 3
144+
# See: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45248
145+
args << "--with-dwarf2" if MacOS.version < :leopard
146+
147+
args << "--disable-nls" if build.without? "nls"
148+
149+
if build.without?("multilib") || !MacOS.prefer_64_bit?
150+
args << "--disable-multilib"
151+
else
152+
args << "--enable-multilib"
153+
end
154+
155+
args << "--enable-host-shared" if build.with?("jit")
156+
157+
mkdir "build" do
158+
unless MacOS::CLT.installed?
159+
# For Xcode-only systems, we need to tell the sysroot path.
160+
# "native-system-headers" will be appended
161+
args << "--with-native-system-header-dir=/usr/include"
162+
args << "--with-sysroot=#{MacOS.sdk_path}"
163+
end
164+
165+
system "../configure", *args
166+
system "make"
167+
system "make", "install"
168+
end
169+
170+
# Handle conflicts between GCC formulae and avoid interfering
171+
# with system compilers.
172+
# Since GCC 4.8 libffi stuff are no longer shipped.
173+
# Rename man7.
174+
Dir.glob(man7/"*.7") { |file| add_suffix file, version_suffix }
175+
# Even when suffixes are appended, the info pages conflict when
176+
# install-info is run. TODO fix this.
177+
info.rmtree
178+
end
179+
180+
def add_suffix(file, suffix)
181+
dir = File.dirname(file)
182+
ext = File.extname(file)
183+
base = File.basename(file, ext)
184+
File.rename file, "#{dir}/#{base}-#{suffix}#{ext}"
185+
end
186+
187+
def caveats
188+
if build.with?("multilib") then <<-EOS.undent
189+
GCC has been built with multilib support. Notably, OpenMP may not work:
190+
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60670
191+
If you need OpenMP support you may want to
192+
brew reinstall gcc --without-multilib
193+
EOS
194+
end
195+
end
196+
197+
test do
198+
(testpath/"hello-c.c").write <<-EOS.undent
199+
#include <stdio.h>
200+
int main()
201+
{
202+
puts("Hello, world!");
203+
return 0;
204+
}
205+
EOS
206+
system "#{bin}/gcc-#{version_suffix}", "-o", "hello-c", "hello-c.c"
207+
assert_equal "Hello, world!\n", `./hello-c`
208+
209+
(testpath/"hello-cc.cc").write <<-EOS.undent
210+
#include <iostream>
211+
int main()
212+
{
213+
std::cout << "Hello, world!" << std::endl;
214+
return 0;
215+
}
216+
EOS
217+
system "#{bin}/g++-#{version_suffix}", "-o", "hello-cc", "hello-cc.cc"
218+
assert_equal "Hello, world!\n", `./hello-cc`
219+
220+
(testpath/"test.f90").write <<-EOS.undent
221+
integer,parameter::m=10000
222+
real::a(m), b(m)
223+
real::fact=0.5
224+
225+
do concurrent (i=1:m)
226+
a(i) = a(i) + fact*b(i)
227+
end do
228+
write(*,"(A)") "Done"
229+
end
230+
EOS
231+
system "#{bin}/gfortran-8", "-o", "test", "test.f90"
232+
assert_equal "Done\n", `./test`
233+
end
234+
end

0 commit comments

Comments
 (0)