Skip to content

Commit d698e87

Browse files
authored
Merge pull request #1791 from Explorer09/configure-libunwind
Fix libunwind detection regression & detect libunwind.pc
2 parents bf17a7e + d522808 commit d698e87

File tree

2 files changed

+61
-36
lines changed

2 files changed

+61
-36
lines changed

CRT.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ in the source distribution for its full text.
2929
#include <sys/mman.h>
3030
#endif
3131

32-
#if defined(HAVE_LIBUNWIND) && defined(HAVE_LOCAL_UNWIND)
32+
#if defined(HAVE_LIBUNWIND_H) && defined(HAVE_LOCAL_UNWIND)
3333
# define PRINT_BACKTRACE
3434
# define UNW_LOCAL_ONLY
3535
# include <libunwind.h>
@@ -1346,7 +1346,7 @@ void CRT_setColors(int colorScheme) {
13461346

13471347
#ifdef PRINT_BACKTRACE
13481348
static void print_backtrace(void) {
1349-
#if defined(HAVE_LIBUNWIND) && defined(HAVE_LOCAL_UNWIND)
1349+
#if defined(HAVE_LIBUNWIND_H) && defined(HAVE_LOCAL_UNWIND)
13501350
unw_context_t context;
13511351
unw_getcontext(&context);
13521352

configure.ac

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,25 @@ if test "x$enable_affinity" = xyes; then
896896
fi
897897

898898

899+
dnl HTOP_PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
900+
dnl This macro is a wrapper of PKG_CHECK_MODULES, which checks if
901+
dnl MODULES exist, and then sets VARIABLE-PREFIX_CFLAGS and
902+
dnl VARIABLE-PREFIX_LIBS from pkg-config --cflags and --libs output
903+
dnl respectively, and then runs ACTION-IF-FOUND. If pkg.m4 is absent or
904+
dnl pkg-config MODULES don't exist, this instead runs
905+
dnl ACTION-IF-NOT-FOUND. ACTION-IF-NOT-FOUND defaults to printing an
906+
dnl error message and exiting.
907+
AC_DEFUN([HTOP_PKG_CHECK_MODULES],
908+
[m4_ifdef(
909+
[PKG_PROG_PKG_CONFIG],
910+
[PKG_CHECK_MODULES([$1], [$2], [$3], [$4])],
911+
[m4_default(
912+
[$4],
913+
[AC_MSG_ERROR([pkg.m4 required to check for pkg-config modules '$2'; please regenerate configure script])]
914+
)]
915+
)]
916+
)
917+
899918
# $1: Header file name
900919
# $2: List of directories to search, separated by spaces
901920
# $3: Additional include directives
@@ -944,37 +963,49 @@ case "$enable_unwind" in
944963
no)
945964
;;
946965
check|yes)
947-
if test "$enable_static" = yes; then
948-
AC_CHECK_LIB([lzma], [lzma_index_buffer_decode])
949-
fi
950-
951-
AC_CHECK_LIB(
952-
[unwind],
953-
[unw_init_local],
966+
HTOP_PKG_CHECK_MODULES(LIBUNWIND, libunwind,
954967
[],
955968
[
956-
if test "$enable_unwind" = yes; then
957-
AC_MSG_ERROR([can not find required library libunwind])
969+
if test "$enable_static" = yes; then
970+
AC_CHECK_LIB([lzma], [lzma_index_buffer_decode])
958971
fi
959-
enable_unwind=no
972+
: "${LIBUNWIND_LIBS='-lunwind'}"
960973
]
961974
)
975+
976+
htop_save_CFLAGS=$CFLAGS
977+
CFLAGS="$AM_CFLAGS $LIBUNWIND_CFLAGS $CFLAGS"
978+
979+
if htop_search_header_dir libunwind.h "/usr/include/libunwind"; then
980+
AC_DEFINE([HAVE_LIBUNWIND_H], 1, [Define to 1 if you have the <libunwind.h> header file.])
981+
elif test "$enable_unwind" = yes; then
982+
AC_MSG_ERROR([can not find required header file libunwind.h])
983+
else
984+
enable_unwind=no
985+
fi
986+
987+
CFLAGS=$htop_save_CFLAGS
962988
;;
963989
*)
964990
AC_MSG_ERROR([bad value '$enable_unwind' for --enable-unwind])
965991
;;
966992
esac
967993

968-
if test "$enable_unwind" = no; then
969-
:
970-
elif htop_search_header_dir libunwind.h "/usr/include/libunwind"; then
994+
if test "$enable_unwind" != no; then
971995
htop_save_CPPFLAGS=$CPPFLAGS
996+
htop_save_CFLAGS=$CFLAGS
997+
htop_save_LIBS=$LIBS
972998
CPPFLAGS="$AM_CPPFLAGS $CPPFLAGS"
999+
CFLAGS="$AM_CFLAGS $LIBUNWIND_CFLAGS $CFLAGS"
1000+
LIBS="$LIBUNWIND_LIBS $LIBS"
9731001

974-
AC_MSG_CHECKING([whether local unwinding works])
1002+
# unw_init_local() is a macro in HP's implemention of libunwind
1003+
# (the most popular one, Mosberger et al.)
1004+
AC_MSG_CHECKING([whether $LIBUNWIND_LIBS supports local unwinding])
9751005
AC_LINK_IFELSE(
9761006
[AC_LANG_PROGRAM(
9771007
[[
1008+
#define UNW_LOCAL_ONLY
9781009
#include <libunwind.h>
9791010
]], [[
9801011
/* If libunwind is built with remote unwinding only,
@@ -1013,24 +1044,28 @@ elif htop_search_header_dir libunwind.h "/usr/include/libunwind"; then
10131044
if test "$enable_unwind" = yes; then
10141045
AC_MSG_WARN([this build of libunwind might not support local unwinding])
10151046
else
1047+
LIBS=$htop_save_LIBS
10161048
enable_unwind=no
10171049
fi
10181050
fi
10191051
],
10201052
[
10211053
AC_MSG_RESULT([no])
1022-
AC_MSG_FAILURE([there are problems with libunwind.h])
1054+
if test "$enable_unwind" = yes; then
1055+
AC_MSG_FAILURE([can not link with libunwind])
1056+
else
1057+
LIBS=$htop_save_LIBS
1058+
enable_unwind=no
1059+
fi
10231060
]
10241061
)
10251062

10261063
CPPFLAGS=$htop_save_CPPFLAGS
1027-
elif test "$enable_unwind" = yes; then
1028-
AC_MSG_ERROR([can not find required header file libunwind.h])
1029-
else
1030-
enable_unwind=no
1064+
CFLAGS=$htop_save_CFLAGS
10311065
fi
10321066

10331067
if test "$enable_unwind" != no; then
1068+
AM_CFLAGS="$AM_CFLAGS $LIBUNWIND_CFLAGS"
10341069
enable_unwind=yes
10351070
AC_DEFINE([HAVE_LOCAL_UNWIND], 1, [Define to 1 if local unwinding is enabled.])
10361071
else
@@ -1113,17 +1148,11 @@ case "$enable_hwloc" in
11131148
no)
11141149
;;
11151150
yes)
1116-
m4_ifdef(
1117-
[PKG_PROG_PKG_CONFIG],
1151+
HTOP_PKG_CHECK_MODULES(HWLOC, hwloc,
11181152
[
1119-
PKG_CHECK_MODULES(HWLOC, hwloc, [
1120-
AM_CFLAGS="$AM_CFLAGS $HWLOC_CFLAGS"
1121-
LIBS="$LIBS $HWLOC_LIBS"
1122-
AC_DEFINE([HAVE_LIBHWLOC], [1], [Define to 1 if you have the 'hwloc' library (-lhwloc).])
1123-
], [
1124-
AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [AC_MSG_ERROR([can not find required library libhwloc])])
1125-
AC_CHECK_HEADERS([hwloc.h], [], [AC_MSG_ERROR([can not find require header file hwloc.h])])
1126-
])
1153+
AM_CFLAGS="$AM_CFLAGS $HWLOC_CFLAGS"
1154+
LIBS="$LIBS $HWLOC_LIBS"
1155+
AC_DEFINE([HAVE_LIBHWLOC], [1], [Define to 1 if you have the 'hwloc' library (-lhwloc).])
11271156
], [
11281157
AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [AC_MSG_ERROR([can not find required library libhwloc])])
11291158
AC_CHECK_HEADERS([hwloc.h], [], [AC_MSG_ERROR([can not find require header file hwloc.h])])
@@ -1318,11 +1347,7 @@ esac
13181347
case "$enable_delayacct" in
13191348
check|yes)
13201349
if test "x${LIBNL3_CFLAGS+y}" = x; then
1321-
m4_ifdef(
1322-
[PKG_PROG_PKG_CONFIG],
1323-
[PKG_CHECK_MODULES(LIBNL3, libnl-3.0, [], [LIBNL3_CFLAGS="-I/usr/include/libnl3"])],
1324-
[LIBNL3_CFLAGS="-I/usr/include/libnl3"]
1325-
)
1350+
HTOP_PKG_CHECK_MODULES(LIBNL3, libnl-3.0, [], [LIBNL3_CFLAGS="-I/usr/include/libnl3"])
13261351
fi
13271352

13281353
htop_save_CFLAGS=$CFLAGS

0 commit comments

Comments
 (0)