PortSystem 1.0

name			apple-gcc40
version			5494
categories		lang
platforms		{darwin < 13}
license			GPL-2
maintainers		nomaintainer
description		Apple's version of gcc 4.0
long_description	Apple's version of the GNU compiler collection, \
			version 4.0. Supports C and Objective-C only.

homepage		http://opensource.apple.com/
#master_sites		https://github.com/apple-oss-distributions/gcc/archive/
# handle stealth update; remove with next version change
master_sites    macports_distfiles
distname		gcc_40-${version}

checksums           sha1    07574623e23103cb4024410ca48481fbb5da322e \
                    rmd160  d7a5d15d312b9d7295564cf3862ec63296e769a3 \
                    sha256  86b9c1d48c30042ba23d181a58ceeb3afb850b595206d976f78c985baea4b5ad

post-extract { file mkdir ${workpath}/build }

set nprefix ${prefix}/lib/${name}

# try to avoid non-Apple programs at all costs (rather volatile build)
configure.dir		${workpath}/build
configure.cmd		${worksrcpath}/configure
configure.pre_args	--prefix=${nprefix}
# C++ breaks!
configure.args		--enable-languages=c,objc \
			--program-suffix=-apple-4.0
configure.cflags
configure.ldflags
configure.cppflags
configure.env		PATH=/bin:/usr/bin:/sbin:/usr/sbin
configure.cxx_stdlib    libstdc++

patchfiles			patch-c-incpath.c.diff \
					patch-gcc-texi.diff

platform darwin 8 {
	patchfiles		patch-config-darwin.h
}

build.dir		${configure.dir}

destroot.dir		${build.dir}

# STAGE1_CFLAGS="-O2 -fkeep-inline-functions" : from configure.ac
# BOOT_CFLAGS="-O2 -g" : from Makefile.tpl
# -std=gnu89 : for building with compilers that default to c99 (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 -std=gnu89" STAGE1_CFLAGS="-O2 -fkeep-inline-functions -D_FORTIFY_SOURCE=0 -std=gnu89"

post-patch {
	reinplace "s/-DIN_GCC/-DIN_GCC -std=gnu89/" ${worksrcpath}/gcc/Makefile.in
}

post-destroot {
	file delete -force \
		${destroot}${nprefix}/man ${destroot}${nprefix}/info
	system "cd ${destroot}${prefix}/bin && ln -sf ${nprefix}/bin/gcc-apple-4.0 && ln -sf ${nprefix}/bin/cpp-apple-4.0"
}

# It's difficult to distinguish between Apple's gcc-4.0 and gcc-4.2 releases
livecheck.type  none