source: trunk/SConstruct @ 2501

Last change on this file since 2501 was 2501, checked in by Malte Marquarding, 12 years ago

implicitly call staging

File size: 8.8 KB
Line 
1import os
2import sys
3import distutils.sysconfig
4import platform
5import SCons
6
7# try to autodetect numpy
8def 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
24def get_moduledir(prefix="/usr/local"):
25    moduledir = distutils.sysconfig.get_python_lib(1,0, prefix)
26    if sys.platform.startswith('linux') \
27            and platform.architecture()[0] == '64bit' \
28            and platform.dist()[0].lower() not in ['debian', 'ubuntu']:
29        # hack to install into /usr/lib64 if scons is in the 32bit /usr/lib/
30        if moduledir.startswith("/usr"):
31           moduledir = moduledir.replace("lib", "lib64")
32    return moduledir
33
34EnsureSConsVersion(1,0,0)
35
36opts = Variables("options.cfg")
37opts.AddVariables(
38                ("FORTRAN", "The fortran compiler", None),
39                ("f2clib", "The fortran to c library", None),
40                PathVariable("prefix",
41                "The root installation path",
42                           distutils.sysconfig.PREFIX),
43                ("moduledir",
44                 "The python module path (site-packages))",
45                 None),
46                PathVariable("casacoreroot", "The location of casacore",
47                             "/usr/local"),
48                ("boostroot", "The root dir where boost is installed", None),
49                ("boostlib", "The name of the boost python library",
50                 "boost_python"),
51                ("boostlibdir", "The boost library location", None),
52                ("boostincdir", "The boost header file location", None),
53                ("lapackroot",
54                 "The root directory where lapack is installed", None),
55                ("lapacklibdir", "The lapack library location", None),
56                ("lapacklib",
57                 "The lapack library name (e.g. for specialized AMD libraries",
58                 "lapack"),
59                ("blasroot",
60                 "The root directory where blas is installed", None),
61                ("blaslibdir", "The blas library location", None),
62                ("blaslib",
63                 "The blas library name (e.g. for specialized AMD libraries",
64                 "blas"),
65                ("cfitsioroot",
66                 "The root directory where cfistio is installed", None),
67                ("cfitsiolibdir", "The cfitsio library location", None),
68                ("cfitsiolib", "The cfitsio library name", "cfitsio"),
69                ("cfitsioincdir", "The cfitsio include location", None),
70                ("wcslib", "The wcs library name", "wcs"),
71                ("wcsroot",
72                 "The root directory where wcs is installed", None),
73                ("wcslibdir", "The wcs library location", None),
74                ("rpfitslib", "The rpfits library name", "rpfits"),
75                ("rpfitsroot",
76                 "The root directory where rpfits is installed", None),
77                ("rpfitslibdir", "The rpfits library location", None),
78                ("pyraproot", "The root directory where libpyrap is installed",
79                 None),
80                ("numpyincdir", "numpy header file directory",
81                 get_numpy_incdir()),
82                ("pyraplib", "The name of the pyrap library", "pyrap"),
83                ("pyraplibdir", "The directory where libpyrap is installed",
84                 None),
85                ("pyrapincdir", "The pyrap include location",
86                 None),
87                BoolVariable("enable_pyrap", "Use pyrap conversion library",
88                             False),
89
90                EnumVariable("mode", "The type of build.", "release",
91                           ["release","debug"], ignorecase=1),
92                EnumVariable("makedoc", "Build the userguide in specified format",
93                           "none",
94                           ["none", "pdf", "html"], ignorecase=1),
95                BoolVariable("apps", "Build cpp apps", True),
96                BoolVariable("alma", "Enable alma specific functionality",
97                             False),
98                )
99
100env = Environment( toolpath = ['./scons'],
101                   tools = ["default", "archiver", "utils",
102                            "quietinstall", "casaoptions", "casa"],
103                   ENV = { 'PATH' : os.environ[ 'PATH' ],
104                          'HOME' : os.environ[ 'HOME' ] },
105                   options = opts)
106
107Help(opts.GenerateHelpText(env))
108env.SConsignFile()
109
110if not env.GetOption('clean'):
111    conf = Configure(env)
112
113    conf.env.AppendUnique(LIBPATH=os.path.join(conf.env["casacoreroot"],
114                                               "lib"))
115    conf.env.AppendUnique(CPPPATH=os.path.join(conf.env["casacoreroot"],
116                                               "include", "casacore"))
117    if not conf.CheckLib("casa_casa", language='c++'): Exit(1)
118    conf.env.PrependUnique(LIBS=["casa_images", "casa_ms", "casa_components",
119                                 "casa_coordinates", "casa_lattices",
120                                 "casa_fits", "casa_measures", "casa_scimath",
121                                 "casa_scimath_f", "casa_tables",
122                                 "casa_mirlib"])
123    conf.env.Append(CPPPATH=[distutils.sysconfig.get_python_inc()])
124    if not conf.CheckHeader("Python.h", language='c'):
125        Exit(1)
126    pylib = 'python'+distutils.sysconfig.get_python_version()
127    if env['PLATFORM'] == "darwin":
128        conf.env.Append(FRAMEWORKS=["Python"])
129    else:
130        if not conf.CheckLib(library=pylib, language='c'): Exit(1)
131
132    conf.env.AddCustomPackage('boost')
133    if not conf.CheckLibWithHeader(conf.env["boostlib"],
134                                   'boost/python.hpp', language='c++'):
135        Exit(1)
136
137#    conf.env.AddCustomPackage('pyrap')
138    if False and conf.CheckLib(conf.env["pyraplib"], language='c++', autoadd=0):
139        conf.env.Append(CPPFLAGS=['-DHAVE_LIBPYRAP'])
140#        conf.env.PrependUnique(LIBS=env['pyraplib'])
141    else:
142        conf.env.AppendUnique(CPPPATH=[conf.env["numpyincdir"]])
143        # numpy 1.0 uses config.h; numpy >= 1.1 uses numpyconfig.h
144        if conf.CheckHeader("numpy/config.h") or \
145               conf.CheckHeader("numpy/numpyconfig.h"):
146            conf.env.Append(CPPDEFINES=["-DAIPS_USENUMPY"])
147        else:
148            conf.env.Exit(1)
149        conf.env.Append(CPPFLAGS=['-DHAVE_LIBPYRAP'])
150        # compile in pyrap here...
151        conf.env["pyrapint"] = "#/external/libpyrap/pyrap-0.3.2"
152    # test for cfitsio
153    if not conf.CheckLib("m"): Exit(1)
154    conf.env.AddCustomPackage('cfitsio')
155    if not conf.CheckLibWithHeader(conf.env["cfitsiolib"],
156                                   'fitsio.h', language='c'):
157        Exit(1)
158    conf.env.AddCustomPackage('wcs')
159    if not conf.CheckLibWithHeader(conf.env["wcslib"],
160                                   'wcslib/wcs.h', language='c'):
161        Exit(1)
162    conf.env.AddCustomPackage('rpfits')
163    if not conf.CheckLib(conf.env["rpfitslib"], language="c"):
164        Exit(1)
165
166    # test for blas/lapack
167    lapackname = conf.env.get("lapacklib", "lapack")
168    conf.env.AddCustomPackage("lapack")
169    if not conf.CheckLib(lapackname): Exit(1)
170    blasname = conf.env.get("blaslib", "blas")
171    conf.env.AddCustomPackage("blas")
172    if not conf.CheckLib(blasname): Exit(1)
173    conf.env.CheckFortran(conf)
174    if not conf.CheckLib('stdc++', language='c++'): Exit(1)
175    if conf.env["alma"]:
176        conf.env.Append(CPPFLAGS=['-DUSE_CASAPY'])
177    if not conf.env.get("moduledir"):
178        mdir = get_moduledir(conf.env.get("prefix"))
179        if env["PLATFORM"] == "darwin":
180            mdir = distutils.sysconfig.get_python_lib(1,0)           
181        conf.env["moduledir"] =  mdir
182    env = conf.Finish()
183
184env["version"] = "4.1.x"
185
186if env['mode'] == 'release':
187    if env["PLATFORM"] != "darwin":
188        env.Append(LINKFLAGS=['-Wl,-O1', '-s'])
189    env.Append(CCFLAGS=["-O2"])
190else:
191    env.Append(CCFLAGS=["-g", "-W", "-Wall"])
192
193# Export for SConscript files
194Export("env")
195
196# build externals
197env.SConscript("external-alma/SConscript")
198# build library
199so = env.SConscript("src/SConscript", variant_dir="build", duplicate=0)
200# test module import, to see if there are unresolved symbols
201def test_module(target,source,env):
202    pth = str(target[0])
203    mod = os.path.splitext(pth)[0]
204    sys.path.insert(2, os.path.split(mod)[0])
205    __import__(os.path.split(mod)[1])
206    print "ok"
207    return 0
208def test_str(target, source, env):
209    return "Testing module..."
210
211taction = Action(test_module, test_str)
212env.AddPostAction(so, taction)
213
214# Need this to make makedist work
215dummy = env.Install()
216env.Alias('install', dummy)
217
218# make binary distribution
219env["stagedir"] = "asap-%s" % (env["version"])
220env.Command('Staging distribution for archive in %s' % env["stagedir"],
221            '', env.MessageAction)
222env.QInstall("$stagedir/asap", [so,  env.SGlob("python/*.py")] )
223env.QInstall("$stagedir/bin", ["bin/asap", "bin/asap_update_data"])
224env.QInstall("$stagedir", ["packaging/setup.py"])
225env.QInstall("$stagedir/debian", env.SGlob("packaging/debian/*") )
226
227if env["apps"]:
228    env.SConscript("apps/SConscript")
229
230if env.GetOption("clean"):
231    Execute(Delete(".sconf_temp"))
232
233if env["makedoc"].lower() != "none":
234    env.SConscript("doc/SConscript")
Note: See TracBrowser for help on using the repository browser.