afc7e99155d392ec5396ee2e208f2155b79b2891
[matrix.git] / matrix / config.py
1 # Copyright (C) 2007-2008 Movial Oy
2 # Authors: Timo Savola <tsavola@movial.fi>
3 #          Kalle Vahlman <kalle.vahlman@movial.fi>
4
5 import os
6
7 class Board(object):
8         def __init__(self, name, arch, gcc_march,
9                      gcc_mcpu=None,
10                      gcc_mfpu=None,
11                      gcc_options=None,
12                      gnu_host=None,
13                      flash_erase_size=65536,
14                      flash_pad_size=0):
15                 self.name = name
16                 self.arch = arch
17                 self.gcc_march = gcc_march
18                 self.gcc_mcpu = gcc_mcpu
19                 self.gcc_mfpu = gcc_mfpu
20                 self.gcc_options = gcc_options
21                 self.gnu_host = gnu_host
22                 self.flash_erase_size = flash_erase_size
23                 self.flash_pad_size = flash_pad_size
24
25                 config.boards[name] = self
26
27 def Component(*args, **kwargs):
28         import components
29
30         c = components.Component(*args, **kwargs)
31         config.components[c.name] = c
32         return c
33
34 def PlatformProvidedComponent(*args, **kwargs):
35         import components
36
37         c = components.PlatformProvidedComponent(*args, **kwargs)
38         config.components[c.name] = c
39         return c
40
41 def parse(name, required=False):
42         if os.path.isabs(name):
43                 path = os.path.join(config.top_dir, name)
44         else:
45                 path = name
46
47         if os.path.exists(path):
48                 if config.debug:
49                         print 'Parsing', path
50
51                 execfile(path, actions, config.__dict__)
52         else:
53                 msg = 'Config file not found: %s' % name
54                 if required:
55                         raise RuntimeError(msg)
56                 elif config.debug:
57                         print msg
58
59 actions = dict(
60         Board = Board,
61         Component = Component,
62         PlatformProvidedComponent = PlatformProvidedComponent,
63         parse = parse,
64 )
65
66 class Config(object):
67         def __init__(self):
68                 self.top_dir = os.environ.get('MATRIX_TOPDIR', '')
69
70                 __cache_dir = os.path.join(self.top_dir, 'build-cache')
71                 self.cache_dir = os.environ.get('MATRIX_CACHEDIR', __cache_dir)
72
73                 self.script_dir = None
74
75                 self.boards = {}
76                 self.board = None
77                 self.components = {}
78                 self.roots = []
79                 self.flags = []
80                 self.libc = 'glibc'
81                 self.verbose = False
82                 self.debug = False
83                 self.force = False
84                 self.keep_going = False
85                 self.jobs = 1
86                 self.make_jobs = 1
87
88 config = Config()