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