targets/__init__.py
author laurent
Fri, 16 Oct 2009 10:37:53 +0200
changeset 419 1cdae505be9e
parent 209 08dc3d064cb5
child 425 f390e9fdd2cf
permissions -rwxr-xr-x
Warning in c_ext compiling fixed
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     3
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     4
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     5
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     6
#See COPYING file for copyrights details.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     7
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     8
#This library is free software; you can redistribute it and/or
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     9
#modify it under the terms of the GNU General Public
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    10
#License as published by the Free Software Foundation; either
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    11
#version 2.1 of the License, or (at your option) any later version.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    12
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    13
#This library is distributed in the hope that it will be useful,
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    14
#but WITHOUT ANY WARRANTY; without even the implied warranty of
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    15
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    16
#General Public License for more details.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    17
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    18
#You should have received a copy of the GNU General Public
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    19
#License along with this library; if not, write to the Free Software
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    20
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    21
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    22
# Package initialisation
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    23
#import targets
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    24
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    25
"""
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    26
Beremiz Targets
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    27
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    28
- Target are python packages, containing at least one "XSD" file
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    29
- Target class may inherit from a toolchain_(toolchainname)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    30
- The target folder's name must match to name define in the XSD for TargetType
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    31
"""
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    32
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    33
from os import listdir, path
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    34
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    35
_base_path = path.split(__file__)[0]
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    36
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    37
targets = [name for name in listdir(_base_path) if path.isdir(path.join(_base_path, name)) and name.upper() != "CVS" and not name.startswith("__")]
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    38
toolchains = [name for name in listdir(_base_path) if not path.isdir(path.join(_base_path, name)) and name.upper() != "CVS" and name.endswith(".py") and not name.startswith("__") and not name.endswith(".pyc")]
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    39
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    40
DictXSD_toolchain = {}
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    41
DictXSD_target = {}
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    42
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    43
targetchoices = ""
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    44
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    45
# Get all xsd toolchains
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    46
for toolchain in toolchains :
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    47
     toolchainname = path.splitext(toolchain)[0]
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    48
     xsdfilename = path.join(_base_path, "XSD_%s"%(toolchainname))
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    49
     if path.isfile(xsdfilename):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    50
         xsd_toolchain_string = ""
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    51
         for line in open(xsdfilename).readlines():
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    52
             xsd_toolchain_string += line
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    53
         DictXSD_toolchain[toolchainname] = xsd_toolchain_string
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    54
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    55
# Get all xsd targets 
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    56
for targetname in targets:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    57
    xsdfilename = path.join(_base_path, targetname, "XSD")
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    58
    if path.isfile(xsdfilename):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    59
        xsd_target_string = ""
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    60
        for line in open(xsdfilename).readlines():
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    61
            xsd_target_string += line
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    62
        DictXSD_target[targetname] = xsd_target_string%DictXSD_toolchain
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    63
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    64
for target in DictXSD_target.keys():
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    65
    targetchoices += DictXSD_target[target]
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    66
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents: 205
diff changeset
    67
def targetcode(target_name, code_name=None):
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents: 205
diff changeset
    68
    if code_name is None:
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents: 205
diff changeset
    69
        code_name="plc_%s_main.c"%target_name
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents: 205
diff changeset
    70
    filename = path.join(path.split(__file__)[0], target_name, code_name)
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents: 205
diff changeset
    71
    return open(filename).read()
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents: 205
diff changeset
    72
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents: 205
diff changeset
    73
def code(name):
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents: 205
diff changeset
    74
    filename = path.join(path.split(__file__)[0],name + ".c")
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents: 205
diff changeset
    75
    return open(filename).read()
205
ee8d1f4528ef move specific target runtimes to their targets directory
greg
parents: 203
diff changeset
    76
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    77
from toolchain_gcc import toolchain_gcc