# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Contributor: luozhu <luozhu2@h-partners.com>
# Maintainer: luozhu <luozhu2@h-partners.com>

pkgname=qpdf
pkgver=v11.6.3
pkgrel=0
pkgdesc="QPDF is a command-line tool and C++ library that performs content-preserving transformations on PDF files. "
url="https://github.com/qpdf/qpdf"
archs=("armeabi-v7a" "arm64-v8a")
license=("Apache License 2.0")
depends=("openssl" "jpeg" "zlib")
makedepends=()

source="https://github.com/$pkgname/$pkgname/archive/refs/tags/$pkgver.tar.gz"

autounpack=true
downloadpackage=true

builddir=$pkgname-${pkgver:1}
packagename=$builddir.tar.gz

patchflag=true
prepare() {
    if $patchflag
    then
       cd $builddir
       patch -p1 < ../qpdf_ohos_test.patch
       cd $OLDPWD
       patchflag=false
    fi
    mkdir -p $builddir/$ARCH-build
}

build() {
    cd $builddir
    PKG_CONFIG_LIBDIR="${pkgconfigpath}" cmake "$@" -DBUILD_SHARED_LIBS=OFF -B$ARCH-build -S./ > $buildlog 2>&1
    $MAKE -C $ARCH-build >> $buildlog 2>&1
    ret=$?
    cd $OLDPWD
    return $ret
}

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

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

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