[1125] | 1 | import os
|
---|
| 2 | import sys
|
---|
[1082] | 3 | import distutils.sysconfig
|
---|
| 4 | import platform
|
---|
[1184] | 5 | import SCons
|
---|
[1082] | 6 |
|
---|
[1873] | 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 |
|
---|
[2517] | 24 | def get_libdir():
|
---|
| 25 | return os.path.basename(distutils.sysconfig.get_config_var('LIBDIR'))
|
---|
| 26 |
|
---|
[2518] | 27 | LIBDIR = 'lib' #get_libdir()
|
---|
[2517] | 28 |
|
---|
[2166] | 29 | EnsureSConsVersion(1,0,0)
|
---|
[1464] | 30 |
|
---|
[2503] | 31 | opts = Variables("options.cache")
|
---|
[1464] | 32 | opts.AddVariables(
|
---|
[2505] | 33 | ("extraroot", "Addition tree to look for packages", None),
|
---|
[1325] | 34 | ("FORTRAN", "The fortran compiler", None),
|
---|
| 35 | ("f2clib", "The fortran to c library", None),
|
---|
[1464] | 36 | PathVariable("casacoreroot", "The location of casacore",
|
---|
[1740] | 37 | "/usr/local"),
|
---|
[2506] | 38 | BoolVariable("casacorestatic",
|
---|
| 39 | "Link statically against casacore",
|
---|
| 40 | False),
|
---|
[1325] | 41 | ("boostroot", "The root dir where boost is installed", None),
|
---|
| 42 | ("boostlib", "The name of the boost python library",
|
---|
| 43 | "boost_python"),
|
---|
| 44 | ("boostlibdir", "The boost library location", None),
|
---|
| 45 | ("boostincdir", "The boost header file location", None),
|
---|
| 46 | ("lapackroot",
|
---|
| 47 | "The root directory where lapack is installed", None),
|
---|
| 48 | ("lapacklibdir", "The lapack library location", None),
|
---|
| 49 | ("lapacklib",
|
---|
| 50 | "The lapack library name (e.g. for specialized AMD libraries",
|
---|
[1327] | 51 | "lapack"),
|
---|
[1325] | 52 | ("blasroot",
|
---|
| 53 | "The root directory where blas is installed", None),
|
---|
| 54 | ("blaslibdir", "The blas library location", None),
|
---|
| 55 | ("blaslib",
|
---|
| 56 | "The blas library name (e.g. for specialized AMD libraries",
|
---|
[1327] | 57 | "blas"),
|
---|
[1325] | 58 | ("cfitsioroot",
|
---|
| 59 | "The root directory where cfistio is installed", None),
|
---|
| 60 | ("cfitsiolibdir", "The cfitsio library location", None),
|
---|
[1327] | 61 | ("cfitsiolib", "The cfitsio library name", "cfitsio"),
|
---|
[1325] | 62 | ("cfitsioincdir", "The cfitsio include location", None),
|
---|
[1740] | 63 | ("wcslib", "The wcs library name", "wcs"),
|
---|
[1325] | 64 | ("wcsroot",
|
---|
| 65 | "The root directory where wcs is installed", None),
|
---|
| 66 | ("wcslibdir", "The wcs library location", None),
|
---|
[1354] | 67 | ("rpfitslib", "The rpfits library name", "rpfits"),
|
---|
[1325] | 68 | ("rpfitsroot",
|
---|
| 69 | "The root directory where rpfits is installed", None),
|
---|
| 70 | ("rpfitslibdir", "The rpfits library location", None),
|
---|
[2503] | 71 |
|
---|
[1501] | 72 | ("pyraproot", "The root directory where libpyrap is installed",
|
---|
| 73 | None),
|
---|
[1873] | 74 | ("numpyincdir", "numpy header file directory",
|
---|
| 75 | get_numpy_incdir()),
|
---|
[2503] | 76 | BoolVariable("enable_pyrap",
|
---|
| 77 | "Use pyrap conversion library from system",
|
---|
| 78 | False),
|
---|
[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),
|
---|
[1464] | 84 | EnumVariable("mode", "The type of build.", "release",
|
---|
[1135] | 85 | ["release","debug"], ignorecase=1),
|
---|
[2503] | 86 | EnumVariable("makedoc",
|
---|
| 87 | "Build the userguide in specified format",
|
---|
| 88 | "none",
|
---|
| 89 | ["none", "pdf", "html"], ignorecase=1),
|
---|
[1740] | 90 | BoolVariable("apps", "Build cpp apps", True),
|
---|
[1501] | 91 | BoolVariable("alma", "Enable alma specific functionality",
|
---|
| 92 | False),
|
---|
[1130] | 93 | )
|
---|
[1082] | 94 |
|
---|
[1135] | 95 | env = Environment( toolpath = ['./scons'],
|
---|
[2505] | 96 | tools = ["default", "utils", "casa"],
|
---|
[1135] | 97 | ENV = { 'PATH' : os.environ[ 'PATH' ],
|
---|
[1120] | 98 | 'HOME' : os.environ[ 'HOME' ] },
|
---|
[1135] | 99 | options = opts)
|
---|
[1082] | 100 |
|
---|
[2503] | 101 | env.Help(opts.GenerateHelpText(env))
|
---|
[1120] | 102 | env.SConsignFile()
|
---|
[2503] | 103 | if not ( env.GetOption('clean') or env.GetOption('help') ):
|
---|
[1325] | 104 |
|
---|
[1130] | 105 | conf = Configure(env)
|
---|
[2507] | 106 | if conf.env.get("extraroot", None):
|
---|
[2506] | 107 | conf.env.AddCustomPackage('extra')
|
---|
[1130] | 108 | conf.env.Append(CPPPATH=[distutils.sysconfig.get_python_inc()])
|
---|
| 109 | if not conf.CheckHeader("Python.h", language='c'):
|
---|
| 110 | Exit(1)
|
---|
[1325] | 111 | pylib = 'python'+distutils.sysconfig.get_python_version()
|
---|
| 112 | if env['PLATFORM'] == "darwin":
|
---|
| 113 | conf.env.Append(FRAMEWORKS=["Python"])
|
---|
[1130] | 114 | else:
|
---|
[1325] | 115 | if not conf.CheckLib(library=pylib, language='c'): Exit(1)
|
---|
| 116 |
|
---|
| 117 | conf.env.AddCustomPackage('boost')
|
---|
[2506] | 118 | libname = conf.env["boostlib"]
|
---|
| 119 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
| 120 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
| 121 | else:
|
---|
| 122 | if not conf.CheckLibWithHeader(libname,
|
---|
| 123 | 'boost/python.hpp', language='c++'):
|
---|
| 124 | Exit(1)
|
---|
[1501] | 125 |
|
---|
[2503] | 126 | if env["enable_pyrap"]:
|
---|
| 127 | conf.env.AddCustomPackage('pyrap')
|
---|
| 128 | if conf.CheckLib(conf.env["pyraplib"], language='c++', autoadd=0):
|
---|
| 129 | conf.env.PrependUnique(LIBS=env['pyraplib'])
|
---|
| 130 | else:
|
---|
| 131 | Exit(1)
|
---|
[1873] | 132 | else:
|
---|
| 133 | conf.env.AppendUnique(CPPPATH=[conf.env["numpyincdir"]])
|
---|
[2503] | 134 | if conf.CheckHeader("numpy/numpyconfig.h"):
|
---|
[1873] | 135 | conf.env.Append(CPPDEFINES=["-DAIPS_USENUMPY"])
|
---|
| 136 | else:
|
---|
| 137 | conf.env.Exit(1)
|
---|
[2503] | 138 | # compile in pyrap from here...
|
---|
[1873] | 139 | conf.env["pyrapint"] = "#/external/libpyrap/pyrap-0.3.2"
|
---|
[2503] | 140 | conf.env.Append(CPPFLAGS=['-DHAVE_LIBPYRAP'])
|
---|
| 141 |
|
---|
[2517] | 142 | if not conf.CheckLib("m"):
|
---|
| 143 | Exit(1)
|
---|
[1325] | 144 | # test for cfitsio
|
---|
| 145 | conf.env.AddCustomPackage('cfitsio')
|
---|
[2506] | 146 | libname = conf.env["cfitsiolib"]
|
---|
[2517] | 147 | if not conf.CheckHeader("fitsio.h"):
|
---|
| 148 | #SuSE is being special
|
---|
| 149 | conf.env.AppendUnique(CPPPATH=['/usr/include/libcfitsio0'])
|
---|
| 150 | if not conf.CheckHeader("fitsio.h"):
|
---|
| 151 | Exit(1)
|
---|
[2506] | 152 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
| 153 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
| 154 | else:
|
---|
[2517] | 155 | if not conf.CheckLib(libname, language='c'):
|
---|
[2506] | 156 | Exit(1)
|
---|
[1325] | 157 | conf.env.AddCustomPackage('wcs')
|
---|
[2506] | 158 | libname = conf.env["wcslib"]
|
---|
| 159 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
| 160 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
| 161 | else:
|
---|
| 162 | if not conf.CheckLibWithHeader(libname,
|
---|
| 163 | 'wcslib/wcs.h', language='c'):
|
---|
| 164 | Exit(1)
|
---|
| 165 |
|
---|
[1325] | 166 | conf.env.AddCustomPackage('rpfits')
|
---|
[2517] | 167 | if not conf.CheckLibWithHeader(conf.env["rpfitslib"], "RPFITS.h",
|
---|
| 168 | language="c"):
|
---|
[1354] | 169 | Exit(1)
|
---|
[2506] | 170 |
|
---|
| 171 | libpath = ""
|
---|
[2510] | 172 | for p in [conf.env["casacoreroot"], conf.env.get("extraroot", "")]:
|
---|
[2506] | 173 | pth = os.path.join(p, "include", "casacore")
|
---|
| 174 | if os.path.exists(pth):
|
---|
[2517] | 175 | libpth = os.path.join(p, LIBDIR)
|
---|
[2506] | 176 | conf.env.AppendUnique(CPPPATH=[pth])
|
---|
| 177 | break
|
---|
| 178 | cclibs = ["casa_images", "casa_ms", "casa_components",
|
---|
| 179 | "casa_coordinates", "casa_lattices",
|
---|
| 180 | "casa_fits", "casa_measures", "casa_scimath",
|
---|
[2517] | 181 | "casa_scimath_f", "casa_tables", "casa_casa"]
|
---|
[2506] | 182 | if conf.env["casacorestatic"]:
|
---|
| 183 | libs = [ env.File(os.path.join(libpth, "lib"+lib+".a")) \
|
---|
| 184 | for lib in cclibs ]
|
---|
| 185 | else:
|
---|
| 186 | conf.env.AppendUnique(LIBPATH=libpth)
|
---|
| 187 | if not conf.CheckLibWithHeader("casa_casa", "casa/aips.h",
|
---|
| 188 | language='c++', autoadd=0):
|
---|
| 189 | Exit(1)
|
---|
| 190 | libs = cclibs
|
---|
| 191 | conf.env.PrependUnique(LIBS=libs)
|
---|
[1325] | 192 |
|
---|
| 193 | # test for blas/lapack
|
---|
[1331] | 194 | conf.env.AddCustomPackage("lapack")
|
---|
[2506] | 195 | libname = conf.env.get("lapacklib", "lapack")
|
---|
| 196 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
| 197 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
| 198 | else:
|
---|
| 199 | if not conf.CheckLib(libname): Exit(1)
|
---|
| 200 | libname = conf.env.get("blaslib", "blas")
|
---|
| 201 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
| 202 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
| 203 | else:
|
---|
| 204 | if not conf.CheckLib(libname): Exit(1)
|
---|
| 205 |
|
---|
| 206 | libname = conf.env.get("f2clib", "gfortran")
|
---|
| 207 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
| 208 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
| 209 | else:
|
---|
| 210 | conf.env.CheckFortran(conf)
|
---|
[1130] | 211 | if not conf.CheckLib('stdc++', language='c++'): Exit(1)
|
---|
[1433] | 212 | if conf.env["alma"]:
|
---|
[2485] | 213 | conf.env.Append(CPPFLAGS=['-DUSE_CASAPY'])
|
---|
[1082] | 214 | env = conf.Finish()
|
---|
[1120] | 215 |
|
---|
[2503] | 216 | opts.Save('options.cache', env)
|
---|
| 217 |
|
---|
[2485] | 218 | env["version"] = "4.1.x"
|
---|
[1135] | 219 |
|
---|
[1120] | 220 | if env['mode'] == 'release':
|
---|
[1335] | 221 | if env["PLATFORM"] != "darwin":
|
---|
| 222 | env.Append(LINKFLAGS=['-Wl,-O1', '-s'])
|
---|
| 223 | env.Append(CCFLAGS=["-O2"])
|
---|
| 224 | else:
|
---|
[2179] | 225 | env.Append(CCFLAGS=["-g", "-W", "-Wall"])
|
---|
[1184] | 226 |
|
---|
| 227 | # Export for SConscript files
|
---|
[1135] | 228 | Export("env")
|
---|
[1082] | 229 |
|
---|
[1325] | 230 | # build externals
|
---|
[2503] | 231 | ext = env.SConscript("external-alma/SConscript")
|
---|
| 232 |
|
---|
[1184] | 233 | # build library
|
---|
[2179] | 234 | so = env.SConscript("src/SConscript", variant_dir="build", duplicate=0)
|
---|
[2503] | 235 |
|
---|
| 236 | apps = env.SConscript("apps/SConscript")
|
---|
| 237 |
|
---|
[1195] | 238 | # test module import, to see if there are unresolved symbols
|
---|
| 239 | def test_module(target,source,env):
|
---|
| 240 | pth = str(target[0])
|
---|
| 241 | mod = os.path.splitext(pth)[0]
|
---|
| 242 | sys.path.insert(2, os.path.split(mod)[0])
|
---|
| 243 | __import__(os.path.split(mod)[1])
|
---|
| 244 | print "ok"
|
---|
| 245 | return 0
|
---|
[2503] | 246 |
|
---|
[1195] | 247 | def test_str(target, source, env):
|
---|
| 248 | return "Testing module..."
|
---|
[1184] | 249 |
|
---|
[1195] | 250 | taction = Action(test_module, test_str)
|
---|
| 251 | env.AddPostAction(so, taction)
|
---|
| 252 |
|
---|
| 253 | if env.GetOption("clean"):
|
---|
| 254 | Execute(Delete(".sconf_temp"))
|
---|
[2503] | 255 | Execute(Delete("options.cache"))
|
---|
[2166] | 256 |
|
---|
| 257 | if env["makedoc"].lower() != "none":
|
---|
| 258 | env.SConscript("doc/SConscript")
|
---|