blob: 5a19c920d560b0ef85673e2738737170495aeddf [file] [log] [blame]
Adam Langleycfd80a92019-11-08 14:40:08 -08001# coding=utf8
2
Adam Langley9e1a6602015-05-05 17:47:53 -07003# Copyright (c) 2015, Google Inc.
4#
5# Permission to use, copy, modify, and/or distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
Matt Braithwaite16695892016-06-09 09:34:11 -070017"""Enumerates source files for consumption by various build systems."""
Adam Langley9e1a6602015-05-05 17:47:53 -070018
Matt Braithwaite16695892016-06-09 09:34:11 -070019import optparse
Adam Langley9e1a6602015-05-05 17:47:53 -070020import os
21import subprocess
22import sys
Adam Langley9c164b22015-06-10 18:54:47 -070023import json
Adam Langley9e1a6602015-05-05 17:47:53 -070024
25
26# OS_ARCH_COMBOS maps from OS and platform to the OpenSSL assembly "style" for
27# that platform and the extension used by asm files.
28OS_ARCH_COMBOS = [
David Benjamin351b2f82022-02-06 12:57:17 -050029 ('apple', 'arm', 'ios32', [], 'S'),
30 ('apple', 'aarch64', 'ios64', [], 'S'),
31 ('apple', 'x86', 'macosx', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'),
32 ('apple', 'x86_64', 'macosx', [], 'S'),
Adam Langley9e1a6602015-05-05 17:47:53 -070033 ('linux', 'arm', 'linux32', [], 'S'),
34 ('linux', 'aarch64', 'linux64', [], 'S'),
Adam Langley7c075b92017-05-22 15:31:13 -070035 ('linux', 'ppc64le', 'linux64le', [], 'S'),
Adam Langley9e1a6602015-05-05 17:47:53 -070036 ('linux', 'x86', 'elf', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'),
37 ('linux', 'x86_64', 'elf', [], 'S'),
Adam Langley9e1a6602015-05-05 17:47:53 -070038 ('win', 'x86', 'win32n', ['-DOPENSSL_IA32_SSE2'], 'asm'),
39 ('win', 'x86_64', 'nasm', [], 'asm'),
Anthony Robertsafd5dba2020-10-19 12:27:51 +010040 ('win', 'aarch64', 'win64', [], 'S'),
Adam Langley9e1a6602015-05-05 17:47:53 -070041]
42
43# NON_PERL_FILES enumerates assembly files that are not processed by the
44# perlasm system.
45NON_PERL_FILES = {
46 ('linux', 'arm'): [
Adam Langley7b8b9c12016-01-04 07:13:00 -080047 'src/crypto/curve25519/asm/x25519-asm-arm.S',
David Benjamin3c4a5cb2016-03-29 17:43:31 -040048 'src/crypto/poly1305/poly1305_arm_asm.S',
Adam Langley7b935932018-11-12 13:53:42 -080049 ],
Adam Langley9e1a6602015-05-05 17:47:53 -070050}
51
Matt Braithwaite16695892016-06-09 09:34:11 -070052PREFIX = None
Adam Langley990a3232018-05-22 10:02:59 -070053EMBED_TEST_DATA = True
Matt Braithwaite16695892016-06-09 09:34:11 -070054
55
56def PathOf(x):
57 return x if not PREFIX else os.path.join(PREFIX, x)
58
Adam Langley9e1a6602015-05-05 17:47:53 -070059
David Benjamin70690f72023-01-25 09:56:43 -050060LICENSE_TEMPLATE = """Copyright (c) 2015, Google Inc.
61
62Permission to use, copy, modify, and/or distribute this software for any
63purpose with or without fee is hereby granted, provided that the above
64copyright notice and this permission notice appear in all copies.
65
66THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
67WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
68MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
69SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
70WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
71OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
72CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.""".split("\n")
73
74def LicenseHeader(comment):
75 lines = []
76 for line in LICENSE_TEMPLATE:
77 if not line:
78 lines.append(comment)
79 else:
80 lines.append("%s %s" % (comment, line))
81 lines.append("")
82 return "\n".join(lines)
83
84
Adam Langley9e1a6602015-05-05 17:47:53 -070085class Android(object):
86
87 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -050088 self.header = LicenseHeader("#") + """
Dan Willemsenb57e4fc2016-07-21 11:08:44 -070089# This file is created by generate_build_files.py. Do not edit manually.
Adam Langley9e1a6602015-05-05 17:47:53 -070090"""
91
92 def PrintVariableSection(self, out, name, files):
93 out.write('%s := \\\n' % name)
94 for f in sorted(files):
95 out.write(' %s\\\n' % f)
96 out.write('\n')
97
98 def WriteFiles(self, files, asm_outputs):
Dan Willemsenb57e4fc2016-07-21 11:08:44 -070099 # New Android.bp format
100 with open('sources.bp', 'w+') as blueprint:
101 blueprint.write(self.header.replace('#', '//'))
102
Pete Bentley44544d92019-08-15 15:01:26 +0100103 # Separate out BCM files to allow different compilation rules (specific to Android FIPS)
104 bcm_c_files = files['bcm_crypto']
105 non_bcm_c_files = [file for file in files['crypto'] if file not in bcm_c_files]
106 non_bcm_asm = self.FilterBcmAsm(asm_outputs, False)
107 bcm_asm = self.FilterBcmAsm(asm_outputs, True)
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700108
Pete Bentley44544d92019-08-15 15:01:26 +0100109 self.PrintDefaults(blueprint, 'libcrypto_sources', non_bcm_c_files, non_bcm_asm)
110 self.PrintDefaults(blueprint, 'libcrypto_bcm_sources', bcm_c_files, bcm_asm)
111 self.PrintDefaults(blueprint, 'libssl_sources', files['ssl'])
112 self.PrintDefaults(blueprint, 'bssl_sources', files['tool'])
113 self.PrintDefaults(blueprint, 'boringssl_test_support_sources', files['test_support'])
114 self.PrintDefaults(blueprint, 'boringssl_crypto_test_sources', files['crypto_test'])
115 self.PrintDefaults(blueprint, 'boringssl_ssl_test_sources', files['ssl_test'])
116
117 # Legacy Android.mk format, only used by Trusty in new branches
118 with open('sources.mk', 'w+') as makefile:
119 makefile.write(self.header)
120 makefile.write('\n')
121 self.PrintVariableSection(makefile, 'crypto_sources', files['crypto'])
122
123 for ((osname, arch), asm_files) in asm_outputs:
124 if osname != 'linux':
125 continue
126 self.PrintVariableSection(
127 makefile, '%s_%s_sources' % (osname, arch), asm_files)
128
129 def PrintDefaults(self, blueprint, name, files, asm_outputs={}):
130 """Print a cc_defaults section from a list of C files and optionally assembly outputs"""
131 blueprint.write('\n')
132 blueprint.write('cc_defaults {\n')
133 blueprint.write(' name: "%s",\n' % name)
134 blueprint.write(' srcs: [\n')
135 for f in sorted(files):
136 blueprint.write(' "%s",\n' % f)
137 blueprint.write(' ],\n')
138
139 if asm_outputs:
140 blueprint.write(' target: {\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700141 for ((osname, arch), asm_files) in asm_outputs:
Steven Valdez93d242b2016-10-06 13:49:01 -0400142 if osname != 'linux' or arch == 'ppc64le':
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700143 continue
144 if arch == 'aarch64':
145 arch = 'arm64'
146
Dan Willemsen2eb4bc52017-10-16 14:37:00 -0700147 blueprint.write(' linux_%s: {\n' % arch)
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700148 blueprint.write(' srcs: [\n')
149 for f in sorted(asm_files):
150 blueprint.write(' "%s",\n' % f)
151 blueprint.write(' ],\n')
152 blueprint.write(' },\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700153 blueprint.write(' },\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700154
Pete Bentley44544d92019-08-15 15:01:26 +0100155 blueprint.write('}\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700156
Pete Bentley44544d92019-08-15 15:01:26 +0100157 def FilterBcmAsm(self, asm, want_bcm):
158 """Filter a list of assembly outputs based on whether they belong in BCM
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700159
Pete Bentley44544d92019-08-15 15:01:26 +0100160 Args:
161 asm: Assembly file lists to filter
162 want_bcm: If true then include BCM files, otherwise do not
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700163
Pete Bentley44544d92019-08-15 15:01:26 +0100164 Returns:
165 A copy of |asm| with files filtered according to |want_bcm|
166 """
167 return [(archinfo, filter(lambda p: ("/crypto/fipsmodule/" in p) == want_bcm, files))
168 for (archinfo, files) in asm]
Adam Langley9e1a6602015-05-05 17:47:53 -0700169
170
David Benjamineca48e52019-08-13 11:51:53 -0400171class AndroidCMake(object):
172
173 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -0500174 self.header = LicenseHeader("#") + """
David Benjamineca48e52019-08-13 11:51:53 -0400175# This file is created by generate_build_files.py. Do not edit manually.
176# To specify a custom path prefix, set BORINGSSL_ROOT before including this
177# file, or use list(TRANSFORM ... PREPEND) from CMake 3.12.
178
179"""
180
181 def PrintVariableSection(self, out, name, files):
182 out.write('set(%s\n' % name)
183 for f in sorted(files):
184 # Ideally adding the prefix would be the caller's job, but
185 # list(TRANSFORM ... PREPEND) is only available starting CMake 3.12. When
186 # sources.cmake is the source of truth, we can ask Android to either write
187 # a CMake function or update to 3.12.
188 out.write(' ${BORINGSSL_ROOT}%s\n' % f)
189 out.write(')\n')
190
191 def WriteFiles(self, files, asm_outputs):
192 # The Android emulator uses a custom CMake buildsystem.
193 #
194 # TODO(davidben): Move our various source lists into sources.cmake and have
195 # Android consume that directly.
196 with open('android-sources.cmake', 'w+') as out:
197 out.write(self.header)
198
199 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
200 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
201 self.PrintVariableSection(out, 'tool_sources', files['tool'])
202 self.PrintVariableSection(out, 'test_support_sources',
203 files['test_support'])
204 self.PrintVariableSection(out, 'crypto_test_sources',
205 files['crypto_test'])
206 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
207
208 for ((osname, arch), asm_files) in asm_outputs:
209 self.PrintVariableSection(
210 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
211
212
Adam Langley049ef412015-06-09 18:20:57 -0700213class Bazel(object):
214 """Bazel outputs files suitable for including in Bazel files."""
215
216 def __init__(self):
217 self.firstSection = True
218 self.header = \
219"""# This file is created by generate_build_files.py. Do not edit manually.
220
221"""
222
223 def PrintVariableSection(self, out, name, files):
224 if not self.firstSection:
225 out.write('\n')
226 self.firstSection = False
227
228 out.write('%s = [\n' % name)
229 for f in sorted(files):
Matt Braithwaite16695892016-06-09 09:34:11 -0700230 out.write(' "%s",\n' % PathOf(f))
Adam Langley049ef412015-06-09 18:20:57 -0700231 out.write(']\n')
232
233 def WriteFiles(self, files, asm_outputs):
Chuck Haysc608d6b2015-10-06 17:54:16 -0700234 with open('BUILD.generated.bzl', 'w+') as out:
Adam Langley049ef412015-06-09 18:20:57 -0700235 out.write(self.header)
236
237 self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
Adam Langleyfd499932017-04-04 14:21:43 -0700238 self.PrintVariableSection(out, 'fips_fragments', files['fips_fragments'])
Adam Langley049ef412015-06-09 18:20:57 -0700239 self.PrintVariableSection(
240 out, 'ssl_internal_headers', files['ssl_internal_headers'])
241 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
242 self.PrintVariableSection(out, 'crypto_headers', files['crypto_headers'])
243 self.PrintVariableSection(
244 out, 'crypto_internal_headers', files['crypto_internal_headers'])
245 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
246 self.PrintVariableSection(out, 'tool_sources', files['tool'])
Adam Langleyf11f2332016-06-30 11:56:19 -0700247 self.PrintVariableSection(out, 'tool_headers', files['tool_headers'])
Adam Langley049ef412015-06-09 18:20:57 -0700248
249 for ((osname, arch), asm_files) in asm_outputs:
Adam Langley049ef412015-06-09 18:20:57 -0700250 self.PrintVariableSection(
Piotr Sikora3f5fe602015-10-28 12:24:35 -0700251 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
Adam Langley049ef412015-06-09 18:20:57 -0700252
Chuck Haysc608d6b2015-10-06 17:54:16 -0700253 with open('BUILD.generated_tests.bzl', 'w+') as out:
Adam Langley9c164b22015-06-10 18:54:47 -0700254 out.write(self.header)
255
256 out.write('test_support_sources = [\n')
David Benjaminc5aa8412016-07-29 17:41:58 -0400257 for filename in sorted(files['test_support'] +
258 files['test_support_headers'] +
259 files['crypto_internal_headers'] +
260 files['ssl_internal_headers']):
Adam Langley9c164b22015-06-10 18:54:47 -0700261 if os.path.basename(filename) == 'malloc.cc':
262 continue
Matt Braithwaite16695892016-06-09 09:34:11 -0700263 out.write(' "%s",\n' % PathOf(filename))
Adam Langley9c164b22015-06-10 18:54:47 -0700264
Adam Langley7b6acc52017-07-27 16:33:27 -0700265 out.write(']\n')
Chuck Haysc608d6b2015-10-06 17:54:16 -0700266
David Benjamin96628432017-01-19 19:05:47 -0500267 self.PrintVariableSection(out, 'crypto_test_sources',
268 files['crypto_test'])
269 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
Adam Langley990a3232018-05-22 10:02:59 -0700270 self.PrintVariableSection(out, 'crypto_test_data',
271 files['crypto_test_data'])
Adam Langley3e502c82019-10-16 09:56:38 -0700272 self.PrintVariableSection(out, 'urandom_test_sources',
273 files['urandom_test'])
David Benjamin96628432017-01-19 19:05:47 -0500274
Adam Langley049ef412015-06-09 18:20:57 -0700275
Robert Sloane091af42017-10-09 12:47:17 -0700276class Eureka(object):
277
278 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -0500279 self.header = LicenseHeader("#") + """
Robert Sloane091af42017-10-09 12:47:17 -0700280# This file is created by generate_build_files.py. Do not edit manually.
281
282"""
283
284 def PrintVariableSection(self, out, name, files):
285 out.write('%s := \\\n' % name)
286 for f in sorted(files):
287 out.write(' %s\\\n' % f)
288 out.write('\n')
289
290 def WriteFiles(self, files, asm_outputs):
291 # Legacy Android.mk format
292 with open('eureka.mk', 'w+') as makefile:
293 makefile.write(self.header)
294
295 self.PrintVariableSection(makefile, 'crypto_sources', files['crypto'])
296 self.PrintVariableSection(makefile, 'ssl_sources', files['ssl'])
297 self.PrintVariableSection(makefile, 'tool_sources', files['tool'])
298
299 for ((osname, arch), asm_files) in asm_outputs:
300 if osname != 'linux':
301 continue
302 self.PrintVariableSection(
303 makefile, '%s_%s_sources' % (osname, arch), asm_files)
304
305
David Benjamin38d01c62016-04-21 18:47:57 -0400306class GN(object):
307
308 def __init__(self):
309 self.firstSection = True
David Benjamin70690f72023-01-25 09:56:43 -0500310 self.header = LicenseHeader("#") + """
David Benjamin38d01c62016-04-21 18:47:57 -0400311# This file is created by generate_build_files.py. Do not edit manually.
312
313"""
314
315 def PrintVariableSection(self, out, name, files):
316 if not self.firstSection:
317 out.write('\n')
318 self.firstSection = False
319
320 out.write('%s = [\n' % name)
321 for f in sorted(files):
322 out.write(' "%s",\n' % f)
323 out.write(']\n')
324
325 def WriteFiles(self, files, asm_outputs):
326 with open('BUILD.generated.gni', 'w+') as out:
327 out.write(self.header)
328
David Benjaminc5aa8412016-07-29 17:41:58 -0400329 self.PrintVariableSection(out, 'crypto_sources',
James Robinson98dd68f2018-04-11 14:47:34 -0700330 files['crypto'] +
David Benjaminc5aa8412016-07-29 17:41:58 -0400331 files['crypto_internal_headers'])
James Robinson98dd68f2018-04-11 14:47:34 -0700332 self.PrintVariableSection(out, 'crypto_headers',
333 files['crypto_headers'])
David Benjaminc5aa8412016-07-29 17:41:58 -0400334 self.PrintVariableSection(out, 'ssl_sources',
James Robinson98dd68f2018-04-11 14:47:34 -0700335 files['ssl'] + files['ssl_internal_headers'])
336 self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
David Benjaminbb0cb952020-12-17 16:35:39 -0500337 self.PrintVariableSection(out, 'tool_sources',
338 files['tool'] + files['tool_headers'])
David Benjamin38d01c62016-04-21 18:47:57 -0400339
340 for ((osname, arch), asm_files) in asm_outputs:
341 self.PrintVariableSection(
342 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
343
344 fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0]
345 for fuzzer in files['fuzz']]
346 self.PrintVariableSection(out, 'fuzzers', fuzzers)
347
348 with open('BUILD.generated_tests.gni', 'w+') as out:
349 self.firstSection = True
350 out.write(self.header)
351
David Benjamin96628432017-01-19 19:05:47 -0500352 self.PrintVariableSection(out, 'test_support_sources',
David Benjaminc5aa8412016-07-29 17:41:58 -0400353 files['test_support'] +
354 files['test_support_headers'])
David Benjamin96628432017-01-19 19:05:47 -0500355 self.PrintVariableSection(out, 'crypto_test_sources',
356 files['crypto_test'])
David Benjaminf014d602019-05-07 18:58:06 -0500357 self.PrintVariableSection(out, 'crypto_test_data',
358 files['crypto_test_data'])
David Benjamin96628432017-01-19 19:05:47 -0500359 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
David Benjamin38d01c62016-04-21 18:47:57 -0400360
361
362class GYP(object):
363
364 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -0500365 self.header = LicenseHeader("#") + """
David Benjamin38d01c62016-04-21 18:47:57 -0400366# This file is created by generate_build_files.py. Do not edit manually.
367
368"""
369
370 def PrintVariableSection(self, out, name, files):
371 out.write(' \'%s\': [\n' % name)
372 for f in sorted(files):
373 out.write(' \'%s\',\n' % f)
374 out.write(' ],\n')
375
376 def WriteFiles(self, files, asm_outputs):
377 with open('boringssl.gypi', 'w+') as gypi:
378 gypi.write(self.header + '{\n \'variables\': {\n')
379
David Benjaminc5aa8412016-07-29 17:41:58 -0400380 self.PrintVariableSection(gypi, 'boringssl_ssl_sources',
381 files['ssl'] + files['ssl_headers'] +
382 files['ssl_internal_headers'])
383 self.PrintVariableSection(gypi, 'boringssl_crypto_sources',
384 files['crypto'] + files['crypto_headers'] +
385 files['crypto_internal_headers'])
David Benjamin38d01c62016-04-21 18:47:57 -0400386
387 for ((osname, arch), asm_files) in asm_outputs:
388 self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' %
389 (osname, arch), asm_files)
390
391 gypi.write(' }\n}\n')
392
Adam Langleycfd80a92019-11-08 14:40:08 -0800393class CMake(object):
394
395 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -0500396 self.header = LicenseHeader("#") + R'''
Adam Langleycfd80a92019-11-08 14:40:08 -0800397# This file is created by generate_build_files.py. Do not edit manually.
398
David Benjamind0b66c72021-03-22 17:30:02 -0400399cmake_minimum_required(VERSION 3.5)
Adam Langleycfd80a92019-11-08 14:40:08 -0800400
401project(BoringSSL LANGUAGES C CXX)
402
403if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
404 set(CLANG 1)
405endif()
406
407if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
David Benjamin493d5cb2022-04-18 17:20:27 -0400408 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fvisibility=hidden -fno-common -fno-exceptions -fno-rtti")
David Benjamin49f03292021-03-22 17:35:06 -0400409 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fno-common -std=c11")
Adam Langleycfd80a92019-11-08 14:40:08 -0800410endif()
411
412# pthread_rwlock_t requires a feature flag.
413if(NOT WIN32)
414 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
415endif()
416
417if(WIN32)
418 add_definitions(-D_HAS_EXCEPTIONS=0)
419 add_definitions(-DWIN32_LEAN_AND_MEAN)
420 add_definitions(-DNOMINMAX)
421 # Allow use of fopen.
422 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
423 # VS 2017 and higher supports STL-only warning suppressions.
424 # A bug in CMake < 3.13.0 may cause the space in this value to
425 # cause issues when building with NASM. In that case, update CMake.
426 add_definitions("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987")
427endif()
428
429add_definitions(-DBORINGSSL_IMPLEMENTATION)
430
Adam Langley89730072020-01-17 08:18:07 -0800431# CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an
432# architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR
433# alone, and expects all architecture-specific logic to be conditioned within
434# the source files rather than the build. This does not work for our assembly
435# files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture
436# builds.
437if(NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES)
438 list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES)
David Benjamin7e265972021-08-04 14:28:55 -0400439 if(NOT NUM_ARCHES EQUAL 1)
Adam Langley89730072020-01-17 08:18:07 -0800440 message(FATAL_ERROR "Universal binaries not supported.")
441 endif()
442 list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR)
443endif()
444
Adam Langleycfd80a92019-11-08 14:40:08 -0800445if(OPENSSL_NO_ASM)
446 add_definitions(-DOPENSSL_NO_ASM)
447 set(ARCH "generic")
David Benjamin7e265972021-08-04 14:28:55 -0400448elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800449 set(ARCH "x86_64")
David Benjamin7e265972021-08-04 14:28:55 -0400450elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800451 set(ARCH "x86_64")
David Benjamin7e265972021-08-04 14:28:55 -0400452elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800453 # cmake reports AMD64 on Windows, but we might be building for 32-bit.
David Benjamin884614c2020-06-16 10:59:58 -0400454 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
Adam Langleycfd80a92019-11-08 14:40:08 -0800455 set(ARCH "x86_64")
456 else()
457 set(ARCH "x86")
458 endif()
David Benjamin7e265972021-08-04 14:28:55 -0400459elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
Adam Langleycfd80a92019-11-08 14:40:08 -0800460 set(ARCH "x86")
David Benjamin7e265972021-08-04 14:28:55 -0400461elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
Adam Langleycfd80a92019-11-08 14:40:08 -0800462 set(ARCH "x86")
David Benjamin7e265972021-08-04 14:28:55 -0400463elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686")
Adam Langleycfd80a92019-11-08 14:40:08 -0800464 set(ARCH "x86")
David Benjamin7e265972021-08-04 14:28:55 -0400465elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800466 set(ARCH "aarch64")
David Benjamin7e265972021-08-04 14:28:55 -0400467elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800468 set(ARCH "aarch64")
469# Apple A12 Bionic chipset which is added in iPhone XS/XS Max/XR uses arm64e architecture.
David Benjamin7e265972021-08-04 14:28:55 -0400470elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64e")
Adam Langleycfd80a92019-11-08 14:40:08 -0800471 set(ARCH "aarch64")
David Benjamin7e265972021-08-04 14:28:55 -0400472elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm*")
Adam Langleycfd80a92019-11-08 14:40:08 -0800473 set(ARCH "arm")
David Benjamin7e265972021-08-04 14:28:55 -0400474elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "mips")
Adam Langleycfd80a92019-11-08 14:40:08 -0800475 # Just to avoid the “unknown processor” error.
476 set(ARCH "generic")
David Benjamin7e265972021-08-04 14:28:55 -0400477elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le")
Adam Langleycfd80a92019-11-08 14:40:08 -0800478 set(ARCH "ppc64le")
479else()
480 message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
481endif()
482
483if(NOT OPENSSL_NO_ASM)
484 if(UNIX)
485 enable_language(ASM)
486
487 # Clang's integerated assembler does not support debug symbols.
488 if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang")
489 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g")
490 endif()
491
492 # CMake does not add -isysroot and -arch flags to assembly.
493 if(APPLE)
494 if(CMAKE_OSX_SYSROOT)
495 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"")
496 endif()
497 foreach(arch ${CMAKE_OSX_ARCHITECTURES})
498 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}")
499 endforeach()
500 endif()
501 else()
502 set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8")
503 enable_language(ASM_NASM)
504 endif()
505endif()
506
Adam Langleya0cdbf92020-01-21 09:07:46 -0800507if(BUILD_SHARED_LIBS)
508 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
509 # Enable position-independent code globally. This is needed because
510 # some library targets are OBJECT libraries.
511 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
512endif()
513
Adam Langleycfd80a92019-11-08 14:40:08 -0800514include_directories(src/include)
515
516'''
517
518 def PrintLibrary(self, out, name, files):
519 out.write('add_library(\n')
520 out.write(' %s\n\n' % name)
521
522 for f in sorted(files):
523 out.write(' %s\n' % PathOf(f))
524
525 out.write(')\n\n')
526
527 def PrintExe(self, out, name, files, libs):
528 out.write('add_executable(\n')
529 out.write(' %s\n\n' % name)
530
531 for f in sorted(files):
532 out.write(' %s\n' % PathOf(f))
533
534 out.write(')\n\n')
535 out.write('target_link_libraries(%s %s)\n\n' % (name, ' '.join(libs)))
536
537 def PrintSection(self, out, name, files):
538 out.write('set(\n')
539 out.write(' %s\n\n' % name)
540 for f in sorted(files):
541 out.write(' %s\n' % PathOf(f))
542 out.write(')\n\n')
543
544 def WriteFiles(self, files, asm_outputs):
545 with open('CMakeLists.txt', 'w+') as cmake:
546 cmake.write(self.header)
547
548 for ((osname, arch), asm_files) in asm_outputs:
549 self.PrintSection(cmake, 'CRYPTO_%s_%s_SOURCES' % (osname, arch),
550 asm_files)
551
552 cmake.write(
David Benjamin68addd22022-02-08 00:25:34 -0500553R'''if(APPLE)
David Benjamin351b2f82022-02-06 12:57:17 -0500554 set(CRYPTO_ARCH_SOURCES ${CRYPTO_apple_${ARCH}_SOURCES})
Adam Langleycfd80a92019-11-08 14:40:08 -0800555elseif(UNIX)
556 set(CRYPTO_ARCH_SOURCES ${CRYPTO_linux_${ARCH}_SOURCES})
557elseif(WIN32)
558 set(CRYPTO_ARCH_SOURCES ${CRYPTO_win_${ARCH}_SOURCES})
559endif()
560
561''')
562
563 self.PrintLibrary(cmake, 'crypto',
564 files['crypto'] + ['${CRYPTO_ARCH_SOURCES}'])
565 self.PrintLibrary(cmake, 'ssl', files['ssl'])
Adam Langleyff631132020-01-13 15:24:22 -0800566 self.PrintExe(cmake, 'bssl', files['tool'], ['ssl', 'crypto'])
567
568 cmake.write(
David Benjamin8f88b272020-07-09 13:35:01 -0400569R'''if(NOT WIN32 AND NOT ANDROID)
Adam Langleyff631132020-01-13 15:24:22 -0800570 target_link_libraries(crypto pthread)
571endif()
572
David Benjamin8f88b272020-07-09 13:35:01 -0400573if(WIN32)
574 target_link_libraries(bssl ws2_32)
575endif()
576
Adam Langleyff631132020-01-13 15:24:22 -0800577''')
David Benjamin38d01c62016-04-21 18:47:57 -0400578
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400579class JSON(object):
580 def WriteFiles(self, files, asm_outputs):
581 sources = dict(files)
582 for ((osname, arch), asm_files) in asm_outputs:
583 sources['crypto_%s_%s' % (osname, arch)] = asm_files
584 with open('sources.json', 'w+') as f:
585 json.dump(sources, f, sort_keys=True, indent=2)
586
Adam Langley9e1a6602015-05-05 17:47:53 -0700587def FindCMakeFiles(directory):
588 """Returns list of all CMakeLists.txt files recursively in directory."""
589 cmakefiles = []
590
591 for (path, _, filenames) in os.walk(directory):
592 for filename in filenames:
593 if filename == 'CMakeLists.txt':
594 cmakefiles.append(os.path.join(path, filename))
595
596 return cmakefiles
597
Adam Langleyfd499932017-04-04 14:21:43 -0700598def OnlyFIPSFragments(path, dent, is_dir):
Matthew Braithwaite95511e92017-05-08 16:38:03 -0700599 return is_dir or (path.startswith(
600 os.path.join('src', 'crypto', 'fipsmodule', '')) and
601 NoTests(path, dent, is_dir))
Adam Langley9e1a6602015-05-05 17:47:53 -0700602
Adam Langleyfd499932017-04-04 14:21:43 -0700603def NoTestsNorFIPSFragments(path, dent, is_dir):
Adam Langley323f1eb2017-04-06 17:29:10 -0700604 return (NoTests(path, dent, is_dir) and
605 (is_dir or not OnlyFIPSFragments(path, dent, is_dir)))
Adam Langleyfd499932017-04-04 14:21:43 -0700606
607def NoTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700608 """Filter function that can be passed to FindCFiles in order to remove test
609 sources."""
610 if is_dir:
611 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400612 return 'test.' not in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700613
614
Adam Langleyfd499932017-04-04 14:21:43 -0700615def OnlyTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700616 """Filter function that can be passed to FindCFiles in order to remove
617 non-test sources."""
618 if is_dir:
David Benjamin26073832015-05-11 20:52:48 -0400619 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400620 return '_test.' in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700621
622
Adam Langleyfd499932017-04-04 14:21:43 -0700623def AllFiles(path, dent, is_dir):
David Benjamin26073832015-05-11 20:52:48 -0400624 """Filter function that can be passed to FindCFiles in order to include all
625 sources."""
626 return True
627
628
Adam Langleyfd499932017-04-04 14:21:43 -0700629def NoTestRunnerFiles(path, dent, is_dir):
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700630 """Filter function that can be passed to FindCFiles or FindHeaderFiles in
631 order to exclude test runner files."""
632 # NOTE(martinkr): This prevents .h/.cc files in src/ssl/test/runner, which
633 # are in their own subpackage, from being included in boringssl/BUILD files.
634 return not is_dir or dent != 'runner'
635
636
David Benjamin3ecd0a52017-05-19 15:26:18 -0400637def NotGTestSupport(path, dent, is_dir):
David Benjaminc3889632019-03-01 15:03:05 -0500638 return 'gtest' not in dent and 'abi_test' not in dent
David Benjamin96628432017-01-19 19:05:47 -0500639
640
Adam Langleyfd499932017-04-04 14:21:43 -0700641def SSLHeaderFiles(path, dent, is_dir):
Aaron Green0e150022018-10-16 12:05:29 -0700642 return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h', 'srtp.h']
Adam Langley049ef412015-06-09 18:20:57 -0700643
644
Adam Langley9e1a6602015-05-05 17:47:53 -0700645def FindCFiles(directory, filter_func):
646 """Recurses through directory and returns a list of paths to all the C source
647 files that pass filter_func."""
648 cfiles = []
649
650 for (path, dirnames, filenames) in os.walk(directory):
651 for filename in filenames:
652 if not filename.endswith('.c') and not filename.endswith('.cc'):
653 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700654 if not filter_func(path, filename, False):
Adam Langley9e1a6602015-05-05 17:47:53 -0700655 continue
656 cfiles.append(os.path.join(path, filename))
657
658 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700659 if not filter_func(path, dirname, True):
Adam Langley9e1a6602015-05-05 17:47:53 -0700660 del dirnames[i]
661
David Benjaminedd4c5f2020-08-19 14:46:17 -0400662 cfiles.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700663 return cfiles
664
665
Adam Langley049ef412015-06-09 18:20:57 -0700666def FindHeaderFiles(directory, filter_func):
667 """Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
668 hfiles = []
669
670 for (path, dirnames, filenames) in os.walk(directory):
671 for filename in filenames:
672 if not filename.endswith('.h'):
673 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700674 if not filter_func(path, filename, False):
Adam Langley049ef412015-06-09 18:20:57 -0700675 continue
676 hfiles.append(os.path.join(path, filename))
677
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700678 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700679 if not filter_func(path, dirname, True):
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700680 del dirnames[i]
681
David Benjaminedd4c5f2020-08-19 14:46:17 -0400682 hfiles.sort()
Adam Langley049ef412015-06-09 18:20:57 -0700683 return hfiles
684
685
Adam Langley9e1a6602015-05-05 17:47:53 -0700686def ExtractPerlAsmFromCMakeFile(cmakefile):
687 """Parses the contents of the CMakeLists.txt file passed as an argument and
688 returns a list of all the perlasm() directives found in the file."""
689 perlasms = []
690 with open(cmakefile) as f:
691 for line in f:
692 line = line.strip()
693 if not line.startswith('perlasm('):
694 continue
695 if not line.endswith(')'):
696 raise ValueError('Bad perlasm line in %s' % cmakefile)
697 # Remove "perlasm(" from start and ")" from end
698 params = line[8:-1].split()
699 if len(params) < 2:
700 raise ValueError('Bad perlasm line in %s' % cmakefile)
701 perlasms.append({
702 'extra_args': params[2:],
703 'input': os.path.join(os.path.dirname(cmakefile), params[1]),
704 'output': os.path.join(os.path.dirname(cmakefile), params[0]),
705 })
706
707 return perlasms
708
709
710def ReadPerlAsmOperations():
711 """Returns a list of all perlasm() directives found in CMake config files in
712 src/."""
713 perlasms = []
714 cmakefiles = FindCMakeFiles('src')
715
716 for cmakefile in cmakefiles:
717 perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile))
718
719 return perlasms
720
721
722def PerlAsm(output_filename, input_filename, perlasm_style, extra_args):
723 """Runs the a perlasm script and puts the output into output_filename."""
724 base_dir = os.path.dirname(output_filename)
725 if not os.path.isdir(base_dir):
726 os.makedirs(base_dir)
David Benjaminfdd8e9c2016-06-26 13:18:50 -0400727 subprocess.check_call(
728 ['perl', input_filename, perlasm_style] + extra_args + [output_filename])
Adam Langley9e1a6602015-05-05 17:47:53 -0700729
730
731def ArchForAsmFilename(filename):
732 """Returns the architectures that a given asm file should be compiled for
733 based on substrings in the filename."""
734
735 if 'x86_64' in filename or 'avx2' in filename:
736 return ['x86_64']
737 elif ('x86' in filename and 'x86_64' not in filename) or '586' in filename:
738 return ['x86']
739 elif 'armx' in filename:
740 return ['arm', 'aarch64']
741 elif 'armv8' in filename:
742 return ['aarch64']
743 elif 'arm' in filename:
744 return ['arm']
David Benjamin9f16ce12016-09-27 16:30:22 -0400745 elif 'ppc' in filename:
746 return ['ppc64le']
Adam Langley9e1a6602015-05-05 17:47:53 -0700747 else:
748 raise ValueError('Unknown arch for asm filename: ' + filename)
749
750
751def WriteAsmFiles(perlasms):
752 """Generates asm files from perlasm directives for each supported OS x
753 platform combination."""
754 asmfiles = {}
755
756 for osarch in OS_ARCH_COMBOS:
757 (osname, arch, perlasm_style, extra_args, asm_ext) = osarch
758 key = (osname, arch)
759 outDir = '%s-%s' % key
760
761 for perlasm in perlasms:
762 filename = os.path.basename(perlasm['input'])
763 output = perlasm['output']
764 if not output.startswith('src'):
765 raise ValueError('output missing src: %s' % output)
766 output = os.path.join(outDir, output[4:])
William Hessec618c402015-06-22 16:34:02 +0200767 if output.endswith('-armx.${ASM_EXT}'):
768 output = output.replace('-armx',
769 '-armx64' if arch == 'aarch64' else '-armx32')
Adam Langley9e1a6602015-05-05 17:47:53 -0700770 output = output.replace('${ASM_EXT}', asm_ext)
771
772 if arch in ArchForAsmFilename(filename):
773 PerlAsm(output, perlasm['input'], perlasm_style,
774 perlasm['extra_args'] + extra_args)
775 asmfiles.setdefault(key, []).append(output)
776
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000777 for (key, non_perl_asm_files) in NON_PERL_FILES.items():
Adam Langley9e1a6602015-05-05 17:47:53 -0700778 asmfiles.setdefault(key, []).extend(non_perl_asm_files)
779
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000780 for files in asmfiles.values():
David Benjaminedd4c5f2020-08-19 14:46:17 -0400781 files.sort()
782
Adam Langley9e1a6602015-05-05 17:47:53 -0700783 return asmfiles
784
785
David Benjamin3ecd0a52017-05-19 15:26:18 -0400786def ExtractVariablesFromCMakeFile(cmakefile):
787 """Parses the contents of the CMakeLists.txt file passed as an argument and
788 returns a dictionary of exported source lists."""
789 variables = {}
790 in_set_command = False
791 set_command = []
792 with open(cmakefile) as f:
793 for line in f:
794 if '#' in line:
795 line = line[:line.index('#')]
796 line = line.strip()
797
798 if not in_set_command:
799 if line.startswith('set('):
800 in_set_command = True
801 set_command = []
802 elif line == ')':
803 in_set_command = False
804 if not set_command:
805 raise ValueError('Empty set command')
806 variables[set_command[0]] = set_command[1:]
807 else:
808 set_command.extend([c for c in line.split(' ') if c])
809
810 if in_set_command:
811 raise ValueError('Unfinished set command')
812 return variables
813
814
Adam Langley049ef412015-06-09 18:20:57 -0700815def main(platforms):
David Benjamin3ecd0a52017-05-19 15:26:18 -0400816 cmake = ExtractVariablesFromCMakeFile(os.path.join('src', 'sources.cmake'))
Andres Erbsen5b280a82017-10-30 15:58:33 +0000817 crypto_c_files = (FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments) +
Adam Langley7f028812019-10-18 14:48:11 -0700818 FindCFiles(os.path.join('src', 'third_party', 'fiat'), NoTestsNorFIPSFragments))
Adam Langleyfd499932017-04-04 14:21:43 -0700819 fips_fragments = FindCFiles(os.path.join('src', 'crypto', 'fipsmodule'), OnlyFIPSFragments)
Adam Langleyfeca9e52017-01-23 13:07:50 -0800820 ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
David Benjamin38d01c62016-04-21 18:47:57 -0400821 tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
Adam Langleyf11f2332016-06-30 11:56:19 -0700822 tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles)
Adam Langley9e1a6602015-05-05 17:47:53 -0700823
Pete Bentley44544d92019-08-15 15:01:26 +0100824 # BCM shared library C files
825 bcm_crypto_c_files = [
826 os.path.join('src', 'crypto', 'fipsmodule', 'bcm.c')
827 ]
828
Adam Langley9e1a6602015-05-05 17:47:53 -0700829 # Generate err_data.c
830 with open('err_data.c', 'w+') as err_data:
831 subprocess.check_call(['go', 'run', 'err_data_generate.go'],
832 cwd=os.path.join('src', 'crypto', 'err'),
833 stdout=err_data)
834 crypto_c_files.append('err_data.c')
David Benjaminedd4c5f2020-08-19 14:46:17 -0400835 crypto_c_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700836
David Benjamin38d01c62016-04-21 18:47:57 -0400837 test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
David Benjamin3ecd0a52017-05-19 15:26:18 -0400838 NotGTestSupport)
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700839 test_support_h_files = (
840 FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) +
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700841 FindHeaderFiles(os.path.join('src', 'ssl', 'test'), NoTestRunnerFiles))
David Benjamin26073832015-05-11 20:52:48 -0400842
Adam Langley990a3232018-05-22 10:02:59 -0700843 crypto_test_files = []
844 if EMBED_TEST_DATA:
845 # Generate crypto_test_data.cc
846 with open('crypto_test_data.cc', 'w+') as out:
847 subprocess.check_call(
848 ['go', 'run', 'util/embed_test_data.go'] + cmake['CRYPTO_TEST_DATA'],
849 cwd='src',
850 stdout=out)
851 crypto_test_files += ['crypto_test_data.cc']
David Benjamin3ecd0a52017-05-19 15:26:18 -0400852
Adam Langley990a3232018-05-22 10:02:59 -0700853 crypto_test_files += FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
David Benjamin96ee4a82017-07-09 23:46:47 -0400854 crypto_test_files += [
David Benjaminc3889632019-03-01 15:03:05 -0500855 'src/crypto/test/abi_test.cc',
David Benjamin3ecd0a52017-05-19 15:26:18 -0400856 'src/crypto/test/file_test_gtest.cc',
857 'src/crypto/test/gtest_main.cc',
858 ]
Adam Langley3e502c82019-10-16 09:56:38 -0700859 # urandom_test.cc is in a separate binary so that it can be test PRNG
860 # initialisation.
861 crypto_test_files = [
862 file for file in crypto_test_files
863 if not file.endswith('/urandom_test.cc')
864 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400865 crypto_test_files.sort()
David Benjamin1d5a5702017-02-13 22:11:49 -0500866
867 ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
Robert Sloanae1e0872019-03-01 16:01:30 -0800868 ssl_test_files += [
869 'src/crypto/test/abi_test.cc',
870 'src/crypto/test/gtest_main.cc',
871 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400872 ssl_test_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700873
Adam Langley3e502c82019-10-16 09:56:38 -0700874 urandom_test_files = [
875 'src/crypto/fipsmodule/rand/urandom_test.cc',
876 ]
877
David Benjamin38d01c62016-04-21 18:47:57 -0400878 fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
879
David Benjaminedd4c5f2020-08-19 14:46:17 -0400880 ssl_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
881 SSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700882
Adam Langleyfd499932017-04-04 14:21:43 -0700883 def NotSSLHeaderFiles(path, filename, is_dir):
884 return not SSLHeaderFiles(path, filename, is_dir)
David Benjaminedd4c5f2020-08-19 14:46:17 -0400885 crypto_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
886 NotSSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700887
888 ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
Andres Erbsen5b280a82017-10-30 15:58:33 +0000889 crypto_internal_h_files = (
890 FindHeaderFiles(os.path.join('src', 'crypto'), NoTests) +
Adam Langley7f028812019-10-18 14:48:11 -0700891 FindHeaderFiles(os.path.join('src', 'third_party', 'fiat'), NoTests))
Adam Langley049ef412015-06-09 18:20:57 -0700892
Adam Langley9e1a6602015-05-05 17:47:53 -0700893 files = {
Pete Bentley44544d92019-08-15 15:01:26 +0100894 'bcm_crypto': bcm_crypto_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700895 'crypto': crypto_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700896 'crypto_headers': crypto_h_files,
897 'crypto_internal_headers': crypto_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400898 'crypto_test': crypto_test_files,
Adam Langley990a3232018-05-22 10:02:59 -0700899 'crypto_test_data': sorted('src/' + x for x in cmake['CRYPTO_TEST_DATA']),
Adam Langleyfd499932017-04-04 14:21:43 -0700900 'fips_fragments': fips_fragments,
David Benjamin38d01c62016-04-21 18:47:57 -0400901 'fuzz': fuzz_c_files,
Adam Langleyfeca9e52017-01-23 13:07:50 -0800902 'ssl': ssl_source_files,
Adam Langley049ef412015-06-09 18:20:57 -0700903 'ssl_headers': ssl_h_files,
904 'ssl_internal_headers': ssl_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400905 'ssl_test': ssl_test_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400906 'tool': tool_c_files,
Adam Langleyf11f2332016-06-30 11:56:19 -0700907 'tool_headers': tool_h_files,
David Benjaminc5aa8412016-07-29 17:41:58 -0400908 'test_support': test_support_c_files,
909 'test_support_headers': test_support_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400910 'urandom_test': urandom_test_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700911 }
912
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000913 asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).items())
Adam Langley9e1a6602015-05-05 17:47:53 -0700914
Adam Langley049ef412015-06-09 18:20:57 -0700915 for platform in platforms:
916 platform.WriteFiles(files, asm_outputs)
Adam Langley9e1a6602015-05-05 17:47:53 -0700917
918 return 0
919
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400920ALL_PLATFORMS = {
921 'android': Android,
922 'android-cmake': AndroidCMake,
923 'bazel': Bazel,
924 'cmake': CMake,
925 'eureka': Eureka,
926 'gn': GN,
927 'gyp': GYP,
928 'json': JSON,
929}
Adam Langley9e1a6602015-05-05 17:47:53 -0700930
Adam Langley9e1a6602015-05-05 17:47:53 -0700931if __name__ == '__main__':
David Benjamin4acc7dd2022-11-19 10:13:49 -0500932 parser = optparse.OptionParser(
933 usage='Usage: %%prog [--prefix=<path>] [all|%s]' %
934 '|'.join(sorted(ALL_PLATFORMS.keys())))
Matt Braithwaite16695892016-06-09 09:34:11 -0700935 parser.add_option('--prefix', dest='prefix',
936 help='For Bazel, prepend argument to all source files')
Adam Langley990a3232018-05-22 10:02:59 -0700937 parser.add_option(
938 '--embed_test_data', type='choice', dest='embed_test_data',
939 action='store', default="true", choices=["true", "false"],
David Benjaminf014d602019-05-07 18:58:06 -0500940 help='For Bazel or GN, don\'t embed data files in crypto_test_data.cc')
Matt Braithwaite16695892016-06-09 09:34:11 -0700941 options, args = parser.parse_args(sys.argv[1:])
942 PREFIX = options.prefix
Adam Langley990a3232018-05-22 10:02:59 -0700943 EMBED_TEST_DATA = (options.embed_test_data == "true")
Matt Braithwaite16695892016-06-09 09:34:11 -0700944
945 if not args:
946 parser.print_help()
947 sys.exit(1)
Adam Langley9e1a6602015-05-05 17:47:53 -0700948
David Benjamin4acc7dd2022-11-19 10:13:49 -0500949 if 'all' in args:
950 platforms = [platform() for platform in ALL_PLATFORMS.values()]
951 else:
952 platforms = []
953 for s in args:
954 platform = ALL_PLATFORMS.get(s)
955 if platform is None:
956 parser.print_help()
957 sys.exit(1)
958 platforms.append(platform())
Adam Langley9e1a6602015-05-05 17:47:53 -0700959
Adam Langley049ef412015-06-09 18:20:57 -0700960 sys.exit(main(platforms))