# Maintainer: Evangelos Foutras <foutrelis@archlinux.org>
# Contributor: Jan "heftig" Steffens <jan.steffens@gmail.com>

pkgname=lldb
pkgver=21.1.5
pkgrel=1
pkgdesc="Next generation, high-performance debugger"
arch=('x86_64' 'aarch64')
url="https://lldb.llvm.org/"
license=('Apache-2.0 WITH LLVM-exception')
depends=('llvm-libs' 'clang' 'gcc-libs' 'zlib' 'xz' 'libedit' 'ncurses'
         'libxml2' 'python')
makedepends=('llvm' 'cmake' 'ninja' 'swig' 'python-sphinx')
_source_base=https://github.com/llvm/llvm-project/releases/download/llvmorg-$pkgver
source=($_source_base/lldb-$pkgver.src.tar.xz{,.sig}
        $_source_base/llvm-$pkgver.src.tar.xz{,.sig}
        $_source_base/cmake-$pkgver.src.tar.xz{,.sig})
sha256sums=('d1d40bedb280062f21997aa5cf5e518cc2dea11dcddbd1d306b08394e7c7f15f'
            'SKIP'
            'c9d6ca5073255192850471a276b3a00a6555c6dd09df6cb3eab77801f0a1cae0'
            'SKIP'
            '48013d5714a96419bf993a2e5e4c5827377e8cf9c565070731fb2305d50d9511'
            'SKIP')
validpgpkeys=('474E22316ABF4785A88C6E8EA2C794A986419D8A'  # Tom Stellard <tstellar@redhat.com>
              'D574BD5D1D0E98895E3BF90044F2485E45D59042'  # Tobias Hieta <tobias@hieta.se>
              'FFB3368980F3E6BB5737145A316C56D064CACBA5'  # Douglas Yung <douglas.yung@sony.com>
              '71046D1E9C6656BDD61171873E83BABF4A4F9E85'  # Cullen Rhodes <cullen.rhodes@arm.com>
)

prepare() {
  rename -v -- "-$pkgver.src" '' {llvm,cmake}-$pkgver.src
  cd lldb-$pkgver.src
  mkdir build
}

build() {
  cd lldb-$pkgver.src/build

  # Build only minimal debug info to reduce size
  CFLAGS=${CFLAGS/-g /-g1 }
  CXXFLAGS=${CXXFLAGS/-g /-g1 }

  local cmake_args=(
    -G Ninja
    -DCMAKE_BUILD_TYPE=Release
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_SKIP_RPATH=ON
    -DCLANG_LINK_CLANG_DYLIB=ON
    -DLLVM_ENABLE_SPHINX=ON
    -DLLVM_LINK_LLVM_DYLIB=ON
  )
  cmake .. "${cmake_args[@]}"
  ninja all docs-lldb-man
}

package() {
  cd lldb-$pkgver.src/build

  DESTDIR="$pkgdir" ninja install
  install -Dm644 ../LICENSE.TXT "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  install -Dm644 docs/man/lldb.1 "$pkgdir/usr/share/man/man1/lldb.1"

  # Compile Python scripts
  python -m compileall -d /usr/lib "$pkgdir/usr/lib"
  python -O -m compileall -d /usr/lib "$pkgdir/usr/lib"
  python -OO -m compileall -d /usr/lib "$pkgdir/usr/lib"
}

# vim:set ts=2 sw=2 et:
