Permalink
Browse files

FEAT: cluster + fftpack build on darwin.

  • Loading branch information...
cournape committed Jun 1, 2011
1 parent 75caf27 commit 4cf2a8903aeb0f3bce8d04d3fbf0120bfda743f5
Showing with 348 additions and 0 deletions.
  1. +49 −0 bento.info
  2. +112 −0 bscript
  3. +104 −0 f2py.py
  4. +7 −0 scipy/cluster/bento.info
  5. +63 −0 scipy/fftpack/bento.info
  6. +13 −0 scipy/fftpack/bscript
View
@@ -0,0 +1,49 @@
+Name: scipy
+Version: 0.10.0
+Summary: SciPy: Scientific Library for Python
+Url: http://www.scipy.org
+DownloadUrl: http://sourceforge.net/project/showfiles.php?group_id=27747&package_id=19531
+Description:
+ SciPy (pronounced "Sigh Pie") is open-source software for mathematics,
+ science, and engineering. The SciPy library depends on NumPy, which
+ provides convenient and fast N-dimensional array manipulation. The SciPy
+ library is built to work with NumPy arrays, and provides many user-friendly
+ and efficient numerical routines such as routines for numerical integration
+ and optimization. Together, they run on all popular operating systems, are
+ quick to install, and are free of charge. NumPy and SciPy are easy to use,
+ but powerful enough to be depended upon by some of the world's leading
+ scientists and engineers. If you need to manipulate numbers on a computer
+ and display or publish the results, give SciPy a try!
+Maintainer: SciPy Developers
+MaintainerEmail: scipy-dev@scipy.org
+License: BSD
+Platforms: Windows,Linux,Solaris,Mac OS-X,Unix
+Classifiers:
+ Development Status :: 4 - Beta,
+ Intended Audience :: Science/Research,
+ Intended Audience :: Developers,
+ License :: OSI Approved,
+ Programming Language :: C,
+ Programming Language :: Python,
+ Programming Language :: Python :: 3,
+ Topic :: Software Development,
+ Topic :: Scientific/Engineering,
+ Operating System :: Microsoft :: Windows,
+ Operating System :: POSIX,
+ Operating System :: Unix,
+ Operating System :: MacOS
+
+HookFile:
+ bscript,
+ scipy/fftpack/bscript
+
+Recurse:
+ scipy/cluster,
+ scipy/fftpack
+
+Library:
+ Packages:
+ scipy,
+ scipy.cluster,
+ scipy.constants,
+ scipy.fftpack
View
112 bscript
@@ -0,0 +1,112 @@
+import sys
+
+from numpy.distutils.misc_util \
+ import \
+ get_numpy_include_dirs
+from numpy.distutils.conv_template \
+ import \
+ process_str as process_c_str
+
+from bento.commands import hooks
+from bento.commands.extras.waf \
+ import \
+ ConfigureWafContext, BuildWafContext, register_options
+
+import waflib
+from waflib import Options
+
+# FIXME: add this to numpy so that we can reuse it
+class CTemplateTask(waflib.Task.Task):
+ color = 'BLUE'
+ before = ['c']
+ def run(self):
+ s = self.inputs[0]
+ cnt = s.read()
+ writestr = process_c_str(cnt)
+ o = self.outputs[0]
+ o.write(writestr)
+
+@waflib.TaskGen.feature("c_template")
+@waflib.TaskGen.extension(".src")
+def c_template(self, node):
+ outs = []
+ outs.append(node.change_ext(""))
+
+ tsk = self.create_task('CTemplateTask', node, outs)
+ if "c" in self.features:
+ self.source.append(outs[0])
+
+@hooks.startup
+def startup(context):
+ context.register_context("configure", ConfigureWafContext)
+ context.register_context("build", BuildWafContext)
+
+@hooks.options
+def options(context):
+ register_options(context)
+
+@hooks.pre_configure()
+def pre_configure(context):
+ opts = context.waf_options_context
+ opts.load("compiler_fc")
+ opts.load("f2py")
+ Options.options.check_fc = "gfortran"
+
+ conf = context.waf_context
+ conf.load("compiler_fc")
+ conf.load("f2py")
+
+def remove_flag(name, flag):
+ while True:
+ if name in flag:
+ i = flag.index(name)
+ flag.pop(i)
+ else:
+ break
+
+def remove_flag_postvalue(name, flag):
+ while True:
+ if name in flag:
+ i = flag.index(name)
+ flag.pop(i)
+ flag.pop(i)
+ else:
+ break
+
+def remove_flag_prevalue(name, flag):
+ while True:
+ if name in flag:
+ i = flag.index(name)
+ flag.pop(i-1)
+ flag.pop(i-1)
+ else:
+ break
+
+@hooks.post_configure()
+def post_configure(context):
+ conf = context.waf_context
+
+ conf.env.INCLUDES = get_numpy_include_dirs()
+
+ cflags_pyext = conf.env.CFLAGS_PYEXT
+ cflags_pyext.append("-Wfatal-errors")
+ conf.env.CFLAGS_PYEXT = cflags_pyext
+
+ if sys.platform == "darwin":
+ # FIXME: fix upstream waf tool to work on mac os X
+ conf.env.CC = ["/usr/bin/gcc-4.0"]
+ conf.env.LINK_CC = ["/usr/bin/gcc-4.0"]
+ # FIXME: fix upstream waf tool to avoid linking against libpython2.6.so
+ # (cause crashes when importing the extension)
+ name = "python%s" % ".".join([str(i) for i in sys.version_info[:2]])
+ remove_flag(name, conf.env.LIB_PYEXT)
+ remove_flag("-dynamiclib", conf.env.LINKFLAGS_cshlib)
+ remove_flag_postvalue("-compatibility_version", conf.env.CFLAGS_cshlib)
+ remove_flag_postvalue("-current_version", conf.env.CFLAGS_cshlib)
+ for flag in [conf.env.CFLAGS_PYEXT, conf.env.LINKFLAGS_PYEXT,
+ conf.env.CXXFLAGS_PYEXT, conf.env.FCFLAGS]:
+ remove_flag_prevalue("ppc", flag)
+ conf.env.LINKFLAGS_cshlib.extend(["-undefined", "dynamic_lookup", "-bundle"])
+ conf.env["MACOSX_DEPLOYMENT_TARGET"] = "10.4"
+
+ conf.env.MACOSX_DEPLOYMENT_TARGET = "10.4"
View
104 f2py.py
@@ -0,0 +1,104 @@
+import os.path as op
+import re
+
+import numpy.f2py
+import numpy.distutils.misc_util
+
+from waflib import Task
+from waflib.TaskGen import extension
+
+CGEN_TEMPLATE = '%smodule'
+FOBJECT_FILE = 'fortranobject.c'
+FHEADER_FILE = 'fortranobject.h'
+FWRAP_TEMPLATE = '%s-f2pywrappers.f'
+
+# This path is relative to build directory
+F2PY_TEMP_DIR = '.f2py'
+
+# Those regex are copied from build_src in numpy.distutils.command
+F2PY_MODNAME_MATCH = re.compile(r'\s*python\s*module\s*(?P<name>[\w_]+)',
+ re.I).match
+F2PY_UMODNAME_MATCH = re.compile(r'\s*python\s*module\s*(?P<name>[\w_]*?'\
+ '__user__[\w_]*)',re.I).match
+# End of copy
+def is_pyf(node):
+ return node.name.endswith(".pyf")
+
+def f2py_modulename(node):
+ """This returns the name of the module from the pyf source file.
+
+ source is expected to be one string, containing the whole source file
+ code."""
+ name = None
+ for line in node.read().splitlines():
+ m = F2PY_MODNAME_MATCH(line)
+ if m:
+ if F2PY_UMODNAME_MATCH(line): # skip *__user__* names
+ continue
+ name = m.group('name')
+ break
+ return name
+
+@extension('.pyf')
+def add_f2py_files(task_gen, node):
+ ext = '.c'
+
+ includes = task_gen.env["INCLUDES"]
+ d = op.dirname(numpy.f2py.__file__)
+ includes.append(op.join(d, 'src'))
+ includes.extend(numpy.distutils.misc_util.get_numpy_include_dirs())
+ task_gen.env["INCLUDES"] = includes
+
+ if is_pyf(node):
+ module_name = f2py_modulename(node)
+ module_node = node.parent.find_or_declare("%smodule.c" % module_name)
+ parent_node = module_node.parent
+
+ # Make sure module_node is a generated file to avoid overwriting user
+ # content (I really don't like find_or_declare).
+ assert module_node.is_bld()
+ build_dir = parent_node.bldpath()
+
+ fortranobject_node = task_gen.bld.bldnode.find_node(op.join(F2PY_TEMP_DIR, FOBJECT_FILE))
+ assert fortranobject_node is not None
+ fwrapper_node = parent_node.find_or_declare(FWRAP_TEMPLATE % module_name)
+ fwrapper_node.write("")
+
+ # XXX: evil hack to make get_bld_sig work here. Find out how to do this properly
+ fortranobject_node.is_bld = lambda : False
+ fwrapper_node.is_bld = lambda : False
+ task_gen.source.append(fortranobject_node)
+ task_gen.source.append(fwrapper_node)
+
+ task_gen.env.F2PYFLAGS.extend(["--build-dir", build_dir])
+
+ tsk = task_gen.create_task('f2py', node, module_node)
+ task_gen.source += tsk.outputs
+ else:
+ raise NotImplementedError("non .pyf input not supported yet.")
+
+class f2py(Task.Task):
+ run_str = '${F2PY} ${F2PYFLAGS} ${SRC}'
+ color = 'CYAN'
+
+def configure(conf):
+ if not conf.env.CC and not conf.env.CXX:
+ conf.fatal('Load a C/C++ compiler first')
+ if not conf.env.PYTHON:
+ conf.fatal('Load the python tool first!')
+ conf.find_program('f2py', var='F2PY')
+ # FIXME: this has nothing to do here
+ conf.env.F2PYFLAGS = ["--quiet"]
+
+ f2py_tempdir = conf.bldnode.make_node(F2PY_TEMP_DIR)
+ f2py_tempdir.mkdir()
+
+ fobject = f2py_tempdir.make_node(FOBJECT_FILE)
+
+ d = op.dirname(numpy.f2py.__file__)
+ source_c = op.join(d, 'src', FOBJECT_FILE)
+ fobject.write(open(source_c).read())
+
+ #fheader = f2py_tempdir.make_node(FHEADER_FILE)
+ #source_c = op.join(d, 'src', FHEADER_FILE)
+ #fheader.write(open(source_c).read())
View
@@ -0,0 +1,7 @@
+Library:
+ Extension: _hierarchy_wrap
+ Sources:
+ src/hierarchy_wrap.c, src/hierarchy.c
+ Extension: _vq
+ Sources:
+ src/vq_module.c, src/vq.c
View
@@ -0,0 +1,63 @@
+Library:
+ CompiledLibrary: fftpack
+ Sources:
+ src/fftpack/cfftb.f,
+ src/fftpack/cfftb1.f,
+ src/fftpack/cfftf.f,
+ src/fftpack/cfftf1.f,
+ src/fftpack/cffti.f,
+ src/fftpack/cffti1.f,
+ src/fftpack/cosqb.f,
+ src/fftpack/cosqf.f,
+ src/fftpack/cosqi.f,
+ src/fftpack/cost.f,
+ src/fftpack/costi.f,
+ src/fftpack/rfftb.f,
+ src/fftpack/rfftb1.f,
+ src/fftpack/rfftf.f,
+ src/fftpack/rfftf1.f,
+ src/fftpack/rffti.f,
+ src/fftpack/rffti1.f,
+ src/fftpack/sinqb.f,
+ src/fftpack/sinqf.f,
+ src/fftpack/sinqi.f,
+ src/fftpack/sint.f,
+ src/fftpack/sint1.f,
+ src/fftpack/sinti.f
+ CompiledLibrary: dfftpack
+ Sources:
+ src/dfftpack/dcosqb.f,
+ src/dfftpack/dcosqf.f,
+ src/dfftpack/dcosqi.f,
+ src/dfftpack/dcost.f,
+ src/dfftpack/dcosti.f,
+ src/dfftpack/dfftb.f,
+ src/dfftpack/dfftb1.f,
+ src/dfftpack/dfftf.f,
+ src/dfftpack/dfftf1.f,
+ src/dfftpack/dffti.f,
+ src/dfftpack/dffti1.f,
+ src/dfftpack/dsinqb.f,
+ src/dfftpack/dsinqf.f,
+ src/dfftpack/dsinqi.f,
+ src/dfftpack/dsint.f,
+ src/dfftpack/dsint1.f,
+ src/dfftpack/dsinti.f,
+ src/dfftpack/zfftb.f,
+ src/dfftpack/zfftb1.f,
+ src/dfftpack/zfftf.f,
+ src/dfftpack/zfftf1.f,
+ src/dfftpack/zffti.f,
+ src/dfftpack/zffti1.f
+ Extension: _fftpack
+ Sources:
+ src/zfft.c,
+ src/drfft.c,
+ src/zrfft.c,
+ src/zfftnd.c,
+ fftpack.pyf,
+ src/dct.c.src
+ Extension: convolve
+ Sources:
+ src/convolve.c,
+ convolve.pyf
View
@@ -0,0 +1,13 @@
+from bento.commands import hooks
+
+@hooks.pre_build()
+def pbuild(context):
+ bld = context.waf_context
+
+ def builder(extension):
+ bld(features="c pyext cshlib bento",
+ source=extension.sources,
+ target=extension.name,
+ includes="src",
+ use="dfftpack fftpack")
+ context.register_builder("_fftpack", builder)

0 comments on commit 4cf2a89

Please sign in to comment.