# -*- mode: python -*-

Import("env windows linux darwin solaris")

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

env = env.Clone()

env.Append(CPPDEFINES=["JSFILE", "EXPORT_JS_API", "JS_C_STRINGS_ARE_UTF8"])

for to_remove in ['-Werror', '/TP', '/O2', '/Gy']:
    removeIfPresent(env['CCFLAGS'], to_remove)

if windows:
    env.Append(CCFLAGS=['/wd4748'])

removeIfPresent(env['CPPDEFINES'], 'NDEBUG')

if linux or darwin:
    env.Append(CPPDEFINES=['HAVE_VA_COPY', 'VA_COPY=va_copy'])
elif solaris:
    env.Append(CPPDEFINES=['SOLARIS', 'HAVE_VA_LIST_AS_ARRAY', 'SVR4', 'SYSV', 'HAVE_LOCALTIME_R'])

env.Program('jskwgen', 'jskwgen.c')
env.Program('jscpucfg', 'jscpucfg.c')

env.Command('jsautokw.h', ['${PROGREFIX}jskwgen${PROGSUFFIX}'],
            '$SOURCE >$TARGET')

env.Command('jsautocfg.h', ['${PROGREFIX}jscpucfg${PROGSUFFIX}'],
            '$SOURCE >$TARGET')

env.StaticLibrary(
    "js",
    [ "jsapi.c",
      "jsarena.c",
      "jsarray.c",
      "jsatom.c",
      "jsbool.c",
      "jscntxt.c",
      "jsdate.c",
      "jsdbgapi.c",
      "jsdhash.c",
      "jsdtoa.c",
      "jsemit.c",
      "jsexn.c",
      "jsfun.c",
      "jsgc.c",
      "jshash.c",
      "jsiter.c",
      "jsinterp.c",
      "jslock.c",
      "jslog2.c",
      "jslong.c",
      "jsmath.c",
      "jsnum.c",
      "jsobj.c",
      "jsopcode.c",
      "jsparse.c",
      "jsprf.c",
      "jsregexp.c",
      "jsscan.c",
      "jsscope.c",
      "jsscript.c",
      "jsstr.c",
      "jsutil.c",
      "jsxdrapi.c",
      "jsxml.c",
      "prmjtime.c",
      ])
