# $Id: Portfile 67424 2010-05-09 08:30:29Z mww@macports.org $

PortSystem 1.0

name			gcc46
version			4.6-20100508
platforms		darwin
categories		lang
maintainers		mww
license			GPLv3
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}/

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-${version}.tar.bz2 \
                    md5     8ba704b7c3f741e2640762201eaa7bb3 \
                    sha1    01672a44844c5a663f67043972d7b15266f65c28 \
                    rmd160  368f769c0bb6eaaddca0627bf8480e178558c7ad \
                    gcc-fortran-${version}.tar.bz2 \
                    md5     cc801a8814ccc1b4f81f3c8a57cee429 \
                    sha1    292511c76a3f2797201dddd0ae826c97fdac6320 \
                    rmd160  efd4d2456452e9ac66842f7b8bc0df03a87fdc42 \
                    gcc-g++-${version}.tar.bz2 \
                    md5     4457a96af1244e4e5d4213ce7d0ced9e \
                    sha1    8599f936c66520d328752db5222ef509be917a76 \
                    rmd160  7b48d44c800a926db216484227ea789e10ca5c0b \
                    gcc-java-${version}.tar.bz2 \
                    md5     59ce09dab13e8711938b556e206aab91 \
                    sha1    ef51c9ade9e9eaa16eddf841f7fa94e83c49aab7 \
                    rmd160  9287fc3d29e5bb69bb085c6c75f0e4ed41bdc4e4 \
                    gcc-objc-${version}.tar.bz2 \
                    md5     fd6a4db8468ce6b96ad33c14b018ebd8 \
                    sha1    0aae17fc79c1d7e3b02073fccecd91e80cdc31d0 \
                    rmd160  bdc05738a54ad1631505be94bdaccbc44603b337

use_bzip2		yes

# gmp and mpfr are not universal
universal_variant       no

depends_lib		port:gmp port:mpfr port:libiconv port:libmpc

set major		4.6

worksrcdir		build

# the generated compiler doesn't accept -arch
if {[info exists build_arch] && ${os.platform} == "darwin"} {
    configure.cc_archflags
    configure.cxx_archflags
    configure.objc_archflags
    configure.pre_args-append --build=${build_arch}-apple-darwin${os.major}
}

pre-configure {
	file mkdir ${worksrcpath}
}

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} \
		--enable-stage1-checking
# do NOT use MacPorts binutils -- they do not work
configure.env-append    AR_FOR_TARGET=/usr/bin/ar \
			AS_FOR_TARGET=/usr/bin/as \
			LD_FOR_TARGET=/usr/bin/ld \
			NM_FOR_TARGET=/usr/bin/nm \
			OBJDUMP_FOR_TARGET=/usr/bin/objdump \
			RANLIB_FOR_TARGET=/usr/bin/ranlib \
			STRIP_FOR_TARGET=/usr/bin/strip

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}/
	}
	# install select file for gcc_select
	xinstall -m 755 -d ${destroot}${prefix}/etc/select/gcc
	xinstall -m 444 ${filespath}/mp-gcc46 ${destroot}${prefix}/etc/select/gcc/
}

platform powerpc {
	configure.args-append --disable-multilib
}

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

livecheck.type	regex
livecheck.url	ftp://gcc.gnu.org/pub/gcc/snapshots/
livecheck.regex	LATEST-4.6 -> (4.6-\[0-9\]+)

