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