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

try:
  env_etc.eigen_dist = os.path.abspath(os.path.join(libtbx.env.dist_path("boost"),"../eigen"))
  if not os.path.isdir(env_etc.eigen_dist) and hasattr(env_etc, "conda_cpppath"):
    for candidate in env_etc.conda_cpppath:
      if os.path.isdir(os.path.join(candidate, "eigen3")):
        env_etc.eigen_dist = os.path.abspath(os.path.join(os.path.join(candidate, "eigen3")))
  if os.path.isdir(env_etc.eigen_dist):
    env_etc.eigen_include = env_etc.eigen_dist
    env_etc.scitbx_ex_bev_common_includes = [
      env_etc.eigen_include,
      env_etc.libtbx_include,
      env_etc.scitbx_include,
      env_etc.boost_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.scitbx_ex_bev_common_includes)
    if (env_etc.static_libraries): builder = env.StaticLibrary
    else:                          builder = env.SharedLibrary
    # future expansion, create static library
    #builder(
    #  target="#lib/scitbx_ex_bev",
    #  source=["scitbx_ex_bev_core.cpp"]
    #  )

    if (not env_etc.no_boost_python):
      Import("env_boost_python_ext")
      env_scitbx_ex_bev_boost_python_ext = env_boost_python_ext.Clone()
    #  env_scitbx_ex_bev_boost_python_ext.Prepend(
    #                 LIBS=["scitbx_ex_bev",])
      env_scitbx_ex_bev_boost_python_ext.SharedLibrary(
                     target="#lib/scitbx_examples_bevington_ext", source="bevington_ext.cpp")
      env_etc.include_registry.append(
        env=env_scitbx_ex_bev_boost_python_ext,
        paths=env_etc.scitbx_ex_bev_common_includes)
      Export("env_scitbx_ex_bev_boost_python_ext")
except Exception:
  pass
