Import("env")


Import("env_base", "env_etc")

import libtbx, os

env_etc.dials_indexing_dist = libtbx.env.dist_path("dials")
env_etc.dials_indexing_include = os.path.dirname(env_etc.dials_indexing_dist)
env_etc.dials_indexing_common_includes = [
    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.include_registry.append(env=env, paths=env_etc.dials_indexing_common_includes)

sources = ["boost_python/fft3d.cc", "boost_python/indexing_ext.cc"]

# Since this code is not using OpenMP a bug in the Microsoft VS2008 compiler means that
# any /openmp flag must be removed in order to avoid creating a broken library
if env_etc.compiler == "win32_cl" and "/openmp" in env["SHCCFLAGS"]:
    ccflags_without_omp = []
    for f in env["SHCCFLAGS"]:
        if "/openmp" != f:
            ccflags_without_omp.append(f)
    env["SHCCFLAGS"] = ccflags_without_omp

# Handle cctbx renaming of ann in installed environments
LIB_ANN = "ann"
if libtbx.env.module_is_installed("annlib"):
    LIB_ANN = "ann_cctbx"

env.SharedLibrary(
    target="#/lib/dials_algorithms_indexing_ext",
    source=sources,
    LIBS=[LIB_ANN] + env["LIBS"],
)
