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("userconfig.py")
|
---|
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 | print casacoretooldir
|
---|
85 | env.Tool('casa', [casacoretooldir])
|
---|
86 |
|
---|
87 | if not env.GetOption('clean'):
|
---|
88 | conf = Configure(env)
|
---|
89 |
|
---|
90 | conf.env.AppendUnique(LIBPATH=os.path.join(conf.env["casacoreroot"],
|
---|
91 | "lib"))
|
---|
92 | conf.env.AppendUnique(CPPPATH=os.path.join(conf.env["casacoreroot"],
|
---|
93 | "include", "casacore"))
|
---|
94 | if not conf.CheckLib("casa_casa", language='c++'): Exit(1)
|
---|
95 | 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"])
|
---|
96 | conf.env.Append(CPPPATH=[distutils.sysconfig.get_python_inc()])
|
---|
97 | if not conf.CheckHeader("Python.h", language='c'):
|
---|
98 | Exit(1)
|
---|
99 | pylib = 'python'+distutils.sysconfig.get_python_version()
|
---|
100 | if env['PLATFORM'] == "darwin":
|
---|
101 | conf.env.Append(FRAMEWORKS=["Python"])
|
---|
102 | else:
|
---|
103 | if not conf.CheckLib(library=pylib, language='c'): Exit(1)
|
---|
104 |
|
---|
105 | conf.env.AddCustomPackage('boost')
|
---|
106 | if not conf.CheckLibWithHeader(env["boostlib"],
|
---|
107 | 'boost/python.hpp', language='c++'):
|
---|
108 | Exit(1)
|
---|
109 | # test for cfitsio
|
---|
110 | if not conf.CheckLib("m"): Exit(1)
|
---|
111 | conf.env.AddCustomPackage('cfitsio')
|
---|
112 | if not conf.CheckLibWithHeader(conf.env["cfitsiolib"],
|
---|
113 | 'fitsio.h', language='c'):
|
---|
114 | Exit(1)
|
---|
115 | conf.env.AddCustomPackage('wcs')
|
---|
116 | if not conf.CheckLibWithHeader('wcs', 'wcslib/wcs.h', language='c'):
|
---|
117 | Exit(1)
|
---|
118 | conf.env.AddCustomPackage('rpfits')
|
---|
119 | if not conf.CheckLib("rpfits"): Exit(1)
|
---|
120 |
|
---|
121 | # test for blas/lapack
|
---|
122 | blasname = conf.env.get("blaslib", "blas")
|
---|
123 | conf.env.AddCustomPackage("blas")
|
---|
124 | if not conf.CheckLib(conf.env["blaslib"]): Exit(1)
|
---|
125 | conf.env.AddCustomPackage("lapack")
|
---|
126 | if not conf.CheckLib(conf.env["lapacklib"]): Exit(1)
|
---|
127 | conf.env.CheckFortran(conf)
|
---|
128 | if not conf.CheckLib('stdc++', language='c++'): Exit(1)
|
---|
129 | env = conf.Finish()
|
---|
130 |
|
---|
131 | env["version"] = "trunk"
|
---|
132 |
|
---|
133 | if env['mode'] == 'release':
|
---|
134 | env.Append(LINKFLAGS=['-Wl,-O1'])
|
---|
135 |
|
---|
136 | # Export for SConscript files
|
---|
137 | Export("env")
|
---|
138 |
|
---|
139 | # build externals
|
---|
140 | env.SConscript("external/SConscript")
|
---|
141 | # build library
|
---|
142 | so = env.SConscript("src/SConscript", build_dir="build", duplicate=0)
|
---|
143 | # test module import, to see if there are unresolved symbols
|
---|
144 | def test_module(target,source,env):
|
---|
145 | pth = str(target[0])
|
---|
146 | mod = os.path.splitext(pth)[0]
|
---|
147 | sys.path.insert(2, os.path.split(mod)[0])
|
---|
148 | __import__(os.path.split(mod)[1])
|
---|
149 | print "ok"
|
---|
150 | return 0
|
---|
151 | def test_str(target, source, env):
|
---|
152 | return "Testing module..."
|
---|
153 |
|
---|
154 | taction = Action(test_module, test_str)
|
---|
155 | env.AddPostAction(so, taction)
|
---|
156 |
|
---|
157 | # install targets
|
---|
158 | somod = env.Install("$moduledir/asap", so )
|
---|
159 | pymods = env.Install("$moduledir/asap", env.SGlob("python/*.py"))
|
---|
160 | bins = env.Install("$prefix/bin", ["bin/asap", "bin/asap_update_data"])
|
---|
161 | shares = env.Install("$moduledir/asap/data", "share/ipythonrc-asap")
|
---|
162 | env.Alias('install', [somod, pymods, bins, shares])
|
---|
163 |
|
---|
164 | # install aips++ data repos
|
---|
165 | rootdir=None
|
---|
166 | outdir = os.path.join(env["moduledir"],'asap','data')
|
---|
167 | sources = ['ephemerides','geodetic']
|
---|
168 | if os.path.exists("/nfs/aips++/data"):
|
---|
169 | rootdir = "/nfs/aips++/data"
|
---|
170 | elif os.path.exists("data"):
|
---|
171 | rootdir = "./data"
|
---|
172 | if rootdir is not None:
|
---|
173 | ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources)
|
---|
174 | data = env.InstallAs(ofiles, ifiles)
|
---|
175 | env.Alias('install', data)
|
---|
176 |
|
---|
177 | # make binary distribution
|
---|
178 | if len(env["makedist"]):
|
---|
179 | env["stagedir"] = "asap-%s-%s" % (env["version"], env["makedist"])
|
---|
180 | env.Command('Staging distribution for archive in %s' % env["stagedir"],
|
---|
181 | '', env.MessageAction)
|
---|
182 | st0 = env.QInstall("$stagedir/asap", [so, env.SGlob("python/*.py")] )
|
---|
183 | env.QInstall("$stagedir/bin", ["bin/asap", "bin/asap_update_data"])
|
---|
184 | env.QInstall("$stagedir", ["bin/install"])
|
---|
185 | env.QInstall("$stagedir/asap/data", "share/ipythonrc-asap")
|
---|
186 | if rootdir is not None:
|
---|
187 | # This creates a directory Using data table... - disabled
|
---|
188 | #env.Command("Using data tables in %s" % rootdir,
|
---|
189 | # '', env.MessageAction)
|
---|
190 | outdir = os.path.join(env["stagedir"],'asap','data')
|
---|
191 | ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources)
|
---|
192 | env.QInstallAs(ofiles, ifiles)
|
---|
193 | else:
|
---|
194 | env.Command("No data tables available. Use 'asap_update_data' after install",
|
---|
195 | '', env.MessageAction)
|
---|
196 | arch = env.Archiver(os.path.join("dist",env["stagedir"]),
|
---|
197 | env["stagedir"])
|
---|
198 | env.AddPostAction(arch, Delete("$stagedir"))
|
---|
199 | if env["makedoc"].lower() != "none":
|
---|
200 | env.SConscript("doc/SConscript")
|
---|
201 |
|
---|
202 | if env.GetOption("clean"):
|
---|
203 | Execute(Delete(".sconf_temp"))
|
---|