source: branches/casa-prerelease/pre-asap/SConstruct@ 2141

Last change on this file since 2141 was 2140, checked in by Takeshi Nakazato, 14 years ago

merge bug fix on trunk (r2139).

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