source: trunk/SConstruct@ 1894

Last change on this file since 1894 was 1873, checked in by Malte Marquarding, 14 years ago

Move to compile in pyrap out of external if it isn't found in the system

File size: 10.3 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_PYRAP'])
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 # compile in pyrap here...
161 conf.env["pyrapint"] = "#/external/libpyrap/pyrap-0.3.2"
162 # test for cfitsio
163 if not conf.CheckLib("m"): Exit(1)
164 conf.env.AddCustomPackage('cfitsio')
165 if not conf.CheckLibWithHeader(conf.env["cfitsiolib"],
166 'fitsio.h', language='c'):
167 Exit(1)
168 conf.env.AddCustomPackage('wcs')
169 if not conf.CheckLibWithHeader(conf.env["wcslib"],
170 'wcslib/wcs.h', language='c'):
171 Exit(1)
172 conf.env.AddCustomPackage('rpfits')
173 if not conf.CheckLib(conf.env["rpfitslib"], language="c"):
174 Exit(1)
175
176 # test for blas/lapack
177 lapackname = conf.env.get("lapacklib", "lapack")
178 conf.env.AddCustomPackage("lapack")
179 if not conf.CheckLib(lapackname): Exit(1)
180 blasname = conf.env.get("blaslib", "blas")
181 conf.env.AddCustomPackage("blas")
182 if not conf.CheckLib(blasname): Exit(1)
183 conf.env.CheckFortran(conf)
184 if not conf.CheckLib('stdc++', language='c++'): Exit(1)
185 if conf.env["alma"]:
186 conf.env.Append(CPPFLAGS=['-DUSE_ALMA'])
187 env = conf.Finish()
188
189env["version"] = "3.0.0"
190
191if env['mode'] == 'release':
192 if env["PLATFORM"] != "darwin":
193 env.Append(LINKFLAGS=['-Wl,-O1', '-s'])
194 env.Append(CCFLAGS=["-O2"])
195else:
196 env.Append(CCFLAGS=["-g", "-Wall"])
197
198# Export for SConscript files
199Export("env")
200
201# build externals
202env.SConscript("external-alma/SConscript")
203# build library
204so = env.SConscript("src/SConscript", build_dir="build", duplicate=0)
205# test module import, to see if there are unresolved symbols
206def test_module(target,source,env):
207 pth = str(target[0])
208 mod = os.path.splitext(pth)[0]
209 sys.path.insert(2, os.path.split(mod)[0])
210 __import__(os.path.split(mod)[1])
211 print "ok"
212 return 0
213def test_str(target, source, env):
214 return "Testing module..."
215
216taction = Action(test_module, test_str)
217env.AddPostAction(so, taction)
218
219# install targets
220installs = []
221installs.append(env.Install("$moduledir/asap", so))
222installs.append(env.Install("$moduledir/asap", env.SGlob("python/*.py")))
223installs.append(env.Install("$prefix/bin",
224 ["bin/asap", "bin/asap_update_data"]))
225installs.append(env.Install("$moduledir/asap/data", "share/ipythonrc-asap"))
226installs.append(env.Install("$moduledir/asap/data", "share/ipy_user_conf.py"))
227env.Alias('install', installs)
228
229# install aips++ data repos
230rootdir = None
231outdir = os.path.join(env["moduledir"],'asap','data')
232sources = ['ephemerides','geodetic']
233if os.path.exists("/nfs/aips++/data"):
234 rootdir = "/nfs/aips++/data"
235elif os.path.exists("data"):
236 rootdir = "./data"
237if rootdir is not None:
238 ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources)
239 data = env.InstallAs(ofiles, ifiles)
240 env.Alias('install', data)
241
242# make binary distribution
243if len(env["makedist"]):
244 env["stagedir"] = "asap-%s-%s" % (env["version"], env["makedist"])
245 env.Command('Staging distribution for archive in %s' % env["stagedir"],
246 '', env.MessageAction)
247 st0 = env.QInstall("$stagedir/asap", [so, env.SGlob("python/*.py")] )
248 env.QInstall("$stagedir/bin", ["bin/asap", "bin/asap_update_data"])
249 env.QInstall("$stagedir", ["bin/install"])
250 env.QInstall("$stagedir/asap/data", "share/ipythonrc-asap")
251 env.QInstall("$stagedir/asap/data", "share/ipy_user_conf.py")
252 if rootdir is not None:
253 # This creates a directory Using data table... - disabled
254 #env.Command("Using data tables in %s" % rootdir,
255 # '', env.MessageAction)
256 outdir = os.path.join(env["stagedir"],'asap','data')
257 ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources)
258 env.QInstallAs(ofiles, ifiles)
259 else:
260 env.Command("No data tables available. Use 'asap_update_data' after install",
261 '', env.MessageAction)
262 arch = env.Archiver(os.path.join("dist",env["stagedir"]),
263 env["stagedir"])
264 env.AddPostAction(arch, Delete("$stagedir"))
265if env["makedoc"].lower() != "none":
266 env.SConscript("doc/SConscript")
267
268if env["apps"]:
269 env.SConscript("apps/SConscript")
270
271if env.GetOption("clean"):
272 Execute(Delete(".sconf_temp"))
Note: See TracBrowser for help on using the repository browser.