blob: 0cabe9c2b283b1902107622f77ae35636f8af730 [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
Adam Langleycfd80a92019-11-08 14:40:08 -0800449if(NOT OPENSSL_NO_ASM)
David Benjamin741c1532023-01-25 17:37:16 -0500450 # On x86 and x86_64 Windows, we use the NASM output.
451 if(WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|x86_64|amd64|x86|i[3-6]86")
452 enable_language(ASM_NASM)
453 set(OPENSSL_NASM TRUE)
454 set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8")
455 else()
Adam Langleycfd80a92019-11-08 14:40:08 -0800456 enable_language(ASM)
David Benjamin741c1532023-01-25 17:37:16 -0500457 set(OPENSSL_ASM TRUE)
Adam Langleycfd80a92019-11-08 14:40:08 -0800458 # CMake does not add -isysroot and -arch flags to assembly.
459 if(APPLE)
460 if(CMAKE_OSX_SYSROOT)
461 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"")
462 endif()
463 foreach(arch ${CMAKE_OSX_ARCHITECTURES})
464 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}")
465 endforeach()
466 endif()
David Benjamin741c1532023-01-25 17:37:16 -0500467 if(NOT WIN32)
468 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack")
469 endif()
470 # Clang's integerated assembler does not support debug symbols.
471 if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang")
472 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g")
473 endif()
Adam Langleycfd80a92019-11-08 14:40:08 -0800474 endif()
475endif()
476
Adam Langleya0cdbf92020-01-21 09:07:46 -0800477if(BUILD_SHARED_LIBS)
478 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
479 # Enable position-independent code globally. This is needed because
480 # some library targets are OBJECT libraries.
481 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
482endif()
483
Adam Langleycfd80a92019-11-08 14:40:08 -0800484include_directories(src/include)
485
486'''
487
488 def PrintLibrary(self, out, name, files):
489 out.write('add_library(\n')
490 out.write(' %s\n\n' % name)
491
492 for f in sorted(files):
493 out.write(' %s\n' % PathOf(f))
494
495 out.write(')\n\n')
496
497 def PrintExe(self, out, name, files, libs):
498 out.write('add_executable(\n')
499 out.write(' %s\n\n' % name)
500
501 for f in sorted(files):
502 out.write(' %s\n' % PathOf(f))
503
504 out.write(')\n\n')
505 out.write('target_link_libraries(%s %s)\n\n' % (name, ' '.join(libs)))
506
David Benjamin741c1532023-01-25 17:37:16 -0500507 def PrintVariable(self, out, name, files):
Adam Langleycfd80a92019-11-08 14:40:08 -0800508 out.write('set(\n')
509 out.write(' %s\n\n' % name)
510 for f in sorted(files):
511 out.write(' %s\n' % PathOf(f))
512 out.write(')\n\n')
513
514 def WriteFiles(self, files, asm_outputs):
515 with open('CMakeLists.txt', 'w+') as cmake:
516 cmake.write(self.header)
517
David Benjamin741c1532023-01-25 17:37:16 -0500518 asm_sources = []
519 nasm_sources = []
Adam Langleycfd80a92019-11-08 14:40:08 -0800520 for ((osname, arch), asm_files) in asm_outputs:
David Benjamin741c1532023-01-25 17:37:16 -0500521 if (osname, arch) in (('win', 'x86'), ('win', 'x86_64')):
522 nasm_sources.extend(asm_files)
523 else:
524 asm_sources.extend(asm_files)
525 self.PrintVariable(cmake, 'CRYPTO_SOURCES_ASM', sorted(asm_sources))
526 self.PrintVariable(cmake, 'CRYPTO_SOURCES_NASM', sorted(nasm_sources))
Adam Langleycfd80a92019-11-08 14:40:08 -0800527
528 cmake.write(
David Benjamin741c1532023-01-25 17:37:16 -0500529R'''if(OPENSSL_ASM)
530 list(APPEND CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_ASM})
531endif()
532if(OPENSSL_NASM)
533 list(APPEND CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_NASM})
Adam Langleycfd80a92019-11-08 14:40:08 -0800534endif()
535
536''')
537
538 self.PrintLibrary(cmake, 'crypto',
David Benjamin741c1532023-01-25 17:37:16 -0500539 files['crypto'] + ['${CRYPTO_SOURCES_ASM_USED}'])
Adam Langleycfd80a92019-11-08 14:40:08 -0800540 self.PrintLibrary(cmake, 'ssl', files['ssl'])
Adam Langleyff631132020-01-13 15:24:22 -0800541 self.PrintExe(cmake, 'bssl', files['tool'], ['ssl', 'crypto'])
542
543 cmake.write(
David Benjamin741c1532023-01-25 17:37:16 -0500544R'''if(NOT ANDROID)
545 find_package(Threads REQUIRED)
546 target_link_libraries(crypto Threads::Threads)
Adam Langleyff631132020-01-13 15:24:22 -0800547endif()
548
David Benjamin8f88b272020-07-09 13:35:01 -0400549if(WIN32)
550 target_link_libraries(bssl ws2_32)
551endif()
552
Adam Langleyff631132020-01-13 15:24:22 -0800553''')
David Benjamin38d01c62016-04-21 18:47:57 -0400554
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400555class JSON(object):
556 def WriteFiles(self, files, asm_outputs):
557 sources = dict(files)
558 for ((osname, arch), asm_files) in asm_outputs:
559 sources['crypto_%s_%s' % (osname, arch)] = asm_files
560 with open('sources.json', 'w+') as f:
561 json.dump(sources, f, sort_keys=True, indent=2)
562
Adam Langley9e1a6602015-05-05 17:47:53 -0700563def FindCMakeFiles(directory):
564 """Returns list of all CMakeLists.txt files recursively in directory."""
565 cmakefiles = []
566
567 for (path, _, filenames) in os.walk(directory):
568 for filename in filenames:
569 if filename == 'CMakeLists.txt':
570 cmakefiles.append(os.path.join(path, filename))
571
572 return cmakefiles
573
Adam Langleyfd499932017-04-04 14:21:43 -0700574def OnlyFIPSFragments(path, dent, is_dir):
Matthew Braithwaite95511e92017-05-08 16:38:03 -0700575 return is_dir or (path.startswith(
576 os.path.join('src', 'crypto', 'fipsmodule', '')) and
577 NoTests(path, dent, is_dir))
Adam Langley9e1a6602015-05-05 17:47:53 -0700578
Adam Langleyfd499932017-04-04 14:21:43 -0700579def NoTestsNorFIPSFragments(path, dent, is_dir):
Adam Langley323f1eb2017-04-06 17:29:10 -0700580 return (NoTests(path, dent, is_dir) and
581 (is_dir or not OnlyFIPSFragments(path, dent, is_dir)))
Adam Langleyfd499932017-04-04 14:21:43 -0700582
583def NoTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700584 """Filter function that can be passed to FindCFiles in order to remove test
585 sources."""
586 if is_dir:
587 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400588 return 'test.' not in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700589
590
Adam Langleyfd499932017-04-04 14:21:43 -0700591def OnlyTests(path, dent, is_dir):
Adam Langley9e1a6602015-05-05 17:47:53 -0700592 """Filter function that can be passed to FindCFiles in order to remove
593 non-test sources."""
594 if is_dir:
David Benjamin26073832015-05-11 20:52:48 -0400595 return dent != 'test'
David Benjamin96ee4a82017-07-09 23:46:47 -0400596 return '_test.' in dent
Adam Langley9e1a6602015-05-05 17:47:53 -0700597
598
Adam Langleyfd499932017-04-04 14:21:43 -0700599def AllFiles(path, dent, is_dir):
David Benjamin26073832015-05-11 20:52:48 -0400600 """Filter function that can be passed to FindCFiles in order to include all
601 sources."""
602 return True
603
604
Adam Langleyfd499932017-04-04 14:21:43 -0700605def NoTestRunnerFiles(path, dent, is_dir):
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700606 """Filter function that can be passed to FindCFiles or FindHeaderFiles in
607 order to exclude test runner files."""
608 # NOTE(martinkr): This prevents .h/.cc files in src/ssl/test/runner, which
609 # are in their own subpackage, from being included in boringssl/BUILD files.
610 return not is_dir or dent != 'runner'
611
612
David Benjamin3ecd0a52017-05-19 15:26:18 -0400613def NotGTestSupport(path, dent, is_dir):
David Benjaminc3889632019-03-01 15:03:05 -0500614 return 'gtest' not in dent and 'abi_test' not in dent
David Benjamin96628432017-01-19 19:05:47 -0500615
616
Adam Langleyfd499932017-04-04 14:21:43 -0700617def SSLHeaderFiles(path, dent, is_dir):
Aaron Green0e150022018-10-16 12:05:29 -0700618 return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h', 'srtp.h']
Adam Langley049ef412015-06-09 18:20:57 -0700619
620
Adam Langley9e1a6602015-05-05 17:47:53 -0700621def FindCFiles(directory, filter_func):
622 """Recurses through directory and returns a list of paths to all the C source
623 files that pass filter_func."""
624 cfiles = []
625
626 for (path, dirnames, filenames) in os.walk(directory):
627 for filename in filenames:
628 if not filename.endswith('.c') and not filename.endswith('.cc'):
629 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700630 if not filter_func(path, filename, False):
Adam Langley9e1a6602015-05-05 17:47:53 -0700631 continue
632 cfiles.append(os.path.join(path, filename))
633
634 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700635 if not filter_func(path, dirname, True):
Adam Langley9e1a6602015-05-05 17:47:53 -0700636 del dirnames[i]
637
David Benjaminedd4c5f2020-08-19 14:46:17 -0400638 cfiles.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700639 return cfiles
640
641
Adam Langley049ef412015-06-09 18:20:57 -0700642def FindHeaderFiles(directory, filter_func):
643 """Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
644 hfiles = []
645
646 for (path, dirnames, filenames) in os.walk(directory):
647 for filename in filenames:
648 if not filename.endswith('.h'):
649 continue
Adam Langleyfd499932017-04-04 14:21:43 -0700650 if not filter_func(path, filename, False):
Adam Langley049ef412015-06-09 18:20:57 -0700651 continue
652 hfiles.append(os.path.join(path, filename))
653
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700654 for (i, dirname) in enumerate(dirnames):
Adam Langleyfd499932017-04-04 14:21:43 -0700655 if not filter_func(path, dirname, True):
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700656 del dirnames[i]
657
David Benjaminedd4c5f2020-08-19 14:46:17 -0400658 hfiles.sort()
Adam Langley049ef412015-06-09 18:20:57 -0700659 return hfiles
660
661
Adam Langley9e1a6602015-05-05 17:47:53 -0700662def ExtractPerlAsmFromCMakeFile(cmakefile):
663 """Parses the contents of the CMakeLists.txt file passed as an argument and
664 returns a list of all the perlasm() directives found in the file."""
665 perlasms = []
666 with open(cmakefile) as f:
667 for line in f:
668 line = line.strip()
669 if not line.startswith('perlasm('):
670 continue
671 if not line.endswith(')'):
672 raise ValueError('Bad perlasm line in %s' % cmakefile)
673 # Remove "perlasm(" from start and ")" from end
674 params = line[8:-1].split()
David Benjamin19676212023-01-25 10:03:53 -0500675 if len(params) != 4:
Adam Langley9e1a6602015-05-05 17:47:53 -0700676 raise ValueError('Bad perlasm line in %s' % cmakefile)
677 perlasms.append({
David Benjamin19676212023-01-25 10:03:53 -0500678 'arch': params[1],
679 'output': os.path.join(os.path.dirname(cmakefile), params[2]),
680 'input': os.path.join(os.path.dirname(cmakefile), params[3]),
Adam Langley9e1a6602015-05-05 17:47:53 -0700681 })
682
683 return perlasms
684
685
686def ReadPerlAsmOperations():
687 """Returns a list of all perlasm() directives found in CMake config files in
688 src/."""
689 perlasms = []
690 cmakefiles = FindCMakeFiles('src')
691
692 for cmakefile in cmakefiles:
693 perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile))
694
695 return perlasms
696
697
698def PerlAsm(output_filename, input_filename, perlasm_style, extra_args):
699 """Runs the a perlasm script and puts the output into output_filename."""
700 base_dir = os.path.dirname(output_filename)
701 if not os.path.isdir(base_dir):
702 os.makedirs(base_dir)
David Benjaminfdd8e9c2016-06-26 13:18:50 -0400703 subprocess.check_call(
704 ['perl', input_filename, perlasm_style] + extra_args + [output_filename])
Adam Langley9e1a6602015-05-05 17:47:53 -0700705
706
Adam Langley9e1a6602015-05-05 17:47:53 -0700707def WriteAsmFiles(perlasms):
708 """Generates asm files from perlasm directives for each supported OS x
709 platform combination."""
710 asmfiles = {}
711
David Benjamin19676212023-01-25 10:03:53 -0500712 for perlasm in perlasms:
713 for (osname, arch, perlasm_style, extra_args, asm_ext) in OS_ARCH_COMBOS:
714 if arch != perlasm['arch']:
715 continue
716 # TODO(https://crbug.com/boringssl/524): Now that we incorporate osname in
717 # the output filename, the asm files can just go in a single directory.
718 # For now, we keep them in target-specific directories to avoid breaking
719 # downstream scripts.
720 key = (osname, arch)
721 outDir = '%s-%s' % key
Adam Langley9e1a6602015-05-05 17:47:53 -0700722 output = perlasm['output']
723 if not output.startswith('src'):
724 raise ValueError('output missing src: %s' % output)
725 output = os.path.join(outDir, output[4:])
David Benjamin19676212023-01-25 10:03:53 -0500726 output = '%s-%s.%s' % (output, osname, asm_ext)
727 PerlAsm(output, perlasm['input'], perlasm_style, extra_args)
728 asmfiles.setdefault(key, []).append(output)
Adam Langley9e1a6602015-05-05 17:47:53 -0700729
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000730 for (key, non_perl_asm_files) in NON_PERL_FILES.items():
Adam Langley9e1a6602015-05-05 17:47:53 -0700731 asmfiles.setdefault(key, []).extend(non_perl_asm_files)
732
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000733 for files in asmfiles.values():
David Benjaminedd4c5f2020-08-19 14:46:17 -0400734 files.sort()
735
Adam Langley9e1a6602015-05-05 17:47:53 -0700736 return asmfiles
737
738
David Benjamin3ecd0a52017-05-19 15:26:18 -0400739def ExtractVariablesFromCMakeFile(cmakefile):
740 """Parses the contents of the CMakeLists.txt file passed as an argument and
741 returns a dictionary of exported source lists."""
742 variables = {}
743 in_set_command = False
744 set_command = []
745 with open(cmakefile) as f:
746 for line in f:
747 if '#' in line:
748 line = line[:line.index('#')]
749 line = line.strip()
750
751 if not in_set_command:
752 if line.startswith('set('):
753 in_set_command = True
754 set_command = []
755 elif line == ')':
756 in_set_command = False
757 if not set_command:
758 raise ValueError('Empty set command')
759 variables[set_command[0]] = set_command[1:]
760 else:
761 set_command.extend([c for c in line.split(' ') if c])
762
763 if in_set_command:
764 raise ValueError('Unfinished set command')
765 return variables
766
767
Adam Langley049ef412015-06-09 18:20:57 -0700768def main(platforms):
David Benjamin3ecd0a52017-05-19 15:26:18 -0400769 cmake = ExtractVariablesFromCMakeFile(os.path.join('src', 'sources.cmake'))
Andres Erbsen5b280a82017-10-30 15:58:33 +0000770 crypto_c_files = (FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments) +
Adam Langley7f028812019-10-18 14:48:11 -0700771 FindCFiles(os.path.join('src', 'third_party', 'fiat'), NoTestsNorFIPSFragments))
Adam Langleyfd499932017-04-04 14:21:43 -0700772 fips_fragments = FindCFiles(os.path.join('src', 'crypto', 'fipsmodule'), OnlyFIPSFragments)
Adam Langleyfeca9e52017-01-23 13:07:50 -0800773 ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
David Benjamin38d01c62016-04-21 18:47:57 -0400774 tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
Adam Langleyf11f2332016-06-30 11:56:19 -0700775 tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles)
Adam Langley9e1a6602015-05-05 17:47:53 -0700776
Pete Bentley44544d92019-08-15 15:01:26 +0100777 # BCM shared library C files
778 bcm_crypto_c_files = [
779 os.path.join('src', 'crypto', 'fipsmodule', 'bcm.c')
780 ]
781
Adam Langley9e1a6602015-05-05 17:47:53 -0700782 # Generate err_data.c
783 with open('err_data.c', 'w+') as err_data:
784 subprocess.check_call(['go', 'run', 'err_data_generate.go'],
785 cwd=os.path.join('src', 'crypto', 'err'),
786 stdout=err_data)
787 crypto_c_files.append('err_data.c')
David Benjaminedd4c5f2020-08-19 14:46:17 -0400788 crypto_c_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700789
David Benjamin38d01c62016-04-21 18:47:57 -0400790 test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
David Benjamin3ecd0a52017-05-19 15:26:18 -0400791 NotGTestSupport)
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700792 test_support_h_files = (
793 FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) +
Martin Kreichgauer8b487b72017-04-03 16:07:27 -0700794 FindHeaderFiles(os.path.join('src', 'ssl', 'test'), NoTestRunnerFiles))
David Benjamin26073832015-05-11 20:52:48 -0400795
Adam Langley990a3232018-05-22 10:02:59 -0700796 crypto_test_files = []
797 if EMBED_TEST_DATA:
798 # Generate crypto_test_data.cc
799 with open('crypto_test_data.cc', 'w+') as out:
800 subprocess.check_call(
801 ['go', 'run', 'util/embed_test_data.go'] + cmake['CRYPTO_TEST_DATA'],
802 cwd='src',
803 stdout=out)
804 crypto_test_files += ['crypto_test_data.cc']
David Benjamin3ecd0a52017-05-19 15:26:18 -0400805
Adam Langley990a3232018-05-22 10:02:59 -0700806 crypto_test_files += FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
David Benjamin96ee4a82017-07-09 23:46:47 -0400807 crypto_test_files += [
David Benjaminc3889632019-03-01 15:03:05 -0500808 'src/crypto/test/abi_test.cc',
David Benjamin3ecd0a52017-05-19 15:26:18 -0400809 'src/crypto/test/file_test_gtest.cc',
810 'src/crypto/test/gtest_main.cc',
811 ]
Adam Langley3e502c82019-10-16 09:56:38 -0700812 # urandom_test.cc is in a separate binary so that it can be test PRNG
813 # initialisation.
814 crypto_test_files = [
815 file for file in crypto_test_files
816 if not file.endswith('/urandom_test.cc')
817 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400818 crypto_test_files.sort()
David Benjamin1d5a5702017-02-13 22:11:49 -0500819
820 ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
Robert Sloanae1e0872019-03-01 16:01:30 -0800821 ssl_test_files += [
822 'src/crypto/test/abi_test.cc',
823 'src/crypto/test/gtest_main.cc',
824 ]
David Benjaminedd4c5f2020-08-19 14:46:17 -0400825 ssl_test_files.sort()
Adam Langley9e1a6602015-05-05 17:47:53 -0700826
Adam Langley3e502c82019-10-16 09:56:38 -0700827 urandom_test_files = [
828 'src/crypto/fipsmodule/rand/urandom_test.cc',
829 ]
830
David Benjamin38d01c62016-04-21 18:47:57 -0400831 fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
832
David Benjaminedd4c5f2020-08-19 14:46:17 -0400833 ssl_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
834 SSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700835
Adam Langleyfd499932017-04-04 14:21:43 -0700836 def NotSSLHeaderFiles(path, filename, is_dir):
837 return not SSLHeaderFiles(path, filename, is_dir)
David Benjaminedd4c5f2020-08-19 14:46:17 -0400838 crypto_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
839 NotSSLHeaderFiles)
Adam Langley049ef412015-06-09 18:20:57 -0700840
841 ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
Andres Erbsen5b280a82017-10-30 15:58:33 +0000842 crypto_internal_h_files = (
843 FindHeaderFiles(os.path.join('src', 'crypto'), NoTests) +
Adam Langley7f028812019-10-18 14:48:11 -0700844 FindHeaderFiles(os.path.join('src', 'third_party', 'fiat'), NoTests))
Adam Langley049ef412015-06-09 18:20:57 -0700845
Adam Langley9e1a6602015-05-05 17:47:53 -0700846 files = {
Pete Bentley44544d92019-08-15 15:01:26 +0100847 'bcm_crypto': bcm_crypto_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700848 'crypto': crypto_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700849 'crypto_headers': crypto_h_files,
850 'crypto_internal_headers': crypto_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400851 'crypto_test': crypto_test_files,
Adam Langley990a3232018-05-22 10:02:59 -0700852 'crypto_test_data': sorted('src/' + x for x in cmake['CRYPTO_TEST_DATA']),
Adam Langleyfd499932017-04-04 14:21:43 -0700853 'fips_fragments': fips_fragments,
David Benjamin38d01c62016-04-21 18:47:57 -0400854 'fuzz': fuzz_c_files,
Adam Langleyfeca9e52017-01-23 13:07:50 -0800855 'ssl': ssl_source_files,
Adam Langley049ef412015-06-09 18:20:57 -0700856 'ssl_headers': ssl_h_files,
857 'ssl_internal_headers': ssl_internal_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400858 'ssl_test': ssl_test_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400859 'tool': tool_c_files,
Adam Langleyf11f2332016-06-30 11:56:19 -0700860 'tool_headers': tool_h_files,
David Benjaminc5aa8412016-07-29 17:41:58 -0400861 'test_support': test_support_c_files,
862 'test_support_headers': test_support_h_files,
David Benjaminedd4c5f2020-08-19 14:46:17 -0400863 'urandom_test': urandom_test_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700864 }
865
Yoshisato Yanagisawa56508162021-03-23 05:34:47 +0000866 asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).items())
Adam Langley9e1a6602015-05-05 17:47:53 -0700867
Adam Langley049ef412015-06-09 18:20:57 -0700868 for platform in platforms:
869 platform.WriteFiles(files, asm_outputs)
Adam Langley9e1a6602015-05-05 17:47:53 -0700870
871 return 0
872
David Benjamin8c0a6eb2020-07-16 14:45:51 -0400873ALL_PLATFORMS = {
874 'android': Android,
875 'android-cmake': AndroidCMake,
876 'bazel': Bazel,
877 'cmake': CMake,
878 'eureka': Eureka,
879 'gn': GN,
880 'gyp': GYP,
881 'json': JSON,
882}
Adam Langley9e1a6602015-05-05 17:47:53 -0700883
Adam Langley9e1a6602015-05-05 17:47:53 -0700884if __name__ == '__main__':
David Benjamin4acc7dd2022-11-19 10:13:49 -0500885 parser = optparse.OptionParser(
886 usage='Usage: %%prog [--prefix=<path>] [all|%s]' %
887 '|'.join(sorted(ALL_PLATFORMS.keys())))
Matt Braithwaite16695892016-06-09 09:34:11 -0700888 parser.add_option('--prefix', dest='prefix',
889 help='For Bazel, prepend argument to all source files')
Adam Langley990a3232018-05-22 10:02:59 -0700890 parser.add_option(
891 '--embed_test_data', type='choice', dest='embed_test_data',
892 action='store', default="true", choices=["true", "false"],
David Benjaminf014d602019-05-07 18:58:06 -0500893 help='For Bazel or GN, don\'t embed data files in crypto_test_data.cc')
Matt Braithwaite16695892016-06-09 09:34:11 -0700894 options, args = parser.parse_args(sys.argv[1:])
895 PREFIX = options.prefix
Adam Langley990a3232018-05-22 10:02:59 -0700896 EMBED_TEST_DATA = (options.embed_test_data == "true")
Matt Braithwaite16695892016-06-09 09:34:11 -0700897
898 if not args:
899 parser.print_help()
900 sys.exit(1)
Adam Langley9e1a6602015-05-05 17:47:53 -0700901
David Benjamin4acc7dd2022-11-19 10:13:49 -0500902 if 'all' in args:
903 platforms = [platform() for platform in ALL_PLATFORMS.values()]
904 else:
905 platforms = []
906 for s in args:
907 platform = ALL_PLATFORMS.get(s)
908 if platform is None:
909 parser.print_help()
910 sys.exit(1)
911 platforms.append(platform())
Adam Langley9e1a6602015-05-05 17:47:53 -0700912
Adam Langley049ef412015-06-09 18:20:57 -0700913 sys.exit(main(platforms))