@@ -182,14 +182,14 @@ m4_version_prereq(
182182 [ AC_HEADER_STDC ]
183183)
184184AC_CHECK_HEADERS (
185- [
186- stdlib.h
187- string.h
188- strings.h
189- sys/param.h
190- sys/time.h
191- sys/utsname.h
192- unistd.h
185+ [ \
186+ stdlib.h \
187+ string.h \
188+ strings.h \
189+ sys/param.h \
190+ sys/time.h \
191+ sys/utsname.h \
192+ unistd.h \
193193 ] ,
194194 [ ] ,
195195 [ AC_MSG_ERROR ( [ can not find required generic header files] ) ]
402402
403403AC_SEARCH_LIBS ( [ clock_gettime] , [ rt] )
404404
405- AC_CHECK_FUNCS ( [
406- clock_gettime
407- dladdr
408- faccessat
409- fstatat
410- host_get_clock_service
411- memfd_create
412- openat
413- readlinkat
414- sched_getscheduler
415- sched_setscheduler
416- strnlen
405+ AC_CHECK_FUNCS ( [ \
406+ clock_gettime \
407+ dladdr \
408+ faccessat \
409+ fstatat \
410+ host_get_clock_service \
411+ memfd_create \
412+ openat \
413+ readlinkat \
414+ sched_getscheduler \
415+ sched_setscheduler \
416+ strnlen \
417417] )
418418
419419# strchrnul is available in macOS since 15.4, but the user may specify an older
@@ -780,27 +780,58 @@ esac
780780htop_save_CFLAGS=$CFLAGS
781781CFLAGS="$AM_CFLAGS $CFLAGS"
782782
783+ have_curses_header=no
784+ have_term_header=no
785+
783786if test "x$enable_unicode" = xyes; then
784- AC_CHECK_HEADERS ( [ ncursesw/curses.h] , [ ] ,
785- [ AC_CHECK_HEADERS ( [ ncurses/ncurses.h] , [ ] ,
786- [ AC_CHECK_HEADERS ( [ ncurses/curses.h] , [ ] ,
787- [ AC_CHECK_HEADERS ( [ ncurses.h] , [ ] ,
788- [ AC_MSG_ERROR ( [ can not find required ncurses header file] ) ] ) ] ) ] ) ] )
789-
790- AC_CHECK_HEADERS ( [ ncursesw/term.h] , [ ] ,
791- [ AC_CHECK_HEADERS ( [ ncurses/term.h] , [ ] ,
792- [ AC_CHECK_HEADERS ( [ term.h] , [ ] ,
793- [ AC_MSG_ERROR ( [ can not find required term header file] ) ] ) ] ) ] )
787+ AC_CHECK_HEADERS (
788+ [ \
789+ ncursesw/curses.h \
790+ ncurses/ncurses.h \
791+ ncurses/curses.h \
792+ ncurses.h \
793+ ] , [
794+ have_curses_header=yes
795+ break
796+ ]
797+ )
798+ AC_CHECK_HEADERS (
799+ [ \
800+ ncursesw/term.h \
801+ ncurses/term.h \
802+ term.h \
803+ ] , [
804+ have_term_header=yes
805+ break
806+ ]
807+ )
794808else
795- AC_CHECK_HEADERS ( [ curses.h] , [ ] ,
796- [ AC_CHECK_HEADERS ( [ ncurses/curses.h] , [ ] ,
797- [ AC_CHECK_HEADERS ( [ ncurses/ncurses.h] , [ ] ,
798- [ AC_CHECK_HEADERS ( [ ncurses.h] , [ ] ,
799- [ AC_MSG_ERROR ( [ can not find required ncurses header file] ) ] ) ] ) ] ) ] )
800-
801- AC_CHECK_HEADERS ( [ ncurses/term.h] , [ ] ,
802- [ AC_CHECK_HEADERS ( [ term.h] , [ ] ,
803- [ AC_MSG_ERROR ( [ can not find required term header file] ) ] ) ] )
809+ AC_CHECK_HEADERS (
810+ [ \
811+ curses.h \
812+ ncurses/curses.h \
813+ ncurses/ncurses.h \
814+ ncurses.h \
815+ ] , [
816+ have_curses_header=yes
817+ break
818+ ]
819+ )
820+ AC_CHECK_HEADERS (
821+ [ \
822+ ncurses/term.h \
823+ term.h \
824+ ] , [
825+ have_term_header=yes
826+ break
827+ ]
828+ )
829+ fi
830+
831+ if test "$have_curses_header" = no; then
832+ AC_MSG_ERROR ( [ can not find required curses header file] )
833+ elif test "$have_term_header" = no; then
834+ AC_MSG_ERROR ( [ can not find required term header file] )
804835fi
805836
806837CFLAGS="-I$srcdir $CFLAGS"
@@ -896,6 +927,25 @@ if test "x$enable_affinity" = xyes; then
896927fi
897928
898929
930+ dnl HTOP_PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
931+ dnl This macro is a wrapper of PKG_CHECK_MODULES, which checks if
932+ dnl MODULES exist, and then sets VARIABLE-PREFIX_CFLAGS and
933+ dnl VARIABLE-PREFIX_LIBS from pkg-config --cflags and --libs output
934+ dnl respectively, and then runs ACTION-IF-FOUND. If pkg.m4 is absent or
935+ dnl pkg-config MODULES don't exist, this instead runs
936+ dnl ACTION-IF-NOT-FOUND. ACTION-IF-NOT-FOUND defaults to printing an
937+ dnl error message and exiting.
938+ AC_DEFUN ( [ HTOP_PKG_CHECK_MODULES] ,
939+ [ m4_ifdef (
940+ [ PKG_PROG_PKG_CONFIG] ,
941+ [ PKG_CHECK_MODULES([ $1 ] , [ $2 ] , [ $3 ] , [ $4 ] )] ,
942+ [ m4_default (
943+ [ $4 ] ,
944+ [ AC_MSG_ERROR ( [ pkg.m4 required to check for pkg-config modules '$2 '; please regenerate configure script] ) ]
945+ ) ]
946+ ) ]
947+ )
948+
899949# $1: Header file name
900950# $2: List of directories to search, separated by spaces
901951# $3: Additional include directives
@@ -944,37 +994,49 @@ case "$enable_unwind" in
944994 no)
945995 ;;
946996 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] ,
997+ HTOP_PKG_CHECK_MODULES(LIBUNWIND, libunwind,
954998 [ ] ,
955999 [
956- if test "$enable_unwind " = yes; then
957- AC_MSG_ERROR ( [ can not find required library libunwind ] )
1000+ if test "$enable_static " = yes; then
1001+ AC_CHECK_LIB ( [ lzma ] , [ lzma_index_buffer_decode ] )
9581002 fi
959- enable_unwind=no
1003+ : "${LIBUNWIND_LIBS='-lunwind'}"
9601004 ]
9611005 )
1006+
1007+ htop_save_CFLAGS=$CFLAGS
1008+ CFLAGS="$AM_CFLAGS $LIBUNWIND_CFLAGS $CFLAGS"
1009+
1010+ if htop_search_header_dir libunwind.h "/usr/include/libunwind"; then
1011+ AC_DEFINE ( [ HAVE_LIBUNWIND_H] , 1 , [ Define to 1 if you have the <libunwind.h> header file.] )
1012+ elif test "$enable_unwind" = yes; then
1013+ AC_MSG_ERROR ( [ can not find required header file libunwind.h] )
1014+ else
1015+ enable_unwind=no
1016+ fi
1017+
1018+ CFLAGS=$htop_save_CFLAGS
9621019 ;;
9631020 *)
9641021 AC_MSG_ERROR ( [ bad value '$enable_unwind' for --enable-unwind] )
9651022 ;;
9661023esac
9671024
968- if test "$enable_unwind" = no; then
969- :
970- elif htop_search_header_dir libunwind.h "/usr/include/libunwind"; then
1025+ if test "$enable_unwind" != no; then
9711026 htop_save_CPPFLAGS=$CPPFLAGS
1027+ htop_save_CFLAGS=$CFLAGS
1028+ htop_save_LIBS=$LIBS
9721029 CPPFLAGS="$AM_CPPFLAGS $CPPFLAGS"
1030+ CFLAGS="$AM_CFLAGS $LIBUNWIND_CFLAGS $CFLAGS"
1031+ LIBS="$LIBUNWIND_LIBS $LIBS"
9731032
974- AC_MSG_CHECKING ( [ whether local unwinding works] )
1033+ # unw_init_local() is a macro in HP's implemention of libunwind
1034+ # (the most popular one, Mosberger et al.)
1035+ AC_MSG_CHECKING ( [ whether $LIBUNWIND_LIBS supports local unwinding] )
9751036 AC_LINK_IFELSE (
9761037 [ AC_LANG_PROGRAM (
9771038 [ [
1039+ #define UNW_LOCAL_ONLY
9781040#include <libunwind.h>
9791041 ] ] , [ [
9801042 /* If libunwind is built with remote unwinding only,
@@ -1013,24 +1075,28 @@ elif htop_search_header_dir libunwind.h "/usr/include/libunwind"; then
10131075 if test "$enable_unwind" = yes; then
10141076 AC_MSG_WARN ( [ this build of libunwind might not support local unwinding] )
10151077 else
1078+ LIBS=$htop_save_LIBS
10161079 enable_unwind=no
10171080 fi
10181081 fi
10191082 ] ,
10201083 [
10211084 AC_MSG_RESULT ( [ no] )
1022- AC_MSG_FAILURE ( [ there are problems with libunwind.h] )
1085+ if test "$enable_unwind" = yes; then
1086+ AC_MSG_FAILURE ( [ can not link with libunwind] )
1087+ else
1088+ LIBS=$htop_save_LIBS
1089+ enable_unwind=no
1090+ fi
10231091 ]
10241092 )
10251093
10261094 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
1095+ CFLAGS=$htop_save_CFLAGS
10311096fi
10321097
10331098if test "$enable_unwind" != no; then
1099+ AM_CFLAGS="$AM_CFLAGS $LIBUNWIND_CFLAGS"
10341100 enable_unwind=yes
10351101 AC_DEFINE ( [ HAVE_LOCAL_UNWIND] , 1 , [ Define to 1 if local unwinding is enabled.] )
10361102else
@@ -1113,17 +1179,11 @@ case "$enable_hwloc" in
11131179 no)
11141180 ;;
11151181 yes)
1116- m4_ifdef (
1117- [ PKG_PROG_PKG_CONFIG] ,
1182+ HTOP_PKG_CHECK_MODULES(HWLOC, hwloc,
11181183 [
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- ] )
1184+ AM_CFLAGS="$AM_CFLAGS $HWLOC_CFLAGS"
1185+ LIBS="$LIBS $HWLOC_LIBS"
1186+ AC_DEFINE ( [ HAVE_LIBHWLOC] , [ 1] , [ Define to 1 if you have the 'hwloc' library (-lhwloc).] )
11271187 ] , [
11281188 AC_CHECK_LIB ( [ hwloc] , [ hwloc_get_proc_cpubind] , [ ] , [ AC_MSG_ERROR ( [ can not find required library libhwloc] ) ] )
11291189 AC_CHECK_HEADERS ( [ hwloc.h] , [ ] , [ AC_MSG_ERROR ( [ can not find require header file hwloc.h] ) ] )
@@ -1318,11 +1378,7 @@ esac
13181378case "$enable_delayacct" in
13191379 check|yes)
13201380 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- )
1381+ HTOP_PKG_CHECK_MODULES(LIBNL3, libnl-3.0, [ ] , [ LIBNL3_CFLAGS="-I/usr/include/libnl3"] )
13261382 fi
13271383
13281384 htop_save_CFLAGS=$CFLAGS
0 commit comments