1 |
schorsch |
1.16 |
from __future__ import print_function |
2 |
schorsch |
1.1 |
|
3 |
|
|
import os |
4 |
|
|
import sys |
5 |
schorsch |
1.16 |
import re |
6 |
schorsch |
1.14 |
import platform |
7 |
schorsch |
1.1 |
import ConfigParser |
8 |
|
|
|
9 |
|
|
|
10 |
|
|
_platdir = 'platform' |
11 |
|
|
|
12 |
|
|
|
13 |
schorsch |
1.2 |
def read_plat(env, args, fn): |
14 |
schorsch |
1.13 |
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 |
schorsch |
1.1 |
cfig.read(fn) |
22 |
schorsch |
1.12 |
buildvars = [['CC', |
23 |
|
|
'TIFFINCLUDE', # where to find preinstalled tifflib headers |
24 |
|
|
'TIFFLIB', # where to find a preinstalled tifflib library |
25 |
|
|
], # replace |
26 |
schorsch |
1.3 |
['CPPPATH', 'CPPDEFINES', 'CPPFLAGS', 'CCFLAGS', |
27 |
schorsch |
1.11 |
'LIBPATH', 'LINKFLAGS', |
28 |
|
|
'EZXML_CPPDEFINES', # build flags specific to ezxml.c |
29 |
|
|
]] # append |
30 |
schorsch |
1.1 |
vars = [ |
31 |
|
|
['install', |
32 |
|
|
['RAD_BASEDIR', 'RAD_BINDIR', 'RAD_RLIBDIR', 'RAD_MANDIR'], |
33 |
|
|
[]], |
34 |
|
|
['code', |
35 |
schorsch |
1.12 |
[ # replace |
36 |
|
|
], |
37 |
schorsch |
1.7 |
[ # append |
38 |
schorsch |
1.11 |
'RAD_COMPAT', # theoretically obsolete (src/common/strcmp.c) |
39 |
schorsch |
1.7 |
'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 |
schorsch |
1.10 |
'RAD_PROCESS', # our process abstraction and win_popen() |
45 |
|
|
'RAD_PCALLS', # more custom process abstraction |
46 |
|
|
]], |
47 |
schorsch |
1.1 |
] |
48 |
schorsch |
1.16 |
if env.get('RAD_DEBUG',0) not in(0,'0','','n','no','false',None): |
49 |
schorsch |
1.2 |
vars.insert(0, ['debug'] + buildvars) |
50 |
schorsch |
1.16 |
print('Processing DEBUG version') |
51 |
|
|
else: |
52 |
|
|
vars.insert(0, ['build'] + buildvars) |
53 |
|
|
print('Processing RELEASE version') |
54 |
schorsch |
1.1 |
for section in vars: |
55 |
|
|
if cfig.has_section(section[0]): |
56 |
schorsch |
1.7 |
for p in section[1]: # single items to replace |
57 |
schorsch |
1.1 |
try: v = cfig.get(section[0], p) |
58 |
|
|
except ConfigParser.NoOptionError: continue |
59 |
schorsch |
1.16 |
if section[0] in ('install','build','debug') and '{' in v: |
60 |
|
|
v = subst_osenvvars(v) |
61 |
schorsch |
1.1 |
env[p] = v |
62 |
schorsch |
1.15 |
#print('%s: %s' % (p, env[p])) |
63 |
schorsch |
1.7 |
for p in section[2]: # multiple items to append |
64 |
schorsch |
1.16 |
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 |
schorsch |
1.1 |
except ConfigParser.NoOptionError: continue |
70 |
schorsch |
1.9 |
apply(env.Append,[],{p:env.Split(v)}) |
71 |
schorsch |
1.1 |
# 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 |
schorsch |
1.16 |
def subst_osenvvars(s): |
78 |
|
|
try: return s.format(**os.environ) |
79 |
|
|
except KeyError: return s |
80 |
|
|
|
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 |
schorsch |
1.1 |
|
97 |
schorsch |
1.15 |
def load_plat(env, args, arch=None): |
98 |
|
|
memmodel, binformat = platform.architecture() |
99 |
|
|
platsys = platform.system() |
100 |
schorsch |
1.16 |
print('Detected platform "%s" (%s).' % (platsys, memmodel)) |
101 |
schorsch |
1.15 |
cfgname = platsys + '_' + memmodel[:2] |
102 |
schorsch |
1.16 |
|
103 |
schorsch |
1.15 |
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 |
schorsch |
1.16 |
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 |
schorsch |
1.15 |
return 1 |
112 |
|
|
pfn = os.path.join(_platdir, cfgname + '.cfg') |
113 |
|
|
if os.path.isfile(pfn): |
114 |
schorsch |
1.16 |
print('Reading configuration "%s"' % pfn) |
115 |
schorsch |
1.15 |
read_plat(env, args, pfn) |
116 |
|
|
return 1 |
117 |
|
|
|
118 |
schorsch |
1.1 |
if os.name == 'posix': |
119 |
|
|
pfn = os.path.join(_platdir, 'posix.cfg') |
120 |
|
|
if os.path.isfile(pfn): |
121 |
schorsch |
1.16 |
print('No platform specific configuration found.\n') |
122 |
|
|
print('Reading generic configuration "%s".' % pfn) |
123 |
schorsch |
1.2 |
read_plat(env, args, pfn) |
124 |
schorsch |
1.1 |
return 1 |
125 |
|
|
|
126 |
schorsch |
1.16 |
print('Platform "%s", system "%s" not supported yet' |
127 |
|
|
% (os.name, sys.platform)) |
128 |
schorsch |
1.1 |
sys.exit(2) |
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|