-SRD_LIB_VERSION_CURRENT=1
-SRD_LIB_VERSION_REVISION=0
-SRD_LIB_VERSION_AGE=0
-SRD_LIB_VERSION="$SRD_LIB_VERSION_CURRENT:$SRD_LIB_VERSION_REVISION:$SRD_LIB_VERSION_AGE"
-SRD_LIB_LDFLAGS="-version-info $SRD_LIB_VERSION"
-AC_SUBST(SRD_LIB_VERSION_CURRENT)
-AC_SUBST(SRD_LIB_VERSION_REVISION)
-AC_SUBST(SRD_LIB_VERSION_AGE)
-AC_SUBST(SRD_LIB_VERSION)
-AC_SUBST(SRD_LIB_LDFLAGS)
-
-# assume we can build tests/runtc unless proven otherwise
-build_runtc="yes"
-
-# Checks for libraries.
-
-# libglib-2.0 is always needed.
-# Note: glib-2.0 is part of the libsigrokdecode API
-# (hard pkg-config requirement).
-AM_PATH_GLIB_2_0([2.24.0],
- [CFLAGS="$CFLAGS $GLIB_CFLAGS"; LIBS="$LIBS $GLIB_LIBS"])
-
-# Python support. We require at least Python >= 3.0.
-CPPFLAGS_PYTHON=""
-LDFLAGS_PYTHON=""
-PKG_CHECK_MODULES([python3], [python3 >= 3.0],
- [have_python3="yes"; CPPFLAGS_PYTHON="$python3_CFLAGS";
- LDFLAGS_PYTHON="$python3_LIBS"], [have_python3="no"])
-case "$build" in
-*mingw*)
- # We currently hardcode the paths to the Python 3.2 default install
- # location as there's no 'python-config' script on Windows, it seems.
- # Note: We add both the /c/ and c:/ syntax (needed for cmake).
- AC_MSG_WARN([using hardcoded Python3 configuration on MinGW])
- CPPFLAGS_PYTHON="-I/c/Python32/include -Ic:/Python32/include"
- LDFLAGS_PYTHON="-L/c/Python32/libs -Lc:/Python32/libs -lpython32"
- ;;
-*)
- if test x"$have_python3" = xno; then
- AC_MSG_ERROR([python3 not found])
- fi
- ;;
-esac
-AC_SUBST(CPPFLAGS_PYTHON)
-AC_SUBST(LDFLAGS_PYTHON)
+# Format: current:revision:age.
+SR_LIB_VERSION_SET([SRD_LIB_VERSION], [4:0:0])
+
+AM_CONDITIONAL([WIN32], [test -z "${host_os##mingw*}" || test -z "${host_os##cygwin*}"])
+
+# Initialize pkg-config.
+# We require at least 0.22, as "Requires.private" behaviour changed there.
+PKG_PROG_PKG_CONFIG
+
+############################
+## Package dependencies ##
+############################
+
+# Initialize pkg-config.
+# We require at least 0.22, as "Requires.private" behaviour changed there.
+PKG_PROG_PKG_CONFIG([0.22])
+
+# Collect the pkg-config module names of all dependencies in SRD_PKGLIBS.
+# These are used to derive the compiler flags and for the "Requires.private"
+# field in the generated libsigrokdecode.pc file.
+SRD_PKGLIBS=
+SRD_PKGLIBS_TESTS=
+
+# Keep track of all checked modules so we can list them at the end.
+SR_PKG_CHECK_SUMMARY([srd_pkglibs_summary])
+
+# Python 3 is always needed.
+# 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])