1 |
schorsch |
1.1 |
|
2 |
|
|
import os |
3 |
|
|
import sys |
4 |
schorsch |
1.14 |
import platform |
5 |
schorsch |
1.1 |
import ConfigParser |
6 |
|
|
|
7 |
|
|
|
8 |
|
|
_platdir = 'platform' |
9 |
|
|
|
10 |
|
|
|
11 |
schorsch |
1.2 |
def read_plat(env, args, fn): |
12 |
schorsch |
1.13 |
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 |
schorsch |
1.1 |
cfig.read(fn) |
20 |
schorsch |
1.12 |
buildvars = [['CC', |
21 |
|
|
'TIFFINCLUDE', # where to find preinstalled tifflib headers |
22 |
|
|
'TIFFLIB', # where to find a preinstalled tifflib library |
23 |
|
|
], # replace |
24 |
schorsch |
1.3 |
['CPPPATH', 'CPPDEFINES', 'CPPFLAGS', 'CCFLAGS', |
25 |
schorsch |
1.11 |
'LIBPATH', 'LINKFLAGS', |
26 |
|
|
'EZXML_CPPDEFINES', # build flags specific to ezxml.c |
27 |
|
|
]] # append |
28 |
schorsch |
1.1 |
vars = [ |
29 |
|
|
['install', |
30 |
|
|
['RAD_BASEDIR', 'RAD_BINDIR', 'RAD_RLIBDIR', 'RAD_MANDIR'], |
31 |
|
|
[]], |
32 |
|
|
['code', |
33 |
schorsch |
1.12 |
[ # replace |
34 |
|
|
], |
35 |
schorsch |
1.7 |
[ # append |
36 |
schorsch |
1.11 |
'RAD_COMPAT', # theoretically obsolete (src/common/strcmp.c) |
37 |
schorsch |
1.7 |
'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 |
schorsch |
1.10 |
'RAD_PROCESS', # our process abstraction and win_popen() |
43 |
|
|
'RAD_PCALLS', # more custom process abstraction |
44 |
|
|
]], |
45 |
schorsch |
1.1 |
] |
46 |
schorsch |
1.2 |
if args.get('RAD_DEBUG',0): |
47 |
|
|
vars.insert(0, ['debug'] + buildvars) |
48 |
|
|
else: vars.insert(0, ['build'] + buildvars) |
49 |
schorsch |
1.1 |
for section in vars: |
50 |
|
|
if cfig.has_section(section[0]): |
51 |
schorsch |
1.7 |
for p in section[1]: # single items to replace |
52 |
schorsch |
1.1 |
try: v = cfig.get(section[0], p) |
53 |
|
|
except ConfigParser.NoOptionError: continue |
54 |
|
|
env[p] = v |
55 |
|
|
#print '%s: %s' % (p, env[p]) |
56 |
schorsch |
1.7 |
for p in section[2]: # multiple items to append |
57 |
schorsch |
1.1 |
try: v = cfig.get(section[0], p) |
58 |
|
|
except ConfigParser.NoOptionError: continue |
59 |
schorsch |
1.9 |
apply(env.Append,[],{p:env.Split(v)}) |
60 |
schorsch |
1.1 |
# XXX Check that basedir exists. |
61 |
|
|
for k in ['RAD_BINDIR', 'RAD_RLIBDIR', 'RAD_MANDIR']: |
62 |
|
|
if (env.has_key('RAD_BASEDIR') and env.has_key(k) |
63 |
|
|
and not os.path.isabs(env[k])): |
64 |
|
|
env[k] = os.path.join(env['RAD_BASEDIR'],env[k]) |
65 |
|
|
|
66 |
|
|
|
67 |
schorsch |
1.14 |
def load_plat(env, args, ourplat=None): |
68 |
|
|
if ourplat == None: # override |
69 |
schorsch |
1.1 |
p = sys.platform |
70 |
schorsch |
1.14 |
else: p = ourplat |
71 |
|
|
# if p == 'win32' and platform.architecture()[0] == '64bit': |
72 |
|
|
# p = 'win64' |
73 |
schorsch |
1.4 |
if p == 'win32' and 'gcc' in env['TOOLS']: |
74 |
schorsch |
1.7 |
# we don't really want to know this here... |
75 |
schorsch |
1.4 |
p = 'mingw' |
76 |
schorsch |
1.1 |
pl = [] |
77 |
|
|
print 'Detected platform "%s" (%s).' % (sys.platform, os.name) |
78 |
|
|
for i in [len(p), -1, -2]: |
79 |
|
|
pfn = os.path.join(_platdir, p[:i] + '_custom.cfg') |
80 |
|
|
if os.path.isfile(pfn): |
81 |
|
|
print 'Reading configuration "%s"' % pfn |
82 |
schorsch |
1.2 |
read_plat(env, args, pfn) |
83 |
schorsch |
1.1 |
return 1 |
84 |
|
|
pfn = os.path.join(_platdir, p[:i] + '.cfg') |
85 |
|
|
if os.path.isfile(pfn): |
86 |
|
|
print 'Reading configuration "%s"' % pfn |
87 |
schorsch |
1.2 |
read_plat(env, args, pfn) |
88 |
schorsch |
1.1 |
return 1 |
89 |
|
|
|
90 |
|
|
if os.name == 'posix': |
91 |
|
|
pfn = os.path.join(_platdir, 'posix.cfg') |
92 |
|
|
if os.path.isfile(pfn): |
93 |
|
|
print 'Reading generic configuration "%s".' % pfn |
94 |
schorsch |
1.2 |
read_plat(env, args, pfn) |
95 |
schorsch |
1.1 |
return 1 |
96 |
|
|
|
97 |
|
|
print 'Platform "%s/%s" not supported yet' % (os.name, sys.platform) |
98 |
|
|
sys.exit(2) |
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|