Skip to content

Commit e4082a6

Browse files
committed
gcc14 14.2.0
1 parent 5915ef7 commit e4082a6

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 missing crc32_combine on Tiger
47+
depends_on "zlib"
48+
49+
if MacOS.version < :leopard
50+
# The as that comes with Tiger isn't capable of dealing with the
51+
# PPC asm that comes in libitm
52+
depends_on "cctools" => :build
53+
end
54+
55+
# Needs a newer tigerbrew-provided GCC to build
56+
fails_with :gcc_4_0
57+
fails_with :gcc
58+
fails_with :llvm
59+
60+
# GCC bootstraps itself, so it is OK to have an incompatible C++ stdlib
61+
cxxstdlib_check :skip
62+
63+
# Applied upstream: https://github.com/gcc-mirror/gcc/commit/1cfe4a4d0d4447b364815d5e5c889deb2e533669
64+
# Can remove in a later version.
65+
patch :p0 do
66+
url "https://github.com/macports/macports-ports/raw/b5a5b6679f59dcad1b21f66bb01e3f8a3a377b4b/lang/gcc14/files/darwin-ppc-fpu.patch"
67+
sha256 "7f14356f2e9efdf46503ca1156302c9b294db52569f4d56073267142b6d2ee71"
68+
end
69+
70+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117834
71+
patch :p0 do
72+
url "https://github.com/macports/macports-ports/raw/b5a5b6679f59dcad1b21f66bb01e3f8a3a377b4b/lang/gcc14/files/darwin8-define-PTHREAD_RWLOCK_INITIALIZER.patch"
73+
sha256 "57ffac38f4d5eb4d92634d9e7c339f961e3eb908d13a944d622bfc6915a4f435"
74+
end
75+
76+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117857
77+
patch :p0 do
78+
url "https://github.com/macports/macports-ports/raw/b5a5b6679f59dcad1b21f66bb01e3f8a3a377b4b/lang/gcc14/files/darwin8-ttyname_r.patch"
79+
sha256 "b81cbbe43e07a8575c1f626e76db18f4ca9e11772077b71fc5caacbfb8e24dbf"
80+
end
81+
82+
# The bottles are built on systems with the CLT installed, and do not work
83+
# out of the box on Xcode-only systems due to an incorrect sysroot.
84+
def pour_bottle?
85+
MacOS::CLT.installed?
86+
end
87+
88+
def version_suffix
89+
version.to_s.slice(/\d\d/)
90+
end
91+
92+
def install
93+
# GCC Bug 25127 for PowerPC
94+
# https://gcc.gnu.org/bugzilla//show_bug.cgi?id=25127
95+
# ../../../libgcc/unwind.inc: In function '_Unwind_RaiseException':
96+
# ../../../libgcc/unwind.inc:136:1: internal compiler error: in rs6000_emit_prologue, at config/rs6000/rs6000.c:26535
97+
# GCC 7 fails to install on 10.6 x86_64 at stage3
98+
# https://github.com/mistydemeo/tigerbrew/issues/554
99+
ENV.no_optimization
100+
101+
# Otherwise libstdc++ will be incorrectly tagged with cpusubtype 10 (G4e)
102+
# https://github.com/mistydemeo/tigerbrew/issues/538
103+
if Hardware::CPU.family == :g3 || ARGV.bottle_arch == :g3
104+
ENV.append_to_cflags "-force_cpusubtype_ALL"
105+
end
106+
107+
if MacOS.version < :leopard
108+
ENV["AS"] = ENV["AS_FOR_TARGET"] = "#{Formula["cctools"].bin}/as"
109+
end
110+
111+
# We avoiding building:
112+
# - Ada, which requires a pre-existing GCC Ada compiler to bootstrap
113+
# - Go, currently not supported on macOS
114+
# - BRIG
115+
languages = %w[c c++ objc obj-c++ fortran]
116+
117+
# JIT compiler is off by default, enabling it has performance cost
118+
languages << "jit" if build.with? "jit"
119+
120+
args = [
121+
"--build=#{arch}-apple-darwin#{osmajor}",
122+
"--prefix=#{prefix}",
123+
"--libdir=#{lib}/gcc/#{version_suffix}",
124+
"--enable-languages=#{languages.join(",")}",
125+
# Make most executables versioned to avoid conflicts.
126+
"--program-suffix=-#{version_suffix}",
127+
"--with-gmp=#{Formula["gmp"].opt_prefix}",
128+
"--with-mpfr=#{Formula["mpfr"].opt_prefix}",
129+
"--with-mpc=#{Formula["libmpc"].opt_prefix}",
130+
"--with-isl=#{Formula["isl"].opt_prefix}",
131+
"--with-system-zlib",
132+
"--enable-checking=release",
133+
"--with-pkgversion=Tigerbrew #{name} #{pkg_version} #{build.used_options*" "}".strip,
134+
"--with-bugurl=https://github.com/mistydemeo/tigerbrew/issues",
135+
]
136+
137+
# "Building GCC with plugin support requires a host that supports
138+
# -fPIC, -shared, -ldl and -rdynamic."
139+
args << "--enable-plugin" if MacOS.version > :leopard
140+
141+
# Otherwise make fails during comparison at stage 3
142+
# See: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45248
143+
args << "--with-dwarf2" if MacOS.version < :leopard
144+
145+
args << "--disable-nls" if build.without? "nls"
146+
147+
if build.without?("multilib") || !MacOS.prefer_64_bit?
148+
args << "--disable-multilib"
149+
else
150+
args << "--enable-multilib"
151+
end
152+
153+
args << "--enable-host-shared" if build.with?("jit")
154+
155+
mkdir "build" do
156+
unless MacOS::CLT.installed?
157+
# For Xcode-only systems, we need to tell the sysroot path.
158+
# "native-system-headers" will be appended
159+
args << "--with-native-system-header-dir=/usr/include"
160+
args << "--with-sysroot=#{MacOS.sdk_path}"
161+
end
162+
163+
system "../configure", *args
164+
# These two flags are required for zlib to be found in the last stage
165+
system "make", "ZLIBINC=-I#{Formula["zlib"].opt_include}",
166+
"ZLIB=-L#{Formula["zlib"].opt_lib} -lz"
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)