def __init__(self): """Initialize the target The build_flags dictionnary is used to set attributes of runtime_build.gpr""" TargetConfiguration.__init__(self) ArchSupport.__init__(self) self.config_files = {} self.runtimes = {} self.rts_options = RTSProfiles(self) self.build_flags = { 'source_dirs': None, 'common_flags': [ '-fcallgraph-info=su,da', '-ffunction-sections', '-fdata-sections' ], 'asm_flags': [], 'c_flags': ['-DIN_RTS', '-Dinhibit_libc'] } readme = self.readme_file if readme: self.config_files.update({'README': readfile(readme)}) for profile in self.system_ads: # Set the scenario variable values for the base profile rts = FilesHolder() self.runtimes[profile] = rts if 'ravenscar' not in profile: rts.rts_vars = self.rts_options.zfp_scenarios(math_lib=False) elif 'full' in profile: rts.rts_vars = self.rts_options.full_scenarios(math_lib=True) else: rts.rts_vars = self.rts_options.sfp_scenarios(math_lib=False) rts.add_sources( 'arch', {'system.ads': 'src/system/%s' % self.system_ads[profile]}) rts.build_flags = copy.deepcopy(self.build_flags) rts.config_files = {} # Update the runtimes objects according to target specifications self.amend_rts(profile, rts) # Check that dependencies are met self.rts_options.check_deps(rts.rts_vars) assert len(self.runtimes) > 0, "No runtime defined"
def __init__(self): """Initialize the target The build_flags dictionnary is used to set attributes of runtime_build.gpr""" TargetConfiguration.__init__(self) ArchSupport.__init__(self) self.config_files = {} self.runtimes = {} self.rts_options = RTSProfiles(self) self.build_flags = { 'source_dirs': None, 'common_flags': [ '-fcallgraph-info=su,da', '-ffunction-sections', '-fdata-sections' ], 'asm_flags': [], 'c_flags': ['-DIN_RTS', '-Dinhibit_libc'] } readme = self.readme_file if readme: self.config_files.update({'README': readfile(readme)}) for profile in self.system_ads: # Set the scenario variable values for the base profile rts = FilesHolder() self.runtimes[profile] = rts if 'ravenscar' not in profile: rts.rts_vars = self.rts_options.zfp_scenarios(math_lib=False) elif 'full' in profile: rts.rts_vars = self.rts_options.full_scenarios(math_lib=True) else: rts.rts_vars = self.rts_options.sfp_scenarios(math_lib=False) # By default, system.ads files are searched for in # bb-runtimes/src/system. # This works fine in general, however, for custom runtimes, we may # need to change the location of this file for various reasons # so if we detect a slash in the base name, this means that we # lookup the file as any other regular source file. system_ads = self.system_ads[profile] if '/' in system_ads: rts.add_sources('arch', {'system.ads': system_ads}) else: rts.add_sources('arch', {'system.ads': 'src/system/%s' % system_ads}) rts.build_flags = copy.deepcopy(self.build_flags) rts.config_files = {} # Update the runtimes objects according to target specifications self.amend_rts(profile, rts) # Check that dependencies are met self.rts_options.check_deps(rts.rts_vars) assert len(self.runtimes) > 0, "No runtime defined"
def install(self, destination, prefix): # Build target directories destination = os.path.abspath(destination) if not os.path.exists(destination): os.mkdir(destination) installed_files = [] gnarl_dirs = [] gnarl_langs = [] gnat_dirs = [] gnat_langs = [] script_files = [] # Install the bsp base = destination base_bsp = os.path.join(base, self.tgt.rel_path) if 'README' in self.tgt.config_files: cnt = self.tgt.config_files['README'] readme_fname = os.path.join(destination, 'README-%s.txt' % self.tgt.name) with open(readme_fname, 'w') as fp: fp.write(cnt) scripts = [] self.tgt.install_ld_scripts(destination, scripts, installed_files) for d in scripts: full = os.path.join(base, d) rel = os.path.join('..', os.path.relpath(full, base_bsp)) script_files.append(rel) # Install source files for the BSP/RTSs bsp_gnat = [] bsp_gnarl = [] self.tgt.install_libgnat(destination, bsp_gnat, installed_files) has_ravenscar = False for rts in self.tgt.runtimes: if 'ravenscar' in rts: has_ravenscar = True break if has_ravenscar: # install ravenscar support self.tgt.install_libgnarl(destination, bsp_gnarl, installed_files) for d in bsp_gnat: full = os.path.join(base, d) rel = os.path.join('..', os.path.relpath(full, base_bsp)) # gnat_dirs is used to generate libgnat.gpr, so relative to the # bsp directory gnat_dirs.append(rel) if 'C' not in gnat_langs and self.tgt.has_c(d): gnat_langs.append('C') if 'Asm' not in gnat_langs and self.tgt.has_asm(d): gnat_langs.append('Asm') if 'Asm_Cpp' not in gnat_langs and self.tgt.has_asm_cpp(d): gnat_langs.append('Asm_Cpp') for d in bsp_gnarl: full = os.path.join(base, d) rel = os.path.join('..', os.path.relpath(full, base_bsp)) gnarl_dirs.append(rel) if 'C' not in gnarl_langs and self.tgt.has_c(d): gnarl_langs.append('C') if 'Asm' not in gnarl_langs and self.tgt.has_asm(d): gnarl_langs.append('Asm') if 'Asm_Cpp' not in gnarl_langs and self.tgt.has_asm_cpp(d): gnarl_langs.append('Asm_Cpp') # Now install the rts-specific sources for rts_name, rts_obj in self.tgt.runtimes.items(): base_rts = os.path.join(base_bsp, rts_name) rts_gnat = [d for d in gnat_dirs] rts_gnarl = [d for d in gnarl_dirs] rts_gnat_langs = [l for l in gnat_langs] rts_gnarl_langs = [l for l in gnarl_langs] if prefix is not None: if prefix.endswith('/'): install_prefix = prefix else: install_prefix = prefix + '/' elif self.tgt.target is not None: if self.tgt.is_pikeos: install_prefix = 'lib/gcc/%s/%s/' % ( self.tgt.target, FilesHolder.gcc_version()) else: install_prefix = self.tgt.target + '/lib/gnat/' else: install_prefix = 'lib/gnat/' if self.tgt.is_pikeos or self.tgt.target is None: install_prefix += 'rts-%s' % rts_name else: install_prefix += '%s-%s' % (rts_name, self.tgt.name) if not os.path.exists(base_rts): os.makedirs(base_rts) for d in ['obj', 'adalib']: path = os.path.join(base_rts, d) if not os.path.exists(path): os.mkdir(path) for dirname, l in rts_obj.dirs.items(): if l is None or len(l) == 0: continue if 'gnarl' in dirname: if dirname not in gnarl_dirs: rts_gnarl.append(dirname) if 'C' not in rts_gnarl_langs and \ dirname in rts_obj.c_srcs: rts_gnarl_langs.append('C') if 'Asm' not in rts_gnarl_langs and \ dirname in rts_obj.asm_srcs: rts_gnarl_langs.append('Asm') if 'Asm_Cpp' not in rts_gnarl_langs and \ dirname in rts_obj.asm_cpp_srcs: rts_gnarl_langs.append('Asm_Cpp') else: if dirname not in gnat_dirs: rts_gnat.append(dirname) if 'C' not in rts_gnat_langs and \ dirname in rts_obj.c_srcs: rts_gnat_langs.append('C') if 'Asm' not in rts_gnat_langs and \ dirname in rts_obj.asm_srcs: rts_gnat_langs.append('Asm') if 'Asm_Cpp' not in rts_gnat_langs and \ dirname in rts_obj.asm_cpp_srcs: rts_gnat_langs.append('Asm_Cpp') full = os.path.join(base_rts, dirname) if not os.path.exists(full): os.makedirs(full) for srcname, pair in l.items(): self.tgt._copy_pair(srcname, pair, full) # user-defined sources rts_gnat.append('user_srcs') path = os.path.join(base_rts, 'user_srcs') if not os.path.exists(path): os.mkdir(path) # Generate ada_source_path, used for the rts bootstrap with open(os.path.join(base_rts, 'ada_source_path'), 'w') as fp: for d in sorted(rts_gnat + rts_gnarl): fp.write(d + '\n') # Generate ada_object_path with open(os.path.join(base_rts, 'ada_object_path'), 'w') as fp: fp.write('adalib\n') # Write config files for name, content in self.tgt.config_files.iteritems(): with open(os.path.join(base_rts, name), 'w') as fp: fp.write(content) with open(os.path.join(base_rts, 'runtime.xml'), 'w') as fp: fp.write(self.tgt.dump_runtime_xml(rts_name, rts_obj)) # and now install the rts project with the proper scenario values self.dump_rts_project_file(rts_name, rts_obj.rts_vars, destination, install_prefix) inst_files = ['runtime.xml'] support_dir = os.path.relpath(os.path.join(destination, 'support'), base_rts) inst_files.append(os.path.join(support_dir, 'ada_source_path')) inst_files.append(os.path.join(support_dir, 'ada_object_path')) for name, content in rts_obj.config_files.iteritems(): inst_files.append(name) with open(os.path.join(base_rts, name), 'w') as fp: fp.write(content) if len(script_files) > 0: link_sources = '"%s"' % '",\n "'.join(script_files) else: link_sources = '' build_flags = { 'link_sources': link_sources, 'rts_files': '",\n "'.join(inst_files) } cnt = readfile(datapath('install.gpr')) # Format cnt = cnt.format(**build_flags) # Write with open(os.path.join(base_rts, 'install.gpr'), 'w') as fp: fp.write(cnt) # and the potentially runtime specific target_options.gpr project build_flags = {} for f in ['common_flags', 'asm_flags', 'c_flags']: build_flags[f] = '",\n "'.join(rts_obj.build_flags[f]) cnt = readfile(datapath('target_options.gpr')) # Format cnt = cnt.format(**build_flags) # Write with open(os.path.join(base_rts, 'target_options.gpr'), 'w') as fp: fp.write(cnt) # Set source_dirs and languages prj_values = {} prj_values['gnat_source_dirs'] = '"%s"' % ('",\n "'.join( sorted(rts_gnat)), ) if len(rts_gnarl) == 0: prj_values['gnarl_source_dirs'] = '' else: prj_values['gnarl_source_dirs'] = '"%s"' % ('",\n "'.join( sorted(rts_gnarl)), ) prj_values['gnat_langs'] = '", "'.join(["Ada"] + rts_gnat_langs) prj_values['gnarl_langs'] = '", "'.join(["Ada"] + rts_gnarl_langs) all_langs = [] for l in rts_gnat_langs + rts_gnarl_langs: if l not in all_langs: all_langs.append(l) prj_values['all_langs'] = '", "'.join(all_langs) if 'ravenscar' not in rts_name: projects = ('libgnat', ) elif 'full' in rts_name: projects = ('libgnat_full', 'libgnarl_full') else: projects = ('libgnat', 'libgnarl') for fname in projects: cnt = readfile(datapath('%s.gpr' % fname)) # Format cnt = cnt.format(**prj_values) # Write if '_full' in fname: dest = fname.replace('_full', '') empty_c = os.path.join(base_rts, 'empty.c') with open(empty_c, 'w') as fp: fp.write('') else: dest = fname with open(os.path.join(base_rts, '%s.gpr' % dest), 'w') as fp: fp.write(cnt)