[1437] | 1 | import sys
|
---|
[1176] | 2 | import os
|
---|
[1135] | 3 | import glob
|
---|
[1437] | 4 | import re
|
---|
| 5 | import platform
|
---|
[1135] | 6 |
|
---|
[2517] | 7 | def get_libdir():
|
---|
| 8 | import distutils.sysconfig
|
---|
| 9 | return os.path.basename(distutils.sysconfig.get_config_var('LIBDIR'))
|
---|
| 10 |
|
---|
| 11 | LIBDIR = "lib" #get_libdir()
|
---|
| 12 |
|
---|
[1135] | 13 | def generate(env):
|
---|
[1437] | 14 |
|
---|
| 15 | def SGlob(pattern, excludedirs=[], recursive=False):
|
---|
| 16 | # always exclude .svn
|
---|
| 17 | excludedirs.append(".svn")
|
---|
| 18 | path = env.GetBuildPath('SConscript').replace('SConscript', '')
|
---|
| 19 | if recursive:
|
---|
| 20 | # remove '*' from pattern is accidentally specified
|
---|
| 21 | pattern=pattern.replace("*", "")
|
---|
| 22 | out = []
|
---|
| 23 | for d, ld, fls in os.walk(path):
|
---|
| 24 | # remove directorys to be excluded
|
---|
| 25 | for exd in excludedirs:
|
---|
| 26 | if exd in ld:
|
---|
| 27 | ld.remove(exd)
|
---|
| 28 | for f in fls:
|
---|
| 29 | if f.endswith(pattern):
|
---|
| 30 | drel=d.replace(path,"")
|
---|
| 31 | out.append(os.path.join(drel,f))
|
---|
| 32 | return out
|
---|
| 33 | else:
|
---|
| 34 | return [ i.replace(path, '') for i in glob.glob(path + pattern) ]
|
---|
[1135] | 35 | env.SGlob = SGlob
|
---|
| 36 |
|
---|
[1437] | 37 | def AddCustomPath(path=None):
|
---|
| 38 | if path is None or not os.path.exists(path):
|
---|
| 39 | env.Exit(1)
|
---|
[1135] | 40 | env.PrependUnique(CPPPATH = [os.path.join(path, "include")])
|
---|
[2517] | 41 | env.PrependUnique(LIBPATH = [os.path.join(path, LIBDIR)])
|
---|
[1135] | 42 | env.AddCustomPath = AddCustomPath
|
---|
| 43 |
|
---|
[1325] | 44 | def AddCustomPackage(pkgname=None):
|
---|
| 45 | if pkgname is None:
|
---|
[1437] | 46 | return
|
---|
| 47 | pkgroot = env.get("%sroot" % pkgname, None)
|
---|
| 48 | pkgincd = env.get("%sincdir" % pkgname, None)
|
---|
| 49 | pkglibd = env.get("%slibdir" % pkgname, None)
|
---|
| 50 | incd = None
|
---|
| 51 | libd = None
|
---|
| 52 | if pkgroot is not None:
|
---|
| 53 | incd = os.path.join(pkgroot, "include")
|
---|
[2517] | 54 | libd = os.path.join(pkgroot, LIBDIR)
|
---|
[1437] | 55 | else:
|
---|
| 56 | if pkgincd is not None:
|
---|
| 57 | incd = pkgincd
|
---|
| 58 | if pkglibd is not None:
|
---|
| 59 | libd = pkglibd
|
---|
| 60 | if incd is not None:
|
---|
| 61 | if not os.path.exists(incd):
|
---|
| 62 | print "Custom %s include dir '%s' not found" % (pkgname, incd)
|
---|
| 63 | env.Exit(1)
|
---|
| 64 | env.PrependUnique(CPPPATH = [incd])
|
---|
| 65 | if libd is not None:
|
---|
| 66 | if not os.path.exists(libd):
|
---|
| 67 | print "Custom %s lib dir '%s' not found" % (pkgname, libd)
|
---|
| 68 | env.Exit(1)
|
---|
| 69 | env.PrependUnique(LIBPATH = [libd])
|
---|
[1325] | 70 |
|
---|
| 71 | env.AddCustomPackage = AddCustomPackage
|
---|
| 72 |
|
---|
[1437] | 73 | def PlatformIdent():
|
---|
| 74 | p = sys.platform
|
---|
| 75 | # replace the trailing 2 in linux2
|
---|
| 76 | p = re.sub(re.compile("2$"), "", p)
|
---|
| 77 | return p + "_" + platform.machine()
|
---|
| 78 | env.PlatformIdent = PlatformIdent
|
---|
| 79 |
|
---|
| 80 | def MergeFlags():
|
---|
| 81 | def _to_list(xf):
|
---|
| 82 | if xf.count(","):
|
---|
| 83 | return xf.split(",")
|
---|
| 84 | return xf.split()
|
---|
| 85 |
|
---|
| 86 | xf=env.get("extracppflags", None)
|
---|
| 87 | if xf:
|
---|
| 88 | env.AppendUnique(CPPFLAGS=_to_list(xf))
|
---|
| 89 | xf=env.get("extralinkflags", None)
|
---|
| 90 | if xf:
|
---|
| 91 | env.AppendUnique(LINKFLAGS=_to_list(xf))
|
---|
| 92 | env.AppendUnique(SHLINKFLAGS=_to_list(xf))
|
---|
| 93 | xf=env.get("extracxxflags", None)
|
---|
| 94 | if xf:
|
---|
| 95 | env.AppendUnique(CXXFLAGS=_to_list(xf))
|
---|
| 96 | xf=env.get("extrafflags", None)
|
---|
| 97 | if xf:
|
---|
| 98 | env.AppendUnique(FORTRANFLAGS=_to_list(xf))
|
---|
| 99 | env.AppendUnique(SHFORTRANFLAGS=_to_list(xf))
|
---|
| 100 | xf=env.get("extracflags", None)
|
---|
| 101 | if xf:
|
---|
| 102 | env.AppendUnique(CCFLAGS=_to_list(xf))
|
---|
| 103 | # set the extra flags if available
|
---|
| 104 | MergeFlags()
|
---|
| 105 |
|
---|
[1325] | 106 | def CheckFortran(conf):
|
---|
[1437] | 107 |
|
---|
| 108 | def getf2clib(fc):
|
---|
[1325] | 109 | fdict = {'gfortran': 'gfortran', 'g77': 'g2c', 'f77': 'f2c'}
|
---|
[1437] | 110 | return fdict[fc]
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | if not conf.env.has_key("FORTRAN"):
|
---|
| 114 | # auto-detect fortran
|
---|
| 115 | detect_fortran = conf.env.Detect(['gfortran', 'g77', 'f77'])
|
---|
| 116 | conf.env["FORTRAN"] = detect_fortran
|
---|
| 117 | f2clib = conf.env.get("f2clib", getf2clib(conf.env["FORTRAN"]))
|
---|
| 118 | if not conf.CheckLib(f2clib):
|
---|
| 119 | conf.env.Exit(1)
|
---|
| 120 |
|
---|
| 121 | if conf.env["FORTRAN"].startswith("g77"):
|
---|
[1325] | 122 | fflags = ["-Wno-globals", "-fno-second-underscore"]
|
---|
[1437] | 123 | conf.env.AppendUnique(SHFORTRANFLAGS=fflags)
|
---|
| 124 | conf.env.AppendUnique(FORTRANFLAGS=fflags)
|
---|
| 125 | conf.env.AppendUnique(SHFORTRANFLAGS=['-fPIC'])
|
---|
| 126 |
|
---|
[1325] | 127 | env.CheckFortran = CheckFortran
|
---|
| 128 |
|
---|
[1465] | 129 | def WalkDirTree(targetroot, sourceroot, sources):
|
---|
| 130 | ifiles = []
|
---|
| 131 | ofiles = []
|
---|
| 132 | for s in sources:
|
---|
| 133 | if os.path.isdir(os.path.join(sourceroot ,s)):
|
---|
| 134 | for d,ld,f in os.walk(os.path.join(sourceroot ,s)):
|
---|
| 135 | for fl in f:
|
---|
| 136 | ifile = os.path.join(d, fl)
|
---|
| 137 | ifiles.append(ifile)
|
---|
| 138 | ofile = ifile.replace(sourceroot, targetroot)
|
---|
| 139 | ofiles.append(ofile)
|
---|
| 140 | return ofiles, ifiles
|
---|
| 141 | env.WalkDirTree = WalkDirTree
|
---|
| 142 |
|
---|
| 143 |
|
---|
[1184] | 144 | def null_action(target, source, env): return 0
|
---|
[1176] | 145 |
|
---|
[1184] | 146 | def message(target, source, env):
|
---|
| 147 | return "%s" % target[0]
|
---|
| 148 | env.MessageAction = env.Action(null_action, message)
|
---|
| 149 |
|
---|
[1135] | 150 | def exists(env):
|
---|
[1176] | 151 | try:
|
---|
| 152 | import os
|
---|
| 153 | import glob
|
---|
| 154 | except ImportError:
|
---|
| 155 | return False
|
---|
| 156 | else:
|
---|
| 157 | return True
|
---|