def __init__(self, platform, configuration, filename): self.configuration = configuration if platform.is_windows(): self.filename = convert_to_windows_slashes(filename) self.format = 'Windows' else: self.filename = convert_to_linux_slashes(filename) self.format = 'Unix'
def write_all_target(self, line_list): """ Output the "all" rule """ source_list = [] if self.solution.project_list: codefiles = self.solution.project_list[0].codefiles else: codefiles = [] for item in codefiles: if item.type is FileTypes.c or \ item.type is FileTypes.cpp or \ item.type is FileTypes.x86: entry = convert_to_linux_slashes(item.relative_pathname) source_list.append(entry) if source_list: line_list.extend( ['', '#', '# Disable building the source files', '#', '']) items = ' '.join(source_list) line_list.append(items + ': ;') line_list.extend([ '', '#', '# Build the object file folder', '#', '', '$(OBJS): | $(TEMP_DIR)', '', '$(TEMP_DIR):', '\t@-mkdir -p $(TEMP_DIR)' ]) line_list.extend([ '', '#', '# Build the object files', '#', ]) for item in source_list: # Hack off the .cpp extension index = item.rfind('.') if index == -1: entry = item else: entry = item[:index] # Hack off the directory prefix index = entry.rfind('/') if index != -1: entry = entry[index + 1:] line_list.extend([ '', '$(TEMP_DIR)/{0}.o: {1} ; $(BUILD_CPP)'.format( entry, item) ]) return 0
def write_files(self, line_list): """ Output the list of object files to create """ line_list.extend( ['', '#', '# Object files to work with for the library', '#', '']) obj_list = [] if self.solution.project_list: codefiles = self.solution.project_list[0].codefiles else: codefiles = [] for item in codefiles: if item.type is FileTypes.c or \ item.type is FileTypes.cpp or \ item.type is FileTypes.x86: tempfile = convert_to_linux_slashes(item.relative_pathname) index = tempfile.rfind('.') if index == -1: entry = tempfile else: entry = tempfile[:index] index = entry.rfind('/') if index != -1: entry = entry[index + 1:] obj_list.append(entry) if obj_list: colon = 'OBJS:= ' for item in sorted(obj_list): line_list.append(colon + '$(TEMP_DIR)/' + item + '.o \\') colon = '\t' # Remove the ' &' from the last line line_list[-1] = line_list[-1][:-2] line_list.append('') colon = 'DEPS:= ' for item in sorted(obj_list): line_list.append(colon + '$(TEMP_DIR)/' + item + '.d \\') colon = '\t' # Remove the ' &' from the last line line_list[-1] = line_list[-1][:-2] else: line_list.append('OBJS:=') line_list.append('DEPS:=') return 0
def get_abspath(self): """ Return the full pathname of the file entry. Returns: Absolute pathname for the file. """ if get_windows_host_type(): file_name = self.relative_pathname else: file_name = convert_to_linux_slashes(self.relative_pathname) return os.path.abspath(os.path.join(self.working_directory, file_name))
def __init__(self, platform, configuration, filename): if platform.is_windows(): self.filename = convert_to_windows_slashes(filename) self.format = 'Windows' else: self.filename = convert_to_linux_slashes(filename) self.format = 'Unix' self.flags = '' if self.filename.endswith('.lib') or self.filename.endswith('.a'): self.kind = 'Library' else: self.kind = 'Text' if configuration != 'Release' and \ self.filename.endswith(('.c', '.cpp')): self.flags = 'Debug'
def write_source_dir(self, line_list): """ Write out the list of directories for the source """ # Set the folders for the source code to search line_list.extend([ '', '#', '# SOURCE_DIRS = Work directories for the source code', '#', '' ]) # Extract the directories from the files # Sort them for consistent diffs for source control include_folders = [] source_folders = [] for configuration in self.configuration_list: for item in configuration.get_unique_chained_list( '_source_include_list'): if item not in source_folders: source_folders.append(item) for item in configuration.get_unique_chained_list( 'include_folders_list'): if item not in include_folders: include_folders.append(item) if source_folders: colon = ':=' for item in sorted(source_folders): line_list.append('SOURCE_DIRS ' + colon + encapsulate_path_linux(item)) colon = '+=' else: line_list.append('SOURCE_DIRS :=') # Extra include folders line_list.extend([ '', '#', '# INCLUDE_DIRS = Header includes', '#', '', 'INCLUDE_DIRS = $(SOURCE_DIRS) $(BURGER_SDKS)/linux/burgerlib' ]) for item in include_folders: line_list.append('INCLUDE_DIRS +=' + convert_to_linux_slashes(item)) return 0
def __init__(self, platform, path, root=None, title='SearchPath'): self.settings = SETTING(title) if path.startswith('$('): index = path.find(')') if index != -1: root = path[2:index] path = path[index + 1:] if path[0] in ('\\', '/'): path = path[1:] if platform.is_windows(): self.settings.addsetting('Path', convert_to_windows_slashes(path)) pathformat = 'Windows' else: self.settings.addsetting('Path', convert_to_linux_slashes(path)) pathformat = 'Unix' self.settings.addsetting('PathFormat', pathformat) if root is not None: self.settings.addsetting('PathRoot', root)
def write_source_dir(self, line_list): """ Write out the list of directories for the source """ # Save the refernence BURGER_SDKS line_list.extend([ '', '#', '# Ensure sdks are pulled from the environment', '#', '', 'BURGER_SDKS = $(%BURGER_SDKS)' ]) # Set the folders for the source code to search line_list.extend([ '', '#', '# SOURCE_DIRS = Work directories for the source code', '#', '' ]) # Extract the directories from the files # Sort them for consistent diffs for source control include_folders = [] source_folders = [] for configuration in self.configuration_list: for item in configuration.get_unique_chained_list( '_source_include_list'): if item not in source_folders: source_folders.append(item) for item in configuration.get_unique_chained_list( 'include_folders_list'): if item not in include_folders: include_folders.append(item) if source_folders: colon = '=' for item in sorted(source_folders): line_list.append('SOURCE_DIRS ' + colon + encapsulate_path_linux(item)) colon = '+=;' else: line_list.append('SOURCE_DIRS =') # Save the project name line_list.extend([ '', '#', '# Name of the output library', '#', '', 'PROJECT_NAME = ' + self.solution.name ]) # Save the base name of the temp directory line_list.extend([ '', '#', '# Base name of the temp directory', '#', '', 'BASE_TEMP_DIR = temp/$(PROJECT_NAME)', 'BASE_SUFFIX = wat$(TARGET_SUFFIX_$(%TARGET))' '$(CONFIG_SUFFIX_$(%CONFIG))', 'TEMP_DIR = $(BASE_TEMP_DIR)$(BASE_SUFFIX)' ]) # Save the final binary output directory line_list.extend( ['', '#', '# Binary directory', '#', '', 'DESTINATION_DIR = bin']) # Extra include folders line_list.extend([ '', '#', '# INCLUDE_DIRS = Header includes', '#', '', 'INCLUDE_DIRS = $(SOURCE_DIRS)' ]) for item in include_folders: line_list.append('INCLUDE_DIRS +=;' + convert_to_linux_slashes(item)) return 0
def __init__(self, solution, projectname=None, idecode=None, platformcode=None): """ Initialize the exporter. """ ## Parent solution self.solution = solution ## List of all configurations self.configuration_list = [] self.solution = solution self.projectname = projectname self.idecode = idecode self.platformcode = platformcode self.projectnamecode = '' # str(projectname + idecode + platformcode) # Data chunks self.project_list = [] self.orderedtargets = [] self.group = GROUP(None) # Create a phony empty project called "Everything" that will # build all sub project rootproject = self.addtarget('Everything', 'None') # Process all the projects and configurations for project in solution.get_project_list(): # Make sure a platform was present if project.platform is None: project.platform = project.configuration_list[0].platform # Process the filenames project.get_file_list( [FileTypes.h, FileTypes.cpp, FileTypes.c, FileTypes.rc]) # Add to the master list self.configuration_list.extend(project.configuration_list) # Get the source files that are compatible listh = source_file_filter(project.codefiles, FileTypes.h) listcpp = source_file_filter(project.codefiles, FileTypes.cpp) listwindowsresource = [] if project.platform.is_windows(): listwindowsresource = source_file_filter( project.codefiles, FileTypes.rc) alllists = listh + listcpp + listwindowsresource # Select the project linker for the platform if project.platform.is_windows(): linker = 'Win32 x86 Linker' else: linker = 'MacOS PPC Linker' # Create sets of configuration names and projects for configuration in project.configuration_list: if not configuration.library_folders_list: if project.platform.is_windows(): configuration.library_folders_list = [ '$(CodeWarrior)/MSL', '$(CodeWarrior)/Win32-x86 Support' ] if not configuration.project_type.is_library(): if configuration.debug: configuration.libraries_list.append( 'MSL_All_x86_D.lib') else: configuration.libraries_list.append( 'MSL_All_x86.lib') configuration.cw_name = configuration.name # Create the project for the configuration # and add to the "Everything" project target = self.addtarget(configuration.cw_name, linker) rootproject.addsubtarget(target) # Add any environment variables if needed temp_list = configuration.get_unique_chained_list( 'cw_environment_variables') if temp_list: entry = target.addsetting('UserSourceTrees') for item in temp_list: entry.subsettings.append(UserSourceTree(item)) # Create a OutputDirectory record for saving # the output to the bin folder target.settinglist.append( SearchPath(configuration.platform, 'bin', 'Project', 'OutputDirectory')) # User include folders temp_list = configuration.get_unique_chained_list( '_source_include_list') temp_list.extend( configuration.get_unique_chained_list( 'include_folders_list')) if temp_list: usersearchpaths = target.addsetting('UserSearchPaths') for item in temp_list: entry = usersearchpaths.addsetting() entry.subsettings.append( SearchPathAndFlags(configuration.platform, item, 'Project', False)) # System include folders temp_list = configuration.get_unique_chained_list( '_library_folders_list') if temp_list: systemsearchpaths = target.addsetting('SystemSearchPaths') for item in temp_list: entry = systemsearchpaths.addsetting() entry.subsettings.append( SearchPathAndFlags( solution.project_list[0].platform, item, 'CodeWarrior', False)) # Generic settings for all platforms # C/C++ Language target.settinglist.append(MWFrontEnd_C()) definelist = configuration.get_chained_list('define_list') # C/C++ Preprocessor target.settinglist.append(C_CPP_Preprocessor(definelist)) # C/C++ Warnings target.settinglist.append(MWWarning_C()) # Windows settings if configuration.platform.is_windows(): # x86 Target target.settinglist.append( MWProject_X86( configuration.project_type, solution.name + solution.ide.get_short_code() + 'w32' + configuration.short_code)) # x86 CodeGen target.settinglist.append(MWCodeGen_X86( configuration.name)) # Global Optimizations target.settinglist.append( GlobalOptimizer_X86(configuration.name)) # x86 Dissassembler target.settinglist.append(PDisasmX86()) # x86 Linker target.settinglist.append(MWLinker_X86()) # Create the list of libraries to add to the project if # it's an application liblist = [] if not configuration.project_type.is_library(): liblist = configuration.get_unique_chained_list( 'libraries_list') # Generate the file and group lists if alllists or liblist: filelist = [] for item in alllists: parts = convert_to_linux_slashes( item.relative_pathname).split('/') filelist.append(unicode(parts[len(parts) - 1])) # Add to file group self.addtogroups(configuration.platform, configuration.name, parts) filelist = sorted(filelist, key=unicode.lower) for item in filelist: target.filelist.append( FILE(configuration.platform, configuration.name, item)) target.linkorder.append( FILEREF(configuration.platform, None, item)) # Sort case insensitive liblist = sorted(liblist, key=unicode.lower) for item in liblist: target.filelist.append( FILE(configuration.platform, configuration.name, item)) target.linkorder.append( FILEREF(configuration.platform, None, item)) # Add to file group self.addtogroups(configuration.platform, configuration.name, ['Libraries', item])
def write_builds(self, line_list): """ Output the rule to build the exes/libs """ line_list.extend(['', '#', '# Create final binaries', '#']) for configuration in self.configuration_list: if configuration.project_type == ProjectTypes.library: suffix = '.a' prefix = 'lib' else: suffix = '' prefix = '' line_list.append('') line_list.append('bin/' + prefix + self.solution.name + 'mak' + configuration.platform.get_short_code()[-3:] + configuration.short_code + suffix + ': $(OBJS) ' + self.solution.makefile_filename + ' | bin') if configuration.project_type is ProjectTypes.library: line_list.append('\t@ar -rcs $@ $(OBJS)') if configuration.deploy_folder: deploy_folder = convert_to_linux_slashes( configuration.deploy_folder, force_ending_slash=True)[:-1] line_list.extend([ '\t@if [ -f /bin/wslpath ]; then \\', '\tp4.exe edit $$(wslpath -a -w \'{}/$(@F)\'); \\'. format(deploy_folder), '\tcp -T "$@" "{}/$(@F)"; \\'.format(deploy_folder), '\tp4.exe revert -a $$(wslpath -a -w \'{}/$(@F)\'); \\' .format(deploy_folder), '\telse \\', '\tp4 edit "{}/$(@F)"; \\'.format(deploy_folder), '\tcp -T "$@" "{}/$(@F)"; \\'.format(deploy_folder), '\tp4 revert -a "{}/$(@F)"; \\'.format(deploy_folder), '\tfi' ]) else: line_list.append('\t@$(LINK) -o $@ $(OBJS) ' '$(LFlags$(CONFIG)$(TARGET))') if configuration.deploy_folder: deploy_folder = convert_to_linux_slashes( configuration.deploy_folder, force_ending_slash=True)[:-1] line_list.extend([ '\t@-p4 edit "{}/{}'.format(deploy_folder, self.solution.name), '\t@-cp -T "$^@" "{}/{}'.format( deploy_folder, self.solution.name), '\t@-p4 revert -a "{}/{}'.format( deploy_folder, self.solution.name) ]) line_list.append('') line_list.extend([ '%.d: ;', '', '%: %,v', '', '%: RCS/%,v', '', '%: RCS/%', '', '%: s.%', '', '%: SCCS/s.%', '', '%.h: ;', '', '#', '# Include the generated dependencies', '#', '', '-include $(DEPS)' ]) return 0
def generate(self, line_list=None): """ Write out the Watcom project. Args: line_list: string list to save the XML text """ if line_list is None: line_list = [] # Save the standard XML header for CodeBlocks line_list.append( '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>') line_list.append('<CodeBlocks_project_file>') line_list.append('\t<FileVersion major="1" minor="6" />') line_list.append('\t<Project>') # Output the project settings line_list.append('\t\t<Option title="' + self.solution.name + '" />') line_list.append('\t\t<Option makefile="makefile" />') line_list.append('\t\t<Option pch_mode="2" />') line_list.append('\t\t<Option compiler="ow" />') # Output the per target build settings line_list.append('\t\t<Build>') for configuration in self.configuration_list: target_name = configuration.name + '_' + configuration.platform.get_short_code( ) line_list.append('\t\t\t<Target title="' + target_name + '">') binary_name = 'bin/{}{}'.format(configuration.project.name, configuration.get_suffix()) if configuration.project_type.is_library(): binary_name = binary_name + '.lib' else: binary_name = binary_name + '.exe' line_list.append('\t\t\t\t<Option output="' + binary_name + '" prefix_auto="0" extension_auto="0" />') line_list.append('\t\t\t\t<Option working_dir="" />') intdirectory = 'temp/{}{}/'.format(configuration.project.name, configuration.get_suffix()) line_list.append('\t\t\t\t<Option object_output="' + intdirectory + '" />') if configuration.project_type is ProjectTypes.tool: line_list.append('\t\t\t\t<Option type="1" />') else: line_list.append('\t\t\t\t<Option type="2" />') line_list.append('\t\t\t\t<Option compiler="ow" />') line_list.append('\t\t\t\t<Option createDefFile="1" />') line_list.append('\t\t\t\t<Compiler>') if configuration.platform.is_msdos(): line_list.append('\t\t\t\t\t<Add option="-bt=dos" />') else: line_list.append('\t\t\t\t\t<Add option="-bt=nt" />') # Include symbols if configuration.debug: line_list.append('\t\t\t\t\t<Add option="-d2" />') # Enable optimizations if configuration.optimization: line_list.append('\t\t\t\t\t<Add option="-ox" />') line_list.append('\t\t\t\t\t<Add option="-ot" />') # Maximum warnings line_list.append('\t\t\t\t\t<Add option="-wx" />') # Pentium Pro floating point line_list.append('\t\t\t\t\t<Add option="-fp6" />') # Pentium Pro optimizations line_list.append('\t\t\t\t\t<Add option="-6r" />') # Error file name line_list.append('\t\t\t\t\t<Add option="-fr=$(ERROR_FILE)" />') # Defines for item in configuration.get_chained_list('define_list'): line_list.append('\t\t\t\t\t<Add option="-d' + item + '" />') line_list.append('\t\t\t\t</Compiler>') line_list.append('\t\t\t</Target>') line_list.append('\t\t\t<Environment>') line_list.append( '\t\t\t\t<Variable name="ERROR_FILE" value="$(TARGET_OBJECT_DIR)foo.err" />' ) line_list.append('\t\t\t</Environment>') line_list.append('\t\t</Build>') # Output the virtual target line_list.append('\t\t<VirtualTargets>') target_list = [] for configuration in self.configuration_list: target_name = configuration.name + '_' + configuration.platform.get_short_code( ) target_list.append(target_name) line_list.append('\t\t\t<Add alias="Everything" targets="' + ';'.join(target_list) + '" />') line_list.append('\t\t</VirtualTargets>') # Output the global compiler settings line_list.append('\t\t<Compiler>') # Extract the directories from the files # Sort them for consistent diffs for source control include_folders = [] for configuration in self.configuration_list: for item in configuration.get_unique_chained_list( '_source_include_list'): if item not in include_folders: include_folders.append(item) for item in configuration.get_unique_chained_list( 'include_folders_list'): if item not in include_folders: include_folders.append(item) for item in sorted(include_folders): line_list.append('\t\t\t<Add directory=\'"' + convert_to_linux_slashes(item) + '"\' />') if not self.solution.project_list[0].project_type.is_library() or \ self.solution.name != 'burger': line_list.append( '\t\t\t<Add directory=\'"$(BURGER_SDKS)/windows/burgerlib"\' />' ) line_list.append('\t\t</Compiler>') # Output the list of source files if self.solution.project_list: codefiles = self.solution.project_list[0].codefiles else: codefiles = [] for item in codefiles: line_list.append('\t\t<Unit filename="' + convert_to_linux_slashes(item.relative_pathname) + '" />') # Add the extensions (If any) line_list.append('\t\t<Extensions>') line_list.append('\t\t\t<code_completion />') line_list.append('\t\t\t<envvars />') line_list.append('\t\t\t<debugger />') line_list.append('\t\t</Extensions>') # Close the file line_list.append('\t</Project>') line_list.append('</CodeBlocks_project_file>') return 0