aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-12-11 22:32:25 -0500
committerJack Lloyd <[email protected]>2017-12-11 22:32:25 -0500
commitfd05ab57f2c13e0ba2ac371d3fa81b4ecdcecfc7 (patch)
tree1539bcb42c02b62a8cf25baf1cf2c1cc51810bf5
parent4206f35cad8488f96c7236b6d07b982fd56923b1 (diff)
parent4cc5e2fe991d4233f053abedf73a5dc22594330b (diff)
Merge GH #1351 Cleanup macro generation in build.h
-rwxr-xr-xconfigure.py168
-rw-r--r--src/build-data/arch/x86_32.txt4
-rw-r--r--src/build-data/arch/x86_64.txt4
-rw-r--r--src/build-data/buildh.in53
-rw-r--r--src/build-data/cc/clang.txt4
-rw-r--r--src/build-data/cc/gcc.txt4
-rw-r--r--src/build-data/cc/msvc.txt4
-rw-r--r--src/build-data/cc/sunstudio.txt4
-rw-r--r--src/lib/hash/sha1/sha1_x86/info.txt2
-rw-r--r--src/lib/hash/sha2_32/sha2_32_x86/info.txt2
-rwxr-xr-xsrc/scripts/install.py2
11 files changed, 117 insertions, 134 deletions
diff --git a/configure.py b/configure.py
index 713302a32..7237cb9b0 100755
--- a/configure.py
+++ b/configure.py
@@ -335,7 +335,7 @@ def process_command_line(args): # pylint: disable=too-many-locals
target_group.add_option('--disable-%s' % (isa_extn),
help='disable %s intrinsics' % (isa_extn_name),
action='append_const',
- const=isa_extn.replace('-', ''),
+ const=isa_extn.replace('-', '').replace('.', ''),
dest='disable_intrinsics')
build_group = optparse.OptionGroup(parser, 'Build options')
@@ -574,10 +574,9 @@ def process_command_line(args): # pylint: disable=too-many-locals
if args != []:
raise UserError('Unhandled option(s): ' + ' '.join(args))
- if options.with_endian != None and \
- options.with_endian not in ['little', 'big']:
- raise UserError('Bad value to --with-endian "%s"' % (
- options.with_endian))
+
+ if options.with_endian not in [None, 'little', 'big']:
+ raise UserError('Bad value to --with-endian "%s"' % (options.with_endian))
if options.debug_mode:
options.no_optimizations = True
@@ -798,22 +797,11 @@ class ModuleInfo(InfoObject):
self.requires = lex.requires
self.warning = ' '.join(lex.warning) if lex.warning else None
- def add_dir_name(filename):
- if filename.count(':') == 0:
- return os.path.join(self.lives_in, filename)
-
- # modules can request to add files of the form
- # MODULE_NAME:FILE_NAME to add a file from another module
- # For these, assume other module is always in a
- # neighboring directory; this is true for all current uses
- return os.path.join(os.path.split(self.lives_in)[0],
- *filename.split(':'))
-
# Modify members
- self.source = [normalize_source_path(add_dir_name(s)) for s in self.source]
- self.header_internal = [add_dir_name(s) for s in self.header_internal]
- self.header_public = [add_dir_name(s) for s in self.header_public]
- self.header_external = [add_dir_name(s) for s in self.header_external]
+ self.source = [normalize_source_path(os.path.join(self.lives_in, s)) for s in self.source]
+ self.header_internal = [os.path.join(self.lives_in, s) for s in self.header_internal]
+ self.header_public = [os.path.join(self.lives_in, s) for s in self.header_public]
+ self.header_external = [os.path.join(self.lives_in, s) for s in self.header_external]
# Filesystem read access check
for src in self.source + self.header_internal + self.header_public + self.header_external:
@@ -867,7 +855,7 @@ class ModuleInfo(InfoObject):
return self.header_external
def defines(self):
- return ['HAS_%s %s' % (key, value) for key, value in self._defines.items()]
+ return [(key + ' ' + value) for key, value in self._defines.items()]
def compatible_cpu(self, archinfo, options):
arch_name = archinfo.basename
@@ -990,6 +978,11 @@ class ArchInfo(InfoObject):
self.submodel_aliases = lex.submodel_aliases
self.wordsize = int(lex.wordsize)
+ alphanumeric = re.compile('^[a-z0-9]+$')
+ for isa in self.isa_extensions:
+ 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
@@ -1000,53 +993,15 @@ class ArchInfo(InfoObject):
[k for k in self.submodel_aliases.items()],
key=lambda k: len(k[0]), reverse=True)
- def defines(self, cc, options):
- """
- Return CPU-specific defines for build.h
- """
-
- def form_macro(cpu_name):
- return cpu_name.upper().replace('.', '').replace('-', '_')
-
- macros = []
-
- macros.append('TARGET_ARCH_IS_%s' % (form_macro(self.basename.upper())))
+ def supported_isa_extensions(self, cc, options):
+ isas = []
- if self.basename != options.cpu:
- macros.append('TARGET_CPU_IS_%s' % (form_macro(options.cpu)))
+ for isa in self.isa_extensions:
+ if isa not in options.disable_intrinsics:
+ if cc.isa_flags_for(isa, self.basename) is not None:
+ isas.append(isa)
- enabled_isas = set(self.isa_extensions)
- disabled_isas = set(options.disable_intrinsics)
-
- isa_extensions = sorted(enabled_isas - disabled_isas)
-
- for isa in isa_extensions:
- if cc.isa_flags_for(isa, self.basename) is not None:
- macros.append('TARGET_SUPPORTS_%s' % (form_macro(isa)))
- else:
- logging.warning("Disabling support for %s intrinsics due to missing flag for compiler" % (isa))
-
- endian = options.with_endian or self.endian
-
- if endian != None:
- macros.append('TARGET_CPU_IS_%s_ENDIAN' % (endian.upper()))
- logging.info('Assuming CPU is %s endian' % (endian))
-
- if self.family is not None:
- macros.append('TARGET_CPU_IS_%s_FAMILY' % (self.family.upper()))
-
- macros.append('TARGET_CPU_NATIVE_WORD_SIZE %d' % (self.wordsize))
-
- if self.wordsize == 64:
- macros.append('TARGET_CPU_HAS_NATIVE_64BIT')
-
- if options.with_valgrind:
- macros.append('HAS_VALGRIND')
-
- if options.with_openmp:
- macros.append('TARGET_HAS_OPENMP')
-
- return macros
+ return sorted(isas)
MachOptFlags = collections.namedtuple('MachOptFlags', ['flags', 'submodel_prefix'])
@@ -1294,14 +1249,6 @@ class CompilerInfo(InfoObject): # pylint: disable=too-many-instance-attributes
return '$(LINKER)'
- def defines(self):
- """
- Return defines for build.h
- """
-
- return ['BUILD_COMPILER_IS_' + self.macro_name]
-
-
class OsInfo(InfoObject): # pylint: disable=too-many-instance-attributes
def __init__(self, infofile):
super(OsInfo, self).__init__(infofile)
@@ -1378,24 +1325,16 @@ class OsInfo(InfoObject): # pylint: disable=too-many-instance-attributes
self.static_suffix = lex.static_suffix
self.target_features = lex.target_features
- def defines(self, options):
- r = []
- r += ['TARGET_OS_IS_%s' % (self.basename.upper())]
-
- if self.os_type != None:
- r += ['TARGET_OS_TYPE_IS_%s' % (self.os_type.upper())]
-
- def feat_macros():
- for feat in self.target_features:
- if feat not in options.without_os_features:
- yield 'TARGET_OS_HAS_' + feat.upper()
- for feat in options.with_os_features:
- if feat not in self.target_features:
- yield 'TARGET_OS_HAS_' + feat.upper()
-
- r += sorted(feat_macros())
- return r
+ def enabled_features(self, options):
+ feats = []
+ for feat in self.target_features:
+ if feat not in options.without_os_features:
+ feats.append(feat)
+ for feat in options.with_os_features:
+ if feat not in self.target_features:
+ feats.append(feat)
+ return sorted(feats)
def fixup_proc_name(proc):
proc = proc.lower().replace(' ', '')
@@ -1491,7 +1430,7 @@ def process_template(template_file, variables):
def __init__(self, vals):
self.vals = vals
- self.value_pattern = re.compile(r'%{([a-z][a-z_0-9]+)}')
+ self.value_pattern = re.compile(r'%{([a-z][a-z_0-9\|]+)}')
self.cond_pattern = re.compile('%{(if|unless) ([a-z][a-z_0-9]+)}')
self.for_pattern = re.compile('(.*)%{for ([a-z][a-z_0-9]+)}')
self.join_pattern = re.compile('(.*)%{join ([a-z][a-z_0-9]+)}')
@@ -1502,6 +1441,11 @@ def process_template(template_file, variables):
v = match.group(1)
if v in self.vals:
return str(self.vals.get(v))
+ if v.endswith('|upper'):
+ v = v.replace('|upper', '')
+ if v in self.vals:
+ return str(self.vals.get(v)).upper()
+
raise KeyError(v)
lines = template.splitlines()
@@ -1564,7 +1508,7 @@ def process_template(template_file, variables):
for_val = for_val.replace('%{' + ik + '}', iv)
output += for_val + "\n"
else:
- output += for_body.replace('%{i}', v)
+ output += for_body.replace('%{i}', v).replace('%{i|upper}', v.upper())
output += "\n"
else:
output += lines[idx] + "\n"
@@ -1725,10 +1669,10 @@ def house_ecc_curve_macros(house_curve):
if curve_id < 0xfe00 or curve_id > 0xfeff:
raise UserError('TLS curve ID not in reserved range (see RFC 4492)')
- return ['HOUSE_ECC_CURVE_NAME \"' + p[1] + '\"',
- 'HOUSE_ECC_CURVE_OID \"' + p[2] + '\"',
- 'HOUSE_ECC_CURVE_PEM ' + _read_pem(filepath=p[0]),
- 'HOUSE_ECC_CURVE_TLS_ID ' + hex(curve_id)]
+ return ['NAME \"' + p[1] + '\"',
+ 'OID \"' + p[2] + '\"',
+ 'PEM ' + _read_pem(filepath=p[0]),
+ 'TLS_ID ' + hex(curve_id)]
def create_template_vars(source_paths, build_config, options, modules, cc, arch, osinfo):
#pylint: disable=too-many-locals,too-many-branches,too-many-statements
@@ -1737,9 +1681,6 @@ def create_template_vars(source_paths, build_config, options, modules, cc, arch,
Create the template variables needed to process the makefile, build.h, etc
"""
- def make_cpp_macros(macros):
- return '\n'.join(['#define BOTAN_' + macro for macro in macros])
-
def external_link_cmd():
return (' ' + cc.add_lib_dir_option + options.with_external_libdir) if options.with_external_libdir else ''
@@ -1862,7 +1803,10 @@ 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,
+ 'cpu_is_64bit': arch.wordsize == 64,
'bakefile_arch': 'x86' if options.arch == 'x86_32' else 'x86_64',
@@ -1891,6 +1835,7 @@ def create_template_vars(source_paths, build_config, options, modules, cc, arch,
'ldflags': options.ldflags or '',
'cc_warning_flags': cc.cc_warning_flags(options),
'output_to_exe': cc.output_to_exe,
+ 'cc_macro': cc.macro_name,
'shared_flags': cc.gen_shared_flags(options),
'cmake_shared_flags': cmake_escape(cc.gen_shared_flags(options)),
@@ -1918,22 +1863,21 @@ def create_template_vars(source_paths, build_config, options, modules, cc, arch,
'libs_used': [lib.replace('.lib', '') for lib in link_to('libs')],
'include_paths': build_config.format_include_paths(cc, options.with_external_includedir),
- 'module_defines': make_cpp_macros(sorted(flatten([m.defines() for m in modules]))),
-
- 'target_os_defines': make_cpp_macros(osinfo.defines(options)),
-
- 'target_compiler_defines': make_cpp_macros(cc.defines()),
-
- 'target_cpu_defines': make_cpp_macros(arch.defines(cc, options)),
+ 'module_defines': sorted(flatten([m.defines() for m in modules])),
- 'botan_include_dir': build_config.botan_include_dir,
+ 'os_features': osinfo.enabled_features(options),
+ 'os_name': osinfo.basename,
+ 'os_type': osinfo.os_type,
+ 'cpu_features': arch.supported_isa_extensions(cc, options),
+ 'house_ecc_curve_defines': house_ecc_curve_macros(options.house_curve),
- 'unsafe_fuzzer_mode_define': '#define BOTAN_UNSAFE_FUZZER_MODE' if options.unsafe_fuzzer_mode else '',
- 'fuzzer_type': '#define BOTAN_FUZZER_IS_%s' % (options.build_fuzzers.upper()) if options.build_fuzzers else '',
+ 'fuzzer_mode': options.unsafe_fuzzer_mode,
+ 'fuzzer_type': options.build_fuzzers.upper() if options.build_fuzzers else '',
- 'mod_list': '\n'.join(sorted([m.basename for m in modules])),
+ 'with_valgrind': options.with_valgrind,
+ 'with_openmp': options.with_openmp,
- 'house_ecc_curve_defines': make_cpp_macros(house_ecc_curve_macros(options.house_curve))
+ 'mod_list': sorted([m.basename for m in modules])
}
if options.os != 'windows':
diff --git a/src/build-data/arch/x86_32.txt b/src/build-data/arch/x86_32.txt
index 20401e034..0aa9b6683 100644
--- a/src/build-data/arch/x86_32.txt
+++ b/src/build-data/arch/x86_32.txt
@@ -68,7 +68,7 @@ rdrand
rdseed
sha
sse2
-sse4.1
-sse4.2
+sse41
+sse42
ssse3
</isa_extensions>
diff --git a/src/build-data/arch/x86_64.txt b/src/build-data/arch/x86_64.txt
index 49f8a6a55..1757e4f42 100644
--- a/src/build-data/arch/x86_64.txt
+++ b/src/build-data/arch/x86_64.txt
@@ -47,7 +47,7 @@ rdrand
rdseed
sha
sse2
-sse4.1
-sse4.2
+sse41
+sse42
ssse3
</isa_extensions>
diff --git a/src/build-data/buildh.in b/src/build-data/buildh.in
index 822a73c44..cacc01ed0 100644
--- a/src/build-data/buildh.in
+++ b/src/build-data/buildh.in
@@ -24,8 +24,13 @@
/* How many bits per limb in a BigInt */
#define BOTAN_MP_WORD_BITS %{mp_bits}
-%{unsafe_fuzzer_mode_define}
-%{fuzzer_type}
+
+%{if fuzzer_mode}
+#define BOTAN_UNSAFE_FUZZER_MODE
+%{endif}
+%{if fuzzer_type}
+#define BOTAN_FUZZER_IS_%{fuzzer_type}
+%{endif}
#define BOTAN_INSTALL_PREFIX R"(%{prefix})"
#define BOTAN_INSTALL_HEADER_DIR "%{includedir}/botan-%{version_major}"
@@ -38,22 +43,56 @@
#endif
/* Target identification and feature test macros */
-%{target_os_defines}
-%{target_cpu_defines}
+#define BOTAN_TARGET_OS_IS_%{os_name|upper}
+%{if os_type}
+#define BOTAN_TARGET_OS_TYPE_IS_%{os_type|upper}
+%{endif}
+
+%{for os_features}
+#define BOTAN_TARGET_OS_HAS_%{i|upper}
+%{endfor}
+
+#define BOTAN_BUILD_COMPILER_IS_%{cc_macro}
+
+#define BOTAN_TARGET_ARCH_IS_%{arch|upper}
+%{if endian}
+#define BOTAN_TARGET_CPU_IS_%{endian|upper}_ENDIAN
+%{endif}
+%{if cpu_family}
+#define BOTAN_TARGET_CPU_IS_%{cpu_family|upper}_FAMILY
+%{endif}
+%{if cpu_is_64bit}
+#define BOTAN_TARGET_CPU_HAS_NATIVE_64BIT
+%{endif}
-%{target_compiler_defines}
+%{for cpu_features}
+#define BOTAN_TARGET_SUPPORTS_%{i|upper}
+%{endfor}
+
+%{if with_valgrind}
+#define BOTAN_HAS_VALGRIND
+%{endif}
+
+%{if with_openmp}
+#define BOTAN_TARGET_HAS_OPENMP
+%{endif}
/*
* Module availability definitions
*/
-%{module_defines}
+%{for module_defines}
+#define BOTAN_HAS_%{i}
+%{endfor}
/*
* Local/misc configuration options (if any) follow
*/
%{local_config}
-%{house_ecc_curve_defines}
+
+%{for house_ecc_curve_defines}
+#define BOTAN_HOUSE_ECC_CURVE_%{i}
+%{endfor}
/*
* Things you can edit (but probably shouldn't)
diff --git a/src/build-data/cc/clang.txt b/src/build-data/cc/clang.txt
index 44dd654f3..aaef4357a 100644
--- a/src/build-data/cc/clang.txt
+++ b/src/build-data/cc/clang.txt
@@ -37,8 +37,8 @@ llvm -> "llvm-link"
<isa_flags>
sse2 -> "-msse2"
ssse3 -> "-mssse3"
-sse4.1 -> "-msse4.1"
-sse4.2 -> "-msse4.2"
+sse41 -> "-msse4.1"
+sse42 -> "-msse4.2"
avx2 -> "-mavx2"
bmi2 -> "-mbmi2"
aesni -> "-maes -mpclmul -mssse3"
diff --git a/src/build-data/cc/gcc.txt b/src/build-data/cc/gcc.txt
index 64c52f076..ce1f47ae0 100644
--- a/src/build-data/cc/gcc.txt
+++ b/src/build-data/cc/gcc.txt
@@ -47,8 +47,8 @@ default -> "$(LINKER)"
<isa_flags>
sse2 -> "-msse2"
ssse3 -> "-mssse3"
-sse4.1 -> "-msse4.1"
-sse4.2 -> "-msse4.2"
+sse41 -> "-msse4.1"
+sse42 -> "-msse4.2"
avx2 -> "-mavx2"
bmi2 -> "-mbmi2"
aesni -> "-maes -mpclmul -mssse3"
diff --git a/src/build-data/cc/msvc.txt b/src/build-data/cc/msvc.txt
index 6df218a4f..b816d33f8 100644
--- a/src/build-data/cc/msvc.txt
+++ b/src/build-data/cc/msvc.txt
@@ -34,8 +34,8 @@ ar_output_to "/OUT:"
<isa_flags>
sse2 -> ""
ssse3 -> ""
-sse4.1 -> ""
-sse4.2 -> ""
+sse41 -> ""
+sse42 -> ""
x86_64:avx2 -> ""
bmi2 -> ""
aesni -> ""
diff --git a/src/build-data/cc/sunstudio.txt b/src/build-data/cc/sunstudio.txt
index 38f9d828c..e983bf701 100644
--- a/src/build-data/cc/sunstudio.txt
+++ b/src/build-data/cc/sunstudio.txt
@@ -54,8 +54,8 @@ x86_64 -> "-m64"
# https://docs.oracle.com/cd/E37069_01/html/E37074/bjapp.html#OSSCGbkazd
sse2 -> "-xarch=sse2"
ssse3 -> "-xarch=ssse3"
-sse4.1 -> "-xarch=sse4_1"
-sse4.2 -> "-xarch=sse4_2"
+sse41 -> "-xarch=sse4.1"
+sse42 -> "-xarch=sse4.2"
aesni -> "-xarch=aes"
avx -> "-xarch=avx"
rdrand -> "-xarch=avx_i"
diff --git a/src/lib/hash/sha1/sha1_x86/info.txt b/src/lib/hash/sha1/sha1_x86/info.txt
index 9cddd40a2..cfa1750c2 100644
--- a/src/lib/hash/sha1/sha1_x86/info.txt
+++ b/src/lib/hash/sha1/sha1_x86/info.txt
@@ -2,7 +2,7 @@
SHA1_X86_SHA_NI -> 20170518
</defines>
-need_isa sha,ssse3,sse4.1
+need_isa sha,ssse3,sse41
<cc>
clang:3.9
diff --git a/src/lib/hash/sha2_32/sha2_32_x86/info.txt b/src/lib/hash/sha2_32/sha2_32_x86/info.txt
index bf34e73a3..838d2a4a8 100644
--- a/src/lib/hash/sha2_32/sha2_32_x86/info.txt
+++ b/src/lib/hash/sha2_32/sha2_32_x86/info.txt
@@ -2,7 +2,7 @@
SHA2_32_X86 -> 20170518
</defines>
-need_isa sha,sse4.1
+need_isa sha,sse41
<cc>
gcc:5.0
diff --git a/src/scripts/install.py b/src/scripts/install.py
index c6e4ec2cd..d30493ebe 100755
--- a/src/scripts/install.py
+++ b/src/scripts/install.py
@@ -229,7 +229,7 @@ def main(args):
copy_file(cfg['botan_pkgconfig'],
prepend_destdir(os.path.join(pkgconfig_dir, os.path.basename(cfg['botan_pkgconfig']))))
- if 'ffi' in cfg['mod_list'].split('\n'):
+ if 'ffi' in cfg['mod_list']:
for ver in cfg['python_version'].split(','):
py_lib_path = os.path.join(lib_dir, 'python%s' % (ver), 'site-packages')
logging.debug('Installing python module to %s' % (py_lib_path))