ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/build_utils/load_plat.py
(Generate patch)

Comparing ray/build_utils/load_plat.py (file contents):
Revision 1.9 by schorsch, Wed Jun 7 12:25:36 2006 UTC vs.
Revision 1.16 by schorsch, Thu Mar 10 17:36:18 2016 UTC

# Line 1 | Line 1
1 + from __future__ import print_function
2  
3   import os
4   import sys
5 + import re
6 + import platform
7   import ConfigParser
8  
9  
# Line 8 | Line 11 | _platdir = 'platform'
11  
12  
13   def read_plat(env, args, fn):
14 <        cfig = ConfigParser.ConfigParser(env.Dictionary())
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'], # replace
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 <                        'LIBPATH', 'LINKFLAGS']] # append
27 >                        '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
35 >                        [   # replace
36 >                        ],
37                          [   # append
38 <                        'RAD_COMPAT',    # currently obsolete
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()
44 >                        'RAD_PROCESS',    # our process abstraction and win_popen()
45 >                        'RAD_PCALLS',     # more custom process abstraction
46 >                        ]],
47          ]
48 <        if args.get('RAD_DEBUG',0):
48 >        if env.get('RAD_DEBUG',0) not in(0,'0','','n','no','false',None):
49                  vars.insert(0, ['debug'] + buildvars)
50 <        else: vars.insert(0, ['build'] + 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])
62 >                                #print('%s: %s' % (p, env[p]))
63                          for p in section[2]: # multiple items to append
64 <                                try: v = cfig.get(section[0], p)
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.
# Line 48 | Line 74 | def read_plat(env, args, fn):
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 load_plat(env, args, platform=None):
82 <        if platform == None: # override
83 <                p = sys.platform
84 <        else: p = platform
85 <        if p == 'win32' and 'gcc' in env['TOOLS']:
86 <                # we don't really want to know this here...
87 <                p = 'mingw'
88 <        pl = []
89 <        print 'Detected platform "%s" (%s).' % (sys.platform, os.name)
90 <        for i in [len(p), -1, -2]:
91 <                pfn = os.path.join(_platdir, p[:i] + '_custom.cfg')
92 <                if os.path.isfile(pfn):
93 <                        print 'Reading configuration "%s"' % pfn
94 <                        read_plat(env, args, pfn)
95 <                        return 1
96 <                pfn = os.path.join(_platdir, p[:i] + '.cfg')
97 <                if os.path.isfile(pfn):
98 <                        print 'Reading configuration "%s"' % pfn
99 <                        read_plat(env, args, pfn)
100 <                        return 1
101 <                
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, args, arch=None):
98 >        memmodel, binformat = platform.architecture()
99 >        platsys = platform.system()
100 >        print('Detected platform "%s" (%s).' % (platsys, memmodel))
101 >        cfgname = platsys + '_' + memmodel[:2]
102 >
103 >        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 >        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 >                return 1
112 >        pfn = os.path.join(_platdir, cfgname + '.cfg')
113 >        if os.path.isfile(pfn):
114 >                print('Reading configuration "%s"' % pfn)
115 >                read_plat(env, args, pfn)
116 >                return 1
117 >
118          if os.name == 'posix':
119                  pfn = os.path.join(_platdir, 'posix.cfg')
120                  if os.path.isfile(pfn):
121 <                        print 'Reading generic configuration "%s".' % pfn
121 >                        print('No platform specific configuration found.\n')
122 >                        print('Reading generic configuration "%s".' % pfn)
123                          read_plat(env, args, pfn)
124                          return 1
125  
126 <        print 'Platform "%s/%s" not supported yet' % (os.name, sys.platform)
126 >        print('Platform "%s", system "%s" not supported yet'
127 >                        % (os.name, sys.platform))
128          sys.exit(2)
129  
130          

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines