blob: 1cc8af37eb31b13942439cae4aa81a4148d668c4 [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 Benjaminf6584e72017-06-08 16:27:16 -040029 ('ios', 'arm', 'ios32', [], 'S'),
30 ('ios', 'aarch64', 'ios64', [], 'S'),
Adam Langley9e1a6602015-05-05 17:47:53 -070031 ('linux', 'arm', 'linux32', [], 'S'),
32 ('linux', 'aarch64', 'linux64', [], 'S'),
Adam Langley7c075b92017-05-22 15:31:13 -070033 ('linux', 'ppc64le', 'linux64le', [], 'S'),
Adam Langley9e1a6602015-05-05 17:47:53 -070034 ('linux', 'x86', 'elf', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'),
35 ('linux', 'x86_64', 'elf', [], 'S'),
36 ('mac', 'x86', 'macosx', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'),
37 ('mac', 'x86_64', 'macosx', [], 'S'),
38 ('win', 'x86', 'win32n', ['-DOPENSSL_IA32_SSE2'], 'asm'),
39 ('win', 'x86_64', 'nasm', [], 'asm'),
40]
41
42# NON_PERL_FILES enumerates assembly files that are not processed by the
43# perlasm system.
44NON_PERL_FILES = {
45 ('linux', 'arm'): [
Adam Langley7b8b9c12016-01-04 07:13:00 -080046 'src/crypto/curve25519/asm/x25519-asm-arm.S',
David Benjamin3c4a5cb2016-03-29 17:43:31 -040047 'src/crypto/poly1305/poly1305_arm_asm.S',
Adam Langley7b935932018-11-12 13:53:42 -080048 ],
49 ('linux', 'x86_64'): [
50 'src/crypto/hrss/asm/poly_rq_mul.S',
Adam Langley9e1a6602015-05-05 17:47:53 -070051 ],
52}
53
Matt Braithwaite16695892016-06-09 09:34:11 -070054PREFIX = None
Adam Langley990a3232018-05-22 10:02:59 -070055EMBED_TEST_DATA = True
Matt Braithwaite16695892016-06-09 09:34:11 -070056
57
58def PathOf(x):
59 return x if not PREFIX else os.path.join(PREFIX, x)
60
Adam Langley9e1a6602015-05-05 17:47:53 -070061
Adam Langley9e1a6602015-05-05 17:47:53 -070062class Android(object):
63
64 def __init__(self):
65 self.header = \
66"""# Copyright (C) 2015 The Android Open Source Project
67#
68# Licensed under the Apache License, Version 2.0 (the "License");
69# you may not use this file except in compliance with the License.
70# You may obtain a copy of the License at
71#
72# http://www.apache.org/licenses/LICENSE-2.0
73#
74# Unless required by applicable law or agreed to in writing, software
75# distributed under the License is distributed on an "AS IS" BASIS,
76# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
77# See the License for the specific language governing permissions and
78# limitations under the License.
79
Dan Willemsenb57e4fc2016-07-21 11:08:44 -070080# This file is created by generate_build_files.py. Do not edit manually.
Adam Langley9e1a6602015-05-05 17:47:53 -070081"""
82
83 def PrintVariableSection(self, out, name, files):
84 out.write('%s := \\\n' % name)
85 for f in sorted(files):
86 out.write(' %s\\\n' % f)
87 out.write('\n')
88
89 def WriteFiles(self, files, asm_outputs):
Dan Willemsenb57e4fc2016-07-21 11:08:44 -070090 # New Android.bp format
91 with open('sources.bp', 'w+') as blueprint:
92 blueprint.write(self.header.replace('#', '//'))
93
Pete Bentley44544d92019-08-15 15:01:26 +010094 # Separate out BCM files to allow different compilation rules (specific to Android FIPS)
95 bcm_c_files = files['bcm_crypto']
96 non_bcm_c_files = [file for file in files['crypto'] if file not in bcm_c_files]
97 non_bcm_asm = self.FilterBcmAsm(asm_outputs, False)
98 bcm_asm = self.FilterBcmAsm(asm_outputs, True)
Dan Willemsenb57e4fc2016-07-21 11:08:44 -070099
Pete Bentley44544d92019-08-15 15:01:26 +0100100 self.PrintDefaults(blueprint, 'libcrypto_sources', non_bcm_c_files, non_bcm_asm)
101 self.PrintDefaults(blueprint, 'libcrypto_bcm_sources', bcm_c_files, bcm_asm)
102 self.PrintDefaults(blueprint, 'libssl_sources', files['ssl'])
103 self.PrintDefaults(blueprint, 'bssl_sources', files['tool'])
104 self.PrintDefaults(blueprint, 'boringssl_test_support_sources', files['test_support'])
105 self.PrintDefaults(blueprint, 'boringssl_crypto_test_sources', files['crypto_test'])
106 self.PrintDefaults(blueprint, 'boringssl_ssl_test_sources', files['ssl_test'])
107
108 # Legacy Android.mk format, only used by Trusty in new branches
109 with open('sources.mk', 'w+') as makefile:
110 makefile.write(self.header)
111 makefile.write('\n')
112 self.PrintVariableSection(makefile, 'crypto_sources', files['crypto'])
113
114 for ((osname, arch), asm_files) in asm_outputs:
115 if osname != 'linux':
116 continue
117 self.PrintVariableSection(
118 makefile, '%s_%s_sources' % (osname, arch), asm_files)
119
120 def PrintDefaults(self, blueprint, name, files, asm_outputs={}):
121 """Print a cc_defaults section from a list of C files and optionally assembly outputs"""
122 blueprint.write('\n')
123 blueprint.write('cc_defaults {\n')
124 blueprint.write(' name: "%s",\n' % name)
125 blueprint.write(' srcs: [\n')
126 for f in sorted(files):
127 blueprint.write(' "%s",\n' % f)
128 blueprint.write(' ],\n')
129
130 if asm_outputs:
131 blueprint.write(' target: {\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700132 for ((osname, arch), asm_files) in asm_outputs:
Steven Valdez93d242b2016-10-06 13:49:01 -0400133 if osname != 'linux' or arch == 'ppc64le':
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700134 continue
135 if arch == 'aarch64':
136 arch = 'arm64'
137
Dan Willemsen2eb4bc52017-10-16 14:37:00 -0700138 blueprint.write(' linux_%s: {\n' % arch)
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700139 blueprint.write(' srcs: [\n')
140 for f in sorted(asm_files):
141 blueprint.write(' "%s",\n' % f)
142 blueprint.write(' ],\n')
143 blueprint.write(' },\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700144 blueprint.write(' },\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700145
Pete Bentley44544d92019-08-15 15:01:26 +0100146 blueprint.write('}\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700147
Pete Bentley44544d92019-08-15 15:01:26 +0100148 def FilterBcmAsm(self, asm, want_bcm):
149 """Filter a list of assembly outputs based on whether they belong in BCM
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700150
Pete Bentley44544d92019-08-15 15:01:26 +0100151 Args:
152 asm: Assembly file lists to filter
153 want_bcm: If true then include BCM files, otherwise do not
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700154
Pete Bentley44544d92019-08-15 15:01:26 +0100155 Returns:
156 A copy of |asm| with files filtered according to |want_bcm|
157 """
158 return [(archinfo, filter(lambda p: ("/crypto/fipsmodule/" in p) == want_bcm, files))
159 for (archinfo, files) in asm]
Adam Langley9e1a6602015-05-05 17:47:53 -0700160
161
David Benjamineca48e52019-08-13 11:51:53 -0400162class AndroidCMake(object):
163
164 def __init__(self):
165 self.header = \
166"""# Copyright (C) 2019 The Android Open Source Project
167#
168# Licensed under the Apache License, Version 2.0 (the "License");
169# you may not use this file except in compliance with the License.
170# You may obtain a copy of the License at
171#
172# http://www.apache.org/licenses/LICENSE-2.0
173#
174# Unless required by applicable law or agreed to in writing, software
175# distributed under the License is distributed on an "AS IS" BASIS,
176# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
177# See the License for the specific language governing permissions and
178# limitations under the License.
179
180# This file is created by generate_build_files.py. Do not edit manually.
181# To specify a custom path prefix, set BORINGSSL_ROOT before including this
182# file, or use list(TRANSFORM ... PREPEND) from CMake 3.12.
183
184"""
185
186 def PrintVariableSection(self, out, name, files):
187 out.write('set(%s\n' % name)
188 for f in sorted(files):
189 # Ideally adding the prefix would be the caller's job, but
190 # list(TRANSFORM ... PREPEND) is only available starting CMake 3.12. When
191 # sources.cmake is the source of truth, we can ask Android to either write
192 # a CMake function or update to 3.12.
193 out.write(' ${BORINGSSL_ROOT}%s\n' % f)
194 out.write(')\n')
195
196 def WriteFiles(self, files, asm_outputs):
197 # The Android emulator uses a custom CMake buildsystem.
198 #
199 # TODO(davidben): Move our various source lists into sources.cmake and have
200 # Android consume that directly.
201 with open('android-sources.cmake', 'w+') as out:
202 out.write(self.header)
203
204 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
205 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
206 self.PrintVariableSection(out, 'tool_sources', files['tool'])
207 self.PrintVariableSection(out, 'test_support_sources',
208 files['test_support'])
209 self.PrintVariableSection(out, 'crypto_test_sources',
210 files['crypto_test'])
211 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
212
213 for ((osname, arch), asm_files) in asm_outputs:
214 self.PrintVariableSection(
215 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
216
217
Adam Langley049ef412015-06-09 18:20:57 -0700218class Bazel(object):
219 """Bazel outputs files suitable for including in Bazel files."""
220
221 def __init__(self):
222 self.firstSection = True
223 self.header = \
224"""# This file is created by generate_build_files.py. Do not edit manually.
225
226"""
227
228 def PrintVariableSection(self, out, name, files):
229 if not self.firstSection:
230 out.write('\n')
231 self.firstSection = False
232
233 out.write('%s = [\n' % name)
234 for f in sorted(files):
Matt Braithwaite16695892016-06-09 09:34:11 -0700235 out.write(' "%s",\n' % PathOf(f))
Adam Langley049ef412015-06-09 18:20:57 -0700236 out.write(']\n')
237
238 def WriteFiles(self, files, asm_outputs):
Chuck Haysc608d6b2015-10-06 17:54:16 -0700239 with open('BUILD.generated.bzl', 'w+') as out:
Adam Langley049ef412015-06-09 18:20:57 -0700240 out.write(self.header)
241
242 self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
Adam Langleyfd499932017-04-04 14:21:43 -0700243 self.PrintVariableSection(out, 'fips_fragments', files['fips_fragments'])
Adam Langley049ef412015-06-09 18:20:57 -0700244 self.PrintVariableSection(
245 out, 'ssl_internal_headers', files['ssl_internal_headers'])
246 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
247 self.PrintVariableSection(out, 'crypto_headers', files['crypto_headers'])
248 self.PrintVariableSection(
249 out, 'crypto_internal_headers', files['crypto_internal_headers'])
250 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
251 self.PrintVariableSection(out, 'tool_sources', files['tool'])
Adam Langleyf11f2332016-06-30 11:56:19 -0700252 self.PrintVariableSection(out, 'tool_headers', files['tool_headers'])
Adam Langley049ef412015-06-09 18:20:57 -0700253
254 for ((osname, arch), asm_files) in asm_outputs:
Adam Langley049ef412015-06-09 18:20:57 -0700255 self.PrintVariableSection(
Piotr Sikora3f5fe602015-10-28 12:24:35 -0700256 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
Adam Langley049ef412015-06-09 18:20:57 -0700257
Chuck Haysc608d6b2015-10-06 17:54:16 -0700258 with open('BUILD.generated_tests.bzl', 'w+') as out:
Adam Langley9c164b22015-06-10 18:54:47 -0700259 out.write(self.header)
260
261 out.write('test_support_sources = [\n')
David Benjaminc5aa8412016-07-29 17:41:58 -0400262 for filename in sorted(files['test_support'] +
263 files['test_support_headers'] +
264 files['crypto_internal_headers'] +
265 files['ssl_internal_headers']):
Adam Langley9c164b22015-06-10 18:54:47 -0700266 if os.path.basename(filename) == 'malloc.cc':
267 continue
Matt Braithwaite16695892016-06-09 09:34:11 -0700268 out.write(' "%s",\n' % PathOf(filename))
Adam Langley9c164b22015-06-10 18:54:47 -0700269
Adam Langley7b6acc52017-07-27 16:33:27 -0700270 out.write(']\n')
Chuck Haysc608d6b2015-10-06 17:54:16 -0700271
David Benjamin96628432017-01-19 19:05:47 -0500272 self.PrintVariableSection(out, 'crypto_test_sources',
273 files['crypto_test'])
274 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
Adam Langley990a3232018-05-22 10:02:59 -0700275 self.PrintVariableSection(out, 'crypto_test_data',
276 files['crypto_test_data'])
Adam Langley3e502c82019-10-16 09:56:38 -0700277 self.PrintVariableSection(out, 'urandom_test_sources',
278 files['urandom_test'])
David Benjamin96628432017-01-19 19:05:47 -0500279
Adam Langley049ef412015-06-09 18:20:57 -0700280
Robert Sloane091af42017-10-09 12:47:17 -0700281class Eureka(object):
282
283 def __init__(self):
284 self.header = \
285"""# Copyright (C) 2017 The Android Open Source Project
286#
287# Licensed under the Apache License, Version 2.0 (the "License");
288# you may not use this file except in compliance with the License.
289# You may obtain a copy of the License at
290#
291# http://www.apache.org/licenses/LICENSE-2.0
292#
293# Unless required by applicable law or agreed to in writing, software
294# distributed under the License is distributed on an "AS IS" BASIS,
295# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
296# See the License for the specific language governing permissions and
297# limitations under the License.
298
299# This file is created by generate_build_files.py. Do not edit manually.
300
301"""
302
303 def PrintVariableSection(self, out, name, files):
304 out.write('%s := \\\n' % name)
305 for f in sorted(files):
306 out.write(' %s\\\n' % f)
307 out.write('\n')
308
309 def WriteFiles(self, files, asm_outputs):
310 # Legacy Android.mk format
311 with open('eureka.mk', 'w+') as makefile:
312 makefile.write(self.header)
313
314 self.PrintVariableSection(makefile, 'crypto_sources', files['crypto'])
315 self.PrintVariableSection(makefile, 'ssl_sources', files['ssl'])
316 self.PrintVariableSection(makefile, 'tool_sources', files['tool'])
317
318 for ((osname, arch), asm_files) in asm_outputs:
319 if osname != 'linux':
320 continue
321 self.PrintVariableSection(
322 makefile, '%s_%s_sources' % (osname, arch), asm_files)
323
324
David Benjamin38d01c62016-04-21 18:47:57 -0400325class GN(object):
326
327 def __init__(self):
328 self.firstSection = True
329 self.header = \
330"""# Copyright (c) 2016 The Chromium Authors. All rights reserved.
331# Use of this source code is governed by a BSD-style license that can be
332# found in the LICENSE file.
333
334# This file is created by generate_build_files.py. Do not edit manually.
335
336"""
337
338 def PrintVariableSection(self, out, name, files):
339 if not self.firstSection:
340 out.write('\n')
341 self.firstSection = False
342
343 out.write('%s = [\n' % name)
344 for f in sorted(files):
345 out.write(' "%s",\n' % f)
346 out.write(']\n')
347
348 def WriteFiles(self, files, asm_outputs):
349 with open('BUILD.generated.gni', 'w+') as out:
350 out.write(self.header)
351
David Benjaminc5aa8412016-07-29 17:41:58 -0400352 self.PrintVariableSection(out, 'crypto_sources',
James Robinson98dd68f2018-04-11 14:47:34 -0700353 files['crypto'] +
David Benjaminc5aa8412016-07-29 17:41:58 -0400354 files['crypto_internal_headers'])
James Robinson98dd68f2018-04-11 14:47:34 -0700355 self.PrintVariableSection(out, 'crypto_headers',
356 files['crypto_headers'])
David Benjaminc5aa8412016-07-29 17:41:58 -0400357 self.PrintVariableSection(out, 'ssl_sources',
James Robinson98dd68f2018-04-11 14:47:34 -0700358 files['ssl'] + files['ssl_internal_headers'])
359 self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
David Benjaminbb0cb952020-12-17 16:35:39 -0500360 self.PrintVariableSection(out, 'tool_sources',
361 files['tool'] + files['tool_headers'])
David Benjamin38d01c62016-04-21 18:47:57 -0400362
363 for ((osname, arch), asm_files) in asm_outputs:
364 self.PrintVariableSection(
365 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
366
367 fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0]
368 for fuzzer in files['fuzz']]
369 self.PrintVariableSection(out, 'fuzzers', fuzzers)
370
371 with open('BUILD.generated_tests.gni', 'w+') as out:
372 self.firstSection = True
373 out.write(self.header)
374
David Benjamin96628432017-01-19 19:05:47 -0500375 self.PrintVariableSection(out, 'test_support_sources',
David Benjaminc5aa8412016-07-29 17:41:58 -0400376 files['test_support'] +
377 files['test_support_headers'])
David Benjamin96628432017-01-19 19:05:47 -0500378 self.PrintVariableSection(out, 'crypto_test_sources',
379 files['crypto_test'])
David Benjaminf014d602019-05-07 18:58:06 -0500380 self.PrintVariableSection(out, 'crypto_test_data',
381 files['crypto_test_data'])
David Benjamin96628432017-01-19 19:05:47 -0500382 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
David Benjamin38d01c62016-04-21 18:47:57 -0400383
384
385class GYP(object):
386
387 def __init__(self):
388 self.header = \
389"""# Copyright (c) 2016 The Chromium Authors. All rights reserved.
390# Use of this source code is governed by a BSD-style license that can be
391# found in the LICENSE file.
392
393# This file is created by generate_build_files.py. Do not edit manually.
394
395"""
396
397 def PrintVariableSection(self, out, name, files):
398 out.write(' \'%s\': [\n' % name)
399 for f in sorted(files):
400 out.write(' \'%s\',\n' % f)
401 out.write(' ],\n')
402
403 def WriteFiles(self, files, asm_outputs):
404 with open('boringssl.gypi', 'w+') as gypi:
405 gypi.write(self.header + '{\n \'variables\': {\n')
406
David Benjaminc5aa8412016-07-29 17:41:58 -0400407 self.PrintVariableSection(gypi, 'boringssl_ssl_sources',
408 files['ssl'] + files['ssl_headers'] +
409 files['ssl_internal_headers'])
410 self.PrintVariableSection(gypi, 'boringssl_crypto_sources',
411 files['crypto'] + files['crypto_headers'] +
412 files['crypto_internal_headers'])
David Benjamin38d01c62016-04-21 18:47:57 -0400413
414 for ((osname, arch), asm_files) in asm_outputs:
415 self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' %
416 (osname, arch), asm_files)
417
418 gypi.write(' }\n}\n')
419
Adam Langleycfd80a92019-11-08 14:40:08 -0800420class CMake(object):
421
422 def __init__(self):
423 self.header = \
424R'''# Copyright (c) 2019 The Chromium Authors. All rights reserved.
425# Use of this source code is governed by a BSD-style license that can be
426# found in the LICENSE file.
427
428# This file is created by generate_build_files.py. Do not edit manually.
429
430cmake_minimum_required(VERSION 3.0)
431
432project(BoringSSL LANGUAGES C CXX)
433
434if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
435 set(CLANG 1)
436endif()
437
438if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
439 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fvisibility=hidden -fno-common -fno-exceptions -fno-rtti")
440 if(APPLE)
441 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
442 endif()
443
444 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fno-common")
445 if((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR CLANG)
446 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
447 else()
448 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
449 endif()
450endif()
451
452# pthread_rwlock_t requires a feature flag.
453if(NOT WIN32)
454 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
455endif()
456
457if(WIN32)
458 add_definitions(-D_HAS_EXCEPTIONS=0)
459 add_definitions(-DWIN32_LEAN_AND_MEAN)
460 add_definitions(-DNOMINMAX)
461 # Allow use of fopen.
462 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
463 # VS 2017 and higher supports STL-only warning suppressions.
464 # A bug in CMake < 3.13.0 may cause the space in this value to
465 # cause issues when building with NASM. In that case, update CMake.
466 add_definitions("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987")
467endif()
468
469add_definitions(-DBORINGSSL_IMPLEMENTATION)
470
Adam Langley89730072020-01-17 08:18:07 -0800471# CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an
472# architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR
473# alone, and expects all architecture-specific logic to be conditioned within
474# the source files rather than the build. This does not work for our assembly
475# files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture
476# builds.
477if(NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES)
478 list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES)
479 if(NOT ${NUM_ARCHES} EQUAL 1)
480 message(FATAL_ERROR "Universal binaries not supported.")
481 endif()
482 list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR)
483endif()
484
Adam Langleycfd80a92019-11-08 14:40:08 -0800485if(OPENSSL_NO_ASM)
486 add_definitions(-DOPENSSL_NO_ASM)
487 set(ARCH "generic")
488elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
489 set(ARCH "x86_64")
490elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
491 set(ARCH "x86_64")
492elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
493 # cmake reports AMD64 on Windows, but we might be building for 32-bit.
David Benjamin884614c2020-06-16 10:59:58 -0400494 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
Adam Langleycfd80a92019-11-08 14:40:08 -0800495 set(ARCH "x86_64")
496 else()
497 set(ARCH "x86")
498 endif()
499elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
500 set(ARCH "x86")
501elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
502 set(ARCH "x86")
503elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
504 set(ARCH "x86")
505elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
506 set(ARCH "aarch64")
507elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
508 set(ARCH "aarch64")
509# Apple A12 Bionic chipset which is added in iPhone XS/XS Max/XR uses arm64e architecture.
510elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64e")
511 set(ARCH "aarch64")
512elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*")
513 set(ARCH "arm")
514elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips")
515 # Just to avoid the “unknown processor” error.
516 set(ARCH "generic")
517elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le")
518 set(ARCH "ppc64le")
519else()
520 message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
521endif()
522
523if(NOT OPENSSL_NO_ASM)
524 if(UNIX)
525 enable_language(ASM)
526
527 # Clang's integerated assembler does not support debug symbols.
528 if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang")
529 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g")
530 endif()
531
532 # CMake does not add -isysroot and -arch flags to assembly.
533 if(APPLE)
534 if(CMAKE_OSX_SYSROOT)
535 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"")
536 endif()
537 foreach(arch ${CMAKE_OSX_ARCHITECTURES})
538 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}")
539 endforeach()
540 endif()
541 else()
542 set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8")
543 enable_language(ASM_NASM)
544 endif()
545endif()
546
Adam Langleya0cdbf92020-01-21 09:07:46 -0800547if(BUILD_SHARED_LIBS)
548 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
549 # Enable position-independent code globally. This is needed because
550 # some library targets are OBJECT libraries.
551 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
552endif()
553
Adam Langleycfd80a92019-11-08 14:40:08 -0800554include_directories(src/include)
555
556'''
557
558 def PrintLibrary(self, out, name, files):
559 out.write('add_library(\n')
560 out.write(' %s\n\n' % name)
561
562 for f in sorted(files):
563 out.write(' %s\n' % PathOf(f))
564
565 out.write(')\n\n')
566
567 def PrintExe(self, out, name, files, libs):
568 out.write('add_executable(\n')
569 out.write(' %s\n\n' % name)
570
571 for f in sorted(files):
572 out.write(' %s\n' % PathOf(f))
573
574 out.write(')\n\n')
575 out.write('target_link_libraries(%s %s)\n\n' % (name, ' '.join(libs)))
576
577 def PrintSection(self, out, name, files):
578 out.write('set(\n')
579 out.write(' %s\n\n' % name)
580 for f in sorted(files):
581 out.write(' %s\n' % PathOf(f))
582 out.write(')\n\n')
583
584 def WriteFiles(self, files, asm_outputs):
585 with open('CMakeLists.txt', 'w+') as cmake:
586 cmake.write(self.header)
587
588 for ((osname, arch), asm_files) in asm_outputs:
589 self.PrintSection(cmake, 'CRYPTO_%s_%s_SOURCES' % (osname, arch),
590 asm_files)
591
592 cmake.write(
593R'''if(APPLE AND ${ARCH} STREQUAL "aarch64")
594 set(CRYPTO_ARCH_SOURCES ${CRYPTO_ios_aarch64_SOURCES})
595elseif(APPLE AND ${ARCH} STREQUAL "arm")
596 set(CRYPTO_ARCH_SOURCES ${CRYPTO_ios_arm_SOURCES})
597elseif(APPLE)
598 set(CRYPTO_ARCH_SOURCES ${CRYPTO_mac_${ARCH}_SOURCES})
599elseif(UNIX)
600 set(CRYPTO_ARCH_SOURCES ${CRYPTO_linux_${ARCH}_SOURCES})
601elseif(WIN32)
602 set(CRYPTO_ARCH_SOURCES ${CRYPTO_win_${ARCH}_SOURCES})
603endif()
604
605''')
606
607 self.PrintLibrary(cmake, 'crypto',
608 files['crypto'] + ['${CRYPTO_ARCH_SOURCES}'])
609 self.PrintLibrary(cmake, 'ssl', files['ssl'])
Adam Langleyff631132020-01-13 15:24:22 -0800610 self.PrintExe(cmake, 'bssl', files['tool'], ['ssl', 'crypto'])
611
612 cmake.write(
David Benjamin8f88b272020-07-09 13:35:01 -0400613R'''if(NOT WIN32 AND NOT ANDROID)
Adam Langleyff631132020-01-13 15:24:22 -0800614 target_link_libraries(crypto pthread)
615endif()
616
David Benjamin8f88b272020-07-09 13:35:01 -0400617if(WIN32)
618 target_link_libraries(bssl ws2_32)
619endif()
620
Adam Langleyff631132020-01-13 15:24:22 -0800621''')
David Benjamin38d01c62016-04-21 18:47:57 -0400622
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400623class JSON(object):
624 def WriteFiles(self, files, asm_outputs):
625 sources = dict(files)
626 for ((osname, arch), asm_files) in asm_outputs:
627 sources['crypto_%s_%s' % (osname, arch)] = asm_files
628 with open('sources.json', 'w+') as f:
629 json.dump(sources, f, sort_keys=True, indent=2)
630
Adam Langley9e1a6602015-05-05 17:47:53 -0700631def FindCMakeFiles(directory):
632 """Returns list of all CMakeLists.txt files recursively in directory."""
633 cmakefiles = []
634
635 for (path, _, filenames) in os.walk(directory):
636 for filename in filenames:
637 if filename == 'CMakeLists.txt':
638 cmakefiles.append(os.path.join(path, filename))
639
640 return cmakefiles
641
Adam Langleyfd499932017-04-04 14:21:43 -0700642def OnlyFIPSFragments(path, dent, is_dir):
Matthew Braithwaite95511e92017-05-08 16:38:03 -0700643 return is_dir or (path.startswith(
644 os.path.join('src', 'crypto', 'fipsmodule', '')) and
645 NoTests(path, dent, is_dir))
Adam Langley9e1a6602015-05-05 17:47:53 -0700646
Adam Langleyfd499932017-04-04 14:21:43 -0700647def NoTestsNorFIPSFragments(path, dent, is_dir):
Adam Langley323f1eb2017-04-06 17:29:10 -0700648 return (NoTests(path, dent, is_dir) and
649 (is_dir or not OnlyFIPSFragments(path, dent, is_dir)))
Adam Langleyfd499932017-04-04 14:21:43 -0700650
651def NoTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700652 """Filter function that can be passed to FindCFiles in order to remove test
653 sources."""
654 if is_dir:
655 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400656 return 'test.' not in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700657
658
Adam Langleyfd499932017-04-04 14:21:43 -0700659def OnlyTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700660 """Filter function that can be passed to FindCFiles in order to remove
661 non-test sources."""
662 if is_dir:
David Benjamin26073832015-05-11 20:52:48 -0400663 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400664 return '_test.' in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700665
666
Adam Langleyfd499932017-04-04 14:21:43 -0700667def AllFiles(path, dent, is_dir):
David Benjamin26073832015-05-11 20:52:48 -0400668 """Filter function that can be passed to FindCFiles in order to include all
669 sources."""
670 return True
671
672
Adam Langleyfd499932017-04-04 14:21:43 -0700673def NoTestRunnerFiles(path, dent, is_dir):
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700674 """Filter function that can be passed to FindCFiles or FindHeaderFiles in
675 order to exclude test runner files."""
676 # NOTE(martinkr): This prevents .h/.cc files in src/ssl/test/runner, which
677 # are in their own subpackage, from being included in boringssl/BUILD files.
678 return not is_dir or dent != 'runner'
679
680
David Benjamin3ecd0a52017-05-19 15:26:18 -0400681def NotGTestSupport(path, dent, is_dir):
David Benjaminc3889632019-03-01 15:03:05 -0500682 return 'gtest' not in dent and 'abi_test' not in dent
David Benjamin96628432017-01-19 19:05:47 -0500683
684
Adam Langleyfd499932017-04-04 14:21:43 -0700685def SSLHeaderFiles(path, dent, is_dir):
Aaron Green0e150022018-10-16 12:05:29 -0700686 return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h', 'srtp.h']
Adam Langley049ef412015-06-09 18:20:57 -0700687
688
Adam Langley9e1a6602015-05-05 17:47:53 -0700689def FindCFiles(directory, filter_func):
690 """Recurses through directory and returns a list of paths to all the C source
691 files that pass filter_func."""
692 cfiles = []
693
694 for (path, dirnames, filenames) in os.walk(directory):
695 for filename in filenames:
696 if not filename.endswith('.c') and not filename.endswith('.cc'):
697 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700698 if not filter_func(path, filename, False):
Adam Langley9e1a6602015-05-05 17:47:53 -0700699 continue
700 cfiles.append(os.path.join(path, filename))
701
702 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700703 if not filter_func(path, dirname, True):
Adam Langley9e1a6602015-05-05 17:47:53 -0700704 del dirnames[i]
705
David Benjaminedd4c5f2020-08-19 14:46:17 -0400706 cfiles.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700707 return cfiles
708
709
Adam Langley049ef412015-06-09 18:20:57 -0700710def FindHeaderFiles(directory, filter_func):
711 """Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
712 hfiles = []
713
714 for (path, dirnames, filenames) in os.walk(directory):
715 for filename in filenames:
716 if not filename.endswith('.h'):
717 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700718 if not filter_func(path, filename, False):
Adam Langley049ef412015-06-09 18:20:57 -0700719 continue
720 hfiles.append(os.path.join(path, filename))
721
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700722 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700723 if not filter_func(path, dirname, True):
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700724 del dirnames[i]
725
David Benjaminedd4c5f2020-08-19 14:46:17 -0400726 hfiles.sort()
Adam Langley049ef412015-06-09 18:20:57 -0700727 return hfiles
728
729
Adam Langley9e1a6602015-05-05 17:47:53 -0700730def ExtractPerlAsmFromCMakeFile(cmakefile):
731 """Parses the contents of the CMakeLists.txt file passed as an argument and
732 returns a list of all the perlasm() directives found in the file."""
733 perlasms = []
734 with open(cmakefile) as f:
735 for line in f:
736 line = line.strip()
737 if not line.startswith('perlasm('):
738 continue
739 if not line.endswith(')'):
740 raise ValueError('Bad perlasm line in %s' % cmakefile)
741 # Remove "perlasm(" from start and ")" from end
742 params = line[8:-1].split()
743 if len(params) < 2:
744 raise ValueError('Bad perlasm line in %s' % cmakefile)
745 perlasms.append({
746 'extra_args': params[2:],
747 'input': os.path.join(os.path.dirname(cmakefile), params[1]),
748 'output': os.path.join(os.path.dirname(cmakefile), params[0]),
749 })
750
751 return perlasms
752
753
754def ReadPerlAsmOperations():
755 """Returns a list of all perlasm() directives found in CMake config files in
756 src/."""
757 perlasms = []
758 cmakefiles = FindCMakeFiles('src')
759
760 for cmakefile in cmakefiles:
761 perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile))
762
763 return perlasms
764
765
766def PerlAsm(output_filename, input_filename, perlasm_style, extra_args):
767 """Runs the a perlasm script and puts the output into output_filename."""
768 base_dir = os.path.dirname(output_filename)
769 if not os.path.isdir(base_dir):
770 os.makedirs(base_dir)
David Benjaminfdd8e9c2016-06-26 13:18:50 -0400771 subprocess.check_call(
772 ['perl', input_filename, perlasm_style] + extra_args + [output_filename])
Adam Langley9e1a6602015-05-05 17:47:53 -0700773
774
775def ArchForAsmFilename(filename):
776 """Returns the architectures that a given asm file should be compiled for
777 based on substrings in the filename."""
778
779 if 'x86_64' in filename or 'avx2' in filename:
780 return ['x86_64']
781 elif ('x86' in filename and 'x86_64' not in filename) or '586' in filename:
782 return ['x86']
783 elif 'armx' in filename:
784 return ['arm', 'aarch64']
785 elif 'armv8' in filename:
786 return ['aarch64']
787 elif 'arm' in filename:
788 return ['arm']
David Benjamin9f16ce12016-09-27 16:30:22 -0400789 elif 'ppc' in filename:
790 return ['ppc64le']
Adam Langley9e1a6602015-05-05 17:47:53 -0700791 else:
792 raise ValueError('Unknown arch for asm filename: ' + filename)
793
794
795def WriteAsmFiles(perlasms):
796 """Generates asm files from perlasm directives for each supported OS x
797 platform combination."""
798 asmfiles = {}
799
800 for osarch in OS_ARCH_COMBOS:
801 (osname, arch, perlasm_style, extra_args, asm_ext) = osarch
802 key = (osname, arch)
803 outDir = '%s-%s' % key
804
805 for perlasm in perlasms:
806 filename = os.path.basename(perlasm['input'])
807 output = perlasm['output']
808 if not output.startswith('src'):
809 raise ValueError('output missing src: %s' % output)
810 output = os.path.join(outDir, output[4:])
William Hessec618c402015-06-22 16:34:02 +0200811 if output.endswith('-armx.${ASM_EXT}'):
812 output = output.replace('-armx',
813 '-armx64' if arch == 'aarch64' else '-armx32')
Adam Langley9e1a6602015-05-05 17:47:53 -0700814 output = output.replace('${ASM_EXT}', asm_ext)
815
816 if arch in ArchForAsmFilename(filename):
817 PerlAsm(output, perlasm['input'], perlasm_style,
818 perlasm['extra_args'] + extra_args)
819 asmfiles.setdefault(key, []).append(output)
820
821 for (key, non_perl_asm_files) in NON_PERL_FILES.iteritems():
822 asmfiles.setdefault(key, []).extend(non_perl_asm_files)
823
David Benjaminedd4c5f2020-08-19 14:46:17 -0400824 for files in asmfiles.itervalues():
825 files.sort()
826
Adam Langley9e1a6602015-05-05 17:47:53 -0700827 return asmfiles
828
829
David Benjamin3ecd0a52017-05-19 15:26:18 -0400830def ExtractVariablesFromCMakeFile(cmakefile):
831 """Parses the contents of the CMakeLists.txt file passed as an argument and
832 returns a dictionary of exported source lists."""
833 variables = {}
834 in_set_command = False
835 set_command = []
836 with open(cmakefile) as f:
837 for line in f:
838 if '#' in line:
839 line = line[:line.index('#')]
840 line = line.strip()
841
842 if not in_set_command:
843 if line.startswith('set('):
844 in_set_command = True
845 set_command = []
846 elif line == ')':
847 in_set_command = False
848 if not set_command:
849 raise ValueError('Empty set command')
850 variables[set_command[0]] = set_command[1:]
851 else:
852 set_command.extend([c for c in line.split(' ') if c])
853
854 if in_set_command:
855 raise ValueError('Unfinished set command')
856 return variables
857
858
Adam Langley049ef412015-06-09 18:20:57 -0700859def main(platforms):
David Benjamin3ecd0a52017-05-19 15:26:18 -0400860 cmake = ExtractVariablesFromCMakeFile(os.path.join('src', 'sources.cmake'))
Andres Erbsen5b280a82017-10-30 15:58:33 +0000861 crypto_c_files = (FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments) +
Adam Langley7f028812019-10-18 14:48:11 -0700862 FindCFiles(os.path.join('src', 'third_party', 'fiat'), NoTestsNorFIPSFragments))
Adam Langleyfd499932017-04-04 14:21:43 -0700863 fips_fragments = FindCFiles(os.path.join('src', 'crypto', 'fipsmodule'), OnlyFIPSFragments)
Adam Langleyfeca9e52017-01-23 13:07:50 -0800864 ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
David Benjamin38d01c62016-04-21 18:47:57 -0400865 tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
Adam Langleyf11f2332016-06-30 11:56:19 -0700866 tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles)
Adam Langley9e1a6602015-05-05 17:47:53 -0700867
Pete Bentley44544d92019-08-15 15:01:26 +0100868 # BCM shared library C files
869 bcm_crypto_c_files = [
870 os.path.join('src', 'crypto', 'fipsmodule', 'bcm.c')
871 ]
872
Adam Langley9e1a6602015-05-05 17:47:53 -0700873 # Generate err_data.c
874 with open('err_data.c', 'w+') as err_data:
875 subprocess.check_call(['go', 'run', 'err_data_generate.go'],
876 cwd=os.path.join('src', 'crypto', 'err'),
877 stdout=err_data)
878 crypto_c_files.append('err_data.c')
David Benjaminedd4c5f2020-08-19 14:46:17 -0400879 crypto_c_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700880
David Benjamin38d01c62016-04-21 18:47:57 -0400881 test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
David Benjamin3ecd0a52017-05-19 15:26:18 -0400882 NotGTestSupport)
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700883 test_support_h_files = (
884 FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) +
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700885 FindHeaderFiles(os.path.join('src', 'ssl', 'test'), NoTestRunnerFiles))
David Benjamin26073832015-05-11 20:52:48 -0400886
Adam Langley990a3232018-05-22 10:02:59 -0700887 crypto_test_files = []
888 if EMBED_TEST_DATA:
889 # Generate crypto_test_data.cc
890 with open('crypto_test_data.cc', 'w+') as out:
891 subprocess.check_call(
892 ['go', 'run', 'util/embed_test_data.go'] + cmake['CRYPTO_TEST_DATA'],
893 cwd='src',
894 stdout=out)
895 crypto_test_files += ['crypto_test_data.cc']
David Benjamin3ecd0a52017-05-19 15:26:18 -0400896
Adam Langley990a3232018-05-22 10:02:59 -0700897 crypto_test_files += FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
David Benjamin96ee4a82017-07-09 23:46:47 -0400898 crypto_test_files += [
David Benjaminc3889632019-03-01 15:03:05 -0500899 'src/crypto/test/abi_test.cc',
David Benjamin3ecd0a52017-05-19 15:26:18 -0400900 'src/crypto/test/file_test_gtest.cc',
901 'src/crypto/test/gtest_main.cc',
902 ]
Adam Langley3e502c82019-10-16 09:56:38 -0700903 # urandom_test.cc is in a separate binary so that it can be test PRNG
904 # initialisation.
905 crypto_test_files = [
906 file for file in crypto_test_files
907 if not file.endswith('/urandom_test.cc')
908 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400909 crypto_test_files.sort()
David Benjamin1d5a5702017-02-13 22:11:49 -0500910
911 ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
Robert Sloanae1e0872019-03-01 16:01:30 -0800912 ssl_test_files += [
913 'src/crypto/test/abi_test.cc',
914 'src/crypto/test/gtest_main.cc',
915 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400916 ssl_test_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700917
Adam Langley3e502c82019-10-16 09:56:38 -0700918 urandom_test_files = [
919 'src/crypto/fipsmodule/rand/urandom_test.cc',
920 ]
921
David Benjamin38d01c62016-04-21 18:47:57 -0400922 fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
923
David Benjaminedd4c5f2020-08-19 14:46:17 -0400924 ssl_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
925 SSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700926
Adam Langleyfd499932017-04-04 14:21:43 -0700927 def NotSSLHeaderFiles(path, filename, is_dir):
928 return not SSLHeaderFiles(path, filename, is_dir)
David Benjaminedd4c5f2020-08-19 14:46:17 -0400929 crypto_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
930 NotSSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700931
932 ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
Andres Erbsen5b280a82017-10-30 15:58:33 +0000933 crypto_internal_h_files = (
934 FindHeaderFiles(os.path.join('src', 'crypto'), NoTests) +
Adam Langley7f028812019-10-18 14:48:11 -0700935 FindHeaderFiles(os.path.join('src', 'third_party', 'fiat'), NoTests))
Adam Langley049ef412015-06-09 18:20:57 -0700936
Adam Langley9e1a6602015-05-05 17:47:53 -0700937 files = {
Pete Bentley44544d92019-08-15 15:01:26 +0100938 'bcm_crypto': bcm_crypto_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700939 'crypto': crypto_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700940 'crypto_headers': crypto_h_files,
941 'crypto_internal_headers': crypto_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400942 'crypto_test': crypto_test_files,
Adam Langley990a3232018-05-22 10:02:59 -0700943 'crypto_test_data': sorted('src/' + x for x in cmake['CRYPTO_TEST_DATA']),
Adam Langleyfd499932017-04-04 14:21:43 -0700944 'fips_fragments': fips_fragments,
David Benjamin38d01c62016-04-21 18:47:57 -0400945 'fuzz': fuzz_c_files,
Adam Langleyfeca9e52017-01-23 13:07:50 -0800946 'ssl': ssl_source_files,
Adam Langley049ef412015-06-09 18:20:57 -0700947 'ssl_headers': ssl_h_files,
948 'ssl_internal_headers': ssl_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400949 'ssl_test': ssl_test_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400950 'tool': tool_c_files,
Adam Langleyf11f2332016-06-30 11:56:19 -0700951 'tool_headers': tool_h_files,
David Benjaminc5aa8412016-07-29 17:41:58 -0400952 'test_support': test_support_c_files,
953 'test_support_headers': test_support_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400954 'urandom_test': urandom_test_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700955 }
956
957 asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).iteritems())
958
Adam Langley049ef412015-06-09 18:20:57 -0700959 for platform in platforms:
960 platform.WriteFiles(files, asm_outputs)
Adam Langley9e1a6602015-05-05 17:47:53 -0700961
962 return 0
963
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400964ALL_PLATFORMS = {
965 'android': Android,
966 'android-cmake': AndroidCMake,
967 'bazel': Bazel,
968 'cmake': CMake,
969 'eureka': Eureka,
970 'gn': GN,
971 'gyp': GYP,
972 'json': JSON,
973}
Adam Langley9e1a6602015-05-05 17:47:53 -0700974
Adam Langley9e1a6602015-05-05 17:47:53 -0700975if __name__ == '__main__':
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400976 parser = optparse.OptionParser(usage='Usage: %%prog [--prefix=<path>] [%s]' %
977 '|'.join(sorted(ALL_PLATFORMS.keys())))
Matt Braithwaite16695892016-06-09 09:34:11 -0700978 parser.add_option('--prefix', dest='prefix',
979 help='For Bazel, prepend argument to all source files')
Adam Langley990a3232018-05-22 10:02:59 -0700980 parser.add_option(
981 '--embed_test_data', type='choice', dest='embed_test_data',
982 action='store', default="true", choices=["true", "false"],
David Benjaminf014d602019-05-07 18:58:06 -0500983 help='For Bazel or GN, don\'t embed data files in crypto_test_data.cc')
Matt Braithwaite16695892016-06-09 09:34:11 -0700984 options, args = parser.parse_args(sys.argv[1:])
985 PREFIX = options.prefix
Adam Langley990a3232018-05-22 10:02:59 -0700986 EMBED_TEST_DATA = (options.embed_test_data == "true")
Matt Braithwaite16695892016-06-09 09:34:11 -0700987
988 if not args:
989 parser.print_help()
990 sys.exit(1)
Adam Langley9e1a6602015-05-05 17:47:53 -0700991
Adam Langley049ef412015-06-09 18:20:57 -0700992 platforms = []
Matt Braithwaite16695892016-06-09 09:34:11 -0700993 for s in args:
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400994 platform = ALL_PLATFORMS.get(s)
995 if platform is None:
Matt Braithwaite16695892016-06-09 09:34:11 -0700996 parser.print_help()
997 sys.exit(1)
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400998 platforms.append(platform())
Adam Langley9e1a6602015-05-05 17:47:53 -0700999
Adam Langley049ef412015-06-09 18:20:57 -07001000 sys.exit(main(platforms))