source: trunk/scons_ext.py@ 2518

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

More updates to get a distutils/scons build going

File size: 3.2 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 ('casacorestatic=', None,
14 'use static casacore libraries'),
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'),
21 ('cfitsioincdir=', None, 'The custom cfitsio include dir'),
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'),
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'),
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
47 self.casacorestatic = None
48 self.boostroot = None
49 self.boostlib = None
50 self.cfitsioroot = None
51 self.cfitsiolib = None
52 self.cfitsioincdir = None
53 self.wcsroot = None
54 self.wcslib = None
55 self.rpfitsroot = None
56 self.rpfitslib = None
57 self.blaslib = None
58 self.lapacklib = None
59 self.f2clib = None
60
61 def finalize_options(self):
62 build_ext.build_ext.finalize_options(self)
63 for opt in self.user_options:
64 attr = opt[0].strip("=")
65 v = getattr(self, attr)
66 if v is not None:
67 if opt[1] is None:
68 self._scons_options.append("=".join([attr, v]))
69 else:
70 self._scons_options.append(" ".join(["-"+opt[1], v]))
71
72 def build_extensions(self):
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])
80 if not os.path.exists(extdir):
81 os.makedirs(extdir)
82 cmd = ['scons'] + self._scons_options
83 retcode = subprocess.call(cmd)
84 if retcode != 0:
85 raise RuntimeError('scons failed')
86 # copy extension into distutils build directory
87 if os.path.exists("build/_asap.so"):
88 shutil.copy("build/_asap.so", extdir)
Note: See TracBrowser for help on using the repository browser.