ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/build_utils/load_plat.py
Revision: 1.18
Committed: Tue Apr 19 21:21:23 2016 UTC (8 years ago) by schorsch
Content type: text/x-python
Branch: MAIN
CVS Tags: rad5R1
Changes since 1.17: +6 -5 lines
Log Message:
Build with VC2013 until text pipe bug is fixed; prepare for pyinstaller on scripts

File Contents

# Content
1 from __future__ import print_function
2
3 import os
4 import sys
5 import re
6 import platform
7 import ConfigParser
8
9
10 _platdir = 'platform'
11
12
13 def read_plat(env, fn):
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',
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 '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 [ # 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 env.get('RAD_DEBUG',0) not in(0,'0','','n','no','false',None):
49 vars.insert(0, ['debug'] + 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]: # 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]: # 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: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 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):
98 memmodel, binformat = platform.architecture()
99 # XXX env['TARGET_ARCH'] --> memmodel
100 platsys = platform.system()
101 print('Detected platform "%s" (%s).' % (platsys, memmodel))
102 cfgname = platsys + '_' + memmodel[:2]
103
104 env['RAD_BUILDBIN'] = os.path.join('#scbuild', cfgname, 'bin')
105 env['RAD_BUILDLIB'] = os.path.join('#scbuild', cfgname, 'lib')
106 env['RAD_BUILDOBJ'] = os.path.join('#scbuild', cfgname, 'obj')
107
108 cust_pfn = os.path.join(_platdir, cfgname + '_custom.cfg')
109 if os.path.isfile(cust_pfn):
110 print('Reading configuration "%s"' % cust_pfn)
111 read_plat(env, cust_pfn)
112 return 1
113 pfn = os.path.join(_platdir, cfgname + '.cfg')
114 if os.path.isfile(pfn):
115 print('Reading configuration "%s"' % pfn)
116 read_plat(env, pfn)
117 return 1
118
119 if os.name == 'posix':
120 pfn = os.path.join(_platdir, 'posix.cfg')
121 if os.path.isfile(pfn):
122 print('No platform specific configuration found.\n')
123 print('Reading generic configuration "%s".' % pfn)
124 read_plat(env, pfn)
125 return 1
126
127 print('Platform "%s", system "%s" not supported yet'
128 % (os.name, sys.platform))
129 sys.exit(2)
130
131
132