source: trunk/SConstruct@ 1882

Last change on this file since 1882 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
RevLine 
[1125]1import os
2import sys
[1082]3import distutils.sysconfig
4import platform
[1184]5import SCons
[1082]6
[1873]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
[1125]24moduledir = distutils.sysconfig.get_python_lib()
[1740]25
26if sys.platform.startswith('linux') and platform.architecture()[0] == '64bit':
[1136]27 # hack to install into /usr/lib64 if scons is in the 32bit /usr/lib/
28 if moduledir.startswith("/usr/lib/"):
[1155]29 moduledir = moduledir.replace("lib", "lib64")
[1082]30
[1464]31EnsureSConsVersion(1,1,0)
32
33opts = Variables("options.cfg")
34opts.AddVariables(
[1325]35 ("FORTRAN", "The fortran compiler", None),
36 ("f2clib", "The fortran to c library", None),
[1464]37 PathVariable("prefix",
[1325]38 "The root installation path",
[1130]39 distutils.sysconfig.PREFIX),
[1464]40 PathVariable("moduledir",
[1120]41 "The python module path (site-packages))",
42 moduledir),
[1464]43 PathVariable("casacoreroot", "The location of casacore",
[1740]44 "/usr/local"),
[1325]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",
[1327]55 "lapack"),
[1325]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",
[1327]61 "blas"),
[1325]62 ("cfitsioroot",
63 "The root directory where cfistio is installed", None),
64 ("cfitsiolibdir", "The cfitsio library location", None),
[1327]65 ("cfitsiolib", "The cfitsio library name", "cfitsio"),
[1325]66 ("cfitsioincdir", "The cfitsio include location", None),
[1740]67 ("wcslib", "The wcs library name", "wcs"),
[1325]68 ("wcsroot",
69 "The root directory where wcs is installed", None),
70 ("wcslibdir", "The wcs library location", None),
[1354]71 ("rpfitslib", "The rpfits library name", "rpfits"),
[1325]72 ("rpfitsroot",
73 "The root directory where rpfits is installed", None),
74 ("rpfitslibdir", "The rpfits library location", None),
[1501]75 ("pyraproot", "The root directory where libpyrap is installed",
76 None),
[1873]77 ("numpyincdir", "numpy header file directory",
78 get_numpy_incdir()),
[1501]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",
[1687]85 False),
[1501]86
[1464]87 EnumVariable("mode", "The type of build.", "release",
[1135]88 ["release","debug"], ignorecase=1),
[1177]89 ("makedist",
[1195]90 "Make a binary archive giving a suffix, e.g. sarge or fc5",
[1259]91 ""),
[1464]92 EnumVariable("makedoc", "Build the userguide in specified format",
[1259]93 "none",
[1406]94 ["none", "pdf", "html"], ignorecase=1),
[1740]95 BoolVariable("apps", "Build cpp apps", True),
[1501]96 BoolVariable("alma", "Enable alma specific functionality",
97 False),
[1130]98 )
[1082]99
[1135]100env = Environment( toolpath = ['./scons'],
[1325]101 tools = ["default", "archiver", "utils",
[1184]102 "quietinstall"],
[1135]103 ENV = { 'PATH' : os.environ[ 'PATH' ],
[1120]104 'HOME' : os.environ[ 'HOME' ] },
[1135]105 options = opts)
[1082]106
[1120]107Help(opts.GenerateHelpText(env))
108env.SConsignFile()
[1325]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
[1406]117env.Tool('casaoptions', [casacoretooldir])
118opts.Update(env)
[1325]119env.Tool('casa', [casacoretooldir])
120
[1082]121if not env.GetOption('clean'):
[1130]122 conf = Configure(env)
[1326]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)
[1443]129 conf.env.PrependUnique(LIBS=["casa_images", "casa_ms", "casa_components",
[1354]130 "casa_coordinates", "casa_lattices",
131 "casa_fits", "casa_measures", "casa_scimath",
132 "casa_scimath_f", "casa_tables",
133 "casa_mirlib"])
[1130]134 conf.env.Append(CPPPATH=[distutils.sysconfig.get_python_inc()])
135 if not conf.CheckHeader("Python.h", language='c'):
136 Exit(1)
[1325]137 pylib = 'python'+distutils.sysconfig.get_python_version()
138 if env['PLATFORM'] == "darwin":
139 conf.env.Append(FRAMEWORKS=["Python"])
[1130]140 else:
[1325]141 if not conf.CheckLib(library=pylib, language='c'): Exit(1)
142
143 conf.env.AddCustomPackage('boost')
[1501]144 if not conf.CheckLibWithHeader(conf.env["boostlib"],
[1325]145 'boost/python.hpp', language='c++'):
146 Exit(1)
[1501]147
148 conf.env.AddCustomPackage('pyrap')
[1873]149 if conf.CheckLib(conf.env["pyraplib"], language='c++', autoadd=0):
[1501]150 conf.env.Append(CPPFLAGS=['-DHAVE_PYRAP'])
151 conf.env.PrependUnique(LIBS=env['pyraplib'])
[1873]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"
[1325]162 # test for cfitsio
163 if not conf.CheckLib("m"): Exit(1)
164 conf.env.AddCustomPackage('cfitsio')
[1327]165 if not conf.CheckLibWithHeader(conf.env["cfitsiolib"],
166 'fitsio.h', language='c'):
[1325]167 Exit(1)
168 conf.env.AddCustomPackage('wcs')
[1740]169 if not conf.CheckLibWithHeader(conf.env["wcslib"],
170 'wcslib/wcs.h', language='c'):
[1325]171 Exit(1)
172 conf.env.AddCustomPackage('rpfits')
[1354]173 if not conf.CheckLib(conf.env["rpfitslib"], language="c"):
174 Exit(1)
[1325]175
176 # test for blas/lapack
[1740]177 lapackname = conf.env.get("lapacklib", "lapack")
[1331]178 conf.env.AddCustomPackage("lapack")
[1740]179 if not conf.CheckLib(lapackname): Exit(1)
[1325]180 blasname = conf.env.get("blaslib", "blas")
181 conf.env.AddCustomPackage("blas")
[1740]182 if not conf.CheckLib(blasname): Exit(1)
[1325]183 conf.env.CheckFortran(conf)
[1130]184 if not conf.CheckLib('stdc++', language='c++'): Exit(1)
[1433]185 if conf.env["alma"]:
186 conf.env.Append(CPPFLAGS=['-DUSE_ALMA'])
[1082]187 env = conf.Finish()
[1120]188
[1819]189env["version"] = "3.0.0"
[1135]190
[1120]191if env['mode'] == 'release':
[1335]192 if env["PLATFORM"] != "darwin":
193 env.Append(LINKFLAGS=['-Wl,-O1', '-s'])
194 env.Append(CCFLAGS=["-O2"])
195else:
[1396]196 env.Append(CCFLAGS=["-g", "-Wall"])
[1184]197
198# Export for SConscript files
[1135]199Export("env")
[1082]200
[1325]201# build externals
[1819]202env.SConscript("external-alma/SConscript")
[1184]203# build library
[1082]204so = env.SConscript("src/SConscript", build_dir="build", duplicate=0)
[1195]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..."
[1184]215
[1195]216taction = Action(test_module, test_str)
217env.AddPostAction(so, taction)
218
[1184]219# install targets
[1740]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)
[1184]228
229# install aips++ data repos
[1740]230rootdir = None
[1184]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"):
[1195]236 rootdir = "./data"
[1184]237if rootdir is not None:
238 ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources)
239 data = env.InstallAs(ofiles, ifiles)
240 env.Alias('install', data)
[1202]241
[1177]242# make binary distribution
243if len(env["makedist"]):
[1184]244 env["stagedir"] = "asap-%s-%s" % (env["version"], env["makedist"])
245 env.Command('Staging distribution for archive in %s' % env["stagedir"],
246 '', env.MessageAction)
[1195]247 st0 = env.QInstall("$stagedir/asap", [so, env.SGlob("python/*.py")] )
[1184]248 env.QInstall("$stagedir/bin", ["bin/asap", "bin/asap_update_data"])
[1195]249 env.QInstall("$stagedir", ["bin/install"])
250 env.QInstall("$stagedir/asap/data", "share/ipythonrc-asap")
[1511]251 env.QInstall("$stagedir/asap/data", "share/ipy_user_conf.py")
[1195]252 if rootdir is not None:
[1202]253 # This creates a directory Using data table... - disabled
254 #env.Command("Using data tables in %s" % rootdir,
255 # '', env.MessageAction)
[1184]256 outdir = os.path.join(env["stagedir"],'asap','data')
257 ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources)
258 env.QInstallAs(ofiles, ifiles)
[1195]259 else:
260 env.Command("No data tables available. Use 'asap_update_data' after install",
[1202]261 '', env.MessageAction)
[1184]262 arch = env.Archiver(os.path.join("dist",env["stagedir"]),
263 env["stagedir"])
264 env.AddPostAction(arch, Delete("$stagedir"))
[1259]265if env["makedoc"].lower() != "none":
266 env.SConscript("doc/SConscript")
[1195]267
[1406]268if env["apps"]:
269 env.SConscript("apps/SConscript")
270
[1195]271if env.GetOption("clean"):
272 Execute(Delete(".sconf_temp"))
Note: See TracBrowser for help on using the repository browser.