1 | import os |
---|
2 | import sys |
---|
3 | import distutils.sysconfig |
---|
4 | import platform |
---|
5 | import SCons |
---|
6 | |
---|
7 | moduledir = distutils.sysconfig.get_python_lib() |
---|
8 | if platform.architecture()[0] == '64bit': |
---|
9 | # hack to install into /usr/lib64 if scons is in the 32bit /usr/lib/ |
---|
10 | if moduledir.startswith("/usr/lib/"): |
---|
11 | moduledir = moduledir.replace("lib", "lib64") |
---|
12 | |
---|
13 | opts = Options("options.cfg") |
---|
14 | opts.AddOptions( |
---|
15 | ("FORTRAN", "The fortran compiler", None), |
---|
16 | ("f2clib", "The fortran to c library", None), |
---|
17 | PathOption("prefix", |
---|
18 | "The root installation path", |
---|
19 | distutils.sysconfig.PREFIX), |
---|
20 | PathOption("moduledir", |
---|
21 | "The python module path (site-packages))", |
---|
22 | moduledir), |
---|
23 | PathOption("casacoreroot", "The location of casacore", |
---|
24 | "/usr/local"), |
---|
25 | ("boostroot", "The root dir where boost is installed", None), |
---|
26 | ("boostlib", "The name of the boost python library", |
---|
27 | "boost_python"), |
---|
28 | ("boostlibdir", "The boost library location", None), |
---|
29 | ("boostincdir", "The boost header file location", None), |
---|
30 | ("lapackroot", |
---|
31 | "The root directory where lapack is installed", None), |
---|
32 | ("lapacklibdir", "The lapack library location", None), |
---|
33 | ("lapacklib", |
---|
34 | "The lapack library name (e.g. for specialized AMD libraries", |
---|
35 | "lapack"), |
---|
36 | ("blasroot", |
---|
37 | "The root directory where blas is installed", None), |
---|
38 | ("blaslibdir", "The blas library location", None), |
---|
39 | ("blaslib", |
---|
40 | "The blas library name (e.g. for specialized AMD libraries", |
---|
41 | "blas"), |
---|
42 | ("cfitsioroot", |
---|
43 | "The root directory where cfistio is installed", None), |
---|
44 | ("cfitsiolibdir", "The cfitsio library location", None), |
---|
45 | ("cfitsiolib", "The cfitsio library name", "cfitsio"), |
---|
46 | ("cfitsioincdir", "The cfitsio include location", None), |
---|
47 | ("wcsroot", |
---|
48 | "The root directory where wcs is installed", None), |
---|
49 | ("wcslibdir", "The wcs library location", None), |
---|
50 | ("rpfitsroot", |
---|
51 | "The root directory where rpfits is installed", None), |
---|
52 | ("rpfitslibdir", "The rpfits library location", None), |
---|
53 | |
---|
54 | EnumOption("mode", "The type of build.", "debug", |
---|
55 | ["release","debug"], ignorecase=1), |
---|
56 | ("makedist", |
---|
57 | "Make a binary archive giving a suffix, e.g. sarge or fc5", |
---|
58 | ""), |
---|
59 | EnumOption("makedoc", "Build the userguide in specified format", |
---|
60 | "none", |
---|
61 | ["none", "pdf", "html"], ignorecase=1) |
---|
62 | ) |
---|
63 | |
---|
64 | env = Environment( toolpath = ['./scons'], |
---|
65 | tools = ["default", "archiver", "utils", |
---|
66 | "quietinstall"], |
---|
67 | ENV = { 'PATH' : os.environ[ 'PATH' ], |
---|
68 | 'HOME' : os.environ[ 'HOME' ] }, |
---|
69 | options = opts) |
---|
70 | |
---|
71 | Help(opts.GenerateHelpText(env)) |
---|
72 | env.SConsignFile() |
---|
73 | |
---|
74 | if env["PLATFORM"] == "darwin": |
---|
75 | env.EnsureSConsVersion(0,96,95) |
---|
76 | |
---|
77 | casacoretooldir = os.path.join(env["casacoreroot"],"share", |
---|
78 | "casacore") |
---|
79 | if not os.path.exists(casacoretooldir): |
---|
80 | print "Could not find casacore scons tools" |
---|
81 | Exit(1) |
---|
82 | |
---|
83 | # load casacore specific build flags |
---|
84 | env.Tool('casa', [casacoretooldir]) |
---|
85 | |
---|
86 | if not env.GetOption('clean'): |
---|
87 | conf = Configure(env) |
---|
88 | |
---|
89 | conf.env.AppendUnique(LIBPATH=os.path.join(conf.env["casacoreroot"], |
---|
90 | "lib")) |
---|
91 | conf.env.AppendUnique(CPPPATH=os.path.join(conf.env["casacoreroot"], |
---|
92 | "include", "casacore")) |
---|
93 | if not conf.CheckLib("casa_casa", language='c++'): Exit(1) |
---|
94 | conf.env.PrependUnique(LIBS=["casa_ms", "casa_components", "casa_coordinates", "casa_lattices", "casa_fits", "casa_measures", "casa_scimath", "casa_scimath_f", "casa_tables", "casa_mirlib"]) |
---|
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 | if not conf.CheckLibWithHeader(env["boostlib"], |
---|
106 | 'boost/python.hpp', language='c++'): |
---|
107 | Exit(1) |
---|
108 | # test for cfitsio |
---|
109 | if not conf.CheckLib("m"): Exit(1) |
---|
110 | conf.env.AddCustomPackage('cfitsio') |
---|
111 | if not conf.CheckLibWithHeader(conf.env["cfitsiolib"], |
---|
112 | 'fitsio.h', language='c'): |
---|
113 | Exit(1) |
---|
114 | conf.env.AddCustomPackage('wcs') |
---|
115 | if not conf.CheckLibWithHeader('wcs', 'wcslib/wcs.h', language='c'): |
---|
116 | Exit(1) |
---|
117 | conf.env.AddCustomPackage('rpfits') |
---|
118 | if not conf.CheckLib("rpfits"): Exit(1) |
---|
119 | |
---|
120 | # test for blas/lapack |
---|
121 | conf.env.AddCustomPackage("lapack") |
---|
122 | if not conf.CheckLib(conf.env["lapacklib"]): Exit(1) |
---|
123 | blasname = conf.env.get("blaslib", "blas") |
---|
124 | conf.env.AddCustomPackage("blas") |
---|
125 | if not conf.CheckLib(conf.env["blaslib"]): Exit(1) |
---|
126 | conf.env.CheckFortran(conf) |
---|
127 | if not conf.CheckLib('stdc++', language='c++'): Exit(1) |
---|
128 | env = conf.Finish() |
---|
129 | |
---|
130 | env["version"] = "trunk" |
---|
131 | |
---|
132 | if env['mode'] == 'release': |
---|
133 | if env["PLATFORM"] != "darwin": |
---|
134 | env.Append(LINKFLAGS=['-Wl,-O1', '-s']) |
---|
135 | env.Append(CCFLAGS=["-O2"]) |
---|
136 | else: |
---|
137 | env.Append(CCFLAGS=["-g"]) |
---|
138 | |
---|
139 | # Export for SConscript files |
---|
140 | Export("env") |
---|
141 | |
---|
142 | # build externals |
---|
143 | env.SConscript("external/SConscript") |
---|
144 | # build library |
---|
145 | so = env.SConscript("src/SConscript", build_dir="build", duplicate=0) |
---|
146 | # test module import, to see if there are unresolved symbols |
---|
147 | def test_module(target,source,env): |
---|
148 | pth = str(target[0]) |
---|
149 | mod = os.path.splitext(pth)[0] |
---|
150 | sys.path.insert(2, os.path.split(mod)[0]) |
---|
151 | __import__(os.path.split(mod)[1]) |
---|
152 | print "ok" |
---|
153 | return 0 |
---|
154 | def test_str(target, source, env): |
---|
155 | return "Testing module..." |
---|
156 | |
---|
157 | taction = Action(test_module, test_str) |
---|
158 | env.AddPostAction(so, taction) |
---|
159 | |
---|
160 | # install targets |
---|
161 | somod = env.Install("$moduledir/asap", so ) |
---|
162 | pymods = env.Install("$moduledir/asap", env.SGlob("python/*.py")) |
---|
163 | bins = env.Install("$prefix/bin", ["bin/asap", "bin/asap_update_data"]) |
---|
164 | shares = env.Install("$moduledir/asap/data", "share/ipythonrc-asap") |
---|
165 | env.Alias('install', [somod, pymods, bins, shares]) |
---|
166 | |
---|
167 | # install aips++ data repos |
---|
168 | rootdir=None |
---|
169 | outdir = os.path.join(env["moduledir"],'asap','data') |
---|
170 | sources = ['ephemerides','geodetic'] |
---|
171 | if os.path.exists("/nfs/aips++/data"): |
---|
172 | rootdir = "/nfs/aips++/data" |
---|
173 | elif os.path.exists("data"): |
---|
174 | rootdir = "./data" |
---|
175 | if rootdir is not None: |
---|
176 | ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources) |
---|
177 | data = env.InstallAs(ofiles, ifiles) |
---|
178 | env.Alias('install', data) |
---|
179 | |
---|
180 | # make binary distribution |
---|
181 | if len(env["makedist"]): |
---|
182 | env["stagedir"] = "asap-%s-%s" % (env["version"], env["makedist"]) |
---|
183 | env.Command('Staging distribution for archive in %s' % env["stagedir"], |
---|
184 | '', env.MessageAction) |
---|
185 | st0 = env.QInstall("$stagedir/asap", [so, env.SGlob("python/*.py")] ) |
---|
186 | env.QInstall("$stagedir/bin", ["bin/asap", "bin/asap_update_data"]) |
---|
187 | env.QInstall("$stagedir", ["bin/install"]) |
---|
188 | env.QInstall("$stagedir/asap/data", "share/ipythonrc-asap") |
---|
189 | if rootdir is not None: |
---|
190 | # This creates a directory Using data table... - disabled |
---|
191 | #env.Command("Using data tables in %s" % rootdir, |
---|
192 | # '', env.MessageAction) |
---|
193 | outdir = os.path.join(env["stagedir"],'asap','data') |
---|
194 | ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources) |
---|
195 | env.QInstallAs(ofiles, ifiles) |
---|
196 | else: |
---|
197 | env.Command("No data tables available. Use 'asap_update_data' after install", |
---|
198 | '', env.MessageAction) |
---|
199 | arch = env.Archiver(os.path.join("dist",env["stagedir"]), |
---|
200 | env["stagedir"]) |
---|
201 | env.AddPostAction(arch, Delete("$stagedir")) |
---|
202 | if env["makedoc"].lower() != "none": |
---|
203 | env.SConscript("doc/SConscript") |
---|
204 | |
---|
205 | if env.GetOption("clean"): |
---|
206 | Execute(Delete(".sconf_temp")) |
---|