# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python from cerbero.build.build import modify_environment from cerbero.tools.libtool import LibtoolLibrary from cerbero.utils import shell, messages class Recipe(recipe.Recipe): name = 'openssl' # Note: openssl helpfully moves tarballs somewhere else (old/x.y.z/) # whenever a new release comes out, so make sure to mirror to fdo when # bumping the release! version = '1.1.1e' licenses = [{License.OPENSSL: ['LICENSE']}] stype = SourceType.TARBALL url = 'https://ftp.openssl.org/source/{0}-{1}.tar.gz'.format(name, version) tarball_checksum = '694f61ac11cb51c9bf73f54e771ff6022b0327a43bbdfa1b2f19de1662a6dcbe' deps = ['ca-certificates', 'zlib'] # Parallel make fails randomly due to undefined macros, probably races allow_parallel_build = False # Configure script is perl, not shell config_sh_needs_shell = False patches = ['openssl/0001-Load-ca-certificate.crt-from-PREFIX-etc-ssl-on-macOS.patch'] files_bins = ['openssl'] files_libs = ['libcrypto', 'libssl'] files_devel = ['include/openssl', 'lib/pkgconfig/openssl.pc', 'lib/pkgconfig/libssl.pc', 'lib/pkgconfig/libcrypto.pc'] def prepare(self): # map platforms if self.config.target_platform == Platform.IOS: if self.config.target_arch == Architecture.ARMv7: self.openssl_platform = 'BSD-generic32' elif self.config.target_arch == Architecture.ARMv7S: self.openssl_platform = 'BSD-generic32' elif self.config.target_arch == Architecture.X86: self.openssl_platform = 'BSD-generic32' elif self.config.target_arch == Architecture.X86_64: self.openssl_platform = 'BSD-generic64' elif self.config.target_arch == Architecture.ARM64: self.openssl_platform = 'BSD-generic64' else: raise NotImplementedError elif self.config.target_platform == Platform.ANDROID: if self.config.target_arch == Architecture.ARM: self.openssl_platform = 'android-arm' elif self.config.target_arch == Architecture.ARMv7: self.openssl_platform = 'android-arm' elif self.config.target_arch == Architecture.ARM64: self.openssl_platform = 'android-arm64' elif self.config.target_arch == Architecture.X86: self.openssl_platform = 'android-x86' elif self.config.target_arch == Architecture.X86_64: self.openssl_platform = 'android-x86_64' else: raise NotImplementedError self.make += ['CROSS_SYSROOT=' + self.config.sysroot] elif self.config.target_platform == Platform.DARWIN: if self.config.target_arch == Architecture.X86: self.openssl_platform = 'darwin-i386-cc' elif self.config.target_arch == Architecture.X86_64: self.openssl_platform = 'darwin64-x86_64-cc' else: raise NotImplementedError elif self.config.target_platform == Platform.LINUX: if self.config.target_arch == Architecture.X86: self.openssl_platform = 'linux-elf' elif self.config.target_arch == Architecture.X86_64: self.openssl_platform = 'linux-x86_64' elif self.config.target_arch == Architecture.ARM: self.openssl_platform = 'linux-armv4' elif self.config.target_arch == Architecture.ARMv7: self.openssl_platform = 'linux-armv4' elif self.config.target_arch == Architecture.ARM64: self.openssl_platform = 'linux-aarch64' else: raise NotImplementedError elif self.config.target_platform == Platform.WINDOWS: if self.config.target_arch == Architecture.X86: self.openssl_platform = 'mingw' elif self.config.target_arch == Architecture.X86_64: self.openssl_platform = 'mingw64' else: raise NotImplementedError cflags = self.get_env('CFLAGS') + '-fPIC -DOPENSSL_PIC' ldflags = self.get_env('LDFLAGS') + '-fPIC' ranlib = self.get_env('RANLIB') ar = self.get_env('AR') # Need to add CFLAGS to CC because CFLAG is not used everywhere in the # build, and we can't pass arguments via Configure because on Darwin, # Configure reads the `-arch x86_64` as meaning that you want to use # `x86_64` as the platform, and errors out about a redefined platform. cc = self.get_env('CC') + ' ' + self.get_env('CFLAGS') ld = self.get_env('LD') + ' ' + self.get_env('LDFLAGS') # NOTE: CFLAG and LDFLAG are not typos! self.make += ['AR=' + ar, 'RANLIB=' + ranlib, 'CC=' + cc, 'LD=' + ld, 'CFLAG=' + cflags, 'LDFLAG=' + ldflags] self.make_install = ['make', 'install_sw', 'RANLIB=' + ranlib] # We probably don't need and can't use the tools on these platforms if self.config.target_platform in (Platform.IOS, Platform.ANDROID): self.make += ['build_libs', 'openssl.pc', 'libssl.pc', 'libcrypto.pc'] self.make_install = ['make', 'install_dev', 'RANLIB=' + ranlib] if self.config.platform == Platform.WINDOWS: # Msys ships with a too-old perl, so we modify PATH to use the # mingw-perl that was downloaded and installed by bootstrap. openssl_path = os.path.join(self.config.mingw_perl_prefix, 'bin') self.prepend_env('PATH', openssl_path, sep=';') @modify_environment async def configure(self): if self.config.platform == Platform.WINDOWS: perl, found, newer = shell.check_perl_version('5.10.0', env=self.env) m = 'please run bootstrap again' if newer is None: raise FatalError('Perl not found, ' + m) if newer is False: raise FatalError('Configured Perl {!r} is {} which is too old, {}' ''.format(perl, found, m)) # OpenSSL guesses the libdir incorrectly on x86_64 config_sh = 'perl ./Configure --prefix=' + self.config.prefix + \ ' --libdir=lib' + self.config.lib_suffix + ' no-makedepend ' if self.config.target_platform == Platform.IOS: # Note: disable 'no-devcryptoeng' when we finally target the # *real* ios configuration targets config_sh += ' no-shared no-dso no-async no-devcryptoeng ' # Undefined symbols in aesni_* in libcrypto.a only on x86_64 if self.config.target_arch == Architecture.X86_64: config_sh += ' no-asm ' else: config_sh += ' shared ' # ssl3 is needed by sphinx which is used by gst-validate, which tries # to use this libssl and fails with undefined symbols. md2 is needed by # librpmio.so.8, which is used during package generation on Fedora. if self.config.target_platform == Platform.LINUX: config_sh += ' enable-ssl3 enable-ssl3-method enable-md2 ' await shell.async_call(config_sh + self.openssl_platform, self.build_dir, logfile=self.logfile, env=self.env) def post_install(self): # XXX: Don't forget to update this when the soname is bumped! # We don't build shared libraries on iOS as the build system # of openssl is broken and iOS does not support them anyway. if self.config.target_platform != Platform.IOS: libtool_la = LibtoolLibrary('ssl', 1, 1, 0, self.config.libdir, self.config.target_platform, deps=['crypto']) libtool_la.save() libtool_la = LibtoolLibrary('crypto', 1, 1, 0, self.config.libdir, self.config.target_platform) libtool_la.save() super().post_install()