diff options
-rw-r--r-- | doc/source/reference/distutils.rst | 22 | ||||
-rw-r--r-- | numpy/core/setup.py | 4 | ||||
-rw-r--r-- | numpy/distutils/misc_util.py | 81 |
3 files changed, 99 insertions, 8 deletions
diff --git a/doc/source/reference/distutils.rst b/doc/source/reference/distutils.rst index 051a1c031..8b628a507 100644 --- a/doc/source/reference/distutils.rst +++ b/doc/source/reference/distutils.rst @@ -229,6 +229,28 @@ misc_util Add the sequence of files to the beginning of the scripts list. Scripts will be installed under the <prefix>/bin/ directory. + .. method:: add_installed_library(name, sources, install_dir, **build_info) + + Similar to add_library, but the corresponding library is installed. + Most C libraries are only used to build python extensions, but + libraries built through this method will be installed so that they can + be reused by third-party. install_dir is relative to the current + subpackage. + + Example + ------- + config.add_installed_library('foo', sources=['foo.c'], install_dir='lib') + + If the package corresponding to config is 'fubar', this will install + the library in fubar/lib. + + Note + ---- + The best way to encode the necessary options to link against those C + libraries is to use a libname.ini file, and use get_info to retrieve + those informations (see add_npy_pkg_config method for more + information). + .. method:: paths(*paths) Applies glob.glob(...) to each path in the sequence (if needed) and diff --git a/numpy/core/setup.py b/numpy/core/setup.py index bffe43fce..1ae70f885 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -614,9 +614,9 @@ def configuration(parent_package='',top_path=None): config.add_installed_library('npymath', 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", + config.add_npy_pkg_config("npymath.ini.in", "lib/npy-pkg-config", subst_dict) - config.add_installed_pkg_config("mlib.ini.in", "lib/npy-pkg-config", + config.add_npy_pkg_config("mlib.ini.in", "lib/npy-pkg-config", subst_dict) multiarray_deps = [ diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py index 1fe482801..9d9c8128f 100644 --- a/numpy/distutils/misc_util.py +++ b/numpy/distutils/misc_util.py @@ -1204,7 +1204,26 @@ class Configuration(object): self.libraries.append((name, build_info)) def add_installed_library(self, name, sources, install_dir, build_info=None): - """Add installable library to configuration. + """Similar to add_library, but the corresponding library is installed. + + Most C libraries are only used to build python extensions, but + libraries built through this method will be installed so that they can + be reused by third-party. install_dir is relative to the current + subpackage. + + Example + ------- + config.add_installed_library('foo', sources=['foo.c'], install_dir='lib') + + If the package corresponding to config is 'fubar', this will install + the library in fubar/lib. + + Note + ---- + The best way to encode the necessary options to link against those C + libraries is to use a libname.ini file, and use get_info to retrieve + those informations (see add_npy_pkg_config method for more + information). """ if not build_info: build_info = {} @@ -1212,16 +1231,66 @@ 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 = {} + def add_npy_pkg_config(self, template, install_dir, subst_dict=None): + """Generate a npy-pkg config file from the template, and install it in + given install directory, using subst_dict for variable substitution. + + Parameters + ---------- + template: str + the path of the template, relatively to the current package path + install_dir: str + where to install the npy-pkg config file, relatively to the current + package path + subst_dict: dict (None by default) + if given, any string of the form @key@ will be replaced by + subst_dict[key] in the template file when installed. The install + prefix is always available through the variable @prefix@, since the + install prefix is not easy to get reliably from setup.py. + + Example + ------- + config.add_npy_pkg_config('foo.ini.in', 'lib', {'foo': bar}) + + Assuming the foo.ini.in file has the following content: + + ''' + [meta] + Name=@foo@ + Version=1.0 + Description=dummy description + + [default] + Cflags=-I@prefix@/include + Libs= + ''' + + The generated file will have the following content: + [meta] + Name=bar + Version=1.0 + Description=dummy description + + [default] + Cflags=-Iprefix_dir/include + Libs= + + Note + ---- + This works for both standard installs and in-place builds, i.e. the + @prefix@ refer to the source directory for in-place builds. + """ + if subst_dict is None: + subst_dict = {} 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)) + self.installed_pkg_config[self.name].append((template, install_dir, + subst_dict)) else: - self.installed_pkg_config[self.name] = [(template, install_dir, d)] + self.installed_pkg_config[self.name] = [(template, install_dir, + subst_dict)] def add_scons_installed_library(self, name, install_dir): """Add an scons-built installable library to distutils. |