# file      : libbutl-archive/buildfile
# license   : MIT; see accompanying LICENSE file

import intf_libs = lib{butl}

windows = ($c.target.class == 'windows')

gcc  = ($c.class == 'gcc')
msvc = ($c.class == 'msvc')

lib{butl-archive}: {hxx cxx}{*}
lib{butl-archive}: {h c}{* -archive_windows}
lib{butl-archive}: {h c}{archive_windows}: include = $windows
lib{butl-archive}: $intf_libs

# Build options.
#
cc.poptions =+ "-I$src_root"

obja{*}: cxx.poptions += -DLIBBUTL_ARCHIVE_STATIC_BUILD
objs{*}: cxx.poptions += -DLIBBUTL_ARCHIVE_SHARED_BUILD

# We treat libarchive and libz sources as implementation details with hidden
# symbols to prevent clashes (e.g., if a build system module links "real"
# libarchive or libz).
#
# Note that __LIBARCHIVE_BUILD is defined by archive_platform.h.
#
cc.poptions += -DLIBARCHIVE_STATIC

c.poptions =+ "-I$src_base" # Needed for <zconf.h> inclusion.
c.poptions += -DHAVE_CONFIG_H

if $windows
  c.poptions += -D_WIN32_WINNT=0x0602

# Note that we don't need -fvisibility-inlines-hidden since all inline
# functions (only in libarchive) are static.
#
if $gcc
  c.coptions += -fvisibility=hidden

# Disable warnings.
#
if $gcc
  c.coptions += -Wno-implicit-fallthrough
elif $msvc
  c.coptions += /wd4244 /wd4267

# Export options.
#
lib{butl-archive}:
{
  cxx.export.poptions = "-I$src_root"
  cxx.export.libs = $intf_libs
}

liba{butl-archive}: cxx.export.poptions += -DLIBBUTL_ARCHIVE_STATIC
libs{butl-archive}: cxx.export.poptions += -DLIBBUTL_ARCHIVE_SHARED

# For pre-releases use the complete version to make sure they cannot be used
# in place of another pre-release or the final version. See the version module
# for details on the version.* variable values.
#
if $version.pre_release
  lib{butl-archive}: bin.lib.version = @"-$version.project_id"
else
  lib{butl-archive}: bin.lib.version = @"-$version.major.$version.minor"

# Install into the libbutl/archive/libbutl-archive/ subdirectory of, say,
# /usr/include (so we end up with libbutl/archive/libbutl-archive/...).
# Arrange via pkg-config to be able to include headers as
# <libbutl-archive/...>.
#
# The reason we add an extra archive/ subdirectory instead of installing
# directly into libbutl/ is because adding -I for libbutl/ will make all the
# libbutl headers includable without a prefix and thus prone to clashes.
#
h{*}: install = false
hxx{*}: install = include/libbutl/archive/libbutl-archive/

lib{butl-archive}: c.pkgconfig.include = include/libbutl/archive/

# Static config.h generation (see README-DEV for details).
#
#\
using autoconf

h{config}: in{config}
{
  autoconf.aliases =

  autoconf.aliases += HAVE_DECL_INT32_MAX@HAVE_INT32_MAX
  autoconf.aliases += HAVE_DECL_INT32_MIN@HAVE_INT32_MIN
  autoconf.aliases += HAVE_DECL_INT64_MAX@HAVE_INT64_MAX
  autoconf.aliases += HAVE_DECL_INT64_MIN@HAVE_INT64_MIN

  autoconf.aliases += HAVE_DECL_UINT32_MAX@HAVE_UINT32_MAX
  autoconf.aliases += HAVE_DECL_UINT64_MAX@HAVE_UINT64_MAX

  autoconf.aliases += HAVE_DECL_INTMAX_MAX@HAVE_INTMAX_MAX
  autoconf.aliases += HAVE_DECL_INTMAX_MIN@HAVE_INTMAX_MIN
  autoconf.aliases += HAVE_DECL_UINTMAX_MAX@HAVE_UINTMAX_MAX

  autoconf.aliases += HAVE_DECL_SIZE_MAX@HAVE_SIZE_MAX
  autoconf.aliases += HAVE_DECL_SSIZE_MAX@HAVE_SSIZE_MAX

  autoconf.aliases += MAJOR_IN_SYSMACROS@HAVE_SYS_SYSMACROS_H

  # For now we only have gzip compression.
  #
  HAVE_ZLIB_H = true
  HAVE_LZMA_H = false
  HAVE_BZLIB_H = false
  HAVE_LZ4_H = false

  # None of these should be needed for our use-case.
  #
  HAVE_ICONV = false
  HAVE_ICONV_H = false
  HAVE_LOCALCHARSET_H = false
  HAVE_LOCALE_CHARSET = false

  HAVE_ACL_SET_FD = false
  HAVE_ACL_SET_FD_NP = false

  HAVE_EXT2FS_EXT2_FS_H = false
  HAVE_LINUX_EXT2_FS_H = false
  HAVE_LINUX_FS_H = false
}
#\
