1 | import os
|
---|
2 | import sys
|
---|
3 | import distutils.sysconfig
|
---|
4 | import platform
|
---|
5 | import SCons
|
---|
6 |
|
---|
7 | # try to autodetect numpy
|
---|
8 | def get_numpy_incdir():
|
---|
9 | try:
|
---|
10 | # try to find an egg
|
---|
11 | from pkg_resources import require
|
---|
12 | tmp = require("numpy")
|
---|
13 | import numpy
|
---|
14 | return numpy.__path__[0]+"/core/include"
|
---|
15 | except Exception:
|
---|
16 | # now try standard package
|
---|
17 | try:
|
---|
18 | import numpy
|
---|
19 | return numpy.__path__[0]+"/core/include"
|
---|
20 | except ImportError:
|
---|
21 | pass
|
---|
22 | return ""
|
---|
23 |
|
---|
24 | def get_libdir():
|
---|
25 | return os.path.basename(distutils.sysconfig.get_config_var('LIBDIR'))
|
---|
26 |
|
---|
27 | LIBDIR = 'lib' #get_libdir()
|
---|
28 |
|
---|
29 | EnsureSConsVersion(1,0,0)
|
---|
30 |
|
---|
31 | opts = Variables("options.cache")
|
---|
32 | opts.AddVariables(
|
---|
33 | ("extraroot", "Addition tree to look for packages", None),
|
---|
34 | ("FORTRAN", "The fortran compiler", None),
|
---|
35 | ("f2clib", "The fortran to c library", None),
|
---|
36 | PathVariable("casacoreroot", "The location of casacore",
|
---|
37 | "/usr/local"),
|
---|
38 | BoolVariable("casacorestatic",
|
---|
39 | "Link statically against casacore",
|
---|
40 | False),
|
---|
41 | ("boostroot", "The root dir where boost is installed", None),
|
---|
42 | ("boostlib", "The name of the boost python library",
|
---|
43 | "boost_python"),
|
---|
44 | ("boostlibdir", "The boost library location", None),
|
---|
45 | ("boostincdir", "The boost header file location", None),
|
---|
46 | ("lapackroot",
|
---|
47 | "The root directory where lapack is installed", None),
|
---|
48 | ("lapacklibdir", "The lapack library location", None),
|
---|
49 | ("lapacklib",
|
---|
50 | "The lapack library name (e.g. for specialized AMD libraries",
|
---|
51 | "lapack"),
|
---|
52 | ("blasroot",
|
---|
53 | "The root directory where blas is installed", None),
|
---|
54 | ("blaslibdir", "The blas library location", None),
|
---|
55 | ("blaslib",
|
---|
56 | "The blas library name (e.g. for specialized AMD libraries",
|
---|
57 | "blas"),
|
---|
58 | ("cfitsioroot",
|
---|
59 | "The root directory where cfistio is installed", None),
|
---|
60 | ("cfitsiolibdir", "The cfitsio library location", None),
|
---|
61 | ("cfitsiolib", "The cfitsio library name", "cfitsio"),
|
---|
62 | ("cfitsioincdir", "The cfitsio include location", None),
|
---|
63 | ("wcslib", "The wcs library name", "wcs"),
|
---|
64 | ("wcsroot",
|
---|
65 | "The root directory where wcs is installed", None),
|
---|
66 | ("wcslibdir", "The wcs library location", None),
|
---|
67 | ("rpfitslib", "The rpfits library name", "rpfits"),
|
---|
68 | ("rpfitsroot",
|
---|
69 | "The root directory where rpfits is installed", None),
|
---|
70 | ("rpfitslibdir", "The rpfits library location", None),
|
---|
71 |
|
---|
72 | ("pyraproot", "The root directory where libpyrap is installed",
|
---|
73 | None),
|
---|
74 | ("numpyincdir", "numpy header file directory",
|
---|
75 | get_numpy_incdir()),
|
---|
76 | BoolVariable("enable_pyrap",
|
---|
77 | "Use pyrap conversion library from system",
|
---|
78 | False),
|
---|
79 | ("pyraplib", "The name of the pyrap library", "pyrap"),
|
---|
80 | ("pyraplibdir", "The directory where libpyrap is installed",
|
---|
81 | None),
|
---|
82 | ("pyrapincdir", "The pyrap include location",
|
---|
83 | None),
|
---|
84 | EnumVariable("mode", "The type of build.", "release",
|
---|
85 | ["release","debug"], ignorecase=1),
|
---|
86 | EnumVariable("makedoc",
|
---|
87 | "Build the userguide in specified format",
|
---|
88 | "none",
|
---|
89 | ["none", "pdf", "html"], ignorecase=1),
|
---|
90 | BoolVariable("apps", "Build cpp apps", True),
|
---|
91 | BoolVariable("alma", "Enable alma specific functionality",
|
---|
92 | False),
|
---|
93 | )
|
---|
94 |
|
---|
95 | env = Environment( toolpath = ['./scons'],
|
---|
96 | tools = ["default", "utils", "casa"],
|
---|
97 | ENV = { 'PATH' : os.environ[ 'PATH' ],
|
---|
98 | 'HOME' : os.environ[ 'HOME' ] },
|
---|
99 | options = opts)
|
---|
100 |
|
---|
101 | env.Help(opts.GenerateHelpText(env))
|
---|
102 | env.SConsignFile()
|
---|
103 | if not ( env.GetOption('clean') or env.GetOption('help') ):
|
---|
104 |
|
---|
105 | conf = Configure(env)
|
---|
106 | if conf.env.get("extraroot", None):
|
---|
107 | conf.env.AddCustomPackage('extra')
|
---|
108 | conf.env.Append(CPPPATH=[distutils.sysconfig.get_python_inc()])
|
---|
109 | if not conf.CheckHeader("Python.h", language='c'):
|
---|
110 | Exit(1)
|
---|
111 | pylib = 'python'+distutils.sysconfig.get_python_version()
|
---|
112 | if env['PLATFORM'] == "darwin":
|
---|
113 | conf.env.Append(FRAMEWORKS=["Python"])
|
---|
114 | else:
|
---|
115 | if not conf.CheckLib(library=pylib, language='c'): Exit(1)
|
---|
116 |
|
---|
117 | conf.env.AddCustomPackage('boost')
|
---|
118 | libname = conf.env["boostlib"]
|
---|
119 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
120 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
121 | else:
|
---|
122 | if not conf.CheckLibWithHeader(libname,
|
---|
123 | 'boost/python.hpp', language='c++'):
|
---|
124 | Exit(1)
|
---|
125 |
|
---|
126 | if env["enable_pyrap"]:
|
---|
127 | conf.env.AddCustomPackage('pyrap')
|
---|
128 | if conf.CheckLib(conf.env["pyraplib"], language='c++', autoadd=0):
|
---|
129 | conf.env.PrependUnique(LIBS=env['pyraplib'])
|
---|
130 | else:
|
---|
131 | Exit(1)
|
---|
132 | else:
|
---|
133 | conf.env.AppendUnique(CPPPATH=[conf.env["numpyincdir"]])
|
---|
134 | if conf.CheckHeader("numpy/numpyconfig.h"):
|
---|
135 | conf.env.Append(CPPDEFINES=["-DAIPS_USENUMPY"])
|
---|
136 | else:
|
---|
137 | conf.env.Exit(1)
|
---|
138 | # compile in pyrap from here...
|
---|
139 | conf.env["pyrapint"] = "#/external/libpyrap/pyrap-0.3.2"
|
---|
140 | conf.env.Append(CPPFLAGS=['-DHAVE_LIBPYRAP'])
|
---|
141 |
|
---|
142 | if not conf.CheckLib("m"):
|
---|
143 | Exit(1)
|
---|
144 | # test for cfitsio
|
---|
145 | conf.env.AddCustomPackage('cfitsio')
|
---|
146 | libname = conf.env["cfitsiolib"]
|
---|
147 | if not conf.CheckHeader("fitsio.h"):
|
---|
148 | #SuSE is being special
|
---|
149 | conf.env.AppendUnique(CPPPATH=['/usr/include/libcfitsio0'])
|
---|
150 | if not conf.CheckHeader("fitsio.h"):
|
---|
151 | Exit(1)
|
---|
152 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
153 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
154 | else:
|
---|
155 | if not conf.CheckLib(libname, language='c'):
|
---|
156 | Exit(1)
|
---|
157 | conf.env.AddCustomPackage('wcs')
|
---|
158 | libname = conf.env["wcslib"]
|
---|
159 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
160 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
161 | else:
|
---|
162 | if not conf.CheckLibWithHeader(libname,
|
---|
163 | 'wcslib/wcs.h', language='c'):
|
---|
164 | Exit(1)
|
---|
165 |
|
---|
166 | conf.env.AddCustomPackage('rpfits')
|
---|
167 | if not conf.CheckLibWithHeader(conf.env["rpfitslib"], "RPFITS.h",
|
---|
168 | language="c"):
|
---|
169 | Exit(1)
|
---|
170 |
|
---|
171 | libpath = ""
|
---|
172 | for p in [conf.env["casacoreroot"], conf.env.get("extraroot", "")]:
|
---|
173 | pth = os.path.join(p, "include", "casacore")
|
---|
174 | if os.path.exists(pth):
|
---|
175 | libpth = os.path.join(p, LIBDIR)
|
---|
176 | conf.env.AppendUnique(CPPPATH=[pth])
|
---|
177 | break
|
---|
178 | cclibs = ["casa_images", "casa_ms", "casa_components",
|
---|
179 | "casa_coordinates", "casa_lattices",
|
---|
180 | "casa_fits", "casa_measures", "casa_scimath",
|
---|
181 | "casa_scimath_f", "casa_tables", "casa_casa"]
|
---|
182 | if conf.env["casacorestatic"]:
|
---|
183 | libs = [ env.File(os.path.join(libpth, "lib"+lib+".a")) \
|
---|
184 | for lib in cclibs ]
|
---|
185 | else:
|
---|
186 | conf.env.AppendUnique(LIBPATH=libpth)
|
---|
187 | if not conf.CheckLibWithHeader("casa_casa", "casa/aips.h",
|
---|
188 | language='c++', autoadd=0):
|
---|
189 | Exit(1)
|
---|
190 | libs = cclibs
|
---|
191 | conf.env.PrependUnique(LIBS=libs)
|
---|
192 |
|
---|
193 | # test for blas/lapack
|
---|
194 | conf.env.AddCustomPackage("lapack")
|
---|
195 | libname = conf.env.get("lapacklib", "lapack")
|
---|
196 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
197 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
198 | else:
|
---|
199 | if not conf.CheckLib(libname): Exit(1)
|
---|
200 | libname = conf.env.get("blaslib", "blas")
|
---|
201 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
202 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
203 | else:
|
---|
204 | if not conf.CheckLib(libname): Exit(1)
|
---|
205 |
|
---|
206 | libname = conf.env.get("f2clib", "gfortran")
|
---|
207 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
208 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
209 | else:
|
---|
210 | conf.env.CheckFortran(conf)
|
---|
211 | if not conf.CheckLib('stdc++', language='c++'): Exit(1)
|
---|
212 | if conf.env["alma"]:
|
---|
213 | conf.env.Append(CPPFLAGS=['-DUSE_CASAPY'])
|
---|
214 | env = conf.Finish()
|
---|
215 |
|
---|
216 | opts.Save('options.cache', env)
|
---|
217 |
|
---|
218 | env["version"] = "4.1.x"
|
---|
219 |
|
---|
220 | if env['mode'] == 'release':
|
---|
221 | if env["PLATFORM"] != "darwin":
|
---|
222 | env.Append(LINKFLAGS=['-Wl,-O1', '-s'])
|
---|
223 | env.Append(CCFLAGS=["-O2"])
|
---|
224 | else:
|
---|
225 | env.Append(CCFLAGS=["-g", "-W", "-Wall"])
|
---|
226 |
|
---|
227 | # Export for SConscript files
|
---|
228 | Export("env")
|
---|
229 |
|
---|
230 | # build externals
|
---|
231 | ext = env.SConscript("external-alma/SConscript")
|
---|
232 |
|
---|
233 | # build library
|
---|
234 | so = env.SConscript("src/SConscript", variant_dir="build", duplicate=0)
|
---|
235 |
|
---|
236 | apps = env.SConscript("apps/SConscript")
|
---|
237 |
|
---|
238 | # test module import, to see if there are unresolved symbols
|
---|
239 | def test_module(target,source,env):
|
---|
240 | pth = str(target[0])
|
---|
241 | mod = os.path.splitext(pth)[0]
|
---|
242 | sys.path.insert(2, os.path.split(mod)[0])
|
---|
243 | __import__(os.path.split(mod)[1])
|
---|
244 | print "ok"
|
---|
245 | return 0
|
---|
246 |
|
---|
247 | def test_str(target, source, env):
|
---|
248 | return "Testing module..."
|
---|
249 |
|
---|
250 | taction = Action(test_module, test_str)
|
---|
251 | env.AddPostAction(so, taction)
|
---|
252 |
|
---|
253 | if env.GetOption("clean"):
|
---|
254 | Execute(Delete(".sconf_temp"))
|
---|
255 | Execute(Delete("options.cache"))
|
---|
256 |
|
---|
257 | if env["makedoc"].lower() != "none":
|
---|
258 | env.SConscript("doc/SConscript")
|
---|