8 """ |
8 """ |
9 This abstract class contains GCC specific code. |
9 This abstract class contains GCC specific code. |
10 It cannot be used as this and should be inherited in a target specific |
10 It cannot be used as this and should be inherited in a target specific |
11 class such as target_linux or target_win32 |
11 class such as target_linux or target_win32 |
12 """ |
12 """ |
13 def __init__(self, PuginsRootInstance): |
13 def __init__(self, PluginsRootInstance): |
14 self.PuginsRootInstance = PuginsRootInstance |
14 self.PluginsRootInstance = PluginsRootInstance |
15 self.logger = PuginsRootInstance.logger |
15 self.logger = PluginsRootInstance.logger |
16 self.exe = PuginsRootInstance.GetProjectName() + self.extension |
16 self.exe = PluginsRootInstance.GetProjectName() + self.extension |
17 self.buildpath = PuginsRootInstance._getBuildPath() |
17 self.buildpath = PluginsRootInstance._getBuildPath() |
18 self.exe_path = os.path.join(self.buildpath, self.exe) |
18 self.exe_path = os.path.join(self.buildpath, self.exe) |
19 self.md5key = None |
19 self.md5key = None |
20 self.srcmd5 = {} |
20 self.srcmd5 = {} |
21 |
21 |
22 def getBuilderCFLAGS(self): |
22 def getBuilderCFLAGS(self): |
23 """ |
23 """ |
24 Returns list of builder specific CFLAGS |
24 Returns list of builder specific CFLAGS |
25 """ |
25 """ |
26 return [self.PuginsRootInstance.BeremizRoot.getTargetType().getcontent()["value"].getCFLAGS()] |
26 return [self.PluginsRootInstance.BeremizRoot.getTargetType().getcontent()["value"].getCFLAGS()] |
27 |
27 |
28 def getBuilderLDFLAGS(self): |
28 def getBuilderLDFLAGS(self): |
29 """ |
29 """ |
30 Returns list of builder specific LDFLAGS |
30 Returns list of builder specific LDFLAGS |
31 """ |
31 """ |
32 return self.PuginsRootInstance.LDFLAGS + \ |
32 return self.PluginsRootInstance.LDFLAGS + \ |
33 [self.PuginsRootInstance.BeremizRoot.getTargetType().getcontent()["value"].getLDFLAGS()] |
33 [self.PluginsRootInstance.BeremizRoot.getTargetType().getcontent()["value"].getLDFLAGS()] |
34 |
34 |
35 def GetBinaryCode(self): |
35 def GetBinaryCode(self): |
36 try: |
36 try: |
37 return open(self.exe_path, "rb").read() |
37 return open(self.exe_path, "rb").read() |
38 except Exception, e: |
38 except Exception, e: |
76 # TODO detect cicular deps. |
76 # TODO detect cicular deps. |
77 return reduce(operator.and_, map(self.check_and_update_hash_and_deps, deps), match) |
77 return reduce(operator.and_, map(self.check_and_update_hash_and_deps, deps), match) |
78 |
78 |
79 def build(self): |
79 def build(self): |
80 # Retrieve toolchain user parameters |
80 # Retrieve toolchain user parameters |
81 toolchain_params = self.PuginsRootInstance.BeremizRoot.getTargetType().getcontent()["value"] |
81 toolchain_params = self.PluginsRootInstance.BeremizRoot.getTargetType().getcontent()["value"] |
82 self.compiler = toolchain_params.getCompiler() |
82 self.compiler = toolchain_params.getCompiler() |
83 self.linker = toolchain_params.getLinker() |
83 self.linker = toolchain_params.getLinker() |
84 |
84 |
85 Builder_CFLAGS = ' '.join(self.getBuilderCFLAGS()) |
85 Builder_CFLAGS = ' '.join(self.getBuilderCFLAGS()) |
86 |
86 |
87 ######### GENERATE OBJECT FILES ######################################## |
87 ######### GENERATE OBJECT FILES ######################################## |
88 obns = [] |
88 obns = [] |
89 objs = [] |
89 objs = [] |
90 for Location, CFilesAndCFLAGS, DoCalls in self.PuginsRootInstance.LocationCFilesAndCFLAGS: |
90 relink = False |
|
91 for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS: |
91 if Location: |
92 if Location: |
92 self.logger.write("Plugin : " + self.PuginsRootInstance.GetChildByIECLocation(Location).GetCurrentName() + " " + str(Location)+"\n") |
93 self.logger.write("Plugin : " + self.PluginsRootInstance.GetChildByIECLocation(Location).GetCurrentName() + " " + str(Location)+"\n") |
93 else: |
94 else: |
94 self.logger.write("PLC :\n") |
95 self.logger.write("PLC :\n") |
95 |
96 |
96 relink = False |
|
97 for CFile, CFLAGS in CFilesAndCFLAGS: |
97 for CFile, CFLAGS in CFilesAndCFLAGS: |
98 bn = os.path.basename(CFile) |
98 bn = os.path.basename(CFile) |
99 obn = os.path.splitext(bn)[0]+".o" |
99 obn = os.path.splitext(bn)[0]+".o" |
100 objectfilename = os.path.splitext(CFile)[0]+".o" |
100 objectfilename = os.path.splitext(CFile)[0]+".o" |
101 |
101 |
113 "\"%s\" -c \"%s\" -o \"%s\" %s %s"% |
113 "\"%s\" -c \"%s\" -o \"%s\" %s %s"% |
114 (self.compiler, CFile, objectfilename, Builder_CFLAGS, CFLAGS) |
114 (self.compiler, CFile, objectfilename, Builder_CFLAGS, CFLAGS) |
115 ).spin() |
115 ).spin() |
116 |
116 |
117 if status : |
117 if status : |
|
118 self.srcmd5.pop(bn) |
118 self.logger.write_error("C compilation of "+ bn +" failed.\n") |
119 self.logger.write_error("C compilation of "+ bn +" failed.\n") |
119 return False |
120 return False |
120 |
121 |
121 obns.append(obn) |
122 obns.append(obn) |
122 objs.append(objectfilename) |
123 objs.append(objectfilename) |