def generateMakefile(self, outPath='.', projectName='a', includePaths='', sourceFiles='', verbose=False): objects = [] try: fout = open( os.path.join(outPath, MAKEFILE), 'w' ) fout.write( '#\n# Automatically generated Makefile\n#\n\n' ) fout.write( 'PROJECT = ' + projectName + '\n\n' ) fout.write( 'OUTPUT_DIR = ' + outPath + '\n' ) fout.write( 'ELF_FILE = $(OUTPUT_DIR)/$(PROJECT).elf\n' ) fout.write( 'BIN_FILE = $(OUTPUT_DIR)/$(PROJECT).bin\n' ) fout.write( 'MAP_FILE = $(OUTPUT_DIR)/$(PROJECT).map\n' ) fout.write( 'LKR_SCRIPT = ' + getLinkerScript() + '\n\n') fout.write( 'TCHAIN = ' + self.TCHAIN.replace('\\','/') + '\n\n' ) fout.write( 'INCLUDES = \\\n' ) for path in includePaths: fout.write( '\t' + path + ' \\\n' ) fout.write( '\n\n' ) fout.write( 'DEFINES = ' + getCompilerDefines() + '\n') fout.write( 'CFLAGS = ' + self.Configs.getCflags() + ' $(DEFINES)\n') fout.write( 'CXXFLAGS = ' + self.Configs.getCxxflags() + ' $(DEFINES)\n') fout.write( 'AFLAGS = ' + self.Configs.getAflags() + '\n' ) fout.write( 'LFLAGS = ' + self.Configs.getLflags() + '\n\n' ) fout.write( 'LIBGCC = ${shell ${TCHAIN}gcc ${CFLAGS} -print-libgcc-file-name}\n' ) fout.write( 'LIBC = ${shell ${TCHAIN}gcc ${CFLAGS} -print-file-name=libc.a}\n' ) fout.write( 'LIBM = ${shell ${TCHAIN}gcc ${CFLAGS} -print-file-name=libm.a}\n' ) fout.write( 'LIBNOSYS = ${shell ${TCHAIN}gcc ${CXXFLAGS} -print-file-name=libnosys.a}\n' ) fout.write( 'LIBCPP = ${shell ${TCHAIN}g++ ${CXXFLAGS} -print-file-name=libstdc++.a}\n\n\n' ) fout.write( 'RM = ' + self.Configs.getRmCmd() + '\n\n\n' ) fout.write( 'OBJECTS = \\\n' ) for src in sourceFiles: src = str(src) folder, objname = os.path.split( src[:src.rfind('.')] + '.o' ) if folder.find('libraries')!=0 and folder.find('hardware')!=0: folder = 'user' objdir = os.path.join(outPath, 'obj', folder) if not os.path.exists(objdir): os.makedirs( objdir ) obj = '$(OUTPUT_DIR)/obj/' + folder + '/' + objname fout.write( '\t' + obj + ' \\\n' ) objects.append(obj) fout.write( '\n\n' ) fout.write( 'all : $(BIN_FILE)\n' ) fout.write( '\t@$(TCHAIN)size $(ELF_FILE)\n\n' ) fout.write( 'clean:\n' ) fout.write( '\t@$(RM) $(OBJECTS)\n' ) fout.write( '\t@$(RM) $(OUTPUT_DIR)/$(PROJECT).*\n\n\n' ) fout.write( '$(ELF_FILE): $(OBJECTS)\n' ) fout.write( '\t@echo [LINKER] $(@F)\n\t') if not verbose: fout.write( '@' ) fout.write( '$(TCHAIN)ld $(LFLAGS) $^ -o $@ $(LIBGCC) $(LIBC) $(LIBM) $(LIBNOSYS) $(LIBCPP)\n\n' ) fout.write( '$(BIN_FILE): $(ELF_FILE)\n' ) fout.write( '\t@echo [BIN Copy] $(@F)\n') fout.write( '\t@$(TCHAIN)objcopy -Obinary $< $@\n\n\n' ) i = 0 for src in sourceFiles: src = str(src) fout.write( objects[i] + ' : ' + src + '\n') src_ext = os.path.splitext(src)[1].lower() if src_ext == USER_CODE_EXT: fout.write( '\t@echo [CXX] $< \n\t' ) if not verbose: fout.write( '@' ) fout.write( '$(TCHAIN)gcc $(INCLUDES) $(CXXFLAGS) -x c++ $< -o $@\n\n') elif src_ext == '.s': fout.write( '\t@echo [AS] $(<F)\n\t' ) if not verbose: fout.write( '@' ) fout.write( '$(TCHAIN)as $(AFLAGS) $< -o $@\n\n') elif src_ext == '.c': fout.write( '\t@echo [CC] $(<F)\n\t' ) if not verbose: fout.write( '@' ) fout.write( '$(TCHAIN)gcc $(INCLUDES) $(CFLAGS) $< -o $@\n\n') elif src_ext == '.cpp': fout.write( '\t@echo [CPP] $(<F)\n\t' ) if not verbose: fout.write( '@' ) fout.write( '$(TCHAIN)g++ $(INCLUDES) $(CXXFLAGS) $< -o $@\n\n') i += 1 fout.close() return True except: return False
def generateMakefile(self, outPath='.', projectName='a', includePaths='', sourceFiles='', verbose=False): objects = [] try: fout = open(os.path.join(outPath, MAKEFILE), 'w') fout.write('#\n# Automatically generated Makefile\n#\n\n') fout.write('PROJECT = ' + projectName + '\n\n') fout.write('OUTPUT_DIR = ' + outPath + '\n') fout.write('ELF_FILE = $(OUTPUT_DIR)/$(PROJECT).elf\n') fout.write('BIN_FILE = $(OUTPUT_DIR)/$(PROJECT).bin\n') fout.write('MAP_FILE = $(OUTPUT_DIR)/$(PROJECT).map\n') fout.write('LKR_SCRIPT = ' + getLinkerScript() + '\n\n') fout.write('TCHAIN = ' + self.TCHAIN.replace('\\', '/') + '\n\n') fout.write('INCLUDES = \\\n') for path in includePaths: fout.write('\t' + path + ' \\\n') fout.write('\n\n') fout.write('DEFINES = ' + getCompilerDefines() + '\n') fout.write('CFLAGS = ' + self.Configs.getCflags() + ' $(DEFINES)\n') fout.write('CXXFLAGS = ' + self.Configs.getCxxflags() + ' $(DEFINES)\n') fout.write('AFLAGS = ' + self.Configs.getAflags() + '\n') fout.write('LFLAGS = ' + self.Configs.getLflags() + '\n\n\n') fout.write('RM = ' + self.Configs.getRmCmd() + '\n\n\n') fout.write('OBJECTS = \\\n') for src in sourceFiles: src = str(src) folder, objname = os.path.split(src[:src.rfind('.')] + '.o') if folder.find('libraries') != 0 and folder.find( 'hardware') != 0: folder = 'user' objdir = os.path.join(outPath, 'obj', folder) if not os.path.exists(objdir): os.makedirs(objdir) obj = '$(OUTPUT_DIR)/obj/' + folder + '/' + objname fout.write('\t' + obj + ' \\\n') objects.append(obj) fout.write('\n\n') fout.write('all : $(BIN_FILE)\n') fout.write('\t@$(TCHAIN)size $(ELF_FILE)\n\n') fout.write('clean:\n') fout.write('\t@$(RM) $(OBJECTS)\n') fout.write('\t@$(RM) $(OUTPUT_DIR)/$(PROJECT).*\n\n\n') fout.write('$(ELF_FILE): $(OBJECTS)\n') fout.write('\t@echo [LINKER] $(@F)\n\t') if not verbose: fout.write('@') fout.write('$(TCHAIN)gcc $(LFLAGS) $^ -o $@\n\n') fout.write('$(BIN_FILE): $(ELF_FILE)\n') fout.write('\t@echo [BIN Copy] $(@F)\n') fout.write('\t@$(TCHAIN)objcopy -Obinary $< $@\n\n\n') i = 0 for src in sourceFiles: src = str(src) fout.write(objects[i] + ' : ' + src + '\n') src_ext = os.path.splitext(src)[1].lower() if src_ext == USER_CODE_EXT: fout.write('\t@echo [CXX] $< \n\t') if not verbose: fout.write('@') fout.write( '$(TCHAIN)gcc $(INCLUDES) $(CXXFLAGS) -x c++ $< -o $@\n\n' ) elif src_ext == '.s': fout.write('\t@echo [AS] $(<F)\n\t') if not verbose: fout.write('@') fout.write('$(TCHAIN)as $(AFLAGS) $< -o $@\n\n') elif src_ext == '.c': fout.write('\t@echo [CC] $(<F)\n\t') if not verbose: fout.write('@') fout.write( '$(TCHAIN)gcc $(INCLUDES) $(CFLAGS) $< -o $@\n\n') elif src_ext == '.cpp': fout.write('\t@echo [CPP] $(<F)\n\t') if not verbose: fout.write('@') fout.write( '$(TCHAIN)gcc $(INCLUDES) $(CXXFLAGS) $< -o $@\n\n') i += 1 fout.close() return True except: return False
def generateMakefile(self, outPath='.', projectName='a', includePaths='', sourceFiles='', verbose=False): objects = [] try: fout = open(os.path.join(outPath, MAKEFILE), 'w') fout.write('#\n# Automatically generated Makefile\n#\n\n') fout.write('PROJECT = ' + projectName + '\n') fout.write('MCUARCH = ' + getMcuArchitecture(self.McuPart) + '\n') fout.write('MCUPART = ' + self.McuPart + '\n\n') fout.write('OUTPUT_DIR = ' + outPath + '\n') fout.write('ELF_FILE = $(OUTPUT_DIR)/$(PROJECT).elf\n') fout.write('HEX_FILE = $(OUTPUT_DIR)/$(PROJECT).hex\n') fout.write('MAP_FILE = $(OUTPUT_DIR)/$(PROJECT).map\n') fout.write('LKR_SCRIPT = ' + getLinkerScript(self.McuPart) + '\n\n') fout.write('TCHAIN = ' + self.TCHAIN.replace('\\', '/') + '\n\n') fout.write('INCLUDES = \\\n') for path in includePaths: fout.write('\t' + path + ' \\\n') fout.write('\n\n') fout.write('DEFINES = ' + getCompilerDefines() + '\n') fout.write('CFLAGS = ' + self.Configs.getCflags() + ' $(DEFINES)\n') fout.write('CXXFLAGS = ' + self.Configs.getCxxflags() + ' $(DEFINES)\n') fout.write('AFLAGS = ' + self.Configs.getAflags() + '\n') fout.write('LFLAGS = ' + self.Configs.getLflags() + '\n\n\n') fout.write('RM = ' + self.Configs.getRmCmd() + '\n\n\n') fout.write('OBJECTS = \\\n') for src in sourceFiles: src = str(src) folder, objname = os.path.split(src[:src.rfind('.')] + '.o') if folder.find('libraries') != 0 and folder.find( 'hardware') != 0: folder = 'user' objdir = os.path.join(outPath, 'obj', folder) if not os.path.exists(objdir): os.makedirs(objdir) obj = '$(OUTPUT_DIR)/obj/' + folder + '/' + objname fout.write('\t' + obj + ' \\\n') objects.append(obj) fout.write('\n\n') fout.write('all : $(OBJECTS)\n') fout.write('\t@echo [LINK] $(notdir $(ELF_FILE))\n\t') if not verbose: fout.write('@') fout.write('$(TCHAIN)g++ $(LFLAGS) $^ -o $(ELF_FILE)\n') fout.write('\t@echo [HEX] $(notdir $(HEX_FILE))\n') fout.write( '\t@$(TCHAIN)objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $(ELF_FILE) $(HEX_FILE)\n' ) fout.write('\t@$(TCHAIN)size $(ELF_FILE)\n\n') fout.write('clean:\n') fout.write('\t@$(RM) $(OBJECTS)\n') fout.write('\t@$(RM) $(ELF_FILE) $(HEX_FILE) $(MAP_FILE)\n\n\n') fout.write('program: $(HEX_FILE)\n') fout.write( '\tbatchisp -device at32$(MCUPART) -hardware RS232 -port $(COMPORT) ' ) fout.write( '-operation erase f memory flash blankcheck loadbuffer $(HEX_FILE) ' ) fout.write('program verify start reset 0\n\n\n') i = 0 for src in sourceFiles: src = str(src) fout.write(objects[i] + ' : ' + src + '\n') src_ext = os.path.splitext(src)[1].lower() if src_ext == USER_CODE_EXT: fout.write('\t@echo [CXX] $< \n\t') if not verbose: fout.write('@') fout.write( '$(TCHAIN)g++ $(INCLUDES) $(CXXFLAGS) -x c++ $< -o $@\n\n' ) elif src_ext == '.s': fout.write('\t@echo [AS] $(<F)\n\t') if not verbose: fout.write('@') fout.write( '$(TCHAIN)gcc -x assembler-with-cpp $(AFLAGS) $< -o $@\n\n' ) elif src_ext == '.c': fout.write('\t@echo [CC] $(<F)\n\t') if not verbose: fout.write('@') fout.write( '$(TCHAIN)gcc $(INCLUDES) $(CFLAGS) $< -o $@\n\n') elif src_ext == '.cpp': fout.write('\t@echo [CPP] $(<F)\n\t') if not verbose: fout.write('@') fout.write( '$(TCHAIN)g++ $(INCLUDES) $(CXXFLAGS) $< -o $@\n\n') i += 1 fout.close() return True except: return False
def generateMakefile(self, outPath='.', projectName='a', includePaths='', sourceFiles='', verbose=False): objects = [] try: fout = open( os.path.join(outPath, MAKEFILE), 'w' ) fout.write( '#\n# Automatically generated Makefile\n#\n\n' ) fout.write( 'PROJECT = ' + projectName + '\n' ) fout.write( 'MCUARCH = ' + getMcuArchitecture(self.McuPart) + '\n' ) fout.write( 'MCUPART = ' + self.McuPart + '\n\n' ) fout.write( 'OUTPUT_DIR = ' + outPath + '\n' ) fout.write( 'ELF_FILE = $(OUTPUT_DIR)/$(PROJECT).elf\n' ) fout.write( 'HEX_FILE = $(OUTPUT_DIR)/$(PROJECT).hex\n' ) fout.write( 'MAP_FILE = $(OUTPUT_DIR)/$(PROJECT).map\n' ) fout.write( 'LKR_SCRIPT = ' + getLinkerScript(self.McuPart) + '\n\n') fout.write( 'TCHAIN = ' + self.TCHAIN.replace('\\','/') + '\n\n' ) fout.write( 'INCLUDES = \\\n' ) for path in includePaths: fout.write( '\t' + path + ' \\\n' ) fout.write( '\n\n' ) fout.write( 'DEFINES = ' + getCompilerDefines() + '\n') fout.write( 'CFLAGS = ' + self.Configs.getCflags() + ' $(DEFINES)\n') fout.write( 'CXXFLAGS = ' + self.Configs.getCxxflags() + ' $(DEFINES)\n') fout.write( 'AFLAGS = ' + self.Configs.getAflags() + '\n' ) fout.write( 'LFLAGS = ' + self.Configs.getLflags() + '\n\n\n' ) fout.write( 'RM = ' + self.Configs.getRmCmd() + '\n\n\n' ) fout.write( 'OBJECTS = \\\n' ) for src in sourceFiles: src = str(src) folder, objname = os.path.split( src[:src.rfind('.')] + '.o' ) if folder.find('libraries')!=0 and folder.find('hardware')!=0: folder = 'user' objdir = os.path.join(outPath, 'obj', folder) if not os.path.exists(objdir): os.makedirs( objdir ) obj = '$(OUTPUT_DIR)/obj/' + folder + '/' + objname fout.write( '\t' + obj + ' \\\n' ) objects.append(obj) fout.write( '\n\n' ) fout.write( 'all : $(OBJECTS)\n' ) fout.write( '\t@echo [LINK] $(notdir $(ELF_FILE))\n\t') if not verbose: fout.write( '@' ) fout.write( '$(TCHAIN)g++ $(LFLAGS) $^ -o $(ELF_FILE)\n' ) fout.write( '\t@echo [HEX] $(notdir $(HEX_FILE))\n') fout.write( '\t@$(TCHAIN)objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $(ELF_FILE) $(HEX_FILE)\n' ) fout.write( '\t@$(TCHAIN)size $(ELF_FILE)\n\n' ) fout.write( 'clean:\n' ) fout.write( '\t@$(RM) $(OBJECTS)\n' ) fout.write( '\t@$(RM) $(ELF_FILE) $(HEX_FILE) $(MAP_FILE)\n\n\n' ) fout.write( 'program: $(HEX_FILE)\n' ) fout.write( '\tbatchisp -device at32$(MCUPART) -hardware RS232 -port $(COMPORT) ' ) fout.write( '-operation erase f memory flash blankcheck loadbuffer $(HEX_FILE) ' ) fout.write( 'program verify start reset 0\n\n\n' ) i = 0 for src in sourceFiles: src = str(src) fout.write( objects[i] + ' : ' + src + '\n') src_ext = os.path.splitext(src)[1].lower() if src_ext == USER_CODE_EXT: fout.write( '\t@echo [CXX] $< \n\t' ) if not verbose: fout.write( '@' ) fout.write( '$(TCHAIN)g++ $(INCLUDES) $(CXXFLAGS) -x c++ $< -o $@\n\n') elif src_ext == '.s': fout.write( '\t@echo [AS] $(<F)\n\t' ) if not verbose: fout.write( '@' ) fout.write( '$(TCHAIN)gcc -x assembler-with-cpp $(AFLAGS) $< -o $@\n\n') elif src_ext == '.c': fout.write( '\t@echo [CC] $(<F)\n\t' ) if not verbose: fout.write( '@' ) fout.write( '$(TCHAIN)gcc $(INCLUDES) $(CFLAGS) $< -o $@\n\n') elif src_ext == '.cpp': fout.write( '\t@echo [CPP] $(<F)\n\t' ) if not verbose: fout.write( '@' ) fout.write( '$(TCHAIN)g++ $(INCLUDES) $(CXXFLAGS) $< -o $@\n\n') i += 1 fout.close() return True except: return False