app=llvm
version=10.0.1
build=2sml
homepage="http://llvm.org/"
desc="LLVM compiler toolkit"
requires="libffi libxml2 perl"

build() {
  mkandenterbuilddir
  rm -rf $app-"$version".src

  tar xf $srcdir/$app-"$version".src.tar.?z*
  cd $app-"$version".src 
  fixbuilddirpermissions

  applypatch $srcdir/0001-Disable-dynamic-lib-tests-for-musl-s-dlclose-is-noop.patch
  applypatch $srcdir/fix-LLVMConfig-cmake-install-prefix.patch
  applypatch $srcdir/fix-memory-mf_exec-on-aarch64.patch
  applypatch $srcdir/python3-test.patch
  
  # We don't need our optimisations for small builds
  unset CFLAGS CXXFLAGS
  mkdir -p smbuild && cd smbuild

  # Set build targets
  if [ "$arch" = "x86_64" ] ; then
    buildtarget='X86;AMDGPU;BPF'
  elif [ "$arch" = "aarch64" ] ; then
    buildtarget="AArch64;ARM;BPF"
  fi

  cmake .. -Wno-dev \
    -DCMAKE_BUILD_TYPE=MinSizeRel \
    -DCMAKE_INSTALL_PREFIX="/" \
    -DLLVM_BUILD_DOCS=OFF \
    -DLLVM_BUILD_EXAMPLES=OFF \
    -DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON \
    -DLLVM_BUILD_LLVM_DYLIB=ON \
    -DLLVM_BUILD_TESTS=ON \
    -DLLVM_ENABLE_CXX1Y=ON \
    -DLLVM_ENABLE_FFI=ON \
    -DLLVM_ENABLE_LIBCXX=OFF \
    -DLLVM_ENABLE_PIC=ON \
    -DLLVM_ENABLE_RTTI=ON \
    -DLLVM_ENABLE_SPHINX=OFF \
    -DLLVM_ENABLE_TERMINFO=ON \
    -DLLVM_ENABLE_ZLIB=ON \
    -DLLVM_INCLUDE_EXAMPLES=OFF \
    -DLLVM_LINK_LLVM_DYLIB=ON \
    -DLLVM_APPEND_VC_REV=OFF \
    -DLLVM_INSTALL_UTILS=ON \
    -DLLVM_TARGETS_TO_BUILD="$buildtarget" 

  make llvm-tblgen
  make
  python3 ../utils/lit/setup.py build
  make install DESTDIR=$pkg 

  cp ../LICENSE.TXT $pkgdocs/

  mkfinalpkg
}

sha512sums="
cf34d037c1684d09e7e38d5fc131714eac93c78353d6186b2f806a8fb22dcae0f4748ce22d6faf178c95cfcf20bdc3fa7c5238518a154b3112781f5ab70edaa4  llvm-10.0.1.src.tar.xz
695502bd3b5454c2f5630c59a8cf5f8aeb0deac16a76a8a4df34849e1e35c12ed4234572a320fe4c7e96f974f572f429eb816c5aa3dcfb17057f550eac596495  0001-Disable-dynamic-lib-tests-for-musl-s-dlclose-is-noop.patch
7d4825d16107e56a14b7b05be847f03d75e2e05952bea0742a1233b5b0441c9934d8058e612abb6471272884372d9bfd3348355fbd3c19cba82a554003cc3eec  fix-LLVMConfig-cmake-install-prefix.patch
64b9ecb246cc94ce7f617b3699b3306de0872a1a9b0ade88563330aa6f9a60742bb1d73f95743d0f033ea8b1535e2e612250c8f50bddf4419741ca18f40eca1d  fix-memory-mf_exec-on-aarch64.patch
53cc0d13dd871e9b775bb4e7567de4f9a97d91b8246cd7ce74607fd88d6e3e2ab9455f5b4195bc7f9dbdedbc77d659d43e98ec0b7cd78cd395aaea6919510287  python3-test.patch
"
