#!/bin/sh

# SPDX-FileCopyrightText: 2021 Andrius Štikonas <andrius@stikonas.eu>
# SPDX-FileCopyrightText: 2021-22 Samuel Tyler <samuel@samuelt.me>
# SPDX-FileCopyrightText: 2021 Paul Dersey <pdersey@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later

set -ex

# Check tarball checksums
checksum-transcriber sources
sha256sum -c sources.SHA256SUM

mkdir build src
cd build

# Extract
cp ${DISTFILES}/${pkg}.tar.gz ../src/
gzip -d -f ../src/${pkg}.tar.gz
untar --file ../src/${pkg}.tar
rm -r ../src

cd ${pkg}

# Prepare
cp ../../mk/main.mk Makefile
cp ../../files/getdate_stub.c lib/getdate_stub.c
catm src/create.c.new ../../files/stat_override.c src/create.c
cp src/create.c.new src/create.c

# Build
make -f Makefile

# Install
cp tar ${PREFIX}/bin/tar
chmod 755 ${PREFIX}/bin/tar

cd ../..

# Checksums
if match x${UPDATE_CHECKSUMS} xTrue; then
    sha256sum -o ${pkg}.checksums \
        /usr/bin/tar

    cp ${pkg}.checksums ${SRCDIR}
else
    sha256sum -c ${pkg}.checksums
fi
