def __init__(self, sourceFilePath, includePaths, sourceDirPath, objectDirPath, makeConf): Rule.__init__(self) relPath = sourceFilePath.getRelevantPath(sourceDirPath) dirName = relPath.getDirName() baseName = relPath.getBaseName() objectSubDirPath = objectDirPath.join(dirName) objectFilePath = objectSubDirPath.join(PathUtil.getPrefix(baseName)) if sourceFilePath.getExt() not in makeConf['asm_src_exts']: objectFilePath.appendExt('o') if sourceFilePath.getExt() in makeConf['asm_src_exts'] and makeConf['asm_with_object_ext']: objectFilePath.appendExt('o') self.setTarget(objectFilePath.shellString()) self.sourceFilePath = sourceFilePath self.includePaths = includePaths self.objectSubDirPath = objectSubDirPath if self.sourceFilePath.getExt() in makeConf['c_src_exts']: self.includePaths.extend(PathUtil.toPathList(makeConf['c_include_paths'])) elif self.sourceFilePath.getExt() in makeConf['cxx_src_exts']: if makeConf['cxx_using_c_include_paths']: self.includePaths.extend(PathUtil.toPathList(makeConf['c_include_paths'])) self.includePaths.extend(PathUtil.toPathList(makeConf['cxx_include_paths'])) elif self.sourceFilePath.getExt() in makeConf['asm_src_exts']: self.includePaths.extend(PathUtil.toPathList(makeConf['asm_include_paths'])) self.targetLine = self.generateTargetLine(makeConf) makeDirectoryAction = MakeDirectoryAction(objectSubDirPath) compileAction = GCCCompileAction(objectFilePath, sourceFilePath, includePaths, makeConf) self.addBuildAction(makeDirectoryAction) self.addBuildAction(compileAction)
def __init__(self, sourceFilePath, includePaths, sourceDirPath, objectDirPath, makeConf): Rule.__init__(self) relPath = sourceFilePath.getRelevantPath(sourceDirPath) dirName = relPath.getDirName() baseName = relPath.getBaseName() objectSubDirPath = objectDirPath.join(dirName) objectFilePath = objectSubDirPath.join(PathUtil.getPrefix(baseName)) if sourceFilePath.getExt() not in makeConf['asm_src_exts']: objectFilePath.appendExt('o') if sourceFilePath.getExt( ) in makeConf['asm_src_exts'] and makeConf['asm_with_object_ext']: objectFilePath.appendExt('o') self.setTarget(objectFilePath.shellString()) self.sourceFilePath = sourceFilePath self.includePaths = includePaths self.objectSubDirPath = objectSubDirPath if self.sourceFilePath.getExt() in makeConf['c_src_exts']: self.includePaths.extend( PathUtil.toPathList(makeConf['c_include_paths'])) elif self.sourceFilePath.getExt() in makeConf['cxx_src_exts']: if makeConf['cxx_using_c_include_paths']: self.includePaths.extend( PathUtil.toPathList(makeConf['c_include_paths'])) self.includePaths.extend( PathUtil.toPathList(makeConf['cxx_include_paths'])) elif self.sourceFilePath.getExt() in makeConf['asm_src_exts']: self.includePaths.extend( PathUtil.toPathList(makeConf['asm_include_paths'])) self.targetLine = self.generateTargetLine(makeConf) makeDirectoryAction = MakeDirectoryAction(objectSubDirPath) compileAction = GCCCompileAction(objectFilePath, sourceFilePath, includePaths, makeConf) self.addBuildAction(makeDirectoryAction) self.addBuildAction(compileAction)
def make(self, projectConfig): makeConf = { 'target_type': projectConfig.getItem('make.configuration.target.type', self.defaultConf['target_type']), 'cc': projectConfig.getItem('make.configuration.compiler.c.cc', self.defaultConf['cc']), 'cxxc': projectConfig.getItem('make.configuration.compiler.cpp.cc', self.defaultConf['cxxc']), 'cflags': projectConfig.getItem('make.configuration.compiler.c.flags', self.defaultConf['cflags']), 'cxxflags': projectConfig.getItem('make.configuration.compiler.cpp.flags', self.defaultConf['cxxflags']), 'fpic': projectConfig.getItem('make.configuration.compiler.fpic', self.defaultConf['fpic']), 'autolink': projectConfig.getItem('make.configuration.linker.autolink', self.defaultConf['autolink']), 'ar': projectConfig.getItem('make.configuration.archiver.ar', self.defaultConf['ar']), 'ld': projectConfig.getItem('make.configuration.linker.ld', self.defaultConf['ld']), 'ldflags': projectConfig.getItem('make.configuration.linker.flags', self.defaultConf['ldflags']), 'ld_library_paths': projectConfig.getItem('make.configuration.linker.library_paths', self.defaultConf['ld_library_paths']), 'libraries': projectConfig.getItem('make.configuration.linker.libraries', []), 'c_src_exts': projectConfig.getItem('make.configuration.compiler.c.src_exts', self.defaultConf['c_src_exts']), 'cxx_src_exts': projectConfig.getItem('make.configuration.compiler.cpp.src_exts', self.defaultConf['cxx_src_exts']), 'c_include_paths': projectConfig.getItem('make.configuration.compiler.c.include_paths', self.defaultConf['c_include_paths']), 'cxx_include_paths': projectConfig.getItem('make.configuration.compiler.cpp.include_paths', self.defaultConf['cxx_include_paths']), 'cxx_using_c_include_paths': projectConfig.getItem('make.configuration.compiler.cpp.inherit_c_include_path', self.defaultConf['cxx_using_c_include_paths']) } makefile = GMakeDocument(TARGET_MAKEFILE_PATH) self.mainSourceFiles.clear() self.objectFiles.clear() cSourceFiles = [] cppSourceFiles = [] FileUtil.searchAllFiles(cSourceFiles, SRC_MAIN_PATH, makeConf['c_src_exts']) FileUtil.searchAllFiles(cppSourceFiles, SRC_MAIN_PATH, makeConf['cxx_src_exts']) self.mainSourceFiles.extend(cSourceFiles) self.mainSourceFiles.extend(cppSourceFiles) for fileName in self.mainSourceFiles: filePath = Path(fileName, True) relPath = filePath.getRelevantPath(SRC_MAIN_PATH) dirName = relPath.getDirName() baseName = relPath.getBaseName() subMakeDirPath = TARGET_SUBMAKE_MAIN_PATH.join(dirName) FileUtil.createDirectory(subMakeDirPath) subMakefilePath = subMakeDirPath.join(PathUtil.getPrefix(baseName)) subMakefilePath.appendExt('mk') subMakefile = GMakeDocument(subMakefilePath) compileRule = GCCCompileRule(filePath, [INCLUDE_MAIN_PATH], SRC_MAIN_PATH, TARGET_OBJECT_MAIN_PATH, makeConf) subMakefile.addRule(compileRule) makefile.addSubDocument(subMakefile) objectFilePath = Path(compileRule.getTarget()) self.objectFiles.append(objectFilePath) if makeConf['autolink']: if makeConf['target_type'] == 'executable': subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH) finalFileName = '%(name)s-%(version)s' % { 'name': projectConfig.getItem('project.name', 'noname'), 'version': projectConfig.getItem('project.version', '1.0.0')} finalFilePath = TARGET_PATH.join(finalFileName) linkRule = GCCLinkRule(finalFilePath, self.objectFiles, makeConf) subMakefile.addRule(linkRule) makefile.addSubDocument(subMakefile) allRule = GMakeSimpleRule('all', [finalFilePath]) makefile.addRule(allRule) elif makeConf['target_type'] == 'dynamic_library': subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH) finalFileName = 'lib%(name)s.so.%(version)s' % { 'name': projectConfig.getItem('project.name', 'noname'), 'version': projectConfig.getItem('project.version', '1.0.0')} finalFilePath = TARGET_PATH.join(finalFileName) linkRule = GCCLinkRule(finalFilePath, self.objectFiles, makeConf) subMakefile.addRule(linkRule) makefile.addSubDocument(subMakefile) allRule = GMakeSimpleRule('all', [finalFilePath]) makefile.addRule(allRule) elif makeConf['target_type'] == 'static_library': subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH) finalFileName = 'lib%(name)s.a.%(version)s' % { 'name': projectConfig.getItem('project.name', 'noname'), 'version': projectConfig.getItem('project.version', '1.0.0')} finalFilePath = TARGET_PATH.join(finalFileName) arRule = ArRule(finalFilePath, self.objectFiles, makeConf) subMakefile.addRule(arRule) makefile.addSubDocument(subMakefile) allRule = GMakeSimpleRule('all', [finalFilePath]) makefile.addRule(allRule) else: self.logger.warn('target_type is not recognized!') sys.exit(1) else: allRule = GMakeSimpleRule('all', self.objectFiles) makefile.addRule(allRule) makefile.writeToFile() return True
def make(self, projectConfig): makeConf = { 'target_type': projectConfig.getItem('make.configuration.target.type', self.defaultConf['target_type']), 'cc': projectConfig.getItem('make.configuration.compiler.c.cc', self.defaultConf['cc']), 'cxxc': projectConfig.getItem('make.configuration.compiler.cpp.cc', self.defaultConf['cxxc']), 'cflags': projectConfig.getItem('make.configuration.compiler.c.flags', self.defaultConf['cflags']), 'cxxflags': projectConfig.getItem('make.configuration.compiler.cpp.flags', self.defaultConf['cxxflags']), 'fpic': projectConfig.getItem('make.configuration.compiler.fpic', self.defaultConf['fpic']), 'autolink': projectConfig.getItem('make.configuration.linker.autolink', self.defaultConf['autolink']), 'ar': projectConfig.getItem('make.configuration.archiver.ar', self.defaultConf['ar']), 'ld': projectConfig.getItem('make.configuration.linker.ld', self.defaultConf['ld']), 'ldflags': projectConfig.getItem('make.configuration.linker.flags', self.defaultConf['ldflags']), 'ld_library_paths': projectConfig.getItem('make.configuration.linker.library_paths', self.defaultConf['ld_library_paths']), 'libraries': projectConfig.getItem('make.configuration.linker.libraries', []), 'c_src_exts': projectConfig.getItem('make.configuration.compiler.c.src_exts', self.defaultConf['c_src_exts']), 'cxx_src_exts': projectConfig.getItem('make.configuration.compiler.cpp.src_exts', self.defaultConf['cxx_src_exts']), 'c_include_paths': projectConfig.getItem( 'make.configuration.compiler.c.include_paths', self.defaultConf['c_include_paths']), 'cxx_include_paths': projectConfig.getItem( 'make.configuration.compiler.cpp.include_paths', self.defaultConf['cxx_include_paths']), 'cxx_using_c_include_paths': projectConfig.getItem( 'make.configuration.compiler.cpp.inherit_c_include_path', self.defaultConf['cxx_using_c_include_paths']) } makefile = GMakeDocument(TARGET_MAKEFILE_PATH) self.mainSourceFiles.clear() self.objectFiles.clear() cSourceFiles = [] cppSourceFiles = [] FileUtil.searchAllFiles(cSourceFiles, SRC_MAIN_PATH, makeConf['c_src_exts']) FileUtil.searchAllFiles(cppSourceFiles, SRC_MAIN_PATH, makeConf['cxx_src_exts']) self.mainSourceFiles.extend(cSourceFiles) self.mainSourceFiles.extend(cppSourceFiles) for fileName in self.mainSourceFiles: filePath = Path(fileName, True) relPath = filePath.getRelevantPath(SRC_MAIN_PATH) dirName = relPath.getDirName() baseName = relPath.getBaseName() subMakeDirPath = TARGET_SUBMAKE_MAIN_PATH.join(dirName) FileUtil.createDirectory(subMakeDirPath) subMakefilePath = subMakeDirPath.join(PathUtil.getPrefix(baseName)) subMakefilePath.appendExt('mk') subMakefile = GMakeDocument(subMakefilePath) compileRule = GCCCompileRule(filePath, [INCLUDE_MAIN_PATH], SRC_MAIN_PATH, TARGET_OBJECT_MAIN_PATH, makeConf) subMakefile.addRule(compileRule) makefile.addSubDocument(subMakefile) objectFilePath = Path(compileRule.getTarget()) self.objectFiles.append(objectFilePath) if makeConf['autolink']: if makeConf['target_type'] == 'executable': subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH) finalFileName = '%(name)s-%(version)s' % { 'name': projectConfig.getItem('project.name', 'noname'), 'version': projectConfig.getItem('project.version', '1.0.0') } finalFilePath = TARGET_PATH.join(finalFileName) linkRule = GCCLinkRule(finalFilePath, self.objectFiles, makeConf) subMakefile.addRule(linkRule) makefile.addSubDocument(subMakefile) allRule = GMakeSimpleRule('all', [finalFilePath]) makefile.addRule(allRule) elif makeConf['target_type'] == 'dynamic_library': subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH) finalFileName = 'lib%(name)s.so.%(version)s' % { 'name': projectConfig.getItem('project.name', 'noname'), 'version': projectConfig.getItem('project.version', '1.0.0') } finalFilePath = TARGET_PATH.join(finalFileName) linkRule = GCCLinkRule(finalFilePath, self.objectFiles, makeConf) subMakefile.addRule(linkRule) makefile.addSubDocument(subMakefile) allRule = GMakeSimpleRule('all', [finalFilePath]) makefile.addRule(allRule) elif makeConf['target_type'] == 'static_library': subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH) finalFileName = 'lib%(name)s.a.%(version)s' % { 'name': projectConfig.getItem('project.name', 'noname'), 'version': projectConfig.getItem('project.version', '1.0.0') } finalFilePath = TARGET_PATH.join(finalFileName) arRule = ArRule(finalFilePath, self.objectFiles, makeConf) subMakefile.addRule(arRule) makefile.addSubDocument(subMakefile) allRule = GMakeSimpleRule('all', [finalFilePath]) makefile.addRule(allRule) else: self.logger.warn('target_type is not recognized!') sys.exit(1) else: allRule = GMakeSimpleRule('all', self.objectFiles) makefile.addRule(allRule) makefile.writeToFile() return True