#!/bin/sh

. $Y_PORT_UTILS/sig.sh

set -e

SRC_FILENAME="lua-${Y_PORT_VERSION}.tar.gz"
SRC_SHA256="9fbf5e28ef86c69858f6d3d34eccc32e911c1a28b4120ff3e84aaa70cfbf1e30"
RELEASE_BASE="https://www.lua.org/ftp"
RELEASE_URL="$RELEASE_BASE/$SRC_FILENAME"

build_dir=$3

mkdir -p $build_dir
cd $build_dir

if [ ! -f .source-ready ]; then
    curl -LO $RELEASE_URL
    verify_sha256 $SRC_SHA256 $SRC_FILENAME

    tar xf $SRC_FILENAME

    cd lua-${Y_PORT_VERSION}
    for patch in $1/patches/*.patch; do
        echo Apply $patch
        patch -p1 <$patch
    done

    touch $build_dir/.source-ready
fi
