# -*- 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

PortSystem          1.0

name                gcc7-bootstrap

version             7.5.0
revision            0

platforms           {darwin < 9}
categories          lang
maintainers         nomaintainer

# an exception in the license allows dependents to not be GPL
license             {GPL-3+ Permissive}

description         isolated gcc version used for bootstrapping.
long_description    ${description}
homepage            https://gcc.gnu.org/

master_sites        http://gcc.gnu.org/pub/gcc/releases/gcc-${version}/:gcc \
                    gnu:gcc/gcc-${version}:gcc \
                    http://gcc.gnu.org/pub/gcc/infrastructure/:gccinfrastructure \
                    gnu:gcc/infrastructure:gccinfrastructure

distname            gcc-${version}
dist_subdir         gcc

set    MPFR         mpfr-4.1.0
set    GMP          gmp-6.2.1
set    MPC          mpc-1.2.1
set    ISL          isl-0.24

distfiles           ${distname}${extract.suffix}:gcc \
                    ${MPFR}.tar.bz2:gccinfrastructure \
                    ${GMP}.tar.bz2:gccinfrastructure \
                    ${MPC}.tar.gz:gccinfrastructure \
                    ${ISL}.tar.bz2:gccinfrastructure

checksums           gcc-7.5.0.tar.gz \
                    rmd160  e5d647a8d26cd300b17b1a7defefe9292bf7a5d9 \
                    sha256  4f518f18cfb694ad7975064e99e200fe98af13603b47e67e801ba9580e50a07f \
                    size    112743638 \
                    mpfr-4.1.0.tar.bz2 \
                    rmd160  7a6d028b63c864566f62d47a58521e00a2890c28 \
                    sha256  feced2d430dd5a97805fa289fed3fc8ff2b094c02d05287fd6133e7f1f0ec926 \
                    size    1747243 \
                    gmp-6.2.1.tar.bz2 \
                    rmd160  2a4204453eb608bec6bb647ff5a0c47ca4d43878 \
                    sha256  eae9326beb4158c386e39a356818031bd28f3124cf915f8c5b1dc4c7a36b4d7c \
                    size    2493916 \
                    mpc-1.2.1.tar.gz \
                    rmd160  8c25b71d080936aab6ffa84f4f9d99b662d82c47 \
                    sha256  17503d2c395dfcf106b622dc142683c1199431d095367c6aacba6eec30340459 \
                    size    838731 \
                    isl-0.24.tar.bz2 \
                    rmd160  b3bf8e1ad50207d4eebecc47cb4cffdac6581a57 \
                    sha256  fcf78dd9656c10eb8cf9fbd5f59a0b6b01386205fe1934b3b287a0a1898145c0 \
                    size    2261594 \
                    make-3.81.tar.gz \
                    rmd160  a713a72875cb9a29568677c98022465c6f55cbbf \
                    sha256  16b77de9f013bcd536b7bc1efbe314223aedfe250f9063e33cbb4dfd347215a2 \
                    size    1564560


extract {
    foreach f ${distfiles} {
        set f [lindex [split ${f} :] 0]
        ui_debug "Extracting: ${f}"
        if {[string match "*bz2*" ${f}]} {
            system -W ${workpath} "/usr/bin/tar xjf [shellescape ${distpath}/${f}]"
        }
        if {[string match "*gz*" ${f}]}  {
            system -W ${workpath} "/usr/bin/tar xzf [shellescape ${distpath}/${f}]"
        }
    }
}

post-extract {
    ln -s ${workpath}/${MPFR} ${worksrcpath}/mpfr
    ln -s ${workpath}/${GMP}  ${worksrcpath}/gmp
    ln -s ${workpath}/${MPC}  ${worksrcpath}/mpc
    ln -s ${workpath}/${ISL}  ${worksrcpath}/isl
}


# Skip bootstrap comparison
post-patch {
    reinplace {s|^do-compare =|do-compare = /usr/bin/true|g} \
        ${worksrcpath}/Makefile.in \
        ${worksrcpath}/config/bootstrap-debug.mk \
        ${worksrcpath}/config/bootstrap-debug-lean.mk \
        ${worksrcpath}/config/bootstrap-debug-lib.mk
}

# sterilize MacPorts build environment
compiler.cpath
compiler.library_path

configure.cxx_stdlib

configure.cflags
configure.cxxflags
configure.cppflags
configure.optflags
configure.ldflags

configure.universal_cflags
configure.universal_cxxflags
configure.universal_cppflags
configure.universal_ldflags
configure.universal_args

configure.ccache    no
configure.distcc    no

configure.env-append    PATH=/usr/bin:/bin:/usr/sbin:/sbin
build.env-append        PATH=/usr/bin:/bin:/usr/sbin:/sbin

set prefix_frozen   ${prefix}
prefix              ${prefix}/libexec/${name}

platform darwin 8 i386 {
    patchfiles-append patch-gcc7-tiger-intel.diff
}

configure.cmd       ${worksrcpath}/configure
configure.dir       ${workpath}/build
configure.args      --enable-languages=c,c++,objc,obj-c++ \
                    --enable-bootstrap \
                    --with-system-zlib \
                    --without-zstd \
                    --disable-nls \
                    --disable-tls \
                    --with-bugurl=https://trac.macports.org/newticket

build.dir           ${configure.dir}
build.target        bootstrap-lean

universal_variant   no

platform darwin 8 {

    # Tiger has special requirements.
    # apple-gcc42 is required for most Tiger software. It requires cctools and ld64
    # to be installed to properly function. gcc7 is configured to run against these.
    # so cctools and ld64 need to be lib_deps for gcc7 on Tiger.

    depends_lib port:cctools port:ld64
    depends_skip_archcheck-append cctools ld64

    # Tiger comes with make 3.80 but we need 3.81
    set    MAKE_V       make-3.81

    master_sites-append gnu:make:gccmake
    distfiles-append    ${MAKE_V}.tar.gz:gccmake
    checksums-append    make-3.81.tar.gz \
                        rmd160  a713a72875cb9a29568677c98022465c6f55cbbf \
                        sha256  16b77de9f013bcd536b7bc1efbe314223aedfe250f9063e33cbb4dfd347215a2 \
                        size    1564560

    pre-configure {
        file mkdir ${workpath}/bins
        system -W ${workpath}/${MAKE_V}    "CC=/usr/bin/cc ./configure && make"
        ln -s ${workpath}/${MAKE_V}/make   ${workpath}/bins/make
    }

    configure.env-append    MAKE=${workpath}/bins/make
    build.env-append        MAKE=${workpath}/bins/make

    configure.env-replace   PATH=/usr/bin:/bin:/usr/sbin:/sbin \
                            PATH=${workpath}/bins:/usr/bin:/bin:/usr/sbin:/sbin

    build.env-replace       PATH=/usr/bin:/bin:/usr/sbin:/sbin \
                            PATH=${workpath}/bins:/usr/bin:/bin:/usr/sbin:/sbin
    configure.args-append \
                    --with-dwarf2 \
                    --with-as=${prefix_frozen}/bin/as \
                    --with-ld=${prefix_frozen}/bin/ld \
                    --with-ar=${prefix_frozen}/bin/ar
}

livecheck.type      none
