source: branches/hpc33/SConstruct@ 2527

Last change on this file since 2527 was 2321, checked in by Malte Marquarding, 13 years ago

Ticket #249: scantbable schema was changed. This required an update to scantable version 4. I have added a class STUpgrade to handle all schema upgrades. This is handled transparently in the scantable constructor

File size: 10.8 KB
Line 
1import os
2import sys
3import distutils.sysconfig
4import platform
5import SCons
6
7# try to autodetect numpy
8def 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
24def get_moduledir(prefix="/usr/local"):
25 moduledir = distutils.sysconfig.get_python_lib(1,0, prefix)
26 if sys.platform.startswith('linux') \
27 and platform.architecture()[0] == '64bit' \
28 and platform.dist()[0].lower() not in ['debian', 'ubuntu']:
29 # hack to install into /usr/lib64 if scons is in the 32bit /usr/lib/
30 if moduledir.startswith("/usr"):
31 moduledir = moduledir.replace("lib", "lib64")
32 return moduledir
33
34EnsureSConsVersion(1,0,0)
35
36opts = Variables("options.cfg")
37opts.AddVariables(
38 ("FORTRAN", "The fortran compiler", None),
39 ("f2clib", "The fortran to c library", None),
40 PathVariable("prefix",
41 "The root installation path",
42 distutils.sysconfig.PREFIX),
43 ("moduledir",
44 "The python module path (site-packages))",
45 None),
46 PathVariable("casacoreroot", "The location of casacore",
47 "/usr/local"),
48 ("boostroot", "The root dir where boost is installed", None),
49 ("boostlib", "The name of the boost python library",
50 "boost_python"),
51 ("boostlibdir", "The boost library location", None),
52 ("boostincdir", "The boost header file location", None),
53 ("lapackroot",
54 "The root directory where lapack is installed", None),
55 ("lapacklibdir", "The lapack library location", None),
56 ("lapacklib",
57 "The lapack library name (e.g. for specialized AMD libraries",
58 "lapack"),
59 ("blasroot",
60 "The root directory where blas is installed", None),
61 ("blaslibdir", "The blas library location", None),
62 ("blaslib",
63 "The blas library name (e.g. for specialized AMD libraries",
64 "blas"),
65 ("cfitsioroot",
66 "The root directory where cfistio is installed", None),
67 ("cfitsiolibdir", "The cfitsio library location", None),
68 ("cfitsiolib", "The cfitsio library name", "cfitsio"),
69 ("cfitsioincdir", "The cfitsio include location", None),
70 ("wcslib", "The wcs library name", "wcs"),
71 ("wcsroot",
72 "The root directory where wcs is installed", None),
73 ("wcslibdir", "The wcs library location", None),
74 ("rpfitslib", "The rpfits library name", "rpfits"),
75 ("rpfitsroot",
76 "The root directory where rpfits is installed", None),
77 ("rpfitslibdir", "The rpfits library location", None),
78 ("pyraproot", "The root directory where libpyrap is installed",
79 None),
80 ("numpyincdir", "numpy header file directory",
81 get_numpy_incdir()),
82 ("pyraplib", "The name of the pyrap library", "pyrap"),
83 ("pyraplibdir", "The directory where libpyrap is installed",
84 None),
85 ("pyrapincdir", "The pyrap include location",
86 None),
87 BoolVariable("enable_pyrap", "Use pyrap conversion library",
88 False),
89
90 EnumVariable("mode", "The type of build.", "release",
91 ["release","debug"], ignorecase=1),
92 ("makedist",
93 "Make a binary archive giving a suffix, e.g. sarge or fc5",
94 ""),
95 EnumVariable("makedoc", "Build the userguide in specified format",
96 "none",
97 ["none", "pdf", "html"], ignorecase=1),
98 BoolVariable("apps", "Build cpp apps", True),
99 BoolVariable("alma", "Enable alma specific functionality",
100 False),
101 )
102
103env = Environment( toolpath = ['./scons'],
104 tools = ["default", "archiver", "utils",
105 "quietinstall"],
106 ENV = { 'PATH' : os.environ[ 'PATH' ],
107 'HOME' : os.environ[ 'HOME' ] },
108 options = opts)
109
110Help(opts.GenerateHelpText(env))
111env.SConsignFile()
112
113casacoretooldir = os.path.join(env["casacoreroot"],"share",
114 "casacore")
115if not os.path.exists(casacoretooldir):
116 print "Could not find casacore scons tools"
117 Exit(1)
118
119# load casacore specific build flags
120env.Tool('casaoptions', [casacoretooldir])
121opts.Update(env)
122env.Tool('casa', [casacoretooldir])
123
124if not env.GetOption('clean'):
125 conf = Configure(env)
126
127 conf.env.AppendUnique(LIBPATH=os.path.join(conf.env["casacoreroot"],
128 "lib"))
129 conf.env.AppendUnique(CPPPATH=os.path.join(conf.env["casacoreroot"],
130 "include", "casacore"))
131 if not conf.CheckLib("casa_casa", language='c++'): Exit(1)
132 conf.env.PrependUnique(LIBS=["casa_images", "casa_ms", "casa_components",
133 "casa_coordinates", "casa_lattices",
134 "casa_fits", "casa_measures", "casa_scimath",
135 "casa_scimath_f", "casa_tables",
136 "casa_mirlib"])
137 conf.env.Append(CPPPATH=[distutils.sysconfig.get_python_inc()])
138 if not conf.CheckHeader("Python.h", language='c'):
139 Exit(1)
140 pylib = 'python'+distutils.sysconfig.get_python_version()
141 if env['PLATFORM'] == "darwin":
142 conf.env.Append(FRAMEWORKS=["Python"])
143 else:
144 if not conf.CheckLib(library=pylib, language='c'): Exit(1)
145
146 conf.env.AddCustomPackage('boost')
147 if not conf.CheckLibWithHeader(conf.env["boostlib"],
148 'boost/python.hpp', language='c++'):
149 Exit(1)
150
151 conf.env.AddCustomPackage('pyrap')
152 if conf.CheckLib(conf.env["pyraplib"], language='c++', autoadd=0):
153 conf.env.Append(CPPFLAGS=['-DHAVE_LIBPYRAP'])
154 conf.env.PrependUnique(LIBS=env['pyraplib'])
155 else:
156 conf.env.AppendUnique(CPPPATH=[conf.env["numpyincdir"]])
157 # numpy 1.0 uses config.h; numpy >= 1.1 uses numpyconfig.h
158 if conf.CheckHeader("numpy/config.h") or \
159 conf.CheckHeader("numpy/numpyconfig.h"):
160 conf.env.Append(CPPDEFINES=["-DAIPS_USENUMPY"])
161 else:
162 conf.env.Exit(1)
163 conf.env.Append(CPPFLAGS=['-DHAVE_LIBPYRAP'])
164 # compile in pyrap here...
165 conf.env["pyrapint"] = "#/external/libpyrap/pyrap-0.3.2"
166 # test for cfitsio
167 if not conf.CheckLib("m"): Exit(1)
168 conf.env.AddCustomPackage('cfitsio')
169 if not conf.CheckLibWithHeader(conf.env["cfitsiolib"],
170 'fitsio.h', language='c'):
171 Exit(1)
172 conf.env.AddCustomPackage('wcs')
173 if not conf.CheckLibWithHeader(conf.env["wcslib"],
174 'wcslib/wcs.h', language='c'):
175 Exit(1)
176 conf.env.AddCustomPackage('rpfits')
177 if not conf.CheckLib(conf.env["rpfitslib"], language="c"):
178 Exit(1)
179
180 # test for blas/lapack
181 lapackname = conf.env.get("lapacklib", "lapack")
182 conf.env.AddCustomPackage("lapack")
183 if not conf.CheckLib(lapackname): Exit(1)
184 blasname = conf.env.get("blaslib", "blas")
185 conf.env.AddCustomPackage("blas")
186 if not conf.CheckLib(blasname): Exit(1)
187 conf.env.CheckFortran(conf)
188 if not conf.CheckLib('stdc++', language='c++'): Exit(1)
189 if conf.env["alma"]:
190 conf.env.Append(CPPFLAGS=['-DUSE_ALMA'])
191 if not conf.env.get("moduledir"):
192 mdir = get_moduledir(conf.env.get("prefix"))
193 if env["PLATFORM"] == "darwin":
194 mdir = distutils.sysconfig.get_python_lib(1,0)
195 conf.env["moduledir"] = mdir
196 env = conf.Finish()
197
198env["version"] = "4.0.x"
199
200if env['mode'] == 'release':
201 if env["PLATFORM"] != "darwin":
202 env.Append(LINKFLAGS=['-Wl,-O1', '-s'])
203 env.Append(CCFLAGS=["-O2"])
204else:
205 env.Append(CCFLAGS=["-g", "-W", "-Wall"])
206
207# Export for SConscript files
208Export("env")
209
210# build externals
211env.SConscript("external-alma/SConscript")
212# build library
213so = env.SConscript("src/SConscript", variant_dir="build", duplicate=0)
214# test module import, to see if there are unresolved symbols
215def test_module(target,source,env):
216 pth = str(target[0])
217 mod = os.path.splitext(pth)[0]
218 sys.path.insert(2, os.path.split(mod)[0])
219 __import__(os.path.split(mod)[1])
220 print "ok"
221 return 0
222def test_str(target, source, env):
223 return "Testing module..."
224
225taction = Action(test_module, test_str)
226env.AddPostAction(so, taction)
227
228# install targets
229installs = []
230installs.append(env.Install("$moduledir/asap", so))
231installs.append(env.Install("$moduledir/asap", env.SGlob("python/*.py")))
232installs.append(env.Install("$prefix/bin",
233 ["bin/asap", "bin/asap_update_data"]))
234installs.append(env.Install("$moduledir/asap/data", "share/ipythonrc-asap"))
235installs.append(env.Install("$moduledir/asap/data", "share/ipy_user_conf.py"))
236env.Alias('install', installs)
237
238# install aips++ data repos
239rootdir = None
240outdir = os.path.join(env["moduledir"],'asap','data')
241sources = ['ephemerides','geodetic']
242if os.path.exists("/nfs/aips++/data"):
243 rootdir = "/nfs/aips++/data"
244elif os.path.exists("data"):
245 rootdir = "./data"
246if rootdir is not None:
247 ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources)
248 data = env.InstallAs(ofiles, ifiles)
249 env.Alias('install', data)
250
251# make binary distribution
252if len(env["makedist"]):
253 env["stagedir"] = "asap-%s" % (env["version"])
254 env.Command('Staging distribution for archive in %s' % env["stagedir"],
255 '', env.MessageAction)
256 env.QInstall("$stagedir/asap", [so, env.SGlob("python/*.py")] )
257 env.QInstall("$stagedir/bin", ["bin/asap", "bin/asap_update_data"])
258 env.QInstall("$stagedir", ["packaging/setup.py"])
259 env.QInstall("$stagedir/debian", env.SGlob("packaging/debian/*") )
260 env.QInstall("$stagedir/asap/data", "share/ipythonrc-asap")
261 env.QInstall("$stagedir/asap/data", "share/ipy_user_conf.py")
262 if rootdir is not None:
263 # This creates a directory Using data table... - disabled
264 #env.Command("Using data tables in %s" % rootdir,
265 # '', env.MessageAction)
266 outdir = os.path.join(env["stagedir"],'asap','data')
267 ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources)
268 env.QInstallAs(ofiles, ifiles)
269 else:
270 env.Command("No data tables available. Use 'asap_update_data' after install",
271 '', env.MessageAction)
272# arch = env.Archiver(os.path.join("dist",
273# env["stagedir"]+"_"+env["makedist"]),
274# env["stagedir"])
275# env.AddPostAction(arch, Delete("$stagedir"))
276
277if env["apps"]:
278 env.SConscript("apps/SConscript")
279
280if env.GetOption("clean"):
281 Execute(Delete(".sconf_temp"))
282
283if env["makedoc"].lower() != "none":
284 env.SConscript("doc/SConscript")
Note: See TracBrowser for help on using the repository browser.