#!/usr/bin/env bash
name='lld'
release='3'
version='18.1.1'
url='https://github.com/llvm/llvm-project'
description='The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.'
email='aliriza.keskin@pardus.org.tr'
maintainer='aliriza'
license=('GPLv3')
source=(
    "https://github.com/llvm/llvm-project/releases/download/llvmorg-$version/lld-$version.src.tar.xz"
    "https://github.com/llvm/llvm-project/releases/download/llvmorg-$version/cmake-$version.src.tar.xz"
    "https://github.com/llvm/llvm-project/releases/download/llvmorg-$version/libunwind-$version.src.tar.xz"
    "https://github.com/llvm/llvm-project/releases/download/llvmorg-$version/llvm-$version.src.tar.xz"
)

depends=(llvm)
makedepends=()
sha256sums=(
    '8456e8be08767f1f257733c5b56d0671d5b1a43fd78ffa53f024f307641f4612'
    '5308023d1c1e9feb264c14f58db35c53061123300a7eb940364f46d574c8b2d6'
    '999182a47a85dc27c426e301e100e6240082d602219a650137ea9a691c63dc53'
    'ab0508d02b2d126ceb98035c28638a9d7b1e7fa5ef719396236e72f59a02e1ac'
)

group=(sys.devel)
uses=()
arch=('x86_64')

cd $name-$version.src

prepare(){
    mv ../cmake{-$version.src,}
    mv ../libunwind{-$version.src,}
}

local cmake_args=(
    -G Ninja
    -DCMAKE_BUILD_TYPE=Release
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_INSTALL_DOCDIR=share/doc
    -DCMAKE_SKIP_RPATH=ON
    -DBUILD_SHARED_LIBS=ON
    -DLLVM_BUILD_DOCS=OFF
    -DLLVM_ENABLE_SPHINX=OFF
    -DLLVM_EXTERNAL_LIT=/usr/bin/lit
    -DLLVM_INCLUDE_TESTS=ON
    -DLLVM_LINK_LLVM_DYLIB=ON
    -DLLVM_INCLUDE_TESTS=OFF
    -DLLVM_MAIN_SRC_DIR="$(realpath ../llvm-$version.src)"
    -DSPHINX_WARNINGS_AS_ERRORS=OFF
)

setup(){
    mkdir build && cd build
    cmake .. ${cmake_args[@]}
}

build(){
    ninja -C build
}

package(){
    ninja -C build install
}

