[2504] | 1 | import os, sys, platform
|
---|
| 2 | import subprocess
|
---|
[2525] | 3 | import glob
|
---|
[2504] | 4 | import shutil
|
---|
| 5 | from distutils.command import build_ext
|
---|
| 6 |
|
---|
[2525] | 7 | try:
|
---|
| 8 | from setuptools import setup as _setup
|
---|
| 9 | from setuptools import Extension
|
---|
| 10 | except ImportError, ex:
|
---|
| 11 | from distutils.core import setup as _setup
|
---|
| 12 | from distutils.core import Extension
|
---|
| 13 |
|
---|
| 14 | def setup(*args, **kwargs):
|
---|
| 15 | asapso = Extension(name="%s._%s".format(kwargs['name'],kwargs['name']),
|
---|
| 16 | sources=[])
|
---|
| 17 | d = {'ext_modules': [ asapso ],
|
---|
| 18 | 'cmdclass': {'build_ext': scons_ext}
|
---|
| 19 | }
|
---|
| 20 | kwargs.update(d)
|
---|
| 21 | print kwargs
|
---|
| 22 | _setup(*args, **kwargs)
|
---|
| 23 |
|
---|
| 24 |
|
---|
[2504] | 25 | class scons_ext(build_ext.build_ext):
|
---|
| 26 | """Build extensions using scons instead of distutils.
|
---|
| 27 | """
|
---|
| 28 | _scons_options = []
|
---|
| 29 | user_options = \
|
---|
| 30 | [('casacoreroot=', None,
|
---|
| 31 | 'Prefix for casacore installation location'),
|
---|
[2515] | 32 | ('casacorestatic=', None,
|
---|
| 33 | 'use static casacore libraries'),
|
---|
[2504] | 34 | ('boostroot=', None,
|
---|
| 35 | 'Prefix for boost_python installation location'),
|
---|
| 36 | ('boostlib=', None, 'Name of the boost_python library'),
|
---|
| 37 | ('cfitsioroot=', None,
|
---|
| 38 | 'Prefix for cfitsio installation location'),
|
---|
| 39 | ('cfitsiolib=', None, 'Name of the cfitsio library'),
|
---|
[2517] | 40 | ('cfitsioincdir=', None, 'The custom cfitsio include dir'),
|
---|
[2504] | 41 | ('wcsroot=', None, 'Prefix for wcslib installation location'),
|
---|
| 42 | ('wcslib=', None, 'Name of the wcs library'),
|
---|
| 43 | ('rpfitsroot=', None, 'Prefix for rpfits installation location'),
|
---|
| 44 | ('rpfitslib=', None, 'Name of the rpfits library'),
|
---|
[2509] | 45 | ('blaslib=', None, 'Name of the blas library'),
|
---|
| 46 | ('lapacklib=', None, 'Name of the lapack library'),
|
---|
| 47 | ('f2clib=', None, 'Name of the fortran-to-c library'),
|
---|
[2504] | 48 | ('jobs=','j', 'Number of processes'),
|
---|
[2525] | 49 | ('extraflags=', None,
|
---|
| 50 | 'Extra build flags e.g. static libs, defines etc.'),
|
---|
[2504] | 51 | ('extraroot=', None,
|
---|
| 52 | 'Extra root directory where muiltple packages could be found,'
|
---|
| 53 | ' e.g. $HOME, to add $HOME/lib etc to the build.'),
|
---|
| 54 | ]
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 | def initialize_options(self):
|
---|
| 58 | """
|
---|
| 59 | Overload to enable custom settings to be picked up
|
---|
| 60 | """
|
---|
| 61 | build_ext.build_ext.initialize_options(self)
|
---|
| 62 | self._scons_options = []
|
---|
| 63 | # attribute corresponding to directory prefix
|
---|
| 64 | # command line option
|
---|
| 65 | self.jobs = None
|
---|
| 66 | self.extraroot = None
|
---|
[2525] | 67 | self.extraflags = None
|
---|
[2504] | 68 | self.casacoreroot = None
|
---|
[2515] | 69 | self.casacorestatic = None
|
---|
[2504] | 70 | self.boostroot = None
|
---|
| 71 | self.boostlib = None
|
---|
| 72 | self.cfitsioroot = None
|
---|
| 73 | self.cfitsiolib = None
|
---|
[2517] | 74 | self.cfitsioincdir = None
|
---|
[2504] | 75 | self.wcsroot = None
|
---|
| 76 | self.wcslib = None
|
---|
| 77 | self.rpfitsroot = None
|
---|
| 78 | self.rpfitslib = None
|
---|
[2509] | 79 | self.blaslib = None
|
---|
| 80 | self.lapacklib = None
|
---|
| 81 | self.f2clib = None
|
---|
[2504] | 82 |
|
---|
| 83 | def finalize_options(self):
|
---|
| 84 | build_ext.build_ext.finalize_options(self)
|
---|
| 85 | for opt in self.user_options:
|
---|
[2517] | 86 | attr = opt[0].strip("=")
|
---|
| 87 | v = getattr(self, attr)
|
---|
[2504] | 88 | if v is not None:
|
---|
| 89 | if opt[1] is None:
|
---|
[2517] | 90 | self._scons_options.append("=".join([attr, v]))
|
---|
[2504] | 91 | else:
|
---|
| 92 | self._scons_options.append(" ".join(["-"+opt[1], v]))
|
---|
| 93 |
|
---|
| 94 | def build_extensions(self):
|
---|
[2509] | 95 | ext = self.extensions[0]
|
---|
| 96 | try:
|
---|
| 97 | ext_path = self.get_ext_fullpath(ext.name)
|
---|
| 98 | extdir = os.path.dirname(ext_path)
|
---|
| 99 | except AttributeError:
|
---|
| 100 | # hack for pyhton 2.5
|
---|
| 101 | extdir = os.path.join(self.build_lib, ext.name.split(".")[0])
|
---|
[2504] | 102 | if not os.path.exists(extdir):
|
---|
| 103 | os.makedirs(extdir)
|
---|
[2509] | 104 | cmd = ['scons'] + self._scons_options
|
---|
[2517] | 105 | retcode = subprocess.call(cmd)
|
---|
| 106 | if retcode != 0:
|
---|
| 107 | raise RuntimeError('scons failed')
|
---|
[2509] | 108 | # copy extension into distutils build directory
|
---|
[2504] | 109 | if os.path.exists("build/_asap.so"):
|
---|
[2509] | 110 | shutil.copy("build/_asap.so", extdir)
|
---|