Skip to content

Commit ff5be6e

Browse files
authored
bpo-32598: Use autoconf to detect usable OpenSSL (#5242)
Add https://www.gnu.org/software/autoconf-archive/ax_check_openssl.html to auto-detect compiler flags, linker flags and libraries to compile OpenSSL extensions. The M4 macro uses pkg-config and falls back to manual detection. Add autoconf magic to detect usable X509_VERIFY_PARAM_set1_host() and related functions. Refactor setup.py to use new config vars to compile _ssl and _hashlib modules. Signed-off-by: Christian Heimes <[email protected]>
1 parent d911e40 commit ff5be6e

File tree

9 files changed

+585
-83
lines changed

9 files changed

+585
-83
lines changed

Makefile.pre.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ RUNSHARED= @RUNSHARED@
181181
# ensurepip options
182182
ENSUREPIP= @ENSUREPIP@
183183

184+
# OpenSSL options for setup.py so sysconfig can pick up AC_SUBST() vars.
185+
OPENSSL_INCLUDES=@OPENSSL_INCLUDES@
186+
OPENSSL_LIBS=@OPENSSL_LIBS@
187+
OPENSSL_LDFLAGS=@OPENSSL_LDFLAGS@
188+
184189
# Modes for directories, executables and data files created by the
185190
# install process. Default to user-only-writable for all file types.
186191
DIRMODE= 755
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Use autoconf to detect OpenSSL libs, headers and supported features. The
2+
ax_check_openssl M4 macro uses pkg-config to locate OpenSSL and falls back
3+
to manual search.

Modules/_ssl.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ static PySocketModule_APIObject PySocketModule;
6464
#include "openssl/rand.h"
6565
#include "openssl/bio.h"
6666

67+
/* Set HAVE_X509_VERIFY_PARAM_SET1_HOST for non-autoconf builds */
68+
#ifndef HAVE_X509_VERIFY_PARAM_SET1_HOST
69+
# if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER > 0x1000200fL
70+
# define HAVE_X509_VERIFY_PARAM_SET1_HOST
71+
# endif
72+
#endif
73+
6774
/* SSL error object */
6875
static PyObject *PySSLErrorObject;
6976
static PyObject *PySSLCertVerificationErrorObject;

aclocal.m4

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# PARTICULAR PURPOSE.
1313

1414
m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
15-
dnl pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
16-
dnl serial 11 (pkg-config-0.29)
17-
dnl
15+
# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
16+
# serial 11 (pkg-config-0.29.1)
17+
1818
dnl Copyright © 2004 Scott James Remnant <[email protected]>.
1919
dnl Copyright © 2012-2015 Dan Nicholson <[email protected]>
2020
dnl
@@ -55,7 +55,7 @@ dnl
5555
dnl See the "Since" comment for each macro you use to see what version
5656
dnl of the macros you require.
5757
m4_defun([PKG_PREREQ],
58-
[m4_define([PKG_MACROS_VERSION], [0.29])
58+
[m4_define([PKG_MACROS_VERSION], [0.29.1])
5959
m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
6060
[m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
6161
])dnl PKG_PREREQ
@@ -288,3 +288,72 @@ AS_VAR_COPY([$1], [pkg_cv_][$1])
288288
AS_VAR_IF([$1], [""], [$5], [$4])dnl
289289
])dnl PKG_CHECK_VAR
290290

291+
dnl PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES,
292+
dnl [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],
293+
dnl [DESCRIPTION], [DEFAULT])
294+
dnl ------------------------------------------
295+
dnl
296+
dnl Prepare a "--with-" configure option using the lowercase
297+
dnl [VARIABLE-PREFIX] name, merging the behaviour of AC_ARG_WITH and
298+
dnl PKG_CHECK_MODULES in a single macro.
299+
AC_DEFUN([PKG_WITH_MODULES],
300+
[
301+
m4_pushdef([with_arg], m4_tolower([$1]))
302+
303+
m4_pushdef([description],
304+
[m4_default([$5], [build with ]with_arg[ support])])
305+
306+
m4_pushdef([def_arg], [m4_default([$6], [auto])])
307+
m4_pushdef([def_action_if_found], [AS_TR_SH([with_]with_arg)=yes])
308+
m4_pushdef([def_action_if_not_found], [AS_TR_SH([with_]with_arg)=no])
309+
310+
m4_case(def_arg,
311+
[yes],[m4_pushdef([with_without], [--without-]with_arg)],
312+
[m4_pushdef([with_without],[--with-]with_arg)])
313+
314+
AC_ARG_WITH(with_arg,
315+
AS_HELP_STRING(with_without, description[ @<:@default=]def_arg[@:>@]),,
316+
[AS_TR_SH([with_]with_arg)=def_arg])
317+
318+
AS_CASE([$AS_TR_SH([with_]with_arg)],
319+
[yes],[PKG_CHECK_MODULES([$1],[$2],$3,$4)],
320+
[auto],[PKG_CHECK_MODULES([$1],[$2],
321+
[m4_n([def_action_if_found]) $3],
322+
[m4_n([def_action_if_not_found]) $4])])
323+
324+
m4_popdef([with_arg])
325+
m4_popdef([description])
326+
m4_popdef([def_arg])
327+
328+
])dnl PKG_WITH_MODULES
329+
330+
dnl PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
331+
dnl [DESCRIPTION], [DEFAULT])
332+
dnl -----------------------------------------------
333+
dnl
334+
dnl Convenience macro to trigger AM_CONDITIONAL after PKG_WITH_MODULES
335+
dnl check._[VARIABLE-PREFIX] is exported as make variable.
336+
AC_DEFUN([PKG_HAVE_WITH_MODULES],
337+
[
338+
PKG_WITH_MODULES([$1],[$2],,,[$3],[$4])
339+
340+
AM_CONDITIONAL([HAVE_][$1],
341+
[test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"])
342+
])dnl PKG_HAVE_WITH_MODULES
343+
344+
dnl PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
345+
dnl [DESCRIPTION], [DEFAULT])
346+
dnl ------------------------------------------------------
347+
dnl
348+
dnl Convenience macro to run AM_CONDITIONAL and AC_DEFINE after
349+
dnl PKG_WITH_MODULES check. HAVE_[VARIABLE-PREFIX] is exported as make
350+
dnl and preprocessor variable.
351+
AC_DEFUN([PKG_HAVE_DEFINE_WITH_MODULES],
352+
[
353+
PKG_HAVE_WITH_MODULES([$1],[$2],[$3],[$4])
354+
355+
AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"],
356+
[AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])])
357+
])dnl PKG_HAVE_DEFINE_WITH_MODULES
358+
359+
m4_include([m4/ax_check_openssl.m4])

0 commit comments

Comments
 (0)