# $Id: Portfile 71393 2010-09-11 22:47:28Z jmr@macports.org $

PortSystem 1.0

name			gdc
version			0.24
revision		2
set gcc_version		4.1.2
categories		lang
platforms		darwin
maintainers		mww
description		D language compiler
long_description	gcc ${gcc_version} with D language frontend, a new \
				language by digitalmars

homepage		http://dgcc.sourceforge.net/
master_sites		sourceforge:dgcc:gdc \
				gnu:/gcc/gcc-${gcc_version}:gcc
set gdc			gdc-${version}-src.tar.bz2
set gcc_core		gcc-core-${gcc_version}.tar.bz2
set gcc_cxx		gcc-g++-${gcc_version}.tar.bz2
distfiles		${gdc}:gdc ${gcc_core}:gcc ${gcc_cxx}:gcc
checksums		${gdc} sha1 2be913fe061429c1a279e4cf882e947d34946303 \
			${gcc_core} sha1 d6875295f6df1bec4a6f4ab8f0da54bfb8d97306 \
			${gcc_cxx} sha1 e29c6e151050f8b5ac5d680b99483df522606143
use_bzip2		yes
patchfiles		patch-config-i386-darwin.h

set bindir		${prefix}/lib/${name}/bin
set incdir		${prefix}/include/d/${gcc_version}
worksrcdir		build

post-extract {
	file mkdir ${worksrcpath}
	system "ln -sf ${workpath}/d ${workpath}/gcc-${gcc_version}/gcc/d"
}

patch.dir	${workpath}/gcc-${gcc_version}
post-patch {
	system "cd ${workpath}/gcc-${gcc_version}/ && gcc/d/setup-gcc.sh"
	reinplace "s|tjmp %%edx|tjmp *%%edx|" ${workpath}/gcc-${gcc_version}/gcc/config/i386/i386.c
}

# the generated compiler doesn't accept -arch
configure.cc_archflags
configure.cxx_archflags
configure.objc_archflags
configure.ld_archflags

configure.cmd		${workpath}/gcc-${gcc_version}/configure
configure.args		--enable-languages=d,c \
			--bindir=${bindir} \
			--libdir=${prefix}/lib/${name} \
			--includedir=${incdir} \
			--with-gxx-include-dir=${prefix}/include/d/${gcc_version} \
			--infodir=${prefix}/share/info \
			--mandir=${prefix}/share/man \
			--libexecdir=${prefix}/libexec/${name} \
			--with-system-zlib \
			--disable-nls \
			--disable-multilib \
			--with-local-prefix=${prefix}

build.type		gnu
#build.target	bootstrap-lean

post-destroot {
	# install wrapper - this way calling 'gdc' and 'gdmd' just works
	foreach wrp {gdc gdmd} {
		xinstall -m 755 ${filespath}/wrapper.sh ${destroot}${prefix}/bin/${wrp}
		reinplace "s|__BIN__|${bindir}/${wrp}|g" ${destroot}${prefix}/bin/${wrp}
		reinplace "s|__INCDIR__|${incdir}|g" ${destroot}${prefix}/bin/${wrp}
	}

	# remove unnecessary manpages
	foreach man1page {cpp gcc gcov g++} {
		file delete ${destroot}${prefix}/share/man/man1/${man1page}.1
	}
	file delete -force ${destroot}${prefix}/share/man/man7 \
		${destroot}${prefix}/share/info

	# only need -I${incdir} this way:
	system "cd ${destroot}${incdir}/gcc \
		&& find .. -name config.d -exec ln -s {} \\; \
		&& find .. -name configunix.d -exec ln -s {} \\;"
	system "cd ${destroot}${incdir} \
		&& find . -name phobos-ver-syms -exec ln -s {} \\;"
}

livecheck.type	regex
livecheck.url	http://sourceforge.net/export/rss2_projfiles.php?project=dgcc
livecheck.regex	gdc-(\[0-9\.\]+)-src.tar

