# $Id: Portfile 80371 2011-07-10 19:57:48Z jeremyhu@macports.org $

PortSystem 1.0
PortGroup select 1.0

name			gcc44
epoch			1
version			4.4.6
platforms		darwin
categories		lang
maintainers		mww
license			GPLv3
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           gcc-core-${version}.tar.bz2 \
                    md5     c618dde07a74e0d28ba3acd487bb0f3b \
                    sha1    f305ef9c57e8016d37e7726091cb9d5c4013f9aa \
                    rmd160  9bb03852015c16a041566007b83c179178fe06f9 \
                    gcc-fortran-${version}.tar.bz2 \
                    md5     af4577ef1a0aa801d791f98f7ef00ffd \
                    sha1    525b46dbfa572a0cd05c94152db5284b7e0387cb \
                    rmd160  2898f72a9e421424b629284faf93640d20f6e71f \
                    gcc-g++-${version}.tar.bz2 \
                    md5     e1e292564cf230d3ef1f08c206c261a8 \
                    sha1    d12b7fc05ec637d8417f1f5cbc0eedabc79458d5 \
                    rmd160  47c6680e554990cdf2963a0a0b4ed497c85caf61 \
                    gcc-java-${version}.tar.bz2 \
                    md5     0eb904ebc271a3ad667e7e880b6e4b41 \
                    sha1    b0555747acf72c0dede49d04c2dd6f3c6924d640 \
                    rmd160  55379da854e3bc05760e677c6f0ae048e0fb981b \
                    gcc-objc-${version}.tar.bz2 \
                    md5     09deb28b6f8cb63e81bc8d771be9f345 \
                    sha1    f9889d6ce2dcbb2d9ff48baebc11ef4a3621eb06 \
                    rmd160  2cad9c429b0b856f6646b6a392da43e4ada6d82e

use_bzip2		yes

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

patch.dir       ${workpath}/gcc-${version}

set major		4.4

worksrcdir		build

# the generated compiler doesn't accept -arch
configure.cc_archflags
configure.cxx_archflags
configure.objc_archflags
configure.ld_archflags
platform darwin {
    configure.pre_args-append --build=${build_arch}-apple-darwin${os.major}
}

post-extract {
	file mkdir ${worksrcpath}
}

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 \
		--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} \
		--enable-stage1-checking \
		--disable-multilib
# 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

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

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 10 {
	configure.args-append --enable-fully-dynamic-string
}

platform darwin 11 {
	configure.args-append --enable-fully-dynamic-string
}

# odcctools currently do not compile for x64 - move to variant for the time being
variant odcctools \
	description "Use the odcctools instead of the system provided ones - does not work for x64 currently!" {
	depends_lib-append	port:odcctools
	post-patch {
		reinplace "s|/usr/bin/libtool|${prefix}/bin/odlibtool|g" \
			${workpath}/gcc-${version}/gcc/config/darwin.h
	}
	configure.args-append	--with-as=${prefix}/bin/odas \
				--with-ld=${prefix}/bin/odld \
				--with-ar=${prefix}/bin/odar
}

platform powerpc {
    configure.universal_archs ppc ppc64
}
platform i386 {
    configure.universal_archs i386 x86_64
}
configure.universal_cflags
configure.universal_cxxflags
configure.universal_ldflags
configure.universal_args
variant universal {
    configure.args-delete --disable-multilib
}

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