# file      : xsde/buildfile
# license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

lib{xsde}: libul{xsde}

# Attempt to export symbols automatically for MSVC.
#
libs{xsde}: def{xsde}: include = ($cxx.target.system == 'win32-msvc')
def{xsde}: libul{xsde}

# All the dependencies are optional and are interface dependencies.
#
expat_lib =
if $external_expat
  import expat_lib = libexpat%lib{expat}

ace_lib =
if $cdr
  import ace_lib = libace%lib{ACE}

xdr_lib =
if ($xdr && $cxx.target.class == 'linux')
  import xdr_lib = libtirpc%lib{tirpc}

# Parser/serializer builtin type implementations which don't use STL.
#
ts_nstl = any-simple-type   \
          string            \
          normalized-string \
          token             \
          name              \
          nmtoken           \
          nmtokens          \
          ncname            \
          id                \
          idref             \
          idrefs            \
          language          \
          uri               \
          qname

# Parser/serializer builtin type implementations which use STL.
#
ts_ystl = $regex.apply($ts_nstl, '(.+)', '\1-stl')

libul{xsde}: cxx/{    hxx ixx txx cxx}{*       -version             \
                                               -allocator           \
                                               -sys-error           \
                                               -iso8859-1           \
                                               -strdupx             \
                                               -string-sequence-stl \
                                               -qname               \
                                               -string-sequence     \
                                               -schema-error        \
                                               -hashmap           } \
             cxx/{    hxx            }{version                    } \
   cxx/compilers/{    hxx            }{**                         } \
               c/{h c                }{**      -expat/*             \
                                               -regexp/*          } \
                 {h                  }{config                     } \
               c/{doc                }{expat/COPYING genx/LICENSE }

pv = $parser_validation
sv = $serializer_validation
ca = $custom_allocator
en = $encoding
ex = $exceptions
ll = $long_long
pm = $polymorphic
ee = $external_expat

# Note that c/expat/xmltok_*.c are actually headers.
#
libul{xsde}:          {h c}{allocator    }: include = ($ca && $default_allocator)
libul{xsde}:  c/expat/{h c}{* -xmltok_*.c}: include = (!$ee)
libul{xsde}:  c/expat/{  c}{   xmltok_*  }: include = (!$ee ? adhoc : false)
libul{xsde}: c/regexp/{h c}{*            }: include = ($regexp && ($pv || $sv))

libul{xsde}: cxx/{hxx ixx cxx}{allocator}:             include = ($ca && $ex)
libul{xsde}: cxx/{hxx ixx cxx}{sys-error}:             include = (!$ex)
libul{xsde}: cxx/{hxx ixx cxx}{iso8859-1}:             include = ($en == 'iso8859-1')
libul{xsde}: cxx/{hxx ixx cxx}{schema-error xml/**}:   include = ($pv || $sv)
libul{xsde}: cxx/{hxx ixx cxx}{hashmap}:               include = $pm
libul{xsde}: cxx/{hxx ixx cxx}{string-sequence-stl}:   include = $stl
libul{xsde}: cxx/{hxx ixx cxx}{qname string-sequence}: include = (!$stl)
libul{xsde}: cxx/{hxx     cxx}{strdupx}:               include = (!$stl)

libul{xsde}: cxx/hybrid/libul{xsde-h}     \
             cxx/parser/libul{xsde-p}     \
             cxx/serializer/libul{xsde-s}

cxx/hybrid/
{
  libul{xsde-h}:     {hxx ixx txx cxx}{* -*-map}
  libul{xsde-h}:     {hxx ixx     cxx}{   *-map}: include = $pm
  libul{xsde-h}: cdr/{hxx ixx txx cxx}{*       }: include = $cdr
  libul{xsde-h}: xdr/{hxx ixx txx cxx}{*       }: include = $xdr

  # Make sure that these headers are generated before the source code
  # compilation.
  #
  libul{xsde-h}: ../hxx{version} ../../h{config}

  libul{xsde-h}: $expat_lib $ace_lib $xdr_lib
}

cxx/parser/
{
  libul{xsde-p}: {hxx ixx cxx}{** -exceptions        \
                                  -error             \
                                  -*map              \
                                  -validating/*      \
                                  -non-validating/*}

  libul{xsde-p}: {hxx ixx cxx}{exceptions}: include =   $ex
  libul{xsde-p}: {hxx ixx cxx}{error}:      include = (!$ex)
  libul{xsde-p}: {hxx ixx cxx}{*map}:       include =   $pm

  libul{xsde-p}: ../hxx{version} ../../h{config}

  libul{xsde-p}: validating/libul{xsde-pyv}:     include =   $pv
  libul{xsde-p}: non-validating/libul{xsde-pnv}: include = (!$pv)

  validating/
  {
    libul{xsde-pyv}: {hxx ixx cxx}{* -*-map -*long* -{$ts_nstl $ts_ystl}}

    libul{xsde-pyv}: {hxx ixx cxx}{*-map}: include = $pm

    libul{xsde-pyv}: {hxx cxx}{long-long unsigned-long-long}: include =   $ll
    libul{xsde-pyv}: {hxx cxx}{long unsigned-long}:           include = (!$ll)

    libul{xsde-pyv}: {hxx ixx cxx}{+{$ts_ystl}}: include =   $stl
    libul{xsde-pyv}: {hxx ixx cxx}{+{$ts_nstl}}: include = (!$stl)

    libul{xsde-pyv}: ../../hxx{version} ../../../h{config}

    libul{xsde-pyv}: $expat_lib
  }

  non-validating/
  {
    libul{xsde-pnv}: {hxx ixx cxx}{** -*long* -{$ts_nstl $ts_ystl}}

    libul{xsde-pnv}: {hxx cxx}{long-long unsigned-long-long}: include =   $ll
    libul{xsde-pnv}: {hxx cxx}{long unsigned-long}:           include = (!$ll)

    libul{xsde-pnv}: {hxx ixx cxx}{+{$ts_ystl}}: include =   $stl
    libul{xsde-pnv}: {hxx ixx cxx}{+{$ts_nstl}}: include = (!$stl)

    libul{xsde-pnv}: ../../hxx{version} ../../../h{config}

    libul{xsde-pnv}: $expat_lib
  }
}

cxx/serializer/
{
  libul{xsde-s}: {hxx ixx cxx}{** -exceptions        \
                                  -error             \
                                  -*map              \
                                  -validating/*      \
                                  -non-validating/*}

  libul{xsde-s}: {hxx ixx cxx}{exceptions}: include =   $ex
  libul{xsde-s}: {hxx ixx cxx}{error}:      include = (!$ex)
  libul{xsde-s}: {hxx ixx cxx}{*map}:       include = $pm

  libul{xsde-s}: ../hxx{version} ../../h{config}

  libul{xsde-s}: validating/libul{xsde-syv}:     include =   $sv
  libul{xsde-s}: non-validating/libul{xsde-snv}: include = (!$sv)

  validating/
  {
    libul{xsde-syv}: {hxx ixx cxx}{* -*-map -*long* -{$ts_nstl $ts_ystl}}

    libul{xsde-syv}: {hxx ixx cxx}{*-map}: include = $pm

    libul{xsde-syv}: {hxx cxx}{long-long unsigned-long-long}: include =   $ll
    libul{xsde-syv}: {hxx cxx}{long unsigned-long}:           include = (!$ll)

    libul{xsde-syv}: {hxx ixx cxx}{+{$ts_ystl}}: include =   $stl
    libul{xsde-syv}: {hxx ixx cxx}{+{$ts_nstl}}: include = (!$stl)

    libul{xsde-syv}: ../../hxx{version} ../../../h{config}
  }

  non-validating/
  {
    libul{xsde-snv}: {hxx ixx cxx}{** -*long* -{$ts_nstl $ts_ystl}}

    libul{xsde-snv}: {hxx cxx}{long-long unsigned-long-long}: include =   $ll
    libul{xsde-snv}: {hxx cxx}{long unsigned-long}:           include = (!$ll)

    libul{xsde-snv}: {hxx ixx cxx}{+{$ts_ystl}}: include =   $stl
    libul{xsde-snv}: {hxx ixx cxx}{+{$ts_nstl}}: include = (!$stl)

    libul{xsde-snv}: ../../hxx{version} ../../../h{config}
  }
}

# Include the generated version header into the distribution (so that we don't
# pick up an installed one) and don't remove it when cleaning in src (so that
# clean results in a state identical to distributed).
#
cxx/
{
  [rule_hint=version.in] hxx{version}: in{version} $src_root/manifest

  hxx{version}:
  {
    dist  = true
    clean = ($src_root != $out_root)
  }
}

# Generated config file.
#
using autoconf

h{config}: in{config}
{
  autoconf.prefix = XSDE_

  XSDE_ENCODING_UTF8                  = ($encoding == 'utf8')
  XSDE_ENCODING_ISO8859_1             = ($encoding == 'iso8859-1')
  XSDE_STL                            = $stl
  XSDE_STL_ITERATOR                   = $stl_iterator
  XSDE_IOSTREAM                       = $iostream
  XSDE_EXCEPTIONS                     = $exceptions
  XSDE_LONGLONG                       = $long_long
  XSDE_PARSER_VALIDATION              = $parser_validation
  XSDE_SERIALIZER_VALIDATION          = $serializer_validation
  XSDE_REGEXP                         = $regexp
  XSDE_REUSE_STYLE_MIXIN              = ($reuse_style == 'mixin')
  XSDE_REUSE_STYLE_TIEIN              = ($reuse_style == 'tiein')
  XSDE_REUSE_STYLE_NONE               = ($reuse_style == 'none')
  XSDE_CUSTOM_ALLOCATOR               = $custom_allocator
  XSDE_DEFAULT_ALLOCATOR              = $default_allocator
  XSDE_POLYMORPHIC                    = $polymorphic
  XSDE_PARSER_SMAP_BUCKETS            = $parser_smap_buckets
  XSDE_PARSER_IMAP_BUCKETS            = $parser_imap_buckets
  XSDE_SERIALIZER_SMAP_BUCKETS        = $serializer_smap_buckets
  XSDE_SERIALIZER_SMAP_BUCKET_BUCKETS = $serializer_smap_bucket_buckets
  XSDE_SERIALIZER_IMAP_BUCKETS        = $serializer_imap_buckets
  XSDE_EXTERNAL_EXPAT                 = $external_expat
}

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

if ($c.class == 'gcc')
{
  # Disable warnings that pop up with -Wall -Wextra (see libexpat package for
  # details).
  #
  c/expat/  c.coptions += -Wno-implicit-fallthrough
  c/regexp/ c.coptions += -Wno-implicit-fallthrough
}

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

# Export options.
#
lib{xsde}:
{
  cxx.export.poptions = "-I$out_root" "-I$src_root"
  cxx.export.libs = $expat_lib $ace_lib $xdr_lib
}

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

# Install into the xsde/ subdirectory of, say, /usr/include/ recreating
# subdirectories.
#
{h hxx ixx txx}{*}:
{
  install         = include/xsde/
  install.subdirs = true
}

# Most of the Expat headers are private.
#
c/expat/
{
  h{*}: install = false

  h{expat}@./ h{expat_external}@./:
  {
    install = (!$external_expat ? include/xsde/c/expat/ : false)
    install.subdirs = false
  }

  doc{COPYING}@./: install = (!$external_expat ? doc/EXPAT-LICENSE : false)
}

c/genx/
{
  doc{LICENSE}@./: install = doc/GENX-LICENSE
}
