# -*- mode: python -*-

Import('env')

env = env.Clone()

# The below list of defines are used to configure ICU. They must be duplicated exactly in every
# library that injects the third-party ICU headers. If this list is changed here, it must be changed
# in other such libraries as well.
env.Append(
    CPPDEFINES=[
        ('UCONFIG_NO_BREAK_ITERATION', 1),
        ('UCONFIG_NO_FORMATTING', 1),
        ('UCONFIG_NO_TRANSLITERATION', 1),
        ('UCONFIG_NO_REGULAR_EXPRESSIONS', 1),
        ('U_CHARSET_IS_UTF8', 1),
        ('U_DISABLE_RENAMING', 1),
        ('U_STATIC_IMPLEMENTATION', 1),
        ('U_USING_ICU_NAMESPACE', 0),
    ],
)

if env.TargetOSIs('solaris'):
    # On Solaris, compile of certain files fails if the below define is not enabled.  Specifically,
    # files that include "source/common/uposixdefs.h" will have _XOPEN_SOURCE=600 and
    # _XOPEN_SOURCE_EXTENDED=1 defined by default; if the file also includes <sys/feature_tests.h>,
    # then the application is assumed to conform to the XPG4v2 specification, which generates an
    # error because XPG4v2 programs are incompatible with C99. If we keep _XOPEN_SOURCE=600 but
    # force _XOPEN_SOURCE_EXTENDED=0, then <sys/feature_tests.h> chooses XPG6, which resolves the
    # error (since XPG6 is compatible with C99).
    env.Append(
        CPPDEFINES=[
            ('_XOPEN_SOURCE_EXTENDED', 0),
        ],
    )

def removeIfPresent(lst, item):
    try:
        lst.remove(item)
    except ValueError:
        pass

for to_remove in ['-Werror', '-Wall', '-W']:
    removeIfPresent(env['CCFLAGS'], to_remove)

# Suppress sign-compare warnings.
if env.ToolchainIs('clang', 'GCC'):
    env.Append(CCFLAGS=['-Wno-sign-compare'])

if env.TargetOSIs('windows'):
    # C4996: '...': was declared deprecated
    env.Append(CCFLAGS=['/wd4996'])

i18nEnv = env.Clone()
i18nEnv.Append(
    CPPDEFINES=[
        ('U_I18N_IMPLEMENTATION', 1),
    ],
)
i18nEnv.Library(
    target='icu_i18n',
    source=[
        'i18n/affixpatternparser.cpp',
        'i18n/alphaindex.cpp',
        'i18n/anytrans.cpp',
        'i18n/astro.cpp',
        'i18n/basictz.cpp',
        'i18n/bocsu.cpp',
        'i18n/brktrans.cpp',
        'i18n/buddhcal.cpp',
        'i18n/calendar.cpp',
        'i18n/casetrn.cpp',
        'i18n/cecal.cpp',
        'i18n/chnsecal.cpp',
        'i18n/choicfmt.cpp',
        'i18n/coleitr.cpp',
        'i18n/coll.cpp',
        'i18n/collation.cpp',
        'i18n/collationbuilder.cpp',
        'i18n/collationcompare.cpp',
        'i18n/collationdata.cpp',
        'i18n/collationdatabuilder.cpp',
        'i18n/collationdatareader.cpp',
        'i18n/collationdatawriter.cpp',
        'i18n/collationfastlatin.cpp',
        'i18n/collationfastlatinbuilder.cpp',
        'i18n/collationfcd.cpp',
        'i18n/collationiterator.cpp',
        'i18n/collationkeys.cpp',
        'i18n/collationroot.cpp',
        'i18n/collationrootelements.cpp',
        'i18n/collationruleparser.cpp',
        'i18n/collationsets.cpp',
        'i18n/collationsettings.cpp',
        'i18n/collationtailoring.cpp',
        'i18n/collationweights.cpp',
        'i18n/compactdecimalformat.cpp',
        'i18n/coptccal.cpp',
        'i18n/cpdtrans.cpp',
        'i18n/csdetect.cpp',
        'i18n/csmatch.cpp',
        'i18n/csr2022.cpp',
        'i18n/csrecog.cpp',
        'i18n/csrmbcs.cpp',
        'i18n/csrsbcs.cpp',
        'i18n/csrucode.cpp',
        'i18n/csrutf8.cpp',
        'i18n/curramt.cpp',
        'i18n/currfmt.cpp',
        'i18n/currpinf.cpp',
        'i18n/currunit.cpp',
        'i18n/dangical.cpp',
        'i18n/datefmt.cpp',
        'i18n/dayperiodrules.cpp',
        'i18n/dcfmtsym.cpp',
        'i18n/decContext.c',
        'i18n/decNumber.c',
        'i18n/decfmtst.cpp',
        'i18n/decimalformatpattern.cpp',
        'i18n/decimfmt.cpp',
        'i18n/decimfmtimpl.cpp',
        'i18n/digitaffix.cpp',
        'i18n/digitaffixesandpadding.cpp',
        'i18n/digitformatter.cpp',
        'i18n/digitgrouping.cpp',
        'i18n/digitinterval.cpp',
        'i18n/digitlst.cpp',
        'i18n/dtfmtsym.cpp',
        'i18n/dtitvfmt.cpp',
        'i18n/dtitvinf.cpp',
        'i18n/dtptngen.cpp',
        'i18n/dtrule.cpp',
        'i18n/esctrn.cpp',
        'i18n/ethpccal.cpp',
        'i18n/fmtable.cpp',
        'i18n/fmtable_cnv.cpp',
        'i18n/format.cpp',
        'i18n/fphdlimp.cpp',
        'i18n/fpositer.cpp',
        'i18n/funcrepl.cpp',
        'i18n/gender.cpp',
        'i18n/gregocal.cpp',
        'i18n/gregoimp.cpp',
        'i18n/hebrwcal.cpp',
        'i18n/identifier_info.cpp',
        'i18n/indiancal.cpp',
        'i18n/inputext.cpp',
        'i18n/islamcal.cpp',
        'i18n/japancal.cpp',
        'i18n/measfmt.cpp',
        'i18n/measunit.cpp',
        'i18n/measure.cpp',
        'i18n/msgfmt.cpp',
        'i18n/name2uni.cpp',
        'i18n/nfrs.cpp',
        'i18n/nfrule.cpp',
        'i18n/nfsubs.cpp',
        'i18n/nortrans.cpp',
        'i18n/nultrans.cpp',
        'i18n/numfmt.cpp',
        'i18n/numsys.cpp',
        'i18n/olsontz.cpp',
        'i18n/persncal.cpp',
        'i18n/pluralaffix.cpp',
        'i18n/plurfmt.cpp',
        'i18n/plurrule.cpp',
        'i18n/precision.cpp',
        'i18n/quant.cpp',
        'i18n/quantityformatter.cpp',
        'i18n/rbnf.cpp',
        'i18n/rbt.cpp',
        'i18n/rbt_data.cpp',
        'i18n/rbt_pars.cpp',
        'i18n/rbt_rule.cpp',
        'i18n/rbt_set.cpp',
        'i18n/rbtz.cpp',
        'i18n/regexcmp.cpp',
        'i18n/regeximp.cpp',
        'i18n/regexst.cpp',
        'i18n/regextxt.cpp',
        'i18n/region.cpp',
        'i18n/reldatefmt.cpp',
        'i18n/reldtfmt.cpp',
        'i18n/rematch.cpp',
        'i18n/remtrans.cpp',
        'i18n/repattrn.cpp',
        'i18n/rulebasedcollator.cpp',
        'i18n/scientificnumberformatter.cpp',
        'i18n/scriptset.cpp',
        'i18n/search.cpp',
        'i18n/selfmt.cpp',
        'i18n/sharedbreakiterator.cpp',
        'i18n/simpletz.cpp',
        'i18n/smallintformatter.cpp',
        'i18n/smpdtfmt.cpp',
        'i18n/smpdtfst.cpp',
        'i18n/sortkey.cpp',
        'i18n/standardplural.cpp',
        'i18n/strmatch.cpp',
        'i18n/strrepl.cpp',
        'i18n/stsearch.cpp',
        'i18n/taiwncal.cpp',
        'i18n/timezone.cpp',
        'i18n/titletrn.cpp',
        'i18n/tmunit.cpp',
        'i18n/tmutamt.cpp',
        'i18n/tmutfmt.cpp',
        'i18n/tolowtrn.cpp',
        'i18n/toupptrn.cpp',
        'i18n/translit.cpp',
        'i18n/transreg.cpp',
        'i18n/tridpars.cpp',
        'i18n/tzfmt.cpp',
        'i18n/tzgnames.cpp',
        'i18n/tznames.cpp',
        'i18n/tznames_impl.cpp',
        'i18n/tzrule.cpp',
        'i18n/tztrans.cpp',
        'i18n/ucal.cpp',
        'i18n/ucln_in.cpp',
        'i18n/ucol.cpp',
        'i18n/ucol_res.cpp',
        'i18n/ucol_sit.cpp',
        'i18n/ucoleitr.cpp',
        'i18n/ucsdet.cpp',
        'i18n/udat.cpp',
        'i18n/udateintervalformat.cpp',
        'i18n/udatpg.cpp',
        'i18n/ufieldpositer.cpp',
        'i18n/uitercollationiterator.cpp',
        'i18n/ulocdata.c',
        'i18n/umsg.cpp',
        'i18n/unesctrn.cpp',
        'i18n/uni2name.cpp',
        'i18n/unum.cpp',
        'i18n/unumsys.cpp',
        'i18n/upluralrules.cpp',
        'i18n/uregex.cpp',
        'i18n/uregexc.cpp',
        'i18n/uregion.cpp',
        'i18n/usearch.cpp',
        'i18n/uspoof.cpp',
        'i18n/uspoof_build.cpp',
        'i18n/uspoof_conf.cpp',
        'i18n/uspoof_impl.cpp',
        'i18n/uspoof_wsconf.cpp',
        'i18n/utf16collationiterator.cpp',
        'i18n/utf8collationiterator.cpp',
        'i18n/utmscale.c',
        'i18n/utrans.cpp',
        'i18n/valueformatter.cpp',
        'i18n/visibledigits.cpp',
        'i18n/vtzone.cpp',
        'i18n/vzone.cpp',
        'i18n/windtfmt.cpp',
        'i18n/winnmfmt.cpp',
        'i18n/wintzimpl.cpp',
        'i18n/zonemeta.cpp',
        'i18n/zrule.cpp',
        'i18n/ztrans.cpp',
    ],
    LIBDEPS=[
        'icu_common',
    ],
)

commonEnv = env.Clone()
commonEnv.Append(
    CPPDEFINES=[
        ('U_COMMON_IMPLEMENTATION', 1),
    ],
)
commonEnv.Library(
    target='icu_common',
    source=[
        'common/appendable.cpp',
        'common/bmpset.cpp',
        'common/brkeng.cpp',
        'common/brkiter.cpp',
        'common/bytestream.cpp',
        'common/bytestrie.cpp',
        'common/bytestriebuilder.cpp',
        'common/bytestrieiterator.cpp',
        'common/caniter.cpp',
        'common/chariter.cpp',
        'common/charstr.cpp',
        'common/cmemory.c',
        'common/cstr.cpp',
        'common/cstring.c',
        'common/cwchar.c',
        'common/dictbe.cpp',
        'common/dictionarydata.cpp',
        'common/dtintrv.cpp',
        'common/errorcode.cpp',
        'common/filteredbrk.cpp',
        'common/filterednormalizer2.cpp',
        'common/icudataver.c',
        'common/icuplug.cpp',
        'common/listformatter.cpp',
        'common/loadednormalizer2impl.cpp',
        'common/locavailable.cpp',
        'common/locbased.cpp',
        'common/locdispnames.cpp',
        'common/locdspnm.cpp',
        'common/locid.cpp',
        'common/loclikely.cpp',
        'common/locmap.c',
        'common/locresdata.cpp',
        'common/locutil.cpp',
        'common/messagepattern.cpp',
        'common/normalizer2.cpp',
        'common/normalizer2impl.cpp',
        'common/normlzr.cpp',
        'common/parsepos.cpp',
        'common/patternprops.cpp',
        'common/pluralmap.cpp',
        'common/propname.cpp',
        'common/propsvec.c',
        'common/punycode.cpp',
        'common/putil.cpp',
        'common/rbbi.cpp',
        'common/rbbidata.cpp',
        'common/rbbinode.cpp',
        'common/rbbirb.cpp',
        'common/rbbiscan.cpp',
        'common/rbbisetb.cpp',
        'common/rbbistbl.cpp',
        'common/rbbitblb.cpp',
        'common/resbund.cpp',
        'common/resbund_cnv.cpp',
        'common/resource.cpp',
        'common/ruleiter.cpp',
        'common/schriter.cpp',
        'common/serv.cpp',
        'common/servlk.cpp',
        'common/servlkf.cpp',
        'common/servls.cpp',
        'common/servnotf.cpp',
        'common/servrbf.cpp',
        'common/servslkf.cpp',
        'common/sharedobject.cpp',
        'common/simpleformatter.cpp',
        'common/stringpiece.cpp',
        'common/stringtriebuilder.cpp',
        'common/uarrsort.c',
        'common/ubidi.c',
        'common/ubidi_props.c',
        'common/ubidiln.c',
        'common/ubidiwrt.c',
        'common/ubrk.cpp',
        'common/ucase.cpp',
        'common/ucasemap.cpp',
        'common/ucasemap_titlecase_brkiter.cpp',
        'common/ucat.c',
        'common/uchar.c',
        'common/ucharstrie.cpp',
        'common/ucharstriebuilder.cpp',
        'common/ucharstrieiterator.cpp',
        'common/uchriter.cpp',
        'common/ucln_cmn.cpp',
        'common/ucmndata.c',
        'common/ucnv.c',
        'common/ucnv2022.cpp',
        'common/ucnv_bld.cpp',
        'common/ucnv_cb.c',
        'common/ucnv_cnv.c',
        'common/ucnv_ct.c',
        'common/ucnv_err.c',
        'common/ucnv_ext.cpp',
        'common/ucnv_io.cpp',
        'common/ucnv_lmb.c',
        'common/ucnv_set.c',
        'common/ucnv_u16.c',
        'common/ucnv_u32.c',
        'common/ucnv_u7.c',
        'common/ucnv_u8.c',
        'common/ucnvbocu.cpp',
        'common/ucnvdisp.c',
        'common/ucnvhz.c',
        'common/ucnvisci.c',
        'common/ucnvlat1.c',
        'common/ucnvmbcs.cpp',
        'common/ucnvscsu.c',
        'common/ucnvsel.cpp',
        'common/ucol_swp.cpp',
        'common/ucurr.cpp',
        'common/udata.cpp',
        'common/udatamem.c',
        'common/udataswp.c',
        'common/uenum.c',
        'common/uhash.c',
        'common/uhash_us.cpp',
        'common/uidna.cpp',
        'common/uinit.cpp',
        'common/uinvchar.c',
        'common/uiter.cpp',
        'common/ulist.c',
        'common/ulistformatter.cpp',
        'common/uloc.cpp',
        'common/uloc_keytype.cpp',
        'common/uloc_tag.c',
        'common/umapfile.c',
        'common/umath.c',
        'common/umutex.cpp',
        'common/unames.cpp',
        'common/unifiedcache.cpp',
        'common/unifilt.cpp',
        'common/unifunct.cpp',
        'common/uniset.cpp',
        'common/uniset_closure.cpp',
        'common/uniset_props.cpp',
        'common/unisetspan.cpp',
        'common/unistr.cpp',
        'common/unistr_case.cpp',
        'common/unistr_case_locale.cpp',
        'common/unistr_cnv.cpp',
        'common/unistr_props.cpp',
        'common/unistr_titlecase_brkiter.cpp',
        'common/unorm.cpp',
        'common/unormcmp.cpp',
        'common/uobject.cpp',
        'common/uprops.cpp',
        'common/ures_cnv.c',
        'common/uresbund.cpp',
        'common/uresdata.cpp',
        'common/usc_impl.c',
        'common/uscript.c',
        'common/uscript_props.cpp',
        'common/uset.cpp',
        'common/uset_props.cpp',
        'common/usetiter.cpp',
        'common/ushape.cpp',
        'common/usprep.cpp',
        'common/ustack.cpp',
        'common/ustr_cnv.cpp',
        'common/ustr_titlecase_brkiter.cpp',
        'common/ustr_wcs.cpp',
        'common/ustrcase.cpp',
        'common/ustrcase_locale.cpp',
        'common/ustrenum.cpp',
        'common/ustrfmt.c',
        'common/ustring.cpp',
        'common/ustrtrns.cpp',
        'common/utext.cpp',
        'common/utf_impl.c',
        'common/util.cpp',
        'common/util_props.cpp',
        'common/utrace.c',
        'common/utrie.cpp',
        'common/utrie2.cpp',
        'common/utrie2_builder.cpp',
        'common/uts46.cpp',
        'common/utypes.c',
        'common/uvector.cpp',
        'common/uvectr32.cpp',
        'common/uvectr64.cpp',
        'common/wintz.c',
    ],
    LIBDEPS=[
        'icu_data',
    ],
)

env.Library(
    target='icu_data',
    source=[
        'stubdata/stubdata.c',
    ],
)
