#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you 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.
#

# Maintainer: Apache Pulsar <dev@pulsar.apache.org>

pkgname="apache-pulsar-client"
pkgver="$VERSION"
pkgrel=0
pkgdesc="Apache Pulsar - distributed pub-sub messaging system"
url="https://pulsar.apache.org"
arch="all"
license="https://www.apache.org/licenses/LICENSE-2.0.txt"
depends=""
makedepends=""
install=""
subpackages="$pkgname-dev"
source=""
builddir="$srcdir/"

build() {
  set -x -e
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
    git clone https://github.com/microsoft/vcpkg.git
    mv vcpkg $ROOT_DIR/
    export VCPKG_FORCE_SYSTEM_BINARIES=1
    set +e
    cmake -B build -DINTEGRATE_VCPKG=ON -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_MAKE_PROGRAM=make \
        -DCMAKE_INSTALL_PREFIX="/usr" \
        -DBUILD_TESTS=OFF -DBUILD_DYNAMIC_LIB=ON -DBUILD_STATIC_LIB=ON \
        $ROOT_DIR
    if [[ $? -ne 0 ]]; then
        cat $ROOT_DIR/vcpkg/buildtrees/detect_compiler/*.log
        exit 1
    fi
    set -e
    cmake --build build -j8
    $ROOT_DIR/build-support/merge_archives_vcpkg.sh $PWD/build
}

package() {
    set -x -e
    DESTDIR="$pkgdir" cmake --build build --target install
    cp ./build/libpulsarwithdeps.a "$pkgdir/usr/lib/"
}
