# Contributor: Jeff Han <hanjinfei@foxmail.com>
# Maintainer: Jeff Han <hanjinfei@foxmail.com>
pkgname=gmp
pkgver=6.2.1
pkgrel=0
pkgdesc="GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers. There is no practical limit to the precision except the ones implied by the available memory in the machine GMP runs on. GMP has a rich set of functions, and the functions have a regular interface."
url="https://gmplib.org/"
archs=("armeabi-v7a" "arm64-v8a")
license=("gplv2" "gplv3")
depends=()
makedepends=()

source="https://gmplib.org/download/$pkgname/$pkgname-$pkgver.tar.xz"

downloadpackage=true
autounpack=true
buildtools="configure"

builddir=$pkgname-${pkgver}
packagename=$builddir.tar.xz

source envset.sh
host=

prepare() {
    mkdir -p $builddir/$ARCH-build
    if [ $ARCH == "armeabi-v7a" ]
    then
        setarm32ENV
        host=arm-linux
    elif [ $ARCH == "arm64-v8a" ]
    then
        setarm64ENV
        host=aarch64-linux
    else
        echo "${ARCH} not support"
        return -1
    fi
}

build() {
    cd $builddir/$ARCH-build
    ../configure "$@" --host=$host > $buildlog 2>&1
    $MAKE >> $buildlog 2>&1
    ret=$?
    cd $OLDPWD
    return $ret
}

package() {
    cd $builddir/$ARCH-build
    $MAKE install >> $buildlog 2>&1
    cd $OLDPWD
}

check() {
    cd $builddir/$ARCH-build
    $MAKE libtests.la t-bswap t-constants t-count_zeros t-hightomask t-modlinv t-popc t-parity t-sub -C tests/ >> $buildlog 2>&1
    cd $OLDPWD
    unset host
    if [ $ARCH == "armeabi-v7a" ]
    then
        unsetarm32ENV
    elif [ $ARCH == "arm64-v8a" ]
    then
        unsetarm64ENV
    else
        echo "${ARCH} not support"
        return -1
    fi

    echo "The test must be on an OpenHarmony device!"
    # real test CMD
    # make check-TESTS VERBOSE=1 -C tests/
}

# 清理环境
cleanbuild() {
    rm -rf ${PWD}/$builddir #${PWD}/$packagename
}
