# Note that upstream keeps all the library sources in its root directory,
# which we symlink file by file (see README-DEV for source files that we had
# to patch).
#
lib{tommath}: libul{tommath}: {h c}{*}

libs{tommath}: def{tommath}: include = ($c.target.system == 'win32-msvc')
def{tommath}: libul{tommath}

# Build options.
#
src_pfx = [dir_path] $src_root/libtommath/

c.poptions =+ "-I$src_pfx"

if ($c.target.system == 'win32-msvc')
  c.poptions += -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE

# MP_HAS() stringizes macros that are defined empty for enabled features,
# which MSVC preprocessor warns about (C4003). Resulting empty string is
# exactly what MP_HAS() tests for. We have to disable this warning since
# build2 treats preprocessor warnings as errors with MSVC.
#
if ($c.class == 'msvc')
  c.coptions += /wd4003

# Signed integer accessors (MP_GET_SIGNED(), MP_SET_SIGNED()) negate
# unsigned values to get magnitude of negative numbers, which MSVC warns
# about (C4146). Upstream disables this warning as well (see makefile.msvc).
#
if ($c.class == 'msvc')
  c.coptions += /wd4146

if ($c.target.system == 'mingw32')
  c.loptions += -Wl,--export-all-symbols

# Windows random number source (CryptGenRandom()) is provided by
# advapi32.lib, which upstream links explicitly (see makefile.msvc). MinGW
# links it by default.
#
if ($c.target.system == 'win32-msvc')
  c.libs += advapi32.lib

# Export options.
#
lib{tommath}: c.export.poptions = "-I$src_pfx"

# 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{tommath}: bin.lib.version = "-$version.project_id"
else
  lib{tommath}: bin.lib.version = "-$version.major.$version.minor"

# Only install the public header and directly into, say, /usr/include/, as
# upstream does. The rest are private headers.
#
h{tommath}@./: install = include/
h{*}: install = false
