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 | 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 | env.Append(LINKFLAGS=['-Wl,-O1'])
|
---|
134 |
|
---|
135 | # Export for SConscript files
|
---|
136 | Export("env")
|
---|
137 |
|
---|
138 | # build externals
|
---|
139 | env.SConscript("external/SConscript")
|
---|
140 | # build library
|
---|
141 | so = env.SConscript("src/SConscript", build_dir="build", duplicate=0)
|
---|
142 | # test module import, to see if there are unresolved symbols
|
---|
143 | def test_module(target,source,env):
|
---|
144 | pth = str(target[0])
|
---|
145 | mod = os.path.splitext(pth)[0]
|
---|
146 | sys.path.insert(2, os.path.split(mod)[0])
|
---|
147 | __import__(os.path.split(mod)[1])
|
---|
148 | print "ok"
|
---|
149 | return 0
|
---|
150 | def test_str(target, source, env):
|
---|
151 | return "Testing module..."
|
---|
152 |
|
---|
153 | taction = Action(test_module, test_str)
|
---|
154 | env.AddPostAction(so, taction)
|
---|
155 |
|
---|
156 | # install targets
|
---|
157 | somod = env.Install("$moduledir/asap", so )
|
---|
158 | pymods = env.Install("$moduledir/asap", env.SGlob("python/*.py"))
|
---|
159 | bins = env.Install("$prefix/bin", ["bin/asap", "bin/asap_update_data"])
|
---|
160 | shares = env.Install("$moduledir/asap/data", "share/ipythonrc-asap")
|
---|
161 | env.Alias('install', [somod, pymods, bins, shares])
|
---|
162 |
|
---|
163 | # install aips++ data repos
|
---|
164 | rootdir=None
|
---|
165 | outdir = os.path.join(env["moduledir"],'asap','data')
|
---|
166 | sources = ['ephemerides','geodetic']
|
---|
167 | if os.path.exists("/nfs/aips++/data"):
|
---|
168 | rootdir = "/nfs/aips++/data"
|
---|
169 | elif os.path.exists("data"):
|
---|
170 | rootdir = "./data"
|
---|
171 | if rootdir is not None:
|
---|
172 | ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources)
|
---|
173 | data = env.InstallAs(ofiles, ifiles)
|
---|
174 | env.Alias('install', data)
|
---|
175 |
|
---|
176 | # make binary distribution
|
---|
177 | if len(env["makedist"]):
|
---|
178 | env["stagedir"] = "asap-%s-%s" % (env["version"], env["makedist"])
|
---|
179 | env.Command('Staging distribution for archive in %s' % env["stagedir"],
|
---|
180 | '', env.MessageAction)
|
---|
181 | st0 = env.QInstall("$stagedir/asap", [so, env.SGlob("python/*.py")] )
|
---|
182 | env.QInstall("$stagedir/bin", ["bin/asap", "bin/asap_update_data"])
|
---|
183 | env.QInstall("$stagedir", ["bin/install"])
|
---|
184 | env.QInstall("$stagedir/asap/data", "share/ipythonrc-asap")
|
---|
185 | if rootdir is not None:
|
---|
186 | # This creates a directory Using data table... - disabled
|
---|
187 | #env.Command("Using data tables in %s" % rootdir,
|
---|
188 | # '', env.MessageAction)
|
---|
189 | outdir = os.path.join(env["stagedir"],'asap','data')
|
---|
190 | ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources)
|
---|
191 | env.QInstallAs(ofiles, ifiles)
|
---|
192 | else:
|
---|
193 | env.Command("No data tables available. Use 'asap_update_data' after install",
|
---|
194 | '', env.MessageAction)
|
---|
195 | arch = env.Archiver(os.path.join("dist",env["stagedir"]),
|
---|
196 | env["stagedir"])
|
---|
197 | env.AddPostAction(arch, Delete("$stagedir"))
|
---|
198 | if env["makedoc"].lower() != "none":
|
---|
199 | env.SConscript("doc/SConscript")
|
---|
200 |
|
---|
201 | if env.GetOption("clean"):
|
---|
202 | Execute(Delete(".sconf_temp"))
|
---|