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