#!/usr/bin/env bash
name='lld'
release='4'
version='19.1.7'
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=(
    '630bf0f31b210e89fd7869bdfd6c376d010fc3b72ee42f08058435035c432e42'
    '11c5a28f90053b0c43d0dec3d0ad579347fc277199c005206b963c19aae514e3'
    '10e650f436bc416674f01b5e01177405886f4d0f0b2568c6808044eacad52ea0'
    '96f833c6ad99a3e8e1d9aca5f439b8fd2c7efdcf83b664e0af1c0712c5315910'
)

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 ${jobs}
}

package(){
    ninja -C build install ${jobs}
}

