import sys

from libtbx.env_config import get_boost_library_with_python_version

Import("env_scitbx_boost_python_ext", "env_etc")

env = env_scitbx_boost_python_ext.Clone()
env_etc.enable_more_warnings(env=env)
env.SharedLibrary(target="regression_test_ext", source=[
  "regression_test_ext.cpp",
])

# Check for the existence of numpy and use it for the bridge
try:
  import numpy

  # Build a special environment to compile the numpy bridge in
  env_npy = env.Clone()
  env_etc.include_registry.append(env=env_npy, paths=[numpy.get_include()])
  npyflag = "-DSCITBX_HAVE_NUMPY_INCLUDE"
  if env_etc.compiler == "win32_cl":
    npyflag = "/DSCITBX_HAVE_NUMPY_INCLUDE"
  env_npy.Append(SHCXXFLAGS=[ npyflag ])

  if env_etc.boost_version >= 106300:
    # Link the boost_numpy library into the extension
    env.Append(LIBS=
      get_boost_library_with_python_version("boost_numpy", env['LIBPATH']))
except ImportError:
  # We don't have numpy
  env_npy = env

npy_bridge = env_npy.SharedObject(source="numpy_bridge.cpp")

env.SharedLibrary(
  target="#lib/scitbx_array_family_flex_ext",
  source=[
  "flex_ext.cpp",
  "flex_grid.cpp",
  "flex_bool.cpp",
  "flex_size_t.cpp",
  "flex_int.cpp",
  "flex_float.cpp",
  "flex_double.cpp",
  "flex_double_matrix.cpp",
  "flex_complex_double.cpp",
  "flex_std_string.cpp",
  "flex_random.cpp",
  "flex_sort.cpp",
  "flex_histogram.cpp",
  "flex_weighted_histogram.cpp",
  "flex_mean_and_variance.cpp",
  "flex_median.cpp",
  "flex_linear_interpolation.cpp",
  "flex_vec3_double.cpp",
  "flex_vec2_double.cpp",
  "flex_vec3_int.cpp",
  "flex_sym_mat3_double.cpp",
  "flex_mat3_double.cpp",
  "flex_tiny_size_t_2.cpp",
  "loops.cpp",
  "show_sizes.cpp",
  npy_bridge
])

env.SharedLibrary(
  target="#lib/scitbx_array_family_shared_ext",
  source=[
  "shared_ext.cpp",
])
