Portfile

# $Id: Portfile 22478 2007-03-02 05:16:40Z pipping@macports.org $

PortSystem 1.0

name llvm
version 1.7
categories lang
platforms darwin
maintainers nomaintainer@macports.org
description llvm is a next generation compiler infrastructure
long_description llvm brings tools to work on the llvm intermediate \
language incl. a C and C++ frontend.

homepage http://llvm.org/
master_sites http://llvm.org/releases/${version}/

set dllvm llvm-${version}.tar.gz
set dcfront cfrontend-${version}.source.tar.gz
set dgccppc llvm-gcc4-${version}.powerpc-apple-darwin8.6.0.tar.gz
set dgcci386 llvm-gcc4-${version}.i686-apple-darwin8.6.1.tar.gz

distfiles ${dllvm} ${dcfront}

checksums ${dllvm} sha1 16aeb0ceb611d44be7aa2f0d88b8758f9f4d7c2f \
${dcfront} sha1 778d96bbdf279c0758b5c8ea462f8dabb18ca32e \
${dgccppc} sha1 91ecdbe7322da3ced5e99ad8441b3afb5bc2c596 \
${dgcci386} sha1 b24fc165f2ff0f9df5d6092275162b6d811c2687

platform powerpc {
distfiles-append ${dgccppc}
}

# i386 is untested, though this is "just" the bootstrap compiler
platform i386 {
distfiles-append ${dgcci386}
}

post-extract {
system "cd ${workpath} && ln -s llvm-gcc* llvm-gcc"
system "cd ${workpath}/llvm-gcc/bin && ln -s gcc llvm-gcc"
system "cd ${workpath}/llvm-gcc/bin && ln -s g++ llvm-g++"
system "cd ${workpath}/cfrontend && mkdir build install"
}

set llvmprefix ${prefix}/lib/llvm
set tmpdir ${workpath}/tmpdir

configure.pre_args --prefix=${llvmprefix}
configure.args --with-llvmgccdir=${workpath}/llvm-gcc/

worksrcdir llvm

build {
# build llvm
system "cd ${worksrcpath} && make all"

# configure, build && install gcc frontend
system "cd ${workpath}/cfrontend/build \
&& CFEINSTALL=${workpath}/cfrontend/install \
../src/configure --prefix=${llvmprefix} --disable-threads \
--disable-nls --disable-shared --enable-languages=c,c++ \
--program-prefix=llvm-"
system "cd ${workpath}/cfrontend/build && make all"
system "mkdir -p ${tmpdir}"
system "cd ${workpath}/cfrontend/build && make install DESTDIR=${tmpdir}"

# back to llvm backend
system "cd ${worksrcpath} && ./configure --prefix=${llvmprefix} \
--with-llvmgccdir=${tmpdir}${llvmprefix}"
system "cd ${worksrcpath} && make all"
}

set ranlib ${worksrcpath}/Release/bin/llvm-ranlib
destroot {
# install llvm
system "cd ${worksrcpath} \
&& make -C runtime install-bytecode DESTDIR=${destroot}"

# install llvm
xinstall -m 755 -d ${destroot}${llvmprefix}/bin ${destroot}${llvmprefix}/lib
system "cd ${worksrcpath}/Release/bin \
&& cp * ${destroot}${llvmprefix}/bin"
system "cd ${worksrcpath}/Release/lib \
&& cp * ${destroot}${llvmprefix}/lib"

# install cfrontend
system "cd ${workpath}/cfrontend/build && make install DESTDIR=${destroot}"

# ranlib all libs
system "find ${destroot}${llvmprefix} -name \\.a -exec ${ranlib} \{\} \\;"

# symlink tools into place
foreach bin {ar as bcanalyzer c++ cpp db dis extract g++ gcc gccbug gcov ld link nm prof ranlib stub} {
system "cd ${destroot}${prefix}/bin \
&& ln -s ../lib/llvm/bin/llvm-${bin} llvm-${bin}"
}
foreach bin {llc lli analyze bugpoint burg fpcmp llvmc gccas gccld} {
system "cd ${destroot}${prefix}/bin \
&& ln -s ../lib/llvm/bin/${bin} ${bin}"
}
}

post-destroot {
# put manpages into place
system "cd ${destroot}${llvmprefix}/man/man1 \
&& mv llvm-g++.1 llvm-gcc.1 ${destroot}${prefix}/share/man/man1/"

# delete superflous manpages, info files
system "rm -rf ${destroot}${llvmprefix}/man"
system "rm -rf ${destroot}${llvmprefix}/info"
}