Skip to content

Commit ab215fb

Browse files
committed
gcc14 14.2.0
1 parent 5915ef7 commit ab215fb

File tree

1 file changed

+231
-0
lines changed

1 file changed

+231
-0
lines changed

Library/Formula/gcc14.rb

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

0 commit comments

Comments
 (0)