2021-01-21 14:13:59 +01:00
|
|
|
import subprocess
|
2023-09-26 14:14:33 +02:00
|
|
|
from typing import Optional, Sequence, Union
|
2021-01-21 14:13:59 +01:00
|
|
|
|
|
|
|
from build.makeproject import MakeProject
|
2023-09-26 12:47:44 +02:00
|
|
|
from .toolchain import AnyToolchain
|
2021-01-21 14:13:59 +01:00
|
|
|
|
|
|
|
class OpenSSLProject(MakeProject):
|
2023-09-26 14:14:33 +02:00
|
|
|
def __init__(self, url: Union[str, Sequence[str]], md5: str, installed: str,
|
2021-01-21 14:13:59 +01:00
|
|
|
**kwargs):
|
|
|
|
MakeProject.__init__(self, url, md5, installed, install_target='install_dev', **kwargs)
|
|
|
|
|
2023-09-26 12:47:44 +02:00
|
|
|
def get_make_args(self, toolchain: AnyToolchain) -> list[str]:
|
2021-01-21 14:13:59 +01:00
|
|
|
return MakeProject.get_make_args(self, toolchain) + [
|
|
|
|
'CC=' + toolchain.cc,
|
|
|
|
'CFLAGS=' + toolchain.cflags,
|
|
|
|
'CPPFLAGS=' + toolchain.cppflags,
|
|
|
|
'AR=' + toolchain.ar,
|
|
|
|
'RANLIB=' + toolchain.ranlib,
|
|
|
|
'build_libs',
|
|
|
|
]
|
|
|
|
|
2023-09-26 12:47:44 +02:00
|
|
|
def get_make_install_args(self, toolchain: AnyToolchain) -> list[str]:
|
2021-04-20 05:37:49 +02:00
|
|
|
# OpenSSL's Makefile runs "ranlib" during installation
|
|
|
|
return MakeProject.get_make_install_args(self, toolchain) + [
|
|
|
|
'RANLIB=' + toolchain.ranlib,
|
|
|
|
]
|
|
|
|
|
2023-09-26 12:47:44 +02:00
|
|
|
def _build(self, toolchain: AnyToolchain) -> None:
|
2021-01-21 14:13:59 +01:00
|
|
|
src = self.unpack(toolchain, out_of_tree=False)
|
|
|
|
|
|
|
|
# OpenSSL has a weird target architecture scheme with lots of
|
|
|
|
# hard-coded architectures; this table translates between our
|
|
|
|
# "toolchain_arch" (HOST_TRIPLET) and the OpenSSL target
|
|
|
|
openssl_archs = {
|
|
|
|
# not using "android-*" because those OpenSSL targets want
|
|
|
|
# to know where the SDK is, but our own build scripts
|
|
|
|
# prepared everything already to look like a regular Linux
|
|
|
|
# build
|
2023-09-26 15:09:38 +02:00
|
|
|
'armv7a-linux-androideabi': 'linux-generic32',
|
2021-01-21 14:13:59 +01:00
|
|
|
'aarch64-linux-android': 'linux-aarch64',
|
|
|
|
'i686-linux-android': 'linux-x86-clang',
|
|
|
|
'x86_64-linux-android': 'linux-x86_64-clang',
|
|
|
|
|
2023-09-26 15:02:01 +02:00
|
|
|
# generic Linux
|
2021-01-21 14:13:59 +01:00
|
|
|
'arm-linux-gnueabihf': 'linux-generic32',
|
|
|
|
|
|
|
|
# Windows
|
|
|
|
'i686-w64-mingw32': 'mingw',
|
|
|
|
'x86_64-w64-mingw32': 'mingw64',
|
2023-09-26 15:02:01 +02:00
|
|
|
|
|
|
|
# Apple
|
|
|
|
'x86_64-apple-darwin': 'darwin64-x86_64-cc',
|
|
|
|
'aarch64-apple-darwin': 'darwin64-arm64-cc',
|
2021-01-21 14:13:59 +01:00
|
|
|
}
|
|
|
|
|
2023-09-26 15:19:39 +02:00
|
|
|
openssl_arch = openssl_archs[toolchain.host_triplet]
|
2021-01-21 14:13:59 +01:00
|
|
|
|
2023-09-26 15:02:46 +02:00
|
|
|
configure = [
|
|
|
|
'./Configure',
|
|
|
|
'no-shared',
|
|
|
|
'no-module',
|
|
|
|
'no-engine',
|
|
|
|
'no-static-engine',
|
|
|
|
'no-async',
|
|
|
|
'no-tests',
|
2023-09-26 15:05:04 +02:00
|
|
|
'no-makedepend',
|
2023-09-26 15:30:22 +02:00
|
|
|
'--libdir=lib', # no "lib64" on amd64, please
|
2023-09-26 15:02:46 +02:00
|
|
|
'--prefix=' + toolchain.install_prefix,
|
|
|
|
]
|
|
|
|
|
2023-09-26 15:03:43 +02:00
|
|
|
if toolchain.is_windows:
|
|
|
|
# workaround for build failures
|
|
|
|
configure.append('no-asm')
|
|
|
|
|
2023-09-26 15:31:00 +02:00
|
|
|
if toolchain.host_triplet is not None:
|
|
|
|
configure.append(openssl_archs[toolchain.host_triplet])
|
2023-09-26 15:31:20 +02:00
|
|
|
configure.append(f'--cross-compile-prefix={toolchain.host_triplet}-')
|
2023-09-26 15:31:00 +02:00
|
|
|
|
2023-09-26 15:02:46 +02:00
|
|
|
subprocess.check_call(configure, cwd=src, env=toolchain.env)
|
2021-08-28 22:38:02 +02:00
|
|
|
self.build_make(toolchain, src)
|