blob: c221f04781df09193af2a140bd702a5f42afe3f0 [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)
David Benjamin61266e42023-01-29 15:53:30 -0500460 # Work around https://gitlab.kitware.com/cmake/cmake/-/issues/20771 in older
461 # CMake versions.
462 if(APPLE AND CMAKE_VERSION VERSION_LESS 3.19)
Adam Langleycfd80a92019-11-08 14:40:08 -0800463 if(CMAKE_OSX_SYSROOT)
464 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"")
465 endif()
466 foreach(arch ${CMAKE_OSX_ARCHITECTURES})
467 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}")
468 endforeach()
469 endif()
David Benjamin741c1532023-01-25 17:37:16 -0500470 if(NOT WIN32)
471 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack")
472 endif()
473 # Clang's integerated assembler does not support debug symbols.
474 if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang")
475 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g")
476 endif()
Adam Langleycfd80a92019-11-08 14:40:08 -0800477 endif()
478endif()
479
Adam Langleya0cdbf92020-01-21 09:07:46 -0800480if(BUILD_SHARED_LIBS)
481 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
482 # Enable position-independent code globally. This is needed because
483 # some library targets are OBJECT libraries.
484 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
485endif()
486
Adam Langleycfd80a92019-11-08 14:40:08 -0800487include_directories(src/include)
488
489'''
490
491 def PrintLibrary(self, out, name, files):
492 out.write('add_library(\n')
493 out.write(' %s\n\n' % name)
494
495 for f in sorted(files):
496 out.write(' %s\n' % PathOf(f))
497
498 out.write(')\n\n')
499
500 def PrintExe(self, out, name, files, libs):
501 out.write('add_executable(\n')
502 out.write(' %s\n\n' % name)
503
504 for f in sorted(files):
505 out.write(' %s\n' % PathOf(f))
506
507 out.write(')\n\n')
508 out.write('target_link_libraries(%s %s)\n\n' % (name, ' '.join(libs)))
509
David Benjamin741c1532023-01-25 17:37:16 -0500510 def PrintVariable(self, out, name, files):
Adam Langleycfd80a92019-11-08 14:40:08 -0800511 out.write('set(\n')
512 out.write(' %s\n\n' % name)
513 for f in sorted(files):
514 out.write(' %s\n' % PathOf(f))
515 out.write(')\n\n')
516
517 def WriteFiles(self, files, asm_outputs):
518 with open('CMakeLists.txt', 'w+') as cmake:
519 cmake.write(self.header)
520
David Benjamin741c1532023-01-25 17:37:16 -0500521 asm_sources = []
522 nasm_sources = []
Adam Langleycfd80a92019-11-08 14:40:08 -0800523 for ((osname, arch), asm_files) in asm_outputs:
David Benjamin741c1532023-01-25 17:37:16 -0500524 if (osname, arch) in (('win', 'x86'), ('win', 'x86_64')):
525 nasm_sources.extend(asm_files)
526 else:
527 asm_sources.extend(asm_files)
528 self.PrintVariable(cmake, 'CRYPTO_SOURCES_ASM', sorted(asm_sources))
529 self.PrintVariable(cmake, 'CRYPTO_SOURCES_NASM', sorted(nasm_sources))
Adam Langleycfd80a92019-11-08 14:40:08 -0800530
531 cmake.write(
David Benjamin741c1532023-01-25 17:37:16 -0500532R'''if(OPENSSL_ASM)
533 list(APPEND CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_ASM})
534endif()
535if(OPENSSL_NASM)
536 list(APPEND CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_NASM})
Adam Langleycfd80a92019-11-08 14:40:08 -0800537endif()
538
539''')
540
541 self.PrintLibrary(cmake, 'crypto',
David Benjamin741c1532023-01-25 17:37:16 -0500542 files['crypto'] + ['${CRYPTO_SOURCES_ASM_USED}'])
Adam Langleycfd80a92019-11-08 14:40:08 -0800543 self.PrintLibrary(cmake, 'ssl', files['ssl'])
Adam Langleyff631132020-01-13 15:24:22 -0800544 self.PrintExe(cmake, 'bssl', files['tool'], ['ssl', 'crypto'])
545
546 cmake.write(
David Benjamin741c1532023-01-25 17:37:16 -0500547R'''if(NOT ANDROID)
548 find_package(Threads REQUIRED)
549 target_link_libraries(crypto Threads::Threads)
Adam Langleyff631132020-01-13 15:24:22 -0800550endif()
551
David Benjamin8f88b272020-07-09 13:35:01 -0400552if(WIN32)
553 target_link_libraries(bssl ws2_32)
554endif()
555
Adam Langleyff631132020-01-13 15:24:22 -0800556''')
David Benjamin38d01c62016-04-21 18:47:57 -0400557
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400558class JSON(object):
559 def WriteFiles(self, files, asm_outputs):
560 sources = dict(files)
561 for ((osname, arch), asm_files) in asm_outputs:
562 sources['crypto_%s_%s' % (osname, arch)] = asm_files
563 with open('sources.json', 'w+') as f:
564 json.dump(sources, f, sort_keys=True, indent=2)
565
Adam Langley9e1a6602015-05-05 17:47:53 -0700566def FindCMakeFiles(directory):
567 """Returns list of all CMakeLists.txt files recursively in directory."""
568 cmakefiles = []
569
570 for (path, _, filenames) in os.walk(directory):
571 for filename in filenames:
572 if filename == 'CMakeLists.txt':
573 cmakefiles.append(os.path.join(path, filename))
574
575 return cmakefiles
576
Adam Langleyfd499932017-04-04 14:21:43 -0700577def OnlyFIPSFragments(path, dent, is_dir):
Matthew Braithwaite95511e92017-05-08 16:38:03 -0700578 return is_dir or (path.startswith(
579 os.path.join('src', 'crypto', 'fipsmodule', '')) and
580 NoTests(path, dent, is_dir))
Adam Langley9e1a6602015-05-05 17:47:53 -0700581
Adam Langleyfd499932017-04-04 14:21:43 -0700582def NoTestsNorFIPSFragments(path, dent, is_dir):
Adam Langley323f1eb2017-04-06 17:29:10 -0700583 return (NoTests(path, dent, is_dir) and
584 (is_dir or not OnlyFIPSFragments(path, dent, is_dir)))
Adam Langleyfd499932017-04-04 14:21:43 -0700585
586def NoTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700587 """Filter function that can be passed to FindCFiles in order to remove test
588 sources."""
589 if is_dir:
590 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400591 return 'test.' not in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700592
593
Adam Langleyfd499932017-04-04 14:21:43 -0700594def OnlyTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700595 """Filter function that can be passed to FindCFiles in order to remove
596 non-test sources."""
597 if is_dir:
David Benjamin26073832015-05-11 20:52:48 -0400598 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400599 return '_test.' in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700600
601
Adam Langleyfd499932017-04-04 14:21:43 -0700602def AllFiles(path, dent, is_dir):
David Benjamin26073832015-05-11 20:52:48 -0400603 """Filter function that can be passed to FindCFiles in order to include all
604 sources."""
605 return True
606
607
Adam Langleyfd499932017-04-04 14:21:43 -0700608def NoTestRunnerFiles(path, dent, is_dir):
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700609 """Filter function that can be passed to FindCFiles or FindHeaderFiles in
610 order to exclude test runner files."""
611 # NOTE(martinkr): This prevents .h/.cc files in src/ssl/test/runner, which
612 # are in their own subpackage, from being included in boringssl/BUILD files.
613 return not is_dir or dent != 'runner'
614
615
David Benjamin3ecd0a52017-05-19 15:26:18 -0400616def NotGTestSupport(path, dent, is_dir):
David Benjaminc3889632019-03-01 15:03:05 -0500617 return 'gtest' not in dent and 'abi_test' not in dent
David Benjamin96628432017-01-19 19:05:47 -0500618
619
Adam Langleyfd499932017-04-04 14:21:43 -0700620def SSLHeaderFiles(path, dent, is_dir):
Aaron Green0e150022018-10-16 12:05:29 -0700621 return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h', 'srtp.h']
Adam Langley049ef412015-06-09 18:20:57 -0700622
623
Adam Langley9e1a6602015-05-05 17:47:53 -0700624def FindCFiles(directory, filter_func):
625 """Recurses through directory and returns a list of paths to all the C source
626 files that pass filter_func."""
627 cfiles = []
628
629 for (path, dirnames, filenames) in os.walk(directory):
630 for filename in filenames:
631 if not filename.endswith('.c') and not filename.endswith('.cc'):
632 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700633 if not filter_func(path, filename, False):
Adam Langley9e1a6602015-05-05 17:47:53 -0700634 continue
635 cfiles.append(os.path.join(path, filename))
636
637 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700638 if not filter_func(path, dirname, True):
Adam Langley9e1a6602015-05-05 17:47:53 -0700639 del dirnames[i]
640
David Benjaminedd4c5f2020-08-19 14:46:17 -0400641 cfiles.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700642 return cfiles
643
644
Adam Langley049ef412015-06-09 18:20:57 -0700645def FindHeaderFiles(directory, filter_func):
646 """Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
647 hfiles = []
648
649 for (path, dirnames, filenames) in os.walk(directory):
650 for filename in filenames:
651 if not filename.endswith('.h'):
652 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700653 if not filter_func(path, filename, False):
Adam Langley049ef412015-06-09 18:20:57 -0700654 continue
655 hfiles.append(os.path.join(path, filename))
656
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700657 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700658 if not filter_func(path, dirname, True):
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700659 del dirnames[i]
660
David Benjaminedd4c5f2020-08-19 14:46:17 -0400661 hfiles.sort()
Adam Langley049ef412015-06-09 18:20:57 -0700662 return hfiles
663
664
Adam Langley9e1a6602015-05-05 17:47:53 -0700665def ExtractPerlAsmFromCMakeFile(cmakefile):
666 """Parses the contents of the CMakeLists.txt file passed as an argument and
667 returns a list of all the perlasm() directives found in the file."""
668 perlasms = []
669 with open(cmakefile) as f:
670 for line in f:
671 line = line.strip()
672 if not line.startswith('perlasm('):
673 continue
674 if not line.endswith(')'):
675 raise ValueError('Bad perlasm line in %s' % cmakefile)
676 # Remove "perlasm(" from start and ")" from end
677 params = line[8:-1].split()
David Benjamin19676212023-01-25 10:03:53 -0500678 if len(params) != 4:
Adam Langley9e1a6602015-05-05 17:47:53 -0700679 raise ValueError('Bad perlasm line in %s' % cmakefile)
680 perlasms.append({
David Benjamin19676212023-01-25 10:03:53 -0500681 'arch': params[1],
682 'output': os.path.join(os.path.dirname(cmakefile), params[2]),
683 'input': os.path.join(os.path.dirname(cmakefile), params[3]),
Adam Langley9e1a6602015-05-05 17:47:53 -0700684 })
685
686 return perlasms
687
688
689def ReadPerlAsmOperations():
690 """Returns a list of all perlasm() directives found in CMake config files in
691 src/."""
692 perlasms = []
693 cmakefiles = FindCMakeFiles('src')
694
695 for cmakefile in cmakefiles:
696 perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile))
697
698 return perlasms
699
700
701def PerlAsm(output_filename, input_filename, perlasm_style, extra_args):
702 """Runs the a perlasm script and puts the output into output_filename."""
703 base_dir = os.path.dirname(output_filename)
704 if not os.path.isdir(base_dir):
705 os.makedirs(base_dir)
David Benjaminfdd8e9c2016-06-26 13:18:50 -0400706 subprocess.check_call(
707 ['perl', input_filename, perlasm_style] + extra_args + [output_filename])
Adam Langley9e1a6602015-05-05 17:47:53 -0700708
709
Adam Langley9e1a6602015-05-05 17:47:53 -0700710def WriteAsmFiles(perlasms):
711 """Generates asm files from perlasm directives for each supported OS x
712 platform combination."""
713 asmfiles = {}
714
David Benjamin19676212023-01-25 10:03:53 -0500715 for perlasm in perlasms:
716 for (osname, arch, perlasm_style, extra_args, asm_ext) in OS_ARCH_COMBOS:
717 if arch != perlasm['arch']:
718 continue
719 # TODO(https://crbug.com/boringssl/524): Now that we incorporate osname in
720 # the output filename, the asm files can just go in a single directory.
721 # For now, we keep them in target-specific directories to avoid breaking
722 # downstream scripts.
723 key = (osname, arch)
724 outDir = '%s-%s' % key
Adam Langley9e1a6602015-05-05 17:47:53 -0700725 output = perlasm['output']
726 if not output.startswith('src'):
727 raise ValueError('output missing src: %s' % output)
728 output = os.path.join(outDir, output[4:])
David Benjamin19676212023-01-25 10:03:53 -0500729 output = '%s-%s.%s' % (output, osname, asm_ext)
730 PerlAsm(output, perlasm['input'], perlasm_style, extra_args)
731 asmfiles.setdefault(key, []).append(output)
Adam Langley9e1a6602015-05-05 17:47:53 -0700732
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000733 for (key, non_perl_asm_files) in NON_PERL_FILES.items():
Adam Langley9e1a6602015-05-05 17:47:53 -0700734 asmfiles.setdefault(key, []).extend(non_perl_asm_files)
735
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000736 for files in asmfiles.values():
David Benjaminedd4c5f2020-08-19 14:46:17 -0400737 files.sort()
738
Adam Langley9e1a6602015-05-05 17:47:53 -0700739 return asmfiles
740
741
David Benjamin3ecd0a52017-05-19 15:26:18 -0400742def ExtractVariablesFromCMakeFile(cmakefile):
743 """Parses the contents of the CMakeLists.txt file passed as an argument and
744 returns a dictionary of exported source lists."""
745 variables = {}
746 in_set_command = False
747 set_command = []
748 with open(cmakefile) as f:
749 for line in f:
750 if '#' in line:
751 line = line[:line.index('#')]
752 line = line.strip()
753
754 if not in_set_command:
755 if line.startswith('set('):
756 in_set_command = True
757 set_command = []
758 elif line == ')':
759 in_set_command = False
760 if not set_command:
761 raise ValueError('Empty set command')
762 variables[set_command[0]] = set_command[1:]
763 else:
764 set_command.extend([c for c in line.split(' ') if c])
765
766 if in_set_command:
767 raise ValueError('Unfinished set command')
768 return variables
769
770
Adam Langley049ef412015-06-09 18:20:57 -0700771def main(platforms):
David Benjamin3ecd0a52017-05-19 15:26:18 -0400772 cmake = ExtractVariablesFromCMakeFile(os.path.join('src', 'sources.cmake'))
Andres Erbsen5b280a82017-10-30 15:58:33 +0000773 crypto_c_files = (FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments) +
Adam Langley7f028812019-10-18 14:48:11 -0700774 FindCFiles(os.path.join('src', 'third_party', 'fiat'), NoTestsNorFIPSFragments))
Adam Langleyfd499932017-04-04 14:21:43 -0700775 fips_fragments = FindCFiles(os.path.join('src', 'crypto', 'fipsmodule'), OnlyFIPSFragments)
Adam Langleyfeca9e52017-01-23 13:07:50 -0800776 ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
David Benjamin38d01c62016-04-21 18:47:57 -0400777 tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
Adam Langleyf11f2332016-06-30 11:56:19 -0700778 tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles)
Adam Langley9e1a6602015-05-05 17:47:53 -0700779
Pete Bentley44544d92019-08-15 15:01:26 +0100780 # BCM shared library C files
781 bcm_crypto_c_files = [
782 os.path.join('src', 'crypto', 'fipsmodule', 'bcm.c')
783 ]
784
Adam Langley9e1a6602015-05-05 17:47:53 -0700785 # Generate err_data.c
786 with open('err_data.c', 'w+') as err_data:
787 subprocess.check_call(['go', 'run', 'err_data_generate.go'],
788 cwd=os.path.join('src', 'crypto', 'err'),
789 stdout=err_data)
790 crypto_c_files.append('err_data.c')
David Benjaminedd4c5f2020-08-19 14:46:17 -0400791 crypto_c_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700792
David Benjamin38d01c62016-04-21 18:47:57 -0400793 test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
David Benjamin3ecd0a52017-05-19 15:26:18 -0400794 NotGTestSupport)
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700795 test_support_h_files = (
796 FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) +
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700797 FindHeaderFiles(os.path.join('src', 'ssl', 'test'), NoTestRunnerFiles))
David Benjamin26073832015-05-11 20:52:48 -0400798
Adam Langley990a3232018-05-22 10:02:59 -0700799 crypto_test_files = []
800 if EMBED_TEST_DATA:
801 # Generate crypto_test_data.cc
802 with open('crypto_test_data.cc', 'w+') as out:
803 subprocess.check_call(
804 ['go', 'run', 'util/embed_test_data.go'] + cmake['CRYPTO_TEST_DATA'],
805 cwd='src',
806 stdout=out)
807 crypto_test_files += ['crypto_test_data.cc']
David Benjamin3ecd0a52017-05-19 15:26:18 -0400808
Adam Langley990a3232018-05-22 10:02:59 -0700809 crypto_test_files += FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
David Benjamin96ee4a82017-07-09 23:46:47 -0400810 crypto_test_files += [
David Benjaminc3889632019-03-01 15:03:05 -0500811 'src/crypto/test/abi_test.cc',
David Benjamin3ecd0a52017-05-19 15:26:18 -0400812 'src/crypto/test/file_test_gtest.cc',
813 'src/crypto/test/gtest_main.cc',
814 ]
Adam Langley3e502c82019-10-16 09:56:38 -0700815 # urandom_test.cc is in a separate binary so that it can be test PRNG
816 # initialisation.
817 crypto_test_files = [
818 file for file in crypto_test_files
819 if not file.endswith('/urandom_test.cc')
820 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400821 crypto_test_files.sort()
David Benjamin1d5a5702017-02-13 22:11:49 -0500822
823 ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
Robert Sloanae1e0872019-03-01 16:01:30 -0800824 ssl_test_files += [
825 'src/crypto/test/abi_test.cc',
826 'src/crypto/test/gtest_main.cc',
827 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400828 ssl_test_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700829
Adam Langley3e502c82019-10-16 09:56:38 -0700830 urandom_test_files = [
831 'src/crypto/fipsmodule/rand/urandom_test.cc',
832 ]
833
David Benjamin38d01c62016-04-21 18:47:57 -0400834 fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
835
David Benjaminedd4c5f2020-08-19 14:46:17 -0400836 ssl_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
837 SSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700838
Adam Langleyfd499932017-04-04 14:21:43 -0700839 def NotSSLHeaderFiles(path, filename, is_dir):
840 return not SSLHeaderFiles(path, filename, is_dir)
David Benjaminedd4c5f2020-08-19 14:46:17 -0400841 crypto_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
842 NotSSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700843
844 ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
Andres Erbsen5b280a82017-10-30 15:58:33 +0000845 crypto_internal_h_files = (
846 FindHeaderFiles(os.path.join('src', 'crypto'), NoTests) +
Adam Langley7f028812019-10-18 14:48:11 -0700847 FindHeaderFiles(os.path.join('src', 'third_party', 'fiat'), NoTests))
Adam Langley049ef412015-06-09 18:20:57 -0700848
Adam Langley9e1a6602015-05-05 17:47:53 -0700849 files = {
Pete Bentley44544d92019-08-15 15:01:26 +0100850 'bcm_crypto': bcm_crypto_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700851 'crypto': crypto_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700852 'crypto_headers': crypto_h_files,
853 'crypto_internal_headers': crypto_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400854 'crypto_test': crypto_test_files,
Adam Langley990a3232018-05-22 10:02:59 -0700855 'crypto_test_data': sorted('src/' + x for x in cmake['CRYPTO_TEST_DATA']),
Adam Langleyfd499932017-04-04 14:21:43 -0700856 'fips_fragments': fips_fragments,
David Benjamin38d01c62016-04-21 18:47:57 -0400857 'fuzz': fuzz_c_files,
Adam Langleyfeca9e52017-01-23 13:07:50 -0800858 'ssl': ssl_source_files,
Adam Langley049ef412015-06-09 18:20:57 -0700859 'ssl_headers': ssl_h_files,
860 'ssl_internal_headers': ssl_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400861 'ssl_test': ssl_test_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400862 'tool': tool_c_files,
Adam Langleyf11f2332016-06-30 11:56:19 -0700863 'tool_headers': tool_h_files,
David Benjaminc5aa8412016-07-29 17:41:58 -0400864 'test_support': test_support_c_files,
865 'test_support_headers': test_support_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400866 'urandom_test': urandom_test_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700867 }
868
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000869 asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).items())
Adam Langley9e1a6602015-05-05 17:47:53 -0700870
Adam Langley049ef412015-06-09 18:20:57 -0700871 for platform in platforms:
872 platform.WriteFiles(files, asm_outputs)
Adam Langley9e1a6602015-05-05 17:47:53 -0700873
874 return 0
875
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400876ALL_PLATFORMS = {
877 'android': Android,
878 'android-cmake': AndroidCMake,
879 'bazel': Bazel,
880 'cmake': CMake,
881 'eureka': Eureka,
882 'gn': GN,
883 'gyp': GYP,
884 'json': JSON,
885}
Adam Langley9e1a6602015-05-05 17:47:53 -0700886
Adam Langley9e1a6602015-05-05 17:47:53 -0700887if __name__ == '__main__':
David Benjamin4acc7dd2022-11-19 10:13:49 -0500888 parser = optparse.OptionParser(
889 usage='Usage: %%prog [--prefix=<path>] [all|%s]' %
890 '|'.join(sorted(ALL_PLATFORMS.keys())))
Matt Braithwaite16695892016-06-09 09:34:11 -0700891 parser.add_option('--prefix', dest='prefix',
892 help='For Bazel, prepend argument to all source files')
Adam Langley990a3232018-05-22 10:02:59 -0700893 parser.add_option(
894 '--embed_test_data', type='choice', dest='embed_test_data',
895 action='store', default="true", choices=["true", "false"],
David Benjaminf014d602019-05-07 18:58:06 -0500896 help='For Bazel or GN, don\'t embed data files in crypto_test_data.cc')
Matt Braithwaite16695892016-06-09 09:34:11 -0700897 options, args = parser.parse_args(sys.argv[1:])
898 PREFIX = options.prefix
Adam Langley990a3232018-05-22 10:02:59 -0700899 EMBED_TEST_DATA = (options.embed_test_data == "true")
Matt Braithwaite16695892016-06-09 09:34:11 -0700900
901 if not args:
902 parser.print_help()
903 sys.exit(1)
Adam Langley9e1a6602015-05-05 17:47:53 -0700904
David Benjamin4acc7dd2022-11-19 10:13:49 -0500905 if 'all' in args:
906 platforms = [platform() for platform in ALL_PLATFORMS.values()]
907 else:
908 platforms = []
909 for s in args:
910 platform = ALL_PLATFORMS.get(s)
911 if platform is None:
912 parser.print_help()
913 sys.exit(1)
914 platforms.append(platform())
Adam Langley9e1a6602015-05-05 17:47:53 -0700915
Adam Langley049ef412015-06-09 18:20:57 -0700916 sys.exit(main(platforms))