# -*- 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
# $Id: Portfile 107759 2013-07-05 09:00:53Z jeremyhu@macports.org $

PortSystem 1.0
PortGroup select 1.0
PortGroup compiler_blacklist_versions 1.0

name                gcc47
epoch               1

# Whenever this port is bumped for version/revision, please revbump dragonegg-3.[34]-gcc-4.7
version             4.7.3
revision            1
platforms           darwin
categories          lang
maintainers         mww openmaintainer
# an exception in the license allows dependents to not be GPL
license             {GPL-3+ Permissive}
description         The GNU compiler collection
long_description    The GNU compiler collection, including front ends for \
                    C, C++, Objective-C, Objective-C++, Fortran and Java.

homepage            http://gcc.gnu.org/
master_sites        ftp://ftp.funet.fi/pub/mirrors/sources.redhat.com/pub/gcc/releases/gcc-${version}/:gcc \
                    ftp://ftp.gwdg.de/pub/linux/gcc/releases/gcc-${version}/:gcc \
                    ftp://gcc.ftp.nluug.nl/mirror/languages/gcc/releases/gcc-${version}/:gcc \
                    ftp://gcc.gnu.org/pub/gcc/releases/gcc-${version}/:gcc \
                    gnu:gcc/gcc-${version}:gcc \
                    ftp://sourceware.org/pub/java/:ecj \
                    http://mirrors.kernel.org/sources.redhat.com/java/:ecj \
                    http://www.mirrorservice.org/sites/sources.redhat.com/pub/java/:ecj \
                    http://ftp-stud.fht-esslingen.de/pub/Mirrors/sourceware.org/java/:ecj

use_bzip2           yes

set ecj             ecj-4.5.jar

distname            gcc-${version}

distfiles           [suffix ${distname}]:gcc ${ecj}:ecj

extract.only        [suffix ${distname}]

checksums           [suffix ${distname}] \
                    rmd160  b4ba153b098cad726ecd28195ee445aa542d37ae \
                    sha256  2f7c37eb4fc14422ff2358a9ef59c974a75ab41204ef0e49fc34ab1d8981a9c3 \
                    ${ecj} \
                    rmd160  d3f4da657f086b6423f74e93f001132f4855368a \
                    sha256  98fd128f1d374d9e42fd9d4836bdd249c6d511ebc6c0df17fbc1b9df96c3d781

depends_lib         port:gmp port:mpfr port:libiconv port:libmpc port:ppl port:cloog
depends_run         port:gcc_select port:ld64 port:cctools path:lib/libstdc\\\\+\\\\+.6.dylib:libstdcxx

depends_skip_archcheck-append gcc_select ld64 cctools
license_noconflict  gmp mpfr ppl libmpc

patchfiles          ppc_fde_encoding.diff  gcc-PR-53453.patch
patch.dir           ${workpath}/gcc-${version}

set major           4.7

worksrcdir          build

post-extract {
    file mkdir ${worksrcpath}
    copy ${distpath}/${ecj} ${workpath}/${distname}/ecj.jar
}

platform darwin {
    configure.pre_args-append --build=${build_arch}-apple-darwin${os.major}
}

configure.cmd       ../gcc-${version}/configure
configure.args      --enable-languages=c,c++,objc,obj-c++,lto,fortran,java \
                    --libdir=${prefix}/lib/${name} \
                    --includedir=${prefix}/include/${name} \
                    --infodir=${prefix}/share/info \
                    --mandir=${prefix}/share/man \
                    --datarootdir=${prefix}/share/gcc-${major} \
                    --with-libiconv-prefix=${prefix} \
                    --with-local-prefix=${prefix} \
                    --with-system-zlib \
                    --disable-nls \
                    --program-suffix=-mp-${major} \
                    --with-gxx-include-dir=${prefix}/include/${name}/c++/ \
                    --with-gmp=${prefix} \
                    --with-mpfr=${prefix} \
                    --with-mpc=${prefix} \
                    --with-ppl=${prefix} \
                    --with-cloog=${prefix} --enable-cloog-backend=isl \
                    --disable-cloog-version-check \
                    --enable-stage1-checking \
                    --disable-multilib \
                    --enable-lto \
                    --enable-libstdcxx-time \
                    --with-as=${prefix}/bin/as \
                    --with-ld=${prefix}/bin/ld \
                    --with-ar=${prefix}/bin/ar \
                    --with-bugurl=https://trac.macports.org/newticket
# remove this asap when upstream implements a check for ppl 1.0
configure.args-append --disable-ppl-version-check

configure.env-append \
                    AR_FOR_TARGET=${prefix}/bin/ar \
                    AS_FOR_TARGET=${prefix}/bin/as \
                    LD_FOR_TARGET=${prefix}/bin/ld \
                    NM_FOR_TARGET=${prefix}/bin/nm \
                    OBJDUMP_FOR_TARGET=${prefix}/bin/objdump \
                    RANLIB_FOR_TARGET=${prefix}/bin/ranlib \
                    STRIP_FOR_TARGET=${prefix}/bin/strip \
                    OTOOL=${prefix}/bin/otool \
                    OTOOL64=${prefix}/bin/otool

pre-configure {
    configure.args-append --with-pkgversion="MacPorts ${name} ${version}_${revision}${portvariants}"
}

# http://trac.macports.org/ticket/29067
compiler.blacklist-append gcc-4.0

# http://trac.macports.org/ticket/29104
compiler.blacklist-append {llvm-gcc-4.2 < 2336.1}

build.target        bootstrap
use_parallel_build  yes

destroot.target     install install-info-host

post-destroot {
    file delete -force ${destroot}${prefix}/share/man/man7 \
        ${destroot}${prefix}/share/info
    # install/copy ffitarget.h only if we have it
    if {![catch {set ffitarget.h [glob ${destroot}${prefix}/lib/${name}/gcc/*/${version}/include/ffitarget.h]} result]} {
        file copy ${ffitarget.h} ${destroot}${prefix}/include/${name}/
    }

    if {[variant_isset universal]} {
        foreach archdir [glob ${destroot}${prefix}/lib/${name}/*/] {
            if {[file exists ${archdir}/libstdc++.6.dylib]} {
                eval delete [glob ${archdir}/libstdc++*]

		# This symlink is provided as a transition aide and will be removed
		# with a future revision of this port.
                ln -s ${prefix}/lib/libstdc++.6.dylib ${archdir}/libstdc++.6.dylib
            }
        }
    }

    # http://trac.macports.org/ticket/35770
    eval delete [glob ${destroot}${prefix}/lib/${name}/libstdc++*]

    ln -s ${prefix}/lib/libstdc++.6.dylib ${destroot}${prefix}/lib/${name}/libstdc++.dylib

    # This symlink is provided as a transition aide and will be removed
    # with a future revision of this port.
    ln -s ${prefix}/lib/libstdc++.6.dylib ${destroot}${prefix}/lib/${name}/libstdc++.6.dylib
}

select.group        gcc
select.file         ${filespath}/mp-${name}

platform powerpc {
    configure.universal_archs ppc ppc64
}
platform i386 {
    configure.universal_archs i386 x86_64
}
variant universal {
    configure.args-delete --disable-multilib
}
# the generated compiler doesn't accept -arch
configure.env-append CPP="${configure.cc} -E"
build.env-append CPP="${configure.cc} -E"
configure.cc-append [get_canonical_archflags]
configure.cc_archflags
configure.cxx_archflags
configure.objc_archflags
configure.ld_archflags
configure.universal_cflags
configure.universal_cxxflags
configure.universal_ldflags
configure.universal_args

livecheck.type      regex
livecheck.url       http://gcc.gnu.org/gcc-4.7/
livecheck.regex     GCC (4\\.7\\.\[0-9\])

