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 | EnsureSConsVersion(1,0,0)
|
---|
25 |
|
---|
26 | opts = Variables("options.cache")
|
---|
27 | opts.AddVariables(
|
---|
28 | ("extraroot", "Addition tree to look for packages", None),
|
---|
29 | ("FORTRAN", "The fortran compiler", None),
|
---|
30 | ("f2clib", "The fortran to c library", None),
|
---|
31 | PathVariable("casacoreroot", "The location of casacore",
|
---|
32 | "/usr/local"),
|
---|
33 | ("boostroot", "The root dir where boost is installed", None),
|
---|
34 | ("boostlib", "The name of the boost python library",
|
---|
35 | "boost_python"),
|
---|
36 | ("boostlibdir", "The boost library location", None),
|
---|
37 | ("boostincdir", "The boost header file location", None),
|
---|
38 | ("lapackroot",
|
---|
39 | "The root directory where lapack is installed", None),
|
---|
40 | ("lapacklibdir", "The lapack library location", None),
|
---|
41 | ("lapacklib",
|
---|
42 | "The lapack library name (e.g. for specialized AMD libraries",
|
---|
43 | "lapack"),
|
---|
44 | ("blasroot",
|
---|
45 | "The root directory where blas is installed", None),
|
---|
46 | ("blaslibdir", "The blas library location", None),
|
---|
47 | ("blaslib",
|
---|
48 | "The blas library name (e.g. for specialized AMD libraries",
|
---|
49 | "blas"),
|
---|
50 | ("cfitsioroot",
|
---|
51 | "The root directory where cfistio is installed", None),
|
---|
52 | ("cfitsiolibdir", "The cfitsio library location", None),
|
---|
53 | ("cfitsiolib", "The cfitsio library name", "cfitsio"),
|
---|
54 | ("cfitsioincdir", "The cfitsio include location", None),
|
---|
55 | ("wcslib", "The wcs library name", "wcs"),
|
---|
56 | ("wcsroot",
|
---|
57 | "The root directory where wcs is installed", None),
|
---|
58 | ("wcslibdir", "The wcs library location", None),
|
---|
59 | ("rpfitslib", "The rpfits library name", "rpfits"),
|
---|
60 | ("rpfitsroot",
|
---|
61 | "The root directory where rpfits is installed", None),
|
---|
62 | ("rpfitslibdir", "The rpfits library location", None),
|
---|
63 |
|
---|
64 | ("pyraproot", "The root directory where libpyrap is installed",
|
---|
65 | None),
|
---|
66 | ("numpyincdir", "numpy header file directory",
|
---|
67 | get_numpy_incdir()),
|
---|
68 | BoolVariable("enable_pyrap",
|
---|
69 | "Use pyrap conversion library from system",
|
---|
70 | False),
|
---|
71 | ("pyraplib", "The name of the pyrap library", "pyrap"),
|
---|
72 | ("pyraplibdir", "The directory where libpyrap is installed",
|
---|
73 | None),
|
---|
74 | ("pyrapincdir", "The pyrap include location",
|
---|
75 | None),
|
---|
76 | EnumVariable("mode", "The type of build.", "release",
|
---|
77 | ["release","debug"], ignorecase=1),
|
---|
78 | EnumVariable("makedoc",
|
---|
79 | "Build the userguide in specified format",
|
---|
80 | "none",
|
---|
81 | ["none", "pdf", "html"], ignorecase=1),
|
---|
82 | BoolVariable("apps", "Build cpp apps", True),
|
---|
83 | BoolVariable("alma", "Enable alma specific functionality",
|
---|
84 | False),
|
---|
85 | )
|
---|
86 |
|
---|
87 | env = Environment( toolpath = ['./scons'],
|
---|
88 | tools = ["default", "utils", "casa"],
|
---|
89 | ENV = { 'PATH' : os.environ[ 'PATH' ],
|
---|
90 | 'HOME' : os.environ[ 'HOME' ] },
|
---|
91 | options = opts)
|
---|
92 |
|
---|
93 | env.Help(opts.GenerateHelpText(env))
|
---|
94 | env.SConsignFile()
|
---|
95 | if not ( env.GetOption('clean') or env.GetOption('help') ):
|
---|
96 |
|
---|
97 | conf = Configure(env)
|
---|
98 | conf.env.AddCustomPackage('extra')
|
---|
99 | conf.env.AppendUnique(LIBPATH=os.path.join(conf.env["casacoreroot"],
|
---|
100 | "lib"))
|
---|
101 | conf.env.AppendUnique(CPPPATH=os.path.join(conf.env["casacoreroot"],
|
---|
102 | "include", "casacore"))
|
---|
103 | if not conf.CheckLib("casa_casa", language='c++'): Exit(1)
|
---|
104 | conf.env.PrependUnique(LIBS=["casa_images", "casa_ms", "casa_components",
|
---|
105 | "casa_coordinates", "casa_lattices",
|
---|
106 | "casa_fits", "casa_measures", "casa_scimath",
|
---|
107 | "casa_scimath_f", "casa_tables",
|
---|
108 | "casa_mirlib"])
|
---|
109 | conf.env.Append(CPPPATH=[distutils.sysconfig.get_python_inc()])
|
---|
110 | if not conf.CheckHeader("Python.h", language='c'):
|
---|
111 | Exit(1)
|
---|
112 | pylib = 'python'+distutils.sysconfig.get_python_version()
|
---|
113 | if env['PLATFORM'] == "darwin":
|
---|
114 | conf.env.Append(FRAMEWORKS=["Python"])
|
---|
115 | else:
|
---|
116 | if not conf.CheckLib(library=pylib, language='c'): Exit(1)
|
---|
117 |
|
---|
118 | conf.env.AddCustomPackage('boost')
|
---|
119 | if not conf.CheckLibWithHeader(conf.env["boostlib"],
|
---|
120 | 'boost/python.hpp', language='c++'):
|
---|
121 | Exit(1)
|
---|
122 |
|
---|
123 | if env["enable_pyrap"]:
|
---|
124 | conf.env.AddCustomPackage('pyrap')
|
---|
125 | if conf.CheckLib(conf.env["pyraplib"], language='c++', autoadd=0):
|
---|
126 | conf.env.PrependUnique(LIBS=env['pyraplib'])
|
---|
127 | else:
|
---|
128 | Exit(1)
|
---|
129 | else:
|
---|
130 | conf.env.AppendUnique(CPPPATH=[conf.env["numpyincdir"]])
|
---|
131 | # numpy 1.0 uses config.h; numpy >= 1.1 uses numpyconfig.h
|
---|
132 | if conf.CheckHeader("numpy/numpyconfig.h"):
|
---|
133 | conf.env.Append(CPPDEFINES=["-DAIPS_USENUMPY"])
|
---|
134 | else:
|
---|
135 | conf.env.Exit(1)
|
---|
136 | # compile in pyrap from here...
|
---|
137 | conf.env["pyrapint"] = "#/external/libpyrap/pyrap-0.3.2"
|
---|
138 | conf.env.Append(CPPFLAGS=['-DHAVE_LIBPYRAP'])
|
---|
139 |
|
---|
140 | # test for cfitsio
|
---|
141 | if not conf.CheckLib("m"): Exit(1)
|
---|
142 | conf.env.AddCustomPackage('cfitsio')
|
---|
143 | if not conf.CheckLibWithHeader(conf.env["cfitsiolib"],
|
---|
144 | 'fitsio.h', language='c'):
|
---|
145 | Exit(1)
|
---|
146 | conf.env.AddCustomPackage('wcs')
|
---|
147 | if not conf.CheckLibWithHeader(conf.env["wcslib"],
|
---|
148 | 'wcslib/wcs.h', language='c'):
|
---|
149 | Exit(1)
|
---|
150 | conf.env.AddCustomPackage('rpfits')
|
---|
151 | if not conf.CheckLib(conf.env["rpfitslib"], language="c"):
|
---|
152 | Exit(1)
|
---|
153 |
|
---|
154 | # test for blas/lapack
|
---|
155 | lapackname = conf.env.get("lapacklib", "lapack")
|
---|
156 | conf.env.AddCustomPackage("lapack")
|
---|
157 | if not conf.CheckLib(lapackname): Exit(1)
|
---|
158 | blasname = conf.env.get("blaslib", "blas")
|
---|
159 | conf.env.AddCustomPackage("blas")
|
---|
160 | if not conf.CheckLib(blasname): Exit(1)
|
---|
161 | conf.env.CheckFortran(conf)
|
---|
162 | if not conf.CheckLib('stdc++', language='c++'): Exit(1)
|
---|
163 | if conf.env["alma"]:
|
---|
164 | conf.env.Append(CPPFLAGS=['-DUSE_CASAPY'])
|
---|
165 | env = conf.Finish()
|
---|
166 |
|
---|
167 | opts.Save('options.cache', env)
|
---|
168 |
|
---|
169 | env["version"] = "4.1.x"
|
---|
170 |
|
---|
171 | if env['mode'] == 'release':
|
---|
172 | if env["PLATFORM"] != "darwin":
|
---|
173 | env.Append(LINKFLAGS=['-Wl,-O1', '-s'])
|
---|
174 | env.Append(CCFLAGS=["-O2"])
|
---|
175 | else:
|
---|
176 | env.Append(CCFLAGS=["-g", "-W", "-Wall"])
|
---|
177 |
|
---|
178 | # Export for SConscript files
|
---|
179 | Export("env")
|
---|
180 |
|
---|
181 | # build externals
|
---|
182 | ext = env.SConscript("external-alma/SConscript")
|
---|
183 |
|
---|
184 | # build library
|
---|
185 | so = env.SConscript("src/SConscript", variant_dir="build", duplicate=0)
|
---|
186 |
|
---|
187 | apps = env.SConscript("apps/SConscript")
|
---|
188 |
|
---|
189 | # test module import, to see if there are unresolved symbols
|
---|
190 | def test_module(target,source,env):
|
---|
191 | pth = str(target[0])
|
---|
192 | mod = os.path.splitext(pth)[0]
|
---|
193 | sys.path.insert(2, os.path.split(mod)[0])
|
---|
194 | __import__(os.path.split(mod)[1])
|
---|
195 | print "ok"
|
---|
196 | return 0
|
---|
197 |
|
---|
198 | def test_str(target, source, env):
|
---|
199 | return "Testing module..."
|
---|
200 |
|
---|
201 | taction = Action(test_module, test_str)
|
---|
202 | env.AddPostAction(so, taction)
|
---|
203 |
|
---|
204 | if env.GetOption("clean"):
|
---|
205 | Execute(Delete(".sconf_temp"))
|
---|
206 | Execute(Delete("options.cache"))
|
---|
207 |
|
---|
208 | if env["makedoc"].lower() != "none":
|
---|
209 | env.SConscript("doc/SConscript")
|
---|