Blame SOURCES/freeradius-fixes-to-python3-module-since-v3.0.20.patch

601982
From 322f3b0d94f32e01e2db0c76fd38409eddf392ce Mon Sep 17 00:00:00 2001
601982
From: Jorge Pereira <jpereiran@gmail.com>
601982
Date: Thu, 5 Dec 2019 16:02:18 -0300
601982
Subject: [PATCH] Fix rlm_python3 build
601982
601982
Just backporting from the master branch.
601982
601982
Backport from rlm_python (#3184) changes to rlm_python3
601982
601982
Brief:
601982
601982
We should append the 'python_path' to sys.path #3180
601982
601982
we should append 'python_path' paths in 'sys.path', due to PySys_SetPath()
601982
reset the entire python path causing problems to use the existing libraries
601982
601982
Remove unnecessary src/modules/rlm_python3/radiusd_test.py
601982
601982
Don't call if 'instantiate' and 'detach' are not declared.
601982
601982
It's related to the discussion in #3185.
601982
601982
Fix missing destroy for some statements
601982
601982
Fix Py_SetProgramName() use (#3196)
601982
601982
As the documentation says, the use of Py_SetProgramName() with wchar_t*
601982
should be only from Python >= 3.5.x
601982
601982
References:
601982
601982
Python <= 3.4.x https://docs.python.org/3.4/extending/embedding.html#very-high-level-embedding
601982
Python >= 3.5.x https://docs.python.org/3.5/extending/embedding.html#very-high-level-embedding
601982
601982
Add missing 'ifdef WITH_PROXY' checks (#3198)
601982
601982
Clean up (#3197)
601982
601982
don't try and build rlm_python3 if we can't configure it
601982
601982
Just call Py_DECREF() (#3199)
601982
601982
Fix libpython3 cross platform load (#3284)
601982
601982
Python3 fixes (#3350)
601982
601982
* python3-config for Python 3.8 requires --embed parameter
601982
601982
As described in https://bugs.python.org/issue36721, python3-config now
601982
requires --embed for embedded interpreters. Otherwise, -lpython3.8 is
601982
not included in ldflags
601982
601982
* Python 3.8 has removed the "m" suffix in the library name
601982
601982
As discussed in: https://bugs.python.org/issue36707
601982
601982
* Use dl_iterate_phdr to find the appropriate python library
601982
601982
Otherwise, installation of the libpython3-dev packages is required
601982
in most distributions
601982
601982
* Update configure file for rlm_python3
601982
601982
* Use AX_COMPARE_VERSION to check Python version
601982
601982
Keep the module directory in python_path
601982
---
601982
 raddb/mods-available/python             |    2 +-
601982
 raddb/mods-available/python3            |    2 +-
601982
 src/include/conf.h                      |    8 +
601982
 src/main/modules.c                      |    8 -
601982
 src/modules/rlm_python3/configure       | 1008 ++++++++---------------
601982
 src/modules/rlm_python3/configure.ac    |  163 ++--
601982
 src/modules/rlm_python3/radiusd_test.py |   63 --
601982
 src/modules/rlm_python3/rlm_python3.c   |  188 ++---
601982
 8 files changed, 516 insertions(+), 926 deletions(-)
601982
 delete mode 100644 src/modules/rlm_python3/radiusd_test.py
601982
601982
diff --git a/raddb/mods-available/python b/raddb/mods-available/python
601982
index bd172dca05..c19ddcd87e 100644
601982
--- a/raddb/mods-available/python
601982
+++ b/raddb/mods-available/python
601982
@@ -13,7 +13,7 @@ python {
601982
 	#  item is GLOBAL TO THE SERVER.  That is, you cannot have two
601982
 	#  instances of the python module, each with a different path.
601982
 	#
601982
-#        python_path="/path/to/python/files:/another_path/to/python_files/"
601982
+#        python_path="${modconfdir}/${.:name}:/path/to/python/files:/another_path/to/python_files/"
601982
 
601982
 	module = example
601982
 
601982
diff --git a/raddb/mods-available/python3 b/raddb/mods-available/python3
601982
index 246dfd74ce..0593c69f1a 100644
601982
--- a/raddb/mods-available/python3
601982
+++ b/raddb/mods-available/python3
601982
@@ -13,7 +13,7 @@ python3 {
601982
 	#  item is GLOBAL TO THE SERVER.  That is, you cannot have two
601982
 	#  instances of the python module, each with a different path.
601982
 	#
601982
-#        python_path="/path/to/python/files:/another_path/to/python_files/"
601982
+#	python_path="${modconfdir}/${.:name}:/another_path/to/python_files"
601982
 
601982
 	module = example
601982
 
601982
diff --git a/src/include/conf.h b/src/include/conf.h
601982
index 758a332b6e..95005d545f 100644
601982
--- a/src/include/conf.h
601982
+++ b/src/include/conf.h
601982
@@ -13,3 +13,11 @@
601982
 #define SRADUTMP		LOGDIR "/sradutmp"
601982
 #define RADWTMP			LOGDIR "/radwtmp"
601982
 #define SRADWTMP		LOGDIR "/sradwtmp"
601982
+
601982
+#ifdef __APPLE__
601982
+#  define LT_SHREXT ".dylib"
601982
+#elif defined (WIN32)
601982
+#  define LT_SHREXT ".dll"
601982
+#else
601982
+#  define LT_SHREXT ".so"
601982
+#endif
601982
diff --git a/src/main/modules.c b/src/main/modules.c
601982
index 319879c870..c05aa5bf67 100644
601982
--- a/src/main/modules.c
601982
+++ b/src/main/modules.c
601982
@@ -95,14 +95,6 @@ const section_type_value_t section_type_value[MOD_COUNT] = {
601982
 #define RTLD_LOCAL (0)
601982
 #endif
601982
 
601982
-#ifdef __APPLE__
601982
-#  define LT_SHREXT ".dylib"
601982
-#elif defined (WIN32)
601982
-#  define LT_SHREXT ".dll"
601982
-#else
601982
-#  define LT_SHREXT ".so"
601982
-#endif
601982
-
601982
 /** Check if the magic number in the module matches the one in the library
601982
  *
601982
  * This is used to detect potential ABI issues caused by running with modules which
601982
diff --git a/src/modules/rlm_python3/configure b/src/modules/rlm_python3/configure
601982
index ff89a16149..05907f12c3 100755
601982
--- a/src/modules/rlm_python3/configure
601982
+++ b/src/modules/rlm_python3/configure
601982
@@ -588,7 +588,17 @@ LIBOBJS
601982
 targetname
601982
 mod_cflags
601982
 mod_ldflags
601982
-PYTHON3_BIN
601982
+AWK
601982
+PYTHON3_CONFIG_BIN
601982
+pkgpyexecdir
601982
+pyexecdir
601982
+pkgpythondir
601982
+pythondir
601982
+PYTHON_PLATFORM
601982
+PYTHON_EXEC_PREFIX
601982
+PYTHON_PREFIX
601982
+PYTHON_VERSION
601982
+PYTHON
601982
 CPP
601982
 OBJEXT
601982
 EXEEXT
601982
@@ -638,9 +648,7 @@ SHELL'
601982
 ac_subst_files=''
601982
 ac_user_opts='
601982
 enable_option_checking
601982
-with_rlm_python3_bin
601982
-with_rlm_python3_lib_dir
601982
-with_rlm_python3_include_dir
601982
+with_rlm_python3_config_bin
601982
 '
601982
       ac_precious_vars='build_alias
601982
 host_alias
601982
@@ -650,7 +658,8 @@ CFLAGS
601982
 LDFLAGS
601982
 LIBS
601982
 CPPFLAGS
601982
-CPP'
601982
+CPP
601982
+PYTHON'
601982
 
601982
 
601982
 # Initialize some variables set by options.
601982
@@ -1257,9 +1266,7 @@ if test -n "$ac_init_help"; then
601982
 Optional Packages:
601982
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
601982
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
601982
-  --with-rlm-python3-bin=PATH   Path to python3 binary
601982
-  --with-rlm-python3-lib-dir=DIR       Directory for Python library files
601982
-  --with-rlm-python3-include-dir=DIR   Directory for Python include files
601982
+  --with-rlm-python3-config-bin=PATH   Path to python-config3 binary
601982
 
601982
 Some influential environment variables:
601982
   CC          C compiler command
601982
@@ -1270,6 +1277,7 @@ Some influential environment variables:
601982
   CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
601982
               you have headers in a nonstandard directory <include dir>
601982
   CPP         C preprocessor
601982
+  PYTHON      the Python interpreter
601982
 
601982
 Use these variables to override the choices made by `configure' or to help
601982
 it to find libraries and programs with nonstandard names/locations.
601982
@@ -2822,46 +2830,92 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
601982
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
601982
 
601982
 
601982
-		PYTHON3_BIN=
601982
 
601982
-# Check whether --with-rlm-python3-bin was given.
601982
-if test "${with_rlm_python3_bin+set}" = set; then :
601982
-  withval=$with_rlm_python3_bin;  case "$withval" in
601982
-	    no)
601982
-		as_fn_error $? "Need rlm-python3-bin" "$LINENO" 5
601982
-		;;
601982
-	    yes)
601982
-		;;
601982
-	    *)
601982
-		PYTHON3_BIN="$withval"
601982
-		;;
601982
-	  esac
601982
 
601982
-fi
601982
 
601982
 
601982
-	if test "x$PYTHON3_BIN" = x; then
601982
-		for ac_prog in  python3
601982
-do
601982
-  # Extract the first word of "$ac_prog", so it can be a program name with args.
601982
-set dummy $ac_prog; ac_word=$2
601982
+
601982
+        if test -n "$PYTHON"; then
601982
+      # If the user set $PYTHON, use it and don't search something else.
601982
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $PYTHON version is >= 3.0" >&5
601982
+$as_echo_n "checking whether $PYTHON version is >= 3.0... " >&6; }
601982
+      prog="import sys
601982
+# split strings by '.' and convert to numeric.  Append some zeros
601982
+# because we need at least 4 digits for the hex conversion.
601982
+# map returns an iterator in Python 3.0 and a list in 2.x
601982
+minver = list(map(int, '3.0'.split('.'))) + [0, 0, 0]
601982
+minverhex = 0
601982
+# xrange is not present in Python 3.0 and range returns an iterator
601982
+for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[i]
601982
+sys.exit(sys.hexversion < minverhex)"
601982
+  if { echo "$as_me:$LINENO: $PYTHON -c "$prog"" >&5
601982
+   ($PYTHON -c "$prog") >&5 2>&5
601982
+   ac_status=$?
601982
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
601982
+   (exit $ac_status); }; then :
601982
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
601982
+$as_echo "yes" >&6; }
601982
+else
601982
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
601982
+$as_echo "no" >&6; }
601982
+			       as_fn_error $? "Python interpreter is too old" "$LINENO" 5
601982
+fi
601982
+      am_display_PYTHON=$PYTHON
601982
+    else
601982
+      # Otherwise, try each interpreter until we find one that satisfies
601982
+      # VERSION.
601982
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a Python interpreter with version >= 3.0" >&5
601982
+$as_echo_n "checking for a Python interpreter with version >= 3.0... " >&6; }
601982
+if ${am_cv_pathless_PYTHON+:} false; then :
601982
+  $as_echo_n "(cached) " >&6
601982
+else
601982
+
601982
+	for am_cv_pathless_PYTHON in python python2 python3  python3.9 python3.8 python3.7 python3.6 python3.5 python3.4 python3.3  python3.2 python3.1 python3.0  python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1  python2.0 none; do
601982
+	  test "$am_cv_pathless_PYTHON" = none && break
601982
+	  prog="import sys
601982
+# split strings by '.' and convert to numeric.  Append some zeros
601982
+# because we need at least 4 digits for the hex conversion.
601982
+# map returns an iterator in Python 3.0 and a list in 2.x
601982
+minver = list(map(int, '3.0'.split('.'))) + [0, 0, 0]
601982
+minverhex = 0
601982
+# xrange is not present in Python 3.0 and range returns an iterator
601982
+for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[i]
601982
+sys.exit(sys.hexversion < minverhex)"
601982
+  if { echo "$as_me:$LINENO: $am_cv_pathless_PYTHON -c "$prog"" >&5
601982
+   ($am_cv_pathless_PYTHON -c "$prog") >&5 2>&5
601982
+   ac_status=$?
601982
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
601982
+   (exit $ac_status); }; then :
601982
+  break
601982
+fi
601982
+	done
601982
+fi
601982
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_pathless_PYTHON" >&5
601982
+$as_echo "$am_cv_pathless_PYTHON" >&6; }
601982
+      # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
601982
+      if test "$am_cv_pathless_PYTHON" = none; then
601982
+	PYTHON=:
601982
+      else
601982
+        # Extract the first word of "$am_cv_pathless_PYTHON", so it can be a program name with args.
601982
+set dummy $am_cv_pathless_PYTHON; ac_word=$2
601982
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
601982
 $as_echo_n "checking for $ac_word... " >&6; }
601982
-if ${ac_cv_prog_PYTHON3_BIN+:} false; then :
601982
+if ${ac_cv_path_PYTHON+:} false; then :
601982
   $as_echo_n "(cached) " >&6
601982
 else
601982
-  if test -n "$PYTHON3_BIN"; then
601982
-  ac_cv_prog_PYTHON3_BIN="$PYTHON3_BIN" # Let the user override the test.
601982
-else
601982
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
601982
-as_dummy="${PATH}:/usr/bin:/usr/local/bin"
601982
-for as_dir in $as_dummy
601982
+  case $PYTHON in
601982
+  [\\/]* | ?:[\\/]*)
601982
+  ac_cv_path_PYTHON="$PYTHON" # Let the user override the test with a path.
601982
+  ;;
601982
+  *)
601982
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
601982
+for as_dir in $PATH
601982
 do
601982
   IFS=$as_save_IFS
601982
   test -z "$as_dir" && as_dir=.
601982
     for ac_exec_ext in '' $ac_executable_extensions; do
601982
   if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
601982
-    ac_cv_prog_PYTHON3_BIN="$ac_prog"
601982
+    ac_cv_path_PYTHON="$as_dir/$ac_word$ac_exec_ext"
601982
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
601982
     break 2
601982
   fi
601982
@@ -2869,708 +2923,358 @@ done
601982
   done
601982
 IFS=$as_save_IFS
601982
 
601982
+  ;;
601982
+esac
601982
 fi
601982
-fi
601982
-PYTHON3_BIN=$ac_cv_prog_PYTHON3_BIN
601982
-if test -n "$PYTHON3_BIN"; then
601982
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON3_BIN" >&5
601982
-$as_echo "$PYTHON3_BIN" >&6; }
601982
+PYTHON=$ac_cv_path_PYTHON
601982
+if test -n "$PYTHON"; then
601982
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON" >&5
601982
+$as_echo "$PYTHON" >&6; }
601982
 else
601982
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
601982
 $as_echo "no" >&6; }
601982
 fi
601982
 
601982
 
601982
-  test -n "$PYTHON3_BIN" && break
601982
-done
601982
-test -n "$PYTHON3_BIN" || PYTHON3_BIN="not-found"
601982
-
601982
-	fi
601982
-
601982
-	if test "x$PYTHON3_BIN" = "xnot-found"; then
601982
-		fail="python-binary"
601982
-	fi
601982
-
601982
-		PY_LIB_DIR=
601982
-
601982
-# Check whether --with-rlm-python3-lib-dir was given.
601982
-if test "${with_rlm_python3_lib_dir+set}" = set; then :
601982
-  withval=$with_rlm_python3_lib_dir;  case "$withval" in
601982
-	    no)
601982
-		as_fn_error $? "Need rlm-python3-lib-dir" "$LINENO" 5
601982
-		;;
601982
-	    yes)
601982
-		;;
601982
-	    *)
601982
-		PY_LIB_DIR="$withval"
601982
-		;;
601982
-	  esac
601982
-
601982
-fi
601982
+      fi
601982
+      am_display_PYTHON=$am_cv_pathless_PYTHON
601982
+    fi
601982
 
601982
 
601982
-		PY_INC_DIR=
601982
+  if test "$PYTHON" = :; then
601982
+      :
601982
+  else
601982
 
601982
-# Check whether --with-rlm-python3-include-dir was given.
601982
-if test "${with_rlm_python3_include_dir+set}" = set; then :
601982
-  withval=$with_rlm_python3_include_dir;  case "$withval" in
601982
-	    no)
601982
-		as_fn_error $? "Need rlm-python3-include-dir" "$LINENO" 5
601982
-		;;
601982
-	    yes)
601982
-		;;
601982
-	    *)
601982
-		PY_INC_DIR="$withval"
601982
-		;;
601982
-	  esac
601982
 
601982
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $am_display_PYTHON version" >&5
601982
+$as_echo_n "checking for $am_display_PYTHON version... " >&6; }
601982
+if ${am_cv_python_version+:} false; then :
601982
+  $as_echo_n "(cached) " >&6
601982
+else
601982
+  am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[:3])"`
601982
 fi
601982
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_python_version" >&5
601982
+$as_echo "$am_cv_python_version" >&6; }
601982
+  PYTHON_VERSION=$am_cv_python_version
601982
 
601982
 
601982
-	if test x$fail = x; then
601982
-		PY_PREFIX=`${PYTHON3_BIN} -c 'import sys ; print(sys.prefix)'`
601982
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: Python sys.prefix \"${PY_PREFIX}\"" >&5
601982
-$as_echo "$as_me: Python sys.prefix \"${PY_PREFIX}\"" >&6;}
601982
-
601982
-		PY_EXEC_PREFIX=`${PYTHON3_BIN} -c 'import sys ; print(sys.exec_prefix)'`
601982
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: Python sys.exec_prefix \"${PY_EXEC_PREFIX}\"" >&5
601982
-$as_echo "$as_me: Python sys.exec_prefix \"${PY_EXEC_PREFIX}\"" >&6;}
601982
-
601982
-		PY_SYS_VERSION=`${PYTHON3_BIN} -c 'import sys ; print(sys.version[0:3])'`
601982
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: Python sys.version \"${PY_SYS_VERSION}\"" >&5
601982
-$as_echo "$as_me: Python sys.version \"${PY_SYS_VERSION}\"" >&6;}
601982
-
601982
-		if test "x$PY_LIB_DIR" = "x"; then
601982
-			PY_LIB_DIR="$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config"
601982
-			PY_LIB_LOC="-L$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config"
601982
-		fi
601982
-
601982
-		PY_MAKEFILE="$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config/Makefile"
601982
-		if test -f ${PY_MAKEFILE}; then
601982
-			PY_LOCAL_MOD_LIBS=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[:blank:]]/ /g;s/^ *//;s/ *$//'`
601982
-			{ $as_echo "$as_me:${as_lineno-$LINENO}: Python local_mod_libs \"${PY_LOCAL_MOD_LIBS}\"" >&5
601982
-$as_echo "$as_me: Python local_mod_libs \"${PY_LOCAL_MOD_LIBS}\"" >&6;}
601982
-
601982
-			PY_BASE_MOD_LIBS=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[:blank:]]/ /g;s/^ *//;s/ *$//'`
601982
-			{ $as_echo "$as_me:${as_lineno-$LINENO}: Python base_mod_libs \"${PY_BASE_MOD_LIBS}\"" >&5
601982
-$as_echo "$as_me: Python base_mod_libs \"${PY_BASE_MOD_LIBS}\"" >&6;}
601982
-
601982
-			PY_OTHER_LIBS=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[:blank:]]/ /g;s/  / /g;s/^ *//;s/ *$//'`
601982
-			PY_OTHER_LDFLAGS=`sed -n -e 's/^LINKFORSHARED=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[:blank:]]/ /g;s/  / /g;s/^ *//;s/ *$//'`
601982
-			{ $as_echo "$as_me:${as_lineno-$LINENO}: Python other_libs \"${PY_OTHER_LDFLAGS} ${PY_OTHER_LIBS}\"" >&5
601982
-$as_echo "$as_me: Python other_libs \"${PY_OTHER_LDFLAGS} ${PY_OTHER_LIBS}\"" >&6;}
601982
-		fi
601982
-		PY_EXTRA_LIBS="$PY_LOCALMODLIBS $PY_BASE_MOD_LIBS $PY_OTHER_LIBS"
601982
-
601982
-		old_CFLAGS=$CFLAGS
601982
-		CFLAGS="$CFLAGS $PY_CFLAGS"
601982
-		smart_try_dir="$PY_PREFIX/include/python$PY_SYS_VERSION"
601982
-
601982
 
601982
+  PYTHON_PREFIX='${prefix}'
601982
 
601982
-ac_safe=`echo "Python.h" | sed 'y%./+-%__pm%'`
601982
-old_CPPFLAGS="$CPPFLAGS"
601982
-smart_include=
601982
-smart_include_dir="/usr/local/include /opt/include"
601982
+  PYTHON_EXEC_PREFIX='${exec_prefix}'
601982
 
601982
-_smart_try_dir=
601982
-_smart_include_dir=
601982
 
601982
-for _prefix in $smart_prefix ""; do
601982
-  for _dir in $smart_try_dir; do
601982
-    _smart_try_dir="${_smart_try_dir} ${_dir}/${_prefix}"
601982
-  done
601982
-
601982
-  for _dir in $smart_include_dir; do
601982
-    _smart_include_dir="${_smart_include_dir} ${_dir}/${_prefix}"
601982
-  done
601982
-done
601982
-
601982
-if test "x$_smart_try_dir" != "x"; then
601982
-  for try in $_smart_try_dir; do
601982
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python.h in $try" >&5
601982
-$as_echo_n "checking for Python.h in $try... " >&6; }
601982
-    CPPFLAGS="-isystem $try $old_CPPFLAGS"
601982
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
601982
-/* end confdefs.h.  */
601982
-
601982
-		    #include <Python.h>
601982
-int
601982
-main ()
601982
-{
601982
-int a = 1;
601982
-  ;
601982
-  return 0;
601982
-}
601982
-_ACEOF
601982
-if ac_fn_c_try_compile "$LINENO"; then :
601982
-
601982
-		     smart_include="-isystem $try"
601982
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
601982
-$as_echo "yes" >&6; }
601982
-		     break
601982
 
601982
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $am_display_PYTHON platform" >&5
601982
+$as_echo_n "checking for $am_display_PYTHON platform... " >&6; }
601982
+if ${am_cv_python_platform+:} false; then :
601982
+  $as_echo_n "(cached) " >&6
601982
 else
601982
-
601982
-		     smart_include=
601982
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
601982
-$as_echo "no" >&6; }
601982
-
601982
-fi
601982
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
601982
-  done
601982
-  CPPFLAGS="$old_CPPFLAGS"
601982
-fi
601982
-
601982
-if test "x$smart_include" = "x"; then
601982
-  for _prefix in $smart_prefix; do
601982
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${_prefix}/Python.h" >&5
601982
-$as_echo_n "checking for ${_prefix}/Python.h... " >&6; }
601982
-
601982
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
601982
-/* end confdefs.h.  */
601982
-
601982
-		    #include <Python.h>
601982
-int
601982
-main ()
601982
-{
601982
-int a = 1;
601982
-  ;
601982
-  return 0;
601982
-}
601982
-_ACEOF
601982
-if ac_fn_c_try_compile "$LINENO"; then :
601982
-
601982
-		     smart_include="-isystem ${_prefix}/"
601982
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
601982
-$as_echo "yes" >&6; }
601982
-		     break
601982
-
601982
+  am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`
601982
+fi
601982
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_python_platform" >&5
601982
+$as_echo "$am_cv_python_platform" >&6; }
601982
+  PYTHON_PLATFORM=$am_cv_python_platform
601982
+
601982
+
601982
+  # Just factor out some code duplication.
601982
+  am_python_setup_sysconfig="\
601982
+import sys
601982
+# Prefer sysconfig over distutils.sysconfig, for better compatibility
601982
+# with python 3.x.  See automake bug#10227.
601982
+try:
601982
+    import sysconfig
601982
+except ImportError:
601982
+    can_use_sysconfig = 0
601982
+else:
601982
+    can_use_sysconfig = 1
601982
+# Can't use sysconfig in CPython 2.7, since it's broken in virtualenvs:
601982
+# <https://github.com/pypa/virtualenv/issues/118>
601982
+try:
601982
+    from platform import python_implementation
601982
+    if python_implementation() == 'CPython' and sys.version[:3] == '2.7':
601982
+        can_use_sysconfig = 0
601982
+except ImportError:
601982
+    pass"
601982
+
601982
+
601982
+            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $am_display_PYTHON script directory" >&5
601982
+$as_echo_n "checking for $am_display_PYTHON script directory... " >&6; }
601982
+if ${am_cv_python_pythondir+:} false; then :
601982
+  $as_echo_n "(cached) " >&6
601982
 else
601982
+  if test "x$prefix" = xNONE
601982
+     then
601982
+       am_py_prefix=$ac_default_prefix
601982
+     else
601982
+       am_py_prefix=$prefix
601982
+     fi
601982
+     am_cv_python_pythondir=`$PYTHON -c "
601982
+$am_python_setup_sysconfig
601982
+if can_use_sysconfig:
601982
+    sitedir = sysconfig.get_path('purelib', vars={'base':'$am_py_prefix'})
601982
+else:
601982
+    from distutils import sysconfig
601982
+    sitedir = sysconfig.get_python_lib(0, 0, prefix='$am_py_prefix')
601982
+sys.stdout.write(sitedir)"`
601982
+     case $am_cv_python_pythondir in
601982
+     $am_py_prefix*)
601982
+       am__strip_prefix=`echo "$am_py_prefix" | sed 's|.|.|g'`
601982
+       am_cv_python_pythondir=`echo "$am_cv_python_pythondir" | sed "s,^$am__strip_prefix,$PYTHON_PREFIX,"`
601982
+       ;;
601982
+     *)
601982
+       case $am_py_prefix in
601982
+         /usr|/System*) ;;
601982
+         *)
601982
+	  am_cv_python_pythondir=$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages
601982
+	  ;;
601982
+       esac
601982
+       ;;
601982
+     esac
601982
 
601982
-		     smart_include=
601982
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
601982
-$as_echo "no" >&6; }
601982
-
601982
-fi
601982
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
601982
-  done
601982
 fi
601982
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_python_pythondir" >&5
601982
+$as_echo "$am_cv_python_pythondir" >&6; }
601982
+  pythondir=$am_cv_python_pythondir
601982
 
601982
-if test "x$smart_include" = "x"; then
601982
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python.h" >&5
601982
-$as_echo_n "checking for Python.h... " >&6; }
601982
 
601982
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
601982
-/* end confdefs.h.  */
601982
 
601982
-		    #include <Python.h>
601982
-int
601982
-main ()
601982
-{
601982
-int a = 1;
601982
-  ;
601982
-  return 0;
601982
-}
601982
-_ACEOF
601982
-if ac_fn_c_try_compile "$LINENO"; then :
601982
+  pkgpythondir=\${pythondir}/$PACKAGE
601982
 
601982
-		     smart_include=" "
601982
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
601982
-$as_echo "yes" >&6; }
601982
-		     break
601982
 
601982
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $am_display_PYTHON extension module directory" >&5
601982
+$as_echo_n "checking for $am_display_PYTHON extension module directory... " >&6; }
601982
+if ${am_cv_python_pyexecdir+:} false; then :
601982
+  $as_echo_n "(cached) " >&6
601982
 else
601982
-
601982
-		     smart_include=
601982
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
601982
-$as_echo "no" >&6; }
601982
+  if test "x$exec_prefix" = xNONE
601982
+     then
601982
+       am_py_exec_prefix=$am_py_prefix
601982
+     else
601982
+       am_py_exec_prefix=$exec_prefix
601982
+     fi
601982
+     am_cv_python_pyexecdir=`$PYTHON -c "
601982
+$am_python_setup_sysconfig
601982
+if can_use_sysconfig:
601982
+    sitedir = sysconfig.get_path('platlib', vars={'platbase':'$am_py_prefix'})
601982
+else:
601982
+    from distutils import sysconfig
601982
+    sitedir = sysconfig.get_python_lib(1, 0, prefix='$am_py_prefix')
601982
+sys.stdout.write(sitedir)"`
601982
+     case $am_cv_python_pyexecdir in
601982
+     $am_py_exec_prefix*)
601982
+       am__strip_prefix=`echo "$am_py_exec_prefix" | sed 's|.|.|g'`
601982
+       am_cv_python_pyexecdir=`echo "$am_cv_python_pyexecdir" | sed "s,^$am__strip_prefix,$PYTHON_EXEC_PREFIX,"`
601982
+       ;;
601982
+     *)
601982
+       case $am_py_exec_prefix in
601982
+         /usr|/System*) ;;
601982
+         *)
601982
+	   am_cv_python_pyexecdir=$PYTHON_EXEC_PREFIX/lib/python$PYTHON_VERSION/site-packages
601982
+	   ;;
601982
+       esac
601982
+       ;;
601982
+     esac
601982
 
601982
 fi
601982
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
601982
-fi
601982
-
601982
-if test "x$smart_include" = "x"; then
601982
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_python_pyexecdir" >&5
601982
+$as_echo "$am_cv_python_pyexecdir" >&6; }
601982
+  pyexecdir=$am_cv_python_pyexecdir
601982
 
601982
-  for prefix in $smart_prefix; do
601982
 
601982
 
601982
-if test "x$LOCATE" != "x"; then
601982
-        DIRS=
601982
-  file="${_prefix}/${1}"
601982
+  pkgpyexecdir=\${pyexecdir}/$PACKAGE
601982
 
601982
-  for x in `${LOCATE} $file 2>/dev/null`; do
601982
-                                        base=`echo $x | sed "s%/${file}%%"`
601982
-    if test "x$x" = "x$base"; then
601982
-      continue;
601982
-    fi
601982
-
601982
-    dir=`${DIRNAME} $x 2>/dev/null`
601982
-                exclude=`echo ${dir} | ${GREP} /home`
601982
-    if test "x$exclude" != "x"; then
601982
-      continue
601982
-    fi
601982
-
601982
-                    already=`echo \$_smart_include_dir ${DIRS} | ${GREP} ${dir}`
601982
-    if test "x$already" = "x"; then
601982
-      DIRS="$DIRS $dir"
601982
-    fi
601982
-  done
601982
-fi
601982
 
601982
-eval "_smart_include_dir=\"\$_smart_include_dir $DIRS\""
601982
 
601982
-  done
601982
+  fi
601982
 
601982
 
601982
-if test "x$LOCATE" != "x"; then
601982
-        DIRS=
601982
-  file=Python.h
601982
 
601982
-  for x in `${LOCATE} $file 2>/dev/null`; do
601982
-                                        base=`echo $x | sed "s%/${file}%%"`
601982
-    if test "x$x" = "x$base"; then
601982
-      continue;
601982
-    fi
601982
+		PYTHON3_CONFIG_BIN=
601982
 
601982
-    dir=`${DIRNAME} $x 2>/dev/null`
601982
-                exclude=`echo ${dir} | ${GREP} /home`
601982
-    if test "x$exclude" != "x"; then
601982
-      continue
601982
-    fi
601982
+# Check whether --with-rlm-python3-config-bin was given.
601982
+if test "${with_rlm_python3_config_bin+set}" = set; then :
601982
+  withval=$with_rlm_python3_config_bin;  case "$withval" in
601982
+	    no)
601982
+		as_fn_error $? "Need rlm-python3-config-bin" "$LINENO" 5
601982
+		;;
601982
+	    yes)
601982
+		;;
601982
+	    *)
601982
+		PYTHON3_CONFIG_BIN="$withval"
601982
+		;;
601982
+	  esac
601982
 
601982
-                    already=`echo \$_smart_include_dir ${DIRS} | ${GREP} ${dir}`
601982
-    if test "x$already" = "x"; then
601982
-      DIRS="$DIRS $dir"
601982
-    fi
601982
-  done
601982
 fi
601982
 
601982
-eval "_smart_include_dir=\"\$_smart_include_dir $DIRS\""
601982
-
601982
-
601982
-  for try in $_smart_include_dir; do
601982
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python.h in $try" >&5
601982
-$as_echo_n "checking for Python.h in $try... " >&6; }
601982
-    CPPFLAGS="-isystem $try $old_CPPFLAGS"
601982
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
601982
-/* end confdefs.h.  */
601982
-
601982
-		    #include <Python.h>
601982
-int
601982
-main ()
601982
-{
601982
-int a = 1;
601982
-  ;
601982
-  return 0;
601982
-}
601982
-_ACEOF
601982
-if ac_fn_c_try_compile "$LINENO"; then :
601982
-
601982
-		     smart_include="-isystem $try"
601982
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
601982
-$as_echo "yes" >&6; }
601982
-		     break
601982
 
601982
+	if test "x$PYTHON3_CONFIG_BIN" = x; then
601982
+		for ac_prog in  python3-config
601982
+do
601982
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
601982
+set dummy $ac_prog; ac_word=$2
601982
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
601982
+$as_echo_n "checking for $ac_word... " >&6; }
601982
+if ${ac_cv_prog_PYTHON3_CONFIG_BIN+:} false; then :
601982
+  $as_echo_n "(cached) " >&6
601982
 else
601982
-
601982
-		     smart_include=
601982
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
601982
-$as_echo "no" >&6; }
601982
-
601982
-fi
601982
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
601982
+  if test -n "$PYTHON3_CONFIG_BIN"; then
601982
+  ac_cv_prog_PYTHON3_CONFIG_BIN="$PYTHON3_CONFIG_BIN" # Let the user override the test.
601982
+else
601982
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
601982
+as_dummy="${PATH}:/usr/bin:/usr/local/bin"
601982
+for as_dir in $as_dummy
601982
+do
601982
+  IFS=$as_save_IFS
601982
+  test -z "$as_dir" && as_dir=.
601982
+    for ac_exec_ext in '' $ac_executable_extensions; do
601982
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
601982
+    ac_cv_prog_PYTHON3_CONFIG_BIN="$ac_prog"
601982
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
601982
+    break 2
601982
+  fi
601982
+done
601982
   done
601982
-  CPPFLAGS="$old_CPPFLAGS"
601982
-fi
601982
-
601982
-if test "x$smart_include" != "x"; then
601982
-  eval "ac_cv_header_$ac_safe=yes"
601982
-  CPPFLAGS="$smart_include $old_CPPFLAGS"
601982
-  SMART_CPPFLAGS="$smart_include $SMART_CPPFLAGS"
601982
-fi
601982
-
601982
-smart_prefix=
601982
-
601982
-		CFLAGS=$old_CFLAGS
601982
-
601982
-		if test "x$ac_cv_header_Python_h" = "xyes"; then
601982
-			mod_cflags="$SMART_CPPFLAGS"
601982
-		else
601982
-			fail="$fail Python.h"
601982
-			targetname=
601982
-		fi
601982
-
601982
-		old_LIBS=$LIBS
601982
-		LIBS="$LIBS $PY_LIB_LOC $PY_EXTRA_LIBS -lm"
601982
-		smart_try_dir=$PY_LIB_DIR
601982
-
601982
-
601982
-sm_lib_safe=`echo "python${PY_SYS_VERSION}" | sed 'y%./+-%__p_%'`
601982
-sm_func_safe=`echo "Py_Initialize" | sed 'y%./+-%__p_%'`
601982
-
601982
-old_LIBS="$LIBS"
601982
-old_CPPFLAGS="$CPPFLAGS"
601982
-smart_lib=
601982
-smart_ldflags=
601982
-smart_lib_dir=
601982
-
601982
-if test "x$smart_try_dir" != "x"; then
601982
-  for try in $smart_try_dir; do
601982
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Py_Initialize in -lpython${PY_SYS_VERSION} in $try" >&5
601982
-$as_echo_n "checking for Py_Initialize in -lpython${PY_SYS_VERSION} in $try... " >&6; }
601982
-    LIBS="-lpython${PY_SYS_VERSION} $old_LIBS"
601982
-    CPPFLAGS="-L$try -Wl,-rpath,$try $old_CPPFLAGS"
601982
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
601982
-/* end confdefs.h.  */
601982
-extern char Py_Initialize();
601982
-int
601982
-main ()
601982
-{
601982
-Py_Initialize()
601982
-  ;
601982
-  return 0;
601982
-}
601982
-_ACEOF
601982
-if ac_fn_c_try_link "$LINENO"; then :
601982
-
601982
-		 smart_lib="-lpython${PY_SYS_VERSION}"
601982
-		 smart_ldflags="-L$try -Wl,-rpath,$try"
601982
-		 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
601982
-$as_echo "yes" >&6; }
601982
-		 break
601982
+IFS=$as_save_IFS
601982
 
601982
-else
601982
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
601982
-$as_echo "no" >&6; }
601982
 fi
601982
-rm -f core conftest.err conftest.$ac_objext \
601982
-    conftest$ac_exeext conftest.$ac_ext
601982
-  done
601982
-  LIBS="$old_LIBS"
601982
-  CPPFLAGS="$old_CPPFLAGS"
601982
 fi
601982
-
601982
-if test "x$smart_lib" = "x"; then
601982
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Py_Initialize in -lpython${PY_SYS_VERSION}" >&5
601982
-$as_echo_n "checking for Py_Initialize in -lpython${PY_SYS_VERSION}... " >&6; }
601982
-  LIBS="-lpython${PY_SYS_VERSION} $old_LIBS"
601982
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
601982
-/* end confdefs.h.  */
601982
-extern char Py_Initialize();
601982
-int
601982
-main ()
601982
-{
601982
-Py_Initialize()
601982
-  ;
601982
-  return 0;
601982
-}
601982
-_ACEOF
601982
-if ac_fn_c_try_link "$LINENO"; then :
601982
-
601982
-	        smart_lib="-lpython${PY_SYS_VERSION}"
601982
-	        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
601982
-$as_echo "yes" >&6; }
601982
-
601982
+PYTHON3_CONFIG_BIN=$ac_cv_prog_PYTHON3_CONFIG_BIN
601982
+if test -n "$PYTHON3_CONFIG_BIN"; then
601982
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON3_CONFIG_BIN" >&5
601982
+$as_echo "$PYTHON3_CONFIG_BIN" >&6; }
601982
 else
601982
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
601982
 $as_echo "no" >&6; }
601982
 fi
601982
-rm -f core conftest.err conftest.$ac_objext \
601982
-    conftest$ac_exeext conftest.$ac_ext
601982
-  LIBS="$old_LIBS"
601982
-fi
601982
 
601982
-if test "x$smart_lib" = "x"; then
601982
 
601982
+  test -n "$PYTHON3_CONFIG_BIN" && break
601982
+done
601982
+test -n "$PYTHON3_CONFIG_BIN" || PYTHON3_CONFIG_BIN="not-found"
601982
 
601982
-if test "x$LOCATE" != "x"; then
601982
-        DIRS=
601982
-  file=libpython${PY_SYS_VERSION}${libltdl_cv_shlibext}
601982
-
601982
-  for x in `${LOCATE} $file 2>/dev/null`; do
601982
-                                        base=`echo $x | sed "s%/${file}%%"`
601982
-    if test "x$x" = "x$base"; then
601982
-      continue;
601982
-    fi
601982
-
601982
-    dir=`${DIRNAME} $x 2>/dev/null`
601982
-                exclude=`echo ${dir} | ${GREP} /home`
601982
-    if test "x$exclude" != "x"; then
601982
-      continue
601982
-    fi
601982
-
601982
-                    already=`echo \$smart_lib_dir ${DIRS} | ${GREP} ${dir}`
601982
-    if test "x$already" = "x"; then
601982
-      DIRS="$DIRS $dir"
601982
-    fi
601982
-  done
601982
-fi
601982
-
601982
-eval "smart_lib_dir=\"\$smart_lib_dir $DIRS\""
601982
-
601982
-
601982
-
601982
-if test "x$LOCATE" != "x"; then
601982
-        DIRS=
601982
-  file=libpython${PY_SYS_VERSION}.a
601982
-
601982
-  for x in `${LOCATE} $file 2>/dev/null`; do
601982
-                                        base=`echo $x | sed "s%/${file}%%"`
601982
-    if test "x$x" = "x$base"; then
601982
-      continue;
601982
-    fi
601982
-
601982
-    dir=`${DIRNAME} $x 2>/dev/null`
601982
-                exclude=`echo ${dir} | ${GREP} /home`
601982
-    if test "x$exclude" != "x"; then
601982
-      continue
601982
-    fi
601982
-
601982
-                    already=`echo \$smart_lib_dir ${DIRS} | ${GREP} ${dir}`
601982
-    if test "x$already" = "x"; then
601982
-      DIRS="$DIRS $dir"
601982
-    fi
601982
-  done
601982
-fi
601982
-
601982
-eval "smart_lib_dir=\"\$smart_lib_dir $DIRS\""
601982
-
601982
-
601982
-  for try in $smart_lib_dir /usr/local/lib /opt/lib; do
601982
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Py_Initialize in -lpython${PY_SYS_VERSION} in $try" >&5
601982
-$as_echo_n "checking for Py_Initialize in -lpython${PY_SYS_VERSION} in $try... " >&6; }
601982
-    LIBS="-lpython${PY_SYS_VERSION} $old_LIBS"
601982
-    CPPFLAGS="-L$try -Wl,-rpath,$try $old_CPPFLAGS"
601982
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
601982
-/* end confdefs.h.  */
601982
-extern char Py_Initialize();
601982
-int
601982
-main ()
601982
-{
601982
-Py_Initialize()
601982
-  ;
601982
-  return 0;
601982
-}
601982
-_ACEOF
601982
-if ac_fn_c_try_link "$LINENO"; then :
601982
-
601982
-		  smart_lib="-lpython${PY_SYS_VERSION}"
601982
-		  smart_ldflags="-L$try -Wl,-rpath,$try"
601982
-		  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
601982
-$as_echo "yes" >&6; }
601982
-		  break
601982
+	fi
601982
 
601982
+	if test "x$PYTHON3_CONFIG_BIN" = xnot-found; then
601982
+		fail="$fail python3-config"
601982
+	else
601982
+								old_CFLAGS="$CFLAGS"
601982
+		unset CFLAGS
601982
+
601982
+		python3_cflags=`${PYTHON3_CONFIG_BIN} --cflags`
601982
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: ${PYTHON3_CONFIG_BIN}'s cflags were \"${python3_cflags}\"" >&5
601982
+$as_echo "$as_me: ${PYTHON3_CONFIG_BIN}'s cflags were \"${python3_cflags}\"" >&6;}
601982
+
601982
+																mod_cflags=`echo $python3_cflags | sed -e '\
601982
+			s/-I/-isystem/g;\
601982
+			s/-isysroot[ =]\{0,1\}[^-]*//g;\
601982
+			s/-O[^[[:blank:]]]*//g;\
601982
+			s/-Wp,-D_FORTIFY_SOURCE=[[:digit:]]//g;\
601982
+			s/-g[^ ]*//g;\
601982
+			s/-W[^ ]*//g;\
601982
+			s/-DNDEBUG[[:blank:]]*//g;
601982
+			'`
601982
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: Sanitized cflags were \"${mod_cflags}\"" >&5
601982
+$as_echo "$as_me: Sanitized cflags were \"${mod_cflags}\"" >&6;}
601982
+
601982
+						for ac_prog in gawk mawk nawk awk
601982
+do
601982
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
601982
+set dummy $ac_prog; ac_word=$2
601982
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
601982
+$as_echo_n "checking for $ac_word... " >&6; }
601982
+if ${ac_cv_prog_AWK+:} false; then :
601982
+  $as_echo_n "(cached) " >&6
601982
 else
601982
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
601982
-$as_echo "no" >&6; }
601982
-fi
601982
-rm -f core conftest.err conftest.$ac_objext \
601982
-    conftest$ac_exeext conftest.$ac_ext
601982
+  if test -n "$AWK"; then
601982
+  ac_cv_prog_AWK="$AWK" # Let the user override the test.
601982
+else
601982
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
601982
+for as_dir in $PATH
601982
+do
601982
+  IFS=$as_save_IFS
601982
+  test -z "$as_dir" && as_dir=.
601982
+    for ac_exec_ext in '' $ac_executable_extensions; do
601982
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
601982
+    ac_cv_prog_AWK="$ac_prog"
601982
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
601982
+    break 2
601982
+  fi
601982
+done
601982
   done
601982
-  LIBS="$old_LIBS"
601982
-  CPPFLAGS="$old_CPPFLAGS"
601982
-fi
601982
-
601982
-if test "x$smart_lib" != "x"; then
601982
-  eval "ac_cv_lib_${sm_lib_safe}_${sm_func_safe}=yes"
601982
-  LIBS="$smart_ldflags $smart_lib $old_LIBS"
601982
-  SMART_LIBS="$smart_ldflags $smart_lib $SMART_LIBS"
601982
-fi
601982
-
601982
-		LIBS=$old_LIBS
601982
-
601982
-		eval t=\${ac_cv_lib_${sm_lib_safe}_${sm_func_safe}}
601982
-		if test "x$t" = "xyes"; then
601982
-			mod_ldflags="$PY_LIB_LOC $PY_EXTRA_LIBS $SMART_LIBS -lm"
601982
-			targetname=rlm_python3
601982
-		else
601982
-
601982
-
601982
-sm_lib_safe=`echo "python${PY_SYS_VERSION}m" | sed 'y%./+-%__p_%'`
601982
-sm_func_safe=`echo "Py_Initialize" | sed 'y%./+-%__p_%'`
601982
-
601982
-old_LIBS="$LIBS"
601982
-old_CPPFLAGS="$CPPFLAGS"
601982
-smart_lib=
601982
-smart_ldflags=
601982
-smart_lib_dir=
601982
-
601982
-if test "x$smart_try_dir" != "x"; then
601982
-  for try in $smart_try_dir; do
601982
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Py_Initialize in -lpython${PY_SYS_VERSION}m in $try" >&5
601982
-$as_echo_n "checking for Py_Initialize in -lpython${PY_SYS_VERSION}m in $try... " >&6; }
601982
-    LIBS="-lpython${PY_SYS_VERSION}m $old_LIBS"
601982
-    CPPFLAGS="-L$try -Wl,-rpath,$try $old_CPPFLAGS"
601982
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
601982
-/* end confdefs.h.  */
601982
-extern char Py_Initialize();
601982
-int
601982
-main ()
601982
-{
601982
-Py_Initialize()
601982
-  ;
601982
-  return 0;
601982
-}
601982
-_ACEOF
601982
-if ac_fn_c_try_link "$LINENO"; then :
601982
-
601982
-		 smart_lib="-lpython${PY_SYS_VERSION}m"
601982
-		 smart_ldflags="-L$try -Wl,-rpath,$try"
601982
-		 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
601982
-$as_echo "yes" >&6; }
601982
-		 break
601982
+IFS=$as_save_IFS
601982
 
601982
-else
601982
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
601982
-$as_echo "no" >&6; }
601982
 fi
601982
-rm -f core conftest.err conftest.$ac_objext \
601982
-    conftest$ac_exeext conftest.$ac_ext
601982
-  done
601982
-  LIBS="$old_LIBS"
601982
-  CPPFLAGS="$old_CPPFLAGS"
601982
 fi
601982
-
601982
-if test "x$smart_lib" = "x"; then
601982
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Py_Initialize in -lpython${PY_SYS_VERSION}m" >&5
601982
-$as_echo_n "checking for Py_Initialize in -lpython${PY_SYS_VERSION}m... " >&6; }
601982
-  LIBS="-lpython${PY_SYS_VERSION}m $old_LIBS"
601982
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
601982
-/* end confdefs.h.  */
601982
-extern char Py_Initialize();
601982
-int
601982
-main ()
601982
-{
601982
-Py_Initialize()
601982
-  ;
601982
-  return 0;
601982
-}
601982
-_ACEOF
601982
-if ac_fn_c_try_link "$LINENO"; then :
601982
-
601982
-	        smart_lib="-lpython${PY_SYS_VERSION}m"
601982
-	        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
601982
-$as_echo "yes" >&6; }
601982
-
601982
+AWK=$ac_cv_prog_AWK
601982
+if test -n "$AWK"; then
601982
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5
601982
+$as_echo "$AWK" >&6; }
601982
 else
601982
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
601982
 $as_echo "no" >&6; }
601982
 fi
601982
-rm -f core conftest.err conftest.$ac_objext \
601982
-    conftest$ac_exeext conftest.$ac_ext
601982
-  LIBS="$old_LIBS"
601982
-fi
601982
 
601982
-if test "x$smart_lib" = "x"; then
601982
 
601982
+  test -n "$AWK" && break
601982
+done
601982
 
601982
-if test "x$LOCATE" != "x"; then
601982
-        DIRS=
601982
-  file=libpython${PY_SYS_VERSION}m${libltdl_cv_shlibext}
601982
 
601982
-  for x in `${LOCATE} $file 2>/dev/null`; do
601982
-                                        base=`echo $x | sed "s%/${file}%%"`
601982
-    if test "x$x" = "x$base"; then
601982
-      continue;
601982
-    fi
601982
 
601982
-    dir=`${DIRNAME} $x 2>/dev/null`
601982
-                exclude=`echo ${dir} | ${GREP} /home`
601982
-    if test "x$exclude" != "x"; then
601982
-      continue
601982
-    fi
601982
 
601982
-                    already=`echo \$smart_lib_dir ${DIRS} | ${GREP} ${dir}`
601982
-    if test "x$already" = "x"; then
601982
-      DIRS="$DIRS $dir"
601982
-    fi
601982
-  done
601982
-fi
601982
+  # Used to indicate true or false condition
601982
+  ax_compare_version=false
601982
 
601982
-eval "smart_lib_dir=\"\$smart_lib_dir $DIRS\""
601982
+  # Convert the two version strings to be compared into a format that
601982
+  # allows a simple string comparison.  The end result is that a version
601982
+  # string of the form 1.12.5-r617 will be converted to the form
601982
+  # 0001001200050617.  In other words, each number is zero padded to four
601982
+  # digits, and non digits are removed.
601982
 
601982
+  ax_compare_version_A=`echo "${PYTHON_VERSION}" | sed -e 's/\([0-9]*\)/Z\1Z/g' \
601982
+                     -e 's/Z\([0-9]\)Z/Z0\1Z/g' \
601982
+                     -e 's/Z\([0-9][0-9]\)Z/Z0\1Z/g' \
601982
+                     -e 's/Z\([0-9][0-9][0-9]\)Z/Z0\1Z/g' \
601982
+                     -e 's/[^0-9]//g'`
601982
 
601982
 
601982
-if test "x$LOCATE" != "x"; then
601982
-        DIRS=
601982
-  file=libpython${PY_SYS_VERSION}m.a
601982
+  ax_compare_version_B=`echo "3.8" | sed -e 's/\([0-9]*\)/Z\1Z/g' \
601982
+                     -e 's/Z\([0-9]\)Z/Z0\1Z/g' \
601982
+                     -e 's/Z\([0-9][0-9]\)Z/Z0\1Z/g' \
601982
+                     -e 's/Z\([0-9][0-9][0-9]\)Z/Z0\1Z/g' \
601982
+                     -e 's/[^0-9]//g'`
601982
 
601982
-  for x in `${LOCATE} $file 2>/dev/null`; do
601982
-                                        base=`echo $x | sed "s%/${file}%%"`
601982
-    if test "x$x" = "x$base"; then
601982
-      continue;
601982
-    fi
601982
 
601982
-    dir=`${DIRNAME} $x 2>/dev/null`
601982
-                exclude=`echo ${dir} | ${GREP} /home`
601982
-    if test "x$exclude" != "x"; then
601982
-      continue
601982
-    fi
601982
+    ax_compare_version=`echo "x$ax_compare_version_A
601982
+x$ax_compare_version_B" | sed 's/^ *//' | sort -r | sed "s/x${ax_compare_version_A}/true/;s/x${ax_compare_version_B}/false/;1q"`
601982
 
601982
-                    already=`echo \$smart_lib_dir ${DIRS} | ${GREP} ${dir}`
601982
-    if test "x$already" = "x"; then
601982
-      DIRS="$DIRS $dir"
601982
-    fi
601982
-  done
601982
-fi
601982
 
601982
-eval "smart_lib_dir=\"\$smart_lib_dir $DIRS\""
601982
 
601982
+    if test "$ax_compare_version" = "true" ; then
601982
+    EMBED="--embed"
601982
+      fi
601982
 
601982
-  for try in $smart_lib_dir /usr/local/lib /opt/lib; do
601982
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Py_Initialize in -lpython${PY_SYS_VERSION}m in $try" >&5
601982
-$as_echo_n "checking for Py_Initialize in -lpython${PY_SYS_VERSION}m in $try... " >&6; }
601982
-    LIBS="-lpython${PY_SYS_VERSION}m $old_LIBS"
601982
-    CPPFLAGS="-L$try -Wl,-rpath,$try $old_CPPFLAGS"
601982
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
601982
-/* end confdefs.h.  */
601982
-extern char Py_Initialize();
601982
-int
601982
-main ()
601982
-{
601982
-Py_Initialize()
601982
-  ;
601982
-  return 0;
601982
-}
601982
-_ACEOF
601982
-if ac_fn_c_try_link "$LINENO"; then :
601982
 
601982
-		  smart_lib="-lpython${PY_SYS_VERSION}m"
601982
-		  smart_ldflags="-L$try -Wl,-rpath,$try"
601982
-		  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
601982
-$as_echo "yes" >&6; }
601982
-		  break
601982
+		python3_ldflags=`${PYTHON3_CONFIG_BIN} --ldflags $EMBED`
601982
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: ${PYTHON3_CONFIG_BIN}'s ldflags were \"$python3_ldflags}\"" >&5
601982
+$as_echo "$as_me: ${PYTHON3_CONFIG_BIN}'s ldflags were \"$python3_ldflags}\"" >&6;}
601982
 
601982
-else
601982
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
601982
-$as_echo "no" >&6; }
601982
-fi
601982
-rm -f core conftest.err conftest.$ac_objext \
601982
-    conftest$ac_exeext conftest.$ac_ext
601982
-  done
601982
-  LIBS="$old_LIBS"
601982
-  CPPFLAGS="$old_CPPFLAGS"
601982
-fi
601982
+										mod_ldflags=`echo $python3_ldflags | sed -e '\
601982
+			s/-Wl,-O[[:digit:]][[:blank:]]*//g;\
601982
+			s/-Wl,-Bsymbolic-functions[[:blank:]]*//g;\
601982
+			s/-Xlinker -export-dynamic//g;\
601982
+			s/-Wl,-stack_size,[[:digit:]]*[[:blank:]]//g;
601982
+			'`
601982
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: Sanitized ldflags were \"${mod_ldflags}\"" >&5
601982
+$as_echo "$as_me: Sanitized ldflags were \"${mod_ldflags}\"" >&6;}
601982
 
601982
-if test "x$smart_lib" != "x"; then
601982
-  eval "ac_cv_lib_${sm_lib_safe}_${sm_func_safe}=yes"
601982
-  LIBS="$smart_ldflags $smart_lib $old_LIBS"
601982
-  SMART_LIBS="$smart_ldflags $smart_lib $SMART_LIBS"
601982
-fi
601982
+		CFLAGS=$old_CFLAGS
601982
 
601982
-			eval t=\${ac_cv_lib_${sm_lib_safe}_${sm_func_safe}}
601982
-			if test "x$t" = "xyes"; then
601982
-				mod_ldflags="$PY_LIB_LOC $PY_EXTRA_LIBS $SMART_LIBS -lm"
601982
-				targetname=rlm_python3
601982
-			else
601982
-				targetname=
601982
-				fail="$fail libpython$PY_SYS_VERSION"
601982
-			fi
601982
-		fi
601982
+		targetname="rlm_python3"
601982
 	fi
601982
 
601982
-	for ac_func in dl_iterate_phdr
601982
+for ac_func in dl_iterate_phdr
601982
 do :
601982
   ac_fn_c_check_func "$LINENO" "dl_iterate_phdr" "ac_cv_func_dl_iterate_phdr"
601982
 if test "x$ac_cv_func_dl_iterate_phdr" = xyes; then :
601982
@@ -3603,11 +3307,7 @@ ac_config_headers="$ac_config_headers config.h"
601982
 
601982
 
601982
 
601982
-
601982
-  unset ac_cv_env_LIBS_set
601982
-  unset ac_cv_env_LIBS_value
601982
-
601982
-  ac_config_files="$ac_config_files all.mk"
601982
+ac_config_files="$ac_config_files all.mk"
601982
 
601982
 cat >confcache <<\_ACEOF
601982
 # This file is a shell script that caches the results of configure
601982
@@ -4187,6 +3887,7 @@ gives unlimited permission to copy, distribute and modify it."
601982
 
601982
 ac_pwd='$ac_pwd'
601982
 srcdir='$srcdir'
601982
+AWK='$AWK'
601982
 test -n "\$AWK" || AWK=awk
601982
 _ACEOF
601982
 
601982
@@ -4881,4 +4582,3 @@ if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
601982
 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
601982
 fi
601982
 
601982
-
601982
diff --git a/src/modules/rlm_python3/configure.ac b/src/modules/rlm_python3/configure.ac
601982
index a00320fda4..698a8c1d18 100644
601982
--- a/src/modules/rlm_python3/configure.ac
601982
+++ b/src/modules/rlm_python3/configure.ac
601982
@@ -7,128 +7,81 @@ if test x$with_[]modname != xno; then
601982
 
601982
 	AC_PROG_CC
601982
 	AC_PROG_CPP
601982
+	AM_PATH_PYTHON([3.0],, [:])
601982
 
601982
-	dnl extra argument: --with-rlm-python3-bin
601982
-	PYTHON3_BIN=
601982
-	AC_ARG_WITH(rlm-python3-bin,
601982
-	[  --with-rlm-python3-bin=PATH   Path to python3 binary []],
601982
+	dnl extra argument: --with-rlm-python3-config-bin
601982
+	PYTHON3_CONFIG_BIN=
601982
+	AC_ARG_WITH(rlm-python3-config-bin,
601982
+	[  --with-rlm-python3-config-bin=PATH   Path to python-config3 binary []],
601982
 	[ case "$withval" in
601982
 	    no)
601982
-		AC_MSG_ERROR(Need rlm-python3-bin)
601982
+		AC_MSG_ERROR(Need rlm-python3-config-bin)
601982
 		;;
601982
 	    yes)
601982
 		;;
601982
 	    *)
601982
-		PYTHON3_BIN="$withval"
601982
+		PYTHON3_CONFIG_BIN="$withval"
601982
 		;;
601982
 	  esac ]
601982
 	)
601982
 
601982
-	if test "x$PYTHON3_BIN" = x; then
601982
-		AC_CHECK_PROGS(PYTHON3_BIN, [ python3 ], not-found, [${PATH}:/usr/bin:/usr/local/bin])
601982
+	if test "x$PYTHON3_CONFIG_BIN" = x; then
601982
+		AC_CHECK_PROGS(PYTHON3_CONFIG_BIN, [ python3-config ], not-found, [${PATH}:/usr/bin:/usr/local/bin])
601982
 	fi
601982
 
601982
-	if test "x$PYTHON3_BIN" = "xnot-found"; then
601982
-		fail="python-binary"
601982
-	fi
601982
-
601982
-	dnl extra argument: --with-rlm-python3-lib-dir
601982
-	PY_LIB_DIR=
601982
-	AC_ARG_WITH(rlm-python3-lib-dir,
601982
-	[  --with-rlm-python3-lib-dir=DIR       Directory for Python library files []],
601982
-	[ case "$withval" in
601982
-	    no)
601982
-		AC_MSG_ERROR(Need rlm-python3-lib-dir)
601982
-		;;
601982
-	    yes)
601982
-		;;
601982
-	    *)
601982
-		PY_LIB_DIR="$withval"
601982
-		;;
601982
-	  esac ]
601982
-	)
601982
-
601982
-	dnl extra argument: --with-rlm-python3-include-dir
601982
-	PY_INC_DIR=
601982
-	AC_ARG_WITH(rlm-python3-include-dir,
601982
-	[  --with-rlm-python3-include-dir=DIR   Directory for Python include files []],
601982
-	[ case "$withval" in
601982
-	    no)
601982
-		AC_MSG_ERROR(Need rlm-python3-include-dir)
601982
-		;;
601982
-	    yes)
601982
-		;;
601982
-	    *)
601982
-		PY_INC_DIR="$withval"
601982
-		;;
601982
-	  esac ]
601982
-	)
601982
-
601982
-	if test x$fail = x; then
601982
-		PY_PREFIX=`${PYTHON3_BIN} -c 'import sys ; print(sys.prefix)'`
601982
-		AC_MSG_NOTICE([Python sys.prefix \"${PY_PREFIX}\"])
601982
-
601982
-		PY_EXEC_PREFIX=`${PYTHON3_BIN} -c 'import sys ; print(sys.exec_prefix)'`
601982
-		AC_MSG_NOTICE([Python sys.exec_prefix \"${PY_EXEC_PREFIX}\"])
601982
-
601982
-		PY_SYS_VERSION=`${PYTHON3_BIN} -c 'import sys ; print(sys.version[[0:3]])'`
601982
-		AC_MSG_NOTICE([Python sys.version \"${PY_SYS_VERSION}\"])
601982
-
601982
-		if test "x$PY_LIB_DIR" = "x"; then
601982
-			PY_LIB_DIR="$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config"
601982
-			PY_LIB_LOC="-L$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config"
601982
-		fi
601982
-
601982
-		PY_MAKEFILE="$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config/Makefile"
601982
-		if test -f ${PY_MAKEFILE}; then
601982
-			PY_LOCAL_MOD_LIBS=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[[:blank:]]]/ /g;s/^ *//;s/ *$//'`
601982
-			AC_MSG_NOTICE([Python local_mod_libs \"${PY_LOCAL_MOD_LIBS}\"])
601982
-
601982
-			PY_BASE_MOD_LIBS=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[[:blank:]]]/ /g;s/^ *//;s/ *$//'`
601982
-			AC_MSG_NOTICE([Python base_mod_libs \"${PY_BASE_MOD_LIBS}\"])
601982
-
601982
-			PY_OTHER_LIBS=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[[:blank:]]]/ /g;s/  / /g;s/^ *//;s/ *$//'`
601982
-			PY_OTHER_LDFLAGS=`sed -n -e 's/^LINKFORSHARED=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[[:blank:]]]/ /g;s/  / /g;s/^ *//;s/ *$//'`
601982
-			AC_MSG_NOTICE([Python other_libs \"${PY_OTHER_LDFLAGS} ${PY_OTHER_LIBS}\"])
601982
-		fi
601982
-		PY_EXTRA_LIBS="$PY_LOCALMODLIBS $PY_BASE_MOD_LIBS $PY_OTHER_LIBS"
601982
+	if test "x$PYTHON3_CONFIG_BIN" = xnot-found; then
601982
+		fail="$fail python3-config"
601982
+	else
601982
+		dnl #
601982
+		dnl # It is necessary due to a weird behavior with 'python3-config'
601982
+		dnl #
601982
+		old_CFLAGS="$CFLAGS"
601982
+		unset CFLAGS
601982
+
601982
+		python3_cflags=`${PYTHON3_CONFIG_BIN} --cflags`
601982
+		AC_MSG_NOTICE([${PYTHON3_CONFIG_BIN}'s cflags were \"${python3_cflags}\"])
601982
+
601982
+		dnl # Convert -I to -isystem to get rid of warnings about issues in Python headers
601982
+		dnl # Strip -systemroot
601982
+		dnl # Strip optimisation flags (-O[0-9]?). We decide our optimisation level, not python.
601982
+		dnl # -D_FORTIFY_SOURCE needs -O.
601982
+		dnl # Strip debug symbol flags (-g[0-9]?). We decide on debugging symbols, not python
601982
+		dnl # Strip -W*, we decide what warnings are important
601982
+		dnl # Strip -DNDEBUG
601982
+		mod_cflags=`echo $python3_cflags | sed -e '\
601982
+			s/-I/-isystem/g;\
601982
+			s/-isysroot[[ =]]\{0,1\}[[^-]]*//g;\
601982
+			s/-O[[^[[:blank:]]]]*//g;\
601982
+			s/-Wp,-D_FORTIFY_SOURCE=[[[:digit:]]]//g;\
601982
+			s/-g[[^ ]]*//g;\
601982
+			s/-W[[^ ]]*//g;\
601982
+			s/-DNDEBUG[[[:blank:]]]*//g;
601982
+			'`
601982
+		AC_MSG_NOTICE([Sanitized cflags were \"${mod_cflags}\"])
601982
+
601982
+		dnl # From python 3.8, --embed is required
601982
+		dnl # https://bugs.python.org/issue36721
601982
+		AX_COMPARE_VERSION(${PYTHON_VERSION}, [ge], [3.8], [EMBED="--embed"], [])
601982
+
601982
+		python3_ldflags=`${PYTHON3_CONFIG_BIN} --ldflags $EMBED`
601982
+		AC_MSG_NOTICE([${PYTHON3_CONFIG_BIN}'s ldflags were \"$python3_ldflags}\"])
601982
+
601982
+		dnl # Strip -Wl,-O1... Is -O even a valid linker flag??
601982
+		dnl # Strip -Wl,-Bsymbolic-functions as thats not always supported or required
601982
+		dnl # Strip -Xlinker -export-dynamic as it causes weird linking issues on Linux
601982
+		dnl #   See: https://bugs.python.org/issue36508
601982
+		mod_ldflags=`echo $python3_ldflags | sed -e '\
601982
+			s/-Wl,-O[[[:digit:]]][[[:blank:]]]*//g;\
601982
+			s/-Wl,-Bsymbolic-functions[[[:blank:]]]*//g;\
601982
+			s/-Xlinker -export-dynamic//g;\
601982
+			s/-Wl,-stack_size,[[[:digit:]]]*[[[:blank:]]]//g;
601982
+			'`
601982
+		AC_MSG_NOTICE([Sanitized ldflags were \"${mod_ldflags}\"])
601982
 
601982
-		old_CFLAGS=$CFLAGS
601982
-		CFLAGS="$CFLAGS $PY_CFLAGS"
601982
-		smart_try_dir="$PY_PREFIX/include/python$PY_SYS_VERSION"
601982
-		FR_SMART_CHECK_INCLUDE(Python.h)
601982
 		CFLAGS=$old_CFLAGS
601982
 
601982
-		if test "x$ac_cv_header_Python_h" = "xyes"; then
601982
-			mod_cflags="$SMART_CPPFLAGS"
601982
-		else
601982
-			fail="$fail Python.h"
601982
-			targetname=
601982
-		fi
601982
-
601982
-		old_LIBS=$LIBS
601982
-		LIBS="$LIBS $PY_LIB_LOC $PY_EXTRA_LIBS -lm"
601982
-		smart_try_dir=$PY_LIB_DIR
601982
-		FR_SMART_CHECK_LIB(python${PY_SYS_VERSION}, Py_Initialize)
601982
-		LIBS=$old_LIBS
601982
-
601982
-		eval t=\${ac_cv_lib_${sm_lib_safe}_${sm_func_safe}}
601982
-		if test "x$t" = "xyes"; then
601982
-			mod_ldflags="$PY_LIB_LOC $PY_EXTRA_LIBS $SMART_LIBS -lm"
601982
-			targetname=modname
601982
-		else
601982
-			FR_SMART_CHECK_LIB(python${PY_SYS_VERSION}m, Py_Initialize)
601982
-			eval t=\${ac_cv_lib_${sm_lib_safe}_${sm_func_safe}}
601982
-			if test "x$t" = "xyes"; then
601982
-				mod_ldflags="$PY_LIB_LOC $PY_EXTRA_LIBS $SMART_LIBS -lm"
601982
-				targetname=modname
601982
-			else
601982
-				targetname=
601982
-				fail="$fail libpython$PY_SYS_VERSION"
601982
-			fi
601982
-		fi
601982
+		targetname="rlm_python3"
601982
 	fi
601982
-
601982
 	AC_CHECK_FUNCS([dl_iterate_phdr])
601982
 else
601982
 	targetname=
601982
diff --git a/src/modules/rlm_python3/radiusd_test.py b/src/modules/rlm_python3/radiusd_test.py
601982
deleted file mode 100644
601982
index 8582716ccb..0000000000
601982
--- a/src/modules/rlm_python3/radiusd_test.py
601982
+++ /dev/null
601982
@@ -1,63 +0,0 @@
601982
-#! /usr/bin/env python3
601982
-#
601982
-# Python module test
601982
-# Miguel A.L. Paraz <mparaz@mparaz.com>
601982
-#
601982
-# $Id: 8582716ccbf340be00ce081ecf5ab078e93d1183 $
601982
-
601982
-import radiusd
601982
-
601982
-def instantiate(p):
601982
-  print "*** instantiate ***"
601982
-  print p
601982
-
601982
-def authorize(p):
601982
-  print "*** authorize ***"
601982
-  print
601982
-  radiusd.radlog(radiusd.L_INFO, '*** radlog call in authorize ***')
601982
-  print
601982
-  print p 
601982
-  return radiusd.RLM_MODULE_OK
601982
-
601982
-def preacct(p):
601982
-  print "*** preacct ***"
601982
-  print p 
601982
-  return radiusd.RLM_MODULE_OK
601982
-
601982
-def accounting(p):
601982
-  print "*** accounting ***"
601982
-  radiusd.radlog(radiusd.L_INFO, '*** radlog call in accounting (0) ***')
601982
-  print
601982
-  print p 
601982
-  return radiusd.RLM_MODULE_OK
601982
-
601982
-def pre_proxy(p):
601982
-  print "*** pre_proxy ***"
601982
-  print p 
601982
-  return radiusd.RLM_MODULE_OK
601982
-
601982
-def post_proxy(p):
601982
-  print "*** post_proxy ***"
601982
-  print p 
601982
-  return radiusd.RLM_MODULE_OK
601982
-
601982
-def post_auth(p):
601982
-  print "*** post_auth ***"
601982
-  print p 
601982
-  return radiusd.RLM_MODULE_OK
601982
-
601982
-def recv_coa(p):
601982
-  print "*** recv_coa ***"
601982
-  print p 
601982
-  return radiusd.RLM_MODULE_OK
601982
-
601982
-def send_coa(p):
601982
-  print "*** send_coa ***"
601982
-  print p 
601982
-  return radiusd.RLM_MODULE_OK
601982
-
601982
-
601982
-def detach():
601982
-  print "*** goodbye from radiusd_test.py ***"
601982
-  return radiusd.RLM_MODULE_OK
601982
-
601982
diff --git a/src/modules/rlm_python3/rlm_python3.c b/src/modules/rlm_python3/rlm_python3.c
601982
index 06187e4ffa..5da23f4d71 100644
601982
--- a/src/modules/rlm_python3/rlm_python3.c
601982
+++ b/src/modules/rlm_python3/rlm_python3.c
601982
@@ -41,8 +41,17 @@ RCSID("$Id$")
601982
 #include <link.h>
601982
 #endif
601982
 
601982
+/*
601982
+ * Since version 3.8, the "m" suffix is no longer available.
601982
+ * https://bugs.python.org/issue36707
601982
+ */
601982
+#if PY_MINOR_VERSION >= 8
601982
 #define LIBPYTHON_LINKER_NAME \
601982
-	"libpython" STRINGIFY(PY_MAJOR_VERSION) "." STRINGIFY(PY_MINOR_VERSION) "m.so"
601982
+	"libpython" STRINGIFY(PY_MAJOR_VERSION) "." STRINGIFY(PY_MINOR_VERSION) LT_SHREXT
601982
+#else
601982
+#define LIBPYTHON_LINKER_NAME \
601982
+	"libpython" STRINGIFY(PY_MAJOR_VERSION) "." STRINGIFY(PY_MINOR_VERSION) "m" LT_SHREXT
601982
+#endif
601982
 
601982
 static uint32_t		python_instances = 0;
601982
 static void		*python_dlhandle;
601982
@@ -67,8 +76,10 @@ static CONF_PARSER module_config[] = {
601982
 	A(preacct)
601982
 	A(accounting)
601982
 	A(checksimul)
601982
+#ifdef WITH_PROXY
601982
 	A(pre_proxy)
601982
 	A(post_proxy)
601982
+#endif
601982
 	A(post_auth)
601982
 #ifdef WITH_COA
601982
 	A(recv_coa)
601982
@@ -98,7 +109,9 @@ static struct {
601982
 	A(L_AUTH)
601982
 	A(L_INFO)
601982
 	A(L_ERR)
601982
+#ifdef WITH_PROXY
601982
 	A(L_PROXY)
601982
+#endif
601982
 	A(L_ACCT)
601982
 	A(L_DBG_WARN)
601982
 	A(L_DBG_ERR)
601982
@@ -186,18 +199,16 @@ static void python_error_log(void)
601982
 
601982
 	if (!pExcType || !pExcValue) {
601982
 		ERROR("%s:%d, Unknown error", __func__, __LINE__);
601982
-		if (pExcType) {
601982
-			Py_DecRef(pExcType);
601982
-		}
601982
-		if (pExcValue) {
601982
-			Py_DecRef(pExcValue);
601982
-		}
601982
+		Py_XDECREF(pExcType);
601982
+		Py_XDECREF(pExcValue);
601982
 		return;
601982
 	}
601982
 
601982
 	if (((pStr1 = PyObject_Str(pExcType)) != NULL) && 
601982
 	    ((pStr2 = PyObject_Str(pExcValue)) != NULL)) {
601982
 		ERROR("%s:%d, Exception type: %s, Exception value: %s", __func__, __LINE__, PyUnicode_AsUTF8(pStr1), PyUnicode_AsUTF8(pStr2));
601982
+		Py_DECREF(pStr1);
601982
+		Py_DECREF(pStr2);
601982
 	} 
601982
 
601982
 	if (pExcTraceback) {
601982
@@ -217,46 +228,23 @@ static void python_error_log(void)
601982
 				char *str = PyBytes_AsString(pTraceString);
601982
 				ERROR("%s:%d, full_backtrace: %s", __func__, __LINE__, str);
601982
 
601982
-				if (pyth_val) {
601982
-					Py_DecRef(pyth_val);
601982
-				}
601982
-				if (pystr) {
601982
-					Py_DecRef(pystr);
601982
-				}
601982
-				if (pTraceString) {
601982
-					Py_DecRef(pTraceString);
601982
-				}
601982
+				Py_DECREF(pyth_val);
601982
+				Py_DECREF(pystr);
601982
+				Py_DECREF(pTraceString);
601982
+				Py_DECREF(pyth_func);
601982
 			}
601982
-			if (pyth_func) {
601982
-				Py_DecRef(pyth_func);
601982
-			}
601982
-			Py_DecRef(pyth_module);
601982
+			Py_DECREF(pyth_module);
601982
 		} else {
601982
 			ERROR("%s:%d, py_module is null, name: %p", __func__, __LINE__, module_name);
601982
 		}
601982
 
601982
-		if (module_name) {
601982
-			Py_DecRef(module_name);
601982
-		}
601982
-
601982
-		Py_DecRef(pRepr);
601982
+		Py_DECREF(module_name);
601982
+		Py_DECREF(pRepr);
601982
+		Py_DECREF(pExcTraceback);
601982
 	}
601982
 
601982
-	if (pExcType) {
601982
-		Py_DecRef(pExcType);
601982
-	}
601982
-	if (pExcValue) {
601982
-		Py_DecRef(pExcValue);
601982
-	}
601982
-	if (pExcTraceback) {
601982
-		Py_DecRef(pExcTraceback);
601982
-	}
601982
-	if (pStr1) {
601982
-		Py_DecRef(pStr1);
601982
-	}
601982
-	if (pStr2) {
601982
-		Py_DecRef(pStr2);
601982
-	}
601982
+	Py_DECREF(pExcType);
601982
+	Py_DECREF(pExcValue);
601982
 }
601982
 
601982
 static void mod_vptuple(TALLOC_CTX *ctx, REQUEST *request, VALUE_PAIR **vps, PyObject *pValue,
601982
@@ -510,6 +498,7 @@ static rlm_rcode_t do_python_single(REQUEST *request, PyObject *pFunc, char cons
601982
 			goto finish;
601982
 		}
601982
 
601982
+#ifdef WITH_PROXY
601982
 		/* fill proxy vps */
601982
 		if (request->proxy) {
601982
 			if (!mod_populate_vps(pArgs, 4, request->proxy->vps)) {
601982
@@ -517,10 +506,13 @@ static rlm_rcode_t do_python_single(REQUEST *request, PyObject *pFunc, char cons
601982
 				ret = RLM_MODULE_FAIL;
601982
 				goto finish;
601982
 			}
601982
-		} else {
601982
+		} else
601982
+#endif
601982
+		{
601982
 			mod_populate_vps(pArgs, 4, NULL);
601982
 		}
601982
 
601982
+#ifdef WITH_PROXY
601982
 		/* fill proxy_reply vps */
601982
 		if (request->proxy_reply) {
601982
 			if (!mod_populate_vps(pArgs, 5, request->proxy_reply->vps)) {
601982
@@ -528,7 +520,9 @@ static rlm_rcode_t do_python_single(REQUEST *request, PyObject *pFunc, char cons
601982
 				ret = RLM_MODULE_FAIL;
601982
 				goto finish;
601982
 			}
601982
-		} else {
601982
+		} else
601982
+#endif
601982
+		{
601982
 			mod_populate_vps(pArgs, 5, NULL);
601982
 		}
601982
 
601982
@@ -550,9 +544,14 @@ static rlm_rcode_t do_python_single(REQUEST *request, PyObject *pFunc, char cons
601982
 		    PyDict_SetItemString(pDictInput, "request", PyTuple_GET_ITEM(pArgs, 0)) ||
601982
 		    PyDict_SetItemString(pDictInput, "reply", PyTuple_GET_ITEM(pArgs, 1)) ||
601982
 		    PyDict_SetItemString(pDictInput, "config", PyTuple_GET_ITEM(pArgs, 2)) ||
601982
-		    PyDict_SetItemString(pDictInput, "session-state", PyTuple_GET_ITEM(pArgs, 3)) ||
601982
+		    PyDict_SetItemString(pDictInput, "session-state", PyTuple_GET_ITEM(pArgs, 3))
601982
+#ifdef WITH_PROXY
601982
+		    ||
601982
 		    PyDict_SetItemString(pDictInput, "proxy-request", PyTuple_GET_ITEM(pArgs, 4)) ||
601982
-		    PyDict_SetItemString(pDictInput, "proxy-reply", PyTuple_GET_ITEM(pArgs, 5))) {
601982
+		    PyDict_SetItemString(pDictInput, "proxy-reply", PyTuple_GET_ITEM(pArgs, 5))
601982
+#endif
601982
+		    ) {
601982
+
601982
 			ERROR("%s:%d, %s - PyDict_SetItemString failed", __func__, __LINE__, funcname);
601982
 			ret = RLM_MODULE_FAIL;
601982
 			goto finish;
601982
@@ -819,8 +818,10 @@ MOD_FUNC(authorize)
601982
 MOD_FUNC(preacct)
601982
 MOD_FUNC(accounting)
601982
 MOD_FUNC(checksimul)
601982
+#ifdef WITH_PROXY
601982
 MOD_FUNC(pre_proxy)
601982
 MOD_FUNC(post_proxy)
601982
+#endif
601982
 MOD_FUNC(post_auth)
601982
 #ifdef WITH_COA
601982
 MOD_FUNC(recv_coa)
601982
@@ -1102,7 +1103,7 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
601982
 		python_dlhandle = dlopen_libpython(RTLD_NOW | RTLD_GLOBAL);
601982
 		if (!python_dlhandle) WARN("Failed loading libpython symbols into global symbol table");
601982
 
601982
-#if PY_VERSION_HEX > 0x03050000
601982
+#if PY_VERSION_HEX >= 0x03050000
601982
 		{
601982
 			wchar_t  *name;
601982
 
601982
@@ -1110,13 +1111,6 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
601982
 			Py_SetProgramName(name);		/* The value of argv[0] as a wide char string */
601982
 			PyMem_RawFree(name);
601982
 		}
601982
-#elif PY_VERSION_HEX > 0x0300000
601982
-		{
601982
-			wchar_t *name;
601982
-
601982
-			MEM(name = _Py_char2wchar(main_config.name, NULL));
601982
-			Py_SetProgramName(inst->wide_name);		/* The value of argv[0] as a wide char string */
601982
-		}
601982
 #else
601982
 		{
601982
 			char *name;
601982
@@ -1163,37 +1157,34 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
601982
 		 *	the lifetime of the module.
601982
 		 */
601982
 		if (inst->python_path) {
601982
+			char *p, *path;
601982
+			PyObject *sys = PyImport_ImportModule("sys");
601982
+			PyObject *sys_path = PyObject_GetAttrString(sys, "path");
601982
+
601982
+			memcpy(&p, &inst->python_path, sizeof(path));
601982
+
601982
+			for (path = strtok(p, ":"); path != NULL; path = strtok(NULL, ":")) {
601982
 #if PY_VERSION_HEX > 0x03050000
601982
-			{
601982
-				wchar_t *path;
601982
-				PyObject* sys = PyImport_ImportModule("sys");
601982
-				PyObject* sys_path = PyObject_GetAttrString(sys,"path");
601982
-
601982
-				MEM(path = Py_DecodeLocale(inst->python_path, NULL));
601982
-				PyList_Append(sys_path, PyUnicode_FromWideChar(path,-1));				
601982
-				PyObject_SetAttrString(sys,"path",sys_path);
601982
-				PyMem_RawFree(path);
601982
-			}
601982
+				wchar_t *py_path;
601982
+
601982
+				MEM(py_path = Py_DecodeLocale(path, NULL));
601982
+				PyList_Append(sys_path, PyUnicode_FromWideChar(py_path, -1));
601982
+				PyMem_RawFree(py_path);
601982
 #elif PY_VERSION_HEX > 0x03000000
601982
-			{
601982
-				wchar_t *path;
601982
-				PyObject* sys = PyImport_ImportModule("sys");
601982
-				PyObject* sys_path = PyObject_GetAttrString(sys,"path");
601982
-
601982
-				MEM(path = _Py_char2wchar(inst->python_path, NULL));
601982
-				PyList_Append(sys_path, PyUnicode_FromWideChar(path,-1));				
601982
-				PyObject_SetAttrString(sys,"path",sys_path);
601982
-			}
601982
-#else
601982
-			{
601982
-				char *path;
601982
+				wchar_t *py_path;
601982
 
601982
-				memcpy(&path, &inst->python_path, sizeof(path));
601982
-				Py_SetPath(path);
601982
-			}
601982
+				MEM(py_path = _Py_char2wchar(path, NULL));
601982
+				PyList_Append(sys_path, PyUnicode_FromWideChar(py_path, -1));
601982
+				PyMem_RawFree(py_path);
601982
+#else
601982
+				PyList_Append(sys_path, PyLong_FromString(path));
601982
 #endif
601982
-		}
601982
+			}
601982
 
601982
+			PyObject_SetAttrString(sys, "path", sys_path);
601982
+			Py_DecRef(sys);
601982
+			Py_DecRef(sys_path);
601982
+		}
601982
 	} else {
601982
 		inst->module = main_module;
601982
 		Py_IncRef(inst->module);
601982
@@ -1220,7 +1211,7 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
601982
 static int mod_instantiate(CONF_SECTION *conf, void *instance)
601982
 {
601982
 	rlm_python_t	*inst = instance;
601982
-	int		code = 0;
601982
+	int		code = RLM_MODULE_OK;
601982
 
601982
 	inst->name = cf_section_name2(conf);
601982
 	if (!inst->name) inst->name = cf_section_name1(conf);
601982
@@ -1245,8 +1236,10 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
601982
 	PYTHON_FUNC_LOAD(preacct);
601982
 	PYTHON_FUNC_LOAD(accounting);
601982
 	PYTHON_FUNC_LOAD(checksimul);
601982
+#ifdef WITH_PROXY
601982
 	PYTHON_FUNC_LOAD(pre_proxy);
601982
 	PYTHON_FUNC_LOAD(post_proxy);
601982
+#endif
601982
 	PYTHON_FUNC_LOAD(post_auth);
601982
 #ifdef WITH_COA
601982
 	PYTHON_FUNC_LOAD(recv_coa);
601982
@@ -1257,12 +1250,14 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
601982
 	/*
601982
 	 *	Call the instantiate function.
601982
 	 */
601982
-	code = do_python_single(NULL, inst->instantiate.function, "instantiate", inst->pass_all_vps, inst->pass_all_vps_dict);
601982
-	if (code < 0) {
601982
-	error:
601982
-		python_error_log();	/* Needs valid thread with GIL */
601982
-		PyEval_SaveThread();
601982
-		return -1;
601982
+	if (inst->instantiate.function) {
601982
+		code = do_python_single(NULL, inst->instantiate.function, "instantiate", inst->pass_all_vps, inst->pass_all_vps_dict);
601982
+		if (code < 0) {
601982
+		error:
601982
+			python_error_log();	/* Needs valid thread with GIL */
601982
+			PyEval_SaveThread();
601982
+			return -1;
601982
+		}
601982
 	}
601982
 	PyEval_SaveThread();
601982
 
601982
@@ -1272,22 +1267,31 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
601982
 static int mod_detach(void *instance)
601982
 {
601982
 	rlm_python_t *inst = instance;
601982
-	int	     ret;
601982
+	int	     ret = RLM_MODULE_OK;
601982
 
601982
 	/*
601982
 	 *	Call module destructor
601982
 	 */
601982
 	PyEval_RestoreThread(inst->sub_interpreter);
601982
 
601982
-	ret = do_python_single(NULL, inst->detach.function, "detach", inst->pass_all_vps, inst->pass_all_vps_dict);
601982
+	if (inst->detach.function) ret = do_python_single(NULL, inst->detach.function, "detach", inst->pass_all_vps, inst->pass_all_vps_dict);
601982
 
601982
 #define PYTHON_FUNC_DESTROY(_x) python_function_destroy(&inst->_x)
601982
 	PYTHON_FUNC_DESTROY(instantiate);
601982
-	PYTHON_FUNC_DESTROY(authorize);
601982
 	PYTHON_FUNC_DESTROY(authenticate);
601982
+	PYTHON_FUNC_DESTROY(authorize);
601982
 	PYTHON_FUNC_DESTROY(preacct);
601982
 	PYTHON_FUNC_DESTROY(accounting);
601982
 	PYTHON_FUNC_DESTROY(checksimul);
601982
+#ifdef WITH_PROXY
601982
+	PYTHON_FUNC_DESTROY(pre_proxy);
601982
+	PYTHON_FUNC_DESTROY(post_proxy);
601982
+#endif
601982
+	PYTHON_FUNC_DESTROY(post_auth);
601982
+#ifdef WITH_COA
601982
+	PYTHON_FUNC_DESTROY(recv_coa);
601982
+	PYTHON_FUNC_DESTROY(send_coa);
601982
+#endif
601982
 	PYTHON_FUNC_DESTROY(detach);
601982
 
601982
 	Py_DecRef(inst->pythonconf_dict);
601982
@@ -1313,14 +1317,8 @@ static int mod_detach(void *instance)
601982
 		PyThreadState_Swap(main_interpreter); /* Swap to the main thread */
601982
 		Py_Finalize();
601982
 		dlclose(python_dlhandle);
601982
-
601982
-#if PY_VERSION_HEX > 0x03050000
601982
-		//if (inst->wide_name) PyMem_RawFree(inst->wide_name);
601982
-		//if (inst->wide_path) PyMem_RawFree(inst->wide_path);
601982
-#endif
601982
 	}
601982
 
601982
-
601982
 	return ret;
601982
 }
601982
 
601982
@@ -1348,8 +1346,10 @@ module_t rlm_python3 = {
601982
 		[MOD_PREACCT]		= mod_preacct,
601982
 		[MOD_ACCOUNTING]	= mod_accounting,
601982
 		[MOD_SESSION]		= mod_checksimul,
601982
+#ifdef WITH_PROXY
601982
 		[MOD_PRE_PROXY]		= mod_pre_proxy,
601982
 		[MOD_POST_PROXY]	= mod_post_proxy,
601982
+#endif
601982
 		[MOD_POST_AUTH]		= mod_post_auth,
601982
 #ifdef WITH_COA
601982
 		[MOD_RECV_COA]		= mod_recv_coa,
601982
-- 
601982
2.26.2
601982