Ticket #65499: Portfile

File Portfile, 18.3 KB (added by johnrosshunt, 2 years ago)

New Portfile

Line 
1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
2
3PortSystem                                       1.0
4PortGroup           select                       1.0
5PortGroup           compiler_blacklist_versions  1.0
6PortGroup           active_variants              1.1
7PortGroup           conflicts_build              1.0
8PortGroup           cltversion                   1.0
9
10epoch               0
11name                gcc12
12
13homepage            https://gcc.gnu.org/
14
15platforms           darwin
16categories          lang
17maintainers         nomaintainer
18# an exception in the license allows dependents to not be GPL
19license             {GPL-3+ Permissive}
20
21description         The GNU compiler collection
22long_description    {*}${description}, including front ends for \
23                    C, C++, Objective-C, Objective-C++ and Fortran.
24
25version             12.1.0
26revision            3
27subport             libgcc12 { revision 3 }
28
29checksums           rmd160  6cdb114103541230492bbc6093585cb10e5e5ea6 \
30                    sha256  62fd634889f31c02b64af2c468f064b47ad1ca78411c45abe6ac4b5f8dd19c7b \
31                    size    82701928
32
33# Primary releases
34master_sites        https://ftpmirror.gnu.org/gcc/gcc-${version}/ \
35                    https://mirror.its.dal.ca/gnu/gcc/gcc-${version}/ \
36                    https://mirrors.kernel.org/gnu/gcc/gcc-${version}/ \
37                    https://www.mirrorservice.org/sites/ftp.gnu.org/gnu/gcc/gcc-${version}/ \
38                    https://ftp-stud.hs-esslingen.de/pub/Mirrors/ftp.gnu.org/gcc/gcc-${version}/ \
39                    https://mirror.yongbok.net/gnu/gcc/gcc-${version}/ \
40                    http://mirror.koddos.net/gcc/releases/gcc-${version}/ \
41                    ftp://ftp.gwdg.de/pub/linux/gcc/releases/gcc-${version}/ \
42                    ftp://gcc.ftp.nluug.nl/mirror/languages/gcc/releases/gcc-${version}/ \
43                    ftp://gcc.gnu.org/pub/gcc/releases/gcc-${version}/ \
44                    gnu:gcc/gcc-${version}
45
46distname            gcc-${version}
47use_xz              yes
48
49depends_build-append \
50                    port:texinfo
51depends_lib-append  port:cctools \
52                    port:gmp \
53                    path:lib/pkgconfig/isl.pc:isl \
54                    port:ld64 \
55                    port:libiconv \
56                    port:libmpc \
57                    port:mpfr \
58                    port:zlib \
59                    port:zstd
60depends_run-append  port:gcc_select \
61                    path:share/doc/libgcc/README:libgcc
62
63depends_skip_archcheck-append gcc_select ld64 cctools
64license_noconflict  gmp mpfr ppl libmpc zlib
65
66set major           [lindex [split ${version} .-] 0]
67
68platform darwin {
69    configure.pre_args-append --build=${build_arch}-apple-darwin${os.major}
70}
71
72set gcc_configure_langs {c c++ objc obj-c++ lto fortran}
73if {${subport} eq ${name} && ${build_arch} ne "i386"} {
74    # jit compiler is not building on i386 systems
75    # https://trac.macports.org/ticket/61130
76    lappend gcc_configure_langs jit
77}
78
79proc get_clean_sysroot {} {
80    global configure.sdkroot
81    # if the sdkroot is one of the current, rapidly changing SDKS, use the generic one
82    return [regsub {MacOSX1[1-9]\.[0-9]+\.sdk} ${configure.sdkroot} {MacOSX.sdk}]
83}
84
85configure.dir       ${workpath}/build
86configure.cmd       ${worksrcpath}/configure
87configure.args      --enable-languages=[join ${gcc_configure_langs} ","] \
88                    --libdir=${prefix}/lib/${name} \
89                    --includedir=${prefix}/include/${name} \
90                    --infodir=${prefix}/share/info \
91                    --mandir=${prefix}/share/man \
92                    --datarootdir=${prefix}/share/gcc-${major} \
93                    --with-local-prefix=${prefix} \
94                    --with-system-zlib \
95                    --disable-nls \
96                    --program-suffix=-mp-${major} \
97                    --with-gxx-include-dir=${prefix}/include/${name}/c++/ \
98                    --with-gmp=${prefix} \
99                    --with-mpfr=${prefix} \
100                    --with-mpc=${prefix} \
101                    --with-isl=${prefix} \
102                    --with-zstd=${prefix} \
103                    --enable-checking=release \
104                    --disable-multilib \
105                    --enable-lto \
106                    --enable-libstdcxx-time \
107                    --with-build-config=bootstrap-debug \
108                    --with-as=${prefix}/bin/as \
109                    --with-ld=${prefix}/bin/ld \
110                    --with-ar=${prefix}/bin/ar \
111                    --with-bugurl=https://trac.macports.org/newticket \
112                    --enable-host-shared \
113                    --with-darwin-extra-rpath=${prefix}/lib/libgcc \
114                    --with-libiconv-prefix=${prefix}
115
116# see https://lists.macports.org/pipermail/macports-dev/2017-August/036209.html
117# --disable-tls does not limit functionality
118# it only determines how std::call_once works
119configure.args-append  --disable-tls
120
121# Disable ccache
122configure.ccache    no
123
124if { ${os.platform} eq "darwin" } {
125    # gcc has build issues on macOS 11.3 with the use of Xcode 12.5 clang via cctools for ld
126    # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100340
127    # https://trac.macports.org/ticket/62775
128    # Update for gcc12 - Similar issues on macOS 10.6, 10.13 ...
129    if { ([vercmp ${xcodeversion} 12.5] >= 0 && [vercmp ${xcodeversion} 13] < 0) || \
130         ([vercmp ${cltversion} 12.5] >= 0 && [vercmp ${cltversion} 13] < 0) || \
131             ${os.major} < 11 || ${os.major} == 17 } \
132    {
133        # Skip bootstrap comparison entirely
134        configure.args-replace --with-build-config=bootstrap-debug --without-build-config
135        post-patch {
136            reinplace {s|^do-compare =|do-compare = /usr/bin/true|g} \
137                ${worksrcpath}/Makefile.in \
138                ${worksrcpath}/config/bootstrap-debug.mk \
139                ${worksrcpath}/config/bootstrap-debug-lean.mk \
140                ${worksrcpath}/config/bootstrap-debug-lib.mk
141        }
142    }
143}
144
145configure.env-append \
146                    AR_FOR_TARGET=${prefix}/bin/ar \
147                    AS_FOR_TARGET=${prefix}/bin/as \
148                    LD_FOR_TARGET=${prefix}/bin/ld \
149                    NM_FOR_TARGET=${prefix}/bin/nm \
150                    OBJDUMP_FOR_TARGET=${prefix}/bin/objdump \
151                    RANLIB_FOR_TARGET=${prefix}/bin/ranlib \
152                    STRIP_FOR_TARGET=${prefix}/bin/strip \
153                    OTOOL=${prefix}/bin/otool \
154                    OTOOL64=${prefix}/bin/otool
155
156if { ${os.platform} eq "darwin" } {
157    # Patch generated from https://github.com/iains/gcc-12-branch
158    # git diff --no-prefix releases/gcc-12.1.0 gcc-12.1-darwin-r1
159    patchfiles-append  patch-darwin-gcc-${version}.diff
160}
161
162pre-configure {
163
164    # Set package info
165    configure.args-append --with-pkgversion="MacPorts ${name} ${version}_${revision}${portvariants}"
166
167    if {${configure.sdkroot} ne ""} {
168        # We should be using --with-build-sysroot here.  Using --with-sysroot
169        # changes the behavior of the installed gcc to look in that sysroot
170        # by default instead of /.  Using --with-build-sysroot is supposed
171        # to be used during the build but not impact the installed product.
172        # Unfortunately, the build fails because the value doesn't get
173        # plumbed everywhere it is supposed to.
174        #
175        # https://trac.macports.org/ticket/53726
176        # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885
177        configure.args-append --with-sysroot="[get_clean_sysroot]"
178    }
179
180}
181
182variant stdlib_flag description {Enable stdlib command line flag to select c++ runtime} {
183    # Enables support for specifying the c++ runtime via `-stdlib=` in a similar
184    # way to clang. For more details see the later comments in
185    #   https://www.mail-archive.com/gcc-patches@gcc.gnu.org/msg257385.html
186    # Note : This 'bakes' the libc++ include directory into gcc,
187    # which is then used as the default search location when `-stdlib=libc++`
188    # is given. Therefore to have consistency across various OS versions, and to enable
189    # modern c++ standards, use a recent macports clang port to provide this.
190    if { ${os.platform} eq "darwin" && ${os.major} < 11 } {
191        set mp_clang_ver 11
192    } else {
193        set mp_clang_ver 14
194    }
195    if {${subport} eq ${name}} {
196        depends_run-append port:clang-${mp_clang_ver}
197    }
198    configure.args-append --with-gxx-libcxx-include-dir="${prefix}/libexec/llvm-${mp_clang_ver}/include/c++/v1"
199}
200default_variants-append +stdlib_flag
201
202# https://trac.macports.org/ticket/29067
203# https://trac.macports.org/ticket/29104
204# https://trac.macports.org/ticket/47996
205# https://trac.macports.org/ticket/58493
206compiler.blacklist-append {clang < 800} gcc-4.0 *gcc-4.2 {llvm-gcc-4.2 < 2336.1} {macports-clang-3.[4-7]}
207
208# https://build.macports.org/builders/ports-10.13_x86_64-builder/builds/105513/steps/install-port/logs/stdio
209# c++/v1/functional:1408:2: error: no member named 'fancy_abort' in namespace 'std::__1'; did you mean simply 'fancy_abort'?
210compiler.blacklist-append {clang < 1001}
211
212# "-stdlib" would be passed on to the bootstrap compiler if present
213configure.cxx_stdlib
214
215build.dir           ${configure.dir}
216build.target        bootstrap-lean
217
218destroot.target     install install-info-host
219
220# Is this gcc release supported here.
221if { ${os.platform} eq "darwin" && ${os.major} < 10 } {
222    known_fail  yes
223    pre-fetch {
224        ui_error "${name} ${version} is not supported on Darwin ${os.major} ${os.arch}"
225        return -code error "incompatible OS X version"
226    }
227}
228
229# gcc cannot build if libunwind-headers is active
230conflicts_build-append libunwind-headers
231
232# List of dylibs to be installed
233# Note that we really don't want to include libgcc_ext.10.[45].dylib here, but install_name_tool
234# doesn't know how to change the id of stubs, and it's easier than recreating them for each
235# gcc port.
236set dylibs {libgcc_ext.10.4.dylib libgcc_ext.10.5.dylib libgcc_s.1.dylib libgcc_s.1.1.dylib \
237                libgcc_s.2.dylib libgfortran.5.dylib libquadmath.0.dylib libstdc++.6.dylib \
238                libobjc-gnu.4.dylib libgomp.1.dylib libitm.1.dylib libssp.0.dylib libasan.8.dylib \
239                libubsan.1.dylib libatomic.1.dylib libgcc_ehs.1.1.dylib}
240
241if {${subport} ne ${name}} {
242
243    # Always provides primary runtime so always in conflict
244    conflicts libgcc-devel
245
246    # Activate hack for new libgcc
247    # https://trac.macports.org/wiki/PortfileRecipes#deactivatehack
248    pre-activate {
249        if {![catch {set installed [lindex [registry_active libgcc8] 0]}]} {
250            # Extract the epoch of the installed libgcc8
251            set _epoch [lindex $installed 5]
252            # If < 5 need to deactivate
253            if {[vercmp $_epoch 5] < 0} {
254                registry_deactivate_composite libgcc8 "" [list ports_nodepcheck 1]
255            }
256        }
257        if {![catch {set installed [lindex [registry_active libgcc10] 0]}]} {
258            # Extract the epoch of the installed libgcc10
259            set _epoch [lindex $installed 5]
260            # If < 6 need to deactivate
261            if {[vercmp $_epoch 6] < 0} {
262                registry_deactivate_composite libgcc10 "" [list ports_nodepcheck 1]
263            }
264        }
265        if {![catch {set installed [lindex [registry_active libgcc11] 0]}]} {
266            # Extract the epoch of the installed libgcc11
267            set _epoch [lindex $installed 5]
268            # If < 1 need to deactivate
269            if {[vercmp $_epoch 1] < 0} {
270                registry_deactivate_composite libgcc11 "" [list ports_nodepcheck 1]
271            }
272        }
273        if {![catch {set installed [lindex [registry_active libgcc-devel] 0]}]} {
274            # Extract the epoch of the installed libgcc-devel
275            set _epoch [lindex $installed 5]
276            # If < 5 need to deactivate
277            if {[vercmp $_epoch 5] < 0} {
278                registry_deactivate_composite libgcc-devel "" [list ports_nodepcheck 1]
279            }
280        }
281    }
282
283    # http://trac.macports.org/ticket/35770
284    # http://trac.macports.org/ticket/38814
285    # While there can be multiple versions of these runtimes in a single
286    # process, it is not possible to pass objects between different versions,
287    # so we simplify this by having the libgcc port provide the newest version
288    # of these runtimes for all versions of gcc to use.
289    #
290    # If there is a binary incompatible change to the runtime in a future
291    # version of gcc, then the latest version of gcc to provide a given ABI
292    # version should continue to provide a subport for that and older gcc
293    # versions.
294
295    depends_run
296    depends_lib-delete   port:zlib
297    depends_build-append {*}${depends_lib}
298    depends_lib          port:zlib port:libiconv
299
300    configure.args-replace \
301        --libdir=${prefix}/lib/${name} \
302        --libdir=${prefix}/lib/libgcc
303
304    # see https://trac.macports.org/ticket/54766
305    configure.args-replace \
306        --includedir=${prefix}/include/${name} \
307        --includedir=${prefix}/include/gcc
308
309    configure.args-replace \
310        --with-gxx-include-dir=${prefix}/include/${name}/c++/ \
311        --with-gxx-include-dir=${prefix}/include/gcc/c++/
312
313    # TODO: Possibly disable bootstrap with appropriate configure flags.
314    #       the problem is that libstdc++'s configure script tests for tls support
315    #       using the running compiler (not gcc for which libstdc++ is being built).
316    #       Thus when we build with clang, we get a mismatch
317    # http://trac.macports.org/ticket/36116
318    #compiler.blacklist-append {clang < 425}
319    #configure.args-append --disable-bootstrap
320    #build.target        all
321
322    post-destroot {
323
324        # Temporary working dir for dylibs
325        file mkdir ${destroot}${prefix}/lib/libgcc.merged
326
327        # loop over libs to install
328        foreach dylib ${dylibs} {
329
330            # Different OS versions (e.g. Leopard) or architectures (e.g. PPC) don't produce all the dylibs
331            # https://trac.macports.org/ticket/40098
332            # https://trac.macports.org/ticket/40100
333            if {! [file exists ${destroot}${prefix}/lib/libgcc/${dylib}]} {
334                continue
335            }
336
337            move ${destroot}${prefix}/lib/libgcc/${dylib} ${destroot}${prefix}/lib/libgcc.merged
338            if {[variant_exists universal] && [variant_isset universal]} {
339                foreach archdir [glob ${destroot}${prefix}/lib/libgcc/*/] {
340                    set archdir_nodestroot [string map "${destroot}/ /" ${archdir}]
341                    if {[file exists ${archdir}/${dylib}]} {
342                        system "install_name_tool -id ${prefix}/lib/libgcc/${dylib} ${archdir}/${dylib}"
343                        foreach link [glob -tails -directory ${archdir} *.dylib] {
344                            system "install_name_tool -change ${archdir_nodestroot}${link} ${prefix}/lib/libgcc/${link} ${archdir}/${dylib}"
345                        }
346                        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}"
347                    }
348                }
349            }
350
351            # strip debug symbols to supress debugger warnings:
352            # http://trac.macports.org/attachment/ticket/34831
353            if {! [string match *libgcc_ext* ${dylib}]} {
354                system "strip -x ${destroot}${prefix}/lib/libgcc.merged/${dylib}"
355            }
356        }
357
358        file delete -force ${destroot}${prefix}/bin
359        file delete -force ${destroot}${prefix}/share
360        file delete -force ${destroot}${prefix}/lib/libgcc
361        file delete -force ${destroot}${prefix}/libexec
362
363        move ${destroot}${prefix}/lib/libgcc.merged ${destroot}${prefix}/lib/libgcc
364
365        # For binary compatibility with binaries that linked against the old libstdcxx port
366        ln -s libgcc/libstdc++.6.dylib ${destroot}${prefix}/lib/libstdc++.6.dylib
367
368    }
369
370} else {
371
372    post-destroot {
373
374        file delete ${destroot}${prefix}/share/info/dir
375
376        foreach file [glob ${destroot}${prefix}/share/{info,man/man7}/*] {
377            set extension [file extension ${file}]
378            set newfile [regsub "${extension}$" ${file} "-mp-${major}${extension}"]
379            file rename ${file} ${newfile}
380        }
381
382        # loop over libs to install
383        foreach dylib ${dylibs} {
384            # Different OS versions (e.g. Leopard) or architectures (e.g. PPC) don't produce all the dylibs
385            # https://trac.macports.org/ticket/40098
386            # https://trac.macports.org/ticket/40100
387            if {[file exists ${destroot}${prefix}/lib/${name}/${dylib}]} {
388                delete ${destroot}${prefix}/lib/${name}/${dylib}
389                ln -s ${prefix}/lib/libgcc/${dylib} ${destroot}${prefix}/lib/${name}/${dylib}
390            }
391            if {[variant_exists universal] && [variant_isset universal]} {
392                foreach archdir [glob ${destroot}${prefix}/lib/${name}/*/] {
393                    if {[file exists ${archdir}/${dylib}]} {
394                        delete ${archdir}/${dylib}
395                        ln -s ${prefix}/lib/libgcc/${dylib} ${archdir}/${dylib}
396                    }
397                }
398            }
399        }
400
401    }
402
403    select.group        gcc
404    select.file         ${filespath}/mp-${name}
405
406}
407
408platform powerpc {
409    configure.universal_archs ppc ppc64
410}
411if { ${os.platform} eq "darwin" && ${os.major} >= 20 } {
412    platform i386 {
413        configure.universal_archs x86_64 arm64
414    }
415    platform arm {
416        configure.universal_archs x86_64 arm64
417    }
418} else {
419    platform i386 {
420        configure.universal_archs i386 x86_64
421    }
422}
423variant universal {
424    configure.args-delete --disable-multilib
425}
426# the generated compiler doesn't accept -arch
427configure.env-append \
428    "CPP=${configure.cc} -E" \
429    "CPP_FOR_BUILD=${configure.cc} -E" \
430    "CXXCPP=${configure.cxx} -E"
431build.env-append \
432    "CPP=${configure.cc} -E" \
433    "CPP_FOR_BUILD=${configure.cc} -E" \
434    "CXXCPP=${configure.cxx} -E"
435configure.cc-append [get_canonical_archflags]
436configure.cc_archflags
437configure.cxx-append ${configure.cxx_archflags}
438configure.cxx_archflags
439configure.objc_archflags
440configure.ld_archflags
441configure.universal_cflags
442configure.universal_cxxflags
443configure.universal_ldflags
444configure.universal_args
445
446livecheck.type      regex
447livecheck.url       http://mirror.koddos.net/gcc/releases/
448livecheck.regex     gcc-(${major}\\.\[0-9.\]+)/