diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/npymath.ini.in | 2 | ||||
-rw-r--r-- | numpy/core/setup.py | 96 | ||||
-rw-r--r-- | numpy/distutils/command/build_src.py | 69 | ||||
-rw-r--r-- | numpy/distutils/misc_util.py | 13 | ||||
-rw-r--r-- | numpy/distutils/numpy_distribution.py | 2 |
5 files changed, 102 insertions, 80 deletions
diff --git a/numpy/core/npymath.ini.in b/numpy/core/npymath.ini.in index 18f335dcc..73379e47c 100644 --- a/numpy/core/npymath.ini.in +++ b/numpy/core/npymath.ini.in @@ -4,7 +4,7 @@ Description=Portable, core math library implementing C99 standard Version=0.1 [variables] -prefix=@install_dir@ +prefix=@prefix@ libdir=${prefix}@sep@lib includedir=${prefix}@sep@include diff --git a/numpy/core/setup.py b/numpy/core/setup.py index b8d855b6b..bffe43fce 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -30,25 +30,6 @@ except ImportError: import pickle as _pik import copy -def subst_vars(target, source, d): - """Substitute any occurence of @foo@ by d['foo'] from source file into - target.""" - var = re.compile('@([a-zA-Z_]+)@') - fs = open(source, 'r') - try: - ft = open(target, 'w') - try: - for l in fs.readlines(): - m = var.search(l) - if m: - ft.write(l.replace('@%s@' % m.group(1), d[m.group(1)])) - else: - ft.write(l) - finally: - ft.close() - finally: - fs.close() - class CallOnceOnly(object): def __init__(self): self._check_types = None @@ -359,6 +340,7 @@ def configuration(parent_package='',top_path=None): d = os.path.dirname(target) if not os.path.exists(d): os.makedirs(d) + if newer(__file__,target): config_cmd = config.get_config_cmd() log.info('Generating %s',target) @@ -375,19 +357,6 @@ def configuration(parent_package='',top_path=None): mathlibs = check_mathlib(config_cmd) moredefs.append(('MATHLIB',','.join(mathlibs))) - # Write the mlib.ini file - d = os.path.join(build_dir, 'lib', 'npy-pkg-config') - if not os.path.exists(d): - os.makedirs(d) - filename = os.path.join(d, 'mlib.ini') - a = open(filename, 'w') - try: - a.write(mlib_pkg_content(mathlibs)) - finally: - a.close() - # Install it - config.add_data_files(('lib/npy-pkg-config', filename)) - check_math_capabilities(config_cmd, moredefs, mathlibs) moredefs.extend(cocache.check_ieee_macros(config_cmd)[0]) @@ -628,54 +597,27 @@ def configuration(parent_package='',top_path=None): # (don't ask). Because clib are generated before extensions, we have to # explicitly add an extension which has generate_config_h and # generate_numpyconfig_h as sources *before* adding npymath. - def generate_npymath_ini(ext, build_dir): - # This function generate npymath.ini and make sure distutils install - # it. Also handle in-place builds. - from numpy.distutils.misc_util import get_cmd - def inplace_build(): - return get_cmd('build_ext').inplace == 1 - - def install_npymath_ini(target, source, top_prefix): - top_prefix = os.path.abspath(os.path.join(top_prefix)) - prefix = os.path.join(top_prefix, 'numpy', 'core') - d = {'install_dir': prefix, 'sep': os.path.sep} - - subst_vars(target, source, d) - return target - - # install_dir relative to current package build directory - install_dir = 'lib/npy-pkg-config' - template = 'npymath.ini.in' - - basename = os.path.splitext(template)[0] - pkg_path = config.local_path - template = os.path.join(pkg_path, template) - - # where to put the generated file - target_dir = os.path.join(build_dir, pkg_path, install_dir) - if not os.path.exists(target_dir): - os.makedirs(target_dir) - generated = os.path.join(target_dir, basename) - - install_cmd = get_cmd('install') - if hasattr(install_cmd, 'install_libbase'): - top_prefix = install_cmd.install_libbase - source = install_npymath_ini(generated, template, top_prefix) - config.add_data_files((install_dir, source)) - elif inplace_build(): - top_prefix = '.' - generated = install_npymath_ini(generated, template, top_prefix) - - # Copy the generated file into the source tree - installed = os.path.join(pkg_path, install_dir, basename) - if not os.path.exists(os.path.dirname(installed)): - os.makedirs(os.path.dirname(installed)) - shutil.copy(generated, installed) + + subst_dict = dict([("sep", os.path.sep)]) + def get_mathlib_info(*args): + # Another ugly hack: the mathlib info is known once build_src is run, + # but we cannot use add_installed_pkg_config here either, so we only + # updated the substition dictionary during npymath build + config_cmd = config.get_config_cmd() + mlibs = check_mathlib(config_cmd) + + posix_mlib = ' '.join(['-l%s' % l for l in mlibs]) + msvc_mlib = ' '.join(['%s.lib' % l for l in mlibs]) + subst_dict["posix_mathlib"] = posix_mlib + subst_dict["msvc_mathlib"] = msvc_mlib config.add_installed_library('npymath', - sources=[join('src', 'npymath', 'npy_math.c.src'), - generate_npymath_ini], + sources=[join('src', 'npymath', 'npy_math.c.src'), get_mathlib_info], install_dir='numpy/core/lib') + config.add_installed_pkg_config("npymath.ini.in", "lib/npy-pkg-config", + subst_dict) + config.add_installed_pkg_config("mlib.ini.in", "lib/npy-pkg-config", + subst_dict) multiarray_deps = [ join('src', 'multiarray', 'arrayobject.h'), diff --git a/numpy/distutils/command/build_src.py b/numpy/distutils/command/build_src.py index 4ba3f0a9a..15e78eebc 100644 --- a/numpy/distutils/command/build_src.py +++ b/numpy/distutils/command/build_src.py @@ -22,10 +22,29 @@ except ImportError: #import numpy.f2py from numpy.distutils import log from numpy.distutils.misc_util import fortran_ext_match, \ - appendpath, is_string, is_sequence + appendpath, is_string, is_sequence, get_cmd from numpy.distutils.from_template import process_file as process_f_file from numpy.distutils.conv_template import process_file as process_c_file +def subst_vars(target, source, d): + """Substitute any occurence of @foo@ by d['foo'] from source file into + target.""" + var = re.compile('@([a-zA-Z_]+)@') + fs = open(source, 'r') + try: + ft = open(target, 'w') + try: + for l in fs.readlines(): + m = var.search(l) + if m: + ft.write(l.replace('@%s@' % m.group(1), d[m.group(1)])) + else: + ft.write(l) + finally: + ft.close() + finally: + fs.close() + class build_src(build_ext.build_ext): description = "build sources from SWIG, F2PY files or a function" @@ -147,6 +166,7 @@ class build_src(build_ext.build_ext): self.build_extension_sources(ext) self.build_data_files_sources() + self.build_npy_pkg_config() def build_data_files_sources(self): if not self.data_files: @@ -183,6 +203,53 @@ class build_src(build_ext.build_ext): raise TypeError(repr(data)) self.data_files[:] = new_data_files + + def _build_npy_pkg_config(self, info, gd): + import shutil + template, install_dir, subst_dict = info + template_dir = os.path.dirname(template) + for k, v in gd.items(): + subst_dict[k] = v + + if self.inplace == 1: + generated_dir = os.path.join(template_dir, install_dir) + else: + generated_dir = os.path.join(self.build_src, template_dir, + install_dir) + generated = os.path.basename(os.path.splitext(template)[0]) + generated_path = os.path.join(generated_dir, generated) + if not os.path.exists(generated_dir): + os.makedirs(generated_dir) + + subst_vars(generated_path, template, subst_dict) + + # Where to install relatively to install prefix + full_install_dir = os.path.join(template_dir, install_dir) + return full_install_dir, generated_path + + def build_npy_pkg_config(self): + log.info('building npkg modules') + + install_cmd = get_cmd('install') + build_npkg = False + gd = {} + if hasattr(install_cmd, 'install_libbase'): + top_prefix = install_cmd.install_libbase + build_npkg = True + elif self.inplace == 1: + top_prefix = '.' + build_npkg = True + + if build_npkg: + for pkg, infos in self.distribution.installed_pkg_config.items(): + pkg_path = self.distribution.package_dir[pkg] + prefix = os.path.join(os.path.abspath(top_prefix), pkg_path) + d = {'prefix': prefix} + for info in infos: + install_dir, generated = self._build_npy_pkg_config(info, d) + self.distribution.data_files.append((install_dir, + [generated])) + def build_py_modules_sources(self): if not self.py_modules: return diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py index 38dda7e3a..f3a3e04c2 100644 --- a/numpy/distutils/misc_util.py +++ b/numpy/distutils/misc_util.py @@ -600,7 +600,7 @@ class Configuration(object): _list_keys = ['packages', 'ext_modules', 'data_files', 'include_dirs', 'libraries', 'headers', 'scripts', 'py_modules', 'scons_data', 'installed_libraries'] - _dict_keys = ['package_dir'] + _dict_keys = ['package_dir', 'installed_pkg_config'] _extra_keys = ['name', 'version'] numpy_include_dirs = [] @@ -1215,6 +1215,17 @@ class Configuration(object): self._add_library(name, sources, install_dir, build_info) self.installed_libraries.append(InstallableLib(name, build_info, install_dir)) + def add_installed_pkg_config(self, template, install_dir, d=None): + if d is None: + d = {} + basename = os.path.splitext(template)[0] + template = os.path.join(self.package_path, template) + + if self.installed_pkg_config.has_key(self.name): + self.installed_pkg_config[self.name].append((template, install_dir, d)) + else: + self.installed_pkg_config[self.name] = [(template, install_dir, d)] + def add_scons_installed_library(self, name, install_dir): """Add an scons-built installable library to distutils. """ diff --git a/numpy/distutils/numpy_distribution.py b/numpy/distutils/numpy_distribution.py index 3e855b9c3..4424e34cd 100644 --- a/numpy/distutils/numpy_distribution.py +++ b/numpy/distutils/numpy_distribution.py @@ -9,6 +9,8 @@ class NumpyDistribution(Distribution): self.scons_data = [] # A list of installable libraries self.installed_libraries = [] + # A dict of pkg_config files to generate/install + self.installed_pkg_config = {} Distribution.__init__(self, attrs) def has_scons_scripts(self): |