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