SUMMARY="A llvm front end compiler for C and C++" 
DESCRIPTION="
Clang is an 'LLVM native' C/C++/Objective-C compiler, which aims to deliver \
amazingly fast compiles (e.g. about 3x faster than GCC when compiling \
Objective-C code in a debug configuration), extremely useful error and warning \
messages and to provide a platform for building great source level tools.
"

HOMEPAGE="http://www.llvm.org/"
LICENSE="UIUC"
COPYRIGHT="2003-2012 University of Illinois at Urbana-Champaign"

SOURCE_URI="http://llvm.org/releases/${portVersion}/llvm-${portVersion}.src.tar.gz"
CHECKSUM_SHA256="25a5612d692c48481b9b397e2b55f4870e447966d66c96d655241702d44a2628"

SOURCE_URI_2="http://llvm.org/releases/${portVersion}/clang-${portVersion}.src.tar.gz"
CHECKSUM_SHA256_2="22a9780db3b85a7f2eb9ea1f7f6e00da0249e3d12851e8dea0f62f1783242b1b"

REVISION="2"

ARCHITECTURES="x86 x86_64"
if [ $effectiveTargetArchitecture != x86_gcc2 ]; then
	ARCHITECTURES="$ARCHITECTURES x86_gcc2"
fi
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	clang$secondaryArchSuffix = $portVersion
	cmd:clang = $portVersion
	cmd:clang++ = $portVersion
	cmd:c_index_test = $portVersion
	lib:libLTO$secondaryArchSuffix = $portVersion
	lib:libclang$secondaryArchSuffix = $portVersion
	devel:libLTO$secondaryArchSuffix = $portVersion
	devel:libclang$secondaryArchSuffix = $portVersion
	"

REQUIRES="
	haiku$secondaryArchSuffix
	lib:libstdc++$secondaryArchSuffix
	"

BUILD_REQUIRES="
	"

BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:gcc$secondaryArchSuffix
	cmd:groff
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize
	cmd:make
	cmd:python
	cmd:sed
	"

SOURCE_DIR="llvm-${portVersion}"

PATCHES="llvm-${portVersion}.patchset"
PATCHES_2="clang-${portVersion}.patchset"

BUILD()
{
	mkdir -p tools/clang
	cp -rd $sourceDir2/clang-${portVersion}/* tools/clang/
	#cp -r /boot/system/data/libtool/config/. autoconf/
	#cp -r /boot/system/data/libtool/config/. projects/sample/autoconf/
	
	# Haiku C++ requires rtti in a lot of central system components
	# such as Mesa
	export REQUIRES_RTTI=1

	# TODO: clang's build system seems to ignore doc / man / shared dirs?
	runConfigure ./configure --enable-optimized
	make $jobArgs PROJ_datadir=$dataDir PROJ_docsdir=$docDir \
		PROJ_mandir=$manDir PROJ_includedir=$includeDir PROJ_libdir=$libDir
}

INSTALL()
{
	mkdir -p $developDir
	mkdir -p $docDir
	mkdir -p $binDir

	make install-clang PROJ_datadir=$dataDir PROJ_docsdir=$docDir \
		PROJ_mandir=$manDir PROJ_includedir=$includeDir PROJ_libdir=$libDir

	# Remove empty dir that shouldn't be created
	rmdir $prefix/include
	
	# Install static analysis tools
	mkdir -p $developDir/tools/clang$secondaryArchSuffix
	cp -Ra tools/clang/tools/scan-build $developDir/tools/clang$secondaryArchSuffix/
	cp -Ra tools/clang/tools/scan-view $developDir/tools/clang$secondaryArchSuffix/
	
	ln -s $developDir/tools/clang$secondaryArchSuffix/scan-build/scan-build $binDir/scan-build
	ln -s $developDir/tools/clang$secondaryArchSuffix/scan-view/scan-view $binDir/scan-view
	ln -s $binDir/clang $developDir/tools/clang$secondaryArchSuffix/scan-build/clang
	
	prepareInstalledDevelLibs libclang libLTO

	# analysis package
	packageEntries analysis \
		$binDir/scan-build \
		$binDir/scan-view \
		$developDir/tools/clang$secondaryArchSuffix
}

TEST()
{
	make check
}


# ----- analysis package -------------------------------------------------------

SUMMARY_analysis="Static analysis tools using the clang compiler"
PROVIDES_analysis="
	clang${secondaryArchSuffix}_analysis = $portVersion
	cmd:scan_build$secondaryArchSuffix = $portVersion
	cmd:scan_view$secondaryArchSuffix = $portVersion
	"

REQUIRES_analysis="
	clang$secondaryArchSuffix == $portVersion base
	"
