##
##  bazel.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package information
Name:         bazel
Summary:      Google's Build Tool
URL:          http://bazel.io/
Vendor:       Google
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Building
License:      GPL
Version:      0.20.0
Release:      20181130

#   list of sources
Source0:      https://github.com/bazelbuild/bazel/releases/download/%{version}/bazel-%{version}-dist.zip
Patch0:       bazel.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, java, JAVA-JDK
PreReq:       OpenPKG, openpkg >= 20160101, java, JAVA-JDK

%description
    Bazel is Google's own build tool. It has built-in support for
    building both client and server software, including client
    applications for both Android and iOS platforms. It also provides
    an extensible framework that you can use to develop your own build
    rules.

%track
    prog bazel = {
        version   = %{version}
        url       = https://github.com/bazelbuild/bazel/releases
        regex     = (\d+\.\d+\.\d+)\.tar\.gz
    }

%prep
    %setup -q -c
    chmod 644 scripts/bootstrap/bootstrap.sh
    chmod 644 src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt
    %patch -p0

%build
    %{l_shtool} subst %{l_value -s -a} \
        src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt
    %{l_shtool} subst \
        -e "s;/etc/bazel.bazelrc;%{l_prefix}/etc/bazel.bazelrc;" \
        src/main/cpp/blaze_util_posix.cc
    %{l_shtool} subst \
        -e 's;/bin/bash;%{l_bash};g' \
        tools/cpp/link_dynamic_library.sh
    echo "build --strategy=Javac=standalone" >>scripts/packages/debian/bazel.bazelrc
    eval `%{l_prefix}/bin/java-toolkit -e`
    export PROTOC=%{l_prefix}/bin/protoc
    export BAZEL_SH=%{l_bash}
    if [ -x %{l_prefix}/bin/bazel ]; then
        %{l_bash} compile.sh compile %{l_prefix}/bin/bazel
    else
        %{l_bash} compile.sh compile
    fi

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/bazel \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/bazel
    %{l_shtool} install -c -m 755 \
        output/bazel $RPM_BUILD_ROOT%{l_prefix}/libexec/bazel/bazel
    (   echo "#!/bin/sh"
        echo "BAZEL_SH=%{l_bash}; export BAZEL_SH"
        echo "exec %{l_prefix}/libexec/bazel/bazel \${1+\"\$@\"}"
    ) >$RPM_BUILD_ROOT%{l_prefix}/bin/bazel
    chmod a+x $RPM_BUILD_ROOT%{l_prefix}/bin/bazel
    %{l_shtool} install -c -m 644 \
        scripts/packages/debian/bazel.bazelrc \
        $RPM_BUILD_ROOT%{l_prefix}/etc/bazel/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/bazel/*'

%files -f files

%clean

