#!/bin/bash

set -xe

if [ -z "$TARGET" ]; then
    echo "TARGET is not set";
    exit 1
fi

# Build libgpg-error
export LIBGPG_ERROR_VER=1.39
cd /usr/src
curl -sSL "https://www.gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-${LIBGPG_ERROR_VER}.tar.bz2" | tar -xj
cd libgpg-error-$LIBGPG_ERROR_VER
./configure --host "$TARGET" --prefix="$PREFIX" --with-pic --enable-fast-install --disable-dependency-tracking --enable-static --disable-shared --disable-nls --disable-doc --disable-languages --disable-tests
make -j$(nproc) install

# Build libassuan
export LIBASSUAN_VER=2.5.3
cd /usr/src
curl -sSL "https://www.gnupg.org/ftp/gcrypt/libassuan/libassuan-${LIBASSUAN_VER}.tar.bz2" | tar -xj
cd "libassuan-$LIBASSUAN_VER"
./configure --host "$TARGET" --prefix="$PREFIX" --with-pic --enable-fast-install --disable-dependency-tracking --enable-static --disable-shared --disable-doc --with-gpg-error-prefix="$PREFIX"
make -j$(nproc) install

# Build gpgme
export GPGME_VER=1.14.0
cd /usr/src
curl -sSL "https://www.gnupg.org/ftp/gcrypt/gpgme/gpgme-${GPGME_VER}.tar.bz2" | tar -xj
cd "gpgme-$GPGME_VER"
./configure --host "$TARGET" --prefix="$PREFIX" --with-pic --enable-fast-install --disable-dependency-tracking --enable-static --disable-shared --disable-languages --disable-gpg-test --with-gpg-error-prefix="$PREFIX" --with-libassuan-prefix="$PREFIX"
make -j$(nproc) install
