source: trunk/SConstruct @ 1406

Last change on this file since 1406 was 1406, checked in by Malte Marquarding, 16 years ago

work with the latest version of casacore; made release mode default. Add optional build of apps.

File size: 8.2 KB
Line 
1import os
2import sys
3import distutils.sysconfig
4import platform
5import SCons
6
7moduledir = distutils.sysconfig.get_python_lib()
8if  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
13opts = Options("options.cfg")
14opts.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                ("rpfitslib", "The rpfits library name", "rpfits"),
51                ("rpfitsroot",
52                 "The root directory where rpfits is installed", None),
53                ("rpfitslibdir", "The rpfits library location", None),
54#               ("rpfitsincdir", "The rpfits include location", None),
55                EnumOption("mode", "The type of build.", "release",
56                           ["release","debug"], ignorecase=1),
57                ("makedist",
58                 "Make a binary archive giving a suffix, e.g. sarge or fc5",
59                 ""),
60                EnumOption("makedoc", "Build the userguide in specified format",
61                           "none",
62                           ["none", "pdf", "html"], ignorecase=1),
63                BoolOption("apps", "Build cpp apps", False)
64                )
65
66env = Environment( toolpath = ['./scons'],
67                   tools = ["default", "archiver", "utils",
68                            "quietinstall"],
69                   ENV = { 'PATH' : os.environ[ 'PATH' ],
70                          'HOME' : os.environ[ 'HOME' ] },
71                   options = opts)
72
73Help(opts.GenerateHelpText(env))
74env.SConsignFile()
75
76if env["PLATFORM"] == "darwin":
77    env.EnsureSConsVersion(0,96,95)
78
79casacoretooldir = os.path.join(env["casacoreroot"],"share",
80                                   "casacore")
81if not os.path.exists(casacoretooldir):
82    print "Could not find casacore scons tools"
83    Exit(1)
84
85# load casacore specific build flags
86env.Tool('casaoptions', [casacoretooldir])
87env.AddCommonOptions(opts)
88opts.Update(env)
89env.Tool('casa', [casacoretooldir])
90
91if not env.GetOption('clean'):
92    conf = Configure(env)
93
94    conf.env.AppendUnique(LIBPATH=os.path.join(conf.env["casacoreroot"],
95                                               "lib"))
96    conf.env.AppendUnique(CPPPATH=os.path.join(conf.env["casacoreroot"],
97                                               "include", "casacore"))
98    if not conf.CheckLib("casa_casa", language='c++'): Exit(1)
99    conf.env.PrependUnique(LIBS=["casa_ms", "casa_components",
100                                 "casa_coordinates", "casa_lattices",
101                                 "casa_fits", "casa_measures", "casa_scimath",
102                                 "casa_scimath_f", "casa_tables",
103                                 "casa_mirlib"])
104    conf.env.Append(CPPPATH=[distutils.sysconfig.get_python_inc()])
105    if not conf.CheckHeader("Python.h", language='c'):
106        Exit(1)
107    pylib = 'python'+distutils.sysconfig.get_python_version()
108    if env['PLATFORM'] == "darwin":
109        conf.env.Append(FRAMEWORKS=["Python"])
110    else:
111        if not conf.CheckLib(library=pylib, language='c'): Exit(1)
112
113    conf.env.AddCustomPackage('boost')
114    if not conf.CheckLibWithHeader(env["boostlib"],
115                                   'boost/python.hpp', language='c++'):
116        Exit(1)
117    # test for cfitsio
118    if not conf.CheckLib("m"): Exit(1)
119    conf.env.AddCustomPackage('cfitsio')
120    if not conf.CheckLibWithHeader(conf.env["cfitsiolib"],
121                                   'fitsio.h', language='c'):
122        Exit(1)
123    conf.env.AddCustomPackage('wcs')
124    if not conf.CheckLibWithHeader('wcs', 'wcslib/wcs.h', language='c'):
125        Exit(1)
126    conf.env.AddCustomPackage('rpfits')
127    if not conf.CheckLib(conf.env["rpfitslib"], language="c"):
128        Exit(1)
129
130    # test for blas/lapack
131    conf.env.AddCustomPackage("lapack")
132    if not conf.CheckLib(conf.env["lapacklib"]): Exit(1)
133    blasname = conf.env.get("blaslib", "blas")
134    conf.env.AddCustomPackage("blas")
135    if not conf.CheckLib(conf.env["blaslib"]): Exit(1)
136    conf.env.CheckFortran(conf)
137    if not conf.CheckLib('stdc++', language='c++'): Exit(1)
138    env = conf.Finish()
139
140env["version"] = "2.2.x"
141
142if env['mode'] == 'release':
143    if env["PLATFORM"] != "darwin":
144        env.Append(LINKFLAGS=['-Wl,-O1', '-s'])
145    env.Append(CCFLAGS=["-O2"])
146else:
147    env.Append(CCFLAGS=["-g", "-Wall"])
148
149# Export for SConscript files
150Export("env")
151
152# build externals
153env.SConscript("external/SConscript")
154# build library
155so = env.SConscript("src/SConscript", build_dir="build", duplicate=0)
156# test module import, to see if there are unresolved symbols
157def test_module(target,source,env):
158    pth = str(target[0])
159    mod = os.path.splitext(pth)[0]
160    sys.path.insert(2, os.path.split(mod)[0])
161    __import__(os.path.split(mod)[1])
162    print "ok"
163    return 0
164def test_str(target, source, env):
165    return "Testing module..."
166
167taction = Action(test_module, test_str)
168env.AddPostAction(so, taction)
169
170# install targets
171somod = env.Install("$moduledir/asap", so )
172pymods = env.Install("$moduledir/asap", env.SGlob("python/*.py"))
173bins = env.Install("$prefix/bin", ["bin/asap", "bin/asap_update_data"])
174shares = env.Install("$moduledir/asap/data", "share/ipythonrc-asap")
175env.Alias('install', [somod, pymods, bins, shares])
176
177# install aips++ data repos
178rootdir=None
179outdir =  os.path.join(env["moduledir"],'asap','data')
180sources = ['ephemerides','geodetic']
181if os.path.exists("/nfs/aips++/data"):
182    rootdir = "/nfs/aips++/data"
183elif os.path.exists("data"):
184    rootdir = "./data"
185if rootdir is not None:
186    ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources)
187    data =  env.InstallAs(ofiles, ifiles)
188    env.Alias('install', data)
189
190# make binary distribution
191if len(env["makedist"]):
192    env["stagedir"] = "asap-%s-%s" % (env["version"], env["makedist"])
193    env.Command('Staging distribution for archive in %s' % env["stagedir"],
194                '', env.MessageAction)
195    st0 = env.QInstall("$stagedir/asap", [so,  env.SGlob("python/*.py")] )
196    env.QInstall("$stagedir/bin", ["bin/asap", "bin/asap_update_data"])
197    env.QInstall("$stagedir", ["bin/install"])
198    env.QInstall("$stagedir/asap/data", "share/ipythonrc-asap")
199    if rootdir is not None:
200        # This creates a directory Using data table... - disabled
201        #env.Command("Using data tables in %s" % rootdir,
202        #           '', env.MessageAction)
203        outdir =  os.path.join(env["stagedir"],'asap','data')
204        ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources)
205        env.QInstallAs(ofiles, ifiles)
206    else:
207        env.Command("No data tables available. Use 'asap_update_data' after install",
208                    '', env.MessageAction)
209    arch = env.Archiver(os.path.join("dist",env["stagedir"]),
210                        env["stagedir"])
211    env.AddPostAction(arch, Delete("$stagedir"))
212if env["makedoc"].lower() != "none":
213    env.SConscript("doc/SConscript")
214
215if env["apps"]:
216    env.SConscript("apps/SConscript")
217
218if env.GetOption("clean"):
219    Execute(Delete(".sconf_temp"))
Note: See TracBrowser for help on using the repository browser.