#!/bin/sh

# SPDX-FileCopyrightText: 2021-22 Samuel Tyler <samuel@samuelt.me>
#
# SPDX-License-Identifier: GPL-3.0-or-later

set -ex

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

mkdir build
cd build

# Extract
ungz --file ${DISTFILES}/${pkg}.tar.gz --output ${pkg}.tar
untar --file ${pkg}.tar
rm ${pkg}.tar
cd ${pkg}
cp ../../mk/main.mk Makefile

# Create config.h and patchlevel.h
catm config.h
catm patchlevel.h

# Build
make -f Makefile PREFIX=${PREFIX}

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

cd ../..

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

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