1 |
schorsch |
1.1 |
|
2 |
|
|
import os |
3 |
|
|
import sys |
4 |
|
|
import ConfigParser |
5 |
|
|
|
6 |
|
|
|
7 |
|
|
_platdir = 'platform' |
8 |
|
|
|
9 |
|
|
|
10 |
schorsch |
1.2 |
def read_plat(env, args, fn): |
11 |
schorsch |
1.1 |
cfig = ConfigParser.ConfigParser(env.Dictionary()) |
12 |
|
|
cfig.read(fn) |
13 |
schorsch |
1.2 |
buildvars = [['CC'], # replace |
14 |
schorsch |
1.3 |
['CPPPATH', 'CPPDEFINES', 'CPPFLAGS', 'CCFLAGS', |
15 |
|
|
'LIBPATH', 'LINKFLAGS']] # append |
16 |
schorsch |
1.1 |
vars = [ |
17 |
|
|
['install', |
18 |
|
|
['RAD_BASEDIR', 'RAD_BINDIR', 'RAD_RLIBDIR', 'RAD_MANDIR'], |
19 |
|
|
[]], |
20 |
|
|
['code', |
21 |
schorsch |
1.7 |
[], # replace |
22 |
|
|
[ # append |
23 |
|
|
'RAD_COMPAT', # currently obsolete |
24 |
|
|
'RAD_MATHCOMPAT', # erf.c floating point error function |
25 |
|
|
'RAD_ARGSCOMPAT', # fixargv0.c for Windows |
26 |
|
|
'RAD_NETCOMPAT', # [win_]netproc.c for ranimate |
27 |
|
|
'RAD_MLIB', # usually 'm', or any fastlib available |
28 |
|
|
'RAD_SOCKETLIB', # ws_2_32 on Windows (VC links it automatically) |
29 |
|
|
'RAD_PROCESS']], # our process abstraction and win_popen() |
30 |
schorsch |
1.1 |
] |
31 |
schorsch |
1.2 |
if args.get('RAD_DEBUG',0): |
32 |
|
|
vars.insert(0, ['debug'] + buildvars) |
33 |
|
|
else: vars.insert(0, ['build'] + buildvars) |
34 |
schorsch |
1.1 |
for section in vars: |
35 |
|
|
if cfig.has_section(section[0]): |
36 |
schorsch |
1.7 |
for p in section[1]: # single items to replace |
37 |
schorsch |
1.1 |
try: v = cfig.get(section[0], p) |
38 |
|
|
except ConfigParser.NoOptionError: continue |
39 |
|
|
env[p] = v |
40 |
|
|
#print '%s: %s' % (p, env[p]) |
41 |
schorsch |
1.7 |
for p in section[2]: # multiple items to append |
42 |
schorsch |
1.1 |
try: v = cfig.get(section[0], p) |
43 |
|
|
except ConfigParser.NoOptionError: continue |
44 |
schorsch |
1.8 |
apply(env.Append,[],{p:`v`.split()}) |
45 |
schorsch |
1.1 |
#print '%s: %s' % (p, env[p]) |
46 |
|
|
# XXX Check that basedir exists. |
47 |
|
|
for k in ['RAD_BINDIR', 'RAD_RLIBDIR', 'RAD_MANDIR']: |
48 |
|
|
if (env.has_key('RAD_BASEDIR') and env.has_key(k) |
49 |
|
|
and not os.path.isabs(env[k])): |
50 |
|
|
env[k] = os.path.join(env['RAD_BASEDIR'],env[k]) |
51 |
|
|
|
52 |
|
|
|
53 |
schorsch |
1.2 |
def load_plat(env, args, platform=None): |
54 |
schorsch |
1.1 |
if platform == None: # override |
55 |
|
|
p = sys.platform |
56 |
|
|
else: p = platform |
57 |
schorsch |
1.4 |
if p == 'win32' and 'gcc' in env['TOOLS']: |
58 |
schorsch |
1.7 |
# we don't really want to know this here... |
59 |
schorsch |
1.4 |
p = 'mingw' |
60 |
schorsch |
1.1 |
pl = [] |
61 |
|
|
print 'Detected platform "%s" (%s).' % (sys.platform, os.name) |
62 |
|
|
for i in [len(p), -1, -2]: |
63 |
|
|
pfn = os.path.join(_platdir, p[:i] + '_custom.cfg') |
64 |
|
|
if os.path.isfile(pfn): |
65 |
|
|
print 'Reading configuration "%s"' % pfn |
66 |
schorsch |
1.2 |
read_plat(env, args, pfn) |
67 |
schorsch |
1.1 |
return 1 |
68 |
|
|
pfn = os.path.join(_platdir, p[:i] + '.cfg') |
69 |
|
|
if os.path.isfile(pfn): |
70 |
|
|
print 'Reading configuration "%s"' % pfn |
71 |
schorsch |
1.2 |
read_plat(env, args, pfn) |
72 |
schorsch |
1.1 |
return 1 |
73 |
|
|
|
74 |
|
|
if os.name == 'posix': |
75 |
|
|
pfn = os.path.join(_platdir, 'posix.cfg') |
76 |
|
|
if os.path.isfile(pfn): |
77 |
|
|
print 'Reading generic configuration "%s".' % pfn |
78 |
schorsch |
1.2 |
read_plat(env, args, pfn) |
79 |
schorsch |
1.1 |
return 1 |
80 |
|
|
|
81 |
|
|
print 'Platform "%s/%s" not supported yet' % (os.name, sys.platform) |
82 |
|
|
sys.exit(2) |
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|