[1125] | 1 | import os |
---|
| 2 | import sys |
---|
[1082] | 3 | import distutils.sysconfig |
---|
| 4 | import platform |
---|
[1184] | 5 | import SCons |
---|
[1125] | 6 | # scons plug-ins |
---|
[1130] | 7 | #from installtree import InstallTree |
---|
[1082] | 8 | |
---|
[1125] | 9 | moduledir = distutils.sysconfig.get_python_lib() |
---|
[1136] | 10 | if platform.architecture()[0] == '64bit': |
---|
| 11 | # hack to install into /usr/lib64 if scons is in the 32bit /usr/lib/ |
---|
| 12 | if moduledir.startswith("/usr/lib/"): |
---|
[1155] | 13 | moduledir = moduledir.replace("lib", "lib64") |
---|
[1082] | 14 | |
---|
[1120] | 15 | opts = Options("userconfig.py") |
---|
[1130] | 16 | opts.AddOptions(PathOption("prefix", |
---|
| 17 | "The root installation path", |
---|
| 18 | distutils.sysconfig.PREFIX), |
---|
[1120] | 19 | PathOption("moduledir", |
---|
| 20 | "The python module path (site-packages))", |
---|
| 21 | moduledir), |
---|
[1130] | 22 | ("rpfitsdir", "Alternative rpfits location.", ""), |
---|
[1138] | 23 | ("cfitsioincdir", "Alternative cfitsio include dir", ""), |
---|
[1135] | 24 | ("casadir", "Alternative casa location", ""), |
---|
[1120] | 25 | EnumOption("mode", "The type of build.", "debug", |
---|
[1135] | 26 | ["release","debug"], ignorecase=1), |
---|
[1177] | 27 | ("makedist", |
---|
[1195] | 28 | "Make a binary archive giving a suffix, e.g. sarge or fc5", |
---|
[1246] | 29 | ""), |
---|
| 30 | EnumOption("makedoc", "Build the userguide in specified format", |
---|
| 31 | "none", |
---|
| 32 | ["none", "pdf", "html"], ignorecase=1) |
---|
[1130] | 33 | ) |
---|
[1082] | 34 | |
---|
[1135] | 35 | env = Environment( toolpath = ['./scons'], |
---|
[1184] | 36 | tools = ["default", "casa", "archiver", "utils", |
---|
| 37 | "quietinstall"], |
---|
[1135] | 38 | ENV = { 'PATH' : os.environ[ 'PATH' ], |
---|
[1120] | 39 | 'HOME' : os.environ[ 'HOME' ] }, |
---|
[1135] | 40 | options = opts) |
---|
[1082] | 41 | |
---|
[1120] | 42 | Help(opts.GenerateHelpText(env)) |
---|
| 43 | env.SConsignFile() |
---|
[1135] | 44 | env.Append(CASAARCH = '', CASAROOT = '') |
---|
[1138] | 45 | if (os.path.exists(env["cfitsioincdir"])): |
---|
| 46 | env.Append(CPPPATH=[env["cfitsioincdir"]]) |
---|
| 47 | env.AddCustomPath(env["rpfitsdir"]) |
---|
[1082] | 48 | if not env.GetOption('clean'): |
---|
[1130] | 49 | conf = Configure(env) |
---|
| 50 | # import Custom tests |
---|
[1135] | 51 | env.AddCasaTest(conf) |
---|
[1130] | 52 | pylib = 'python'+distutils.sysconfig.get_python_version() |
---|
| 53 | pyinc = "Python.h" |
---|
| 54 | if env['PLATFORM'] == "darwin": |
---|
| 55 | pylib = "Python" |
---|
| 56 | if not conf.CheckLib(library=pylib, language='c'): Exit(1) |
---|
| 57 | conf.env.Append(CPPPATH=[distutils.sysconfig.get_python_inc()]) |
---|
| 58 | if not conf.CheckHeader("Python.h", language='c'): |
---|
| 59 | Exit(1) |
---|
| 60 | if not conf.CheckLibWithHeader('boost_python', 'boost/python.hpp', 'c++'): Exit(1) |
---|
| 61 | conf.env.AddCustomPath(env["rpfitsdir"]) |
---|
[1090] | 62 | if not conf.CheckLib('rpfits'): Exit(1) |
---|
[1138] | 63 | # cfitsio is either in include/ or /include/cfitsio |
---|
| 64 | # handle this |
---|
| 65 | if not conf.CheckLib(library='cfitsio', language='c'): Exit(1) |
---|
| 66 | if not conf.CheckHeader('fitsio.h', language='c'): |
---|
| 67 | if not conf.CheckHeader('cfitsio/fitsio.h', language='c'): |
---|
| 68 | Exit(1) |
---|
| 69 | else: |
---|
| 70 | conf.env.Append(CPPPATH=['/usr/include/cfitsio']) |
---|
[1130] | 71 | if (sys.platform == "darwin"): |
---|
| 72 | conf.env.Append(LIBS = ['-framework vecLib']) |
---|
| 73 | else: |
---|
| 74 | if not conf.CheckLib('lapack'): Exit(1) |
---|
| 75 | if not conf.CheckLib('blas'): Exit(1) |
---|
[1105] | 76 | if not conf.CheckLib('g2c'): Exit(1) |
---|
[1130] | 77 | if not conf.CheckLib('stdc++', language='c++'): Exit(1) |
---|
[1127] | 78 | if not conf.CheckCasa(env["casadir"]): Exit(1) |
---|
[1082] | 79 | env = conf.Finish() |
---|
[1120] | 80 | |
---|
[1261] | 81 | env["version"] = "2.1.0" |
---|
[1135] | 82 | |
---|
[1090] | 83 | # general CPPFLAGS |
---|
[1135] | 84 | env.Append(CPPFLAGS=['-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE', '-O3']) |
---|
[1136] | 85 | |
---|
[1090] | 86 | # 64bit flags |
---|
[1082] | 87 | if platform.architecture()[0] == '64bit': |
---|
[1135] | 88 | env.Append(CPPFLAGS=['-fPIC', '-D__x86_64__', '-DAIPS_64B']) |
---|
[1136] | 89 | |
---|
[1120] | 90 | if env['mode'] == 'release': |
---|
| 91 | env.Append(LINKFLAGS=['-Wl,-O1']) |
---|
[1184] | 92 | |
---|
| 93 | # Export for SConscript files |
---|
[1135] | 94 | Export("env") |
---|
[1082] | 95 | |
---|
[1184] | 96 | # build library |
---|
[1082] | 97 | so = env.SConscript("src/SConscript", build_dir="build", duplicate=0) |
---|
[1195] | 98 | # test module import, to see if there are unresolved symbols |
---|
| 99 | def test_module(target,source,env): |
---|
| 100 | pth = str(target[0]) |
---|
| 101 | mod = os.path.splitext(pth)[0] |
---|
| 102 | sys.path.insert(2, os.path.split(mod)[0]) |
---|
| 103 | __import__(os.path.split(mod)[1]) |
---|
| 104 | print "ok" |
---|
| 105 | return 0 |
---|
| 106 | def test_str(target, source, env): |
---|
| 107 | return "Testing module..." |
---|
[1184] | 108 | |
---|
[1195] | 109 | taction = Action(test_module, test_str) |
---|
| 110 | env.AddPostAction(so, taction) |
---|
| 111 | |
---|
[1184] | 112 | # install targets |
---|
| 113 | somod = env.Install("$moduledir/asap", so ) |
---|
| 114 | pymods = env.Install("$moduledir/asap", env.SGlob("python/*.py")) |
---|
| 115 | bins = env.Install("$prefix/bin", ["bin/asap", "bin/asap_update_data"]) |
---|
[1187] | 116 | shares = env.Install("$moduledir/asap/data", "share/ipythonrc-asap") |
---|
[1184] | 117 | env.Alias('install', [somod, pymods, bins, shares]) |
---|
| 118 | |
---|
| 119 | # install aips++ data repos |
---|
| 120 | rootdir=None |
---|
| 121 | outdir = os.path.join(env["moduledir"],'asap','data') |
---|
| 122 | sources = ['ephemerides','geodetic'] |
---|
| 123 | if os.path.exists("/nfs/aips++/data"): |
---|
| 124 | rootdir = "/nfs/aips++/data" |
---|
| 125 | elif os.path.exists("data"): |
---|
[1195] | 126 | rootdir = "./data" |
---|
[1184] | 127 | if rootdir is not None: |
---|
| 128 | ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources) |
---|
| 129 | data = env.InstallAs(ofiles, ifiles) |
---|
| 130 | env.Alias('install', data) |
---|
[1201] | 131 | |
---|
[1177] | 132 | # make binary distribution |
---|
| 133 | if len(env["makedist"]): |
---|
[1184] | 134 | env["stagedir"] = "asap-%s-%s" % (env["version"], env["makedist"]) |
---|
| 135 | env.Command('Staging distribution for archive in %s' % env["stagedir"], |
---|
| 136 | '', env.MessageAction) |
---|
[1195] | 137 | st0 = env.QInstall("$stagedir/asap", [so, env.SGlob("python/*.py")] ) |
---|
[1184] | 138 | env.QInstall("$stagedir/bin", ["bin/asap", "bin/asap_update_data"]) |
---|
[1195] | 139 | env.QInstall("$stagedir", ["bin/install"]) |
---|
| 140 | env.QInstall("$stagedir/asap/data", "share/ipythonrc-asap") |
---|
| 141 | if rootdir is not None: |
---|
[1201] | 142 | # This creates a directory Using data table... - disabled |
---|
| 143 | #env.Command("Using data tables in %s" % rootdir, |
---|
| 144 | # '', env.MessageAction) |
---|
[1184] | 145 | outdir = os.path.join(env["stagedir"],'asap','data') |
---|
| 146 | ofiles, ifiles = env.WalkDirTree(outdir, rootdir, sources) |
---|
| 147 | env.QInstallAs(ofiles, ifiles) |
---|
[1195] | 148 | else: |
---|
| 149 | env.Command("No data tables available. Use 'asap_update_data' after install", |
---|
[1201] | 150 | '', env.MessageAction) |
---|
[1184] | 151 | arch = env.Archiver(os.path.join("dist",env["stagedir"]), |
---|
| 152 | env["stagedir"]) |
---|
| 153 | env.AddPostAction(arch, Delete("$stagedir")) |
---|
[1246] | 154 | if env["makedoc"].lower() != "none": |
---|
| 155 | env.SConscript("doc/SConscript") |
---|
[1195] | 156 | |
---|
| 157 | if env.GetOption("clean"): |
---|
| 158 | Execute(Delete(".sconf_temp")) |
---|