# $Id: Portfile 93031 2012-05-14 07:27:38Z jeremyhu@macports.org $

PortSystem 1.0
PortGroup select 1.0

name                gcc44
epoch               1
version             4.4.7
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}/ \
                    ftp://ftp.gwdg.de/pub/linux/gcc/releases/gcc-${version}/ \
                    ftp://gcc.ftp.nluug.nl/mirror/languages/gcc/releases/gcc-${version}/ \
                    ftp://gcc.gnu.org/pub/gcc/releases/gcc-${version}/ \
                    gnu:gcc/gcc-${version}

use_bzip2           yes

set dcore           gcc-core-${version}.tar.bz2
set dfort           gcc-fortran-${version}.tar.bz2
set dcxx            gcc-g++-${version}.tar.bz2
set djava           gcc-java-${version}.tar.bz2
set dobjc           gcc-objc-${version}.tar.bz2

distfiles           ${dcore} ${dfort} ${dcxx} ${djava} ${dobjc}
 
checksums           gcc-core-4.4.7.tar.bz2 \
                    md5     3bda0831d654964ee152c46fa8d29e46 \
                    sha1    6db82d9cb0c9c0bd93c80c972e8b08b8dca2455d \
                    rmd160  eb53966a8077cc6753ba06a1f542bf699b3cd95c \
                    gcc-fortran-4.4.7.tar.bz2 \
                    md5     38496cf90e69c99b5fc0fef023a2d9ce \
                    sha1    ef9f57d587fd79b15b9bb61b6a480d859037400a \
                    rmd160  542b0052fcacfde4524bc7695698ff7532c2c8c2 \
                    gcc-g++-4.4.7.tar.bz2 \
                    md5     5494ba2227ccbd7c90f318723b0e7fe5 \
                    sha1    d6c030fd2c666956366ba784e77491adb0b9ad2d \
                    rmd160  50e0aa25aa61efe92d2f2b574eaf5efacf998bee \
                    gcc-java-4.4.7.tar.bz2 \
                    md5     a777517bed21fb850c74dd7015171608 \
                    sha1    891b16c7414d4f5d241c1bd3264b6d198a6a1108 \
                    rmd160  61f947efef544bfbf8333a9ccf867e9c33a379a7 \
                    gcc-objc-4.4.7.tar.bz2 \
                    md5     64121f41d2bd70e51733aaff9e34f41f \
                    sha1    d87e56cf6216795e8c0fd7148918d2e09790c24d \
                    rmd160  660d8e2f8162458e463de6195e58391ee711ed59

depends_lib         port:gmp port:mpfr port:libiconv
depends_run         port:gcc_select port:ld64 port:cctools

depends_skip_archcheck-append gcc_select ld64 cctools

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

set major           4.4

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++,java,fortran \
                    --libdir=${prefix}/lib/${name} \
                    --includedir=${prefix}/include/${name} \
                    --infodir=${prefix}/share/info \
                    --mandir=${prefix}/share/man \
                    --datadir=${prefix}/share/${name} \
                    --with-local-prefix=${prefix} \
                    --with-libiconv-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} \
                    --enable-stage1-checking \
                    --disable-multilib \
                    --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
}

# STAGE1_CFLAGS="-O2 -fkeep-inline-functions" : from configure.ac
# BOOT_CFLAGS="-O2 -g" : from Makefile.tpl
# -std=gnu89 : for building with clang
# -D_FORTIFY_SOURCE=0 : The built compiler might not understand newer builtins
#                       exposed in libc headers for fortified string functions.
#                       Yes, we need to set both BOOT_CFLAGS and STAGE1_CFLAGS
#                       because STAGE1_CFLAGS is used with xgcc for libgcc
build.args-append BOOT_CFLAGS="-O2 -g -D_FORTIFY_SOURCE=0" STAGE1_CFLAGS="-O2 -fkeep-inline-functions -D_FORTIFY_SOURCE=0 -std=gnu89"
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}/
    }
    file rename ${destroot}${prefix}/share/python/aotcompile.py \
                ${destroot}${prefix}/share/python/aotcompile-44.py
    file rename ${destroot}${prefix}/share/python/classfile.py \
                ${destroot}${prefix}/share/python/classfile-44.py
}

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

platform darwin {
    if {${os.major} >= 10} {
        configure.args-append --enable-fully-dynamic-string
    }
}

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.4/
livecheck.regex     GCC (4\\.4\\.\[0-9\])
