# Description: Low Level Virtual Machine, collection of modular and reusable compiler and toolchain.
# URL: http://llvm.org/
# Maintainers: Chris Lattner <sabre at nondot dot org>
# Packager: pierre at nutyx dot org, tnut at nutyx dot org
# Depends on: python 

name=llvm
version=3.7.1
release=1

source=(http://llvm.org/releases/$version/$name-$version.src.tar.xz
	http://llvm.org/releases/$version/cfe-$version.src.tar.xz
	http://llvm.org/releases/$version/compiler-rt-$version.src.tar.xz)

build() {
cd $name-$version.src

mv ../compiler-rt-${version}.src projects/compiler-rt
mv ../cfe-$version.src tools/clang

sed -r "/ifeq.*CompilerTargetArch/s#i386#i686#g" \
    -i projects/compiler-rt/make/platform/clang_linux.mk

case `uname -m` in
        x86_64)
                enable_pic="yes";;
        i?86)
                enable_pic="no";;
esac
sed -e 's:/docs/llvm:/share/doc/llvm-$version:' \
    -i Makefile.config.in

mkdir -v build
cd build
CC=gcc CXX=g++ \
../configure --prefix=/usr \
	--datarootdir=/usr/share \
	--sysconfdir=/etc \
	--enable-libffi \
	--enable-optimized \
	--enable-shared \
	--enable-targets=host,r600 \
	--disable-assertions \
	--docdir=/usr/share/doc/$name-$version
make || make -j1
make DESTDIR=$PKG install || make -j1 DESTDIR=$PKG install
for file in '$PKG/usr/lib/lib{clang,LLVM,LTO}*.a'
do
	test -f $file && chmod -v 644 $file
done

install -v -dm755 $PKG/usr/lib/clang-analyzer

for prog in scan-build scan-view
do
	cp -rfv ../tools/clang/tools/$prog $PKG/usr/lib/clang-analyzer/
	ln -sfv ../lib/clang-analyzer/$prog/$prog $PKG/usr/bin/
done

install -d $PKG/etc/ld.so.conf.d
echo /usr/lib/llvm > $PKG/etc/ld.so.conf.d/llvm.conf

ln -sfv /usr/bin/clang $PKG/usr/lib/clang-analyzer/scan-build/
mkdir -p $PKG/usr/share/man/man1

mv -v $PKG/usr/lib/clang-analyzer/scan-build/scan-build.1 $PKG/usr/share/man/man1/

}
