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