# Contributor: huangminzhong <huangminzhong2@huawei.com>
# Maintainer:  huangminzhong <huangminzhong2@huawei.com>
pkgname=x264
pkgver=stable
pkgrel=0
pkgdesc="x264 is a free software library and application for encoding video streams into the H.264/MPEG-4 AVC compression format, and is released under the terms of the GNU GPL."
url="https://www.videolan.org/developers/x264.html"
archs=("armeabi-v7a" "arm64-v8a")
license=("GNU GPLv2")
depends=()
makedepends=()

source="https://code.videolan.org/videolan/$pkgname/-/archive/$pkgver/$pkgname-$pkgver.tar.gz"

autounpack=true
downloadpackage=true
buildtools="configure"

builddir=$pkgname-$pkgver
packagename=$builddir.tar.gz

source envset.sh
host=
prepare() {
    # 拷贝两份，不污染源码目录
    cp $builddir $builddir-$ARCH-build -rf
    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
    export AS=$CC
}

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

package() {
    cd $builddir-$ARCH-build
    $MAKE install >> $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
}

check() {
    echo "The test must be on an OpenHarmony device!"
}

# 清理环境
cleanbuild() {
    rm -rf ${PWD}/$builddir $builddir-armeabi-v7a-build $builddir-arm64-v8a-build #${PWD}/$packagename
}
