@@ -1015,39 +1015,101 @@ case "$enable_capabilities" in
10151015esac
10161016
10171017
1018+ # $1: libnl-3 search path
1019+ htop_try_link_libnl3 () {
1020+ htop_save_LDFLAGS=$LDFLAGS
1021+ htop_save_LIBS=$LIBS
1022+
1023+ LIBS="-lnl-3 $LIBS"
1024+ if test "x$1" != x; then
1025+ # New library path searched after what user has specified
1026+ LDFLAGS="$LDFLAGS -L$1"
1027+ fi
1028+ AC_LINK_IFELSE ( [ AC_LANG_PROGRAM ( [ [
1029+ /* struct nl_sock* nl_socket_alloc(void); */
1030+ void* nl_socket_alloc(void);
1031+ ] ] , [ [
1032+ void* sock = nl_socket_alloc();
1033+ ] ] ) ] ,
1034+ [ htop_libnl3_link_succeed=yes] ,
1035+ [ htop_libnl3_link_succeed=no] )
1036+
1037+ LDFLAGS=$htop_save_LDFLAGS
1038+ LIBS=$htop_save_LIBS
1039+ } # htop_try_link_libnl3
1040+
10181041AC_ARG_ENABLE ( [ delayacct] ,
10191042 [ AS_HELP_STRING ( [ --enable-delayacct] ,
1020- [ enable Linux delay accounting support; requires pkg-config, libnl-3 and libnl-genl-3 @<:@ default=check@:>@ ] ) ] ,
1043+ [ enable Linux delay accounting support; requires libnl-3 and libnl-genl-3 @<:@ default=check@:>@ ] ) ] ,
10211044 [ ] ,
10221045 [ enable_delayacct=check] )
10231046case "$enable_delayacct" in
1024- no)
1047+ no|yes )
10251048 ;;
10261049 check)
10271050 if test "$my_htop_platform" != linux; then
10281051 enable_delayacct=no
10291052 elif test "$enable_static" = yes; then
10301053 enable_delayacct=no
1031- else
1032- old_CFLAGS="$CFLAGS"
1033- CFLAGS="$CFLAGS -I/usr/include/libnl3"
1034- AC_CHECK_HEADERS ( [ netlink/attr.h netlink/handlers.h netlink/msg.h] , [ enable_delayacct=yes] , [ enable_delayacct=no] )
1035- CFLAGS="$old_CFLAGS"
10361054 fi
10371055 ;;
1038- yes)
1039- old_CFLAGS="$CFLAGS"
1040- CFLAGS="$CFLAGS -I/usr/include/libnl3"
1041- AC_CHECK_HEADERS ( [ netlink/attr.h netlink/handlers.h netlink/msg.h] , [ ] , [ AC_MSG_ERROR ( [ can not find required header files netlink/attr.h, netlink/handlers.h, netlink/msg.h] ) ] )
1042- CFLAGS="$old_CFLAGS"
1043- ;;
10441056 *)
10451057 AC_MSG_ERROR ( [ bad value '$enable_delayacct' for --enable-delayacct] )
10461058 ;;
10471059esac
1060+
1061+ case "$enable_delayacct" in
1062+ check|yes)
1063+ if test "x${LIBNL3_CFLAGS+y}" = x; then
1064+ m4_ifdef ( [ PKG_PROG_PKG_CONFIG] , [
1065+ PKG_CHECK_MODULES(LIBNL3, libnl-3.0, [ ] , [ LIBNL3_CFLAGS="-I/usr/include/libnl3"] )
1066+ ] , [
1067+ LIBNL3_CFLAGS="-I/usr/include/libnl3"
1068+ ] )
1069+ fi
1070+
1071+ htop_save_CFLAGS=$CFLAGS
1072+ # New include path searched after what user has specified
1073+ CFLAGS="$CFLAGS $LIBNL3_CFLAGS"
1074+ AC_CHECK_HEADERS ( [ netlink/attr.h netlink/handlers.h netlink/msg.h] ,
1075+ [ ] ,
1076+ [ if test "$enable_delayacct" = yes; then
1077+ AC_MSG_ERROR ( [ can not find required header files netlink/attr.h, netlink/handlers.h, netlink/msg.h] )
1078+ fi
1079+ enable_delayacct=no] )
1080+ CFLAGS=$htop_save_CFLAGS
1081+
1082+ if test "$enable_delayacct" != no; then
1083+ AC_MSG_CHECKING ( [ the search path of libnl-3] )
1084+
1085+ htop_libnl3_link_succeed=no
1086+ htop_try_link_libnl3 "$LIBNL3_LIBDIR"
1087+ if test "$htop_libnl3_link_succeed${LIBNL3_LIBDIR+y}" = no && test "x$PKG_CONFIG" != x; then
1088+ LIBNL3_LIBDIR=`$PKG_CONFIG --variable=libdir libnl-3.0 2>/dev/null`
1089+ if test "x$LIBNL3_LIBDIR" != x; then
1090+ htop_try_link_libnl3 "$LIBNL3_LIBDIR"
1091+ fi
1092+ fi
1093+
1094+ if test "x$LIBNL3_LIBDIR" = x; then
1095+ AC_MSG_RESULT ( [ (default)] )
1096+ else
1097+ # The path must end with a slash
1098+ LIBNL3_LIBDIR=`echo "x$LIBNL3_LIBDIR" | sed 's/^x//; s|/*$|/|'`
1099+ AC_MSG_RESULT ( [ $LIBNL3_LIBDIR] )
1100+ fi
1101+ AC_DEFINE_UNQUOTED ( [ LIBNL3_LIBDIR] , [ "$LIBNL3_LIBDIR"] , [ libnl-3 search path; use the default search paths if empty] )
1102+ if test "$htop_libnl3_link_succeed" = no; then
1103+ AC_MSG_WARN ( [ libnl-3 binary currently not present; will be needed in htop runtime for delay accounting support] )
1104+ fi
1105+
1106+ enable_delayacct=yes
1107+ fi
1108+ ;;
1109+ esac
10481110if test "$enable_delayacct" = yes; then
10491111 AC_DEFINE ( [ HAVE_DELAYACCT] , [ 1] , [ Define if delay accounting support should be enabled.] )
1050- AM_CFLAGS="$AM_CFLAGS -I/usr/include/libnl3 "
1112+ AM_CFLAGS="$AM_CFLAGS $LIBNL3_CFLAGS "
10511113fi
10521114AM_CONDITIONAL([ HAVE_DELAYACCT] , [ test "$enable_delayacct" = yes] )
10531115
0 commit comments