# Boost.Iostreams Library Build Jamfile

# (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
# (C) Copyright 2004-2007 Jonathan Turkanis
# Distributed under the Boost Software License, Version 1.0. (See accompanying 
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)

# See http://www.boost.org/libs/iostreams for documentation.

project /boost/iostreams : source-location ../src ;

# The biggest trick in this Jamfile is to link to zlib and bzip2 when
# needed. To configure that, a number of variables are used, which must
# be set by user with 'path-constant' either in Boost's root Jamfile, or
# in user-config.jam.

# For each library with either link to existing binary, or build
# a library from the sources.

import modules ;
import os ;
import path ;
import ac ;
local debug = [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ] ;

local libraries-to-install = boost_iostreams ;

for local v in NO_COMPRESSION 
               NO_ZLIB
               NO_BZIP2
               NO_LZMA
               NO_ZSTD
{
    $(v) = [ modules.peek : $(v) ] ;
}

if $(NO_COMPRESSION) != 1 && $(NO_ZLIB) != 1
{
    using zlib : : <build-name>boost_zlib <tag>@tag ;
    zlib-requirements =
        [ ac.check-library /zlib//zlib : <library>/zlib//zlib
          <source>zlib.cpp <source>gzip.cpp ] ;

    if [ os.environ ZLIB_SOURCE ]
    {
        alias boost_zlib : /zlib//zlib ;
        libraries-to-install += boost_zlib ;
    }
}
else
{
    if $(debug)
    {
        ECHO "notice: iostreams: not using zlib compression " ;
    }
}

if $(NO_COMPRESSION) != 1 && $(NO_BZIP2) != 1
{
    using bzip2 : : <build-name>boost_bzip2 <tag>@tag ;
    bzip2-requirements =
        [ ac.check-library /bzip2//bzip2 : <library>/bzip2//bzip2
          <source>bzip2.cpp ] ;

    if [ os.environ BZIP2_SOURCE ]
    {
        alias boost_bzip2 : /bzip2//bzip2 ;
        libraries-to-install += boost_bzip2 ;
    }
}
else
{
    if $(debug)
    {
        ECHO "notice: iostreams: not using bzip compression " ;
    }
}

if $(NO_COMPRESSION) != 1 && $(NO_LZMA) != 1
{
    using lzma ;

    exe has_lzma_cputhreads : ../build/has_lzma_cputhreads.cpp /lzma//lzma ;
    explicit has_lzma_cputhreads ;

    lzma-requirements =
        [ ac.check-library /lzma//lzma : <library>/lzma//lzma
          <source>lzma.cpp ]
        [ check-target-builds has_lzma_cputhreads
            : : <define>BOOST_IOSTREAMS_LZMA_NO_MULTITHREADED=1 ] ;
}
else
{
    if $(debug)
    {
        ECHO "notice: iostreams: not using lzma compression " ;
    }
}

if $(NO_COMPRESSION) != 1 && $(NO_ZSTD) != 1
{
    using zstd ;
    zstd-requirements =
        [ ac.check-library /zstd//zstd : <library>/zstd//zstd
          <source>zstd.cpp ] ;
}
else
{
    if $(debug)
    {
        ECHO "notice: iostreams: not using zstd compression " ;
    }
}

local sources = file_descriptor.cpp mapped_file.cpp ;

lib boost_iostreams 
    : $(sources) 
    : <link>shared:<define>BOOST_IOSTREAMS_DYN_LINK=1 
      <define>BOOST_IOSTREAMS_USE_DEPRECATED
      $(zlib-requirements)
      $(bzip2-requirements)
      $(lzma-requirements)
      $(zstd-requirements)
    :
    : <link>shared:<define>BOOST_IOSTREAMS_DYN_LINK=1
    ;

boost-install $(libraries-to-install) ;
