# $Id: Portfile 92064 2012-04-17 03:12:49Z jeremyhu@macports.org $

PortSystem 1.0
PortGroup select 1.0

name			gcc42
version			4.2.4
revision		3
platforms		darwin
categories		lang
maintainers		mww openmaintainer
# an exception in the license allows dependents to not be GPL
license			{GPL-3+ GPL-2+ Permissive}
description		The GNU compiler collection
long_description	The GNU compiler collection, including front ends for \
			C, C++, Objective-C, Objective-C++, Java and Fortran95.

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}

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		${dcore} sha1 540fa6949415ded321a7cbe80bbf8befe85e3566 \
			${dfort} sha1 7b476983f8b8405a456b30704cd91c7b238381c9 \
			${dcxx} sha1 8b0ed65c5314e0a598a120a841cd00eedd183760 \
			${djava} sha1 ce9587329585c35f870157f3fc937c0dd746b4f3 \
			${dobjc} sha1 5e14e4960b2a0bf74dd867fe71071429b2631406

use_bzip2		yes

# gmp and mpfr are not universal
universal_variant	no

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

set major		4.2

worksrcdir		build

patch {
	# fix names of infopages
	foreach f { cpp cppinternals gcc gccint} {
		reinplace "s|${f}.info|${f}-mp-${version}.info|g" ${workpath}/gcc-${version}/gcc/doc/${f}.texi
	}
}

# the generated compiler doesn't accept -arch
configure.cc-append [get_canonical_archflags]
configure.cc_archflags
configure.cxx_archflags
configure.objc_archflags
configure.ld_archflags
platform darwin {
    if {${os.major} >= 10} {
        depends_lib
        depends_run
        pre-fetch {
            ui_error "$name does not build on Snow Leopard or later."
            error "unsupported platform"
        }
    }
    if {${configure.build_arch} == "x86_64" || ${configure.build_arch} == "ppc64"} {
        configure.pre_args-append --build=${configure.build_arch}-apple-${os.platform}${os.version} \
                                  --host=${configure.build_arch}-apple-${os.platform}${os.version}
    }
}

pre-configure {
	file mkdir ${worksrcpath}
}

configure.cmd		../gcc-${version}/configure
configure.args		--enable-languages=c,c++,java,objc,obj-c++,fortran \
			--libdir=${prefix}/lib/${name} \
			--includedir=${prefix}/include/${name} \
			--infodir=${prefix}/share/info \
			--mandir=${prefix}/share/man \
			--with-local-prefix=${prefix} \
			--with-system-zlib \
			--disable-nls \
			--disable-multilib \
			--program-suffix=-mp-${major} \
			--with-gxx-include-dir=${prefix}/include/${name}/c++/ \
			--with-gmp=${prefix} \
			--with-mpfr=${prefix} \
			--with-as=${prefix}/bin/as \
			--with-ld=${prefix}/bin/ld \
			--with-ar=${prefix}/bin/ar
 
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


use_parallel_build	yes

destroot.target		install install-info-host

post-destroot {
	file delete -force ${destroot}${prefix}/share/man/man7 \
		${destroot}${prefix}/share/info
}

post-destroot {
	# 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}

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