source: trunk/distutils/scons_ext.py @ 2509

Last change on this file since 2509 was 2509, checked in by Malte Marquarding, 12 years ago

Fix python2.5 build and add extra options from scons

File size: 2.9 KB
Line 
1import os, sys, platform
2import subprocess
3import shutil
4from distutils.command import build_ext
5
6class 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'),
13             ('boostroot=', None,
14              'Prefix for boost_python installation location'),
15             ('boostlib=', None, 'Name of the boost_python library'),
16             ('cfitsioroot=', None,
17              'Prefix for cfitsio installation location'),
18             ('cfitsiolib=', None, 'Name of the cfitsio library'),
19             ('wcsroot=', None, 'Prefix for wcslib installation location'),
20             ('wcslib=', None, 'Name of the wcs library'),
21             ('rpfitsroot=', None, 'Prefix for rpfits installation location'),
22             ('rpfitslib=', None, 'Name of the rpfits library'),
23             ('blaslib=', None, 'Name of the blas library'),
24             ('lapacklib=', None, 'Name of the lapack library'),
25             ('f2clib=', None, 'Name of the fortran-to-c library'),
26             ('jobs=','j', 'Number of processes'),
27             ('extraroot=', None,
28              'Extra root directory where muiltple packages could be found,'
29              ' e.g. $HOME, to add $HOME/lib etc to the build.'),
30             ]
31
32
33    def initialize_options(self):
34        """
35        Overload to enable custom settings to be picked up
36        """
37        build_ext.build_ext.initialize_options(self)
38        self._scons_options = []
39        # attribute corresponding to directory prefix
40        # command line option
41        self.jobs = None
42        self.extraroot = None
43        self.casacoreroot = None
44        self.boostroot = None
45        self.boostlib = None
46        self.cfitsioroot = None
47        self.cfitsiolib = None
48        self.wcsroot = None
49        self.wcslib = None
50        self.rpfitsroot = None
51        self.rpfitslib = None
52        self.blaslib = None
53        self.lapacklib = None
54        self.f2clib = None
55
56    def finalize_options(self):
57        build_ext.build_ext.finalize_options(self)
58        for opt in self.user_options:
59            atr = opt[0].strip("=")
60            v = getattr(self, atr)
61            if v is not None:
62                if opt[1] is None:
63                    self._scons_options.append("=".join([atr, v]))
64                else:
65                    self._scons_options.append(" ".join(["-"+opt[1], v]))
66
67    def build_extensions(self):
68        ext = self.extensions[0]       
69        try:
70            ext_path = self.get_ext_fullpath(ext.name)
71            extdir = os.path.dirname(ext_path)
72        except AttributeError:
73            # hack for pyhton 2.5
74            extdir = os.path.join(self.build_lib, ext.name.split(".")[0])
75        if not os.path.exists(extdir):
76            os.makedirs(extdir)
77        cmd = ['scons'] + self._scons_options
78        subprocess.call(cmd)
79        # copy extension into distutils build directory
80        if os.path.exists("build/_asap.so"):
81            shutil.copy("build/_asap.so", extdir)
Note: See TracBrowser for help on using the repository browser.