# $Id: Portfile 93033 2012-05-14 07:33:24Z jeremyhu@macports.org $

PortSystem 1.0
PortGroup select 1.0

name                gcc48
version             4.8-20120506
platforms           darwin
categories          lang
maintainers         mww openmaintainer
license             GPL-3
description         The GNU compiler collection, prerelease BETA
long_description    The GNU compiler collection, including front ends for \
                    C, C++, Objective-C and Objective-C++. This is a \
                    prerelease BETA version and does not have all \
                    available language front ends enabled.

homepage            http://gcc.gnu.org/
master_sites        ftp://ftp.gwdg.de/pub/linux/gcc/snapshots/${version}/ \
                    ftp://ftp.funet.fi/pub/mirrors/sources.redhat.com/pub/gcc/snapshots/${version}/ \
                    ftp://gcc.gnu.org/pub/gcc/snapshots/${version}/ \
                    http://mirrors-us.seosue.com/gcc/snapshots/${version}/ \
                    http://gcc.skazkaforyou.com/snapshots/${version}/

distname            gcc-${version}

checksums           md5     b34cd6c14fd042233b4237fdde4d7f7b \
                    rmd160  c9a7d536dc683839324ebbd97b37e5397492e392 \
                    sha256  0ff0591a5ce39c6bace4a9fc6e26d986c88dece5758dda44c0dce74ce51588bc

supported_archs     i386 x86_64

use_bzip2           yes

depends_lib         port:gmp port:mpfr port:libiconv port:libmpc port:ppl port:cloog
depends_run         port:gcc_select port:ld64 port:cctools

depends_skip_archcheck-append gcc_select ld64 cctools

set major           4.8

worksrcdir          build

post-extract {
    file mkdir ${worksrcpath}
}

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++ \
                    --libdir=${prefix}/lib/${name} \
                    --includedir=${prefix}/include/${name} \
                    --infodir=${prefix}/share/info \
                    --mandir=${prefix}/share/man \
                    --datarootdir=${prefix}/share/gcc-${major} \
                    --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 \
                    --enable-stage1-checking \
                    --disable-multilib \
                    --enable-lto \
                    --with-as=${prefix}/bin/as \
                    --with-ld=${prefix}/bin/ld \
                    --with-ar=${prefix}/bin/ar \
                    --with-bugurl=https://trac.macports.org/newticket

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/29104
if {${configure.compiler} == "llvm-gcc-4.2"} {
    configure.compiler clang
}

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}/
    }
}

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

# due to popular request - untested for the BETA; will be removed as soon as other languages than C compile successfuly
variant gfortran conflicts java \
    description "Enables Fortran/gfortran; this language will be enabled in the final version - this variant is completely untested!" {
    configure.args-delete --enable-languages=c,c++,objc,obj-c++
    configure.args-append --enable-languages=c,c++,objc,obj-c++,fortran
}

# due to popular request - untested for the BETA; will be removed as soon as other languages than C compile successfuly
variant java conflicts gfortran \
    description "Enables Java/gcj; this language will be enabled in the final version - this variant is completely untested!" {
    configure.args-delete --enable-languages=c,c++,objc,obj-c++
    configure.args-append --enable-languages=c,c++,objc,obj-c++,java
    post-destroot {
        file rename ${destroot}${prefix}/share/python/aotcompile.py \
            ${destroot}${prefix}/share/python/aotcompile-46.py
        file rename ${destroot}${prefix}/share/python/classfile.py \
            ${destroot}${prefix}/share/python/classfile-46.py
    }
}

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       ftp://gcc.gnu.org/pub/gcc/snapshots/
livecheck.regex     LATEST-4.8 -> (4.8-\[0-9\]+)
