Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the build for RedHat-based distribution #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from distutils.core import Extension

import os, sys
import platform


def load_description():
Expand Down Expand Up @@ -40,7 +41,6 @@ def finalize_options(self):
build_ext.build_ext.finalize_options(self)

openssl_include = os.path.join(self.openssl, 'include')
openssl_lib = os.path.join(self.openssl, 'lib')

self.swig_opts = ['-I%s' % i for i in self.include_dirs + [openssl_include]] + ['-includeall', '-noproxy']
if self.swig_extra is not None:
Expand All @@ -49,8 +49,40 @@ def finalize_options(self):
else:
self.swig_opts.append(self.swig_extra)

self.include_dirs.append(openssl_include)
self.library_dirs.append(openssl_lib)
# This fixes the build on newer RedHat-based distros
# See https://gitlab.com/m2crypto/m2crypto/-/issues/100 for more info
if platform.system() == "Linux":
# For RedHat-based distros, the '-D__{arch}__' option for
# Swig needs to be normalized, particularly on i386.
mach = platform.machine().lower()
if mach in ('i386', 'i486', 'i586', 'i686'):
arch = '__i386__'
elif mach in ('ppc64', 'powerpc64', 'ppc64le', 'ppc64el'):
arch = '__powerpc64__'
elif mach in ('ppc', 'powerpc'):
arch = '__powerpc__'
else:
arch = '__%s__' % mach
self.swig_opts.append('-D%s' % arch)
if mach in ('ppc64le', 'ppc64el'):
self.swig_opts.append('-D_CALL_ELF=2')
if mach in ('arm64_be'):
self.swig_opts.append('-D__AARCH64EB__')

# Some Linux distributor has added the following line in
# /usr/include/openssl/opensslconf.h:
#
# #include "openssl-x85_64.h"
#
# This is fine with C compilers, because they are smart enough to
# handle 'local inclusion' correctly. Swig, on the other hand, is
# not as smart, and needs to be told where to find this file...
#
# Note that this is risky workaround, since it takes away the
# namespace that OpenSSL uses. If someone else has similarly
# named header files in /usr/include, there will be clashes.
self.swig_opts.append('-I' + os.path.join(openssl_include, 'openssl'))


m2ext = Extension(name="m2ext._m2ext",
sources=["swig/m2ext.i"],
Expand Down