Blame SOURCES/ldns-1.7.1-Support-sysconfig-python-module-in-python_devel.patch

df3714
--- a/m4/ax_python_devel.m4	2019-07-26 17:07:44.000000000 +0200
df3714
+++ b/m4/ax_python_devel.m4	2022-02-15 10:29:28.876543000 +0100
df3714
@@ -1,5 +1,5 @@
df3714
 # ===========================================================================
df3714
-#      http://www.gnu.org/software/autoconf-archive/ax_python_devel.html
df3714
+#     https://www.gnu.org/software/autoconf-archive/ax_python_devel.html
df3714
 # ===========================================================================
df3714
 #
df3714
 # SYNOPSIS
df3714
@@ -12,8 +12,8 @@
df3714
 #   in your configure.ac.
df3714
 #
df3714
 #   This macro checks for Python and tries to get the include path to
df3714
-#   'Python.h'. It provides the $(PYTHON_CPPFLAGS) and $(PYTHON_LDFLAGS)
df3714
-#   output variables. It also exports $(PYTHON_EXTRA_LIBS) and
df3714
+#   'Python.h'. It provides the $(PYTHON_CPPFLAGS) and $(PYTHON_LIBS) output
df3714
+#   variables. It also exports $(PYTHON_EXTRA_LIBS) and
df3714
 #   $(PYTHON_EXTRA_LDFLAGS) for embedding Python in your code.
df3714
 #
df3714
 #   You can search for some particular version of Python by passing a
df3714
@@ -52,7 +52,7 @@
df3714
 #   Public License for more details.
df3714
 #
df3714
 #   You should have received a copy of the GNU General Public License along
df3714
-#   with this program. If not, see <http://www.gnu.org/licenses/>.
df3714
+#   with this program. If not, see <https://www.gnu.org/licenses/>.
df3714
 #
df3714
 #   As a special exception, the respective Autoconf Macro's copyright owner
df3714
 #   gives unlimited permission to copy, distribute and modify the configure
df3714
@@ -67,7 +67,7 @@
df3714
 #   modified version of the Autoconf Macro, you may extend this special
df3714
 #   exception to the GPL to apply to your modified version as well.
df3714
 
df3714
-#serial 16
df3714
+#serial 23
df3714
 
df3714
 AU_ALIAS([AC_PYTHON_DEVEL], [AX_PYTHON_DEVEL])
df3714
 AC_DEFUN([AX_PYTHON_DEVEL],[
df3714
@@ -99,7 +99,7 @@
df3714
 This version of the AC@&t@_PYTHON_DEVEL macro
df3714
 doesn't work properly with versions of Python before
df3714
 2.1.0. You may need to re-run configure, setting the
df3714
-variables PYTHON_CPPFLAGS, PYTHON_LDFLAGS, PYTHON_SITE_PKG,
df3714
+variables PYTHON_CPPFLAGS, PYTHON_LIBS, PYTHON_SITE_PKG,
df3714
 PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand.
df3714
 Moreover, to disable this check, set PYTHON_NOVERSIONCHECK
df3714
 to something else than an empty string.
df3714
@@ -135,16 +135,25 @@
df3714
 	#
df3714
 	# Check if you have distutils, else fail
df3714
 	#
df3714
-	AC_MSG_CHECKING([for the distutils Python package])
df3714
-	ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
df3714
-	if test -z "$ac_distutils_result"; then
df3714
+	AC_MSG_CHECKING([for the sysconfig Python package])
df3714
+	ac_sysconfig_result=`$PYTHON -c "import sysconfig" 2>&1`
df3714
+	if test $? -eq 0; then
df3714
 		AC_MSG_RESULT([yes])
df3714
+		IMPORT_SYSCONFIG="import sysconfig"
df3714
 	else
df3714
 		AC_MSG_RESULT([no])
df3714
-		AC_MSG_ERROR([cannot import Python module "distutils".
df3714
+
df3714
+		AC_MSG_CHECKING([for the distutils Python package])
df3714
+		ac_sysconfig_result=`$PYTHON -c "from distutils import sysconfig" 2>&1`
df3714
+		if test $? -eq 0; then
df3714
+			AC_MSG_RESULT([yes])
df3714
+			IMPORT_SYSCONFIG="from distutils import sysconfig"
df3714
+		else
df3714
+			AC_MSG_ERROR([cannot import Python module "distutils".
df3714
 Please check your Python installation. The error was:
df3714
-$ac_distutils_result])
df3714
-		PYTHON_VERSION=""
df3714
+$ac_sysconfig_result])
df3714
+			PYTHON_VERSION=""
df3714
+		fi
df3714
 	fi
df3714
 
df3714
 	#
df3714
@@ -152,10 +161,19 @@
df3714
 	#
df3714
 	AC_MSG_CHECKING([for Python include path])
df3714
 	if test -z "$PYTHON_CPPFLAGS"; then
df3714
-		python_path=`$PYTHON -c "import distutils.sysconfig; \
df3714
-			print (distutils.sysconfig.get_python_inc ());"`
df3714
-		plat_python_path=`$PYTHON -c "import distutils.sysconfig; \
df3714
-			print (distutils.sysconfig.get_python_inc (plat_specific=1));"`
df3714
+		if test "$IMPORT_SYSCONFIG" = "import sysconfig"; then
df3714
+			# sysconfig module has different functions
df3714
+			python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \
df3714
+				print (sysconfig.get_path ('include'));"`
df3714
+			plat_python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \
df3714
+				print (sysconfig.get_path ('platinclude'));"`
df3714
+		else
df3714
+			# old distutils way
df3714
+			python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \
df3714
+				print (sysconfig.get_python_inc ());"`
df3714
+			plat_python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \
df3714
+				print (sysconfig.get_python_inc (plat_specific=1));"`
df3714
+		fi
df3714
 		if test -n "${python_path}"; then
df3714
 			if test "${plat_python_path}" != "${python_path}"; then
df3714
 				python_path="-I$python_path -I$plat_python_path"
df3714
@@ -172,14 +190,14 @@
df3714
 	# Check for Python library path
df3714
 	#
df3714
 	AC_MSG_CHECKING([for Python library path])
df3714
-	if test -z "$PYTHON_LDFLAGS"; then
df3714
+	if test -z "$PYTHON_LIBS"; then
df3714
 		# (makes two attempts to ensure we've got a version number
df3714
 		# from the interpreter)
df3714
 		ac_python_version=`cat<
df3714
 
df3714
 # join all versioning strings, on some systems
df3714
 # major/minor numbers could be in different list elements
df3714
-from distutils.sysconfig import *
df3714
+from sysconfig import *
df3714
 e = get_config_var('VERSION')
df3714
 if e is not None:
df3714
 	print(e)
df3714
@@ -202,8 +220,8 @@
df3714
 		ac_python_libdir=`cat<
df3714
 
df3714
 # There should be only one
df3714
-import distutils.sysconfig
df3714
-e = distutils.sysconfig.get_config_var('LIBDIR')
df3714
+$IMPORT_SYSCONFIG
df3714
+e = sysconfig.get_config_var('LIBDIR')
df3714
 if e is not None:
df3714
 	print (e)
df3714
 EOD`
df3714
@@ -211,8 +229,8 @@
df3714
 		# Now, for the library:
df3714
 		ac_python_library=`cat<
df3714
 
df3714
-import distutils.sysconfig
df3714
-c = distutils.sysconfig.get_config_vars()
df3714
+$IMPORT_SYSCONFIG
df3714
+c = sysconfig.get_config_vars()
df3714
 if 'LDVERSION' in c:
df3714
 	print ('python'+c[['LDVERSION']])
df3714
 else:
df3714
@@ -227,45 +245,51 @@
df3714
 		then
df3714
 			# use the official shared library
df3714
 			ac_python_library=`echo "$ac_python_library" | sed "s/^lib//"`
df3714
-			PYTHON_LDFLAGS="-L$ac_python_libdir -l$ac_python_library"
df3714
+			PYTHON_LIBS="-L$ac_python_libdir -l$ac_python_library"
df3714
 		else
df3714
 			# old way: use libpython from python_configdir
df3714
 			ac_python_libdir=`$PYTHON -c \
df3714
-			  "from distutils.sysconfig import get_python_lib as f; \
df3714
+			  "from sysconfig import get_python_lib as f; \
df3714
 			  import os; \
df3714
 			  print (os.path.join(f(plat_specific=1, standard_lib=1), 'config'));"`
df3714
-			PYTHON_LDFLAGS="-L$ac_python_libdir -lpython$ac_python_version"
df3714
+			PYTHON_LIBS="-L$ac_python_libdir -lpython$ac_python_version"
df3714
 		fi
df3714
 
df3714
-		if test -z "PYTHON_LDFLAGS"; then
df3714
+		if test -z "PYTHON_LIBS"; then
df3714
 			AC_MSG_ERROR([
df3714
   Cannot determine location of your Python DSO. Please check it was installed with
df3714
-  dynamic libraries enabled, or try setting PYTHON_LDFLAGS by hand.
df3714
+  dynamic libraries enabled, or try setting PYTHON_LIBS by hand.
df3714
 			])
df3714
 		fi
df3714
 	fi
df3714
-	AC_MSG_RESULT([$PYTHON_LDFLAGS])
df3714
-	AC_SUBST([PYTHON_LDFLAGS])
df3714
+	AC_MSG_RESULT([$PYTHON_LIBS])
df3714
+	AC_SUBST([PYTHON_LIBS])
df3714
 
df3714
 	#
df3714
 	# Check for site packages
df3714
 	#
df3714
 	AC_MSG_CHECKING([for Python site-packages path])
df3714
 	if test -z "$PYTHON_SITE_PKG"; then
df3714
-		PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
df3714
-			print (distutils.sysconfig.get_python_lib(1,0));"`
df3714
+		if test "$IMPORT_SYSCONFIG" = "import sysconfig"; then
df3714
+			PYTHON_SITE_PKG=`$PYTHON -c "$IMPORT_SYSCONFIG; \
df3714
+				print (sysconfig.get_path('platlib'));"`
df3714
+		else
df3714
+			# distutils.sysconfig way
df3714
+			PYTHON_SITE_PKG=`$PYTHON -c "$IMPORT_SYSCONFIG; \
df3714
+				print (sysconfig.get_python_lib(0,0));"`
df3714
+		fi
df3714
 	fi
df3714
 	AC_MSG_RESULT([$PYTHON_SITE_PKG])
df3714
 	AC_SUBST([PYTHON_SITE_PKG])
df3714
 
df3714
 	#
df3714
 	# libraries which must be linked in when embedding
df3714
 	#
df3714
 	AC_MSG_CHECKING(python extra libraries)
df3714
 	if test -z "$PYTHON_EXTRA_LIBS"; then
df3714
-	   PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
df3714
-                conf = distutils.sysconfig.get_config_var; \
df3714
-                print (conf('LIBS'))"`
df3714
+	   PYTHON_EXTRA_LIBS=`$PYTHON -c "$IMPORT_SYSCONFIG; \
df3714
+                conf = sysconfig.get_config_var; \
df3714
+                print (conf('LIBS') + ' ' + conf('SYSLIBS'))"`
df3714
 	fi
df3714
 	AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
df3714
 	AC_SUBST(PYTHON_EXTRA_LIBS)
df3714
@@ -275,8 +316,8 @@
df3714
 	#
df3714
 	AC_MSG_CHECKING(python extra linking flags)
df3714
 	if test -z "$PYTHON_EXTRA_LDFLAGS"; then
df3714
-		PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
df3714
-			conf = distutils.sysconfig.get_config_var; \
df3714
+		PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "$IMPORT_SYSCONFIG; \
df3714
+			conf = sysconfig.get_config_var; \
df3714
 			print (conf('LINKFORSHARED'))"`
df3714
 	fi
df3714
 	AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
df3714
@@ -288,8 +329,10 @@
df3714
 	AC_MSG_CHECKING([consistency of all components of python development environment])
df3714
 	# save current global flags
df3714
 	ac_save_LIBS="$LIBS"
df3714
+	ac_save_LDFLAGS="$LDFLAGS"
df3714
 	ac_save_CPPFLAGS="$CPPFLAGS"
df3714
-	LIBS="$ac_save_LIBS $PYTHON_LDFLAGS $PYTHON_EXTRA_LDFLAGS $PYTHON_EXTRA_LIBS"
df3714
+	LIBS="$ac_save_LIBS $PYTHON_LIBS $PYTHON_EXTRA_LIBS $PYTHON_EXTRA_LIBS"
df3714
+	LDFLAGS="$ac_save_LDFLAGS $PYTHON_EXTRA_LDFLAGS"
df3714
 	CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS"
df3714
 	AC_LANG_PUSH([C])
df3714
 	AC_LINK_IFELSE([
df3714
@@ -300,6 +343,7 @@
df3714
 	# turn back to default flags
df3714
 	CPPFLAGS="$ac_save_CPPFLAGS"
df3714
 	LIBS="$ac_save_LIBS"
df3714
+	LDFLAGS="$ac_save_LDFLAGS"
df3714
 
df3714
 	AC_MSG_RESULT([$pythonexists])
df3714
 
df3714
@@ -307,8 +351,8 @@
df3714
 	   AC_MSG_FAILURE([
df3714
   Could not link test program to Python. Maybe the main Python library has been
df3714
   installed in some non-standard library path. If so, pass it to configure,
df3714
-  via the LDFLAGS environment variable.
df3714
-  Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
df3714
+  via the LIBS environment variable.
df3714
+  Example: ./configure LIBS="-L/usr/non-standard-path/python/lib"
df3714
   ============================================================================
df3714
    ERROR!
df3714
    You probably have to install the development version of the Python package