##
##  boost.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 version
%define       V_openpkg    1.89.0
%define       V_dist       1_89_0

#   package information
Name:         boost
Summary:      Peer-Reviewed Portable C++ Libraries
URL:          http://www.boost.org/
Vendor:       Boost Community
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Language
License:      Boost Software License
Version:      %{V_openpkg}
Release:      20250822

#   package options
%option       with_threads   yes
%option       with_zlib      yes
%option       with_bzip2     yes
%option       with_optimize  yes
%option       with_inlining  no
%option       with_debug     no
%option       with_pch       no

#   list of sources
Source0:      https://archives.boost.io/release/%{V_openpkg}/source/boost_%{V_dist}.tar.gz
Patch0:       boost.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, gcc::with_cxx = yes
PreReq:       OpenPKG, openpkg >= 20160101
%if "%{with_zlib}" == "yes"
BuildPreReq:  zlib
PreReq:       zlib
%endif
%if "%{with_bzip2}" == "yes"
BuildPreReq:  bzip2
PreReq:       bzip2
%endif

%description
    Boost provides peer-reviewed portable C++ class libraries, placing
    emphasis on libraries which work well with the C++ Standard
    Library. The libraries are intended to be widely useful, and are in
    regular use by thousands of programmers across a broad spectrum of
    applications. Aiming to provide missing functionality in current
    standards, Boost was begun by members of the C++ Standards Committee
    Library Working Group. Today, logic from a subset of the boost
    collection is under review by the ISO C++ Standards Committee and
    considered for inclusion in its future standards documents.

%track
    prog boost = {
        version   = %{V_dist}
        url       = https://www.boost.org/users/download/
        regex     = boost_(\d+_\d+_\d+)\.tar\.gz
    }

%prep
    %setup -q -n boost_%{V_dist}
    %patch -p0

%build
    #   set compiler
    export CC="%{l_cc}"
    export CFLAGS="%{l_cflags -O} -Wno-deprecated-declarations"
    export CXX="%{l_cxx}"
    export CXXFLAGS="%{l_cxxflags -O} -Wno-deprecated-declarations"

    #   bootstrap b2(1), the boost build system
    ./bootstrap.sh \
        --prefix=%{l_prefix} \
        --exec-prefix=%{l_prefix} \
        --includedir=%{l_prefix}/include \
        --libdir=%{l_prefix}/lib \
        --without-libraries=python \
        --with-toolset=gcc

    %{l_shtool} mkdir -p obj

    #   configure build options for b2(1) -sBUILD parameter
    debugopts="release"
    optimizeopts="<optimization>off"
    threadopts="<threading>single"
%if "%{with_debug}" == "yes"
    debugopts="$debugopts debug"
%endif
%if "%{with_optimize}" == "yes"
    optimizeopts="<optimization>speed"
%endif
%if "%{with_inlining}" == "yes"
    optimizeopts="$optimizeopts <inlining>full"
%endif
%if "%{with_pch}" == "yes"
    optimizeopts="$optimizeopts <pch>on"
%else
    optimizeopts="$optimizeopts <pch>off"
%endif
%if "%{with_threads}" == "yes"
    threadopts="<threading>single/multi"
%endif

    #   build all libraries
    ./b2 --toolset=gcc --layout=system --builddir=obj "-sBUILD=$debugopts $optimizeopts $threadopts" \
%if "%{with_zlib}" == "yes"
        "-sNO_COMPRESSION=0" "-sZLIB_INCLUDE=%{l_prefix}/include" "-sZLIB_LIBPATH=%{l_prefix}/lib" \
%else
        "-sNOZLIB=1" \
%endif
%if "%{with_bzip2}" == "yes"
        "-sNO_COMPRESSION=0" "-sBZIP2_INCLUDE=%{l_prefix}/include" "-sBZIP2_LIBPATH=%{l_prefix}/lib" \
%else
        "-sNOBZIP2=1" \
%endif
        link=static stage

%install
    ./b2 --toolset=gcc --layout=system --prefix=$RPM_BUILD_ROOT%{l_prefix} \
%if "%{with_zlib}" == "yes"
        "-sNO_COMPRESSION=0" "-sZLIB_INCLUDE=%{l_prefix}/include" "-sZLIB_LIBPATH=%{l_prefix}/lib" \
%else
        "-sNOZLIB=1" \
%endif
%if "%{with_bzip2}" == "yes"
        "-sNO_COMPRESSION=0" "-sBZIP2_INCLUDE=%{l_prefix}/include" "-sBZIP2_LIBPATH=%{l_prefix}/lib" \
%else
        "-sNOBZIP2=1" \
%endif
        link=static install
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/include/boost-*
    rm -rf "$RPM_BUILD_ROOT%{l_prefix}/include/boost/serialization/collection_size_type copy.hpp"
    find $RPM_BUILD_ROOT%{l_prefix}/lib/ \
        -name "*.so" -print -o \
        -name "libboost_*.so.%{V_openpkg}" \
        -print | xargs rm -f
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin
    %{l_shtool} install -c -m 755 \
        b2 $RPM_BUILD_ROOT%{l_prefix}/bin/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

