targets/toolchain_gcc.py
changeset 421 c9ec111ad275
parent 411 8261c8f1e365
child 427 7ac746c07ff2
equal deleted inserted replaced
420:c093ec48f2fd 421:c9ec111ad275
    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, PluginsRootInstance):
    13     def __init__(self, PluginsRootInstance):
    14         self.PluginsRootInstance = PluginsRootInstance
    14         self.PluginsRootInstance = PluginsRootInstance
    15         self.logger = PluginsRootInstance.logger
       
    16         self.exe = PluginsRootInstance.GetProjectName() + self.extension
    15         self.exe = PluginsRootInstance.GetProjectName() + self.extension
    17         self.buildpath = PluginsRootInstance._getBuildPath()
    16         self.buildpath = PluginsRootInstance._getBuildPath()
    18         self.exe_path = os.path.join(self.buildpath, self.exe)
    17         self.exe_path = os.path.join(self.buildpath, self.exe)
    19         self.md5key = None
    18         self.md5key = None
    20         self.srcmd5 = {}
    19         self.srcmd5 = {}
    94         obns = []
    93         obns = []
    95         objs = []
    94         objs = []
    96         relink = False
    95         relink = False
    97         for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS:
    96         for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS:
    98             if Location:
    97             if Location:
    99                 self.logger.write(_("Plugin : ") + self.PluginsRootInstance.GetChildByIECLocation(Location).GetCurrentName() + " " + str(Location)+"\n")
    98                 self.PluginsRootInstance.logger.write(_("Plugin : ") + self.PluginsRootInstance.GetChildByIECLocation(Location).GetCurrentName() + " " + str(Location)+"\n")
   100             else:
    99             else:
   101                 self.logger.write(_("PLC :\n"))
   100                 self.PluginsRootInstance.logger.write(_("PLC :\n"))
   102                 
   101                 
   103             for CFile, CFLAGS in CFilesAndCFLAGS:
   102             for CFile, CFLAGS in CFilesAndCFLAGS:
   104                 bn = os.path.basename(CFile)
   103                 bn = os.path.basename(CFile)
   105                 obn = os.path.splitext(bn)[0]+".o"
   104                 obn = os.path.splitext(bn)[0]+".o"
   106                 objectfilename = os.path.splitext(CFile)[0]+".o"
   105                 objectfilename = os.path.splitext(CFile)[0]+".o"
   107 
   106 
   108                 match = self.check_and_update_hash_and_deps(bn)
   107                 match = self.check_and_update_hash_and_deps(bn)
   109                 
   108                 
   110                 if match:
   109                 if match:
   111                     self.logger.write("   [pass]  "+bn+" -> "+obn+"\n")
   110                     self.PluginsRootInstance.logger.write("   [pass]  "+bn+" -> "+obn+"\n")
   112                 else:
   111                 else:
   113                     relink = True
   112                     relink = True
   114 
   113 
   115                     self.logger.write("   [CC]  "+bn+" -> "+obn+"\n")
   114                     self.PluginsRootInstance.logger.write("   [CC]  "+bn+" -> "+obn+"\n")
   116                     
   115                     
   117                     status, result, err_result = ProcessLogger(
   116                     status, result, err_result = ProcessLogger(
   118                            self.logger,
   117                            self.PluginsRootInstance.logger,
   119                            "\"%s\" -c \"%s\" -o \"%s\" %s %s"%
   118                            "\"%s\" -c \"%s\" -o \"%s\" %s %s"%
   120                                (self.compiler, CFile, objectfilename, Builder_CFLAGS, CFLAGS)
   119                                (self.compiler, CFile, objectfilename, Builder_CFLAGS, CFLAGS)
   121                            ).spin()
   120                            ).spin()
   122 
   121 
   123                     if status :
   122                     if status :
   124                         self.srcmd5.pop(bn)
   123                         self.srcmd5.pop(bn)
   125                         self.logger.write_error(_("C compilation of %s failed.\n")%bn)
   124                         self.PluginsRootInstance.logger.write_error(_("C compilation of %s failed.\n")%bn)
   126                         return False
   125                         return False
   127 
   126 
   128                 obns.append(obn)
   127                 obns.append(obn)
   129                 objs.append(objectfilename)
   128                 objs.append(objectfilename)
   130 
   129 
   131         ######### GENERATE library FILE ########################################
   130         ######### GENERATE library FILE ########################################
   132         # Link all the object files into one binary file
   131         # Link all the object files into one binary file
   133         self.logger.write(_("Linking :\n"))
   132         self.PluginsRootInstance.logger.write(_("Linking :\n"))
   134         if relink:
   133         if relink:
   135             objstring = []
   134             objstring = []
   136     
   135     
   137             # Generate list .o files
   136             # Generate list .o files
   138             listobjstring = '"' + '"  "'.join(objs) + '"'
   137             listobjstring = '"' + '"  "'.join(objs) + '"'
   139     
   138     
   140             ALLldflags = ' '.join(self.getBuilderLDFLAGS())
   139             ALLldflags = ' '.join(self.getBuilderLDFLAGS())
   141     
   140     
   142             self.logger.write("   [CC]  " + ' '.join(obns)+" -> " + self.exe + "\n")
   141             self.PluginsRootInstance.logger.write("   [CC]  " + ' '.join(obns)+" -> " + self.exe + "\n")
   143     
   142     
   144             status, result, err_result = ProcessLogger(
   143             status, result, err_result = ProcessLogger(
   145                    self.logger,
   144                    self.PluginsRootInstance.logger,
   146                    "\"%s\" %s -o \"%s\" %s"%
   145                    "\"%s\" %s -o \"%s\" %s"%
   147                        (self.linker,
   146                        (self.linker,
   148                         listobjstring,
   147                         listobjstring,
   149                         self.exe_path,
   148                         self.exe_path,
   150                         ALLldflags)
   149                         ALLldflags)
   160                 # Store new PLC filename based on md5 key
   159                 # Store new PLC filename based on md5 key
   161                 f = open(self._GetMD5FileName(), "w")
   160                 f = open(self._GetMD5FileName(), "w")
   162                 f.write(self.md5key)
   161                 f.write(self.md5key)
   163                 f.close()
   162                 f.close()
   164         else:
   163         else:
   165             self.logger.write("   [pass]  " + ' '.join(obns)+" -> " + self.exe + "\n")
   164             self.PluginsRootInstance.logger.write("   [pass]  " + ' '.join(obns)+" -> " + self.exe + "\n")
   166             
   165             
   167         
   166         
   168         return True
   167         return True
   169 
   168