import libtbx.load_env
import os
Import("env_base", "env_etc")

env_etc.rstbx_dist = libtbx.env.dist_path("rstbx")
env_etc.rstbx_include = os.path.dirname(env_etc.rstbx_dist)
env_etc.rstbx_common_includes = [
  env_etc.rstbx_include,
  env_etc.libtbx_include,
  env_etc.cctbx_include,
  env_etc.scitbx_include,
  env_etc.chiltbx_include,
  env_etc.omptbx_include,
  env_etc.boost_include,
  env_etc.annlib_dist,
  env_etc.annlib_include[0],
  env_etc.annlib_include[1],
  env_etc.annlib_adaptbx_include[0],
  env_etc.annlib_adaptbx_include[1],
  env_etc.dxtbx_include,
]

env = env_base.Clone(SHLINKFLAGS=env_etc.shlinkflags)
env.Append(LIBS=["cctbx"] + env_etc.libm)
env_etc.include_registry.append(
  env=env,
  paths=env_etc.rstbx_common_includes)

if not libtbx.env.module_is_installed("rstbx"):
  if (env_etc.static_libraries): builder = env.StaticLibrary
  else:                          builder = env.SharedLibrary
  builder(
    target="#lib/rstbx",
    source=["dps_core/dps_core.cpp",
            "dps_core/directional_fft.cpp",
            "dps_core/direction.cpp",
            "indexing_api/indexing_api.cpp",
            "diffraction/ewald_sphere.cpp",
            "diffraction/partial_spot_position_partial_H.cpp"
    ])

  if (not env_etc.no_boost_python):
    Import("env_boost_python_ext")
    env_rstbx_boost_python_ext = env_boost_python_ext.Clone()
    env_rstbx_boost_python_ext.Prepend(
                  LIBS=["rstbx", "ann", "cctbx", "scitbx_boost_python"])
    env_rstbx_boost_python_ext.SharedLibrary(
                  target="#lib/rstbx_ext", source="ext.cpp")
    env_rstbx_boost_python_ext.SharedLibrary(
                      target="#lib/rstbx_array_family_flex_ext",
                      source=[
                        "array_family/ext.cpp",
                        "array_family/flex_rstbx_arrays.cpp",
                      ])
    env_etc.include_registry.append(
      env=env_rstbx_boost_python_ext,
      paths=env_etc.rstbx_common_includes)
    Export("env_rstbx_boost_python_ext")

    SConscript("diffraction/fastbragg/SConscript")
    SConscript("simulation/SConscript")
    SConscript("simage/SConscript")
    SConscript("apps/SConscript")
    SConscript("bpcx/SConscript")
    SConscript("bandpass/SConscript")
    SConscript("symmetry/constraints/SConscript")
    SConscript("indexing_api/SConscript")
