-# Note: We need to try a few different variants, since some systems have a
-# python3.pc file, others have a python-3.3.pc file, and so on.
-# See also: http://sigrok.org/wiki/Libsigrokdecode/Python
-CPPFLAGS_PYTHON=""
-LDFLAGS_PYTHON=""
-PKG_CHECK_MODULES([python3], [python3 >= 3.0],
- [CPPFLAGS_PYTHON="$CPPFLAGS_PYTHON $python3_CFLAGS";
- LDFLAGS_PYTHON="$LDFLAGS_PYTHON $python3_LIBS"],
-[PKG_CHECK_MODULES([python33], [python-3.3 >= 3.0],
- [CPPFLAGS_PYTHON="$CPPFLAGS_PYTHON $python33_CFLAGS";
- LDFLAGS_PYTHON="$LDFLAGS_PYTHON $python33_LIBS"],
-[PKG_CHECK_MODULES([python32], [python-3.2 >= 3.0],
- [CPPFLAGS_PYTHON="$CPPFLAGS_PYTHON $python32_CFLAGS";
- LDFLAGS_PYTHON="$LDFLAGS_PYTHON $python32_LIBS"],
-[PKG_CHECK_MODULES([python31], [python-3.1 >= 3.0],
- [CPPFLAGS_PYTHON="$CPPFLAGS_PYTHON $python31_CFLAGS";
- LDFLAGS_PYTHON="$LDFLAGS_PYTHON $python31_LIBS"],
-[PKG_CHECK_MODULES([python30], [python-3.0 >= 3.0],
- [CPPFLAGS_PYTHON="$CPPFLAGS_PYTHON $python30_CFLAGS";
- LDFLAGS_PYTHON="$LDFLAGS_PYTHON $python30_LIBS"],
-)])])])])
-AC_SUBST(CPPFLAGS_PYTHON)
-AC_SUBST(LDFLAGS_PYTHON)
+# Starting with Python 3.8 we need to check for "python-3.8-embed"
+# first, since usually only that variant will add "-lpython3.8".
+# https://docs.python.org/3/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build
+SR_PKG_CHECK([python3], [SRD_PKGLIBS],
+ [python-3.8-embed], [python-3.8 >= 3.8], [python-3.7 >= 3.7], [python-3.6 >= 3.6], [python-3.5 >= 3.5], [python-3.4 >= 3.4], [python-3.3 >= 3.3], [python-3.2 >= 3.2], [python3 >= 3.2])
+AS_IF([test "x$sr_have_python3" = xno],
+ [AC_MSG_ERROR([Cannot find Python 3 development headers.])])
+
+# We also need to find the name of the python3 executable (for 'make install').
+# Some OSes call this python3, some call it python3.2, etc. etc.
+AC_ARG_VAR([PYTHON3], [Python 3 interpreter])
+AC_CHECK_PROGS([PYTHON3], [python3.8 python3.7 python3.6 python3.5 python3.4 python3.3 python3.2 python3])
+AS_IF([test "x$PYTHON3" = x],
+ [AC_MSG_ERROR([Cannot find Python 3 interpreter.])])
+
+######################
+## Feature checks ##
+######################
+
+# Keep track of all checked modules so we can list them at the end.
+SR_PKG_CHECK_SUMMARY([srd_pkglibs_opt_summary])
+
+# The Check unit testing framework is optional. Disable if not found.
+SR_PKG_CHECK([check], [SRD_PKGLIBS_TESTS], [check >= 0.9.4])
+AM_CONDITIONAL([HAVE_CHECK], [test "x$sr_have_check" = xyes])
+
+# Enable the C99 standard if possible, and enforce the use
+# of SRD_API to explicitly mark all public API functions.
+SRD_EXTRA_CFLAGS=
+SR_CHECK_COMPILE_FLAGS([SRD_EXTRA_CFLAGS], [C99], [-std=c99 -c99 -AC99 -qlanglvl=extc99])
+SR_CHECK_COMPILE_FLAGS([SRD_EXTRA_CFLAGS], [visibility], [-fvisibility=hidden])
+
+# Select suitable compiler warning flags.
+SR_ARG_ENABLE_WARNINGS([SRD_WFLAGS], [-Wall], [-Wall -Wextra -Wmissing-prototypes -Wshadow -Wformat=2 -Wno-format-nonliteral -Wfloat-equal])