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