targets/toolchain_makefile.py
author laurent
Fri, 11 Dec 2009 13:02:30 +0100
changeset 505 7f38c773427b
parent 425 f390e9fdd2cf
child 508 73ecb803d8af
permissions -rwxr-xr-x
Adding support for refreshing FileMenu after plugin tree modification
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     1
import os, re, operator
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     2
from wxPopen import ProcessLogger
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     3
import hashlib, shutil
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     4
from toolchain_gcc import toolchain_gcc
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     5
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     6
includes_re =  re.compile('\s*#include\s*["<]([^">]*)[">].*')
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     7
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     8
class toolchain_makefile(toolchain_gcc):
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     9
    """
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    10
    This abstract class contains GCC specific code.
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    11
    It cannot be used as this and should be inherited in a target specific
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    12
    class such as target_linux or target_win32
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    13
    """
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    14
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    15
    def build(self):
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    16
        srcfiles= []
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    17
        cflags = []
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    18
        for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS:
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    19
            # Get CFiles list to give it to makefile 
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    20
            for CFile, CFLAGS in CFilesAndCFLAGS:
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    21
                CFileName = os.path.basename(CFile)
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    22
                srcfiles.append(CFileName)
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    23
                if CFLAGS not in cflags:
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    24
                    cflags.append(CFLAGS)
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    25
                    
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    26
        beremizcommand = {"src": ' '.join(srcfiles),
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    27
                          "cflags": ' '.join(cflags)
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    28
                         }
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    29
        
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    30
        target = self.getTarget().getcontent()["value"]
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    31
        command = target.getCommand().split(' ') +\
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    32
                  [target.getBuildPath()] +\
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    33
                  [arg % beremizcommand for arg in target.getArguments().split(' ')] +\
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    34
                  target.getRule().split(' ')
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    35
        
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    36
        # Call Makefile to build PLC code and link it with target specific code
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    37
        status, result, err_result = ProcessLogger(self.PluginsRootInstance.logger,
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    38
                                                   command).spin()
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    39
        if status :
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    40
            self.PluginsRootInstance.logger.write_error(_("C compilation of %s failed.\n"))
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    41
            return False
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    42
        return True