| 76 | |
| 77 | # where to install the headers, should be unversioned for the GCC version that |
| 78 | # provides port:libgcc and versioned for all other ports |
| 79 | if {${provides_libgcc}} { |
| 80 | set gcc_headerdir ${prefix}/include/gcc |
| 81 | } else { |
| 82 | set gcc_headerdir ${prefix}/include/${name} |
| 83 | } |
| 84 | |
| 85 | # the runtime libraries are built for installation to lib/gcc${ver3char} (e.g. lib/gcc720) |
| 86 | # but will ultimately still be installed into lib/libgcc . |
| 87 | # The change is only because lib/libgcc and lib/gcc720 have the same length. |
| 112 | if {${os.major} >= 13} { |
| 113 | # use the system assembler by default; now that we use `as -q` that is the |
| 114 | # only way that doesn't oblige users to install a port:clang-xy in addition |
| 115 | # to port:gccN. This can change when the `as` command from port:cctools takes |
| 116 | # a --clang argument to use a specific clang. |
| 117 | configure.args-append \ |
| 118 | --with-as=/usr/bin/as |
| 119 | configure.env-append \ |
| 120 | AS_FOR_TARGET=/usr/bin/as |
| 121 | } else { |
| 122 | # older Xcode versions aren't compatible and oblige selecting a clang port |
| 123 | # via the `port select clang` mechanism. |
| 124 | pre-fetch { |
| 125 | if {![file exists ${prefix}/bin/clang]} { |
| 126 | ui_error "You need to run `port select --set clang mp-clang-${cdv}`" |
| 127 | return -code error "port:${name} needs ${prefix}/bin/clang" |
| 128 | } |
| 129 | } |
| 130 | depends_skip_archcheck-append llvm_select |
| 131 | configure.args-append \ |
| 132 | --with-as=${prefix}/bin/as |
| 133 | configure.env-append \ |
| 134 | AS_FOR_TARGET=${prefix}/bin/as |
| 135 | } |
| 136 | |
142 | | if {${subport} eq "libgcc"} { |
| 194 | # moved upwards from the "dylibs" variable in the port:libgcc post-destroot; |
| 195 | # these are the libraries that are potential dependencies for other ports |
| 196 | # and that are either installed by that port and not the |
| 197 | # main port, or by the main port and as symlinks by port:libgcc. |
| 198 | set standardLibs {libgcc_ext.10.4.dylib libgcc_ext.10.5.dylib \ |
| 199 | libgcc_s.1.dylib libgfortran.4.dylib libquadmath.0.dylib \ |
| 200 | libstdc++.6.dylib libobjc-gnu.4.dylib libgomp.1.dylib \ |
| 201 | libitm.1.dylib libssp.0.dylib libasan.0.dylib libatomic.1.dylib} |
| 202 | |
| 203 | if {${subport} eq "${libgcc_port}"} { |
| 204 | |
157 | | depends_lib-delete path:lib/libgcc/libgcc_s.1.dylib:libgcc |
158 | | |
159 | | configure.args-delete --libdir=${prefix}/lib/${name} |
160 | | configure.args-append --libdir=${prefix}/lib/libgcc |
161 | | |
162 | | # TODO: Possibly disable bootstrap with appropriate configure flags. |
163 | | # the problem is that libstdc++'s configure script tests for tls support |
164 | | # using the running compiler (not gcc for which libstdc++ is being built). |
165 | | # Thus when we build with clang, we get a mismatch |
166 | | # http://trac.macports.org/ticket/36116 |
167 | | #compiler.blacklist-append {clang < 425} |
168 | | #configure.args-append --disable-bootstrap |
169 | | #build.target all |
| 225 | if {![catch {set result [active_variants ${name} with_libgcc {}]}]} { |
| 226 | if {${result}} { |
| 227 | default_variants-append +stub |
| 228 | } |
| 229 | } |
| 230 | if {[variant_isset stub]} { |
| 231 | # reset the depspecs |
| 232 | depends_lib |
| 233 | require_active_variants ${name} with_libgcc |
| 234 | |
| 235 | use_configure no |
| 236 | installs_libs no |
| 237 | supported_archs noarch |
| 238 | fetch {} |
| 239 | extract {} |
| 240 | patch {} |
| 241 | build {} |
| 242 | destroot { |
| 243 | # install something relevant into $prefix/lib/libgcc |
| 244 | xinstall -m 755 -d ${destroot}${prefix}/lib/libgcc |
| 245 | system "echo ${version} > ${destroot}${prefix}/lib/libgcc/libgcc_version.txt" |
| 246 | # there should be no need to install anything related to headers |
| 247 | # For binary compatibility with binaries that linked against the old libstdcxx port |
| 248 | ln -s libgcc/libstdc++.6.dylib ${destroot}${prefix}/lib/libstdc++.6.dylib |
| 249 | } |
| 250 | } else { |
| 251 | depends_lib-delete path:lib/libgcc/libgcc_s.1.dylib:libgcc |
| 252 | require_active_variants ${name} "" with_libgcc |
| 253 | |
| 254 | # port:libgcc builds the runtime libraries for installation in lib/libgcc |
| 255 | configure.args-replace --libdir=${prefix}/lib/gcc${ver3char} \ |
| 256 | --libdir=${prefix}/lib/libgcc |
| 257 | |
| 258 | # bootstrap-less building is a *lot* faster, see: |
| 259 | # http://trac.macports.org/ticket/36116 |
| 260 | # and |
| 261 | # https://trac.macports.org/changeset/103047 |
| 262 | if {${os.major} >= 12} { |
| 263 | compiler.blacklist-append {clang < 425} |
| 264 | configure.args-append --disable-bootstrap |
| 265 | build.target all |
| 266 | } else { |
| 267 | configure.cc_archflags |
| 268 | configure.cxx_archflags |
| 269 | configure.objc_archflags |
| 270 | configure.ld_archflags |
| 271 | configure.universal_cflags |
| 272 | configure.universal_cxxflags |
| 273 | configure.universal_ldflags |
| 274 | configure.universal_args |
| 275 | build.target bootstrap-lean |
| 276 | } |
179 | | foreach dylib ${dylibs} { |
180 | | # Different OS versions (e.g. Leopard) or architectures (e.g. PPC) don't produce all the dylibs |
181 | | # https://trac.macports.org/ticket/40098 |
182 | | # https://trac.macports.org/ticket/40100 |
183 | | if {! [file exists ${destroot}${prefix}/lib/libgcc/${dylib}]} { |
184 | | continue |
185 | | } |
| 285 | foreach dylib ${standardLibs} { |
| 286 | # Different OS versions (eg: Leopard) or architectures (eg: PPC) don't produce all the dylibs |
| 287 | # https://trac.macports.org/ticket/40098 |
| 288 | # https://trac.macports.org/ticket/40100 |
| 289 | if {! [file exists ${destroot}${prefix}/lib/libgcc/${dylib}]} { |
| 290 | continue |
| 291 | } |
187 | | move ${destroot}${prefix}/lib/libgcc/${dylib} ${destroot}${prefix}/lib/libgcc.merged |
188 | | if {[variant_isset universal]} { |
189 | | foreach archdir [glob ${destroot}${prefix}/lib/libgcc/*/] { |
190 | | set archdir_nodestroot [string map "${destroot}/ /" ${archdir}] |
191 | | if {[file exists ${archdir}/${dylib}]} { |
192 | | system "install_name_tool -id ${prefix}/lib/libgcc/${dylib} ${archdir}/${dylib}" |
193 | | foreach link ${dylibs} { |
194 | | system "install_name_tool -change ${archdir_nodestroot}${link} ${prefix}/lib/libgcc/${link} ${archdir}/${dylib}" |
| 293 | move ${destroot}${prefix}/lib/libgcc/${dylib} ${destroot}${prefix}/lib/libgcc.merged |
| 294 | if {[variant_isset universal]} { |
| 295 | foreach archdir [glob ${destroot}${prefix}/lib/libgcc/*/] { |
| 296 | set archdir_nodestroot [string map "${destroot}/ /" ${archdir}] |
| 297 | if {[file exists ${archdir}/${dylib}]} { |
| 298 | system "install_name_tool -id ${prefix}/lib/libgcc/${dylib} ${archdir}/${dylib}" |
| 299 | foreach link ${dylibs} { |
| 300 | system "install_name_tool -change ${archdir_nodestroot}${link} ${prefix}/lib/libgcc/${link} ${archdir}/${dylib}" |
| 301 | } |
| 302 | system "lipo -create -output ${destroot}${prefix}/lib/libgcc.merged/${dylib}~ ${destroot}${prefix}/lib/libgcc.merged/${dylib} ${archdir}/${dylib} && mv ${destroot}${prefix}/lib/libgcc.merged/${dylib}~ ${destroot}${prefix}/lib/libgcc.merged/${dylib}" |
201 | | # strip debug symbols to supress debugger warnings: |
202 | | # http://trac.macports.org/attachment/ticket/34831 |
203 | | if {! [string match *libgcc_ext* ${dylib}]} { |
204 | | system "strip -x ${destroot}${prefix}/lib/libgcc.merged/${dylib}" |
| 307 | if {${os.major} < 13} { |
| 308 | # strip debug symbols to suppress debugger warnings: |
| 309 | # http://trac.macports.org/attachment/ticket/34831 |
| 310 | # This isn't required for lldb |
| 311 | if {! [string match *libgcc_ext* ${dylib}]} { |
| 312 | system "strip -x ${destroot}${prefix}/lib/libgcc.merged/${dylib}" |
| 313 | } |
| 314 | } |
208 | | file delete -force ${destroot}${prefix}/bin |
209 | | file delete -force ${destroot}${prefix}/share |
210 | | file delete -force ${destroot}${prefix}/include |
211 | | file delete -force ${destroot}${prefix}/lib/libgcc |
212 | | file delete -force ${destroot}${prefix}/libexec |
| 317 | file delete -force ${destroot}${prefix}/bin |
| 318 | file delete -force ${destroot}${prefix}/share |
| 319 | file delete -force ${destroot}${prefix}/lib/libgcc |
| 320 | file delete -force ${destroot}${prefix}/libexec |
| 328 | |
| 329 | } else { |
| 330 | ### Main port |
| 331 | |
| 332 | variant with_libgcc conflicts universal description "Include the standard libraries instead of getting them from port:libgcc. For if you install from source." {} |
| 333 | # the quick variant simplifies gcc patch development but also decreases the build time by a factor > 4 |
| 334 | variant quick description "Build ${name} without the usual 3-stage bootstrap.\ |
| 335 | Probably safest with configure.compiler=macports-gcc-${major} but not when that compiler uses libc++!" {} |
| 336 | |
| 337 | depends_run-append port:gcc_select |
| 338 | |
| 339 | if {${os.major} >= 13} { |
| 340 | # OS X 10.9 and up support the system clang toolchain from Xcode and |
| 341 | # MacPorts clang compilers (starting arbitrarily at 3.9) for building |
| 342 | # against the libc++ runtime instead of libstdc++. A feature under |
| 343 | # testing which hopefully can be included into GCC one day under control |
| 344 | # of a -stdlib=libc++ compiler argument. |
| 345 | # Even when that happens it will use a hardcoded clang version determined |
| 346 | # during the GCC build, i.e. these variants will remain. |
| 347 | set libcxx_versions {{} 3.9 4.0 5.0} |
220 | | depends_run-append port:gcc_select |
| 349 | # don't support the system clang toolchain before OS X 10.9 |
| 350 | set libcxx_versions {3.9 4.0 5.0} |
| 351 | } |
| 352 | |
| 353 | foreach cdv ${libcxx_versions} { |
| 354 | set cv [join [split ${cdv} "."] ""] |
| 355 | if {${cdv} eq {}} { |
| 356 | variant libcxx description "Build to use libc++ and the corresponding headers from Xcode (experimental for Xcode <= 6)" {} |
| 357 | } else { |
| 358 | variant libcxx${cv} description "Build to use libc++ and the corresponding headers from port:clang-${cdv}" {} |
| 359 | } |
| 360 | if {[variant_isset libcxx${cv}]} { |
| 361 | if {${cdv} ne {}} { |
| 362 | depends_run-append port:clang-${cdv} |
| 363 | set libcxx_headers "${prefix}/libexec/llvm-${cdv}/include/c++/v1" |
| 364 | set clang_mp "${prefix}/bin/clang-mp-${cdv}" |
| 365 | if {${os.major} >= 13} { |
| 366 | pre-fetch { |
| 367 | if {![file exists ${prefix}/bin/clang]} { |
| 368 | ui_error "You need to run `port select --set clang mp-clang-${cdv}`" |
| 369 | return -code error "port:${name} needs ${prefix}/bin/clang" |
| 370 | } |
| 371 | } |
| 372 | depends_skip_archcheck-append llvm_select |
| 373 | # we need a clang installation anyway, use it for the compiler too |
| 374 | # (if the user used port select to that extent). |
| 375 | configure.args-replace \ |
| 376 | --with-as=/usr/bin/as \ |
| 377 | --with-as=${prefix}/bin/as |
| 378 | configure.env-replace \ |
| 379 | AS_FOR_TARGET=/usr/bin/as \ |
| 380 | AS_FOR_TARGET=${prefix}/bin/as |
| 381 | } |
| 382 | } else { |
| 383 | set libcxx_headers "[file dir [exec xcrun --find clang]]/../include/c++/v1" |
| 384 | set clang_mp "[exec xcrun --find clang]" |
| 385 | } |
| 386 | patchfiles-append patch-use-libcxx.diff |
| 387 | post-patch { |
| 388 | reinplace "s|@LLVMHEADERPATH@|${libcxx_headers}|g" ${worksrcpath}/gcc/incpath.c |
| 389 | # # this will apply when as -q takes a --clang argument. |
| 390 | # reinplace "s|@CLANG@|${clang_mp}|g" ${worksrcpath}/gcc/config/darwin.h |
| 391 | } |
| 392 | |
| 393 | # the reason for the change proposed in https://lists.macports.org/pipermail/macports-dev/2017-August/036209.html |
| 394 | # is moot when using libc++ ; reenable TLS |
| 395 | configure.args-delete --disable-tls |
| 396 | |
| 397 | # GCC_IS_BUILDING_ITSELF: causes g++ to add a static libstdc++ just like it does when building with/for libstdc++ |
| 398 | # GCC_FORCE_LIBSTDCPP: forces the use of libstdc++ for the current build and ignores the default clang C++ header location |
| 399 | # LIBCPP_INCLUDE_PATH: redefines the location of the clang C++ headers; empty means don't use them at all |
| 400 | # The combination below means: build GCC "as usual" itself |
| 401 | configure.env-append GCC_IS_BUILDING_ITSELF=1 GCC_FORCE_LIBSTDCPP=1 |
| 402 | build.env-append GCC_IS_BUILDING_ITSELF=1 GCC_FORCE_LIBSTDCPP=1 |
| 403 | destroot.env-append GCC_IS_BUILDING_ITSELF=1 GCC_FORCE_LIBSTDCPP=1 |
| 404 | } |
| 405 | } |
| 406 | # post-patch { |
| 407 | # # use the system clang as assembler if no libcxx variant is set |
| 408 | # # and `as -q` accepts a --clang argument. |
| 409 | # set clang_mp "[exec xcrun --find clang]" |
| 410 | # reinplace "s|@CLANG@|${clang_mp}|g" ${worksrcpath}/gcc/config/darwin.h |
| 411 | # } |
232 | | foreach dylib {libgcc_ext.10.4.dylib libgcc_ext.10.5.dylib libgcc_s.1.dylib libgfortran.4.dylib libquadmath.0.dylib libstdc++.6.dylib libobjc-gnu.4.dylib libgomp.1.dylib libitm.1.dylib libssp.0.dylib libasan.0.dylib libatomic.1.dylib} { |
233 | | # Different OS versions (e.g. Leopard) or architectures (e.g. PPC) don't produce all the dylibs |
234 | | # https://trac.macports.org/ticket/40098 |
235 | | # https://trac.macports.org/ticket/40100 |
236 | | if {[file exists ${destroot}${prefix}/lib/${name}/${dylib}]} { |
237 | | delete ${destroot}${prefix}/lib/${name}/${dylib} |
238 | | ln -s ${prefix}/lib/libgcc/${dylib} ${destroot}${prefix}/lib/${name}/${dylib} |
| 423 | if {![variant_isset with_libgcc]} { |
| 424 | foreach dylib ${standardLibs} { |
| 425 | # Different OS versions (e.g. Leopard) or architectures (e.g. PPC) don't produce all the dylibs |
| 426 | # https://trac.macports.org/ticket/40098 |
| 427 | # https://trac.macports.org/ticket/40100 |
| 428 | if {[file exists ${destroot}${prefix}/lib/${name}/${dylib}]} { |
| 429 | delete ${destroot}${prefix}/lib/${name}/${dylib} |
| 430 | ln -s ${prefix}/lib/libgcc/${dylib} ${destroot}${prefix}/lib/${name}/${dylib} |
| 431 | } |
| 432 | |
| 433 | if {[variant_isset universal]} { |
| 434 | foreach archdir [glob ${destroot}${prefix}/lib/${name}/*/] { |
| 435 | if {[file exists ${archdir}/${dylib}]} { |
| 436 | delete ${archdir}/${dylib} |
| 437 | ln -s ${prefix}/lib/libgcc/${dylib} ${archdir}/${dylib} |
| 438 | } |
| 439 | } |
| 440 | } |
| 442 | # The C++ headerfiles are installed by port:libgcc too |
| 443 | delete -force ${destroot}${gcc_headerdir}/c++ |
| 444 | } else { |
| 445 | file mkdir ${destroot}${prefix}/lib/libgcc |
| 446 | foreach dylib ${standardLibs} { |
| 447 | # This is a modified "inversed" version of what port:libgcc does when not in stub mode |
| 448 | # the difference is that here we're moving the ${standardLibs} from lib/gcc${ver3char} ($prefix/lib/gcc7) |
| 449 | # into the unversioned $prefix/lib/libgcc and need to adapt their ID and link info accordingly. |
| 450 | if {! [file exists ${destroot}${prefix}/lib/gcc${ver3char}/${dylib}]} { |
| 451 | continue |
| 452 | } |
| 453 | |
| 454 | move ${destroot}${prefix}/lib/gcc${ver3char}/${dylib} ${destroot}${prefix}/lib/libgcc |
| 455 | # put an appropriate symlink in the versioned location |
| 456 | ln -s ${prefix}/lib/libgcc/${dylib} ${destroot}${prefix}/lib/gcc${ver3char}/${dylib} |
241 | | if {[variant_isset universal]} { |
242 | | foreach archdir [glob ${destroot}${prefix}/lib/${name}/*/] { |
243 | | if {[file exists ${archdir}/${dylib}]} { |
244 | | delete ${archdir}/${dylib} |
245 | | ln -s ${prefix}/lib/libgcc/${dylib} ${archdir}/${dylib} |
| 458 | # update ${dylib}'s ID and all of its dependents to match the new location |
| 459 | if {[variant_isset universal]} { |
| 460 | # this case is untested and should never be executed because of the with_libgcc/universal conflict |
| 461 | # Keeping it around for the "just in case". |
| 462 | foreach archdir [glob ${destroot}${prefix}/lib/gcc${ver3char}/*/] { |
| 463 | set archdir_nodestroot [string map "${destroot}/ /" ${archdir}] |
| 464 | if {[file exists ${archdir}/${dylib}]} { |
| 465 | system "install_name_tool -id ${prefix}/lib/libgcc/${dylib} ${archdir}/${dylib}" |
| 466 | foreach link ${dylibs} { |
| 467 | system "install_name_tool -change ${archdir_nodestroot}${link} ${prefix}/lib/libgcc/${link} ${archdir}/${dylib}" |
| 468 | } |
| 469 | system "lipo -create -output ${destroot}${prefix}/lib/libgcc/${dylib}~ ${destroot}${prefix}/lib/libgcc/${dylib} ${archdir}/${dylib} && mv ${destroot}${prefix}/lib/libgcc/${dylib}~ ${destroot}${prefix}/lib/libgcc/${dylib}" |
| 470 | } |
| 471 | } |
| 472 | } else { |
| 473 | if {[string match *libgcc_ext* ${dylib}]} { |
| 474 | # libgcc_ext is a stub library which install_name_tool cannot handle. |
| 475 | # Instead, we do a binary-file search-and-replace, which is possible before the |
| 476 | # original and desired target rpaths have the same length. |
| 477 | system "/usr/bin/ex -b +:1s,${prefix}/lib/gcc${ver3char}/libgcc_s.1.dylib,${prefix}/lib/libgcc/libgcc_s.1.dylib,g +:wq ${destroot}${prefix}/lib/libgcc/${dylib}" |
| 478 | } else { |
| 479 | system "install_name_tool -id ${prefix}/lib/libgcc/${dylib} ${destroot}${prefix}/lib/libgcc/${dylib}" |
| 480 | foreach dep [glob ${destroot}${prefix}/lib/gcc${ver3char}/*.dylib ${destroot}${prefix}/lib/libgcc/*.dylib] { |
| 481 | if {[file type ${dep}] eq "file" && ![string match *libgcc_ext* ${dep}]} { |
| 482 | # ${dylib} has been moved, so update all of its dependents |
| 483 | set old ${prefix}/lib/gcc${ver3char}/${dylib} |
| 484 | set new ${prefix}/lib/libgcc/${dylib} |
| 485 | system "install_name_tool -change ${old} ${new} ${dep}" |
| 486 | } |
| 487 | } |
| 490 | |
| 491 | if {${os.major} < 13} { |
| 492 | # strip debug symbols to suppress debugger warnings: |
| 493 | # http://trac.macports.org/attachment/ticket/34831 |
| 494 | if {! [string match *libgcc_ext* ${dylib}]} { |
| 495 | system "strip -x ${destroot}${prefix}/lib/libgcc/${dylib}" |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | foreach cdv ${libcxx_versions} { |
| 501 | set cv [join [split ${cdv} "."] ""] |
| 502 | if {[variant_isset libcxx${cv}] && [file exists ${destroot}${gcc_headerdir}/c++]} { |
| 503 | # move the stdc++ headers out of the way because g++ shouldn't find them. |
| 504 | # FIXME: needs to go when gcc supports -stdlib=libc++ ! |
| 505 | xinstall -m 755 -d ${destroot}${prefix}/include/${name}-stdinc |
| 506 | file rename ${destroot}${gcc_headerdir}/c++ ${destroot}${prefix}/include/${name}-stdinc/c++ |