+def mkGenerator(projectInfo, makefile):
+ """
+ Generates the mk file for the current project.
+ """
+ mkData = {}
+ mkData["$pname"] = os.path.basename(projectInfo.info("PROJECT_PATH"))
+ 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"], 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"
+ for key in mkData:
+ while makefile.find(key) != -1:
+ makefile = makefile.replace(key, mkData[key])
+ return makefile
+
+def makefileGenerator(projectInfo, makefile):
+ """
+ Generate the Makefile for the current project.
+ """
+ # TODO: write a general function that works for both the mk file and the Makefile
+ while makefile.find("project_name") != -1:
+ makefile = makefile.replace("project_name", os.path.basename(projectInfo.info("PROJECT_PATH")))
+ return makefile
+
+def csrcGenerator(projectInfo):
+ modules = projectInfo.info("MODULES")
+ if "harvard" in projectInfo.info("CPU_INFOS")["CPU_TAGS"]:
+ harvard = True
+ else:
+ harvard = False
+ csrc = []
+ pcsrc = []
+ constants = {}
+ for module, information in modules.items():
+ if information["enabled"]:
+ if "constants" in information:
+ constants.update(information["constants"])
+ for filename, path in findDefinitions(module + ".c", projectInfo):
+ path = path.replace(projectInfo.info("SOURCES_PATH"), projectInfo.info("PROJECT_PATH"))
+ if not harvard or "harvard" not in information or information["harvard"] == "both":
+ csrc.append(path + "/" + filename)
+ if harvard and "harvard" in information:
+ 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"))
+ if not harvard or "harvard" not in information or information["harvard"] == "both":
+ csrc.append(path + "/" + filename)
+ if harvard and "harvard" in information:
+ 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"))
+ if not harvard or "harvard" not in information or information["harvard"] == "both":
+ csrc.append(path + "/" + filename)
+ if harvard and "harvard" in information:
+ pcsrc.append(path + "/" + filename)
+ csrc = " \\\n\t".join(csrc) + " \\"
+ pcsrc = " \\\n\t".join(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 codeliteProjectGenerator(projectInfo):
+ template = open("cltemplates/bertos.project").read()
+ filelist = "\n".join(codelite_project.clFiles(codelite_project.findSources(projectInfo.info("PROJECT_PATH")), projectInfo.info("PROJECT_PATH")))
+ while template.find("$filelist") != -1:
+ template = template.replace("$filelist", filelist)
+ projectName = os.path.basename(projectInfo.info("PROJECT_PATH"))
+ while template.find("$project") != -1:
+ template = template.replace("$project", projectName)
+ return template
+
+def codeliteWorkspaceGenerator(projectInfo):
+ template = open("cltemplates/bertos.workspace").read()
+ projectName = os.path.basename(projectInfo.info("PROJECT_PATH"))
+ while template.find("$project") != -1:
+ template = template.replace("$project", projectName)
+ return template
+