1 | import os
|
---|
2 | import sys
|
---|
3 | import distutils.sysconfig
|
---|
4 | import platform
|
---|
5 | import SCons
|
---|
6 |
|
---|
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 |
|
---|
24 | def get_libdir():
|
---|
25 | return os.path.basename(distutils.sysconfig.get_config_var('LIBDIR'))
|
---|
26 |
|
---|
27 | LIBDIR = 'lib' #get_libdir()
|
---|
28 |
|
---|
29 | EnsureSConsVersion(1,0,0)
|
---|
30 |
|
---|
31 | opts = Variables("options.cache")
|
---|
32 | opts.AddVariables(
|
---|
33 | ("extraroot", "Addition tree to look for packages", None),
|
---|
34 | ("extraflags", "Additional build flags", None),
|
---|
35 | PathVariable("casacoreroot", "The location of casacore",
|
---|
36 | "/usr/local"),
|
---|
37 | BoolVariable("casacorestatic",
|
---|
38 | "Link statically against casacore",
|
---|
39 | False),
|
---|
40 | ("boostroot", "The root dir where boost is installed", None),
|
---|
41 | ("boostlib", "The name of the boost python library",
|
---|
42 | "boost_python"),
|
---|
43 | ("boostlibdir", "The boost library location", None),
|
---|
44 | ("boostincdir", "The boost header file location", None),
|
---|
45 | ("cfitsioroot",
|
---|
46 | "The root directory where cfistio is installed", None),
|
---|
47 | ("cfitsiolibdir", "The cfitsio library location", None),
|
---|
48 | ("cfitsiolib", "The cfitsio library name", "cfitsio"),
|
---|
49 | ("cfitsioincdir", "The cfitsio include location", None),
|
---|
50 | ("wcslib", "The wcs library name", "wcs"),
|
---|
51 | ("wcsroot",
|
---|
52 | "The root directory where wcs is installed", None),
|
---|
53 | ("wcslibdir", "The wcs library location", None),
|
---|
54 | ("rpfitslib", "The rpfits library name", "rpfits"),
|
---|
55 | ("rpfitsroot",
|
---|
56 | "The root directory where rpfits is installed", None),
|
---|
57 | ("rpfitslibdir", "The rpfits library location", None),
|
---|
58 |
|
---|
59 | ("pyraproot", "The root directory where libpyrap is installed",
|
---|
60 | None),
|
---|
61 | ("numpyincdir", "numpy header file directory",
|
---|
62 | get_numpy_incdir()),
|
---|
63 | BoolVariable("enable_pyrap",
|
---|
64 | "Use pyrap conversion library from system",
|
---|
65 | False),
|
---|
66 | ("pyraplib", "The name of the pyrap library", "pyrap"),
|
---|
67 | ("pyraplibdir", "The directory where libpyrap is installed",
|
---|
68 | None),
|
---|
69 | ("pyrapincdir", "The pyrap include location",
|
---|
70 | None),
|
---|
71 | EnumVariable("mode", "The type of build.", "release",
|
---|
72 | ["release","debug"], ignorecase=1),
|
---|
73 | EnumVariable("makedoc",
|
---|
74 | "Build the userguide in specified format",
|
---|
75 | "none",
|
---|
76 | ["none", "pdf", "html"], ignorecase=1),
|
---|
77 | BoolVariable("apps", "Build cpp apps", True),
|
---|
78 | BoolVariable("alma", "Enable alma specific functionality",
|
---|
79 | False),
|
---|
80 | )
|
---|
81 |
|
---|
82 | env = Environment( toolpath = ['./scons'],
|
---|
83 | tools = ["default", "utils", "casa"],
|
---|
84 | ENV = { 'PATH' : os.environ[ 'PATH' ],
|
---|
85 | 'HOME' : os.environ[ 'HOME' ] },
|
---|
86 | options = opts)
|
---|
87 |
|
---|
88 | env.Help(opts.GenerateHelpText(env))
|
---|
89 | env.SConsignFile()
|
---|
90 | if not ( env.GetOption('clean') or env.GetOption('help') ):
|
---|
91 |
|
---|
92 | conf = Configure(env)
|
---|
93 | if conf.env.get("extraroot", None):
|
---|
94 | conf.env.AddCustomPackage('extra')
|
---|
95 | conf.env.Append(CPPPATH=[distutils.sysconfig.get_python_inc()])
|
---|
96 | if not conf.CheckHeader("Python.h", language='c'):
|
---|
97 | Exit(1)
|
---|
98 | pylib = 'python'+distutils.sysconfig.get_python_version()
|
---|
99 | if env['PLATFORM'] == "darwin":
|
---|
100 | conf.env.Append(FRAMEWORKS=["Python"])
|
---|
101 | else:
|
---|
102 | if not conf.CheckLib(library=pylib, language='c'): Exit(1)
|
---|
103 |
|
---|
104 | conf.env.AddCustomPackage('boost')
|
---|
105 | libname = conf.env["boostlib"]
|
---|
106 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
107 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
108 | else:
|
---|
109 | if not conf.CheckLibWithHeader(libname,
|
---|
110 | 'boost/python.hpp', language='c++'):
|
---|
111 | Exit(1)
|
---|
112 |
|
---|
113 | if not conf.CheckLib("m"):
|
---|
114 | Exit(1)
|
---|
115 | # test for cfitsio
|
---|
116 | conf.env.AddCustomPackage('cfitsio')
|
---|
117 | libname = conf.env["cfitsiolib"]
|
---|
118 | if not conf.CheckHeader("fitsio.h"):
|
---|
119 | #SuSE is being special
|
---|
120 | conf.env.AppendUnique(CPPPATH=['/usr/include/libcfitsio0'])
|
---|
121 | if not conf.CheckHeader("fitsio.h"):
|
---|
122 | Exit(1)
|
---|
123 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
124 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
125 | else:
|
---|
126 | if not conf.CheckLib(libname, language='c'):
|
---|
127 | Exit(1)
|
---|
128 | conf.env.AddCustomPackage('wcs')
|
---|
129 | libname = conf.env["wcslib"]
|
---|
130 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
131 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
132 | else:
|
---|
133 | if not conf.CheckLibWithHeader(libname,
|
---|
134 | 'wcslib/wcs.h', language='c'):
|
---|
135 | Exit(1)
|
---|
136 |
|
---|
137 | conf.env.AddCustomPackage('rpfits')
|
---|
138 | if not conf.CheckLibWithHeader(conf.env["rpfitslib"], "RPFITS.h",
|
---|
139 | language="c"):
|
---|
140 | Exit(1)
|
---|
141 |
|
---|
142 | libpath = ""
|
---|
143 | for p in [conf.env["casacoreroot"], conf.env.get("extraroot", "")]:
|
---|
144 | pth = os.path.join(p, "include", "casacore")
|
---|
145 | if os.path.exists(pth):
|
---|
146 | libpath = os.path.join(p, LIBDIR)
|
---|
147 | conf.env.AppendUnique(CPPPATH=[pth,pth+'/..'])
|
---|
148 | break
|
---|
149 | cclibs = ["casa_python", "casa_images", "casa_ms",
|
---|
150 | "casa_coordinates", "casa_lattices",
|
---|
151 | "casa_fits", "casa_measures", "casa_scimath",
|
---|
152 | "casa_scimath_f", "casa_tables", "casa_casa"]
|
---|
153 | if conf.env["casacorestatic"]:
|
---|
154 | libs = [ env.File(os.path.join(libpath, "lib"+lib+".a")) \
|
---|
155 | for lib in cclibs ]
|
---|
156 | else:
|
---|
157 | conf.env.AppendUnique(LIBPATH=libpath)
|
---|
158 | if not conf.CheckLibWithHeader("casa_casa", "casa/aips.h",
|
---|
159 | language='c++', autoadd=0):
|
---|
160 | Exit(1)
|
---|
161 | libs = cclibs
|
---|
162 | conf.env.PrependUnique(LIBS=libs)
|
---|
163 |
|
---|
164 | if not conf.CheckLib('stdc++', language='c++'): Exit(1)
|
---|
165 | if conf.env["alma"]:
|
---|
166 | conf.env.Append(CPPFLAGS=['-DUSE_CASAPY'])
|
---|
167 | if conf.env.get("extraflags"):
|
---|
168 | flags = conf.env.ParseFlags(conf.env["extraflags"])
|
---|
169 | conf.env.MergeFlags(flags)
|
---|
170 | env = conf.Finish()
|
---|
171 |
|
---|
172 | opts.Save('options.cache', env)
|
---|
173 |
|
---|
174 | env["version"] = "4.3.x"
|
---|
175 |
|
---|
176 | if env['mode'] == 'release':
|
---|
177 | if env["PLATFORM"] != "darwin":
|
---|
178 | env.Append(LINKFLAGS=['-Wl,-O1', '-s'])
|
---|
179 | env.Append(CCFLAGS=["-O2"])
|
---|
180 | else:
|
---|
181 | env.Append(CCFLAGS=["-g", "-W", "-Wall"])
|
---|
182 |
|
---|
183 | # Export for SConscript files
|
---|
184 | Export("env")
|
---|
185 |
|
---|
186 | # build externals
|
---|
187 | ext = env.SConscript("external-alma/SConscript")
|
---|
188 |
|
---|
189 | # build library
|
---|
190 | so = env.SConscript("src/SConscript", variant_dir="build", duplicate=0)
|
---|
191 |
|
---|
192 | apps = env.SConscript("apps/SConscript")
|
---|
193 |
|
---|
194 | # test module import, to see if there are unresolved symbols
|
---|
195 | def test_module(target,source,env):
|
---|
196 | pth = str(target[0])
|
---|
197 | mod = os.path.splitext(pth)[0]
|
---|
198 | sys.path.insert(2, os.path.split(mod)[0])
|
---|
199 | __import__(os.path.split(mod)[1])
|
---|
200 | print "ok"
|
---|
201 | return 0
|
---|
202 |
|
---|
203 | def test_str(target, source, env):
|
---|
204 | return "Testing module..."
|
---|
205 |
|
---|
206 | taction = Action(test_module, test_str)
|
---|
207 | env.AddPostAction(so, taction)
|
---|
208 |
|
---|
209 | if env.GetOption("clean"):
|
---|
210 | Execute(Delete(".sconf_temp"))
|
---|
211 | Execute(Delete("options.cache"))
|
---|
212 | Execute(Delete(".sconsign.dblite"))
|
---|
213 | if env["makedoc"].lower() != "none":
|
---|
214 | env.SConscript("doc/SConscript")
|
---|