# Template file for 'libcxx'
pkgname=libcxx
version=11.0.0
revision=1
wrksrc="${pkgname}-${version}.src"
build_style=cmake
configure_args+=" -DLIBCXX_CXX_ABI=libcxxabi -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON
 -DLIBCXX_CXX_ABI_LIBRARY_PATH=${XBPS_CROSS_BASE}/usr/lib
 -DLIBCXXABI_USE_LLVM_UNWINDER=1"
hostmakedepends="llvm11 clang-tools-extra python3"
makedepends="libcxxabi-devel llvm11 llvm-libunwind-devel"
short_desc="New implementation of the C++ standard library, targeting C++11, C++14 and above"
maintainer="Orphaned <orphan@voidlinux.org>"
license="NCSA, MIT"
homepage="https://libcxx.llvm.org"
distfiles="
 https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/libcxx-${version}.src.tar.xz
 https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/libcxxabi-${version}.src.tar.xz
 https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/llvm-${version}.src.tar.xz"
checksum="
 6c1ee6690122f2711a77bc19241834a9219dda5036e1597bfa397f341a9b8b7a
 58697d4427b7a854ec7529337477eb4fba16407222390ad81a40d125673e4c15
 913f68c898dfb4a03b397c5e11c6a2f39d0f22ed7665c9cefa87a34423a72469"

case "$XBPS_TARGET_MACHINE" in
	*-musl) configure_args+=" -DLIBCXX_HAS_MUSL_LIBC=YES"
esac

post_extract() {
	case "$XBPS_TARGET_MACHINE" in
	*-musl) patch -Np1 <${FILESDIR}/libcxx-0001-musl-hacks.patch ;;
	esac

	# Since llvm 11, libcxxabi and llvm need to be present next to the libcxx root
	mv ../libcxxabi-${version}.src ../libcxxabi
	mv ../llvm-${version}.src ../llvm
}

post_patch() {
	case "$XBPS_TARGET_MACHINE" in
		i686-musl|ppc-musl) ;;
		*) return 0 ;;
	esac
	vsed -i 's,#ssp,,' CMakeLists.txt
}

post_install() {
	vlicense LICENSE.TXT
}

libcxx-devel_package() {
	short_desc+=" - development files"
	depends="${sourcepkg}>=${version}_${revision}"
	pkg_install() {
		vmove usr/include
		vmove "usr/lib/*.so"
		vmove "usr/lib/*.a"
	}
}
