17
17
from os .path import splitext , basename , relpath , join , abspath , dirname ,\
18
18
exists
19
19
from os import curdir , getcwd
20
+ from jinja2 .exceptions import TemplateNotFound
20
21
from tools .export .exporters import Exporter
21
22
from tools .utils import NotSupportedException
22
23
from tools .targets import TARGET_MAP
23
- from jinja2 .exceptions import TemplateNotFound
24
24
25
25
26
26
class Makefile (Exporter ):
27
+ """Generic Makefile template that mimics the behavior of the python build
28
+ system
29
+ """
27
30
28
31
DOT_IN_RELATIVE_PATH = True
29
32
30
33
MBED_CONFIG_HEADER_SUPPORTED = True
31
34
32
35
def generate (self ):
33
- # "make" wants Unix paths
36
+ """Generate the makefile
37
+
38
+ Note: subclasses should not need to override this method
39
+ """
34
40
self .resources .win_to_unix ()
35
41
36
- to_be_compiled = []
37
- for r_type in ['s_sources' , 'c_sources' , 'cpp_sources' ]:
38
- r = getattr (self .resources , r_type )
39
- if r :
40
- for source in r :
41
- base , ext = splitext (source )
42
- to_be_compiled .append (base + '.o' )
42
+ to_be_compiled = [splitext (src )[0 ] + ".o" for src in
43
+ self .resources ['s_sources' ] +
44
+ self .resources ['c_sources' ] +
45
+ self .resources ['cpp_sources' ]]
43
46
44
- libraries = []
45
- for lib in self .resources .libraries :
46
- l , _ = splitext (basename (lib ))
47
- libraries .append (l [3 :])
47
+ libraries = [splitext (lib )[0 ][3 :] for lib in self .resources .libraries ]
48
48
49
49
ctx = {
50
50
'name' : self .project_name ,
51
51
'to_be_compiled' : to_be_compiled ,
52
52
'object_files' : self .resources .objects ,
53
- 'include_paths' : self .resources .inc_dirs ,
53
+ 'include_paths' : list ( set ( self .resources .inc_dirs )) ,
54
54
'library_paths' : self .resources .lib_dirs ,
55
55
'linker_script' : self .resources .linker_script ,
56
56
'libraries' : libraries ,
57
57
'symbols' : self .toolchain .get_symbols (),
58
58
'hex_files' : self .resources .hex_files ,
59
59
'vpath' : (["../../.." ]
60
- if basename (dirname (dirname (self .export_dir ))) == "projectfiles"
60
+ if (basename (dirname (dirname (self .export_dir )))
61
+ == "projectfiles" )
61
62
else [".." ]),
62
63
'cc_cmd' : " " .join (self .toolchain .cc ),
63
64
'cppc_cmd' : " " .join (self .toolchain .cppc ),
@@ -68,15 +69,16 @@ def generate(self):
68
69
'link_script_option' : self .LINK_SCRIPT_OPTION ,
69
70
}
70
71
71
- for key in ['include_paths' , 'library_paths' , 'linker_script' , 'hex_files' ]:
72
+ for key in ['include_paths' , 'library_paths' , 'linker_script' ,
73
+ 'hex_files' ]:
72
74
if isinstance (ctx [key ], list ):
73
75
ctx [key ] = [ctx ['vpath' ][0 ] + "/" + t for t in ctx [key ]]
74
76
else :
75
77
ctx [key ] = ctx ['vpath' ][0 ] + "/" + ctx [key ]
76
78
if "../." not in ctx ["include_paths" ]:
77
79
ctx ["include_paths" ] += ['../.' ]
78
- ctx [ "include_paths" ] = list ( set ( ctx [ " include_paths" ]))
79
- for key in [ 'include_paths' , 'library_paths' , 'hex_files' , 'to_be_compiled' , 'symbols' ]:
80
+ for key in [ ' include_paths' , 'library_paths' , 'hex_files' ,
81
+ 'to_be_compiled' , 'symbols' ]:
80
82
ctx [key ] = sorted (ctx [key ])
81
83
ctx .update (self .flags )
82
84
@@ -96,23 +98,26 @@ def generate(self):
96
98
raise NotSupportedException ("This make tool is in development" )
97
99
98
100
99
- class GccArm_Exporter (Makefile ):
101
+ class GccArm (Makefile ):
102
+ """GCC ARM specific makefile target"""
100
103
TARGETS = [target for target , obj in TARGET_MAP .iteritems ()
101
104
if "GCC_ARM" in obj .supported_toolchains ]
102
105
NAME = 'Make-GCC-ARM'
103
106
TOOLCHAIN = "GCC_ARM"
104
107
LINK_SCRIPT_OPTION = "-T"
105
108
106
109
107
- class Armc5_Exporter (Makefile ):
110
+ class Armc5 (Makefile ):
111
+ """ARM Compiler 5 specific makefile target"""
108
112
TARGETS = [target for target , obj in TARGET_MAP .iteritems ()
109
113
if "ARM" in obj .supported_toolchains ]
110
114
NAME = 'Make-ARMc5'
111
115
TOOLCHAIN = "ARM"
112
116
LINK_SCRIPT_OPTION = "--scatter"
113
117
114
118
115
- class IAR_Exporter (Makefile ):
119
+ class IAR (Makefile ):
120
+ """IAR specific makefile target"""
116
121
TARGETS = [target for target , obj in TARGET_MAP .iteritems ()
117
122
if "IAR" in obj .supported_toolchains ]
118
123
NAME = 'Make-IAR'
0 commit comments