def cleanTempMakefile(paths: Paths): ''' Clean default generated Makefile data (sources, includes, names, ...). ''' makefile = mkf.Makefile() try: with open(paths.tmpMakefile, 'r') as makefileHandler: data = makefileHandler.readlines() # do not change project name intentionally # data = makefile.searchAndCleanData(data, makefile.mkfStr.projectName) data = makefile.searchAndCleanData(data, makefile.mkfStr.cSources) data = makefile.searchAndCleanData(data, makefile.mkfStr.asmSources) data = makefile.searchAndCleanData(data, makefile.mkfStr.cDefines) data = makefile.searchAndCleanData(data, makefile.mkfStr.asmDefines) data = makefile.searchAndCleanData(data, makefile.mkfStr.cIncludes) data = makefile.searchAndCleanData(data, makefile.mkfStr.asmIncludes) data = makefile.searchAndCleanData(data, makefile.mkfStr.cIncludes) print("Makefile template prepared.") return data except Exception as err: errorMsg = "Exception during Makefile template preparation:\n" + str(err) utils.printAndQuit(errorMsg)
def createNewMakefile(paths: Paths, keilProjData: KeilProjectData, newMakefileData): ''' Fill and write new makefile with data from Keil project. ''' makefile = mkf.Makefile() try: # sources data = makefile.searchAndAppend(newMakefileData, makefile.mkfStr.cSources, keilProjData.cSources) data = makefile.searchAndAppend(newMakefileData, makefile.mkfStr.asmSources, keilProjData.asmSources) # includes data = makefile.searchAndAppend(newMakefileData, makefile.mkfStr.cIncludes, keilProjData.cIncludes, preappend='-I') data = makefile.searchAndAppend(newMakefileData, makefile.mkfStr.asmIncludes, keilProjData.asmIncludes, preappend='-I') # defines data = makefile.searchAndAppend(newMakefileData, makefile.mkfStr.cDefines, keilProjData.cDefines, preappend='-D') data = makefile.searchAndAppend(newMakefileData, makefile.mkfStr.asmDefines, keilProjData.asmDefines, preappend='-D') # compiler flags # TODO should import? # data = makefile.searchAndAppend(newMakefileData, makefile.mkfStr.cFlags, keilProjData.cCompilerSettings) # data = makefile.searchAndAppend(newMakefileData, makefile.mkfStr.asmFlags, keilProjData.asmCompilerSettings) if keilProjData.cCompilerSettings: print("WARNING: C compiler settings not imported (user must handle manualy):", str(keilProjData.cCompilerSettings)) if keilProjData.asmCompilerSettings: print("WARNING: Asm compiler settings not imported (user must handle manualy):", str(keilProjData.asmCompilerSettings)) if keilProjData.linkerSettings: print("WARNING: Linker settings not imported (user must handle manualy):", str(keilProjData.linkerSettings)) with open(paths.outputMakefile, 'w+') as newMakefileHandler: newMakefileHandler.writelines(data) print("Makefile created in: " + paths.outputMakefile) except Exception as err: errorMsg = "Exception during creating new Makefile:\n" + str(err) utils.printAndQuit(errorMsg)
buildDataFile.write(dataToWrite) print("'buildData.json' file updated!") except Exception as err: errorMsg = "Exception error overwriting 'buildData.json' file:\n" errorMsg += str(err) utils.printAndQuit(errorMsg) ######################################################################################################################## if __name__ == "__main__": utils.verifyFolderStructure() paths = pth.UpdatePaths() makefile = mkf.Makefile() bData = BuildData() # Makefile must exist makefile.checkMakefileFile( ) # no point in continuing if Makefile does not exist # build data (update tools paths if neccessary) bData.checkBuildDataFile() buildData = bData.getBuildData() if not paths.verifyExistingPaths(buildData): buildData = paths.forceUpdatePaths(buildData) makeExePath = buildData[bData.bStr.buildToolsPath] gccExePath = buildData[bData.bStr.gccExePath] # data from current Makefile