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

env = env_base.Clone()
env_etc.enable_more_warnings(env=env)
env_etc.include_registry.append(
  env=env,
  paths=env_etc.scitbx_common_includes)
env = env.Clone(LIBS=env_etc.libm)
env.Program(target="tst_lbfgs", source="tst_lbfgs.cpp")

def append_fable_include(env):
  env_etc.include_registry.append(env=env, paths=[env_etc.fable_include])

lbfgs_fem_obj = None
if (libtbx.env.has_module("fable")):
  env = env.Clone()
  append_fable_include(env=env)
  lbfgs_fem_obj = env.SharedObject(source=["lbfgs_fem.cpp"])
  env.Program(target="sdrive_fem", source=["sdrive_fem.cpp", lbfgs_fem_obj])

if (not env_etc.no_boost_python):
  Import("env_scitbx_boost_python_ext")
  env = env_scitbx_boost_python_ext
  source=["ext.cpp"]
  if (lbfgs_fem_obj is not None):
    env = env.Clone()
    env.Prepend(CPPFLAGS=["-DSCITBX_LBFGS_HAVE_LBFGS_FEM"])
    append_fable_include(env=env)
    source.append(lbfgs_fem_obj)
  env.SharedLibrary(target="#lib/scitbx_lbfgs_ext", source=source)
