### this file is sourced not run
PKGVER=4.0.1
PKGBUILD=1
PKGARCH=i686

# source: post-BLFS 7.8 (2015-12-23)
TARBALL=llvm-$PKGVER.src.tar.xz
MD5SUM=a818e70321b91e2bb2d47e60edd5408f
SRC_URL=http://llvm.org/releases/$PKGVER/$TARBALL
BUNDLE=

SLACKREQ='libffi libxml2'
SLACKDESC="llvm32: llvm32 $PKGVER (Low-Level-Virtual-Machine (LLVM) library)  
llvm32:  
llvm32: The LLVM package contains a collection of modular and reusable compiler 
llvm32: and toolchain technologies. The Low Level Virtual Machine (LLVM) Core 
llvm32: libraries provide a modern source and target-independent optimizer, 
llvm32: along with code generation support for many popular CPUs (as well as 
llvm32: some less common ones). These libraries are built around a well 
llvm32: specified code representation known as the LLVM intermediate 
llvm32: representation (\"LLVM IR\").  
llvm32: 
llvm32: This package contains 32-bit libraries.
"

### default pkg_download
### default pkg_prepare
### package - only collect the libraries
pkg_package() {
	rm -rf bin sbin usr/bin usr/sbin usr/include usr/share
	mkdir -p usr/bin usr/include/llvm/Config &&
	mv -v tmp/llvm-config-32 usr/bin &&
	mv -v tmp/llvm-config-32.h usr/include/llvm/Config
}

### build
pkg_build() {
	cd /tmp/llvm*
	
	mkdir -v build &&
	cd       build &&

	# official cmake build commands from LLVM
	# -DLLVM_BUILD_LLVM_DYLIB=ON - stable, recommended, but big
	# -DBUILD_SHARED_LIBS=ON - experimental, not recommended, but small	
	cmake .. -DCMAKE_INSTALL_PREFIX=/usr  \
	-DLLVM_TARGETS_TO_BUILD="host;AMDGPU" \
	-DLLVM_ENABLE_FFI=ON                  \
	-DCMAKE_BUILD_TYPE=Release            \
	-DLLVM_ENABLE_ASSERTIONS=OFF          \
    -DLLVM_ENABLE_PIC=ON                  \
    -DLLVM_BUILD_TOOLS=OFF				\
	-DLLVM_BUILD_EXAMPLES=OFF			\
	-DLLVM_INCLUDE_EXAMPLES=OFF			\
	-DLLVM_BUILD_TESTS=OFF				\
	-DLLVM_INCLUDE_TESTS=OFF			\
	-DLLVM_BUILD_DOCS=OFF				\
    -DCMAKE_C_FLAGS="${BUILD32} -O2"      \
    -DCMAKE_CXX_FLAGS="${BUILD32} -O2"    \
    -DLLVM_BUILD_32_BITS=ON               \
    -Wno-dev                              \
	&&

	make $MAKEFLAGS && 
	
	#Since we disabled the build of all tools above we have to build llvm-config manually
	make llvm-config &&
	install -m755 /tmp/llvm-*/build/bin/llvm-config /usr/bin/ &&
	
	make $MAKEINSTALLFLAGS install &&
	pkg_build_slackdesc &&
	
	# CBLFS multilib patch
	mv -v /usr/bin/llvm-config /tmp/llvm-config-32 &&
	mv -v /usr/include/llvm/Config/llvm-config.h /tmp/llvm-config-32.h
	
	return 0
}

