blob: faf6d8ab1475cd3106fdd14f1d520c4a3a5e9cf6 [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 Langley04b3a962023-02-08 21:08:49 +000052 ('linux', 'x86_64'): [
53 'src/crypto/hrss/asm/poly_rq_mul.S',
54 ],
Adam Langley9e1a6602015-05-05 17:47:53 -070055}
56
Matt Braithwaite16695892016-06-09 09:34:11 -070057PREFIX = None
Adam Langley990a3232018-05-22 10:02:59 -070058EMBED_TEST_DATA = True
Matt Braithwaite16695892016-06-09 09:34:11 -070059
60
61def PathOf(x):
62 return x if not PREFIX else os.path.join(PREFIX, x)
63
Adam Langley9e1a6602015-05-05 17:47:53 -070064
David Benjamin70690f72023-01-25 09:56:43 -050065LICENSE_TEMPLATE = """Copyright (c) 2015, Google Inc.
66
67Permission to use, copy, modify, and/or distribute this software for any
68purpose with or without fee is hereby granted, provided that the above
69copyright notice and this permission notice appear in all copies.
70
71THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
72WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
73MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
74SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
75WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
76OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
77CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.""".split("\n")
78
79def LicenseHeader(comment):
80 lines = []
81 for line in LICENSE_TEMPLATE:
82 if not line:
83 lines.append(comment)
84 else:
85 lines.append("%s %s" % (comment, line))
86 lines.append("")
87 return "\n".join(lines)
88
89
Adam Langley9e1a6602015-05-05 17:47:53 -070090class Android(object):
91
92 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -050093 self.header = LicenseHeader("#") + """
Dan Willemsenb57e4fc2016-07-21 11:08:44 -070094# This file is created by generate_build_files.py. Do not edit manually.
Adam Langley9e1a6602015-05-05 17:47:53 -070095"""
96
97 def PrintVariableSection(self, out, name, files):
98 out.write('%s := \\\n' % name)
99 for f in sorted(files):
100 out.write(' %s\\\n' % f)
101 out.write('\n')
102
103 def WriteFiles(self, files, asm_outputs):
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700104 # New Android.bp format
105 with open('sources.bp', 'w+') as blueprint:
106 blueprint.write(self.header.replace('#', '//'))
107
Pete Bentley44544d92019-08-15 15:01:26 +0100108 # Separate out BCM files to allow different compilation rules (specific to Android FIPS)
109 bcm_c_files = files['bcm_crypto']
110 non_bcm_c_files = [file for file in files['crypto'] if file not in bcm_c_files]
111 non_bcm_asm = self.FilterBcmAsm(asm_outputs, False)
112 bcm_asm = self.FilterBcmAsm(asm_outputs, True)
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700113
Pete Bentley44544d92019-08-15 15:01:26 +0100114 self.PrintDefaults(blueprint, 'libcrypto_sources', non_bcm_c_files, non_bcm_asm)
115 self.PrintDefaults(blueprint, 'libcrypto_bcm_sources', bcm_c_files, bcm_asm)
116 self.PrintDefaults(blueprint, 'libssl_sources', files['ssl'])
117 self.PrintDefaults(blueprint, 'bssl_sources', files['tool'])
118 self.PrintDefaults(blueprint, 'boringssl_test_support_sources', files['test_support'])
119 self.PrintDefaults(blueprint, 'boringssl_crypto_test_sources', files['crypto_test'])
120 self.PrintDefaults(blueprint, 'boringssl_ssl_test_sources', files['ssl_test'])
121
122 # Legacy Android.mk format, only used by Trusty in new branches
123 with open('sources.mk', 'w+') as makefile:
124 makefile.write(self.header)
125 makefile.write('\n')
126 self.PrintVariableSection(makefile, 'crypto_sources', files['crypto'])
127
128 for ((osname, arch), asm_files) in asm_outputs:
129 if osname != 'linux':
130 continue
131 self.PrintVariableSection(
132 makefile, '%s_%s_sources' % (osname, arch), asm_files)
133
134 def PrintDefaults(self, blueprint, name, files, asm_outputs={}):
135 """Print a cc_defaults section from a list of C files and optionally assembly outputs"""
136 blueprint.write('\n')
137 blueprint.write('cc_defaults {\n')
138 blueprint.write(' name: "%s",\n' % name)
139 blueprint.write(' srcs: [\n')
140 for f in sorted(files):
141 blueprint.write(' "%s",\n' % f)
142 blueprint.write(' ],\n')
143
144 if asm_outputs:
145 blueprint.write(' target: {\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700146 for ((osname, arch), asm_files) in asm_outputs:
David Benjamin5fdc03f2023-01-26 18:55:32 -0500147 if osname != 'linux':
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700148 continue
149 if arch == 'aarch64':
150 arch = 'arm64'
151
Dan Willemsen2eb4bc52017-10-16 14:37:00 -0700152 blueprint.write(' linux_%s: {\n' % arch)
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700153 blueprint.write(' srcs: [\n')
154 for f in sorted(asm_files):
155 blueprint.write(' "%s",\n' % f)
156 blueprint.write(' ],\n')
157 blueprint.write(' },\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700158 blueprint.write(' },\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700159
Pete Bentley44544d92019-08-15 15:01:26 +0100160 blueprint.write('}\n')
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700161
Pete Bentley44544d92019-08-15 15:01:26 +0100162 def FilterBcmAsm(self, asm, want_bcm):
163 """Filter a list of assembly outputs based on whether they belong in BCM
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700164
Pete Bentley44544d92019-08-15 15:01:26 +0100165 Args:
166 asm: Assembly file lists to filter
167 want_bcm: If true then include BCM files, otherwise do not
Dan Willemsenb57e4fc2016-07-21 11:08:44 -0700168
Pete Bentley44544d92019-08-15 15:01:26 +0100169 Returns:
170 A copy of |asm| with files filtered according to |want_bcm|
171 """
David Benjamin19676212023-01-25 10:03:53 -0500172 # TODO(https://crbug.com/boringssl/542): Rather than filtering by filename,
173 # use the variable listed in the CMake perlasm line, available in
174 # ExtractPerlAsmFromCMakeFile.
Pete Bentley44544d92019-08-15 15:01:26 +0100175 return [(archinfo, filter(lambda p: ("/crypto/fipsmodule/" in p) == want_bcm, files))
176 for (archinfo, files) in asm]
Adam Langley9e1a6602015-05-05 17:47:53 -0700177
178
David Benjamineca48e52019-08-13 11:51:53 -0400179class AndroidCMake(object):
180
181 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -0500182 self.header = LicenseHeader("#") + """
David Benjamineca48e52019-08-13 11:51:53 -0400183# This file is created by generate_build_files.py. Do not edit manually.
184# To specify a custom path prefix, set BORINGSSL_ROOT before including this
185# file, or use list(TRANSFORM ... PREPEND) from CMake 3.12.
186
187"""
188
189 def PrintVariableSection(self, out, name, files):
190 out.write('set(%s\n' % name)
191 for f in sorted(files):
192 # Ideally adding the prefix would be the caller's job, but
193 # list(TRANSFORM ... PREPEND) is only available starting CMake 3.12. When
194 # sources.cmake is the source of truth, we can ask Android to either write
195 # a CMake function or update to 3.12.
196 out.write(' ${BORINGSSL_ROOT}%s\n' % f)
197 out.write(')\n')
198
199 def WriteFiles(self, files, asm_outputs):
200 # The Android emulator uses a custom CMake buildsystem.
201 #
202 # TODO(davidben): Move our various source lists into sources.cmake and have
203 # Android consume that directly.
204 with open('android-sources.cmake', 'w+') as out:
205 out.write(self.header)
206
207 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
208 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
209 self.PrintVariableSection(out, 'tool_sources', files['tool'])
210 self.PrintVariableSection(out, 'test_support_sources',
211 files['test_support'])
212 self.PrintVariableSection(out, 'crypto_test_sources',
213 files['crypto_test'])
214 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
215
216 for ((osname, arch), asm_files) in asm_outputs:
217 self.PrintVariableSection(
218 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
219
220
Adam Langley049ef412015-06-09 18:20:57 -0700221class Bazel(object):
222 """Bazel outputs files suitable for including in Bazel files."""
223
224 def __init__(self):
225 self.firstSection = True
226 self.header = \
227"""# This file is created by generate_build_files.py. Do not edit manually.
228
229"""
230
231 def PrintVariableSection(self, out, name, files):
232 if not self.firstSection:
233 out.write('\n')
234 self.firstSection = False
235
236 out.write('%s = [\n' % name)
237 for f in sorted(files):
Matt Braithwaite16695892016-06-09 09:34:11 -0700238 out.write(' "%s",\n' % PathOf(f))
Adam Langley049ef412015-06-09 18:20:57 -0700239 out.write(']\n')
240
241 def WriteFiles(self, files, asm_outputs):
Chuck Haysc608d6b2015-10-06 17:54:16 -0700242 with open('BUILD.generated.bzl', 'w+') as out:
Adam Langley049ef412015-06-09 18:20:57 -0700243 out.write(self.header)
244
245 self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
Adam Langleyfd499932017-04-04 14:21:43 -0700246 self.PrintVariableSection(out, 'fips_fragments', files['fips_fragments'])
Adam Langley049ef412015-06-09 18:20:57 -0700247 self.PrintVariableSection(
248 out, 'ssl_internal_headers', files['ssl_internal_headers'])
249 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
250 self.PrintVariableSection(out, 'crypto_headers', files['crypto_headers'])
251 self.PrintVariableSection(
252 out, 'crypto_internal_headers', files['crypto_internal_headers'])
253 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
254 self.PrintVariableSection(out, 'tool_sources', files['tool'])
Adam Langleyf11f2332016-06-30 11:56:19 -0700255 self.PrintVariableSection(out, 'tool_headers', files['tool_headers'])
Adam Langley049ef412015-06-09 18:20:57 -0700256
257 for ((osname, arch), asm_files) in asm_outputs:
Adam Langley049ef412015-06-09 18:20:57 -0700258 self.PrintVariableSection(
Piotr Sikora3f5fe602015-10-28 12:24:35 -0700259 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
Adam Langley049ef412015-06-09 18:20:57 -0700260
David Benjamin23776d02022-12-09 11:33:17 -0500261 # Generate combined source lists for gas and nasm. Consumers have a choice
262 # of using the per-platform ones or the combined ones. In the combined
263 # mode, Windows x86 and Windows x86_64 must still be special-cased, but
264 # otherwise all assembly files can be linked together.
265 out.write('\n')
266 out.write('crypto_sources_asm = []\n')
267 for (osname, arch, _, _, asm_ext) in OS_ARCH_COMBOS:
268 if asm_ext == 'S':
269 out.write('crypto_sources_asm.extend(crypto_sources_%s_%s)\n' %
270 (osname, arch))
271 out.write('\n')
272 out.write('crypto_sources_nasm = []\n')
273 for (osname, arch, _, _, asm_ext) in OS_ARCH_COMBOS:
274 if asm_ext == 'asm':
275 out.write('crypto_sources_nasm.extend(crypto_sources_%s_%s)\n' %
276 (osname, arch))
277
Chuck Haysc608d6b2015-10-06 17:54:16 -0700278 with open('BUILD.generated_tests.bzl', 'w+') as out:
Adam Langley9c164b22015-06-10 18:54:47 -0700279 out.write(self.header)
280
281 out.write('test_support_sources = [\n')
David Benjaminc5aa8412016-07-29 17:41:58 -0400282 for filename in sorted(files['test_support'] +
283 files['test_support_headers'] +
284 files['crypto_internal_headers'] +
285 files['ssl_internal_headers']):
Adam Langley9c164b22015-06-10 18:54:47 -0700286 if os.path.basename(filename) == 'malloc.cc':
287 continue
Matt Braithwaite16695892016-06-09 09:34:11 -0700288 out.write(' "%s",\n' % PathOf(filename))
Adam Langley9c164b22015-06-10 18:54:47 -0700289
Adam Langley7b6acc52017-07-27 16:33:27 -0700290 out.write(']\n')
Chuck Haysc608d6b2015-10-06 17:54:16 -0700291
David Benjamin96628432017-01-19 19:05:47 -0500292 self.PrintVariableSection(out, 'crypto_test_sources',
293 files['crypto_test'])
294 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
Adam Langley990a3232018-05-22 10:02:59 -0700295 self.PrintVariableSection(out, 'crypto_test_data',
296 files['crypto_test_data'])
Adam Langley3e502c82019-10-16 09:56:38 -0700297 self.PrintVariableSection(out, 'urandom_test_sources',
298 files['urandom_test'])
David Benjamin96628432017-01-19 19:05:47 -0500299
Adam Langley049ef412015-06-09 18:20:57 -0700300
Robert Sloane091af42017-10-09 12:47:17 -0700301class Eureka(object):
302
303 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -0500304 self.header = LicenseHeader("#") + """
Robert Sloane091af42017-10-09 12:47:17 -0700305# This file is created by generate_build_files.py. Do not edit manually.
306
307"""
308
309 def PrintVariableSection(self, out, name, files):
310 out.write('%s := \\\n' % name)
311 for f in sorted(files):
312 out.write(' %s\\\n' % f)
313 out.write('\n')
314
315 def WriteFiles(self, files, asm_outputs):
316 # Legacy Android.mk format
317 with open('eureka.mk', 'w+') as makefile:
318 makefile.write(self.header)
319
320 self.PrintVariableSection(makefile, 'crypto_sources', files['crypto'])
321 self.PrintVariableSection(makefile, 'ssl_sources', files['ssl'])
322 self.PrintVariableSection(makefile, 'tool_sources', files['tool'])
323
324 for ((osname, arch), asm_files) in asm_outputs:
325 if osname != 'linux':
326 continue
327 self.PrintVariableSection(
328 makefile, '%s_%s_sources' % (osname, arch), asm_files)
329
330
David Benjamin38d01c62016-04-21 18:47:57 -0400331class GN(object):
332
333 def __init__(self):
334 self.firstSection = True
David Benjamin70690f72023-01-25 09:56:43 -0500335 self.header = LicenseHeader("#") + """
David Benjamin38d01c62016-04-21 18:47:57 -0400336# This file is created by generate_build_files.py. Do not edit manually.
337
338"""
339
340 def PrintVariableSection(self, out, name, files):
341 if not self.firstSection:
342 out.write('\n')
343 self.firstSection = False
344
345 out.write('%s = [\n' % name)
346 for f in sorted(files):
347 out.write(' "%s",\n' % f)
348 out.write(']\n')
349
350 def WriteFiles(self, files, asm_outputs):
351 with open('BUILD.generated.gni', 'w+') as out:
352 out.write(self.header)
353
David Benjaminc5aa8412016-07-29 17:41:58 -0400354 self.PrintVariableSection(out, 'crypto_sources',
James Robinson98dd68f2018-04-11 14:47:34 -0700355 files['crypto'] +
David Benjaminc5aa8412016-07-29 17:41:58 -0400356 files['crypto_internal_headers'])
James Robinson98dd68f2018-04-11 14:47:34 -0700357 self.PrintVariableSection(out, 'crypto_headers',
358 files['crypto_headers'])
David Benjaminc5aa8412016-07-29 17:41:58 -0400359 self.PrintVariableSection(out, 'ssl_sources',
James Robinson98dd68f2018-04-11 14:47:34 -0700360 files['ssl'] + files['ssl_internal_headers'])
361 self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
David Benjaminbb0cb952020-12-17 16:35:39 -0500362 self.PrintVariableSection(out, 'tool_sources',
363 files['tool'] + files['tool_headers'])
David Benjamin38d01c62016-04-21 18:47:57 -0400364
365 for ((osname, arch), asm_files) in asm_outputs:
366 self.PrintVariableSection(
367 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
368
369 fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0]
370 for fuzzer in files['fuzz']]
371 self.PrintVariableSection(out, 'fuzzers', fuzzers)
372
373 with open('BUILD.generated_tests.gni', 'w+') as out:
374 self.firstSection = True
375 out.write(self.header)
376
David Benjamin96628432017-01-19 19:05:47 -0500377 self.PrintVariableSection(out, 'test_support_sources',
David Benjaminc5aa8412016-07-29 17:41:58 -0400378 files['test_support'] +
379 files['test_support_headers'])
David Benjamin96628432017-01-19 19:05:47 -0500380 self.PrintVariableSection(out, 'crypto_test_sources',
381 files['crypto_test'])
David Benjaminf014d602019-05-07 18:58:06 -0500382 self.PrintVariableSection(out, 'crypto_test_data',
383 files['crypto_test_data'])
David Benjamin96628432017-01-19 19:05:47 -0500384 self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
David Benjamin38d01c62016-04-21 18:47:57 -0400385
386
387class GYP(object):
388
389 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -0500390 self.header = LicenseHeader("#") + """
David Benjamin38d01c62016-04-21 18:47:57 -0400391# This file is created by generate_build_files.py. Do not edit manually.
392
393"""
394
395 def PrintVariableSection(self, out, name, files):
396 out.write(' \'%s\': [\n' % name)
397 for f in sorted(files):
398 out.write(' \'%s\',\n' % f)
399 out.write(' ],\n')
400
401 def WriteFiles(self, files, asm_outputs):
402 with open('boringssl.gypi', 'w+') as gypi:
403 gypi.write(self.header + '{\n \'variables\': {\n')
404
David Benjaminc5aa8412016-07-29 17:41:58 -0400405 self.PrintVariableSection(gypi, 'boringssl_ssl_sources',
406 files['ssl'] + files['ssl_headers'] +
407 files['ssl_internal_headers'])
408 self.PrintVariableSection(gypi, 'boringssl_crypto_sources',
409 files['crypto'] + files['crypto_headers'] +
410 files['crypto_internal_headers'])
David Benjamin38d01c62016-04-21 18:47:57 -0400411
412 for ((osname, arch), asm_files) in asm_outputs:
413 self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' %
414 (osname, arch), asm_files)
415
416 gypi.write(' }\n}\n')
417
Adam Langleycfd80a92019-11-08 14:40:08 -0800418class CMake(object):
419
420 def __init__(self):
David Benjamin70690f72023-01-25 09:56:43 -0500421 self.header = LicenseHeader("#") + R'''
Adam Langleycfd80a92019-11-08 14:40:08 -0800422# This file is created by generate_build_files.py. Do not edit manually.
423
David Benjamin741c1532023-01-25 17:37:16 -0500424cmake_minimum_required(VERSION 3.10)
Adam Langleycfd80a92019-11-08 14:40:08 -0800425
426project(BoringSSL LANGUAGES C CXX)
427
David Benjamin741c1532023-01-25 17:37:16 -0500428set(CMAKE_CXX_STANDARD 14)
429set(CMAKE_CXX_STANDARD_REQUIRED ON)
430set(CMAKE_C_STANDARD 11)
431set(CMAKE_C_STANDARD_REQUIRED ON)
432if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
433 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fno-common -fno-exceptions -fno-rtti")
434 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fno-common")
Adam Langleycfd80a92019-11-08 14:40:08 -0800435endif()
436
David Benjamin741c1532023-01-25 17:37:16 -0500437# pthread_rwlock_t requires a feature flag on glibc.
438if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
Adam Langleycfd80a92019-11-08 14:40:08 -0800439 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
440endif()
441
442if(WIN32)
443 add_definitions(-D_HAS_EXCEPTIONS=0)
444 add_definitions(-DWIN32_LEAN_AND_MEAN)
445 add_definitions(-DNOMINMAX)
446 # Allow use of fopen.
447 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
Adam Langleycfd80a92019-11-08 14:40:08 -0800448endif()
449
450add_definitions(-DBORINGSSL_IMPLEMENTATION)
451
David Benjamin67bb28c2023-02-01 14:40:03 -0500452if(OPENSSL_NO_ASM)
453 add_definitions(-DOPENSSL_NO_ASM)
454else()
David Benjamin741c1532023-01-25 17:37:16 -0500455 # On x86 and x86_64 Windows, we use the NASM output.
456 if(WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|x86_64|amd64|x86|i[3-6]86")
457 enable_language(ASM_NASM)
458 set(OPENSSL_NASM TRUE)
459 set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8")
460 else()
Adam Langleycfd80a92019-11-08 14:40:08 -0800461 enable_language(ASM)
David Benjamin741c1532023-01-25 17:37:16 -0500462 set(OPENSSL_ASM TRUE)
David Benjamin61266e42023-01-29 15:53:30 -0500463 # Work around https://gitlab.kitware.com/cmake/cmake/-/issues/20771 in older
464 # CMake versions.
465 if(APPLE AND CMAKE_VERSION VERSION_LESS 3.19)
Adam Langleycfd80a92019-11-08 14:40:08 -0800466 if(CMAKE_OSX_SYSROOT)
467 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"")
468 endif()
469 foreach(arch ${CMAKE_OSX_ARCHITECTURES})
470 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}")
471 endforeach()
472 endif()
David Benjamin741c1532023-01-25 17:37:16 -0500473 if(NOT WIN32)
474 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack")
475 endif()
476 # Clang's integerated assembler does not support debug symbols.
477 if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang")
478 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g")
479 endif()
Adam Langleycfd80a92019-11-08 14:40:08 -0800480 endif()
481endif()
482
Adam Langleya0cdbf92020-01-21 09:07:46 -0800483if(BUILD_SHARED_LIBS)
484 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
485 # Enable position-independent code globally. This is needed because
486 # some library targets are OBJECT libraries.
487 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
488endif()
489
Adam Langleycfd80a92019-11-08 14:40:08 -0800490include_directories(src/include)
491
492'''
493
494 def PrintLibrary(self, out, name, files):
495 out.write('add_library(\n')
496 out.write(' %s\n\n' % name)
497
498 for f in sorted(files):
499 out.write(' %s\n' % PathOf(f))
500
501 out.write(')\n\n')
502
503 def PrintExe(self, out, name, files, libs):
504 out.write('add_executable(\n')
505 out.write(' %s\n\n' % name)
506
507 for f in sorted(files):
508 out.write(' %s\n' % PathOf(f))
509
510 out.write(')\n\n')
511 out.write('target_link_libraries(%s %s)\n\n' % (name, ' '.join(libs)))
512
David Benjamin741c1532023-01-25 17:37:16 -0500513 def PrintVariable(self, out, name, files):
Adam Langleycfd80a92019-11-08 14:40:08 -0800514 out.write('set(\n')
515 out.write(' %s\n\n' % name)
516 for f in sorted(files):
517 out.write(' %s\n' % PathOf(f))
518 out.write(')\n\n')
519
520 def WriteFiles(self, files, asm_outputs):
521 with open('CMakeLists.txt', 'w+') as cmake:
522 cmake.write(self.header)
523
David Benjamin741c1532023-01-25 17:37:16 -0500524 asm_sources = []
525 nasm_sources = []
Adam Langleycfd80a92019-11-08 14:40:08 -0800526 for ((osname, arch), asm_files) in asm_outputs:
David Benjamin741c1532023-01-25 17:37:16 -0500527 if (osname, arch) in (('win', 'x86'), ('win', 'x86_64')):
528 nasm_sources.extend(asm_files)
529 else:
530 asm_sources.extend(asm_files)
531 self.PrintVariable(cmake, 'CRYPTO_SOURCES_ASM', sorted(asm_sources))
532 self.PrintVariable(cmake, 'CRYPTO_SOURCES_NASM', sorted(nasm_sources))
Adam Langleycfd80a92019-11-08 14:40:08 -0800533
534 cmake.write(
David Benjamin741c1532023-01-25 17:37:16 -0500535R'''if(OPENSSL_ASM)
536 list(APPEND CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_ASM})
537endif()
538if(OPENSSL_NASM)
539 list(APPEND CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_NASM})
Adam Langleycfd80a92019-11-08 14:40:08 -0800540endif()
541
542''')
543
544 self.PrintLibrary(cmake, 'crypto',
David Benjamin741c1532023-01-25 17:37:16 -0500545 files['crypto'] + ['${CRYPTO_SOURCES_ASM_USED}'])
Adam Langleycfd80a92019-11-08 14:40:08 -0800546 self.PrintLibrary(cmake, 'ssl', files['ssl'])
Adam Langleyff631132020-01-13 15:24:22 -0800547 self.PrintExe(cmake, 'bssl', files['tool'], ['ssl', 'crypto'])
548
549 cmake.write(
David Benjamin741c1532023-01-25 17:37:16 -0500550R'''if(NOT ANDROID)
551 find_package(Threads REQUIRED)
552 target_link_libraries(crypto Threads::Threads)
Adam Langleyff631132020-01-13 15:24:22 -0800553endif()
554
David Benjamin8f88b272020-07-09 13:35:01 -0400555if(WIN32)
David Benjamin05866182023-01-29 18:25:06 -0500556 target_link_libraries(crypto ws2_32)
David Benjamin8f88b272020-07-09 13:35:01 -0400557endif()
558
Adam Langleyff631132020-01-13 15:24:22 -0800559''')
David Benjamin38d01c62016-04-21 18:47:57 -0400560
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400561class JSON(object):
562 def WriteFiles(self, files, asm_outputs):
563 sources = dict(files)
564 for ((osname, arch), asm_files) in asm_outputs:
565 sources['crypto_%s_%s' % (osname, arch)] = asm_files
566 with open('sources.json', 'w+') as f:
567 json.dump(sources, f, sort_keys=True, indent=2)
568
Adam Langley9e1a6602015-05-05 17:47:53 -0700569def FindCMakeFiles(directory):
570 """Returns list of all CMakeLists.txt files recursively in directory."""
571 cmakefiles = []
572
573 for (path, _, filenames) in os.walk(directory):
574 for filename in filenames:
575 if filename == 'CMakeLists.txt':
576 cmakefiles.append(os.path.join(path, filename))
577
578 return cmakefiles
579
Adam Langleyfd499932017-04-04 14:21:43 -0700580def OnlyFIPSFragments(path, dent, is_dir):
Matthew Braithwaite95511e92017-05-08 16:38:03 -0700581 return is_dir or (path.startswith(
582 os.path.join('src', 'crypto', 'fipsmodule', '')) and
583 NoTests(path, dent, is_dir))
Adam Langley9e1a6602015-05-05 17:47:53 -0700584
Adam Langleyfd499932017-04-04 14:21:43 -0700585def NoTestsNorFIPSFragments(path, dent, is_dir):
Adam Langley323f1eb2017-04-06 17:29:10 -0700586 return (NoTests(path, dent, is_dir) and
587 (is_dir or not OnlyFIPSFragments(path, dent, is_dir)))
Adam Langleyfd499932017-04-04 14:21:43 -0700588
589def NoTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700590 """Filter function that can be passed to FindCFiles in order to remove test
591 sources."""
592 if is_dir:
593 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400594 return 'test.' not in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700595
596
Adam Langleyfd499932017-04-04 14:21:43 -0700597def OnlyTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700598 """Filter function that can be passed to FindCFiles in order to remove
599 non-test sources."""
600 if is_dir:
David Benjamin26073832015-05-11 20:52:48 -0400601 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400602 return '_test.' in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700603
604
Adam Langleyfd499932017-04-04 14:21:43 -0700605def AllFiles(path, dent, is_dir):
David Benjamin26073832015-05-11 20:52:48 -0400606 """Filter function that can be passed to FindCFiles in order to include all
607 sources."""
608 return True
609
610
Adam Langleyfd499932017-04-04 14:21:43 -0700611def NoTestRunnerFiles(path, dent, is_dir):
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700612 """Filter function that can be passed to FindCFiles or FindHeaderFiles in
613 order to exclude test runner files."""
614 # NOTE(martinkr): This prevents .h/.cc files in src/ssl/test/runner, which
615 # are in their own subpackage, from being included in boringssl/BUILD files.
616 return not is_dir or dent != 'runner'
617
618
David Benjamin3ecd0a52017-05-19 15:26:18 -0400619def NotGTestSupport(path, dent, is_dir):
David Benjaminc3889632019-03-01 15:03:05 -0500620 return 'gtest' not in dent and 'abi_test' not in dent
David Benjamin96628432017-01-19 19:05:47 -0500621
622
Adam Langleyfd499932017-04-04 14:21:43 -0700623def SSLHeaderFiles(path, dent, is_dir):
Aaron Green0e150022018-10-16 12:05:29 -0700624 return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h', 'srtp.h']
Adam Langley049ef412015-06-09 18:20:57 -0700625
626
Adam Langley9e1a6602015-05-05 17:47:53 -0700627def FindCFiles(directory, filter_func):
628 """Recurses through directory and returns a list of paths to all the C source
629 files that pass filter_func."""
630 cfiles = []
631
632 for (path, dirnames, filenames) in os.walk(directory):
633 for filename in filenames:
634 if not filename.endswith('.c') and not filename.endswith('.cc'):
635 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700636 if not filter_func(path, filename, False):
Adam Langley9e1a6602015-05-05 17:47:53 -0700637 continue
638 cfiles.append(os.path.join(path, filename))
639
640 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700641 if not filter_func(path, dirname, True):
Adam Langley9e1a6602015-05-05 17:47:53 -0700642 del dirnames[i]
643
David Benjaminedd4c5f2020-08-19 14:46:17 -0400644 cfiles.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700645 return cfiles
646
647
Adam Langley049ef412015-06-09 18:20:57 -0700648def FindHeaderFiles(directory, filter_func):
649 """Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
650 hfiles = []
651
652 for (path, dirnames, filenames) in os.walk(directory):
653 for filename in filenames:
654 if not filename.endswith('.h'):
655 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700656 if not filter_func(path, filename, False):
Adam Langley049ef412015-06-09 18:20:57 -0700657 continue
658 hfiles.append(os.path.join(path, filename))
659
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700660 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700661 if not filter_func(path, dirname, True):
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700662 del dirnames[i]
663
David Benjaminedd4c5f2020-08-19 14:46:17 -0400664 hfiles.sort()
Adam Langley049ef412015-06-09 18:20:57 -0700665 return hfiles
666
667
Adam Langley9e1a6602015-05-05 17:47:53 -0700668def ExtractPerlAsmFromCMakeFile(cmakefile):
669 """Parses the contents of the CMakeLists.txt file passed as an argument and
670 returns a list of all the perlasm() directives found in the file."""
671 perlasms = []
672 with open(cmakefile) as f:
673 for line in f:
674 line = line.strip()
675 if not line.startswith('perlasm('):
676 continue
677 if not line.endswith(')'):
678 raise ValueError('Bad perlasm line in %s' % cmakefile)
679 # Remove "perlasm(" from start and ")" from end
680 params = line[8:-1].split()
David Benjamin19676212023-01-25 10:03:53 -0500681 if len(params) != 4:
Adam Langley9e1a6602015-05-05 17:47:53 -0700682 raise ValueError('Bad perlasm line in %s' % cmakefile)
683 perlasms.append({
David Benjamin19676212023-01-25 10:03:53 -0500684 'arch': params[1],
685 'output': os.path.join(os.path.dirname(cmakefile), params[2]),
686 'input': os.path.join(os.path.dirname(cmakefile), params[3]),
Adam Langley9e1a6602015-05-05 17:47:53 -0700687 })
688
689 return perlasms
690
691
692def ReadPerlAsmOperations():
693 """Returns a list of all perlasm() directives found in CMake config files in
694 src/."""
695 perlasms = []
696 cmakefiles = FindCMakeFiles('src')
697
698 for cmakefile in cmakefiles:
699 perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile))
700
701 return perlasms
702
703
704def PerlAsm(output_filename, input_filename, perlasm_style, extra_args):
705 """Runs the a perlasm script and puts the output into output_filename."""
706 base_dir = os.path.dirname(output_filename)
707 if not os.path.isdir(base_dir):
708 os.makedirs(base_dir)
David Benjaminfdd8e9c2016-06-26 13:18:50 -0400709 subprocess.check_call(
710 ['perl', input_filename, perlasm_style] + extra_args + [output_filename])
Adam Langley9e1a6602015-05-05 17:47:53 -0700711
712
Adam Langley9e1a6602015-05-05 17:47:53 -0700713def WriteAsmFiles(perlasms):
714 """Generates asm files from perlasm directives for each supported OS x
715 platform combination."""
716 asmfiles = {}
717
David Benjamin19676212023-01-25 10:03:53 -0500718 for perlasm in perlasms:
719 for (osname, arch, perlasm_style, extra_args, asm_ext) in OS_ARCH_COMBOS:
720 if arch != perlasm['arch']:
721 continue
722 # TODO(https://crbug.com/boringssl/524): Now that we incorporate osname in
723 # the output filename, the asm files can just go in a single directory.
724 # For now, we keep them in target-specific directories to avoid breaking
725 # downstream scripts.
726 key = (osname, arch)
727 outDir = '%s-%s' % key
Adam Langley9e1a6602015-05-05 17:47:53 -0700728 output = perlasm['output']
729 if not output.startswith('src'):
730 raise ValueError('output missing src: %s' % output)
731 output = os.path.join(outDir, output[4:])
David Benjamin19676212023-01-25 10:03:53 -0500732 output = '%s-%s.%s' % (output, osname, asm_ext)
733 PerlAsm(output, perlasm['input'], perlasm_style, extra_args)
734 asmfiles.setdefault(key, []).append(output)
Adam Langley9e1a6602015-05-05 17:47:53 -0700735
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000736 for (key, non_perl_asm_files) in NON_PERL_FILES.items():
Adam Langley9e1a6602015-05-05 17:47:53 -0700737 asmfiles.setdefault(key, []).extend(non_perl_asm_files)
738
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000739 for files in asmfiles.values():
David Benjaminedd4c5f2020-08-19 14:46:17 -0400740 files.sort()
741
Adam Langley9e1a6602015-05-05 17:47:53 -0700742 return asmfiles
743
744
David Benjamin3ecd0a52017-05-19 15:26:18 -0400745def ExtractVariablesFromCMakeFile(cmakefile):
746 """Parses the contents of the CMakeLists.txt file passed as an argument and
747 returns a dictionary of exported source lists."""
748 variables = {}
749 in_set_command = False
750 set_command = []
751 with open(cmakefile) as f:
752 for line in f:
753 if '#' in line:
754 line = line[:line.index('#')]
755 line = line.strip()
756
757 if not in_set_command:
758 if line.startswith('set('):
759 in_set_command = True
760 set_command = []
761 elif line == ')':
762 in_set_command = False
763 if not set_command:
764 raise ValueError('Empty set command')
765 variables[set_command[0]] = set_command[1:]
766 else:
767 set_command.extend([c for c in line.split(' ') if c])
768
769 if in_set_command:
770 raise ValueError('Unfinished set command')
771 return variables
772
773
Adam Langley049ef412015-06-09 18:20:57 -0700774def main(platforms):
David Benjamin3ecd0a52017-05-19 15:26:18 -0400775 cmake = ExtractVariablesFromCMakeFile(os.path.join('src', 'sources.cmake'))
Andres Erbsen5b280a82017-10-30 15:58:33 +0000776 crypto_c_files = (FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments) +
Adam Langley7f028812019-10-18 14:48:11 -0700777 FindCFiles(os.path.join('src', 'third_party', 'fiat'), NoTestsNorFIPSFragments))
Adam Langleyfd499932017-04-04 14:21:43 -0700778 fips_fragments = FindCFiles(os.path.join('src', 'crypto', 'fipsmodule'), OnlyFIPSFragments)
Adam Langleyfeca9e52017-01-23 13:07:50 -0800779 ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
David Benjamin38d01c62016-04-21 18:47:57 -0400780 tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
Adam Langleyf11f2332016-06-30 11:56:19 -0700781 tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles)
Adam Langley9e1a6602015-05-05 17:47:53 -0700782
Pete Bentley44544d92019-08-15 15:01:26 +0100783 # BCM shared library C files
784 bcm_crypto_c_files = [
785 os.path.join('src', 'crypto', 'fipsmodule', 'bcm.c')
786 ]
787
Adam Langley9e1a6602015-05-05 17:47:53 -0700788 # Generate err_data.c
789 with open('err_data.c', 'w+') as err_data:
790 subprocess.check_call(['go', 'run', 'err_data_generate.go'],
791 cwd=os.path.join('src', 'crypto', 'err'),
792 stdout=err_data)
793 crypto_c_files.append('err_data.c')
David Benjaminedd4c5f2020-08-19 14:46:17 -0400794 crypto_c_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700795
David Benjamin38d01c62016-04-21 18:47:57 -0400796 test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
David Benjamin3ecd0a52017-05-19 15:26:18 -0400797 NotGTestSupport)
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700798 test_support_h_files = (
799 FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) +
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700800 FindHeaderFiles(os.path.join('src', 'ssl', 'test'), NoTestRunnerFiles))
David Benjamin26073832015-05-11 20:52:48 -0400801
Adam Langley990a3232018-05-22 10:02:59 -0700802 crypto_test_files = []
803 if EMBED_TEST_DATA:
804 # Generate crypto_test_data.cc
805 with open('crypto_test_data.cc', 'w+') as out:
806 subprocess.check_call(
807 ['go', 'run', 'util/embed_test_data.go'] + cmake['CRYPTO_TEST_DATA'],
808 cwd='src',
809 stdout=out)
810 crypto_test_files += ['crypto_test_data.cc']
David Benjamin3ecd0a52017-05-19 15:26:18 -0400811
Adam Langley990a3232018-05-22 10:02:59 -0700812 crypto_test_files += FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
David Benjamin96ee4a82017-07-09 23:46:47 -0400813 crypto_test_files += [
David Benjaminc3889632019-03-01 15:03:05 -0500814 'src/crypto/test/abi_test.cc',
David Benjamin3ecd0a52017-05-19 15:26:18 -0400815 'src/crypto/test/file_test_gtest.cc',
816 'src/crypto/test/gtest_main.cc',
817 ]
Adam Langley3e502c82019-10-16 09:56:38 -0700818 # urandom_test.cc is in a separate binary so that it can be test PRNG
819 # initialisation.
820 crypto_test_files = [
821 file for file in crypto_test_files
822 if not file.endswith('/urandom_test.cc')
823 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400824 crypto_test_files.sort()
David Benjamin1d5a5702017-02-13 22:11:49 -0500825
826 ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
Robert Sloanae1e0872019-03-01 16:01:30 -0800827 ssl_test_files += [
828 'src/crypto/test/abi_test.cc',
829 'src/crypto/test/gtest_main.cc',
830 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400831 ssl_test_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700832
Adam Langley3e502c82019-10-16 09:56:38 -0700833 urandom_test_files = [
834 'src/crypto/fipsmodule/rand/urandom_test.cc',
835 ]
836
David Benjamin38d01c62016-04-21 18:47:57 -0400837 fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
838
David Benjaminedd4c5f2020-08-19 14:46:17 -0400839 ssl_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
840 SSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700841
Adam Langleyfd499932017-04-04 14:21:43 -0700842 def NotSSLHeaderFiles(path, filename, is_dir):
843 return not SSLHeaderFiles(path, filename, is_dir)
David Benjaminedd4c5f2020-08-19 14:46:17 -0400844 crypto_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
845 NotSSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700846
847 ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
Andres Erbsen5b280a82017-10-30 15:58:33 +0000848 crypto_internal_h_files = (
849 FindHeaderFiles(os.path.join('src', 'crypto'), NoTests) +
Adam Langley7f028812019-10-18 14:48:11 -0700850 FindHeaderFiles(os.path.join('src', 'third_party', 'fiat'), NoTests))
Adam Langley049ef412015-06-09 18:20:57 -0700851
Adam Langley9e1a6602015-05-05 17:47:53 -0700852 files = {
Pete Bentley44544d92019-08-15 15:01:26 +0100853 'bcm_crypto': bcm_crypto_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700854 'crypto': crypto_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700855 'crypto_headers': crypto_h_files,
856 'crypto_internal_headers': crypto_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400857 'crypto_test': crypto_test_files,
Adam Langley990a3232018-05-22 10:02:59 -0700858 'crypto_test_data': sorted('src/' + x for x in cmake['CRYPTO_TEST_DATA']),
Adam Langleyfd499932017-04-04 14:21:43 -0700859 'fips_fragments': fips_fragments,
David Benjamin38d01c62016-04-21 18:47:57 -0400860 'fuzz': fuzz_c_files,
Adam Langleyfeca9e52017-01-23 13:07:50 -0800861 'ssl': ssl_source_files,
Adam Langley049ef412015-06-09 18:20:57 -0700862 'ssl_headers': ssl_h_files,
863 'ssl_internal_headers': ssl_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400864 'ssl_test': ssl_test_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400865 'tool': tool_c_files,
Adam Langleyf11f2332016-06-30 11:56:19 -0700866 'tool_headers': tool_h_files,
David Benjaminc5aa8412016-07-29 17:41:58 -0400867 'test_support': test_support_c_files,
868 'test_support_headers': test_support_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400869 'urandom_test': urandom_test_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700870 }
871
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000872 asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).items())
Adam Langley9e1a6602015-05-05 17:47:53 -0700873
Adam Langley049ef412015-06-09 18:20:57 -0700874 for platform in platforms:
875 platform.WriteFiles(files, asm_outputs)
Adam Langley9e1a6602015-05-05 17:47:53 -0700876
877 return 0
878
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400879ALL_PLATFORMS = {
880 'android': Android,
881 'android-cmake': AndroidCMake,
882 'bazel': Bazel,
883 'cmake': CMake,
884 'eureka': Eureka,
885 'gn': GN,
886 'gyp': GYP,
887 'json': JSON,
888}
Adam Langley9e1a6602015-05-05 17:47:53 -0700889
Adam Langley9e1a6602015-05-05 17:47:53 -0700890if __name__ == '__main__':
David Benjamin4acc7dd2022-11-19 10:13:49 -0500891 parser = optparse.OptionParser(
892 usage='Usage: %%prog [--prefix=<path>] [all|%s]' %
893 '|'.join(sorted(ALL_PLATFORMS.keys())))
Matt Braithwaite16695892016-06-09 09:34:11 -0700894 parser.add_option('--prefix', dest='prefix',
895 help='For Bazel, prepend argument to all source files')
Adam Langley990a3232018-05-22 10:02:59 -0700896 parser.add_option(
897 '--embed_test_data', type='choice', dest='embed_test_data',
898 action='store', default="true", choices=["true", "false"],
David Benjaminf014d602019-05-07 18:58:06 -0500899 help='For Bazel or GN, don\'t embed data files in crypto_test_data.cc')
Matt Braithwaite16695892016-06-09 09:34:11 -0700900 options, args = parser.parse_args(sys.argv[1:])
901 PREFIX = options.prefix
Adam Langley990a3232018-05-22 10:02:59 -0700902 EMBED_TEST_DATA = (options.embed_test_data == "true")
Matt Braithwaite16695892016-06-09 09:34:11 -0700903
904 if not args:
905 parser.print_help()
906 sys.exit(1)
Adam Langley9e1a6602015-05-05 17:47:53 -0700907
David Benjamin4acc7dd2022-11-19 10:13:49 -0500908 if 'all' in args:
909 platforms = [platform() for platform in ALL_PLATFORMS.values()]
910 else:
911 platforms = []
912 for s in args:
913 platform = ALL_PLATFORMS.get(s)
914 if platform is None:
915 parser.print_help()
916 sys.exit(1)
917 platforms.append(platform())
Adam Langley9e1a6602015-05-05 17:47:53 -0700918
Adam Langley049ef412015-06-09 18:20:57 -0700919 sys.exit(main(platforms))