targets/toolchain_makefile.py
changeset 1911 c1298e7ffe3a
parent 1575 de2da05089ea
child 1709 1e8900fc8ddb
equal deleted inserted replaced
1910:a375e31bf312 1911:c1298e7ffe3a
       
     1 #!/usr/bin/env python
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 # This file is part of Beremiz, a Integrated Development Environment for
       
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
       
     6 #
       
     7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
       
     8 #
       
     9 # See COPYING file for copyrights details.
       
    10 #
       
    11 # This program is free software; you can redistribute it and/or
       
    12 # modify it under the terms of the GNU General Public License
       
    13 # as published by the Free Software Foundation; either version 2
       
    14 # of the License, or (at your option) any later version.
       
    15 #
       
    16 # This program is distributed in the hope that it will be useful,
       
    17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    19 # GNU General Public License for more details.
       
    20 #
       
    21 # You should have received a copy of the GNU General Public License
       
    22 # along with this program; if not, write to the Free Software
       
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
       
    24 
     1 import os, re, operator
    25 import os, re, operator
     2 from util.ProcessLogger import ProcessLogger
    26 from util.ProcessLogger import ProcessLogger
     3 import hashlib
    27 import hashlib
     4 
    28 
     5 import time
    29 import time
     6 
    30 
     7 includes_re =  re.compile('\s*#include\s*["<]([^">]*)[">].*')
    31 includes_re =  re.compile('\s*#include\s*["<]([^">]*)[">].*')
     8 
       
     9 
       
    10 if os.name == 'nt':
       
    11     # on windows, desktop shortcut launches Beremiz.py
       
    12     # with working dir set to mingw/bin.
       
    13     # then we prefix CWD to PATH in order to ensure that
       
    14     # commands invoked from Makefiles will first resolve
       
    15     # to here.
       
    16     os.environ["PATH"] = os.getcwd()+';'+os.environ["PATH"]
       
    17 
    32 
    18 class toolchain_makefile():
    33 class toolchain_makefile():
    19     def __init__(self, CTRInstance):
    34     def __init__(self, CTRInstance):
    20         self.CTRInstance = CTRInstance
    35         self.CTRInstance = CTRInstance
    21         self.md5key = None 
    36         self.md5key = None 
    78                 if CFLAGS not in cflags:
    93                 if CFLAGS not in cflags:
    79                     cflags.append(CFLAGS)
    94                     cflags.append(CFLAGS)
    80                         
    95                         
    81         oldmd5 = self.md5key
    96         oldmd5 = self.md5key
    82         self.md5key = hashlib.md5(wholesrcdata).hexdigest()
    97         self.md5key = hashlib.md5(wholesrcdata).hexdigest()
    83         props = self.CTRInstance.GetProjectProperties()
    98 
    84         self.md5key += '#'.join([props[key] for key in ['companyName',
       
    85                                                         'projectName',
       
    86                                                         'productName']])
       
    87         self.md5key += '#' #+','.join(map(str,time.localtime()))
       
    88         # Store new PLC filename based on md5 key
    99         # Store new PLC filename based on md5 key
    89         f = open(self._GetMD5FileName(), "w")
   100         f = open(self._GetMD5FileName(), "w")
    90         f.write(self.md5key)
   101         f.write(self.md5key)
    91         f.close()
   102         f.close()
    92 
   103 
    96                               "cflags": ' '.join(cflags),
   107                               "cflags": ' '.join(cflags),
    97                               "md5": self.md5key,
   108                               "md5": self.md5key,
    98                               "buildpath": self.buildpath
   109                               "buildpath": self.buildpath
    99                              }
   110                              }
   100             
   111             
   101             command = [ token % beremizcommand for token in target.getCommand().split(' ')]
   112             # clean sequence of multiple whitespaces 
       
   113             cmd = re.sub(r"[ ]+", " ", target.getCommand())
       
   114 
       
   115             command = [ token % beremizcommand for token in cmd.split(' ')]
   102 
   116 
   103             # 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
   104             status, result, err_result = ProcessLogger(self.CTRInstance.logger,
   118             status, result, err_result = ProcessLogger(self.CTRInstance.logger,
   105                                                        command).spin()
   119                                                        command).spin()
   106             if status :
   120             if status :