| 1 |
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
import platform
|
| 5 |
import ConfigParser
|
| 6 |
|
| 7 |
|
| 8 |
_platdir = 'platform'
|
| 9 |
|
| 10 |
|
| 11 |
def read_plat(env, args, fn):
|
| 12 |
envdict = env.Dictionary().copy()
|
| 13 |
# can't feed ConfigParser the original dict, because it also
|
| 14 |
# contains non-string values.
|
| 15 |
for k,v in envdict.items():
|
| 16 |
if not isinstance(v, str):
|
| 17 |
del envdict[k]
|
| 18 |
cfig = ConfigParser.ConfigParser(envdict)
|
| 19 |
cfig.read(fn)
|
| 20 |
buildvars = [['CC',
|
| 21 |
'TIFFINCLUDE', # where to find preinstalled tifflib headers
|
| 22 |
'TIFFLIB', # where to find a preinstalled tifflib library
|
| 23 |
], # replace
|
| 24 |
['CPPPATH', 'CPPDEFINES', 'CPPFLAGS', 'CCFLAGS',
|
| 25 |
'LIBPATH', 'LINKFLAGS',
|
| 26 |
'EZXML_CPPDEFINES', # build flags specific to ezxml.c
|
| 27 |
]] # append
|
| 28 |
vars = [
|
| 29 |
['install',
|
| 30 |
['RAD_BASEDIR', 'RAD_BINDIR', 'RAD_RLIBDIR', 'RAD_MANDIR'],
|
| 31 |
[]],
|
| 32 |
['code',
|
| 33 |
[ # replace
|
| 34 |
],
|
| 35 |
[ # append
|
| 36 |
'RAD_COMPAT', # theoretically obsolete (src/common/strcmp.c)
|
| 37 |
'RAD_MATHCOMPAT', # erf.c floating point error function
|
| 38 |
'RAD_ARGSCOMPAT', # fixargv0.c for Windows
|
| 39 |
'RAD_NETCOMPAT', # [win_]netproc.c for ranimate
|
| 40 |
'RAD_MLIB', # usually 'm', or any fastlib available
|
| 41 |
'RAD_SOCKETLIB', # ws_2_32 on Windows (VC links it automatically)
|
| 42 |
'RAD_PROCESS', # our process abstraction and win_popen()
|
| 43 |
'RAD_PCALLS', # more custom process abstraction
|
| 44 |
]],
|
| 45 |
]
|
| 46 |
if args.get('RAD_DEBUG',0):
|
| 47 |
vars.insert(0, ['debug'] + buildvars)
|
| 48 |
else: vars.insert(0, ['build'] + buildvars)
|
| 49 |
for section in vars:
|
| 50 |
if cfig.has_section(section[0]):
|
| 51 |
for p in section[1]: # single items to replace
|
| 52 |
try: v = cfig.get(section[0], p)
|
| 53 |
except ConfigParser.NoOptionError: continue
|
| 54 |
if section[0] == 'install' and '{' in v:
|
| 55 |
try:
|
| 56 |
vv = v.format(**os.environ)
|
| 57 |
except KeyError: vv = v
|
| 58 |
else: v = vv
|
| 59 |
env[p] = v
|
| 60 |
#print('%s: %s' % (p, env[p]))
|
| 61 |
for p in section[2]: # multiple items to append
|
| 62 |
try: v = cfig.get(section[0], p)
|
| 63 |
except ConfigParser.NoOptionError: continue
|
| 64 |
apply(env.Append,[],{p:env.Split(v)})
|
| 65 |
# XXX Check that basedir exists.
|
| 66 |
for k in ['RAD_BINDIR', 'RAD_RLIBDIR', 'RAD_MANDIR']:
|
| 67 |
if (env.has_key('RAD_BASEDIR') and env.has_key(k)
|
| 68 |
and not os.path.isabs(env[k])):
|
| 69 |
env[k] = os.path.join(env['RAD_BASEDIR'],env[k])
|
| 70 |
|
| 71 |
|
| 72 |
def load_plat(env, args, arch=None):
|
| 73 |
cfgname = 'posix'
|
| 74 |
memmodel, binformat = platform.architecture()
|
| 75 |
platsys = platform.system()
|
| 76 |
print 'Detected platform "%s" (%s).' % (platsys, memmodel)
|
| 77 |
cfgname = platsys + '_' + memmodel[:2]
|
| 78 |
env['RAD_BUILDBIN'] = os.path.join('#scbuild', cfgname, 'bin')
|
| 79 |
env['RAD_BUILDLIB'] = os.path.join('#scbuild', cfgname, 'lib')
|
| 80 |
env['RAD_BUILDOBJ'] = os.path.join('#scbuild', cfgname, 'obj')
|
| 81 |
|
| 82 |
pfn = os.path.join(_platdir, cfgname + '_custom.cfg')
|
| 83 |
if os.path.isfile(pfn):
|
| 84 |
print 'Reading configuration "%s"' % pfn
|
| 85 |
read_plat(env, args, pfn)
|
| 86 |
return 1
|
| 87 |
pfn = os.path.join(_platdir, cfgname + '.cfg')
|
| 88 |
if os.path.isfile(pfn):
|
| 89 |
print 'Reading configuration "%s"' % pfn
|
| 90 |
read_plat(env, args, pfn)
|
| 91 |
return 1
|
| 92 |
|
| 93 |
if os.name == 'posix':
|
| 94 |
pfn = os.path.join(_platdir, 'posix.cfg')
|
| 95 |
if os.path.isfile(pfn):
|
| 96 |
print 'Reading generic configuration "%s".' % pfn
|
| 97 |
read_plat(env, args, pfn)
|
| 98 |
return 1
|
| 99 |
|
| 100 |
print 'Platform "%s", system "%s" not supported yet' % (os.name, sys.platform)
|
| 101 |
sys.exit(2)
|
| 102 |
|
| 103 |
|
| 104 |
|