diff options
Diffstat (limited to 'configure.py')
-rwxr-xr-x | configure.py | 151 |
1 files changed, 56 insertions, 95 deletions
diff --git a/configure.py b/configure.py index ceb8e4c18..a4cef1a0b 100755 --- a/configure.py +++ b/configure.py @@ -294,7 +294,7 @@ def process_command_line(args): # pylint: disable=too-many-locals target_group = optparse.OptionGroup(parser, 'Target options') - target_group.add_option('--cpu', help='set the target CPU type/model') + target_group.add_option('--cpu', help='set the target CPU architecture') target_group.add_option('--os', help='set the target operating system') @@ -329,7 +329,7 @@ def process_command_line(args): # pylint: disable=too-many-locals target_group.add_option('--without-os-features', action='append', metavar='FEAT', help='specify OS features to disable') - for isa_extn_name in ['SSE2', 'SSSE3', 'SSE4.1', 'SSE4.2', 'AVX2', 'AES-NI', 'AltiVec', 'NEON']: + for isa_extn_name in ['SSE2', 'SSSE3', 'SSE4.1', 'SSE4.2', 'AVX2', 'AES-NI', 'SHA', 'AltiVec', 'NEON']: isa_extn = isa_extn_name.lower() target_group.add_option('--disable-%s' % (isa_extn), @@ -978,8 +978,8 @@ class ArchInfo(InfoObject): super(ArchInfo, self).__init__(infofile) lex = lex_me_harder( infofile, - ['aliases', 'submodels', 'isa_extensions'], - ['submodel_aliases'], + ['aliases', 'isa_extensions'], + [], { 'endian': None, 'family': None, @@ -990,8 +990,6 @@ class ArchInfo(InfoObject): self.endian = lex.endian self.family = lex.family self.isa_extensions = lex.isa_extensions - self.submodels = lex.submodels - self.submodel_aliases = lex.submodel_aliases self.wordsize = int(lex.wordsize) alphanumeric = re.compile('^[a-z0-9]+$') @@ -999,16 +997,6 @@ class ArchInfo(InfoObject): if alphanumeric.match(isa) is None: logging.error('Invalid name for ISA extension "%s"', isa) - def all_submodels(self): - """ - Return a list of all submodels for this arch, ordered longest - to shortest - """ - - return sorted([(k, k) for k in self.submodels] + - [k for k in self.submodel_aliases.items()], - key=lambda k: len(k[0]), reverse=True) - def supported_isa_extensions(self, cc, options): isas = [] @@ -1020,16 +1008,13 @@ class ArchInfo(InfoObject): return sorted(isas) -MachOptFlags = collections.namedtuple('MachOptFlags', ['flags', 'submodel_prefix']) - - class CompilerInfo(InfoObject): # pylint: disable=too-many-instance-attributes def __init__(self, infofile): super(CompilerInfo, self).__init__(infofile) lex = lex_me_harder( infofile, - ['mach_opt'], - ['so_link_commands', 'binary_link_commands', 'mach_abi_linking', 'isa_flags'], + [], + ['cpu_flags', 'so_link_commands', 'binary_link_commands', 'mach_abi_linking', 'isa_flags'], { 'binary_name': None, 'linker_name': None, @@ -1068,6 +1053,7 @@ class CompilerInfo(InfoObject): # pylint: disable=too-many-instance-attributes self.ar_output_to = lex.ar_output_to self.binary_link_commands = lex.binary_link_commands self.binary_name = lex.binary_name + self.cpu_flags = lex.cpu_flags self.compile_flags = lex.compile_flags self.coverage_flags = lex.coverage_flags self.debug_info_flags = lex.debug_info_flags @@ -1090,11 +1076,6 @@ class CompilerInfo(InfoObject): # pylint: disable=too-many-instance-attributes self.visibility_build_flags = lex.visibility_build_flags self.warning_flags = lex.warning_flags - self.mach_opt_flags = {} - for key, value in parse_lex_dict(lex.mach_opt).items(): - parts = value.split("|") - self.mach_opt_flags[key] = MachOptFlags(parts[0], parts[1] if len(parts) == 2 else '') - def isa_flags_for(self, isa, arch): if isa in self.isa_flags: return self.isa_flags[isa] @@ -1164,7 +1145,6 @@ class CompilerInfo(InfoObject): # pylint: disable=too-many-instance-attributes yield all_except yield options.os - yield options.arch yield options.cpu abi_link = list() @@ -1229,20 +1209,8 @@ class CompilerInfo(InfoObject): # pylint: disable=too-many-instance-attributes else: yield self.optimization_flags - def submodel_fixup(full_cpu, mach_opt_flags_tupel): - submodel_replacement = full_cpu.replace(mach_opt_flags_tupel.submodel_prefix, '') - return mach_opt_flags_tupel.flags.replace('SUBMODEL', submodel_replacement) - - if options.cpu != options.arch: - if options.cpu in self.mach_opt_flags: - yield submodel_fixup(options.cpu, self.mach_opt_flags[options.cpu]) - elif options.arch in self.mach_opt_flags: - yield submodel_fixup(options.cpu, self.mach_opt_flags[options.arch]) - - all_arch = 'all_%s' % (options.arch) - - if all_arch in self.mach_opt_flags: - yield self.mach_opt_flags[all_arch][0] + if options.arch in self.cpu_flags: + yield self.cpu_flags[options.arch] return (' '.join(gen_flags(with_debug_info, enable_optimizations))).strip() @@ -1388,21 +1356,7 @@ def canon_processor(archinfo, proc): # First, try to search for an exact match for ainfo in archinfo.values(): if ainfo.basename == proc or proc in ainfo.aliases: - return (ainfo.basename, ainfo.basename) - - for (match, submodel) in ainfo.all_submodels(): - if proc == submodel or proc == match: - return (ainfo.basename, submodel) - - logging.debug('Could not find an exact match for CPU "%s"' % (proc)) - - # Now, try searching via regex match - for ainfo in archinfo.values(): - for (match, submodel) in ainfo.all_submodels(): - if re.search(match, proc) != None: - logging.debug('Possible match "%s" with "%s" (%s)' % ( - proc, match, submodel)) - return (ainfo.basename, submodel) + return ainfo.basename return None @@ -1416,21 +1370,8 @@ def system_cpu_info(): if platform.processor() != '': cpu_info.append(platform.processor()) - try: - with open('/proc/cpuinfo') as f: - for line in f.readlines(): - colon = line.find(':') - if colon > 1: - key = line[0:colon].strip() - val = ' '.join([s.strip() for s in line[colon+1:].split(' ') if s != '']) - - # Different Linux arch use different names for this field in cpuinfo - if key in ["model name", "cpu model", "Processor"]: - logging.info('Detected CPU model "%s" in /proc/cpuinfo' % (val)) - cpu_info.append(val) - break - except IOError: - pass + if 'uname' in os.__dict__: + cpu_info.append(os.uname()[4]) return cpu_info @@ -1767,6 +1708,29 @@ def create_template_vars(source_paths, build_config, options, modules, cc, arch, def cmake_escape(s): return s.replace('(', '\\(').replace(')', '\\)') + def ar_command(): + if options.ar_command: + return options.ar_command + + if cc.ar_command: + if cc.ar_command == cc.binary_name: + return options.compiler_binary or cc.binary_name + else: + return cc.ar_command + + return osinfo.ar_command + + def choose_endian(arch_info, options): + if options.with_endian != None: + return options.with_endian + + if options.cpu.endswith('eb') or options.cpu.endswith('be'): + return 'big' + elif options.cpu.endswith('el') or options.cpu.endswith('le'): + return 'little' + + return arch_info.endian + build_dir = options.with_build_dir or os.path.curdir program_suffix = options.program_suffix or osinfo.program_suffix @@ -1845,8 +1809,7 @@ def create_template_vars(source_paths, build_config, options, modules, cc, arch, 'os': options.os, 'arch': options.arch, 'cpu_family': arch.family, - 'submodel': options.cpu, - 'endian': options.with_endian or arch.endian, + 'endian': choose_endian(arch, options), 'cpu_is_64bit': arch.wordsize == 64, 'bakefile_arch': 'x86' if options.arch == 'x86_32' else 'x86_64', @@ -1886,7 +1849,7 @@ def create_template_vars(source_paths, build_config, options, modules, cc, arch, 'exe_link_cmd': cc.binary_link_command_for(osinfo.basename, options) + external_link_cmd(), 'post_link_cmd': '', - 'ar_command': options.ar_command or cc.ar_command or osinfo.ar_command, + 'ar_command': ar_command(), 'ar_options': cc.ar_options or osinfo.ar_options, 'ar_output_to': cc.ar_output_to, @@ -2354,7 +2317,7 @@ class AmalgamationHeader(object): def write_banner(fd): fd.write("""/* * Botan %s Amalgamation -* (C) 1999-2017 The Botan Authors +* (C) 1999-2018 The Botan Authors * * Botan is released under the Simplified BSD License (see license.txt) */ @@ -2489,7 +2452,7 @@ class AmalgamationGenerator(object): f.write('\n') for isa in self._isas_for_target(target): - f.write('#if defined(__GNUG__)\n') + f.write('#if defined(__GNUG__) && !defined(__clang__)\n') f.write('#pragma GCC target ("%s")\n' % (isa)) f.write('#endif\n') @@ -2679,9 +2642,8 @@ def set_defaults_for_unset_options(options, info_arch, info_cc): # pylint: disab logging.info('Guessing to use compiler %s (use --cc to set)' % (options.compiler)) if options.cpu is None: - (options.arch, options.cpu) = guess_processor(info_arch) - logging.info('Guessing target processor is a %s/%s (use --cpu to set)' % ( - options.arch, options.cpu)) + options.cpu = options.arch = guess_processor(info_arch) + logging.info('Guessing target processor is a %s (use --cpu to set)' % (options.arch)) if options.with_documentation is True: if options.with_sphinx is None and have_program('sphinx-build'): @@ -2704,15 +2666,13 @@ def canonicalize_options(options, info_os, info_arch): options.os = find_canonical_os_name(options.os) # canonical ARCH/CPU - cpu_from_user = options.cpu - results = canon_processor(info_arch, options.cpu) - if results != None: - (options.arch, options.cpu) = results - logging.info('Canonicalized CPU target %s to %s/%s' % ( - cpu_from_user, options.arch, options.cpu)) - else: + options.arch = canon_processor(info_arch, options.cpu) + if options.arch is None: raise UserError('Unknown or unidentifiable processor "%s"' % (options.cpu)) + if options.cpu != options.arch: + logging.info('Canonicalized CPU target %s to %s', options.cpu, options.arch) + shared_libs_supported = options.os in info_os and info_os[options.os].building_shared_supported() if not shared_libs_supported: @@ -2831,6 +2791,7 @@ def calculate_cc_min_version(options, ccinfo, source_paths): 'msvc': r'^ *MSVC ([0-9]{2})([0-9]{2})$', 'gcc': r'^ *GCC ([0-9]+) ([0-9]+)$', 'clang': r'^ *CLANG ([0-9]+) ([0-9]+)$', + 'xlc': r'^ *XLC (0x[0-9a-fA-F]{2})([0-9a-fA-F]{2})$' } if ccinfo.basename not in version_patterns: @@ -2855,13 +2816,16 @@ def calculate_cc_min_version(options, ccinfo, source_paths): logging.warning('Could not execute %s for version check: %s' % (cmd, e)) return "0.0" + def cleanup_output(output): + return ('\n'.join([l for l in output.splitlines() if l.startswith('#') is False])).strip() + match = re.search(version_patterns[ccinfo.basename], cc_output, flags=re.MULTILINE) if match is None: logging.warning("Tried to get %s version, but output '%s' does not match expected version format" % ( - ccinfo.basename, cc_output)) + ccinfo.basename, cleanup_output(cc_output))) return "0.0" - cc_version = "%d.%d" % (int(match.group(1)), int(match.group(2))) + cc_version = "%d.%d" % (int(match.group(1), 0), int(match.group(2), 0)) logging.info('Auto-detected compiler version %s' % (cc_version)) return cc_version @@ -2952,7 +2916,7 @@ def main_action_configure_build(info_modules, source_paths, options, Version.as_string(), Version.vc_rev(), Version.release_type(), - ('dated ' + Version.datestamp()) if Version.datestamp() != 0 else 'undated')) + ('dated %d' % (Version.datestamp())) if Version.datestamp() != 0 else 'undated')) if options.unsafe_fuzzer_mode: logging.warning("The fuzzer mode flag is labeled unsafe for a reason, this version is for testing only") @@ -2996,10 +2960,7 @@ def main(argv): policy.cross_check(info_modules) logging.debug('Known CPU names: ' + ' '.join( - sorted(flatten([[ainfo.basename] + \ - ainfo.aliases + \ - [x for (x, _) in ainfo.all_submodels()] - for ainfo in info_arch.values()])))) + sorted(flatten([[ainfo.basename] + ainfo.aliases for ainfo in info_arch.values()])))) set_defaults_for_unset_options(options, info_arch, info_cc) canonicalize_options(options, info_os, info_arch) @@ -3011,8 +2972,8 @@ def main(argv): module_policy = info_module_policies[options.module_policy] if options.module_policy else None cc_min_version = options.cc_min_version or calculate_cc_min_version(options, cc, source_paths) - logging.info('Target is %s:%s-%s-%s-%s' % ( - options.compiler, cc_min_version, options.os, options.arch, options.cpu)) + logging.info('Target is %s:%s-%s-%s' % ( + options.compiler, cc_min_version, options.os, options.arch)) main_action_configure_build(info_modules, source_paths, options, cc, cc_min_version, arch, osinfo, module_policy) |