blob: 6c589f7936a18a6cd18fa663ec95988aac90efa5 [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 ],
50 ('linux', 'x86_64'): [
51 'src/crypto/hrss/asm/poly_rq_mul.S',
Adam Langley9e1a6602015-05-05 17:47:53 -070052 ],
53}
54
Matt Braithwaite16695892016-06-09 09:34:11 -070055PREFIX = None
Adam Langley990a3232018-05-22 10:02:59 -070056EMBED_TEST_DATA = True
Matt Braithwaite16695892016-06-09 09:34:11 -070057
58
59def PathOf(x):
60 return x if not PREFIX else os.path.join(PREFIX, x)
61
Adam Langley9e1a6602015-05-05 17:47:53 -070062
Adam Langley9e1a6602015-05-05 17:47:53 -070063class Android(object):
64
65 def __init__(self):
66 self.header = \
67"""# Copyright (C) 2015 The Android Open Source Project
68#
69# Licensed under the Apache License, Version 2.0 (the "License");
70# you may not use this file except in compliance with the License.
71# You may obtain a copy of the License at
72#
73# http://www.apache.org/licenses/LICENSE-2.0
74#
75# Unless required by applicable law or agreed to in writing, software
76# distributed under the License is distributed on an "AS IS" BASIS,
77# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
78# See the License for the specific language governing permissions and
79# limitations under the License.
80
Dan Willemsenb57e4fc2016-07-21 11:08:44 -070081# This file is created by generate_build_files.py. Do not edit manually.
Adam Langley9e1a6602015-05-05 17:47:53 -070082"""
83
84 def PrintVariableSection(self, out, name, files):
85 out.write('%s := \\\n' % name)
86 for f in sorted(files):
87 out.write(' %s\\\n' % f)
88 out.write('\n')
89
90 def WriteFiles(self, files, asm_outputs):
Dan Willemsenb57e4fc2016-07-21 11:08:44 -070091 # New Android.bp format
92 with open('sources.bp', 'w+') as blueprint:
93 blueprint.write(self.header.replace('#', '//'))
94
Pete Bentley44544d92019-08-15 15:01:26 +010095 # Separate out BCM files to allow different compilation rules (specific to Android FIPS)
96 bcm_c_files = files['bcm_crypto']
97 non_bcm_c_files = [file for file in files['crypto'] if file not in bcm_c_files]
98 non_bcm_asm = self.FilterBcmAsm(asm_outputs, False)
99 bcm_asm = self.FilterBcmAsm(asm_outputs, True)
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700100
Pete Bentley44544d92019-08-15 15:01:26 +0100101 self.PrintDefaults(blueprint, 'libcrypto_sources', non_bcm_c_files, non_bcm_asm)
102 self.PrintDefaults(blueprint, 'libcrypto_bcm_sources', bcm_c_files, bcm_asm)
103 self.PrintDefaults(blueprint, 'libssl_sources', files['ssl'])
104 self.PrintDefaults(blueprint, 'bssl_sources', files['tool'])
105 self.PrintDefaults(blueprint, 'boringssl_test_support_sources', files['test_support'])
106 self.PrintDefaults(blueprint, 'boringssl_crypto_test_sources', files['crypto_test'])
107 self.PrintDefaults(blueprint, 'boringssl_ssl_test_sources', files['ssl_test'])
108
109 # Legacy Android.mk format, only used by Trusty in new branches
110 with open('sources.mk', 'w+') as makefile:
111 makefile.write(self.header)
112 makefile.write('\n')
113 self.PrintVariableSection(makefile, 'crypto_sources', files['crypto'])
114
115 for ((osname, arch), asm_files) in asm_outputs:
116 if osname != 'linux':
117 continue
118 self.PrintVariableSection(
119 makefile, '%s_%s_sources' % (osname, arch), asm_files)
120
121 def PrintDefaults(self, blueprint, name, files, asm_outputs={}):
122 """Print a cc_defaults section from a list of C files and optionally assembly outputs"""
123 blueprint.write('\n')
124 blueprint.write('cc_defaults {\n')
125 blueprint.write(' name: "%s",\n' % name)
126 blueprint.write(' srcs: [\n')
127 for f in sorted(files):
128 blueprint.write(' "%s",\n' % f)
129 blueprint.write(' ],\n')
130
131 if asm_outputs:
132 blueprint.write(' target: {\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700133 for ((osname, arch), asm_files) in asm_outputs:
Steven Valdez93d242b2016-10-06 13:49:01 -0400134 if osname != 'linux' or arch == 'ppc64le':
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700135 continue
136 if arch == 'aarch64':
137 arch = 'arm64'
138
Dan Willemsen2eb4bc52017-10-16 14:37:00 -0700139 blueprint.write(' linux_%s: {\n' % arch)
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700140 blueprint.write(' srcs: [\n')
141 for f in sorted(asm_files):
142 blueprint.write(' "%s",\n' % f)
143 blueprint.write(' ],\n')
144 blueprint.write(' },\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700145 blueprint.write(' },\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700146
Pete Bentley44544d92019-08-15 15:01:26 +0100147 blueprint.write('}\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700148
Pete Bentley44544d92019-08-15 15:01:26 +0100149 def FilterBcmAsm(self, asm, want_bcm):
150 """Filter a list of assembly outputs based on whether they belong in BCM
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700151
Pete Bentley44544d92019-08-15 15:01:26 +0100152 Args:
153 asm: Assembly file lists to filter
154 want_bcm: If true then include BCM files, otherwise do not
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700155
Pete Bentley44544d92019-08-15 15:01:26 +0100156 Returns:
157 A copy of |asm| with files filtered according to |want_bcm|
158 """
159 return [(archinfo, filter(lambda p: ("/crypto/fipsmodule/" in p) == want_bcm, files))
160 for (archinfo, files) in asm]
Adam Langley9e1a6602015-05-05 17:47:53 -0700161
162
David Benjamineca48e52019-08-13 11:51:53 -0400163class AndroidCMake(object):
164
165 def __init__(self):
166 self.header = \
167"""# Copyright (C) 2019 The Android Open Source Project
168#
169# Licensed under the Apache License, Version 2.0 (the "License");
170# you may not use this file except in compliance with the License.
171# You may obtain a copy of the License at
172#
173# http://www.apache.org/licenses/LICENSE-2.0
174#
175# Unless required by applicable law or agreed to in writing, software
176# distributed under the License is distributed on an "AS IS" BASIS,
177# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
178# See the License for the specific language governing permissions and
179# limitations under the License.
180
181# This file is created by generate_build_files.py. Do not edit manually.
182# To specify a custom path prefix, set BORINGSSL_ROOT before including this
183# file, or use list(TRANSFORM ... PREPEND) from CMake 3.12.
184
185"""
186
187 def PrintVariableSection(self, out, name, files):
188 out.write('set(%s\n' % name)
189 for f in sorted(files):
190 # Ideally adding the prefix would be the caller's job, but
191 # list(TRANSFORM ... PREPEND) is only available starting CMake 3.12. When
192 # sources.cmake is the source of truth, we can ask Android to either write
193 # a CMake function or update to 3.12.
194 out.write(' ${BORINGSSL_ROOT}%s\n' % f)
195 out.write(')\n')
196
197 def WriteFiles(self, files, asm_outputs):
198 # The Android emulator uses a custom CMake buildsystem.
199 #
200 # TODO(davidben): Move our various source lists into sources.cmake and have
201 # Android consume that directly.
202 with open('android-sources.cmake', 'w+') as out:
203 out.write(self.header)
204
205 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
206 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
207 self.PrintVariableSection(out, 'tool_sources', files['tool'])
208 self.PrintVariableSection(out, 'test_support_sources',
209 files['test_support'])
210 self.PrintVariableSection(out, 'crypto_test_sources',
211 files['crypto_test'])
212 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
213
214 for ((osname, arch), asm_files) in asm_outputs:
215 self.PrintVariableSection(
216 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
217
218
Adam Langley049ef412015-06-09 18:20:57 -0700219class Bazel(object):
220 """Bazel outputs files suitable for including in Bazel files."""
221
222 def __init__(self):
223 self.firstSection = True
224 self.header = \
225"""# This file is created by generate_build_files.py. Do not edit manually.
226
227"""
228
229 def PrintVariableSection(self, out, name, files):
230 if not self.firstSection:
231 out.write('\n')
232 self.firstSection = False
233
234 out.write('%s = [\n' % name)
235 for f in sorted(files):
Matt Braithwaite16695892016-06-09 09:34:11 -0700236 out.write(' "%s",\n' % PathOf(f))
Adam Langley049ef412015-06-09 18:20:57 -0700237 out.write(']\n')
238
239 def WriteFiles(self, files, asm_outputs):
Chuck Haysc608d6b2015-10-06 17:54:16 -0700240 with open('BUILD.generated.bzl', 'w+') as out:
Adam Langley049ef412015-06-09 18:20:57 -0700241 out.write(self.header)
242
243 self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
Adam Langleyfd499932017-04-04 14:21:43 -0700244 self.PrintVariableSection(out, 'fips_fragments', files['fips_fragments'])
Adam Langley049ef412015-06-09 18:20:57 -0700245 self.PrintVariableSection(
246 out, 'ssl_internal_headers', files['ssl_internal_headers'])
247 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
248 self.PrintVariableSection(out, 'crypto_headers', files['crypto_headers'])
249 self.PrintVariableSection(
250 out, 'crypto_internal_headers', files['crypto_internal_headers'])
251 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
252 self.PrintVariableSection(out, 'tool_sources', files['tool'])
Adam Langleyf11f2332016-06-30 11:56:19 -0700253 self.PrintVariableSection(out, 'tool_headers', files['tool_headers'])
Adam Langley049ef412015-06-09 18:20:57 -0700254
255 for ((osname, arch), asm_files) in asm_outputs:
Adam Langley049ef412015-06-09 18:20:57 -0700256 self.PrintVariableSection(
Piotr Sikora3f5fe602015-10-28 12:24:35 -0700257 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
Adam Langley049ef412015-06-09 18:20:57 -0700258
Chuck Haysc608d6b2015-10-06 17:54:16 -0700259 with open('BUILD.generated_tests.bzl', 'w+') as out:
Adam Langley9c164b22015-06-10 18:54:47 -0700260 out.write(self.header)
261
262 out.write('test_support_sources = [\n')
David Benjaminc5aa8412016-07-29 17:41:58 -0400263 for filename in sorted(files['test_support'] +
264 files['test_support_headers'] +
265 files['crypto_internal_headers'] +
266 files['ssl_internal_headers']):
Adam Langley9c164b22015-06-10 18:54:47 -0700267 if os.path.basename(filename) == 'malloc.cc':
268 continue
Matt Braithwaite16695892016-06-09 09:34:11 -0700269 out.write(' "%s",\n' % PathOf(filename))
Adam Langley9c164b22015-06-10 18:54:47 -0700270
Adam Langley7b6acc52017-07-27 16:33:27 -0700271 out.write(']\n')
Chuck Haysc608d6b2015-10-06 17:54:16 -0700272
David Benjamin96628432017-01-19 19:05:47 -0500273 self.PrintVariableSection(out, 'crypto_test_sources',
274 files['crypto_test'])
275 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
Adam Langley990a3232018-05-22 10:02:59 -0700276 self.PrintVariableSection(out, 'crypto_test_data',
277 files['crypto_test_data'])
Adam Langley3e502c82019-10-16 09:56:38 -0700278 self.PrintVariableSection(out, 'urandom_test_sources',
279 files['urandom_test'])
David Benjamin96628432017-01-19 19:05:47 -0500280
Adam Langley049ef412015-06-09 18:20:57 -0700281
Robert Sloane091af42017-10-09 12:47:17 -0700282class Eureka(object):
283
284 def __init__(self):
285 self.header = \
286"""# Copyright (C) 2017 The Android Open Source Project
287#
288# Licensed under the Apache License, Version 2.0 (the "License");
289# you may not use this file except in compliance with the License.
290# You may obtain a copy of the License at
291#
292# http://www.apache.org/licenses/LICENSE-2.0
293#
294# Unless required by applicable law or agreed to in writing, software
295# distributed under the License is distributed on an "AS IS" BASIS,
296# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
297# See the License for the specific language governing permissions and
298# limitations under the License.
299
300# This file is created by generate_build_files.py. Do not edit manually.
301
302"""
303
304 def PrintVariableSection(self, out, name, files):
305 out.write('%s := \\\n' % name)
306 for f in sorted(files):
307 out.write(' %s\\\n' % f)
308 out.write('\n')
309
310 def WriteFiles(self, files, asm_outputs):
311 # Legacy Android.mk format
312 with open('eureka.mk', 'w+') as makefile:
313 makefile.write(self.header)
314
315 self.PrintVariableSection(makefile, 'crypto_sources', files['crypto'])
316 self.PrintVariableSection(makefile, 'ssl_sources', files['ssl'])
317 self.PrintVariableSection(makefile, 'tool_sources', files['tool'])
318
319 for ((osname, arch), asm_files) in asm_outputs:
320 if osname != 'linux':
321 continue
322 self.PrintVariableSection(
323 makefile, '%s_%s_sources' % (osname, arch), asm_files)
324
325
David Benjamin38d01c62016-04-21 18:47:57 -0400326class GN(object):
327
328 def __init__(self):
329 self.firstSection = True
330 self.header = \
David Benjaminf0518d42022-11-17 12:21:06 -0500331"""# Copyright 2016 The Chromium Authors
David Benjamin38d01c62016-04-21 18:47:57 -0400332# Use of this source code is governed by a BSD-style license that can be
333# found in the LICENSE file.
334
335# This file is created by generate_build_files.py. Do not edit manually.
336
337"""
338
339 def PrintVariableSection(self, out, name, files):
340 if not self.firstSection:
341 out.write('\n')
342 self.firstSection = False
343
344 out.write('%s = [\n' % name)
345 for f in sorted(files):
346 out.write(' "%s",\n' % f)
347 out.write(']\n')
348
349 def WriteFiles(self, files, asm_outputs):
350 with open('BUILD.generated.gni', 'w+') as out:
351 out.write(self.header)
352
David Benjaminc5aa8412016-07-29 17:41:58 -0400353 self.PrintVariableSection(out, 'crypto_sources',
James Robinson98dd68f2018-04-11 14:47:34 -0700354 files['crypto'] +
David Benjaminc5aa8412016-07-29 17:41:58 -0400355 files['crypto_internal_headers'])
James Robinson98dd68f2018-04-11 14:47:34 -0700356 self.PrintVariableSection(out, 'crypto_headers',
357 files['crypto_headers'])
David Benjaminc5aa8412016-07-29 17:41:58 -0400358 self.PrintVariableSection(out, 'ssl_sources',
James Robinson98dd68f2018-04-11 14:47:34 -0700359 files['ssl'] + files['ssl_internal_headers'])
360 self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
David Benjaminbb0cb952020-12-17 16:35:39 -0500361 self.PrintVariableSection(out, 'tool_sources',
362 files['tool'] + files['tool_headers'])
David Benjamin38d01c62016-04-21 18:47:57 -0400363
364 for ((osname, arch), asm_files) in asm_outputs:
365 self.PrintVariableSection(
366 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
367
368 fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0]
369 for fuzzer in files['fuzz']]
370 self.PrintVariableSection(out, 'fuzzers', fuzzers)
371
372 with open('BUILD.generated_tests.gni', 'w+') as out:
373 self.firstSection = True
374 out.write(self.header)
375
David Benjamin96628432017-01-19 19:05:47 -0500376 self.PrintVariableSection(out, 'test_support_sources',
David Benjaminc5aa8412016-07-29 17:41:58 -0400377 files['test_support'] +
378 files['test_support_headers'])
David Benjamin96628432017-01-19 19:05:47 -0500379 self.PrintVariableSection(out, 'crypto_test_sources',
380 files['crypto_test'])
David Benjaminf014d602019-05-07 18:58:06 -0500381 self.PrintVariableSection(out, 'crypto_test_data',
382 files['crypto_test_data'])
David Benjamin96628432017-01-19 19:05:47 -0500383 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
David Benjamin38d01c62016-04-21 18:47:57 -0400384
385
386class GYP(object):
387
388 def __init__(self):
389 self.header = \
David Benjaminf0518d42022-11-17 12:21:06 -0500390"""# Copyright 2016 The Chromium Authors
David Benjamin38d01c62016-04-21 18:47:57 -0400391# Use of this source code is governed by a BSD-style license that can be
392# found in the LICENSE file.
393
394# This file is created by generate_build_files.py. Do not edit manually.
395
396"""
397
398 def PrintVariableSection(self, out, name, files):
399 out.write(' \'%s\': [\n' % name)
400 for f in sorted(files):
401 out.write(' \'%s\',\n' % f)
402 out.write(' ],\n')
403
404 def WriteFiles(self, files, asm_outputs):
405 with open('boringssl.gypi', 'w+') as gypi:
406 gypi.write(self.header + '{\n \'variables\': {\n')
407
David Benjaminc5aa8412016-07-29 17:41:58 -0400408 self.PrintVariableSection(gypi, 'boringssl_ssl_sources',
409 files['ssl'] + files['ssl_headers'] +
410 files['ssl_internal_headers'])
411 self.PrintVariableSection(gypi, 'boringssl_crypto_sources',
412 files['crypto'] + files['crypto_headers'] +
413 files['crypto_internal_headers'])
David Benjamin38d01c62016-04-21 18:47:57 -0400414
415 for ((osname, arch), asm_files) in asm_outputs:
416 self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' %
417 (osname, arch), asm_files)
418
419 gypi.write(' }\n}\n')
420
Adam Langleycfd80a92019-11-08 14:40:08 -0800421class CMake(object):
422
423 def __init__(self):
424 self.header = \
425R'''# Copyright (c) 2019 The Chromium Authors. All rights reserved.
426# Use of this source code is governed by a BSD-style license that can be
427# found in the LICENSE file.
428
429# This file is created by generate_build_files.py. Do not edit manually.
430
David Benjamind0b66c72021-03-22 17:30:02 -0400431cmake_minimum_required(VERSION 3.5)
Adam Langleycfd80a92019-11-08 14:40:08 -0800432
433project(BoringSSL LANGUAGES C CXX)
434
435if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
436 set(CLANG 1)
437endif()
438
439if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
David Benjamin493d5cb2022-04-18 17:20:27 -0400440 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 -0400441 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fno-common -std=c11")
Adam Langleycfd80a92019-11-08 14:40:08 -0800442endif()
443
444# pthread_rwlock_t requires a feature flag.
445if(NOT WIN32)
446 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
447endif()
448
449if(WIN32)
450 add_definitions(-D_HAS_EXCEPTIONS=0)
451 add_definitions(-DWIN32_LEAN_AND_MEAN)
452 add_definitions(-DNOMINMAX)
453 # Allow use of fopen.
454 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
455 # VS 2017 and higher supports STL-only warning suppressions.
456 # A bug in CMake < 3.13.0 may cause the space in this value to
457 # cause issues when building with NASM. In that case, update CMake.
458 add_definitions("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987")
459endif()
460
461add_definitions(-DBORINGSSL_IMPLEMENTATION)
462
Adam Langley89730072020-01-17 08:18:07 -0800463# CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an
464# architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR
465# alone, and expects all architecture-specific logic to be conditioned within
466# the source files rather than the build. This does not work for our assembly
467# files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture
468# builds.
469if(NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES)
470 list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES)
David Benjamin7e265972021-08-04 14:28:55 -0400471 if(NOT NUM_ARCHES EQUAL 1)
Adam Langley89730072020-01-17 08:18:07 -0800472 message(FATAL_ERROR "Universal binaries not supported.")
473 endif()
474 list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR)
475endif()
476
Adam Langleycfd80a92019-11-08 14:40:08 -0800477if(OPENSSL_NO_ASM)
478 add_definitions(-DOPENSSL_NO_ASM)
479 set(ARCH "generic")
David Benjamin7e265972021-08-04 14:28:55 -0400480elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800481 set(ARCH "x86_64")
David Benjamin7e265972021-08-04 14:28:55 -0400482elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800483 set(ARCH "x86_64")
David Benjamin7e265972021-08-04 14:28:55 -0400484elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800485 # cmake reports AMD64 on Windows, but we might be building for 32-bit.
David Benjamin884614c2020-06-16 10:59:58 -0400486 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
Adam Langleycfd80a92019-11-08 14:40:08 -0800487 set(ARCH "x86_64")
488 else()
489 set(ARCH "x86")
490 endif()
David Benjamin7e265972021-08-04 14:28:55 -0400491elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
Adam Langleycfd80a92019-11-08 14:40:08 -0800492 set(ARCH "x86")
David Benjamin7e265972021-08-04 14:28:55 -0400493elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
Adam Langleycfd80a92019-11-08 14:40:08 -0800494 set(ARCH "x86")
David Benjamin7e265972021-08-04 14:28:55 -0400495elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686")
Adam Langleycfd80a92019-11-08 14:40:08 -0800496 set(ARCH "x86")
David Benjamin7e265972021-08-04 14:28:55 -0400497elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800498 set(ARCH "aarch64")
David Benjamin7e265972021-08-04 14:28:55 -0400499elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800500 set(ARCH "aarch64")
501# Apple A12 Bionic chipset which is added in iPhone XS/XS Max/XR uses arm64e architecture.
David Benjamin7e265972021-08-04 14:28:55 -0400502elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64e")
Adam Langleycfd80a92019-11-08 14:40:08 -0800503 set(ARCH "aarch64")
David Benjamin7e265972021-08-04 14:28:55 -0400504elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm*")
Adam Langleycfd80a92019-11-08 14:40:08 -0800505 set(ARCH "arm")
David Benjamin7e265972021-08-04 14:28:55 -0400506elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "mips")
Adam Langleycfd80a92019-11-08 14:40:08 -0800507 # Just to avoid the “unknown processor” error.
508 set(ARCH "generic")
David Benjamin7e265972021-08-04 14:28:55 -0400509elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le")
Adam Langleycfd80a92019-11-08 14:40:08 -0800510 set(ARCH "ppc64le")
511else()
512 message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
513endif()
514
515if(NOT OPENSSL_NO_ASM)
516 if(UNIX)
517 enable_language(ASM)
518
519 # Clang's integerated assembler does not support debug symbols.
520 if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang")
521 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g")
522 endif()
523
524 # CMake does not add -isysroot and -arch flags to assembly.
525 if(APPLE)
526 if(CMAKE_OSX_SYSROOT)
527 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"")
528 endif()
529 foreach(arch ${CMAKE_OSX_ARCHITECTURES})
530 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}")
531 endforeach()
532 endif()
533 else()
534 set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8")
535 enable_language(ASM_NASM)
536 endif()
537endif()
538
Adam Langleya0cdbf92020-01-21 09:07:46 -0800539if(BUILD_SHARED_LIBS)
540 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
541 # Enable position-independent code globally. This is needed because
542 # some library targets are OBJECT libraries.
543 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
544endif()
545
Adam Langleycfd80a92019-11-08 14:40:08 -0800546include_directories(src/include)
547
548'''
549
550 def PrintLibrary(self, out, name, files):
551 out.write('add_library(\n')
552 out.write(' %s\n\n' % name)
553
554 for f in sorted(files):
555 out.write(' %s\n' % PathOf(f))
556
557 out.write(')\n\n')
558
559 def PrintExe(self, out, name, files, libs):
560 out.write('add_executable(\n')
561 out.write(' %s\n\n' % name)
562
563 for f in sorted(files):
564 out.write(' %s\n' % PathOf(f))
565
566 out.write(')\n\n')
567 out.write('target_link_libraries(%s %s)\n\n' % (name, ' '.join(libs)))
568
569 def PrintSection(self, out, name, files):
570 out.write('set(\n')
571 out.write(' %s\n\n' % name)
572 for f in sorted(files):
573 out.write(' %s\n' % PathOf(f))
574 out.write(')\n\n')
575
576 def WriteFiles(self, files, asm_outputs):
577 with open('CMakeLists.txt', 'w+') as cmake:
578 cmake.write(self.header)
579
580 for ((osname, arch), asm_files) in asm_outputs:
581 self.PrintSection(cmake, 'CRYPTO_%s_%s_SOURCES' % (osname, arch),
582 asm_files)
583
584 cmake.write(
David Benjamin68addd22022-02-08 00:25:34 -0500585R'''if(APPLE)
David Benjamin351b2f82022-02-06 12:57:17 -0500586 set(CRYPTO_ARCH_SOURCES ${CRYPTO_apple_${ARCH}_SOURCES})
Adam Langleycfd80a92019-11-08 14:40:08 -0800587elseif(UNIX)
588 set(CRYPTO_ARCH_SOURCES ${CRYPTO_linux_${ARCH}_SOURCES})
589elseif(WIN32)
590 set(CRYPTO_ARCH_SOURCES ${CRYPTO_win_${ARCH}_SOURCES})
591endif()
592
593''')
594
595 self.PrintLibrary(cmake, 'crypto',
596 files['crypto'] + ['${CRYPTO_ARCH_SOURCES}'])
597 self.PrintLibrary(cmake, 'ssl', files['ssl'])
Adam Langleyff631132020-01-13 15:24:22 -0800598 self.PrintExe(cmake, 'bssl', files['tool'], ['ssl', 'crypto'])
599
600 cmake.write(
David Benjamin8f88b272020-07-09 13:35:01 -0400601R'''if(NOT WIN32 AND NOT ANDROID)
Adam Langleyff631132020-01-13 15:24:22 -0800602 target_link_libraries(crypto pthread)
603endif()
604
David Benjamin8f88b272020-07-09 13:35:01 -0400605if(WIN32)
606 target_link_libraries(bssl ws2_32)
607endif()
608
Adam Langleyff631132020-01-13 15:24:22 -0800609''')
David Benjamin38d01c62016-04-21 18:47:57 -0400610
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400611class JSON(object):
612 def WriteFiles(self, files, asm_outputs):
613 sources = dict(files)
614 for ((osname, arch), asm_files) in asm_outputs:
615 sources['crypto_%s_%s' % (osname, arch)] = asm_files
616 with open('sources.json', 'w+') as f:
617 json.dump(sources, f, sort_keys=True, indent=2)
618
Adam Langley9e1a6602015-05-05 17:47:53 -0700619def FindCMakeFiles(directory):
620 """Returns list of all CMakeLists.txt files recursively in directory."""
621 cmakefiles = []
622
623 for (path, _, filenames) in os.walk(directory):
624 for filename in filenames:
625 if filename == 'CMakeLists.txt':
626 cmakefiles.append(os.path.join(path, filename))
627
628 return cmakefiles
629
Adam Langleyfd499932017-04-04 14:21:43 -0700630def OnlyFIPSFragments(path, dent, is_dir):
Matthew Braithwaite95511e92017-05-08 16:38:03 -0700631 return is_dir or (path.startswith(
632 os.path.join('src', 'crypto', 'fipsmodule', '')) and
633 NoTests(path, dent, is_dir))
Adam Langley9e1a6602015-05-05 17:47:53 -0700634
Adam Langleyfd499932017-04-04 14:21:43 -0700635def NoTestsNorFIPSFragments(path, dent, is_dir):
Adam Langley323f1eb2017-04-06 17:29:10 -0700636 return (NoTests(path, dent, is_dir) and
637 (is_dir or not OnlyFIPSFragments(path, dent, is_dir)))
Adam Langleyfd499932017-04-04 14:21:43 -0700638
639def NoTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700640 """Filter function that can be passed to FindCFiles in order to remove test
641 sources."""
642 if is_dir:
643 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400644 return 'test.' not in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700645
646
Adam Langleyfd499932017-04-04 14:21:43 -0700647def OnlyTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700648 """Filter function that can be passed to FindCFiles in order to remove
649 non-test sources."""
650 if is_dir:
David Benjamin26073832015-05-11 20:52:48 -0400651 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400652 return '_test.' in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700653
654
Adam Langleyfd499932017-04-04 14:21:43 -0700655def AllFiles(path, dent, is_dir):
David Benjamin26073832015-05-11 20:52:48 -0400656 """Filter function that can be passed to FindCFiles in order to include all
657 sources."""
658 return True
659
660
Adam Langleyfd499932017-04-04 14:21:43 -0700661def NoTestRunnerFiles(path, dent, is_dir):
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700662 """Filter function that can be passed to FindCFiles or FindHeaderFiles in
663 order to exclude test runner files."""
664 # NOTE(martinkr): This prevents .h/.cc files in src/ssl/test/runner, which
665 # are in their own subpackage, from being included in boringssl/BUILD files.
666 return not is_dir or dent != 'runner'
667
668
David Benjamin3ecd0a52017-05-19 15:26:18 -0400669def NotGTestSupport(path, dent, is_dir):
David Benjaminc3889632019-03-01 15:03:05 -0500670 return 'gtest' not in dent and 'abi_test' not in dent
David Benjamin96628432017-01-19 19:05:47 -0500671
672
Adam Langleyfd499932017-04-04 14:21:43 -0700673def SSLHeaderFiles(path, dent, is_dir):
Aaron Green0e150022018-10-16 12:05:29 -0700674 return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h', 'srtp.h']
Adam Langley049ef412015-06-09 18:20:57 -0700675
676
Adam Langley9e1a6602015-05-05 17:47:53 -0700677def FindCFiles(directory, filter_func):
678 """Recurses through directory and returns a list of paths to all the C source
679 files that pass filter_func."""
680 cfiles = []
681
682 for (path, dirnames, filenames) in os.walk(directory):
683 for filename in filenames:
684 if not filename.endswith('.c') and not filename.endswith('.cc'):
685 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700686 if not filter_func(path, filename, False):
Adam Langley9e1a6602015-05-05 17:47:53 -0700687 continue
688 cfiles.append(os.path.join(path, filename))
689
690 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700691 if not filter_func(path, dirname, True):
Adam Langley9e1a6602015-05-05 17:47:53 -0700692 del dirnames[i]
693
David Benjaminedd4c5f2020-08-19 14:46:17 -0400694 cfiles.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700695 return cfiles
696
697
Adam Langley049ef412015-06-09 18:20:57 -0700698def FindHeaderFiles(directory, filter_func):
699 """Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
700 hfiles = []
701
702 for (path, dirnames, filenames) in os.walk(directory):
703 for filename in filenames:
704 if not filename.endswith('.h'):
705 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700706 if not filter_func(path, filename, False):
Adam Langley049ef412015-06-09 18:20:57 -0700707 continue
708 hfiles.append(os.path.join(path, filename))
709
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700710 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700711 if not filter_func(path, dirname, True):
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700712 del dirnames[i]
713
David Benjaminedd4c5f2020-08-19 14:46:17 -0400714 hfiles.sort()
Adam Langley049ef412015-06-09 18:20:57 -0700715 return hfiles
716
717
Adam Langley9e1a6602015-05-05 17:47:53 -0700718def ExtractPerlAsmFromCMakeFile(cmakefile):
719 """Parses the contents of the CMakeLists.txt file passed as an argument and
720 returns a list of all the perlasm() directives found in the file."""
721 perlasms = []
722 with open(cmakefile) as f:
723 for line in f:
724 line = line.strip()
725 if not line.startswith('perlasm('):
726 continue
727 if not line.endswith(')'):
728 raise ValueError('Bad perlasm line in %s' % cmakefile)
729 # Remove "perlasm(" from start and ")" from end
730 params = line[8:-1].split()
731 if len(params) < 2:
732 raise ValueError('Bad perlasm line in %s' % cmakefile)
733 perlasms.append({
734 'extra_args': params[2:],
735 'input': os.path.join(os.path.dirname(cmakefile), params[1]),
736 'output': os.path.join(os.path.dirname(cmakefile), params[0]),
737 })
738
739 return perlasms
740
741
742def ReadPerlAsmOperations():
743 """Returns a list of all perlasm() directives found in CMake config files in
744 src/."""
745 perlasms = []
746 cmakefiles = FindCMakeFiles('src')
747
748 for cmakefile in cmakefiles:
749 perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile))
750
751 return perlasms
752
753
754def PerlAsm(output_filename, input_filename, perlasm_style, extra_args):
755 """Runs the a perlasm script and puts the output into output_filename."""
756 base_dir = os.path.dirname(output_filename)
757 if not os.path.isdir(base_dir):
758 os.makedirs(base_dir)
David Benjaminfdd8e9c2016-06-26 13:18:50 -0400759 subprocess.check_call(
760 ['perl', input_filename, perlasm_style] + extra_args + [output_filename])
Adam Langley9e1a6602015-05-05 17:47:53 -0700761
762
763def ArchForAsmFilename(filename):
764 """Returns the architectures that a given asm file should be compiled for
765 based on substrings in the filename."""
766
767 if 'x86_64' in filename or 'avx2' in filename:
768 return ['x86_64']
769 elif ('x86' in filename and 'x86_64' not in filename) or '586' in filename:
770 return ['x86']
771 elif 'armx' in filename:
772 return ['arm', 'aarch64']
773 elif 'armv8' in filename:
774 return ['aarch64']
775 elif 'arm' in filename:
776 return ['arm']
David Benjamin9f16ce12016-09-27 16:30:22 -0400777 elif 'ppc' in filename:
778 return ['ppc64le']
Adam Langley9e1a6602015-05-05 17:47:53 -0700779 else:
780 raise ValueError('Unknown arch for asm filename: ' + filename)
781
782
783def WriteAsmFiles(perlasms):
784 """Generates asm files from perlasm directives for each supported OS x
785 platform combination."""
786 asmfiles = {}
787
788 for osarch in OS_ARCH_COMBOS:
789 (osname, arch, perlasm_style, extra_args, asm_ext) = osarch
790 key = (osname, arch)
791 outDir = '%s-%s' % key
792
793 for perlasm in perlasms:
794 filename = os.path.basename(perlasm['input'])
795 output = perlasm['output']
796 if not output.startswith('src'):
797 raise ValueError('output missing src: %s' % output)
798 output = os.path.join(outDir, output[4:])
William Hessec618c402015-06-22 16:34:02 +0200799 if output.endswith('-armx.${ASM_EXT}'):
800 output = output.replace('-armx',
801 '-armx64' if arch == 'aarch64' else '-armx32')
Adam Langley9e1a6602015-05-05 17:47:53 -0700802 output = output.replace('${ASM_EXT}', asm_ext)
803
804 if arch in ArchForAsmFilename(filename):
805 PerlAsm(output, perlasm['input'], perlasm_style,
806 perlasm['extra_args'] + extra_args)
807 asmfiles.setdefault(key, []).append(output)
808
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000809 for (key, non_perl_asm_files) in NON_PERL_FILES.items():
Adam Langley9e1a6602015-05-05 17:47:53 -0700810 asmfiles.setdefault(key, []).extend(non_perl_asm_files)
811
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000812 for files in asmfiles.values():
David Benjaminedd4c5f2020-08-19 14:46:17 -0400813 files.sort()
814
Adam Langley9e1a6602015-05-05 17:47:53 -0700815 return asmfiles
816
817
David Benjamin3ecd0a52017-05-19 15:26:18 -0400818def ExtractVariablesFromCMakeFile(cmakefile):
819 """Parses the contents of the CMakeLists.txt file passed as an argument and
820 returns a dictionary of exported source lists."""
821 variables = {}
822 in_set_command = False
823 set_command = []
824 with open(cmakefile) as f:
825 for line in f:
826 if '#' in line:
827 line = line[:line.index('#')]
828 line = line.strip()
829
830 if not in_set_command:
831 if line.startswith('set('):
832 in_set_command = True
833 set_command = []
834 elif line == ')':
835 in_set_command = False
836 if not set_command:
837 raise ValueError('Empty set command')
838 variables[set_command[0]] = set_command[1:]
839 else:
840 set_command.extend([c for c in line.split(' ') if c])
841
842 if in_set_command:
843 raise ValueError('Unfinished set command')
844 return variables
845
846
Adam Langley049ef412015-06-09 18:20:57 -0700847def main(platforms):
David Benjamin3ecd0a52017-05-19 15:26:18 -0400848 cmake = ExtractVariablesFromCMakeFile(os.path.join('src', 'sources.cmake'))
Andres Erbsen5b280a82017-10-30 15:58:33 +0000849 crypto_c_files = (FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments) +
Adam Langley7f028812019-10-18 14:48:11 -0700850 FindCFiles(os.path.join('src', 'third_party', 'fiat'), NoTestsNorFIPSFragments))
Adam Langleyfd499932017-04-04 14:21:43 -0700851 fips_fragments = FindCFiles(os.path.join('src', 'crypto', 'fipsmodule'), OnlyFIPSFragments)
Adam Langleyfeca9e52017-01-23 13:07:50 -0800852 ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
David Benjamin38d01c62016-04-21 18:47:57 -0400853 tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
Adam Langleyf11f2332016-06-30 11:56:19 -0700854 tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles)
Adam Langley9e1a6602015-05-05 17:47:53 -0700855
Pete Bentley44544d92019-08-15 15:01:26 +0100856 # BCM shared library C files
857 bcm_crypto_c_files = [
858 os.path.join('src', 'crypto', 'fipsmodule', 'bcm.c')
859 ]
860
Adam Langley9e1a6602015-05-05 17:47:53 -0700861 # Generate err_data.c
862 with open('err_data.c', 'w+') as err_data:
863 subprocess.check_call(['go', 'run', 'err_data_generate.go'],
864 cwd=os.path.join('src', 'crypto', 'err'),
865 stdout=err_data)
866 crypto_c_files.append('err_data.c')
David Benjaminedd4c5f2020-08-19 14:46:17 -0400867 crypto_c_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700868
David Benjamin38d01c62016-04-21 18:47:57 -0400869 test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
David Benjamin3ecd0a52017-05-19 15:26:18 -0400870 NotGTestSupport)
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700871 test_support_h_files = (
872 FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) +
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700873 FindHeaderFiles(os.path.join('src', 'ssl', 'test'), NoTestRunnerFiles))
David Benjamin26073832015-05-11 20:52:48 -0400874
Adam Langley990a3232018-05-22 10:02:59 -0700875 crypto_test_files = []
876 if EMBED_TEST_DATA:
877 # Generate crypto_test_data.cc
878 with open('crypto_test_data.cc', 'w+') as out:
879 subprocess.check_call(
880 ['go', 'run', 'util/embed_test_data.go'] + cmake['CRYPTO_TEST_DATA'],
881 cwd='src',
882 stdout=out)
883 crypto_test_files += ['crypto_test_data.cc']
David Benjamin3ecd0a52017-05-19 15:26:18 -0400884
Adam Langley990a3232018-05-22 10:02:59 -0700885 crypto_test_files += FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
David Benjamin96ee4a82017-07-09 23:46:47 -0400886 crypto_test_files += [
David Benjaminc3889632019-03-01 15:03:05 -0500887 'src/crypto/test/abi_test.cc',
David Benjamin3ecd0a52017-05-19 15:26:18 -0400888 'src/crypto/test/file_test_gtest.cc',
889 'src/crypto/test/gtest_main.cc',
890 ]
Adam Langley3e502c82019-10-16 09:56:38 -0700891 # urandom_test.cc is in a separate binary so that it can be test PRNG
892 # initialisation.
893 crypto_test_files = [
894 file for file in crypto_test_files
895 if not file.endswith('/urandom_test.cc')
896 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400897 crypto_test_files.sort()
David Benjamin1d5a5702017-02-13 22:11:49 -0500898
899 ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
Robert Sloanae1e0872019-03-01 16:01:30 -0800900 ssl_test_files += [
901 'src/crypto/test/abi_test.cc',
902 'src/crypto/test/gtest_main.cc',
903 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400904 ssl_test_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700905
Adam Langley3e502c82019-10-16 09:56:38 -0700906 urandom_test_files = [
907 'src/crypto/fipsmodule/rand/urandom_test.cc',
908 ]
909
David Benjamin38d01c62016-04-21 18:47:57 -0400910 fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
911
David Benjaminedd4c5f2020-08-19 14:46:17 -0400912 ssl_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
913 SSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700914
Adam Langleyfd499932017-04-04 14:21:43 -0700915 def NotSSLHeaderFiles(path, filename, is_dir):
916 return not SSLHeaderFiles(path, filename, is_dir)
David Benjaminedd4c5f2020-08-19 14:46:17 -0400917 crypto_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
918 NotSSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700919
920 ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
Andres Erbsen5b280a82017-10-30 15:58:33 +0000921 crypto_internal_h_files = (
922 FindHeaderFiles(os.path.join('src', 'crypto'), NoTests) +
Adam Langley7f028812019-10-18 14:48:11 -0700923 FindHeaderFiles(os.path.join('src', 'third_party', 'fiat'), NoTests))
Adam Langley049ef412015-06-09 18:20:57 -0700924
Adam Langley9e1a6602015-05-05 17:47:53 -0700925 files = {
Pete Bentley44544d92019-08-15 15:01:26 +0100926 'bcm_crypto': bcm_crypto_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700927 'crypto': crypto_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700928 'crypto_headers': crypto_h_files,
929 'crypto_internal_headers': crypto_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400930 'crypto_test': crypto_test_files,
Adam Langley990a3232018-05-22 10:02:59 -0700931 'crypto_test_data': sorted('src/' + x for x in cmake['CRYPTO_TEST_DATA']),
Adam Langleyfd499932017-04-04 14:21:43 -0700932 'fips_fragments': fips_fragments,
David Benjamin38d01c62016-04-21 18:47:57 -0400933 'fuzz': fuzz_c_files,
Adam Langleyfeca9e52017-01-23 13:07:50 -0800934 'ssl': ssl_source_files,
Adam Langley049ef412015-06-09 18:20:57 -0700935 'ssl_headers': ssl_h_files,
936 'ssl_internal_headers': ssl_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400937 'ssl_test': ssl_test_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400938 'tool': tool_c_files,
Adam Langleyf11f2332016-06-30 11:56:19 -0700939 'tool_headers': tool_h_files,
David Benjaminc5aa8412016-07-29 17:41:58 -0400940 'test_support': test_support_c_files,
941 'test_support_headers': test_support_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400942 'urandom_test': urandom_test_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700943 }
944
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000945 asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).items())
Adam Langley9e1a6602015-05-05 17:47:53 -0700946
Adam Langley049ef412015-06-09 18:20:57 -0700947 for platform in platforms:
948 platform.WriteFiles(files, asm_outputs)
Adam Langley9e1a6602015-05-05 17:47:53 -0700949
950 return 0
951
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400952ALL_PLATFORMS = {
953 'android': Android,
954 'android-cmake': AndroidCMake,
955 'bazel': Bazel,
956 'cmake': CMake,
957 'eureka': Eureka,
958 'gn': GN,
959 'gyp': GYP,
960 'json': JSON,
961}
Adam Langley9e1a6602015-05-05 17:47:53 -0700962
Adam Langley9e1a6602015-05-05 17:47:53 -0700963if __name__ == '__main__':
David Benjamin4acc7dd2022-11-19 10:13:49 -0500964 parser = optparse.OptionParser(
965 usage='Usage: %%prog [--prefix=<path>] [all|%s]' %
966 '|'.join(sorted(ALL_PLATFORMS.keys())))
Matt Braithwaite16695892016-06-09 09:34:11 -0700967 parser.add_option('--prefix', dest='prefix',
968 help='For Bazel, prepend argument to all source files')
Adam Langley990a3232018-05-22 10:02:59 -0700969 parser.add_option(
970 '--embed_test_data', type='choice', dest='embed_test_data',
971 action='store', default="true", choices=["true", "false"],
David Benjaminf014d602019-05-07 18:58:06 -0500972 help='For Bazel or GN, don\'t embed data files in crypto_test_data.cc')
Matt Braithwaite16695892016-06-09 09:34:11 -0700973 options, args = parser.parse_args(sys.argv[1:])
974 PREFIX = options.prefix
Adam Langley990a3232018-05-22 10:02:59 -0700975 EMBED_TEST_DATA = (options.embed_test_data == "true")
Matt Braithwaite16695892016-06-09 09:34:11 -0700976
977 if not args:
978 parser.print_help()
979 sys.exit(1)
Adam Langley9e1a6602015-05-05 17:47:53 -0700980
David Benjamin4acc7dd2022-11-19 10:13:49 -0500981 if 'all' in args:
982 platforms = [platform() for platform in ALL_PLATFORMS.values()]
983 else:
984 platforms = []
985 for s in args:
986 platform = ALL_PLATFORMS.get(s)
987 if platform is None:
988 parser.print_help()
989 sys.exit(1)
990 platforms.append(platform())
Adam Langley9e1a6602015-05-05 17:47:53 -0700991
Adam Langley049ef412015-06-09 18:20:57 -0700992 sys.exit(main(platforms))