1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Fix python executed during configure

Previously it relied on AX_PYTHON_DEVEL, which in turn executes
python-config to get the build flags. However this does not work while
cross compiling because we can't execute the python-config build for the
target platform. To circumvent this problem the python build flags are
now queried via pkgconfig, which has the drawback of not having some
extra build flags, but they do not seem to be needed.

I tested this patch with the termux build system and it build without
their existing hack of injecting python after the configure step. I also
tested non cross compile build on Arch Linux and it also still works.

Fixes #851
This commit is contained in:
j.r 2022-02-18 18:50:02 +01:00
parent 57fb10f0bf
commit 5676159aa5
No known key found for this signature in database
GPG Key ID: E74A18B933F9145E
3 changed files with 9 additions and 10 deletions

View File

@ -98,10 +98,9 @@ elif test "x$enable_python_plugins" != xno; then
AC_MSG_NOTICE([Symlinking Python.framework to $PYTHON_FRAMEWORK]) AC_MSG_NOTICE([Symlinking Python.framework to $PYTHON_FRAMEWORK])
rm -f Python.framework rm -f Python.framework
ln -s $PYTHON_FRAMEWORK Python.framework ]) ln -s $PYTHON_FRAMEWORK Python.framework ])
AC_CHECK_PROG(PYTHON_CONFIG_EXISTS, python-config, yes, no) PKG_CHECK_MODULES([python], [python-embed], [PYTHON_CONFIG_EXISTS=yes], [PYTHON_CONFIG_EXISTS=no])
AC_CHECK_PROG(PYTHON3_CONFIG_EXISTS, python3-config, yes, no) PKG_CHECK_MODULES([python], [python3-embed], [PYTHON3_CONFIG_EXISTS=yes; AC_DEFINE(PY_IS_PYTHON3, [1], [Is Python version 3])], [PYTHON3_CONFIG_EXISTS=no])
if test "$PYTHON_CONFIG_EXISTS" = "yes" || test "$PYTHON3_CONFIG_EXISTS" = "yes"; then if test "$PYTHON_CONFIG_EXISTS" = "yes" || test "$PYTHON3_CONFIG_EXISTS" = "yes"; then
AX_PYTHON_DEVEL
AM_CONDITIONAL([BUILD_PYTHON_API], [true]) AM_CONDITIONAL([BUILD_PYTHON_API], [true])
AC_DEFINE([HAVE_PYTHON], [1], [Python support]) AC_DEFINE([HAVE_PYTHON], [1], [Python support])
else else
@ -357,9 +356,9 @@ AS_IF([test "x$PLATFORM" = xosx],
[AM_CFLAGS="$AM_CFLAGS -Qunused-arguments"]) [AM_CFLAGS="$AM_CFLAGS -Qunused-arguments"])
AM_CFLAGS="$AM_CFLAGS $PTHREAD_CFLAGS $glib_CFLAGS $gio_CFLAGS $curl_CFLAGS ${SQLITE_CFLAGS}" AM_CFLAGS="$AM_CFLAGS $PTHREAD_CFLAGS $glib_CFLAGS $gio_CFLAGS $curl_CFLAGS ${SQLITE_CFLAGS}"
AM_CFLAGS="$AM_CFLAGS $libnotify_CFLAGS ${GTK_CFLAGS} $PYTHON_CPPFLAGS" dnl https://bugs.python.org/issue15018 AM_CFLAGS="$AM_CFLAGS $libnotify_CFLAGS ${GTK_CFLAGS} $python_CFLAGS" dnl https://bugs.python.org/issue15018
AM_CFLAGS="$AM_CFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\" -DICONS_PATH=\"\\\"$ICONS_PATH\\\"\" -DGLOBAL_PYTHON_PLUGINS_PATH=\"\\\"$GLOBAL_PYTHON_PLUGINS_PATH\\\"\" -DGLOBAL_C_PLUGINS_PATH=\"\\\"$GLOBAL_C_PLUGINS_PATH\\\"\"" AM_CFLAGS="$AM_CFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\" -DICONS_PATH=\"\\\"$ICONS_PATH\\\"\" -DGLOBAL_PYTHON_PLUGINS_PATH=\"\\\"$GLOBAL_PYTHON_PLUGINS_PATH\\\"\" -DGLOBAL_C_PLUGINS_PATH=\"\\\"$GLOBAL_C_PLUGINS_PATH\\\"\""
LIBS="$glib_LIBS $gio_LIBS $PTHREAD_LIBS $curl_LIBS $libnotify_LIBS $PYTHON_LIBS $PYTHON_EXTRA_LIBS $PYTHON_LDFLAGS ${GTK_LIBS} ${SQLITE_LIBS} $LIBS" LIBS="$glib_LIBS $gio_LIBS $PTHREAD_LIBS $curl_LIBS $libnotify_LIBS $python_LIBS ${GTK_LIBS} ${SQLITE_LIBS} $LIBS"
AC_SUBST(AM_LDFLAGS) AC_SUBST(AM_LDFLAGS)
AC_SUBST(AM_CFLAGS) AC_SUBST(AM_CFLAGS)

View File

@ -1575,7 +1575,7 @@ static PyMethodDef apiMethods[] = {
{ NULL, NULL, 0, NULL } { NULL, NULL, 0, NULL }
}; };
#if PY_MAJOR_VERSION >= 3 #ifdef PY_IS_PYTHON3
static struct PyModuleDef profModule = { static struct PyModuleDef profModule = {
PyModuleDef_HEAD_INIT, PyModuleDef_HEAD_INIT,
"prof", "prof",
@ -1588,7 +1588,7 @@ static struct PyModuleDef profModule = {
PyMODINIT_FUNC PyMODINIT_FUNC
python_api_init(void) python_api_init(void)
{ {
#if PY_MAJOR_VERSION >= 3 #ifdef PY_IS_PYTHON3
PyObject* result = PyModule_Create(&profModule); PyObject* result = PyModule_Create(&profModule);
if (!result) { if (!result) {
log_debug("Failed to initialise prof module"); log_debug("Failed to initialise prof module");
@ -1604,7 +1604,7 @@ python_api_init(void)
void void
python_init_prof(void) python_init_prof(void)
{ {
#if PY_MAJOR_VERSION >= 3 #ifdef PY_IS_PYTHON3
PyImport_AppendInittab("prof", python_api_init); PyImport_AppendInittab("prof", python_api_init);
Py_Initialize(); Py_Initialize();
PyEval_InitThreads(); PyEval_InitThreads();
@ -1640,7 +1640,7 @@ python_str_or_unicode_to_string(void* obj)
return NULL; return NULL;
} }
#if PY_MAJOR_VERSION >= 3 #ifdef PY_IS_PYTHON3
if (PyUnicode_Check(pyobj)) { if (PyUnicode_Check(pyobj)) {
PyObject* utf8_str = PyUnicode_AsUTF8String(pyobj); PyObject* utf8_str = PyUnicode_AsUTF8String(pyobj);
char* result = strdup(PyBytes_AS_STRING(utf8_str)); char* result = strdup(PyBytes_AS_STRING(utf8_str));

View File

@ -908,7 +908,7 @@ _handle_string_or_none_result(ProfPlugin* plugin, PyObject* result, char* hook)
_python_undefined_error(plugin, hook, "string, unicode or None"); _python_undefined_error(plugin, hook, "string, unicode or None");
return NULL; return NULL;
} }
#if PY_MAJOR_VERSION >= 3 #ifdef PY_IS_PYTHON3
if (result != Py_None && !PyUnicode_Check(result) && !PyBytes_Check(result)) { if (result != Py_None && !PyUnicode_Check(result) && !PyBytes_Check(result)) {
allow_python_threads(); allow_python_threads();
_python_type_error(plugin, hook, "string, unicode or None"); _python_type_error(plugin, hook, "string, unicode or None");