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

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