Back to index

radiance  4R0+20100331
load_plat.py
Go to the documentation of this file.
00001 
00002 import os
00003 import sys
00004 import ConfigParser
00005 
00006 
00007 _platdir = 'platform'
00008 
00009 
00010 def read_plat(env, args, fn):
00011        cfig = ConfigParser.ConfigParser(env.Dictionary())
00012        cfig.read(fn)
00013        buildvars = [['CC',
00014                      'TIFFINCLUDE', # where to find preinstalled tifflib headers
00015                      'TIFFLIB',     # where to find a preinstalled tifflib library
00016                      ], # replace
00017                      ['CPPPATH', 'CPPDEFINES', 'CPPFLAGS', 'CCFLAGS',
00018                      'LIBPATH', 'LINKFLAGS',
00019                      'EZXML_CPPDEFINES', # build flags specific to ezxml.c
00020                      ]] # append
00021        vars = [
00022               ['install',
00023                      ['RAD_BASEDIR', 'RAD_BINDIR', 'RAD_RLIBDIR', 'RAD_MANDIR'],
00024                      []],
00025               ['code',
00026                      [   # replace
00027                      ],
00028                      [   # append
00029                      'RAD_COMPAT',     # theoretically obsolete (src/common/strcmp.c)
00030                      'RAD_MATHCOMPAT', # erf.c floating point error function
00031                      'RAD_ARGSCOMPAT', # fixargv0.c for Windows
00032                      'RAD_NETCOMPAT',  # [win_]netproc.c for ranimate
00033                      'RAD_MLIB',       # usually 'm', or any fastlib available
00034                      'RAD_SOCKETLIB',  # ws_2_32 on Windows (VC links it automatically)
00035                      'RAD_PROCESS',    # our process abstraction and win_popen()
00036                      'RAD_PCALLS',     # more custom process abstraction
00037                      ]],
00038        ]
00039        if args.get('RAD_DEBUG',0):
00040               vars.insert(0, ['debug'] + buildvars)
00041        else: vars.insert(0, ['build'] + buildvars)
00042        for section in vars:
00043               if cfig.has_section(section[0]):
00044                      for p in section[1]: # single items to replace
00045                             try: v = cfig.get(section[0], p)
00046                             except ConfigParser.NoOptionError: continue
00047                             env[p] = v
00048                             #print '%s: %s' % (p, env[p])
00049                      for p in section[2]: # multiple items to append
00050                             try: v = cfig.get(section[0], p)
00051                             except ConfigParser.NoOptionError: continue
00052                             apply(env.Append,[],{p:env.Split(v)})
00053        # XXX Check that basedir exists.
00054        for k in ['RAD_BINDIR', 'RAD_RLIBDIR', 'RAD_MANDIR']:
00055               if (env.has_key('RAD_BASEDIR') and env.has_key(k)
00056                             and not os.path.isabs(env[k])):
00057                      env[k] = os.path.join(env['RAD_BASEDIR'],env[k])
00058 
00059 
00060 def load_plat(env, args, platform=None):
00061        if platform == None: # override
00062               p = sys.platform
00063        else: p = platform
00064        if p == 'win32' and 'gcc' in env['TOOLS']:
00065               # we don't really want to know this here...
00066               p = 'mingw'
00067        pl = []
00068        print 'Detected platform "%s" (%s).' % (sys.platform, os.name)
00069        for i in [len(p), -1, -2]:
00070               pfn = os.path.join(_platdir, p[:i] + '_custom.cfg')
00071               if os.path.isfile(pfn):
00072                      print 'Reading configuration "%s"' % pfn
00073                      read_plat(env, args, pfn)
00074                      return 1
00075               pfn = os.path.join(_platdir, p[:i] + '.cfg')
00076               if os.path.isfile(pfn):
00077                      print 'Reading configuration "%s"' % pfn
00078                      read_plat(env, args, pfn)
00079                      return 1
00080               
00081        if os.name == 'posix':
00082               pfn = os.path.join(_platdir, 'posix.cfg')
00083               if os.path.isfile(pfn):
00084                      print 'Reading generic configuration "%s".' % pfn
00085                      read_plat(env, args, pfn)
00086                      return 1
00087 
00088        print 'Platform "%s/%s" not supported yet' % (os.name, sys.platform)
00089        sys.exit(2)
00090 
00091        
00092