From 0193600e486759f4b0524b520e9128c2a3d19cbd Mon Sep 17 00:00:00 2001 From: Jean Guyomarc'h Date: Sat, 28 May 2016 13:07:22 +0200 Subject: [PATCH] autotools: improve libunwind detection Libuwind may not be shipped with a pkg-config file. It can be distributed on the system, but the autotools would fail to detect it because it relied only on pkg-config. We now first check with pkg-config, and then try to compile and link a program using libuwind to see if it is supported anyway. This is a first step towards a working eina_log_backtrace on Mac OS X. --- configure.ac | 6 +---- m4/efl_libunwind.m4 | 61 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 m4/efl_libunwind.m4 diff --git a/configure.ac b/configure.ac index 40a2edffac..9fd46ba9a9 100644 --- a/configure.ac +++ b/configure.ac @@ -865,11 +865,7 @@ case "${build_profile}" in ;; esac -PKG_CHECK_MODULES(UNWIND, [libunwind libunwind-generic], - [have_unwind=yes], [have_unwind=no]) -AS_IF([test "x$have_unwind" = "xyes"], - [AC_DEFINE([HAVE_UNWIND], [1], [Have libunwind])]) -AM_CONDITIONAL(HAVE_UNWIND, test "x$have_unwind" = "xyes") +EFL_CHECK_LIBUNWIND EINA_CONFIG([HAVE_ALLOCA_H], [test "x${ac_cv_working_alloca_h}" = "xyes"]) EINA_CONFIG([SAFETY_CHECKS], [test "x${have_safety_checks}" = "xyes"]) diff --git a/m4/efl_libunwind.m4 b/m4/efl_libunwind.m4 new file mode 100644 index 0000000000..e9ca682cfb --- /dev/null +++ b/m4/efl_libunwind.m4 @@ -0,0 +1,61 @@ +dnl This code is public domain and can be freely used or copied. +dnl File to auto-detect libunwind + +dnl Macro that checks for libunwind, first by using +dnl pkg-config, then by trying to compile and link a simple +dnl program, to see if libunwind is distributed on the system +dnl but has no pkg-config support +dnl +dnl The biggest usecase is on Mac OS X, where there are no +dnl pkg-config files, and the libunwind headers are lost +dnl in an obscure place on the system (but whom the compilers +dnl distributed by Apple are aware of). +dnl +dnl Usage: EFL_CHECK_LIBUNWIND +dnl will inconditionaly set UNWIND_CFLAGS and UNWIND_LIBS +dnl to follow pkg-config fashion. +dnl +AC_DEFUN([EFL_CHECK_LIBUNWIND], +[dnl + dnl First, check with pkg-config + PKG_CHECK_MODULES([UNWIND], [libunwind libunwind-generic], + [have_unwind=yes], [have_unwind=no]) + + dnl No pkg-config file... maybe system built-in? + if test "x${have_unwind}" = "xno"; then + AC_LANG_PUSH([C]) + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include + ]], + [[ + unw_context_t ctx; + unw_getcontext(&ctx); + ]] + )], + [ + have_unwind="yes" + ], + [ + have_unwind="no" + ] + ) + AC_MSG_CHECKING([for native libunwind]) + AC_MSG_RESULT([${have_unwind}]) + AC_LANG_POP([C]) + + dnl Provide dummy variables to automake. + dnl In case pkg-config succeeded, these will be set and + dnl used in other automake files. To avoid, problems, + dnl we define empty variables. + UNWIND_CFLAGS="" + UNWIND_LIBS="" + AC_SUBST([UNWIND_CFLAGS]) + AC_SUBST([UNWIND_LIBS]) + fi + + AS_IF([test "x$have_unwind" = "xyes"], + [AC_DEFINE([HAVE_UNWIND], [1], [Have libunwind])]) + AM_CONDITIONAL(HAVE_UNWIND, test "x$have_unwind" = "xyes") +])