Import('env')
import os
module_env = env.Clone()
go_dir = Dir('go').abspath
go_archive = os.path.join(go_dir, 'libtitanic_go.a')
go_shared = os.path.join(go_dir, 'libtitanic_go.so')
if os.path.isfile(go_archive) or os.path.isfile(go_shared):
    if os.path.isfile(go_archive):
        env.Append(LIBS=[File(go_archive)])
        if env['platform'] in ['x11', 'linuxbsd']:
            env.Append(LIBS=['pthread', 'dl'])
        elif env['platform'] in ['osx', 'macos']:
            # Go's HTTPS certificate verification uses the system trust store.
            env.Append(LINKFLAGS=['-framework', 'Security', '-framework', 'CoreFoundation'])
    else:
        env.Append(LIBPATH=[go_dir], LIBS=['titanic_go'])
else:
    raise RuntimeError('Missing Go gameplay library')
module_env.add_source_files(env.modules_sources, ['runtime.cpp', 'register_types.cpp'])
