Skip to content

Commit

Permalink
BENTO: start numpy.core configuration
Browse files Browse the repository at this point in the history
We also add configuration helpers in numpy.build_utils.
  • Loading branch information
cournape committed Aug 28, 2011
1 parent d2f648a commit 0c7af4b
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bento.info
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ Classifiers:
Operating System :: Unix,
Operating System :: MacOS

Recurse:
numpy/core

HookFile:
bscript
bscript,
numpy/core/bscript

ExtraSourceFiles:
numpy_templates.py,
Expand Down
5 changes: 5 additions & 0 deletions bscript
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import sys

# Ugly but necessary hack: import numpy here so that wscript in sub directories
# will see this numpy and not an already installed one
import __builtin__
__builtin__.__NUMPY_SETUP__ = True

from bento.commands.hooks \
import \
pre_configure
Expand Down
22 changes: 22 additions & 0 deletions numpy/core/bento.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Library:
CompiledLibrary: npymath
Sources:
src/npymath/_signbit.c,
src/npymath/ieee754.c.src,
src/npymath/npy_math.c.src,
src/npymath/npy_math_complex.c.src
Extension: multiarray
Sources:
src/multiarray/multiarraymodule_onefile.c
Extension: multiarray_tests
Sources:
src/multiarray/multiarray_tests.c.src
Extension: _sort
Sources:
src/_sortmodule.c.src
Extension: umath
Sources:
src/umath/umathmodule_onefile.c
Extension: scalarmath
Sources:
src/scalarmathmodule.c.src
35 changes: 35 additions & 0 deletions numpy/core/bscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from bento.commands.hooks \
import \
pre_configure
import waflib

# Importing this adds new checkers to waf configure context - I don't like this
# way of working, should find a more explicit way to attach new functions to
# context.
import numpy.waf_utils

from setup_common \
import \
OPTIONAL_STDFUNCS_MAYBE, OPTIONAL_STDFUNCS, C99_FUNCS_EXTENDED, \
C99_FUNCS_SINGLE, C99_COMPLEX_TYPES, C99_COMPLEX_FUNCS, \
MANDATORY_FUNCS, C_ABI_VERSION, C_API_VERSION

NUMPYCONFIG_SYM = []

# FIXME
NUMPYCONFIG_SYM.append(('DEFINE_NPY_ENABLE_SEPARATE_COMPILATION', ''))
NUMPYCONFIG_SYM.append(('VISIBILITY_HIDDEN', ''))

NUMPYCONFIG_SYM.append(('NPY_ABI_VERSION', '0x%.8X' % C_ABI_VERSION))
NUMPYCONFIG_SYM.append(('NPY_API_VERSION', '0x%.8X' % C_API_VERSION))

@pre_configure()
def configure(context):
conf = context.waf_context

try:
conf.check_header("endian.h")
NUMPYCONFIG_SYM.append(('DEFINE_NPY_HAVE_ENDIAN_H',
'#define NPY_HAVE_ENDIAN_H 1'))
except waflib.Errors.ConfigurationError:
NUMPYCONFIG_SYM.append(('DEFINE_NPY_HAVE_ENDIAN_H', ''))
79 changes: 79 additions & 0 deletions numpy/waf_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import os
import re

import waflib.Configure
import waflib.Tools.c_config
from waflib import Logs, Utils

DEFKEYS = waflib.Tools.c_config.DEFKEYS
DEFINE_COMMENTS = "define_commentz"

def to_header(dct):
if 'header_name' in dct:
dct = Utils.to_list(dct['header_name'])
return ''.join(['#include <%s>\n' % x for x in dct])
return ''

# Make the given string safe to be used as a CPP macro
def sanitize_string(s):
key_up = s.upper()
return re.sub('[^A-Z0-9_]', '_', key_up)

def validate_arguments(self, kw):
if not 'env' in kw:
kw['env'] = self.env.derive()
if not "compile_mode" in kw:
kw["compile_mode"] = "c"
if not 'compile_filename' in kw:
kw['compile_filename'] = 'test.c' + \
((kw['compile_mode'] == 'cxx') and 'pp' or '')
if not 'features' in kw:
kw['features'] = [kw['compile_mode']]
if not 'execute' in kw:
kw['execute'] = False
if not 'okmsg' in kw:
kw['okmsg'] = 'yes'
if not 'errmsg' in kw:
kw['errmsg'] = 'no !'

def try_compile(self, kw):
self.start_msg(kw["msg"])
ret = None
try:
ret = self.run_c_code(**kw)
except self.errors.ConfigurationError as e:
self.end_msg(kw['errmsg'], 'YELLOW')
if Logs.verbose > 1:
raise
else:
self.fatal('The configuration failed')
else:
kw['success'] = ret
self.end_msg(self.ret_msg(kw['okmsg'], kw))

@waflib.Configure.conf
def check_header(self, header_name, **kw):
code = """
%s
int main()
{
}
""" % to_header({"header_name": header_name})

kw["code"] = code
kw["define_comment"] = "/* Define to 1 if you have the `%s' header. */" % header_name
kw["define_name"] = "HAVE_%s" % sanitize_string(header_name)
if not "features" in kw:
kw["features"] = ["c"]
kw["msg"] = "Checking for header %r" % header_name

validate_arguments(self, kw)
try_compile(self, kw)
ret = kw["success"]

self.post_check(**kw)
if not kw.get('execute', False):
return ret == 0
return ret

0 comments on commit 0c7af4b

Please sign in to comment.