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.xz"
CHECKSUM_SHA256="bf3275d2d7890015c8d8f5e6f4f882f8cf3bf51967297ebe74111d6d8b53be15"

SOURCE_URI_2="http://llvm.org/releases/${portVersion}/cfe-${portVersion}.src.tar.xz"
CHECKSUM_SHA256_2="6773f3f9cf815631cc7e779ec134ddd228dc8e9a250e1ea3a910610c59eb8f5c"

SOURCE_URI_3="http://llvm.org/releases/${portVersion}/clang-tools-extra-${portVersion}.src.tar.xz"
CHECKSUM_SHA256_3="e8d011250389cfc36eb51557ca25ae66ab08173e8d53536a0747356105d72906"

REVISION="1"

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.src"

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

BUILD()
{
	# Add clang tools
	mkdir -p tools/clang
	cp -rd $sourceDir2/cfe-${portVersion}.src/* tools/clang/

	# Add clang tools's tool's (really llvm?)
	mkdir -p tools/clang/tools/extra
	cp -rd $sourceDir3/clang-tools-extra-${portVersion}.src/* tools/clang/tools/extra
	
	# 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
	"
