# file      : icu-bootstrap/buildfile
# license   : Unicode License; see accompanying LICENSE file

# The bootstrap library consists of the icucu, icui18n, icuio, and icutu
# (toolutil) libraries and an empty icudata library. It is used to break the
# following circular dependency chain:
#
#   icuuc -> icudata -> data tools -> icuuc
#
# With the bootstrap library this becomes:
#
#   icuuc -> icudata -> data tools -> icu-bootstrap
#
# Note that data tools still need data normally found in icudata. So for tools
# we instead use the data archive. See the root README-DEV for more details.
#
# Note that io/ is required only by the derb tool.
#
libue{icu-bootstrap}: uc/hxx{**}   uc/cxx{* -putil}     \
                      i18n/hxx{**} i18n/cxx{*}          \
                      io/hxx{**}   io/cxx{*}            \
                      toolutil/{hxx cxx}{*}             \
                      {hxx cxx}{stubdata}

# Bootstrap libraries for the installed and develop cases. The two putil.cpp
# objects define different values for the ICU data directory (where the data
# archive is located; see below).
#
[rule_hint=cxx] libue{icu-bootstrap-install}: uc/obje{putil-install}
[rule_hint=cxx] libue{icu-bootstrap-develop}: uc/obje{putil-develop}

uc/obje{putil-install putil-develop}: uc/cxx{putil}

cxx.poptions += -DU_STATIC_IMPLEMENTATION

c.coptions   += $common_cc_coptions
cxx.coptions += $common_cc_coptions $common_cxx_coptions

if ($cxx.class == 'msvc')
{
  # Disable warnings that pop up with /W3.
  #
  # 4805: '==': unsafe mix of type 'UBool' and type 'bool' in operation
  #
  cxx.coptions += /wd4244 /wd4805
}

uc/
{
  cxx.poptions =+ "-I$src_base"

  cxx.poptions += -DU_COMMON_IMPLEMENTATION

  if $macos
  {
    # Note that upstream requests the POSIX 2004 compliance (see
    # uc/uposixdefs.h for details). This results in compilation errors for
    # some source files when build on MacOS with gcc (as of 9.2; GCC issues
    # 93151 and 93469 are reported). We workaround the issue by disabling this
    # POSIX compliance request for the faulty source files (luckily the
    # request is redundant for them).
    #
    if ($cxx.id == 'gcc')
    {
      obje{putil-develop putil-install umapfile}: \
        cxx.poptions += -D_XOPEN_SOURCE=400
    }
  }

  # Define the ICU data directory path as appropriate for the installed and
  # develop cases so that the tools can find the ICU data archive. (Note that
  # this path will still be overridable at runtime with the ICU_DATA
  # environment variable and the --icudatadir option.)
  #
  # Escape backslashes on Windows.
  #
  dd_install = [dir_path] $regex.replace($data_dir_install, '\\', '\\\\')
  dd_develop = [dir_path] $regex.replace($data_dir_develop, '\\', '\\\\')

  obje{putil-install}: cxx.poptions += -DU_ICU_DATA_DEFAULT_DIR=\""$dd_install"\"
  obje{putil-develop}: cxx.poptions += -DU_ICU_DATA_DEFAULT_DIR=\""$dd_develop"\"
}

i18n/
{
  cxx.poptions =+ "-I$src_root/icu-bootstrap/uc" \
                  "-I$src_base"

  cxx.poptions += -DU_I18N_IMPLEMENTATION
}

io/
{
  cxx.poptions =+ "-I$src_root/icu-bootstrap/uc"        \
                  "-I$src_root/icu-bootstrap/i18n"      \
                  "-I$src_base"

  cxx.poptions += -DU_IO_IMPLEMENTATION
}

toolutil/
{
  cxx.poptions =+ "-I$src_root/icu-bootstrap/uc"        \
                  "-I$src_root/icu-bootstrap/i18n"

  cxx.poptions += -DU_TOOLUTIL_IMPLEMENTATION           \
                  -DUNISTR_FROM_CHAR_EXPLICIT=explicit  \
                  -DUNISTR_FROM_STRING_EXPLICIT=explicit
}

obj{stubdata}: cxx.poptions =+ "-I$src_base/uc"
