# Build recipe for luarocks.
#
# Copyright (C) 2020 Kevin "The Nuclear" Bloom, <kevin.bloom@posteo.net>.
# Copyright (c) 2020-2021 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=luarocks
version=3.5.0
arch=noarch
release=1

# Define major version for Lua release
lua_version=5.4

# Define a category for the output of the package name
pkgcategory=lua

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=https://luarocks.org/releases/${tarname}

description="
The package manager for Lua modules.

Luarocks allows you to create and install Lua modules
as self-contained packages called \"rocks\".
"

homepage=https://luarocks.org/
license="MIT License"

# Source documentation
docs="CHANGELOG.md COPYING CODE_OF_CONDUCT.md README.md"
docsdir="${docdir}/${program}-${version}"

# Limit parallel jobs for this build
jobs=1

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure \
     --prefix=/usr \
     --with-lua=/usr \
     --with-lua-lib=/usr/lib${libSuffix} \
     --sysconfdir=/etc \
     --lua-version=${lua_version}

    make -j${jobs}
    make -j${jobs} DESTDIR="$destdir" install
    mkdir -p "${destdir}/usr/lib${libSuffix}/luarocks/rocks-${lua_version}"

    # To manage (dot) new files
    touch "${destdir}/etc/luarocks/.graft-config"

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"
    cp -p $docs "${destdir}${docsdir}"
}

