blob: ca173c8ba26b91ef4d97c705a7bf59b8070a6903 [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
David Benjamin23776d02022-12-09 11:33:17 -0500258 # Generate combined source lists for gas and nasm. Consumers have a choice
259 # of using the per-platform ones or the combined ones. In the combined
260 # mode, Windows x86 and Windows x86_64 must still be special-cased, but
261 # otherwise all assembly files can be linked together.
262 out.write('\n')
263 out.write('crypto_sources_asm = []\n')
264 for (osname, arch, _, _, asm_ext) in OS_ARCH_COMBOS:
265 if asm_ext == 'S':
266 out.write('crypto_sources_asm.extend(crypto_sources_%s_%s)\n' %
267 (osname, arch))
268 out.write('\n')
269 out.write('crypto_sources_nasm = []\n')
270 for (osname, arch, _, _, asm_ext) in OS_ARCH_COMBOS:
271 if asm_ext == 'asm':
272 out.write('crypto_sources_nasm.extend(crypto_sources_%s_%s)\n' %
273 (osname, arch))
274
Chuck Haysc608d6b2015-10-06 17:54:16 -0700275 with open('BUILD.generated_tests.bzl', 'w+') as out:
Adam Langley9c164b22015-06-10 18:54:47 -0700276 out.write(self.header)
277
278 out.write('test_support_sources = [\n')
David Benjaminc5aa8412016-07-29 17:41:58 -0400279 for filename in sorted(files['test_support'] +
280 files['test_support_headers'] +
281 files['crypto_internal_headers'] +
282 files['ssl_internal_headers']):
Adam Langley9c164b22015-06-10 18:54:47 -0700283 if os.path.basename(filename) == 'malloc.cc':
284 continue
Matt Braithwaite16695892016-06-09 09:34:11 -0700285 out.write(' "%s",\n' % PathOf(filename))
Adam Langley9c164b22015-06-10 18:54:47 -0700286
Adam Langley7b6acc52017-07-27 16:33:27 -0700287 out.write(']\n')
Chuck Haysc608d6b2015-10-06 17:54:16 -0700288
David Benjamin96628432017-01-19 19:05:47 -0500289 self.PrintVariableSection(out, 'crypto_test_sources',
290 files['crypto_test'])
291 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
Adam Langley990a3232018-05-22 10:02:59 -0700292 self.PrintVariableSection(out, 'crypto_test_data',
293 files['crypto_test_data'])
Adam Langley3e502c82019-10-16 09:56:38 -0700294 self.PrintVariableSection(out, 'urandom_test_sources',
295 files['urandom_test'])
David Benjamin96628432017-01-19 19:05:47 -0500296
Adam Langley049ef412015-06-09 18:20:57 -0700297
Robert Sloane091af42017-10-09 12:47:17 -0700298class Eureka(object):
299
300 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -0500301 self.header = LicenseHeader("#") + """
Robert Sloane091af42017-10-09 12:47:17 -0700302# This file is created by generate_build_files.py. Do not edit manually.
303
304"""
305
306 def PrintVariableSection(self, out, name, files):
307 out.write('%s := \\\n' % name)
308 for f in sorted(files):
309 out.write(' %s\\\n' % f)
310 out.write('\n')
311
312 def WriteFiles(self, files, asm_outputs):
313 # Legacy Android.mk format
314 with open('eureka.mk', 'w+') as makefile:
315 makefile.write(self.header)
316
317 self.PrintVariableSection(makefile, 'crypto_sources', files['crypto'])
318 self.PrintVariableSection(makefile, 'ssl_sources', files['ssl'])
319 self.PrintVariableSection(makefile, 'tool_sources', files['tool'])
320
321 for ((osname, arch), asm_files) in asm_outputs:
322 if osname != 'linux':
323 continue
324 self.PrintVariableSection(
325 makefile, '%s_%s_sources' % (osname, arch), asm_files)
326
327
David Benjamin38d01c62016-04-21 18:47:57 -0400328class GN(object):
329
330 def __init__(self):
331 self.firstSection = True
David Benjamin70690f72023-01-25 09:56:43 -0500332 self.header = LicenseHeader("#") + """
David Benjamin38d01c62016-04-21 18:47:57 -0400333# This file is created by generate_build_files.py. Do not edit manually.
334
335"""
336
337 def PrintVariableSection(self, out, name, files):
338 if not self.firstSection:
339 out.write('\n')
340 self.firstSection = False
341
342 out.write('%s = [\n' % name)
343 for f in sorted(files):
344 out.write(' "%s",\n' % f)
345 out.write(']\n')
346
347 def WriteFiles(self, files, asm_outputs):
348 with open('BUILD.generated.gni', 'w+') as out:
349 out.write(self.header)
350
David Benjaminc5aa8412016-07-29 17:41:58 -0400351 self.PrintVariableSection(out, 'crypto_sources',
James Robinson98dd68f2018-04-11 14:47:34 -0700352 files['crypto'] +
David Benjaminc5aa8412016-07-29 17:41:58 -0400353 files['crypto_internal_headers'])
James Robinson98dd68f2018-04-11 14:47:34 -0700354 self.PrintVariableSection(out, 'crypto_headers',
355 files['crypto_headers'])
David Benjaminc5aa8412016-07-29 17:41:58 -0400356 self.PrintVariableSection(out, 'ssl_sources',
James Robinson98dd68f2018-04-11 14:47:34 -0700357 files['ssl'] + files['ssl_internal_headers'])
358 self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
David Benjaminbb0cb952020-12-17 16:35:39 -0500359 self.PrintVariableSection(out, 'tool_sources',
360 files['tool'] + files['tool_headers'])
David Benjamin38d01c62016-04-21 18:47:57 -0400361
362 for ((osname, arch), asm_files) in asm_outputs:
363 self.PrintVariableSection(
364 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
365
366 fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0]
367 for fuzzer in files['fuzz']]
368 self.PrintVariableSection(out, 'fuzzers', fuzzers)
369
370 with open('BUILD.generated_tests.gni', 'w+') as out:
371 self.firstSection = True
372 out.write(self.header)
373
David Benjamin96628432017-01-19 19:05:47 -0500374 self.PrintVariableSection(out, 'test_support_sources',
David Benjaminc5aa8412016-07-29 17:41:58 -0400375 files['test_support'] +
376 files['test_support_headers'])
David Benjamin96628432017-01-19 19:05:47 -0500377 self.PrintVariableSection(out, 'crypto_test_sources',
378 files['crypto_test'])
David Benjaminf014d602019-05-07 18:58:06 -0500379 self.PrintVariableSection(out, 'crypto_test_data',
380 files['crypto_test_data'])
David Benjamin96628432017-01-19 19:05:47 -0500381 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
David Benjamin38d01c62016-04-21 18:47:57 -0400382
383
384class GYP(object):
385
386 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -0500387 self.header = LicenseHeader("#") + """
David Benjamin38d01c62016-04-21 18:47:57 -0400388# This file is created by generate_build_files.py. Do not edit manually.
389
390"""
391
392 def PrintVariableSection(self, out, name, files):
393 out.write(' \'%s\': [\n' % name)
394 for f in sorted(files):
395 out.write(' \'%s\',\n' % f)
396 out.write(' ],\n')
397
398 def WriteFiles(self, files, asm_outputs):
399 with open('boringssl.gypi', 'w+') as gypi:
400 gypi.write(self.header + '{\n \'variables\': {\n')
401
David Benjaminc5aa8412016-07-29 17:41:58 -0400402 self.PrintVariableSection(gypi, 'boringssl_ssl_sources',
403 files['ssl'] + files['ssl_headers'] +
404 files['ssl_internal_headers'])
405 self.PrintVariableSection(gypi, 'boringssl_crypto_sources',
406 files['crypto'] + files['crypto_headers'] +
407 files['crypto_internal_headers'])
David Benjamin38d01c62016-04-21 18:47:57 -0400408
409 for ((osname, arch), asm_files) in asm_outputs:
410 self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' %
411 (osname, arch), asm_files)
412
413 gypi.write(' }\n}\n')
414
Adam Langleycfd80a92019-11-08 14:40:08 -0800415class CMake(object):
416
417 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -0500418 self.header = LicenseHeader("#") + R'''
Adam Langleycfd80a92019-11-08 14:40:08 -0800419# This file is created by generate_build_files.py. Do not edit manually.
420
David Benjamin741c1532023-01-25 17:37:16 -0500421cmake_minimum_required(VERSION 3.10)
Adam Langleycfd80a92019-11-08 14:40:08 -0800422
423project(BoringSSL LANGUAGES C CXX)
424
David Benjamin741c1532023-01-25 17:37:16 -0500425set(CMAKE_CXX_STANDARD 14)
426set(CMAKE_CXX_STANDARD_REQUIRED ON)
427set(CMAKE_C_STANDARD 11)
428set(CMAKE_C_STANDARD_REQUIRED ON)
429if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
430 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fno-common -fno-exceptions -fno-rtti")
431 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fno-common")
Adam Langleycfd80a92019-11-08 14:40:08 -0800432endif()
433
David Benjamin741c1532023-01-25 17:37:16 -0500434# pthread_rwlock_t requires a feature flag on glibc.
435if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
Adam Langleycfd80a92019-11-08 14:40:08 -0800436 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
437endif()
438
439if(WIN32)
440 add_definitions(-D_HAS_EXCEPTIONS=0)
441 add_definitions(-DWIN32_LEAN_AND_MEAN)
442 add_definitions(-DNOMINMAX)
443 # Allow use of fopen.
444 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
Adam Langleycfd80a92019-11-08 14:40:08 -0800445endif()
446
447add_definitions(-DBORINGSSL_IMPLEMENTATION)
448
David Benjamin67bb28c2023-02-01 14:40:03 -0500449if(OPENSSL_NO_ASM)
450 add_definitions(-DOPENSSL_NO_ASM)
451else()
David Benjamin741c1532023-01-25 17:37:16 -0500452 # On x86 and x86_64 Windows, we use the NASM output.
453 if(WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|x86_64|amd64|x86|i[3-6]86")
454 enable_language(ASM_NASM)
455 set(OPENSSL_NASM TRUE)
456 set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8")
457 else()
Adam Langleycfd80a92019-11-08 14:40:08 -0800458 enable_language(ASM)
David Benjamin741c1532023-01-25 17:37:16 -0500459 set(OPENSSL_ASM TRUE)
Adam Langleycfd80a92019-11-08 14:40:08 -0800460 # CMake does not add -isysroot and -arch flags to assembly.
461 if(APPLE)
462 if(CMAKE_OSX_SYSROOT)
463 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"")
464 endif()
465 foreach(arch ${CMAKE_OSX_ARCHITECTURES})
466 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}")
467 endforeach()
468 endif()
David Benjamin741c1532023-01-25 17:37:16 -0500469 if(NOT WIN32)
470 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack")
471 endif()
472 # Clang's integerated assembler does not support debug symbols.
473 if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang")
474 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g")
475 endif()
Adam Langleycfd80a92019-11-08 14:40:08 -0800476 endif()
477endif()
478
Adam Langleya0cdbf92020-01-21 09:07:46 -0800479if(BUILD_SHARED_LIBS)
480 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
481 # Enable position-independent code globally. This is needed because
482 # some library targets are OBJECT libraries.
483 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
484endif()
485
Adam Langleycfd80a92019-11-08 14:40:08 -0800486include_directories(src/include)
487
488'''
489
490 def PrintLibrary(self, out, name, files):
491 out.write('add_library(\n')
492 out.write(' %s\n\n' % name)
493
494 for f in sorted(files):
495 out.write(' %s\n' % PathOf(f))
496
497 out.write(')\n\n')
498
499 def PrintExe(self, out, name, files, libs):
500 out.write('add_executable(\n')
501 out.write(' %s\n\n' % name)
502
503 for f in sorted(files):
504 out.write(' %s\n' % PathOf(f))
505
506 out.write(')\n\n')
507 out.write('target_link_libraries(%s %s)\n\n' % (name, ' '.join(libs)))
508
David Benjamin741c1532023-01-25 17:37:16 -0500509 def PrintVariable(self, out, name, files):
Adam Langleycfd80a92019-11-08 14:40:08 -0800510 out.write('set(\n')
511 out.write(' %s\n\n' % name)
512 for f in sorted(files):
513 out.write(' %s\n' % PathOf(f))
514 out.write(')\n\n')
515
516 def WriteFiles(self, files, asm_outputs):
517 with open('CMakeLists.txt', 'w+') as cmake:
518 cmake.write(self.header)
519
David Benjamin741c1532023-01-25 17:37:16 -0500520 asm_sources = []
521 nasm_sources = []
Adam Langleycfd80a92019-11-08 14:40:08 -0800522 for ((osname, arch), asm_files) in asm_outputs:
David Benjamin741c1532023-01-25 17:37:16 -0500523 if (osname, arch) in (('win', 'x86'), ('win', 'x86_64')):
524 nasm_sources.extend(asm_files)
525 else:
526 asm_sources.extend(asm_files)
527 self.PrintVariable(cmake, 'CRYPTO_SOURCES_ASM', sorted(asm_sources))
528 self.PrintVariable(cmake, 'CRYPTO_SOURCES_NASM', sorted(nasm_sources))
Adam Langleycfd80a92019-11-08 14:40:08 -0800529
530 cmake.write(
David Benjamin741c1532023-01-25 17:37:16 -0500531R'''if(OPENSSL_ASM)
532 list(APPEND CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_ASM})
533endif()
534if(OPENSSL_NASM)
535 list(APPEND CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_NASM})
Adam Langleycfd80a92019-11-08 14:40:08 -0800536endif()
537
538''')
539
540 self.PrintLibrary(cmake, 'crypto',
David Benjamin741c1532023-01-25 17:37:16 -0500541 files['crypto'] + ['${CRYPTO_SOURCES_ASM_USED}'])
Adam Langleycfd80a92019-11-08 14:40:08 -0800542 self.PrintLibrary(cmake, 'ssl', files['ssl'])
Adam Langleyff631132020-01-13 15:24:22 -0800543 self.PrintExe(cmake, 'bssl', files['tool'], ['ssl', 'crypto'])
544
545 cmake.write(
David Benjamin741c1532023-01-25 17:37:16 -0500546R'''if(NOT ANDROID)
547 find_package(Threads REQUIRED)
548 target_link_libraries(crypto Threads::Threads)
Adam Langleyff631132020-01-13 15:24:22 -0800549endif()
550
David Benjamin8f88b272020-07-09 13:35:01 -0400551if(WIN32)
552 target_link_libraries(bssl ws2_32)
553endif()
554
Adam Langleyff631132020-01-13 15:24:22 -0800555''')
David Benjamin38d01c62016-04-21 18:47:57 -0400556
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400557class JSON(object):
558 def WriteFiles(self, files, asm_outputs):
559 sources = dict(files)
560 for ((osname, arch), asm_files) in asm_outputs:
561 sources['crypto_%s_%s' % (osname, arch)] = asm_files
562 with open('sources.json', 'w+') as f:
563 json.dump(sources, f, sort_keys=True, indent=2)
564
Adam Langley9e1a6602015-05-05 17:47:53 -0700565def FindCMakeFiles(directory):
566 """Returns list of all CMakeLists.txt files recursively in directory."""
567 cmakefiles = []
568
569 for (path, _, filenames) in os.walk(directory):
570 for filename in filenames:
571 if filename == 'CMakeLists.txt':
572 cmakefiles.append(os.path.join(path, filename))
573
574 return cmakefiles
575
Adam Langleyfd499932017-04-04 14:21:43 -0700576def OnlyFIPSFragments(path, dent, is_dir):
Matthew Braithwaite95511e92017-05-08 16:38:03 -0700577 return is_dir or (path.startswith(
578 os.path.join('src', 'crypto', 'fipsmodule', '')) and
579 NoTests(path, dent, is_dir))
Adam Langley9e1a6602015-05-05 17:47:53 -0700580
Adam Langleyfd499932017-04-04 14:21:43 -0700581def NoTestsNorFIPSFragments(path, dent, is_dir):
Adam Langley323f1eb2017-04-06 17:29:10 -0700582 return (NoTests(path, dent, is_dir) and
583 (is_dir or not OnlyFIPSFragments(path, dent, is_dir)))
Adam Langleyfd499932017-04-04 14:21:43 -0700584
585def NoTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700586 """Filter function that can be passed to FindCFiles in order to remove test
587 sources."""
588 if is_dir:
589 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400590 return 'test.' not in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700591
592
Adam Langleyfd499932017-04-04 14:21:43 -0700593def OnlyTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700594 """Filter function that can be passed to FindCFiles in order to remove
595 non-test sources."""
596 if is_dir:
David Benjamin26073832015-05-11 20:52:48 -0400597 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400598 return '_test.' in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700599
600
Adam Langleyfd499932017-04-04 14:21:43 -0700601def AllFiles(path, dent, is_dir):
David Benjamin26073832015-05-11 20:52:48 -0400602 """Filter function that can be passed to FindCFiles in order to include all
603 sources."""
604 return True
605
606
Adam Langleyfd499932017-04-04 14:21:43 -0700607def NoTestRunnerFiles(path, dent, is_dir):
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700608 """Filter function that can be passed to FindCFiles or FindHeaderFiles in
609 order to exclude test runner files."""
610 # NOTE(martinkr): This prevents .h/.cc files in src/ssl/test/runner, which
611 # are in their own subpackage, from being included in boringssl/BUILD files.
612 return not is_dir or dent != 'runner'
613
614
David Benjamin3ecd0a52017-05-19 15:26:18 -0400615def NotGTestSupport(path, dent, is_dir):
David Benjaminc3889632019-03-01 15:03:05 -0500616 return 'gtest' not in dent and 'abi_test' not in dent
David Benjamin96628432017-01-19 19:05:47 -0500617
618
Adam Langleyfd499932017-04-04 14:21:43 -0700619def SSLHeaderFiles(path, dent, is_dir):
Aaron Green0e150022018-10-16 12:05:29 -0700620 return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h', 'srtp.h']
Adam Langley049ef412015-06-09 18:20:57 -0700621
622
Adam Langley9e1a6602015-05-05 17:47:53 -0700623def FindCFiles(directory, filter_func):
624 """Recurses through directory and returns a list of paths to all the C source
625 files that pass filter_func."""
626 cfiles = []
627
628 for (path, dirnames, filenames) in os.walk(directory):
629 for filename in filenames:
630 if not filename.endswith('.c') and not filename.endswith('.cc'):
631 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700632 if not filter_func(path, filename, False):
Adam Langley9e1a6602015-05-05 17:47:53 -0700633 continue
634 cfiles.append(os.path.join(path, filename))
635
636 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700637 if not filter_func(path, dirname, True):
Adam Langley9e1a6602015-05-05 17:47:53 -0700638 del dirnames[i]
639
David Benjaminedd4c5f2020-08-19 14:46:17 -0400640 cfiles.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700641 return cfiles
642
643
Adam Langley049ef412015-06-09 18:20:57 -0700644def FindHeaderFiles(directory, filter_func):
645 """Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
646 hfiles = []
647
648 for (path, dirnames, filenames) in os.walk(directory):
649 for filename in filenames:
650 if not filename.endswith('.h'):
651 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700652 if not filter_func(path, filename, False):
Adam Langley049ef412015-06-09 18:20:57 -0700653 continue
654 hfiles.append(os.path.join(path, filename))
655
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700656 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700657 if not filter_func(path, dirname, True):
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700658 del dirnames[i]
659
David Benjaminedd4c5f2020-08-19 14:46:17 -0400660 hfiles.sort()
Adam Langley049ef412015-06-09 18:20:57 -0700661 return hfiles
662
663
Adam Langley9e1a6602015-05-05 17:47:53 -0700664def ExtractPerlAsmFromCMakeFile(cmakefile):
665 """Parses the contents of the CMakeLists.txt file passed as an argument and
666 returns a list of all the perlasm() directives found in the file."""
667 perlasms = []
668 with open(cmakefile) as f:
669 for line in f:
670 line = line.strip()
671 if not line.startswith('perlasm('):
672 continue
673 if not line.endswith(')'):
674 raise ValueError('Bad perlasm line in %s' % cmakefile)
675 # Remove "perlasm(" from start and ")" from end
676 params = line[8:-1].split()
David Benjamin19676212023-01-25 10:03:53 -0500677 if len(params) != 4:
Adam Langley9e1a6602015-05-05 17:47:53 -0700678 raise ValueError('Bad perlasm line in %s' % cmakefile)
679 perlasms.append({
David Benjamin19676212023-01-25 10:03:53 -0500680 'arch': params[1],
681 'output': os.path.join(os.path.dirname(cmakefile), params[2]),
682 'input': os.path.join(os.path.dirname(cmakefile), params[3]),
Adam Langley9e1a6602015-05-05 17:47:53 -0700683 })
684
685 return perlasms
686
687
688def ReadPerlAsmOperations():
689 """Returns a list of all perlasm() directives found in CMake config files in
690 src/."""
691 perlasms = []
692 cmakefiles = FindCMakeFiles('src')
693
694 for cmakefile in cmakefiles:
695 perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile))
696
697 return perlasms
698
699
700def PerlAsm(output_filename, input_filename, perlasm_style, extra_args):
701 """Runs the a perlasm script and puts the output into output_filename."""
702 base_dir = os.path.dirname(output_filename)
703 if not os.path.isdir(base_dir):
704 os.makedirs(base_dir)
David Benjaminfdd8e9c2016-06-26 13:18:50 -0400705 subprocess.check_call(
706 ['perl', input_filename, perlasm_style] + extra_args + [output_filename])
Adam Langley9e1a6602015-05-05 17:47:53 -0700707
708
Adam Langley9e1a6602015-05-05 17:47:53 -0700709def WriteAsmFiles(perlasms):
710 """Generates asm files from perlasm directives for each supported OS x
711 platform combination."""
712 asmfiles = {}
713
David Benjamin19676212023-01-25 10:03:53 -0500714 for perlasm in perlasms:
715 for (osname, arch, perlasm_style, extra_args, asm_ext) in OS_ARCH_COMBOS:
716 if arch != perlasm['arch']:
717 continue
718 # TODO(https://crbug.com/boringssl/524): Now that we incorporate osname in
719 # the output filename, the asm files can just go in a single directory.
720 # For now, we keep them in target-specific directories to avoid breaking
721 # downstream scripts.
722 key = (osname, arch)
723 outDir = '%s-%s' % key
Adam Langley9e1a6602015-05-05 17:47:53 -0700724 output = perlasm['output']
725 if not output.startswith('src'):
726 raise ValueError('output missing src: %s' % output)
727 output = os.path.join(outDir, output[4:])
David Benjamin19676212023-01-25 10:03:53 -0500728 output = '%s-%s.%s' % (output, osname, asm_ext)
729 PerlAsm(output, perlasm['input'], perlasm_style, extra_args)
730 asmfiles.setdefault(key, []).append(output)
Adam Langley9e1a6602015-05-05 17:47:53 -0700731
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000732 for (key, non_perl_asm_files) in NON_PERL_FILES.items():
Adam Langley9e1a6602015-05-05 17:47:53 -0700733 asmfiles.setdefault(key, []).extend(non_perl_asm_files)
734
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000735 for files in asmfiles.values():
David Benjaminedd4c5f2020-08-19 14:46:17 -0400736 files.sort()
737
Adam Langley9e1a6602015-05-05 17:47:53 -0700738 return asmfiles
739
740
David Benjamin3ecd0a52017-05-19 15:26:18 -0400741def ExtractVariablesFromCMakeFile(cmakefile):
742 """Parses the contents of the CMakeLists.txt file passed as an argument and
743 returns a dictionary of exported source lists."""
744 variables = {}
745 in_set_command = False
746 set_command = []
747 with open(cmakefile) as f:
748 for line in f:
749 if '#' in line:
750 line = line[:line.index('#')]
751 line = line.strip()
752
753 if not in_set_command:
754 if line.startswith('set('):
755 in_set_command = True
756 set_command = []
757 elif line == ')':
758 in_set_command = False
759 if not set_command:
760 raise ValueError('Empty set command')
761 variables[set_command[0]] = set_command[1:]
762 else:
763 set_command.extend([c for c in line.split(' ') if c])
764
765 if in_set_command:
766 raise ValueError('Unfinished set command')
767 return variables
768
769
Adam Langley049ef412015-06-09 18:20:57 -0700770def main(platforms):
David Benjamin3ecd0a52017-05-19 15:26:18 -0400771 cmake = ExtractVariablesFromCMakeFile(os.path.join('src', 'sources.cmake'))
Andres Erbsen5b280a82017-10-30 15:58:33 +0000772 crypto_c_files = (FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments) +
Adam Langley7f028812019-10-18 14:48:11 -0700773 FindCFiles(os.path.join('src', 'third_party', 'fiat'), NoTestsNorFIPSFragments))
Adam Langleyfd499932017-04-04 14:21:43 -0700774 fips_fragments = FindCFiles(os.path.join('src', 'crypto', 'fipsmodule'), OnlyFIPSFragments)
Adam Langleyfeca9e52017-01-23 13:07:50 -0800775 ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
David Benjamin38d01c62016-04-21 18:47:57 -0400776 tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
Adam Langleyf11f2332016-06-30 11:56:19 -0700777 tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles)
Adam Langley9e1a6602015-05-05 17:47:53 -0700778
Pete Bentley44544d92019-08-15 15:01:26 +0100779 # BCM shared library C files
780 bcm_crypto_c_files = [
781 os.path.join('src', 'crypto', 'fipsmodule', 'bcm.c')
782 ]
783
Adam Langley9e1a6602015-05-05 17:47:53 -0700784 # Generate err_data.c
785 with open('err_data.c', 'w+') as err_data:
786 subprocess.check_call(['go', 'run', 'err_data_generate.go'],
787 cwd=os.path.join('src', 'crypto', 'err'),
788 stdout=err_data)
789 crypto_c_files.append('err_data.c')
David Benjaminedd4c5f2020-08-19 14:46:17 -0400790 crypto_c_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700791
David Benjamin38d01c62016-04-21 18:47:57 -0400792 test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
David Benjamin3ecd0a52017-05-19 15:26:18 -0400793 NotGTestSupport)
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700794 test_support_h_files = (
795 FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) +
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700796 FindHeaderFiles(os.path.join('src', 'ssl', 'test'), NoTestRunnerFiles))
David Benjamin26073832015-05-11 20:52:48 -0400797
Adam Langley990a3232018-05-22 10:02:59 -0700798 crypto_test_files = []
799 if EMBED_TEST_DATA:
800 # Generate crypto_test_data.cc
801 with open('crypto_test_data.cc', 'w+') as out:
802 subprocess.check_call(
803 ['go', 'run', 'util/embed_test_data.go'] + cmake['CRYPTO_TEST_DATA'],
804 cwd='src',
805 stdout=out)
806 crypto_test_files += ['crypto_test_data.cc']
David Benjamin3ecd0a52017-05-19 15:26:18 -0400807
Adam Langley990a3232018-05-22 10:02:59 -0700808 crypto_test_files += FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
David Benjamin96ee4a82017-07-09 23:46:47 -0400809 crypto_test_files += [
David Benjaminc3889632019-03-01 15:03:05 -0500810 'src/crypto/test/abi_test.cc',
David Benjamin3ecd0a52017-05-19 15:26:18 -0400811 'src/crypto/test/file_test_gtest.cc',
812 'src/crypto/test/gtest_main.cc',
813 ]
Adam Langley3e502c82019-10-16 09:56:38 -0700814 # urandom_test.cc is in a separate binary so that it can be test PRNG
815 # initialisation.
816 crypto_test_files = [
817 file for file in crypto_test_files
818 if not file.endswith('/urandom_test.cc')
819 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400820 crypto_test_files.sort()
David Benjamin1d5a5702017-02-13 22:11:49 -0500821
822 ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
Robert Sloanae1e0872019-03-01 16:01:30 -0800823 ssl_test_files += [
824 'src/crypto/test/abi_test.cc',
825 'src/crypto/test/gtest_main.cc',
826 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400827 ssl_test_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700828
Adam Langley3e502c82019-10-16 09:56:38 -0700829 urandom_test_files = [
830 'src/crypto/fipsmodule/rand/urandom_test.cc',
831 ]
832
David Benjamin38d01c62016-04-21 18:47:57 -0400833 fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
834
David Benjaminedd4c5f2020-08-19 14:46:17 -0400835 ssl_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
836 SSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700837
Adam Langleyfd499932017-04-04 14:21:43 -0700838 def NotSSLHeaderFiles(path, filename, is_dir):
839 return not SSLHeaderFiles(path, filename, is_dir)
David Benjaminedd4c5f2020-08-19 14:46:17 -0400840 crypto_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
841 NotSSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700842
843 ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
Andres Erbsen5b280a82017-10-30 15:58:33 +0000844 crypto_internal_h_files = (
845 FindHeaderFiles(os.path.join('src', 'crypto'), NoTests) +
Adam Langley7f028812019-10-18 14:48:11 -0700846 FindHeaderFiles(os.path.join('src', 'third_party', 'fiat'), NoTests))
Adam Langley049ef412015-06-09 18:20:57 -0700847
Adam Langley9e1a6602015-05-05 17:47:53 -0700848 files = {
Pete Bentley44544d92019-08-15 15:01:26 +0100849 'bcm_crypto': bcm_crypto_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700850 'crypto': crypto_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700851 'crypto_headers': crypto_h_files,
852 'crypto_internal_headers': crypto_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400853 'crypto_test': crypto_test_files,
Adam Langley990a3232018-05-22 10:02:59 -0700854 'crypto_test_data': sorted('src/' + x for x in cmake['CRYPTO_TEST_DATA']),
Adam Langleyfd499932017-04-04 14:21:43 -0700855 'fips_fragments': fips_fragments,
David Benjamin38d01c62016-04-21 18:47:57 -0400856 'fuzz': fuzz_c_files,
Adam Langleyfeca9e52017-01-23 13:07:50 -0800857 'ssl': ssl_source_files,
Adam Langley049ef412015-06-09 18:20:57 -0700858 'ssl_headers': ssl_h_files,
859 'ssl_internal_headers': ssl_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400860 'ssl_test': ssl_test_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400861 'tool': tool_c_files,
Adam Langleyf11f2332016-06-30 11:56:19 -0700862 'tool_headers': tool_h_files,
David Benjaminc5aa8412016-07-29 17:41:58 -0400863 'test_support': test_support_c_files,
864 'test_support_headers': test_support_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400865 'urandom_test': urandom_test_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700866 }
867
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000868 asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).items())
Adam Langley9e1a6602015-05-05 17:47:53 -0700869
Adam Langley049ef412015-06-09 18:20:57 -0700870 for platform in platforms:
871 platform.WriteFiles(files, asm_outputs)
Adam Langley9e1a6602015-05-05 17:47:53 -0700872
873 return 0
874
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400875ALL_PLATFORMS = {
876 'android': Android,
877 'android-cmake': AndroidCMake,
878 'bazel': Bazel,
879 'cmake': CMake,
880 'eureka': Eureka,
881 'gn': GN,
882 'gyp': GYP,
883 'json': JSON,
884}
Adam Langley9e1a6602015-05-05 17:47:53 -0700885
Adam Langley9e1a6602015-05-05 17:47:53 -0700886if __name__ == '__main__':
David Benjamin4acc7dd2022-11-19 10:13:49 -0500887 parser = optparse.OptionParser(
888 usage='Usage: %%prog [--prefix=<path>] [all|%s]' %
889 '|'.join(sorted(ALL_PLATFORMS.keys())))
Matt Braithwaite16695892016-06-09 09:34:11 -0700890 parser.add_option('--prefix', dest='prefix',
891 help='For Bazel, prepend argument to all source files')
Adam Langley990a3232018-05-22 10:02:59 -0700892 parser.add_option(
893 '--embed_test_data', type='choice', dest='embed_test_data',
894 action='store', default="true", choices=["true", "false"],
David Benjaminf014d602019-05-07 18:58:06 -0500895 help='For Bazel or GN, don\'t embed data files in crypto_test_data.cc')
Matt Braithwaite16695892016-06-09 09:34:11 -0700896 options, args = parser.parse_args(sys.argv[1:])
897 PREFIX = options.prefix
Adam Langley990a3232018-05-22 10:02:59 -0700898 EMBED_TEST_DATA = (options.embed_test_data == "true")
Matt Braithwaite16695892016-06-09 09:34:11 -0700899
900 if not args:
901 parser.print_help()
902 sys.exit(1)
Adam Langley9e1a6602015-05-05 17:47:53 -0700903
David Benjamin4acc7dd2022-11-19 10:13:49 -0500904 if 'all' in args:
905 platforms = [platform() for platform in ALL_PLATFORMS.values()]
906 else:
907 platforms = []
908 for s in args:
909 platform = ALL_PLATFORMS.get(s)
910 if platform is None:
911 parser.print_help()
912 sys.exit(1)
913 platforms.append(platform())
Adam Langley9e1a6602015-05-05 17:47:53 -0700914
Adam Langley049ef412015-06-09 18:20:57 -0700915 sys.exit(main(platforms))