blob: 383de02d20a26113298d277aea6811981d938545 [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 Benjamin741c1532023-01-25 17:37:16 -0500404cmake_minimum_required(VERSION 3.10)
Adam Langleycfd80a92019-11-08 14:40:08 -0800405
406project(BoringSSL LANGUAGES C CXX)
407
David Benjamin741c1532023-01-25 17:37:16 -0500408set(CMAKE_CXX_STANDARD 14)
409set(CMAKE_CXX_STANDARD_REQUIRED ON)
410set(CMAKE_C_STANDARD 11)
411set(CMAKE_C_STANDARD_REQUIRED ON)
412if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
413 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fno-common -fno-exceptions -fno-rtti")
414 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fno-common")
Adam Langleycfd80a92019-11-08 14:40:08 -0800415endif()
416
David Benjamin741c1532023-01-25 17:37:16 -0500417# pthread_rwlock_t requires a feature flag on glibc.
418if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
Adam Langleycfd80a92019-11-08 14:40:08 -0800419 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)
Adam Langleycfd80a92019-11-08 14:40:08 -0800428endif()
429
430add_definitions(-DBORINGSSL_IMPLEMENTATION)
431
Adam Langleycfd80a92019-11-08 14:40:08 -0800432if(NOT OPENSSL_NO_ASM)
David Benjamin741c1532023-01-25 17:37:16 -0500433 # On x86 and x86_64 Windows, we use the NASM output.
434 if(WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|x86_64|amd64|x86|i[3-6]86")
435 enable_language(ASM_NASM)
436 set(OPENSSL_NASM TRUE)
437 set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8")
438 else()
Adam Langleycfd80a92019-11-08 14:40:08 -0800439 enable_language(ASM)
David Benjamin741c1532023-01-25 17:37:16 -0500440 set(OPENSSL_ASM TRUE)
Adam Langleycfd80a92019-11-08 14:40:08 -0800441 # CMake does not add -isysroot and -arch flags to assembly.
442 if(APPLE)
443 if(CMAKE_OSX_SYSROOT)
444 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"")
445 endif()
446 foreach(arch ${CMAKE_OSX_ARCHITECTURES})
447 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}")
448 endforeach()
449 endif()
David Benjamin741c1532023-01-25 17:37:16 -0500450 if(NOT WIN32)
451 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack")
452 endif()
453 # Clang's integerated assembler does not support debug symbols.
454 if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang")
455 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g")
456 endif()
Adam Langleycfd80a92019-11-08 14:40:08 -0800457 endif()
458endif()
459
Adam Langleya0cdbf92020-01-21 09:07:46 -0800460if(BUILD_SHARED_LIBS)
461 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
462 # Enable position-independent code globally. This is needed because
463 # some library targets are OBJECT libraries.
464 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
465endif()
466
Adam Langleycfd80a92019-11-08 14:40:08 -0800467include_directories(src/include)
468
469'''
470
471 def PrintLibrary(self, out, name, files):
472 out.write('add_library(\n')
473 out.write(' %s\n\n' % name)
474
475 for f in sorted(files):
476 out.write(' %s\n' % PathOf(f))
477
478 out.write(')\n\n')
479
480 def PrintExe(self, out, name, files, libs):
481 out.write('add_executable(\n')
482 out.write(' %s\n\n' % name)
483
484 for f in sorted(files):
485 out.write(' %s\n' % PathOf(f))
486
487 out.write(')\n\n')
488 out.write('target_link_libraries(%s %s)\n\n' % (name, ' '.join(libs)))
489
David Benjamin741c1532023-01-25 17:37:16 -0500490 def PrintVariable(self, out, name, files):
Adam Langleycfd80a92019-11-08 14:40:08 -0800491 out.write('set(\n')
492 out.write(' %s\n\n' % name)
493 for f in sorted(files):
494 out.write(' %s\n' % PathOf(f))
495 out.write(')\n\n')
496
497 def WriteFiles(self, files, asm_outputs):
498 with open('CMakeLists.txt', 'w+') as cmake:
499 cmake.write(self.header)
500
David Benjamin741c1532023-01-25 17:37:16 -0500501 asm_sources = []
502 nasm_sources = []
Adam Langleycfd80a92019-11-08 14:40:08 -0800503 for ((osname, arch), asm_files) in asm_outputs:
David Benjamin741c1532023-01-25 17:37:16 -0500504 if (osname, arch) in (('win', 'x86'), ('win', 'x86_64')):
505 nasm_sources.extend(asm_files)
506 else:
507 asm_sources.extend(asm_files)
508 self.PrintVariable(cmake, 'CRYPTO_SOURCES_ASM', sorted(asm_sources))
509 self.PrintVariable(cmake, 'CRYPTO_SOURCES_NASM', sorted(nasm_sources))
Adam Langleycfd80a92019-11-08 14:40:08 -0800510
511 cmake.write(
David Benjamin741c1532023-01-25 17:37:16 -0500512R'''if(OPENSSL_ASM)
513 list(APPEND CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_ASM})
514endif()
515if(OPENSSL_NASM)
516 list(APPEND CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_NASM})
Adam Langleycfd80a92019-11-08 14:40:08 -0800517endif()
518
519''')
520
521 self.PrintLibrary(cmake, 'crypto',
David Benjamin741c1532023-01-25 17:37:16 -0500522 files['crypto'] + ['${CRYPTO_SOURCES_ASM_USED}'])
Adam Langleycfd80a92019-11-08 14:40:08 -0800523 self.PrintLibrary(cmake, 'ssl', files['ssl'])
Adam Langleyff631132020-01-13 15:24:22 -0800524 self.PrintExe(cmake, 'bssl', files['tool'], ['ssl', 'crypto'])
525
526 cmake.write(
David Benjamin741c1532023-01-25 17:37:16 -0500527R'''if(NOT ANDROID)
528 find_package(Threads REQUIRED)
529 target_link_libraries(crypto Threads::Threads)
Adam Langleyff631132020-01-13 15:24:22 -0800530endif()
531
David Benjamin8f88b272020-07-09 13:35:01 -0400532if(WIN32)
533 target_link_libraries(bssl ws2_32)
534endif()
535
Adam Langleyff631132020-01-13 15:24:22 -0800536''')
David Benjamin38d01c62016-04-21 18:47:57 -0400537
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400538class JSON(object):
539 def WriteFiles(self, files, asm_outputs):
540 sources = dict(files)
541 for ((osname, arch), asm_files) in asm_outputs:
542 sources['crypto_%s_%s' % (osname, arch)] = asm_files
543 with open('sources.json', 'w+') as f:
544 json.dump(sources, f, sort_keys=True, indent=2)
545
Adam Langley9e1a6602015-05-05 17:47:53 -0700546def FindCMakeFiles(directory):
547 """Returns list of all CMakeLists.txt files recursively in directory."""
548 cmakefiles = []
549
550 for (path, _, filenames) in os.walk(directory):
551 for filename in filenames:
552 if filename == 'CMakeLists.txt':
553 cmakefiles.append(os.path.join(path, filename))
554
555 return cmakefiles
556
Adam Langleyfd499932017-04-04 14:21:43 -0700557def OnlyFIPSFragments(path, dent, is_dir):
Matthew Braithwaite95511e92017-05-08 16:38:03 -0700558 return is_dir or (path.startswith(
559 os.path.join('src', 'crypto', 'fipsmodule', '')) and
560 NoTests(path, dent, is_dir))
Adam Langley9e1a6602015-05-05 17:47:53 -0700561
Adam Langleyfd499932017-04-04 14:21:43 -0700562def NoTestsNorFIPSFragments(path, dent, is_dir):
Adam Langley323f1eb2017-04-06 17:29:10 -0700563 return (NoTests(path, dent, is_dir) and
564 (is_dir or not OnlyFIPSFragments(path, dent, is_dir)))
Adam Langleyfd499932017-04-04 14:21:43 -0700565
566def NoTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700567 """Filter function that can be passed to FindCFiles in order to remove test
568 sources."""
569 if is_dir:
570 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400571 return 'test.' not in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700572
573
Adam Langleyfd499932017-04-04 14:21:43 -0700574def OnlyTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700575 """Filter function that can be passed to FindCFiles in order to remove
576 non-test sources."""
577 if is_dir:
David Benjamin26073832015-05-11 20:52:48 -0400578 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400579 return '_test.' in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700580
581
Adam Langleyfd499932017-04-04 14:21:43 -0700582def AllFiles(path, dent, is_dir):
David Benjamin26073832015-05-11 20:52:48 -0400583 """Filter function that can be passed to FindCFiles in order to include all
584 sources."""
585 return True
586
587
Adam Langleyfd499932017-04-04 14:21:43 -0700588def NoTestRunnerFiles(path, dent, is_dir):
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700589 """Filter function that can be passed to FindCFiles or FindHeaderFiles in
590 order to exclude test runner files."""
591 # NOTE(martinkr): This prevents .h/.cc files in src/ssl/test/runner, which
592 # are in their own subpackage, from being included in boringssl/BUILD files.
593 return not is_dir or dent != 'runner'
594
595
David Benjamin3ecd0a52017-05-19 15:26:18 -0400596def NotGTestSupport(path, dent, is_dir):
David Benjaminc3889632019-03-01 15:03:05 -0500597 return 'gtest' not in dent and 'abi_test' not in dent
David Benjamin96628432017-01-19 19:05:47 -0500598
599
Adam Langleyfd499932017-04-04 14:21:43 -0700600def SSLHeaderFiles(path, dent, is_dir):
Aaron Green0e150022018-10-16 12:05:29 -0700601 return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h', 'srtp.h']
Adam Langley049ef412015-06-09 18:20:57 -0700602
603
Adam Langley9e1a6602015-05-05 17:47:53 -0700604def FindCFiles(directory, filter_func):
605 """Recurses through directory and returns a list of paths to all the C source
606 files that pass filter_func."""
607 cfiles = []
608
609 for (path, dirnames, filenames) in os.walk(directory):
610 for filename in filenames:
611 if not filename.endswith('.c') and not filename.endswith('.cc'):
612 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700613 if not filter_func(path, filename, False):
Adam Langley9e1a6602015-05-05 17:47:53 -0700614 continue
615 cfiles.append(os.path.join(path, filename))
616
617 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700618 if not filter_func(path, dirname, True):
Adam Langley9e1a6602015-05-05 17:47:53 -0700619 del dirnames[i]
620
David Benjaminedd4c5f2020-08-19 14:46:17 -0400621 cfiles.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700622 return cfiles
623
624
Adam Langley049ef412015-06-09 18:20:57 -0700625def FindHeaderFiles(directory, filter_func):
626 """Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
627 hfiles = []
628
629 for (path, dirnames, filenames) in os.walk(directory):
630 for filename in filenames:
631 if not filename.endswith('.h'):
632 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700633 if not filter_func(path, filename, False):
Adam Langley049ef412015-06-09 18:20:57 -0700634 continue
635 hfiles.append(os.path.join(path, filename))
636
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700637 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700638 if not filter_func(path, dirname, True):
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700639 del dirnames[i]
640
David Benjaminedd4c5f2020-08-19 14:46:17 -0400641 hfiles.sort()
Adam Langley049ef412015-06-09 18:20:57 -0700642 return hfiles
643
644
Adam Langley9e1a6602015-05-05 17:47:53 -0700645def ExtractPerlAsmFromCMakeFile(cmakefile):
646 """Parses the contents of the CMakeLists.txt file passed as an argument and
647 returns a list of all the perlasm() directives found in the file."""
648 perlasms = []
649 with open(cmakefile) as f:
650 for line in f:
651 line = line.strip()
652 if not line.startswith('perlasm('):
653 continue
654 if not line.endswith(')'):
655 raise ValueError('Bad perlasm line in %s' % cmakefile)
656 # Remove "perlasm(" from start and ")" from end
657 params = line[8:-1].split()
David Benjamin19676212023-01-25 10:03:53 -0500658 if len(params) != 4:
Adam Langley9e1a6602015-05-05 17:47:53 -0700659 raise ValueError('Bad perlasm line in %s' % cmakefile)
660 perlasms.append({
David Benjamin19676212023-01-25 10:03:53 -0500661 'arch': params[1],
662 'output': os.path.join(os.path.dirname(cmakefile), params[2]),
663 'input': os.path.join(os.path.dirname(cmakefile), params[3]),
Adam Langley9e1a6602015-05-05 17:47:53 -0700664 })
665
666 return perlasms
667
668
669def ReadPerlAsmOperations():
670 """Returns a list of all perlasm() directives found in CMake config files in
671 src/."""
672 perlasms = []
673 cmakefiles = FindCMakeFiles('src')
674
675 for cmakefile in cmakefiles:
676 perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile))
677
678 return perlasms
679
680
681def PerlAsm(output_filename, input_filename, perlasm_style, extra_args):
682 """Runs the a perlasm script and puts the output into output_filename."""
683 base_dir = os.path.dirname(output_filename)
684 if not os.path.isdir(base_dir):
685 os.makedirs(base_dir)
David Benjaminfdd8e9c2016-06-26 13:18:50 -0400686 subprocess.check_call(
687 ['perl', input_filename, perlasm_style] + extra_args + [output_filename])
Adam Langley9e1a6602015-05-05 17:47:53 -0700688
689
Adam Langley9e1a6602015-05-05 17:47:53 -0700690def WriteAsmFiles(perlasms):
691 """Generates asm files from perlasm directives for each supported OS x
692 platform combination."""
693 asmfiles = {}
694
David Benjamin19676212023-01-25 10:03:53 -0500695 for perlasm in perlasms:
696 for (osname, arch, perlasm_style, extra_args, asm_ext) in OS_ARCH_COMBOS:
697 if arch != perlasm['arch']:
698 continue
699 # TODO(https://crbug.com/boringssl/524): Now that we incorporate osname in
700 # the output filename, the asm files can just go in a single directory.
701 # For now, we keep them in target-specific directories to avoid breaking
702 # downstream scripts.
703 key = (osname, arch)
704 outDir = '%s-%s' % key
Adam Langley9e1a6602015-05-05 17:47:53 -0700705 output = perlasm['output']
706 if not output.startswith('src'):
707 raise ValueError('output missing src: %s' % output)
708 output = os.path.join(outDir, output[4:])
David Benjamin19676212023-01-25 10:03:53 -0500709 output = '%s-%s.%s' % (output, osname, asm_ext)
710 PerlAsm(output, perlasm['input'], perlasm_style, extra_args)
711 asmfiles.setdefault(key, []).append(output)
Adam Langley9e1a6602015-05-05 17:47:53 -0700712
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000713 for (key, non_perl_asm_files) in NON_PERL_FILES.items():
Adam Langley9e1a6602015-05-05 17:47:53 -0700714 asmfiles.setdefault(key, []).extend(non_perl_asm_files)
715
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000716 for files in asmfiles.values():
David Benjaminedd4c5f2020-08-19 14:46:17 -0400717 files.sort()
718
Adam Langley9e1a6602015-05-05 17:47:53 -0700719 return asmfiles
720
721
David Benjamin3ecd0a52017-05-19 15:26:18 -0400722def ExtractVariablesFromCMakeFile(cmakefile):
723 """Parses the contents of the CMakeLists.txt file passed as an argument and
724 returns a dictionary of exported source lists."""
725 variables = {}
726 in_set_command = False
727 set_command = []
728 with open(cmakefile) as f:
729 for line in f:
730 if '#' in line:
731 line = line[:line.index('#')]
732 line = line.strip()
733
734 if not in_set_command:
735 if line.startswith('set('):
736 in_set_command = True
737 set_command = []
738 elif line == ')':
739 in_set_command = False
740 if not set_command:
741 raise ValueError('Empty set command')
742 variables[set_command[0]] = set_command[1:]
743 else:
744 set_command.extend([c for c in line.split(' ') if c])
745
746 if in_set_command:
747 raise ValueError('Unfinished set command')
748 return variables
749
750
Adam Langley049ef412015-06-09 18:20:57 -0700751def main(platforms):
David Benjamin3ecd0a52017-05-19 15:26:18 -0400752 cmake = ExtractVariablesFromCMakeFile(os.path.join('src', 'sources.cmake'))
Andres Erbsen5b280a82017-10-30 15:58:33 +0000753 crypto_c_files = (FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments) +
Adam Langley7f028812019-10-18 14:48:11 -0700754 FindCFiles(os.path.join('src', 'third_party', 'fiat'), NoTestsNorFIPSFragments))
Adam Langleyfd499932017-04-04 14:21:43 -0700755 fips_fragments = FindCFiles(os.path.join('src', 'crypto', 'fipsmodule'), OnlyFIPSFragments)
Adam Langleyfeca9e52017-01-23 13:07:50 -0800756 ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
David Benjamin38d01c62016-04-21 18:47:57 -0400757 tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
Adam Langleyf11f2332016-06-30 11:56:19 -0700758 tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles)
Adam Langley9e1a6602015-05-05 17:47:53 -0700759
Pete Bentley44544d92019-08-15 15:01:26 +0100760 # BCM shared library C files
761 bcm_crypto_c_files = [
762 os.path.join('src', 'crypto', 'fipsmodule', 'bcm.c')
763 ]
764
Adam Langley9e1a6602015-05-05 17:47:53 -0700765 # Generate err_data.c
766 with open('err_data.c', 'w+') as err_data:
767 subprocess.check_call(['go', 'run', 'err_data_generate.go'],
768 cwd=os.path.join('src', 'crypto', 'err'),
769 stdout=err_data)
770 crypto_c_files.append('err_data.c')
David Benjaminedd4c5f2020-08-19 14:46:17 -0400771 crypto_c_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700772
David Benjamin38d01c62016-04-21 18:47:57 -0400773 test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
David Benjamin3ecd0a52017-05-19 15:26:18 -0400774 NotGTestSupport)
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700775 test_support_h_files = (
776 FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) +
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700777 FindHeaderFiles(os.path.join('src', 'ssl', 'test'), NoTestRunnerFiles))
David Benjamin26073832015-05-11 20:52:48 -0400778
Adam Langley990a3232018-05-22 10:02:59 -0700779 crypto_test_files = []
780 if EMBED_TEST_DATA:
781 # Generate crypto_test_data.cc
782 with open('crypto_test_data.cc', 'w+') as out:
783 subprocess.check_call(
784 ['go', 'run', 'util/embed_test_data.go'] + cmake['CRYPTO_TEST_DATA'],
785 cwd='src',
786 stdout=out)
787 crypto_test_files += ['crypto_test_data.cc']
David Benjamin3ecd0a52017-05-19 15:26:18 -0400788
Adam Langley990a3232018-05-22 10:02:59 -0700789 crypto_test_files += FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
David Benjamin96ee4a82017-07-09 23:46:47 -0400790 crypto_test_files += [
David Benjaminc3889632019-03-01 15:03:05 -0500791 'src/crypto/test/abi_test.cc',
David Benjamin3ecd0a52017-05-19 15:26:18 -0400792 'src/crypto/test/file_test_gtest.cc',
793 'src/crypto/test/gtest_main.cc',
794 ]
Adam Langley3e502c82019-10-16 09:56:38 -0700795 # urandom_test.cc is in a separate binary so that it can be test PRNG
796 # initialisation.
797 crypto_test_files = [
798 file for file in crypto_test_files
799 if not file.endswith('/urandom_test.cc')
800 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400801 crypto_test_files.sort()
David Benjamin1d5a5702017-02-13 22:11:49 -0500802
803 ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
Robert Sloanae1e0872019-03-01 16:01:30 -0800804 ssl_test_files += [
805 'src/crypto/test/abi_test.cc',
806 'src/crypto/test/gtest_main.cc',
807 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400808 ssl_test_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700809
Adam Langley3e502c82019-10-16 09:56:38 -0700810 urandom_test_files = [
811 'src/crypto/fipsmodule/rand/urandom_test.cc',
812 ]
813
David Benjamin38d01c62016-04-21 18:47:57 -0400814 fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
815
David Benjaminedd4c5f2020-08-19 14:46:17 -0400816 ssl_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
817 SSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700818
Adam Langleyfd499932017-04-04 14:21:43 -0700819 def NotSSLHeaderFiles(path, filename, is_dir):
820 return not SSLHeaderFiles(path, filename, is_dir)
David Benjaminedd4c5f2020-08-19 14:46:17 -0400821 crypto_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
822 NotSSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700823
824 ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
Andres Erbsen5b280a82017-10-30 15:58:33 +0000825 crypto_internal_h_files = (
826 FindHeaderFiles(os.path.join('src', 'crypto'), NoTests) +
Adam Langley7f028812019-10-18 14:48:11 -0700827 FindHeaderFiles(os.path.join('src', 'third_party', 'fiat'), NoTests))
Adam Langley049ef412015-06-09 18:20:57 -0700828
Adam Langley9e1a6602015-05-05 17:47:53 -0700829 files = {
Pete Bentley44544d92019-08-15 15:01:26 +0100830 'bcm_crypto': bcm_crypto_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700831 'crypto': crypto_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700832 'crypto_headers': crypto_h_files,
833 'crypto_internal_headers': crypto_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400834 'crypto_test': crypto_test_files,
Adam Langley990a3232018-05-22 10:02:59 -0700835 'crypto_test_data': sorted('src/' + x for x in cmake['CRYPTO_TEST_DATA']),
Adam Langleyfd499932017-04-04 14:21:43 -0700836 'fips_fragments': fips_fragments,
David Benjamin38d01c62016-04-21 18:47:57 -0400837 'fuzz': fuzz_c_files,
Adam Langleyfeca9e52017-01-23 13:07:50 -0800838 'ssl': ssl_source_files,
Adam Langley049ef412015-06-09 18:20:57 -0700839 'ssl_headers': ssl_h_files,
840 'ssl_internal_headers': ssl_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400841 'ssl_test': ssl_test_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400842 'tool': tool_c_files,
Adam Langleyf11f2332016-06-30 11:56:19 -0700843 'tool_headers': tool_h_files,
David Benjaminc5aa8412016-07-29 17:41:58 -0400844 'test_support': test_support_c_files,
845 'test_support_headers': test_support_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400846 'urandom_test': urandom_test_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700847 }
848
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000849 asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).items())
Adam Langley9e1a6602015-05-05 17:47:53 -0700850
Adam Langley049ef412015-06-09 18:20:57 -0700851 for platform in platforms:
852 platform.WriteFiles(files, asm_outputs)
Adam Langley9e1a6602015-05-05 17:47:53 -0700853
854 return 0
855
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400856ALL_PLATFORMS = {
857 'android': Android,
858 'android-cmake': AndroidCMake,
859 'bazel': Bazel,
860 'cmake': CMake,
861 'eureka': Eureka,
862 'gn': GN,
863 'gyp': GYP,
864 'json': JSON,
865}
Adam Langley9e1a6602015-05-05 17:47:53 -0700866
Adam Langley9e1a6602015-05-05 17:47:53 -0700867if __name__ == '__main__':
David Benjamin4acc7dd2022-11-19 10:13:49 -0500868 parser = optparse.OptionParser(
869 usage='Usage: %%prog [--prefix=<path>] [all|%s]' %
870 '|'.join(sorted(ALL_PLATFORMS.keys())))
Matt Braithwaite16695892016-06-09 09:34:11 -0700871 parser.add_option('--prefix', dest='prefix',
872 help='For Bazel, prepend argument to all source files')
Adam Langley990a3232018-05-22 10:02:59 -0700873 parser.add_option(
874 '--embed_test_data', type='choice', dest='embed_test_data',
875 action='store', default="true", choices=["true", "false"],
David Benjaminf014d602019-05-07 18:58:06 -0500876 help='For Bazel or GN, don\'t embed data files in crypto_test_data.cc')
Matt Braithwaite16695892016-06-09 09:34:11 -0700877 options, args = parser.parse_args(sys.argv[1:])
878 PREFIX = options.prefix
Adam Langley990a3232018-05-22 10:02:59 -0700879 EMBED_TEST_DATA = (options.embed_test_data == "true")
Matt Braithwaite16695892016-06-09 09:34:11 -0700880
881 if not args:
882 parser.print_help()
883 sys.exit(1)
Adam Langley9e1a6602015-05-05 17:47:53 -0700884
David Benjamin4acc7dd2022-11-19 10:13:49 -0500885 if 'all' in args:
886 platforms = [platform() for platform in ALL_PLATFORMS.values()]
887 else:
888 platforms = []
889 for s in args:
890 platform = ALL_PLATFORMS.get(s)
891 if platform is None:
892 parser.print_help()
893 sys.exit(1)
894 platforms.append(platform())
Adam Langley9e1a6602015-05-05 17:47:53 -0700895
Adam Langley049ef412015-06-09 18:20:57 -0700896 sys.exit(main(platforms))