# Description: Free peer-reviewed portable C++ source libraries.
# URL: https://www.boost.org/
# Maintainer: John McQuah, jmcquah at disroot dot org
# Depends on: bzip2 zstd
# Optional: icu openmpi python3-numpy

name=boost
version=1.91.0
release=1
source=(https://archives.boost.io/release/$version/source/${name}_${version//./_}.tar.bz2)

build() {
  cd ${name}_${version//./_}

  # Boost.Build does not allow for disabling of numpy
  # extensions, thereby leading to automagic numpy
  # https://github.com/boostorg/python/issues/111#issuecomment-280447482
  [ -e /usr/bin/numpy-config ] || sed \
    -e 's/\[ unless \[ python\.numpy \] : <build>no \]/<build>no/g' \
    -i libs/python/build/Jamfile

  pushd tools/build
  ./bootstrap.sh --cxxflags="$CXXFLAGS $LDFLAGS"
  ./b2 install --prefix="$PKG"/usr
  ln -s b2 "$PKG"/usr/bin/bjam
  popd

  ./bootstrap.sh --with-toolset=gcc --with-python=/usr/bin/python3

  # support for OpenMPI and ICU
  [ -e /usr/lib/openmpi/libmpi.so ] && echo "using mpi ;" >>project-config.jam || PKGMK_BOOST+=' --without-mpi --without-graph_parallel'
  [ -e /usr/bin/icu-config ] || PKGMK_BOOST+=' --disable-icu boost.locale.icu=off'

  ./b2 install ${PKGMK_BOOST} \
    --prefix="$PKG"/usr \
    --layout=system \
    -j ${JOBS-1} \
    variant=release \
    debug-symbols=off \
    threading=multi \
    runtime-link=shared \
    link=shared,static \
    toolset=gcc \
    python=$(/usr/bin/python3 -c 'import sys; print("%s.%s" % sys.version_info[:2])') \
    cflags="$CPPFLAGS $CFLAGS -fPIC -O3 -ffat-lto-objects" \
    cxxflags="$CPPFLAGS $CXXFLAGS -fPIC -O3 -ffat-lto-objects" \
    linkflags="$LDFLAGS"

  [ -e /usr/bin/numpy-config ] || rm -r "$PKG"/usr/include/boost/python/numpy*
  [ -e /usr/lib/openmpi/libmpi.so ] || rm -r "$PKG"/usr/include/boost/mpi/python*
}
