blob: c319a552952133b8c59e8e0a9d2174ebe5fbe11c [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.
David Benjamin19676212023-01-25 10:03:53 -050028#
29# TODO(https://crbug.com/boringssl/524): This probably should be a map, but some
30# downstream scripts import this to find what folders to add/remove from git.
Adam Langley9e1a6602015-05-05 17:47:53 -070031OS_ARCH_COMBOS = [
David Benjamin351b2f82022-02-06 12:57:17 -050032 ('apple', 'arm', 'ios32', [], 'S'),
33 ('apple', 'aarch64', 'ios64', [], 'S'),
34 ('apple', 'x86', 'macosx', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'),
35 ('apple', 'x86_64', 'macosx', [], 'S'),
Adam Langley9e1a6602015-05-05 17:47:53 -070036 ('linux', 'arm', 'linux32', [], 'S'),
37 ('linux', 'aarch64', 'linux64', [], 'S'),
38 ('linux', 'x86', 'elf', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'),
39 ('linux', 'x86_64', 'elf', [], 'S'),
Adam Langley9e1a6602015-05-05 17:47:53 -070040 ('win', 'x86', 'win32n', ['-DOPENSSL_IA32_SSE2'], 'asm'),
41 ('win', 'x86_64', 'nasm', [], 'asm'),
Anthony Robertsafd5dba2020-10-19 12:27:51 +010042 ('win', 'aarch64', 'win64', [], 'S'),
Adam Langley9e1a6602015-05-05 17:47:53 -070043]
44
45# NON_PERL_FILES enumerates assembly files that are not processed by the
46# perlasm system.
47NON_PERL_FILES = {
48 ('linux', 'arm'): [
Adam Langley7b8b9c12016-01-04 07:13:00 -080049 'src/crypto/curve25519/asm/x25519-asm-arm.S',
David Benjamin3c4a5cb2016-03-29 17:43:31 -040050 'src/crypto/poly1305/poly1305_arm_asm.S',
Adam Langley7b935932018-11-12 13:53:42 -080051 ],
Adam Langley9e1a6602015-05-05 17:47:53 -070052}
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
David Benjamin70690f72023-01-25 09:56:43 -050062LICENSE_TEMPLATE = """Copyright (c) 2015, Google Inc.
63
64Permission to use, copy, modify, and/or distribute this software for any
65purpose with or without fee is hereby granted, provided that the above
66copyright notice and this permission notice appear in all copies.
67
68THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
69WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
70MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
71SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
72WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
73OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
74CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.""".split("\n")
75
76def LicenseHeader(comment):
77 lines = []
78 for line in LICENSE_TEMPLATE:
79 if not line:
80 lines.append(comment)
81 else:
82 lines.append("%s %s" % (comment, line))
83 lines.append("")
84 return "\n".join(lines)
85
86
Adam Langley9e1a6602015-05-05 17:47:53 -070087class Android(object):
88
89 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -050090 self.header = LicenseHeader("#") + """
Dan Willemsenb57e4fc2016-07-21 11:08:44 -070091# This file is created by generate_build_files.py. Do not edit manually.
Adam Langley9e1a6602015-05-05 17:47:53 -070092"""
93
94 def PrintVariableSection(self, out, name, files):
95 out.write('%s := \\\n' % name)
96 for f in sorted(files):
97 out.write(' %s\\\n' % f)
98 out.write('\n')
99
100 def WriteFiles(self, files, asm_outputs):
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700101 # New Android.bp format
102 with open('sources.bp', 'w+') as blueprint:
103 blueprint.write(self.header.replace('#', '//'))
104
Pete Bentley44544d92019-08-15 15:01:26 +0100105 # Separate out BCM files to allow different compilation rules (specific to Android FIPS)
106 bcm_c_files = files['bcm_crypto']
107 non_bcm_c_files = [file for file in files['crypto'] if file not in bcm_c_files]
108 non_bcm_asm = self.FilterBcmAsm(asm_outputs, False)
109 bcm_asm = self.FilterBcmAsm(asm_outputs, True)
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700110
Pete Bentley44544d92019-08-15 15:01:26 +0100111 self.PrintDefaults(blueprint, 'libcrypto_sources', non_bcm_c_files, non_bcm_asm)
112 self.PrintDefaults(blueprint, 'libcrypto_bcm_sources', bcm_c_files, bcm_asm)
113 self.PrintDefaults(blueprint, 'libssl_sources', files['ssl'])
114 self.PrintDefaults(blueprint, 'bssl_sources', files['tool'])
115 self.PrintDefaults(blueprint, 'boringssl_test_support_sources', files['test_support'])
116 self.PrintDefaults(blueprint, 'boringssl_crypto_test_sources', files['crypto_test'])
117 self.PrintDefaults(blueprint, 'boringssl_ssl_test_sources', files['ssl_test'])
118
119 # Legacy Android.mk format, only used by Trusty in new branches
120 with open('sources.mk', 'w+') as makefile:
121 makefile.write(self.header)
122 makefile.write('\n')
123 self.PrintVariableSection(makefile, 'crypto_sources', files['crypto'])
124
125 for ((osname, arch), asm_files) in asm_outputs:
126 if osname != 'linux':
127 continue
128 self.PrintVariableSection(
129 makefile, '%s_%s_sources' % (osname, arch), asm_files)
130
131 def PrintDefaults(self, blueprint, name, files, asm_outputs={}):
132 """Print a cc_defaults section from a list of C files and optionally assembly outputs"""
133 blueprint.write('\n')
134 blueprint.write('cc_defaults {\n')
135 blueprint.write(' name: "%s",\n' % name)
136 blueprint.write(' srcs: [\n')
137 for f in sorted(files):
138 blueprint.write(' "%s",\n' % f)
139 blueprint.write(' ],\n')
140
141 if asm_outputs:
142 blueprint.write(' target: {\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700143 for ((osname, arch), asm_files) in asm_outputs:
David Benjamin5fdc03f2023-01-26 18:55:32 -0500144 if osname != 'linux':
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700145 continue
146 if arch == 'aarch64':
147 arch = 'arm64'
148
Dan Willemsen2eb4bc52017-10-16 14:37:00 -0700149 blueprint.write(' linux_%s: {\n' % arch)
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700150 blueprint.write(' srcs: [\n')
151 for f in sorted(asm_files):
152 blueprint.write(' "%s",\n' % f)
153 blueprint.write(' ],\n')
154 blueprint.write(' },\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700155 blueprint.write(' },\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700156
Pete Bentley44544d92019-08-15 15:01:26 +0100157 blueprint.write('}\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700158
Pete Bentley44544d92019-08-15 15:01:26 +0100159 def FilterBcmAsm(self, asm, want_bcm):
160 """Filter a list of assembly outputs based on whether they belong in BCM
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700161
Pete Bentley44544d92019-08-15 15:01:26 +0100162 Args:
163 asm: Assembly file lists to filter
164 want_bcm: If true then include BCM files, otherwise do not
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700165
Pete Bentley44544d92019-08-15 15:01:26 +0100166 Returns:
167 A copy of |asm| with files filtered according to |want_bcm|
168 """
David Benjamin19676212023-01-25 10:03:53 -0500169 # TODO(https://crbug.com/boringssl/542): Rather than filtering by filename,
170 # use the variable listed in the CMake perlasm line, available in
171 # ExtractPerlAsmFromCMakeFile.
Pete Bentley44544d92019-08-15 15:01:26 +0100172 return [(archinfo, filter(lambda p: ("/crypto/fipsmodule/" in p) == want_bcm, files))
173 for (archinfo, files) in asm]
Adam Langley9e1a6602015-05-05 17:47:53 -0700174
175
David Benjamineca48e52019-08-13 11:51:53 -0400176class AndroidCMake(object):
177
178 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -0500179 self.header = LicenseHeader("#") + """
David Benjamineca48e52019-08-13 11:51:53 -0400180# 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):
David Benjamin70690f72023-01-25 09:56:43 -0500284 self.header = LicenseHeader("#") + """
Robert Sloane091af42017-10-09 12:47:17 -0700285# This file is created by generate_build_files.py. Do not edit manually.
286
287"""
288
289 def PrintVariableSection(self, out, name, files):
290 out.write('%s := \\\n' % name)
291 for f in sorted(files):
292 out.write(' %s\\\n' % f)
293 out.write('\n')
294
295 def WriteFiles(self, files, asm_outputs):
296 # Legacy Android.mk format
297 with open('eureka.mk', 'w+') as makefile:
298 makefile.write(self.header)
299
300 self.PrintVariableSection(makefile, 'crypto_sources', files['crypto'])
301 self.PrintVariableSection(makefile, 'ssl_sources', files['ssl'])
302 self.PrintVariableSection(makefile, 'tool_sources', files['tool'])
303
304 for ((osname, arch), asm_files) in asm_outputs:
305 if osname != 'linux':
306 continue
307 self.PrintVariableSection(
308 makefile, '%s_%s_sources' % (osname, arch), asm_files)
309
310
David Benjamin38d01c62016-04-21 18:47:57 -0400311class GN(object):
312
313 def __init__(self):
314 self.firstSection = True
David Benjamin70690f72023-01-25 09:56:43 -0500315 self.header = LicenseHeader("#") + """
David Benjamin38d01c62016-04-21 18:47:57 -0400316# This file is created by generate_build_files.py. Do not edit manually.
317
318"""
319
320 def PrintVariableSection(self, out, name, files):
321 if not self.firstSection:
322 out.write('\n')
323 self.firstSection = False
324
325 out.write('%s = [\n' % name)
326 for f in sorted(files):
327 out.write(' "%s",\n' % f)
328 out.write(']\n')
329
330 def WriteFiles(self, files, asm_outputs):
331 with open('BUILD.generated.gni', 'w+') as out:
332 out.write(self.header)
333
David Benjaminc5aa8412016-07-29 17:41:58 -0400334 self.PrintVariableSection(out, 'crypto_sources',
James Robinson98dd68f2018-04-11 14:47:34 -0700335 files['crypto'] +
David Benjaminc5aa8412016-07-29 17:41:58 -0400336 files['crypto_internal_headers'])
James Robinson98dd68f2018-04-11 14:47:34 -0700337 self.PrintVariableSection(out, 'crypto_headers',
338 files['crypto_headers'])
David Benjaminc5aa8412016-07-29 17:41:58 -0400339 self.PrintVariableSection(out, 'ssl_sources',
James Robinson98dd68f2018-04-11 14:47:34 -0700340 files['ssl'] + files['ssl_internal_headers'])
341 self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
David Benjaminbb0cb952020-12-17 16:35:39 -0500342 self.PrintVariableSection(out, 'tool_sources',
343 files['tool'] + files['tool_headers'])
David Benjamin38d01c62016-04-21 18:47:57 -0400344
345 for ((osname, arch), asm_files) in asm_outputs:
346 self.PrintVariableSection(
347 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
348
349 fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0]
350 for fuzzer in files['fuzz']]
351 self.PrintVariableSection(out, 'fuzzers', fuzzers)
352
353 with open('BUILD.generated_tests.gni', 'w+') as out:
354 self.firstSection = True
355 out.write(self.header)
356
David Benjamin96628432017-01-19 19:05:47 -0500357 self.PrintVariableSection(out, 'test_support_sources',
David Benjaminc5aa8412016-07-29 17:41:58 -0400358 files['test_support'] +
359 files['test_support_headers'])
David Benjamin96628432017-01-19 19:05:47 -0500360 self.PrintVariableSection(out, 'crypto_test_sources',
361 files['crypto_test'])
David Benjaminf014d602019-05-07 18:58:06 -0500362 self.PrintVariableSection(out, 'crypto_test_data',
363 files['crypto_test_data'])
David Benjamin96628432017-01-19 19:05:47 -0500364 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
David Benjamin38d01c62016-04-21 18:47:57 -0400365
366
367class GYP(object):
368
369 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -0500370 self.header = LicenseHeader("#") + """
David Benjamin38d01c62016-04-21 18:47:57 -0400371# This file is created by generate_build_files.py. Do not edit manually.
372
373"""
374
375 def PrintVariableSection(self, out, name, files):
376 out.write(' \'%s\': [\n' % name)
377 for f in sorted(files):
378 out.write(' \'%s\',\n' % f)
379 out.write(' ],\n')
380
381 def WriteFiles(self, files, asm_outputs):
382 with open('boringssl.gypi', 'w+') as gypi:
383 gypi.write(self.header + '{\n \'variables\': {\n')
384
David Benjaminc5aa8412016-07-29 17:41:58 -0400385 self.PrintVariableSection(gypi, 'boringssl_ssl_sources',
386 files['ssl'] + files['ssl_headers'] +
387 files['ssl_internal_headers'])
388 self.PrintVariableSection(gypi, 'boringssl_crypto_sources',
389 files['crypto'] + files['crypto_headers'] +
390 files['crypto_internal_headers'])
David Benjamin38d01c62016-04-21 18:47:57 -0400391
392 for ((osname, arch), asm_files) in asm_outputs:
393 self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' %
394 (osname, arch), asm_files)
395
396 gypi.write(' }\n}\n')
397
Adam Langleycfd80a92019-11-08 14:40:08 -0800398class CMake(object):
399
400 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -0500401 self.header = LicenseHeader("#") + R'''
Adam Langleycfd80a92019-11-08 14:40:08 -0800402# This file is created by generate_build_files.py. Do not edit manually.
403
David Benjamind0b66c72021-03-22 17:30:02 -0400404cmake_minimum_required(VERSION 3.5)
Adam Langleycfd80a92019-11-08 14:40:08 -0800405
406project(BoringSSL LANGUAGES C CXX)
407
408if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
409 set(CLANG 1)
410endif()
411
412if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
David Benjamin493d5cb2022-04-18 17:20:27 -0400413 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 -0400414 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fno-common -std=c11")
Adam Langleycfd80a92019-11-08 14:40:08 -0800415endif()
416
417# pthread_rwlock_t requires a feature flag.
418if(NOT WIN32)
419 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
420endif()
421
422if(WIN32)
423 add_definitions(-D_HAS_EXCEPTIONS=0)
424 add_definitions(-DWIN32_LEAN_AND_MEAN)
425 add_definitions(-DNOMINMAX)
426 # Allow use of fopen.
427 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
428 # VS 2017 and higher supports STL-only warning suppressions.
429 # A bug in CMake < 3.13.0 may cause the space in this value to
430 # cause issues when building with NASM. In that case, update CMake.
431 add_definitions("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987")
432endif()
433
434add_definitions(-DBORINGSSL_IMPLEMENTATION)
435
Adam Langley89730072020-01-17 08:18:07 -0800436# CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an
437# architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR
438# alone, and expects all architecture-specific logic to be conditioned within
439# the source files rather than the build. This does not work for our assembly
440# files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture
441# builds.
442if(NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES)
443 list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES)
David Benjamin7e265972021-08-04 14:28:55 -0400444 if(NOT NUM_ARCHES EQUAL 1)
Adam Langley89730072020-01-17 08:18:07 -0800445 message(FATAL_ERROR "Universal binaries not supported.")
446 endif()
447 list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR)
448endif()
449
Adam Langleycfd80a92019-11-08 14:40:08 -0800450if(OPENSSL_NO_ASM)
451 add_definitions(-DOPENSSL_NO_ASM)
452 set(ARCH "generic")
David Benjamin7e265972021-08-04 14:28:55 -0400453elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800454 set(ARCH "x86_64")
David Benjamin7e265972021-08-04 14:28:55 -0400455elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800456 set(ARCH "x86_64")
David Benjamin7e265972021-08-04 14:28:55 -0400457elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800458 # cmake reports AMD64 on Windows, but we might be building for 32-bit.
David Benjamin884614c2020-06-16 10:59:58 -0400459 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
Adam Langleycfd80a92019-11-08 14:40:08 -0800460 set(ARCH "x86_64")
461 else()
462 set(ARCH "x86")
463 endif()
David Benjamin7e265972021-08-04 14:28:55 -0400464elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
Adam Langleycfd80a92019-11-08 14:40:08 -0800465 set(ARCH "x86")
David Benjamin7e265972021-08-04 14:28:55 -0400466elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
Adam Langleycfd80a92019-11-08 14:40:08 -0800467 set(ARCH "x86")
David Benjamin7e265972021-08-04 14:28:55 -0400468elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686")
Adam Langleycfd80a92019-11-08 14:40:08 -0800469 set(ARCH "x86")
David Benjamin7e265972021-08-04 14:28:55 -0400470elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800471 set(ARCH "aarch64")
David Benjamin7e265972021-08-04 14:28:55 -0400472elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
Adam Langleycfd80a92019-11-08 14:40:08 -0800473 set(ARCH "aarch64")
474# Apple A12 Bionic chipset which is added in iPhone XS/XS Max/XR uses arm64e architecture.
David Benjamin7e265972021-08-04 14:28:55 -0400475elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64e")
Adam Langleycfd80a92019-11-08 14:40:08 -0800476 set(ARCH "aarch64")
David Benjamin7e265972021-08-04 14:28:55 -0400477elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm*")
Adam Langleycfd80a92019-11-08 14:40:08 -0800478 set(ARCH "arm")
David Benjamin7e265972021-08-04 14:28:55 -0400479elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "mips")
Adam Langleycfd80a92019-11-08 14:40:08 -0800480 # Just to avoid the “unknown processor” error.
481 set(ARCH "generic")
Adam Langleycfd80a92019-11-08 14:40:08 -0800482else()
483 message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
484endif()
485
486if(NOT OPENSSL_NO_ASM)
487 if(UNIX)
488 enable_language(ASM)
489
490 # Clang's integerated assembler does not support debug symbols.
491 if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang")
492 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g")
493 endif()
494
495 # CMake does not add -isysroot and -arch flags to assembly.
496 if(APPLE)
497 if(CMAKE_OSX_SYSROOT)
498 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"")
499 endif()
500 foreach(arch ${CMAKE_OSX_ARCHITECTURES})
501 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}")
502 endforeach()
503 endif()
504 else()
505 set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8")
506 enable_language(ASM_NASM)
507 endif()
508endif()
509
Adam Langleya0cdbf92020-01-21 09:07:46 -0800510if(BUILD_SHARED_LIBS)
511 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
512 # Enable position-independent code globally. This is needed because
513 # some library targets are OBJECT libraries.
514 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
515endif()
516
Adam Langleycfd80a92019-11-08 14:40:08 -0800517include_directories(src/include)
518
519'''
520
521 def PrintLibrary(self, out, name, files):
522 out.write('add_library(\n')
523 out.write(' %s\n\n' % name)
524
525 for f in sorted(files):
526 out.write(' %s\n' % PathOf(f))
527
528 out.write(')\n\n')
529
530 def PrintExe(self, out, name, files, libs):
531 out.write('add_executable(\n')
532 out.write(' %s\n\n' % name)
533
534 for f in sorted(files):
535 out.write(' %s\n' % PathOf(f))
536
537 out.write(')\n\n')
538 out.write('target_link_libraries(%s %s)\n\n' % (name, ' '.join(libs)))
539
540 def PrintSection(self, out, name, files):
541 out.write('set(\n')
542 out.write(' %s\n\n' % name)
543 for f in sorted(files):
544 out.write(' %s\n' % PathOf(f))
545 out.write(')\n\n')
546
547 def WriteFiles(self, files, asm_outputs):
548 with open('CMakeLists.txt', 'w+') as cmake:
549 cmake.write(self.header)
550
551 for ((osname, arch), asm_files) in asm_outputs:
552 self.PrintSection(cmake, 'CRYPTO_%s_%s_SOURCES' % (osname, arch),
553 asm_files)
554
555 cmake.write(
David Benjamin68addd22022-02-08 00:25:34 -0500556R'''if(APPLE)
David Benjamin351b2f82022-02-06 12:57:17 -0500557 set(CRYPTO_ARCH_SOURCES ${CRYPTO_apple_${ARCH}_SOURCES})
Adam Langleycfd80a92019-11-08 14:40:08 -0800558elseif(UNIX)
559 set(CRYPTO_ARCH_SOURCES ${CRYPTO_linux_${ARCH}_SOURCES})
560elseif(WIN32)
561 set(CRYPTO_ARCH_SOURCES ${CRYPTO_win_${ARCH}_SOURCES})
562endif()
563
564''')
565
566 self.PrintLibrary(cmake, 'crypto',
567 files['crypto'] + ['${CRYPTO_ARCH_SOURCES}'])
568 self.PrintLibrary(cmake, 'ssl', files['ssl'])
Adam Langleyff631132020-01-13 15:24:22 -0800569 self.PrintExe(cmake, 'bssl', files['tool'], ['ssl', 'crypto'])
570
571 cmake.write(
David Benjamin8f88b272020-07-09 13:35:01 -0400572R'''if(NOT WIN32 AND NOT ANDROID)
Adam Langleyff631132020-01-13 15:24:22 -0800573 target_link_libraries(crypto pthread)
574endif()
575
David Benjamin8f88b272020-07-09 13:35:01 -0400576if(WIN32)
577 target_link_libraries(bssl ws2_32)
578endif()
579
Adam Langleyff631132020-01-13 15:24:22 -0800580''')
David Benjamin38d01c62016-04-21 18:47:57 -0400581
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400582class JSON(object):
583 def WriteFiles(self, files, asm_outputs):
584 sources = dict(files)
585 for ((osname, arch), asm_files) in asm_outputs:
586 sources['crypto_%s_%s' % (osname, arch)] = asm_files
587 with open('sources.json', 'w+') as f:
588 json.dump(sources, f, sort_keys=True, indent=2)
589
Adam Langley9e1a6602015-05-05 17:47:53 -0700590def FindCMakeFiles(directory):
591 """Returns list of all CMakeLists.txt files recursively in directory."""
592 cmakefiles = []
593
594 for (path, _, filenames) in os.walk(directory):
595 for filename in filenames:
596 if filename == 'CMakeLists.txt':
597 cmakefiles.append(os.path.join(path, filename))
598
599 return cmakefiles
600
Adam Langleyfd499932017-04-04 14:21:43 -0700601def OnlyFIPSFragments(path, dent, is_dir):
Matthew Braithwaite95511e92017-05-08 16:38:03 -0700602 return is_dir or (path.startswith(
603 os.path.join('src', 'crypto', 'fipsmodule', '')) and
604 NoTests(path, dent, is_dir))
Adam Langley9e1a6602015-05-05 17:47:53 -0700605
Adam Langleyfd499932017-04-04 14:21:43 -0700606def NoTestsNorFIPSFragments(path, dent, is_dir):
Adam Langley323f1eb2017-04-06 17:29:10 -0700607 return (NoTests(path, dent, is_dir) and
608 (is_dir or not OnlyFIPSFragments(path, dent, is_dir)))
Adam Langleyfd499932017-04-04 14:21:43 -0700609
610def NoTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700611 """Filter function that can be passed to FindCFiles in order to remove test
612 sources."""
613 if is_dir:
614 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400615 return 'test.' not in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700616
617
Adam Langleyfd499932017-04-04 14:21:43 -0700618def OnlyTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700619 """Filter function that can be passed to FindCFiles in order to remove
620 non-test sources."""
621 if is_dir:
David Benjamin26073832015-05-11 20:52:48 -0400622 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400623 return '_test.' in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700624
625
Adam Langleyfd499932017-04-04 14:21:43 -0700626def AllFiles(path, dent, is_dir):
David Benjamin26073832015-05-11 20:52:48 -0400627 """Filter function that can be passed to FindCFiles in order to include all
628 sources."""
629 return True
630
631
Adam Langleyfd499932017-04-04 14:21:43 -0700632def NoTestRunnerFiles(path, dent, is_dir):
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700633 """Filter function that can be passed to FindCFiles or FindHeaderFiles in
634 order to exclude test runner files."""
635 # NOTE(martinkr): This prevents .h/.cc files in src/ssl/test/runner, which
636 # are in their own subpackage, from being included in boringssl/BUILD files.
637 return not is_dir or dent != 'runner'
638
639
David Benjamin3ecd0a52017-05-19 15:26:18 -0400640def NotGTestSupport(path, dent, is_dir):
David Benjaminc3889632019-03-01 15:03:05 -0500641 return 'gtest' not in dent and 'abi_test' not in dent
David Benjamin96628432017-01-19 19:05:47 -0500642
643
Adam Langleyfd499932017-04-04 14:21:43 -0700644def SSLHeaderFiles(path, dent, is_dir):
Aaron Green0e150022018-10-16 12:05:29 -0700645 return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h', 'srtp.h']
Adam Langley049ef412015-06-09 18:20:57 -0700646
647
Adam Langley9e1a6602015-05-05 17:47:53 -0700648def FindCFiles(directory, filter_func):
649 """Recurses through directory and returns a list of paths to all the C source
650 files that pass filter_func."""
651 cfiles = []
652
653 for (path, dirnames, filenames) in os.walk(directory):
654 for filename in filenames:
655 if not filename.endswith('.c') and not filename.endswith('.cc'):
656 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700657 if not filter_func(path, filename, False):
Adam Langley9e1a6602015-05-05 17:47:53 -0700658 continue
659 cfiles.append(os.path.join(path, filename))
660
661 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700662 if not filter_func(path, dirname, True):
Adam Langley9e1a6602015-05-05 17:47:53 -0700663 del dirnames[i]
664
David Benjaminedd4c5f2020-08-19 14:46:17 -0400665 cfiles.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700666 return cfiles
667
668
Adam Langley049ef412015-06-09 18:20:57 -0700669def FindHeaderFiles(directory, filter_func):
670 """Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
671 hfiles = []
672
673 for (path, dirnames, filenames) in os.walk(directory):
674 for filename in filenames:
675 if not filename.endswith('.h'):
676 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700677 if not filter_func(path, filename, False):
Adam Langley049ef412015-06-09 18:20:57 -0700678 continue
679 hfiles.append(os.path.join(path, filename))
680
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700681 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700682 if not filter_func(path, dirname, True):
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700683 del dirnames[i]
684
David Benjaminedd4c5f2020-08-19 14:46:17 -0400685 hfiles.sort()
Adam Langley049ef412015-06-09 18:20:57 -0700686 return hfiles
687
688
Adam Langley9e1a6602015-05-05 17:47:53 -0700689def ExtractPerlAsmFromCMakeFile(cmakefile):
690 """Parses the contents of the CMakeLists.txt file passed as an argument and
691 returns a list of all the perlasm() directives found in the file."""
692 perlasms = []
693 with open(cmakefile) as f:
694 for line in f:
695 line = line.strip()
696 if not line.startswith('perlasm('):
697 continue
698 if not line.endswith(')'):
699 raise ValueError('Bad perlasm line in %s' % cmakefile)
700 # Remove "perlasm(" from start and ")" from end
701 params = line[8:-1].split()
David Benjamin19676212023-01-25 10:03:53 -0500702 if len(params) != 4:
Adam Langley9e1a6602015-05-05 17:47:53 -0700703 raise ValueError('Bad perlasm line in %s' % cmakefile)
704 perlasms.append({
David Benjamin19676212023-01-25 10:03:53 -0500705 'arch': params[1],
706 'output': os.path.join(os.path.dirname(cmakefile), params[2]),
707 'input': os.path.join(os.path.dirname(cmakefile), params[3]),
Adam Langley9e1a6602015-05-05 17:47:53 -0700708 })
709
710 return perlasms
711
712
713def ReadPerlAsmOperations():
714 """Returns a list of all perlasm() directives found in CMake config files in
715 src/."""
716 perlasms = []
717 cmakefiles = FindCMakeFiles('src')
718
719 for cmakefile in cmakefiles:
720 perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile))
721
722 return perlasms
723
724
725def PerlAsm(output_filename, input_filename, perlasm_style, extra_args):
726 """Runs the a perlasm script and puts the output into output_filename."""
727 base_dir = os.path.dirname(output_filename)
728 if not os.path.isdir(base_dir):
729 os.makedirs(base_dir)
David Benjaminfdd8e9c2016-06-26 13:18:50 -0400730 subprocess.check_call(
731 ['perl', input_filename, perlasm_style] + extra_args + [output_filename])
Adam Langley9e1a6602015-05-05 17:47:53 -0700732
733
Adam Langley9e1a6602015-05-05 17:47:53 -0700734def WriteAsmFiles(perlasms):
735 """Generates asm files from perlasm directives for each supported OS x
736 platform combination."""
737 asmfiles = {}
738
David Benjamin19676212023-01-25 10:03:53 -0500739 for perlasm in perlasms:
740 for (osname, arch, perlasm_style, extra_args, asm_ext) in OS_ARCH_COMBOS:
741 if arch != perlasm['arch']:
742 continue
743 # TODO(https://crbug.com/boringssl/524): Now that we incorporate osname in
744 # the output filename, the asm files can just go in a single directory.
745 # For now, we keep them in target-specific directories to avoid breaking
746 # downstream scripts.
747 key = (osname, arch)
748 outDir = '%s-%s' % key
Adam Langley9e1a6602015-05-05 17:47:53 -0700749 output = perlasm['output']
750 if not output.startswith('src'):
751 raise ValueError('output missing src: %s' % output)
752 output = os.path.join(outDir, output[4:])
David Benjamin19676212023-01-25 10:03:53 -0500753 output = '%s-%s.%s' % (output, osname, asm_ext)
754 PerlAsm(output, perlasm['input'], perlasm_style, extra_args)
755 asmfiles.setdefault(key, []).append(output)
Adam Langley9e1a6602015-05-05 17:47:53 -0700756
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000757 for (key, non_perl_asm_files) in NON_PERL_FILES.items():
Adam Langley9e1a6602015-05-05 17:47:53 -0700758 asmfiles.setdefault(key, []).extend(non_perl_asm_files)
759
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000760 for files in asmfiles.values():
David Benjaminedd4c5f2020-08-19 14:46:17 -0400761 files.sort()
762
Adam Langley9e1a6602015-05-05 17:47:53 -0700763 return asmfiles
764
765
David Benjamin3ecd0a52017-05-19 15:26:18 -0400766def ExtractVariablesFromCMakeFile(cmakefile):
767 """Parses the contents of the CMakeLists.txt file passed as an argument and
768 returns a dictionary of exported source lists."""
769 variables = {}
770 in_set_command = False
771 set_command = []
772 with open(cmakefile) as f:
773 for line in f:
774 if '#' in line:
775 line = line[:line.index('#')]
776 line = line.strip()
777
778 if not in_set_command:
779 if line.startswith('set('):
780 in_set_command = True
781 set_command = []
782 elif line == ')':
783 in_set_command = False
784 if not set_command:
785 raise ValueError('Empty set command')
786 variables[set_command[0]] = set_command[1:]
787 else:
788 set_command.extend([c for c in line.split(' ') if c])
789
790 if in_set_command:
791 raise ValueError('Unfinished set command')
792 return variables
793
794
Adam Langley049ef412015-06-09 18:20:57 -0700795def main(platforms):
David Benjamin3ecd0a52017-05-19 15:26:18 -0400796 cmake = ExtractVariablesFromCMakeFile(os.path.join('src', 'sources.cmake'))
Andres Erbsen5b280a82017-10-30 15:58:33 +0000797 crypto_c_files = (FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments) +
Adam Langley7f028812019-10-18 14:48:11 -0700798 FindCFiles(os.path.join('src', 'third_party', 'fiat'), NoTestsNorFIPSFragments))
Adam Langleyfd499932017-04-04 14:21:43 -0700799 fips_fragments = FindCFiles(os.path.join('src', 'crypto', 'fipsmodule'), OnlyFIPSFragments)
Adam Langleyfeca9e52017-01-23 13:07:50 -0800800 ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
David Benjamin38d01c62016-04-21 18:47:57 -0400801 tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
Adam Langleyf11f2332016-06-30 11:56:19 -0700802 tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles)
Adam Langley9e1a6602015-05-05 17:47:53 -0700803
Pete Bentley44544d92019-08-15 15:01:26 +0100804 # BCM shared library C files
805 bcm_crypto_c_files = [
806 os.path.join('src', 'crypto', 'fipsmodule', 'bcm.c')
807 ]
808
Adam Langley9e1a6602015-05-05 17:47:53 -0700809 # Generate err_data.c
810 with open('err_data.c', 'w+') as err_data:
811 subprocess.check_call(['go', 'run', 'err_data_generate.go'],
812 cwd=os.path.join('src', 'crypto', 'err'),
813 stdout=err_data)
814 crypto_c_files.append('err_data.c')
David Benjaminedd4c5f2020-08-19 14:46:17 -0400815 crypto_c_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700816
David Benjamin38d01c62016-04-21 18:47:57 -0400817 test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
David Benjamin3ecd0a52017-05-19 15:26:18 -0400818 NotGTestSupport)
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700819 test_support_h_files = (
820 FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) +
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700821 FindHeaderFiles(os.path.join('src', 'ssl', 'test'), NoTestRunnerFiles))
David Benjamin26073832015-05-11 20:52:48 -0400822
Adam Langley990a3232018-05-22 10:02:59 -0700823 crypto_test_files = []
824 if EMBED_TEST_DATA:
825 # Generate crypto_test_data.cc
826 with open('crypto_test_data.cc', 'w+') as out:
827 subprocess.check_call(
828 ['go', 'run', 'util/embed_test_data.go'] + cmake['CRYPTO_TEST_DATA'],
829 cwd='src',
830 stdout=out)
831 crypto_test_files += ['crypto_test_data.cc']
David Benjamin3ecd0a52017-05-19 15:26:18 -0400832
Adam Langley990a3232018-05-22 10:02:59 -0700833 crypto_test_files += FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
David Benjamin96ee4a82017-07-09 23:46:47 -0400834 crypto_test_files += [
David Benjaminc3889632019-03-01 15:03:05 -0500835 'src/crypto/test/abi_test.cc',
David Benjamin3ecd0a52017-05-19 15:26:18 -0400836 'src/crypto/test/file_test_gtest.cc',
837 'src/crypto/test/gtest_main.cc',
838 ]
Adam Langley3e502c82019-10-16 09:56:38 -0700839 # urandom_test.cc is in a separate binary so that it can be test PRNG
840 # initialisation.
841 crypto_test_files = [
842 file for file in crypto_test_files
843 if not file.endswith('/urandom_test.cc')
844 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400845 crypto_test_files.sort()
David Benjamin1d5a5702017-02-13 22:11:49 -0500846
847 ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
Robert Sloanae1e0872019-03-01 16:01:30 -0800848 ssl_test_files += [
849 'src/crypto/test/abi_test.cc',
850 'src/crypto/test/gtest_main.cc',
851 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400852 ssl_test_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700853
Adam Langley3e502c82019-10-16 09:56:38 -0700854 urandom_test_files = [
855 'src/crypto/fipsmodule/rand/urandom_test.cc',
856 ]
857
David Benjamin38d01c62016-04-21 18:47:57 -0400858 fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
859
David Benjaminedd4c5f2020-08-19 14:46:17 -0400860 ssl_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
861 SSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700862
Adam Langleyfd499932017-04-04 14:21:43 -0700863 def NotSSLHeaderFiles(path, filename, is_dir):
864 return not SSLHeaderFiles(path, filename, is_dir)
David Benjaminedd4c5f2020-08-19 14:46:17 -0400865 crypto_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
866 NotSSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700867
868 ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
Andres Erbsen5b280a82017-10-30 15:58:33 +0000869 crypto_internal_h_files = (
870 FindHeaderFiles(os.path.join('src', 'crypto'), NoTests) +
Adam Langley7f028812019-10-18 14:48:11 -0700871 FindHeaderFiles(os.path.join('src', 'third_party', 'fiat'), NoTests))
Adam Langley049ef412015-06-09 18:20:57 -0700872
Adam Langley9e1a6602015-05-05 17:47:53 -0700873 files = {
Pete Bentley44544d92019-08-15 15:01:26 +0100874 'bcm_crypto': bcm_crypto_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700875 'crypto': crypto_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700876 'crypto_headers': crypto_h_files,
877 'crypto_internal_headers': crypto_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400878 'crypto_test': crypto_test_files,
Adam Langley990a3232018-05-22 10:02:59 -0700879 'crypto_test_data': sorted('src/' + x for x in cmake['CRYPTO_TEST_DATA']),
Adam Langleyfd499932017-04-04 14:21:43 -0700880 'fips_fragments': fips_fragments,
David Benjamin38d01c62016-04-21 18:47:57 -0400881 'fuzz': fuzz_c_files,
Adam Langleyfeca9e52017-01-23 13:07:50 -0800882 'ssl': ssl_source_files,
Adam Langley049ef412015-06-09 18:20:57 -0700883 'ssl_headers': ssl_h_files,
884 'ssl_internal_headers': ssl_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400885 'ssl_test': ssl_test_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400886 'tool': tool_c_files,
Adam Langleyf11f2332016-06-30 11:56:19 -0700887 'tool_headers': tool_h_files,
David Benjaminc5aa8412016-07-29 17:41:58 -0400888 'test_support': test_support_c_files,
889 'test_support_headers': test_support_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400890 'urandom_test': urandom_test_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700891 }
892
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000893 asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).items())
Adam Langley9e1a6602015-05-05 17:47:53 -0700894
Adam Langley049ef412015-06-09 18:20:57 -0700895 for platform in platforms:
896 platform.WriteFiles(files, asm_outputs)
Adam Langley9e1a6602015-05-05 17:47:53 -0700897
898 return 0
899
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400900ALL_PLATFORMS = {
901 'android': Android,
902 'android-cmake': AndroidCMake,
903 'bazel': Bazel,
904 'cmake': CMake,
905 'eureka': Eureka,
906 'gn': GN,
907 'gyp': GYP,
908 'json': JSON,
909}
Adam Langley9e1a6602015-05-05 17:47:53 -0700910
Adam Langley9e1a6602015-05-05 17:47:53 -0700911if __name__ == '__main__':
David Benjamin4acc7dd2022-11-19 10:13:49 -0500912 parser = optparse.OptionParser(
913 usage='Usage: %%prog [--prefix=<path>] [all|%s]' %
914 '|'.join(sorted(ALL_PLATFORMS.keys())))
Matt Braithwaite16695892016-06-09 09:34:11 -0700915 parser.add_option('--prefix', dest='prefix',
916 help='For Bazel, prepend argument to all source files')
Adam Langley990a3232018-05-22 10:02:59 -0700917 parser.add_option(
918 '--embed_test_data', type='choice', dest='embed_test_data',
919 action='store', default="true", choices=["true", "false"],
David Benjaminf014d602019-05-07 18:58:06 -0500920 help='For Bazel or GN, don\'t embed data files in crypto_test_data.cc')
Matt Braithwaite16695892016-06-09 09:34:11 -0700921 options, args = parser.parse_args(sys.argv[1:])
922 PREFIX = options.prefix
Adam Langley990a3232018-05-22 10:02:59 -0700923 EMBED_TEST_DATA = (options.embed_test_data == "true")
Matt Braithwaite16695892016-06-09 09:34:11 -0700924
925 if not args:
926 parser.print_help()
927 sys.exit(1)
Adam Langley9e1a6602015-05-05 17:47:53 -0700928
David Benjamin4acc7dd2022-11-19 10:13:49 -0500929 if 'all' in args:
930 platforms = [platform() for platform in ALL_PLATFORMS.values()]
931 else:
932 platforms = []
933 for s in args:
934 platform = ALL_PLATFORMS.get(s)
935 if platform is None:
936 parser.print_help()
937 sys.exit(1)
938 platforms.append(platform())
Adam Langley9e1a6602015-05-05 17:47:53 -0700939
Adam Langley049ef412015-06-09 18:20:57 -0700940 sys.exit(main(platforms))