string = open(sourcesDir + "/" + key, "r").read()
for parameter, infos in value.items():
value = infos["value"]
+ if "type" in infos["informations"] and infos["informations"]["type"] == "autoenabled":
+ value = "1"
if "unsigned" in infos["informations"].keys() and infos["informations"]["unsigned"]:
value += "U"
if "long" in infos["informations"].keys() and infos["informations"]["long"]:
mkData["$cpuname"] = projectInfo.info("CPU_INFOS")["CORE_CPU"]
mkData["$cflags"] = " ".join(projectInfo.info("CPU_INFOS")["C_FLAGS"])
mkData["$ldflags"] = " ".join(projectInfo.info("CPU_INFOS")["LD_FLAGS"])
- mkData["$csrc"], mkData["$pcsrc"] = csrcGenerator(projectInfo)
+ mkData["$csrc"], mkData["$pcsrc"], mkData["$constants"] = csrcGenerator(projectInfo)
mkData["$prefix"] = projectInfo.info("TOOLCHAIN")["path"].split("gcc")[0]
mkData["$suffix"] = projectInfo.info("TOOLCHAIN")["path"].split("gcc")[1]
mkData["$cross"] = projectInfo.info("TOOLCHAIN")["path"].split("gcc")[0]
- mkData["$main"] = projectInfo.info("PROJECT_PATH") + "/" + os.path.basename(projectInfo.info("PROJECT_PATH")) + "/main.c"
+ mkData["$main"] = os.path.basename(projectInfo.info("PROJECT_PATH")) + "/main.c"
for key in mkData:
while makefile.find(key) != -1:
makefile = makefile.replace(key, mkData[key])
def csrcGenerator(projectInfo):
modules = projectInfo.info("MODULES")
+ files = projectInfo.info("FILES")
if "harvard" in projectInfo.info("CPU_INFOS")["CPU_TAGS"]:
- pcsrc_need = projectInfo.info("CPU_INFOS")["PC_SRC"]
+ harvard = True
else:
- pcsrc_need = []
+ harvard = False
+ ## file to be included in CSRC variable
csrc = []
+ ## file to be included in PCSRC variable
pcsrc = []
+ ## constants to be included at the beginning of the makefile
+ constants = {}
+ moduleFiles = set([])
+ dependencyFiles = set([])
+ ## assembly sources
+ asmFiles = set([])
for module, information in modules.items():
if information["enabled"]:
- for filename, path in findDefinitions(module + ".c", projectInfo):
- path = path.replace(projectInfo.info("SOURCES_PATH"), projectInfo.info("PROJECT_PATH"))
- csrc.append(path + "/" + filename)
- if module in pcsrc_need:
- pcsrc.append(path + "/" + filename)
- for filename, path in findDefinitions(module + "_" + projectInfo.info("CPU_INFOS")["TOOLCHAIN"] + ".c", projectInfo):
- path = path.replace(projectInfo.info("SOURCES_PATH"), projectInfo.info("PROJECT_PATH"))
- csrc.append(path + "/" + filename)
- if module in pcsrc_need:
- pcsrc.append(path + "/" + filename)
- for tag in projectInfo.info("CPU_INFOS")["CPU_TAGS"]:
- for filename, path in findDefinitions(module + "_" + tag + ".c", projectInfo):
- path = path.replace(projectInfo.info("SOURCES_PATH"), projectInfo.info("PROJECT_PATH"))
- csrc.append(path + "/" + filename)
- if module in pcsrc_need:
- pcsrc.append(path + "/" + filename)
+ if "constants" in information:
+ constants.update(information["constants"])
+ cfiles, sfiles = findModuleFiles(module, projectInfo)
+ moduleFiles |= set(cfiles)
+ asmFiles |= set(sfiles)
+ for fileDependency in information["depends"]:
+ if fileDependency in files:
+ dependencyCFiles, dependencySFiles = findModuleFiles(fileDependency, projectInfo)
+ dependencyFiles |= set(dependencyCFiles)
+ asmFiles |= set(dependencySFiles)
+ for file in moduleFiles:
+ if not harvard or "harvard" not in information or information["harvard"] == "both":
+ csrc.append(file)
+ if harvard and "harvard" in information:
+ pcsrc.append(file)
+ for file in dependencyFiles:
+ csrc.append(file)
csrc = " \\\n\t".join(csrc) + " \\"
pcsrc = " \\\n\t".join(pcsrc) + " \\"
- return csrc, pcsrc
+ constants = "\n".join([os.path.basename(projectInfo.info("PROJECT_PATH")) + "_" + key + " = " + str(value) for key, value in constants.items()])
+ return csrc, pcsrc, constants
+
+def findModuleFiles(module, projectInfo):
+ ## Find the files related to the selected module
+ cfiles = []
+ sfiles = []
+ ## .c files related to the module and the cpu architecture
+ for filename, path in findDefinitions(module + ".c", projectInfo) + \
+ findDefinitions(module + "_" + projectInfo.info("CPU_INFOS")["TOOLCHAIN"] + ".c", projectInfo):
+ path = path.replace(projectInfo.info("SOURCES_PATH") + "/", "")
+ cfiles.append(path + "/" + filename)
+ ## .s files related to the module and the cpu architecture
+ for filename, path in findDefinitions(module + ".s", projectInfo) + \
+ findDefinitions(module + "_" + projectInfo.info("CPU_INFOS")["TOOLCHAIN"] + ".s", projectInfo) + \
+ findDefinitions(module + ".S", projectInfo) + \
+ findDefinitions(module + "_" + projectInfo.info("CPU_INFOS")["TOOLCHAIN"] + ".S", projectInfo):
+ path = path.replace(projectInfo.info("SOURCES_PATH") + "/", "")
+ sfiles.append(path + "/" + filename)
+ ## .c and .s files related to the module and the cpu tags
+ for tag in projectInfo.info("CPU_INFOS")["CPU_TAGS"]:
+ for filename, path in findDefinitions(module + "_" + tag + ".c", projectInfo):
+ path = path.replace(projectInfo.info("SOURCES_PATH") + "/", "")
+ cfiles.append(path + "/" + filename)
+ for filename, path in findDefinitions(module + "_" + tag + ".s", projectInfo) + \
+ findDefinitions(module + "_" + tag + ".S", projectInfo):
+ path = path.replace(projectInfo.info("SOURCES_PATH") + "/", "")
+ sfiles.append(path + "/" + filename)
+ return cfiles, sfiles
def codeliteProjectGenerator(projectInfo):
template = open("cltemplates/bertos.project").read()
if "module_description" in moduleDefinition.keys():
moduleDict[moduleName]["description"] = moduleDefinition["module_description"]
del moduleDefinition["module_description"]
- moduleDict[moduleName]["consts"] = moduleDefinition
+ if const.MODULE_DEFINITION["module_harvard"] in moduleDefinition.keys():
+ harvard = moduleDefinition[const.MODULE_DEFINITION["module_harvard"]]
+ if harvard == "both" or harvard == "pgm_memory":
+ moduleDict[moduleName]["harvard"] = harvard
+ del moduleDefinition[const.MODULE_DEFINITION["module_harvard"]]
+ moduleDict[moduleName]["constants"] = moduleDefinition
moduleDict[moduleName]["enabled"] = False
return toBeParsed, moduleDict
moduleInfoDict = {}
listInfoDict = {}
configurationInfoDict = {}
- for filename, path in findDefinitions("*.h", project):
+ fileDict = {}
+ for filename, path in findDefinitions("*.h", project) + findDefinitions("*.c", project) + findDefinitions("*.s", project) + findDefinitions("*.S", project):
commentList = getCommentList(open(path + "/" + filename, "r").read())
if len(commentList) > 0:
moduleInfo = {}
project.setInfo("MODULES", moduleInfoDict)
project.setInfo("LISTS", listInfoDict)
project.setInfo("CONFIGURATIONS", configurationInfoDict)
+ project.setInfo("FILES", fileDict)
def formatParamNameValue(text):
"""
"min": the minimum value for integer parameters
"max": the maximum value for integer parameters
"long": boolean indicating if the num is a long
+ "unsigned": boolean indicating if the num is an unsigned
"value_list": the name of the enum for enum parameters
"""
configurationInfos = {}
configurationInfos[name] = {}
configurationInfos[name]["value"] = value
configurationInfos[name]["informations"] = informations
+ if not "type" in configurationInfos[name]["informations"]:
+ configurationInfos[name]["informations"]["type"] = findParameterType(configurationInfos[name])
if ("type" in configurationInfos[name]["informations"].keys() and
configurationInfos[name]["informations"]["type"] == "int" and
configurationInfos[name]["value"].find("L") != -1):
configurationInfos[name]["brief"] = brief
return configurationInfos
+def findParameterType(parameter):
+ if "value_list" in parameter["informations"]:
+ return "enum"
+ if "min" in parameter["informations"] or "max" in parameter["informations"] or re.match(r"^\d+U?L?$", parameter["value"]) != None:
+ return "int"
+
def sub(string, parameter, value):
"""
Substitute the given value at the given parameter define in the given string