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'),
|
---|
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 | ('jobs=','j', 'Number of processes'),
|
---|
24 | ('extraroot=', None,
|
---|
25 | 'Extra root directory where muiltple packages could be found,'
|
---|
26 | ' e.g. $HOME, to add $HOME/lib etc to the build.'),
|
---|
27 | ]
|
---|
28 |
|
---|
29 |
|
---|
30 | def initialize_options(self):
|
---|
31 | """
|
---|
32 | Overload to enable custom settings to be picked up
|
---|
33 | """
|
---|
34 | build_ext.build_ext.initialize_options(self)
|
---|
35 | self._scons_options = []
|
---|
36 | # attribute corresponding to directory prefix
|
---|
37 | # command line option
|
---|
38 | self.jobs = None
|
---|
39 | self.extraroot = None
|
---|
40 | self.casacoreroot = None
|
---|
41 | self.boostroot = None
|
---|
42 | self.boostlib = None
|
---|
43 | self.cfitsioroot = None
|
---|
44 | self.cfitsiolib = None
|
---|
45 | self.wcsroot = None
|
---|
46 | self.wcslib = None
|
---|
47 | self.rpfitsroot = None
|
---|
48 | self.rpfitslib = None
|
---|
49 |
|
---|
50 | def finalize_options(self):
|
---|
51 | build_ext.build_ext.finalize_options(self)
|
---|
52 | for opt in self.user_options:
|
---|
53 | atr = opt[0].strip("=")
|
---|
54 | v = getattr(self, atr)
|
---|
55 | if v is not None:
|
---|
56 | if opt[1] is None:
|
---|
57 | self._scons_options.append("=".join([atr, v]))
|
---|
58 | else:
|
---|
59 | self._scons_options.append(" ".join(["-"+opt[1], v]))
|
---|
60 |
|
---|
61 | def build_extensions(self):
|
---|
62 | ext = self.extensions[0]
|
---|
63 | ext_path = self.get_ext_fullpath(ext.name)
|
---|
64 | extdir = os.path.dirname(ext_path)
|
---|
65 | if not os.path.exists(extdir):
|
---|
66 | os.makedirs(extdir)
|
---|
67 | cmd = ['scons', '--quiet'] + self._scons_options
|
---|
68 | subprocess.call(cmd)
|
---|
69 | if os.path.exists("build/_asap.so"):
|
---|
70 | shutil.copy("build/_asap.so", ext_path)
|
---|