#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -e

if [[ "$1" == "build" ]] || ((NO_BUILD)); then
    exit 0
fi

APKBUILD="pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/APKBUILD"
if [[ ! -f "$APKBUILD" ]]; then
    echo "APKBUILD not found at $APKBUILD, run mkosi once with -ff to make sure the APKBUILD is cloned" >&2
    exit 1
fi

# shellcheck source=/dev/null
CARCH="$DISTRIBUTION_ARCHITECTURE" \
     _systemd_upstream=1 \
     . "$APKBUILD"

# shellcheck disable=SC2086
mkosi-install ${makedepends:?}
