31 includes_re = re.compile('\s*#include\s*["<]([^">]*)[">].*') |
31 includes_re = re.compile('\s*#include\s*["<]([^">]*)[">].*') |
32 |
32 |
33 class toolchain_makefile(): |
33 class toolchain_makefile(): |
34 def __init__(self, CTRInstance): |
34 def __init__(self, CTRInstance): |
35 self.CTRInstance = CTRInstance |
35 self.CTRInstance = CTRInstance |
36 self.md5key = None |
36 self.md5key = None |
37 self.buildpath = None |
37 self.buildpath = None |
38 self.SetBuildPath(self.CTRInstance._getBuildPath()) |
38 self.SetBuildPath(self.CTRInstance._getBuildPath()) |
39 |
39 |
40 def SetBuildPath(self, buildpath): |
40 def SetBuildPath(self, buildpath): |
41 if self.buildpath != buildpath: |
41 if self.buildpath != buildpath: |
81 return reduce(operator.concat, map(self.concat_deps, deps), src) |
81 return reduce(operator.concat, map(self.concat_deps, deps), src) |
82 |
82 |
83 def build(self): |
83 def build(self): |
84 srcfiles= [] |
84 srcfiles= [] |
85 cflags = [] |
85 cflags = [] |
86 wholesrcdata = "" |
86 wholesrcdata = "" |
87 for Location, CFilesAndCFLAGS, DoCalls in self.CTRInstance.LocationCFilesAndCFLAGS: |
87 for Location, CFilesAndCFLAGS, DoCalls in self.CTRInstance.LocationCFilesAndCFLAGS: |
88 # Get CFiles list to give it to makefile |
88 # Get CFiles list to give it to makefile |
89 for CFile, CFLAGS in CFilesAndCFLAGS: |
89 for CFile, CFLAGS in CFilesAndCFLAGS: |
90 CFileName = os.path.basename(CFile) |
90 CFileName = os.path.basename(CFile) |
91 wholesrcdata += self.concat_deps(CFileName) |
91 wholesrcdata += self.concat_deps(CFileName) |
92 srcfiles.append(CFileName) |
92 srcfiles.append(CFileName) |
93 if CFLAGS not in cflags: |
93 if CFLAGS not in cflags: |
94 cflags.append(CFLAGS) |
94 cflags.append(CFLAGS) |
95 |
95 |
96 oldmd5 = self.md5key |
96 oldmd5 = self.md5key |
97 self.md5key = hashlib.md5(wholesrcdata).hexdigest() |
97 self.md5key = hashlib.md5(wholesrcdata).hexdigest() |
98 |
98 |
99 # Store new PLC filename based on md5 key |
99 # Store new PLC filename based on md5 key |
100 f = open(self._GetMD5FileName(), "w") |
100 f = open(self._GetMD5FileName(), "w") |
106 beremizcommand = {"src": ' '.join(srcfiles), |
106 beremizcommand = {"src": ' '.join(srcfiles), |
107 "cflags": ' '.join(cflags), |
107 "cflags": ' '.join(cflags), |
108 "md5": self.md5key, |
108 "md5": self.md5key, |
109 "buildpath": self.buildpath |
109 "buildpath": self.buildpath |
110 } |
110 } |
111 |
111 |
112 # clean sequence of multiple whitespaces |
112 # clean sequence of multiple whitespaces |
113 cmd = re.sub(r"[ ]+", " ", target.getCommand().strip()) |
113 cmd = re.sub(r"[ ]+", " ", target.getCommand().strip()) |
114 |
114 |
115 command = [ token % beremizcommand for token in cmd.split(' ')] |
115 command = [ token % beremizcommand for token in cmd.split(' ')] |
116 |
116 |
117 # Call Makefile to build PLC code and link it with target specific code |
117 # Call Makefile to build PLC code and link it with target specific code |