Debian Codegraph @

libdrgn/m4/my_python_devel.m4

raw
1 # Copyright (c) Meta Platforms, Inc. and affiliates.
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3
4 # MY_PYTHON_DEVEL([find-libpython=no])
5 # Check for Python development files and define PYTHON_CPPFLAGS and PYTHON_LIBS
6 # accordingly.
7 AC_DEFUN([MY_PYTHON_DEVEL],
8 [
9 AS_IF([test -z "$PYTHON_CPPFLAGS"],
10 [prog="import sysconfig
11 include = sysconfig.get_path('include')
12 platinclude = sysconfig.get_path('platinclude')
13 include_paths = [[include]]
14 if platinclude != include:
15 include_paths.append(plat_include)
16 print(' '.join('-I' + path for path in include_paths))"
17 PYTHON_CPPFLAGS=`"$PYTHON" -c "$prog"`])
18
19 save_CPPFLAGS="$CPPFLAGS"
20 CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
21
22 AS_IF([test "x$1" = xyes],
23 [AS_IF([test -z "$PYTHON_LIBS"]
24 [prog="import sysconfig
25 print('-L' + sysconfig.get_config_var('LIBDIR') +
26 ' -lpython' + sysconfig.get_config_var('LDVERSION'))"
27 PYTHON_LIBS=`"$PYTHON" -c "$prog"`])
28
29 save_LIBS="$LIBS"
30 LIBS="$LIBS $PYTHON_LIBS"
31
32 AC_MSG_CHECKING([for $PYTHON development headers and library])
33 AC_LINK_IFELSE([AC_LANG_SOURCE([[
34 #include <Python.h>
35
36 int main(void)
37 {
38 Py_Initialize();
39 }
40 ]])],
41 [AC_MSG_RESULT([yes])],
42 [AC_MSG_RESULT([no])
43 AC_MSG_ERROR(
44 [Could not compile and link test program with Python headers and library.
45
46 You may need to install your distribution's Python development package (e.g.,
47 python3-devel or python3-dev) or specify the location of the Python development
48 headers and/or library by setting the PYTHON_CPPFLAGS and PYTHON_LIBS
49 environment variables.])])
50
51 LIBS="$save_LIBS"],
52 [AC_MSG_CHECKING([for $PYTHON development headers])
53 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <Python.h>]])],
54 [AC_MSG_RESULT([yes])],
55 [AC_MSG_RESULT([no])
56 AC_MSG_ERROR(
57 [Could not compile test program with Python headers.
58
59 You may need to install your distribution's Python development package (e.g.,
60 python3-devel or python3-dev) or specify the location of the Python development
61 headers by setting the PYTHON_CPPFLAGS environment variable.])])])
62
63 CPPFLAGS="$save_CPPFLAGS"
64
65 AC_SUBST(PYTHON_CPPFLAGS)
66 AC_SUBST(PYTHON_LIBS)
67 ])