import fftw3tbx
import libtbx.load_env
import os
Import("env_etc")

env_etc.fftw3tbx_dist = libtbx.env.dist_path("fftw3tbx")

env_etc.fftw3tbx_common_includes = [
  env_etc.libtbx_include,
  env_etc.scitbx_include,
  env_etc.boost_include,
]

base_include = libtbx.env.under_build("base/include")
if (os.path.isfile(os.path.join(base_include, fftw3tbx.fftw3_h))):
  env_etc.fftw3tbx_common_includes.insert(1, base_include)

if (not env_etc.no_boost_python):
  Import("env_scitbx_boost_python_ext")
  env_bpl = env_scitbx_boost_python_ext.Clone()
  env_bpl.Prepend(LIBS=["fftw3"])
  env_etc.include_registry.append(
    env=env_bpl,
    paths=env_etc.fftw3tbx_common_includes)
  conf = env_bpl.Configure()
  flag = conf.TryCompile("#include <%s>" % fftw3tbx.fftw3_h, extension=".cpp")
  conf.Finish()
  if (not flag):
    print "fftw3tbx: %s not available." % fftw3tbx.fftw3_h
    print "fftw3tbx: Compilation skipped."
  else:
    env_bpl.SharedLibrary(
      target="#lib/fftw3tbx_ext",
      source=["ext.cpp"])
