blob: 9f2f46b3767294a18e79b04f56ac49c67c0fa133 [file] [log] [blame]
Hisham Muhammadd6231ba2006-03-04 18:16:49 +00001# -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3
Christian Göttschef3623b72021-01-22 19:14:50 +01004# ----------------------------------------------------------------------
Daniel Lange2acd62d2024-04-16 17:44:32 +02005# Build version string.
6# ----------------------------------------------------------------------
7
8m4_define([htop_git_version],
9 m4_normalize(m4_esyscmd([git describe --abbrev=7 --dirty --always --tags 2> /dev/null || echo ''])))
Nathan Scott348c0a62025-04-11 12:00:29 +100010m4_define([htop_release_version], [3.4.1])
Daniel Lange2acd62d2024-04-16 17:44:32 +020011
12# ----------------------------------------------------------------------
Christian Göttschef3623b72021-01-22 19:14:50 +010013# Autoconf initialization.
14# ----------------------------------------------------------------------
15
Christian Göttsche38b6a012021-01-22 19:14:53 +010016AC_PREREQ([2.69])
Daniel Lange2acd62d2024-04-16 17:44:32 +020017AC_INIT([htop], [m4_join([-],m4_defn([htop_release_version]),m4_defn([htop_git_version]))], [htop@groups.io], [], [https://htop.dev/])
Hisham Muhammad3383d8e2015-01-21 23:27:31 -020018
Explorer09b71b07f2016-03-12 12:02:06 +080019AC_CONFIG_SRCDIR([htop.c])
Christian Göttsche38b6a012021-01-22 19:14:53 +010020AC_CONFIG_AUX_DIR([build-aux])
Explorer09b71b07f2016-03-12 12:02:06 +080021AC_CONFIG_HEADERS([config.h])
Explorer09b71b07f2016-03-12 12:02:06 +080022
Sam James939685d2022-01-22 03:54:42 +000023AC_CANONICAL_HOST
Christian Göttsche38b6a012021-01-22 19:14:53 +010024AM_INIT_AUTOMAKE([-Wall std-options subdir-objects])
Hisham Muhammadd6231ba2006-03-04 18:16:49 +000025
Hisham Muhammad300af4b2014-11-19 23:17:16 -020026# ----------------------------------------------------------------------
Christian Göttschef3623b72021-01-22 19:14:50 +010027
28
29# ----------------------------------------------------------------------
30# Checks for platform.
31# ----------------------------------------------------------------------
32
Sam James939685d2022-01-22 03:54:42 +000033case "$host_os" in
Christian Göttschef3623b72021-01-22 19:14:50 +010034linux*|gnu*)
35 my_htop_platform=linux
36 AC_DEFINE([HTOP_LINUX], [], [Building for Linux.])
37 ;;
38freebsd*|kfreebsd*)
39 my_htop_platform=freebsd
40 AC_DEFINE([HTOP_FREEBSD], [], [Building for FreeBSD.])
41 ;;
fraggerfox4b49de42021-03-15 13:14:39 +053042netbsd*)
43 my_htop_platform=netbsd
44 AC_DEFINE([HTOP_NETBSD], [], [Building for NetBSD.])
45 ;;
Christian Göttschef3623b72021-01-22 19:14:50 +010046openbsd*)
47 my_htop_platform=openbsd
48 AC_DEFINE([HTOP_OPENBSD], [], [Building for OpenBSD.])
49 ;;
50dragonfly*)
51 my_htop_platform=dragonflybsd
52 AC_DEFINE([HTOP_DRAGONFLYBSD], [], [Building for DragonFlyBSD.])
53 ;;
54darwin*)
55 my_htop_platform=darwin
56 AC_DEFINE([HTOP_DARWIN], [], [Building for Darwin.])
57 ;;
58solaris*)
59 my_htop_platform=solaris
60 AC_DEFINE([HTOP_SOLARIS], [], [Building for Solaris.])
61 ;;
62*)
63 my_htop_platform=unsupported
64 AC_DEFINE([HTOP_UNSUPPORTED], [], [Building for an unsupported platform.])
65 ;;
66esac
Hisham Muhammad4df76d12008-03-05 09:46:47 +000067
Christian Göttsche38b6a012021-01-22 19:14:53 +010068# Enable extensions, required by hwloc scripts
Explorer09b71b07f2016-03-12 12:02:06 +080069AC_USE_SYSTEM_EXTENSIONS
70
Explorer09de938472024-10-29 07:59:19 +080071# The header of ncurses exposes wide-character interfaces only if
72# _XOPEN_SOURCE_EXTENDED is defined or _XOPEN_SOURCE defined to be
73# >= 500. In DragonFly BSD, FreeBSD and OpenBSD, defining
74# _XOPEN_SOURCE to any value *hides* interfaces that would be useful
75# for htop.
76dnl
77dnl Note: The "#undef" in AH_VERBATIM will be replaced with "#define"
78dnl when config.h is generated.
79AH_VERBATIM([_XOPEN_SOURCE_EXTENDED],
80[/* Enables XPG4v2 (SUSv1) interfaces if they are not enabled already with _XOPEN_SOURCE */
81#ifndef _XOPEN_SOURCE_EXTENDED
82#undef _XOPEN_SOURCE_EXTENDED
83#endif
84])
85AC_DEFINE([_XOPEN_SOURCE_EXTENDED], 1)
86
Benny Baumanna98fc472023-11-29 20:39:25 +010087# Activate some more of the missing global defines
88AC_SYS_LARGEFILE
89
Hisham Muhammadeb229d92014-11-24 18:55:03 -020090# ----------------------------------------------------------------------
Hisham Muhammadeb229d92014-11-24 18:55:03 -020091
Christian Göttschef3623b72021-01-22 19:14:50 +010092
Hisham Muhammad300af4b2014-11-19 23:17:16 -020093# ----------------------------------------------------------------------
Christian Göttschef3623b72021-01-22 19:14:50 +010094# Checks for compiler.
Hisham Muhammad300af4b2014-11-19 23:17:16 -020095# ----------------------------------------------------------------------
Hisham Muhammade46f1422006-07-12 01:15:14 +000096
Christian Göttschef3623b72021-01-22 19:14:50 +010097AC_PROG_CC
98AM_PROG_CC_C_O
Christian Göttschea5e2eff2021-08-25 10:23:30 +020099m4_version_prereq([2.70], [], [AC_PROG_CC_C99])
Christian Göttsche38b6a012021-01-22 19:14:53 +0100100AS_IF([test "x$ac_cv_prog_cc_c99" = xno], [AC_MSG_ERROR([htop is written in C99. A newer compiler is required.])])
Benny Baumann5c7cb912023-11-28 17:42:04 +0100101AM_CFLAGS="-std=c99 -pedantic"
Hisham Muhammadd6231ba2006-03-04 18:16:49 +0000102
Christian Göttschef3623b72021-01-22 19:14:50 +0100103# ----------------------------------------------------------------------
104
105
106# ----------------------------------------------------------------------
Christian Göttsche575edff2021-01-22 19:14:59 +0100107# Checks for static build.
108# ----------------------------------------------------------------------
109
110AC_ARG_ENABLE([static],
111 [AS_HELP_STRING([--enable-static],
112 [build a static htop binary @<:@default=no@:>@])],
113 [],
114 [enable_static=no])
115case "$enable_static" in
116 no)
117 ;;
118 yes)
119 AC_DEFINE([BUILD_STATIC], [1], [Define if building static binary.])
120 CFLAGS="$CFLAGS -static"
121 LDFLAGS="$LDFLAGS -static"
122 ;;
123 *)
124 AC_MSG_ERROR([bad value '$enable_static' for --enable-static option])
125 ;;
126esac
127
128# ----------------------------------------------------------------------
129
Nathan Scottc14a45b2021-02-17 14:43:56 +1100130# ----------------------------------------------------------------------
131# Checks for a PCP-based htop build. (https://pcp.io)
132# ----------------------------------------------------------------------
133
134AC_ARG_ENABLE([pcp],
135 [AS_HELP_STRING([--enable-pcp],
Nathan Scott9ce95572021-04-14 11:34:47 +1000136 [build a pcp-htop binary @<:@default=no@:>@])],
Nathan Scottc14a45b2021-02-17 14:43:56 +1100137 [],
138 [enable_pcp=no])
139case "$enable_pcp" in
140 no)
141 ;;
142 yes)
143 AC_CHECK_HEADERS([pcp/pmapi.h], [my_htop_platform=pcp],
Benny Baumann92324d32021-06-13 19:46:13 +0200144 [AC_MSG_ERROR([can not find PCP header file])])
Nathan Scott94d37982021-06-08 09:46:02 +1000145 AC_SEARCH_LIBS([pmNewContext], [pcp], [], [AC_MSG_ERROR([can not find PCP library])])
146 AC_DEFINE([HTOP_PCP], [1], [Define if building pcp-htop binary.])
Daniel Langefc2377f2021-08-14 10:35:11 +0200147 AC_CONFIG_FILES([pcp-htop.5])
Nathan Scottc14a45b2021-02-17 14:43:56 +1100148 ;;
149 *)
Nathan Scott6bb59f82021-02-19 14:13:27 +1100150 AC_MSG_ERROR([bad value '$enable_pcp' for --enable-pcp option])
Nathan Scottc14a45b2021-02-17 14:43:56 +1100151 ;;
152esac
153
154# ----------------------------------------------------------------------
155
Christian Göttsche575edff2021-01-22 19:14:59 +0100156
157# ----------------------------------------------------------------------
Christian Göttschef3623b72021-01-22 19:14:50 +0100158# Checks for generic header files.
159# ----------------------------------------------------------------------
160
161AC_HEADER_DIRENT
Christian Göttschea5e2eff2021-08-25 10:23:30 +0200162m4_version_prereq([2.70], [AC_CHECK_INCLUDES_DEFAULT], [AC_HEADER_STDC])
Christian Göttschef3623b72021-01-22 19:14:50 +0100163AC_CHECK_HEADERS([ \
164 stdlib.h \
165 string.h \
166 strings.h \
167 sys/param.h \
168 sys/time.h \
Nathan Scott5b50ae32021-03-02 15:58:11 +1100169 sys/utsname.h \
Christian Göttschef3623b72021-01-22 19:14:50 +0100170 unistd.h
Christian Göttsche759a3402021-01-22 19:14:55 +0100171 ], [], [AC_MSG_ERROR([can not find required generic header files])])
Christian Göttschef3623b72021-01-22 19:14:50 +0100172
173AC_HEADER_MAJOR
174dnl glibc 2.25 deprecates 'major' and 'minor' in <sys/types.h> and requires to
175dnl include <sys/sysmacros.h>. However the logic in AC_HEADER_MAJOR has not yet
176dnl been updated in Autoconf 2.69, so use a workaround:
177m4_version_prereq([2.70], [],
178[if test "x$ac_cv_header_sys_mkdev_h" != xyes; then
179 AC_CHECK_HEADER([sys/sysmacros.h], [AC_DEFINE([MAJOR_IN_SYSMACROS], [1],
Explorer0947ae9662023-07-29 03:11:54 +0800180 [Define to 1 if 'major', 'minor', and 'makedev' are declared in <sys/sysmacros.h>.])])
Christian Göttschef3623b72021-01-22 19:14:50 +0100181fi])
182
183# Optional Section
184
185AC_CHECK_HEADERS([execinfo.h])
186
187if test "$my_htop_platform" = darwin; then
188 AC_CHECK_HEADERS([mach/mach_time.h])
189fi
190
191# ----------------------------------------------------------------------
192
193
194# ----------------------------------------------------------------------
195# Checks for typedefs, structures, and compiler characteristics.
196# ----------------------------------------------------------------------
197
Benny Baumanna98fc472023-11-29 20:39:25 +0100198AC_TYPE_MBSTATE_T
199AC_TYPE_MODE_T
200AC_TYPE_OFF_T
Christian Göttschef3623b72021-01-22 19:14:50 +0100201AC_TYPE_PID_T
Benny Baumanna98fc472023-11-29 20:39:25 +0100202AC_TYPE_SIZE_T
203AC_TYPE_SSIZE_T
Christian Göttschef3623b72021-01-22 19:14:50 +0100204AC_TYPE_UID_T
205AC_TYPE_UINT8_T
206AC_TYPE_UINT16_T
207AC_TYPE_UINT32_T
208AC_TYPE_UINT64_T
209
Benny Baumann44d12002021-06-27 12:44:01 +0200210AC_MSG_CHECKING(for alloc_size)
211old_CFLAGS="$CFLAGS"
212CFLAGS="$CFLAGS -Wno-error -Werror=attributes"
213AC_COMPILE_IFELSE([
214 AC_LANG_SOURCE(
215 [
Explorer0978acd632024-08-13 04:30:53 +0800216 /* Attribute supported in GCC 4.3 or later */
Benny Baumann44d12002021-06-27 12:44:01 +0200217 __attribute__((alloc_size(1))) char* my_alloc(int size) { return 0; }
218 ],[]
219 )],
220 AC_DEFINE([HAVE_ATTR_ALLOC_SIZE], 1, [The alloc_size attribute is supported.])
221 AC_MSG_RESULT(yes),
222 AC_MSG_RESULT(no))
223CFLAGS="$old_CFLAGS"
224
Christian Göttsche8387df12023-02-04 17:34:08 +0100225AC_MSG_CHECKING(for access)
226old_CFLAGS="$CFLAGS"
227CFLAGS="$CFLAGS -Wno-error -Werror=attributes"
228AC_COMPILE_IFELSE([
229 AC_LANG_SOURCE(
230 [
Explorer0978acd632024-08-13 04:30:53 +0800231 /* Attribute supported in GCC 10 or later */
Christian Göttsche8387df12023-02-04 17:34:08 +0100232 __attribute__((access(read_only, 1, 2))) extern int foo(const char* str, unsigned len);
233 ],[]
234 )],
235 AC_DEFINE([HAVE_ATTR_ACCESS], 1, [The access attribute is supported.])
236 AC_MSG_RESULT(yes),
237 AC_MSG_RESULT(no))
238CFLAGS="$old_CFLAGS"
239
Explorer09f541f702023-10-11 03:37:39 +0800240AC_MSG_CHECKING(for nonnull)
241old_CFLAGS="$CFLAGS"
242CFLAGS="$CFLAGS -Wno-error -Werror=attributes"
243AC_COMPILE_IFELSE([
244 AC_LANG_SOURCE(
245 [[
246 /* Attribute supported in GCC 3.3 or later */
247 __attribute__((nonnull)) int my_strcmp(const char* a, const char* b);
248 __attribute__((nonnull(1))) long my_strtol(const char* str, char** endptr, int base);
249 ]]
250 )],
251 AC_DEFINE([HAVE_ATTR_NONNULL], 1, [The nonnull attribute is supported.])
252 AC_MSG_RESULT(yes),
253 AC_MSG_RESULT(no))
254CFLAGS="$old_CFLAGS"
255
Benny Baumann0720b102024-07-10 10:53:43 +0200256AC_MSG_CHECKING(for returns_nonnull)
257old_CFLAGS="$CFLAGS"
258CFLAGS="$CFLAGS -Wno-error -Werror=attributes"
259AC_COMPILE_IFELSE([
260 AC_LANG_SOURCE(
261 [[
262 /* Attribute supported in GCC 4.9 or later */
263 __attribute__((returns_nonnull)) void* foo(void);
264 ]]
265 )],
266 AC_DEFINE([HAVE_ATTR_RETNONNULL], 1, [The returns_nonnull attribute is supported.])
267 AC_MSG_RESULT(yes),
268 AC_MSG_RESULT(no))
269CFLAGS="$old_CFLAGS"
270
Christian Göttscheaa0424a2021-08-08 16:54:20 +0200271AC_MSG_CHECKING(for NaN support)
Explorer09b4164332023-07-29 16:24:12 +0800272dnl Note: AC_RUN_IFELSE does not try compiling the program at all when
273dnl $cross_compiling is 'yes'.
274AC_LINK_IFELSE([
Christian Göttscheaa0424a2021-08-08 16:54:20 +0200275 AC_LANG_PROGRAM(
276 [[
Explorer09b4164332023-07-29 16:24:12 +0800277#include <math.h>
Christian Göttscheaa0424a2021-08-08 16:54:20 +0200278 ]],
279 [[
Explorer09b4164332023-07-29 16:24:12 +0800280 double x = NAN;
281 /* Both should evaluate to false -> 0 (exit success) */
282 return isgreater(x, x) || isgreaterequal(x, x);
Christian Göttscheaa0424a2021-08-08 16:54:20 +0200283 ]]
284 )],
Explorer09b4164332023-07-29 16:24:12 +0800285 [flag_finite_math_only=unknown
286 if test "$cross_compiling" = yes; then
287 AC_COMPILE_IFELSE([
288 AC_LANG_SOURCE([[
289/* __FINITE_MATH_ONLY__ is documented in Clang. */
290#ifdef __FINITE_MATH_ONLY__
291#error "should not enable -ffinite-math-only"
292#endif
293 ]])],
294 AC_MSG_RESULT([assume yes (cross compiling)]),
Benny Baumann6aa9ef22023-11-23 12:22:02 +0100295 flag_finite_math_only=yes)
Explorer09b4164332023-07-29 16:24:12 +0800296 elif ./conftest$EXEEXT >&AS_MESSAGE_LOG_FD; then
297 flag_finite_math_only=no
298 AC_MSG_RESULT(yes)
299 else
300 flag_finite_math_only=yes
301 fi
302 if test "$flag_finite_math_only" = yes; then
Christian Göttscheaa0424a2021-08-08 16:54:20 +0200303 AC_MSG_RESULT(no)
Explorer09b4164332023-07-29 16:24:12 +0800304 AC_MSG_WARN([runtime behavior with NaN is not compliant - some functionality might break; consider using '-fno-finite-math-only'])
305 fi],
306 [AC_MSG_RESULT(no)
307 AC_MSG_ERROR([can not find required macros: NAN, isgreater() and isgreaterequal()])])
Christian Göttscheaa0424a2021-08-08 16:54:20 +0200308
Benny Baumanna3951862024-01-22 10:39:28 +0100309AC_MSG_CHECKING(for __builtin_ctz)
310AC_COMPILE_IFELSE([
311 AC_LANG_PROGRAM([], [[__builtin_ctz(1); /* Supported in GCC 3.4 or later */]])],
312 [AC_DEFINE([HAVE_BUILTIN_CTZ], 1, [Define to 1 if the compiler supports '__builtin_ctz' function.])
313 AC_MSG_RESULT(yes)],
314 AC_MSG_RESULT(no))
315
Christian Göttschef3623b72021-01-22 19:14:50 +0100316# ----------------------------------------------------------------------
317
318
319# ----------------------------------------------------------------------
320# Checks for generic library functions.
321# ----------------------------------------------------------------------
322
Christian Göttschee34c3872022-08-09 21:37:14 +0200323AC_SEARCH_LIBS([ceil], [m], [], [AC_MSG_ERROR([can not find required function ceil()])])
Christian Göttschef3623b72021-01-22 19:14:50 +0100324
325if test "$my_htop_platform" = dragonflybsd; then
Christian Göttsche759a3402021-01-22 19:14:55 +0100326 AC_SEARCH_LIBS([kvm_open], [kvm], [], [AC_MSG_ERROR([can not find required function kvm_open()])])
Christian Göttsche2f67a2b2024-01-19 21:06:14 +0100327 AC_SEARCH_LIBS([getdevs], [devstat], [], [AC_MSG_ERROR([can not find required function getdevs()])])
Christian Göttschef3623b72021-01-22 19:14:50 +0100328fi
329
330if test "$my_htop_platform" = freebsd; then
Christian Göttschecae47bb2021-02-05 15:15:01 +0100331 if test "$enable_static" = yes; then
332 AC_SEARCH_LIBS([elf_version], [elf], [], [AC_MSG_ERROR([can not find required function elf_version()])])
333 fi
Christian Göttsche759a3402021-01-22 19:14:55 +0100334 AC_SEARCH_LIBS([kvm_open], [kvm], [], [AC_MSG_ERROR([can not find required function kvm_open()])])
335 AC_SEARCH_LIBS([devstat_checkversion], [devstat], [], [AC_MSG_ERROR([can not find required function devstat_checkversion()])])
Christian Göttschef3623b72021-01-22 19:14:50 +0100336fi
337
338if test "$my_htop_platform" = linux; then
Christian Göttsche575edff2021-01-22 19:14:59 +0100339 if test "$enable_static" != yes; then
340 AC_SEARCH_LIBS([dlopen], [dl dld], [], [AC_MSG_ERROR([can not find required function dlopen()])])
341 fi
Christian Göttschef3623b72021-01-22 19:14:50 +0100342fi
343
fraggerfox4b49de42021-03-15 13:14:39 +0530344if test "$my_htop_platform" = netbsd; then
345 AC_SEARCH_LIBS([kvm_open], [kvm], [], [AC_MSG_ERROR([can not find required function kvm_open()])])
niafdcdc542021-07-26 19:04:44 +0200346 AC_SEARCH_LIBS([prop_dictionary_get], [prop], [], [AC_MSG_ERROR([can not find required function prop_dictionary_get()])])
fraggerfox4b49de42021-03-15 13:14:39 +0530347fi
348
Christian Göttschef3623b72021-01-22 19:14:50 +0100349if test "$my_htop_platform" = openbsd; then
Christian Göttsche759a3402021-01-22 19:14:55 +0100350 AC_SEARCH_LIBS([kvm_open], [kvm], [], [AC_MSG_ERROR([can not find required function kvm_open()])])
Christian Göttschef3623b72021-01-22 19:14:50 +0100351fi
352
353if test "$my_htop_platform" = solaris; then
Christian Göttsche759a3402021-01-22 19:14:55 +0100354 AC_SEARCH_LIBS([kstat_open], [kstat], [], [AC_MSG_ERROR([can not find required function kstat_open()])])
355 AC_SEARCH_LIBS([Pgrab_error], [proc], [], [AC_MSG_ERROR([can not find required function Pgrab_error()])])
356 AC_SEARCH_LIBS([free], [malloc], [], [AC_MSG_ERROR([can not find required function free()])])
Christian Göttschef3623b72021-01-22 19:14:50 +0100357fi
358
359# Optional Section
360
361AC_SEARCH_LIBS([clock_gettime], [rt])
362
363AC_CHECK_FUNCS([ \
364 clock_gettime \
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200365 dladdr \
Christian Göttschef3623b72021-01-22 19:14:50 +0100366 faccessat \
367 fstatat \
368 host_get_clock_service \
Christian Göttsche7b1fa1b2020-12-25 11:03:15 +0100369 memfd_create\
Christian Göttschef3623b72021-01-22 19:14:50 +0100370 openat \
371 readlinkat \
Christian Göttscheda494892023-01-10 19:40:04 +0100372 sched_getscheduler \
373 sched_setscheduler \
Christian Göttschef3623b72021-01-22 19:14:50 +0100374 ])
375
Explorer090a57ba02025-04-08 02:20:35 +0800376# strchrnul is available in macOS since 15.4, but the user may specify an older
377# macOS version ('-mmacos-version-min') to build for. We need to ensure it is
378# actually exposed in the header.
379htop_save_CFLAGS=$CFLAGS
380CFLAGS="$CFLAGS -Werror"
381
382AC_MSG_CHECKING([for strchrnul])
383AC_LINK_IFELSE([AC_LANG_PROGRAM([[
384#include <string.h>
385 ]], [[
386static char ch;
387char* ptr = strchrnul(&ch, 0);
388return ptr != &ch; /* Should be 0 (exit success) */
389 ]])],
390 [AC_MSG_RESULT(yes)
391 AC_DEFINE([HAVE_STRCHRNUL], [1], [Define to 1 if you have the 'strchrnul' function.])],
392 [AC_MSG_RESULT(no)])
393
394CFLAGS=$htop_save_CFLAGS
395
Christian Göttschef3623b72021-01-22 19:14:50 +0100396if test "$my_htop_platform" = darwin; then
SuCicada731812d2024-04-08 18:28:32 +0900397 AC_CHECK_FUNCS([host_statistics64], [
398 AC_CHECK_TYPES([struct vm_statistics64], [], [], [[#include <mach/vm_statistics.h>]])
399 ], [])
Christian Göttschef3623b72021-01-22 19:14:50 +0100400fi
Christian Goettschec2fdfd92020-10-21 17:06:32 +0200401
Nathan Scottd58180b2022-09-13 12:14:40 +1000402if test "$my_htop_platform" = pcp; then
403 AC_CHECK_FUNCS([pmLookupDescs])
404fi
405
Christian Göttsche575edff2021-01-22 19:14:59 +0100406if test "$my_htop_platform" = linux && test "x$enable_static" = xyes; then
Christian Göttschee59176f2024-01-10 17:12:18 +0100407 AC_CHECK_LIB([systemd], [sd_bus_open_system], [], [], [-lcap])
Christian Göttsche575edff2021-01-22 19:14:59 +0100408fi
409
Hisham Muhammad300af4b2014-11-19 23:17:16 -0200410# ----------------------------------------------------------------------
Hisham Muhammadeb229d92014-11-24 18:55:03 -0200411
Hisham Muhammadd6231ba2006-03-04 18:16:49 +0000412
Christian Göttschef3623b72021-01-22 19:14:50 +0100413# ----------------------------------------------------------------------
414# Checks for cross-platform features and flags.
415# ----------------------------------------------------------------------
Hisham Muhammada5dfaa22008-09-23 04:31:13 +0000416
Explorer09fd083142024-09-19 06:08:41 +0800417dnl PKG_PROG_PKG_CONFIG initializes $PKG_CONFIG and related variables.
418dnl If the macro is not called, some pkg-config checks might be skipped
419dnl and $PKG_CONFIG might be unset.
420m4_ifdef([PKG_PROG_PKG_CONFIG], [
421 PKG_PROG_PKG_CONFIG()
Explorer0976e7dd42024-10-29 07:57:54 +0800422 pkg_m4_included=1 # Makefile might grep this keyword. Don't remove.
Explorer09baf70412024-09-19 06:15:08 +0800423], [
Explorer09baf70412024-09-19 06:15:08 +0800424 m4_warn(
425 [syntax],
426 [pkg.m4 is absent or older than version 0.16; this 'configure' would have incomplete pkg-config support])
Explorer09fd083142024-09-19 06:08:41 +0800427])
428
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100429AC_ARG_ENABLE([unicode],
430 [AS_HELP_STRING([--enable-unicode],
431 [enable Unicode support @<:@default=yes@:>@])],
432 [],
433 [enable_unicode=yes])
Hisham Muhammaddb682862015-12-09 17:17:30 -0200434
Explorer095d1948b2024-09-19 06:27:31 +0800435AC_ARG_VAR([CURSES_CFLAGS], [C compiler flags for curses; this overrides auto detected values])
436AC_ARG_VAR([CURSES_LIBS], [linker flags for curses; this overrides auto detected values])
437
Explorer097ad9ec22024-10-29 07:59:30 +0800438curses_pkg_names="ncurses6 ncurses5 ncurses ncursest6 ncursest5 \
439 ncursest curses"
Explorer095d1948b2024-09-19 06:27:31 +0800440
441if test "x$enable_unicode" = xyes; then
Explorer097ad9ec22024-10-29 07:59:30 +0800442 curses_pkg_names="ncursesw6 ncursesw5 ncursesw ncursestw6 ncursestw5 \
443 ncursestw $curses_pkg_names"
Explorer095d1948b2024-09-19 06:27:31 +0800444fi
445
446AC_ARG_WITH([curses],
447 [AS_HELP_STRING([--with-curses=NAME],
448 [select curses package NAME to link with; e.g. ncursesw6])],
449 [],
450 [with_curses=check])
451case $with_curses in
Explorer0952c9e3d2024-10-26 21:00:57 +0800452check|yes)
Explorer095d1948b2024-09-19 06:27:31 +0800453 : # No-op. Use default list.
454 ;;
Explorer0952c9e3d2024-10-26 21:00:57 +0800455no)
Explorer095d1948b2024-09-19 06:27:31 +0800456 AC_MSG_ERROR([bad value '$with_curses' for --with-curses option])
457 ;;
458*)
459 if test "x${CURSES_CFLAGS+y}${CURSES_LIBS+y}" = xyy; then
460 AC_MSG_WARN([ignoring --with-curses value due to override])
461 fi
462 curses_pkg_names=`echo "x$with_curses" | sed 's/^x\(lib\)\{0,1\}//'`
463 ;;
464esac
465
466# $1: C preprocessor and compiler flags for curses library
467# $2: linker flags for curses library
468htop_check_curses_capability () {
469 htop_curses_cflags=${CURSES_CFLAGS-"$1"}
470 htop_curses_libs=${CURSES_LIBS-"$2"}
471
472 echo "curses cflags${CURSES_CFLAGS+ (override)}: $htop_curses_cflags" >&AS_MESSAGE_LOG_FD
473 echo "curses libs${CURSES_LIBS+ (override)}: $htop_curses_libs" >&AS_MESSAGE_LOG_FD
474
475 htop_msg_linker_flags=$htop_curses_libs
476 if test "`echo x $htop_msg_linker_flags`" = x; then
477 htop_msg_linker_flags="(no linker flags)"
478 fi
479
480 htop_curses_status=0 # 0 for success; nonzero for failure
481
482 htop_save_CFLAGS=$CFLAGS
483 htop_save_LIBS=$LIBS
484 CFLAGS="$AM_CFLAGS $htop_curses_cflags $CFLAGS"
485 LIBS="$htop_curses_libs $LIBS"
486
487 # At this point we have not checked the name of curses header, so
488 # use forward declaration for the linking tests below.
489
Explorer09b4582992024-10-29 07:59:08 +0800490 # htop uses keypad(), but for ncurses implementation, the symbol is
491 # in "-ltinfo" and not "-lncurses".
Explorer09d5f24d22024-08-21 19:56:21 +0800492 # Check "-ltinfo" symbols first, as libncurses might require
493 # explicit "-ltinfo" to link (for internal dependency).
494 AC_MSG_CHECKING([for keypad in $htop_msg_linker_flags])
495 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer09d5f24d22024-08-21 19:56:21 +0800496/* int keypad(WINDOW* win, bool enable); */
Explorer09d5f24d22024-08-21 19:56:21 +0800497int keypad(void* win, int enable);
498 ]], [[
Explorer09b4582992024-10-29 07:59:08 +0800499static char dummy;
500keypad((void*)&dummy, 0);
Explorer09d5f24d22024-08-21 19:56:21 +0800501 ]])],
502 [AC_MSG_RESULT(yes)],
503 [AC_MSG_RESULT(no)
504 htop_curses_status=1])
505
Explorer095d1948b2024-09-19 06:27:31 +0800506 # htop calls refresh(), which might be implemented as a macro.
507 # It is more reliable to test linking with doupdate(), which
508 # refresh() would call internally.
Explorer09d5f24d22024-08-21 19:56:21 +0800509 if test "$htop_curses_status" -eq 0; then
510 AC_MSG_CHECKING([for doupdate in $htop_msg_linker_flags])
511 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer095d1948b2024-09-19 06:27:31 +0800512int doupdate(void);
Explorer09d5f24d22024-08-21 19:56:21 +0800513 ]], [[
Explorer095d1948b2024-09-19 06:27:31 +0800514doupdate();
Explorer09d5f24d22024-08-21 19:56:21 +0800515 ]])],
516 [AC_MSG_RESULT(yes)
517 htop_curses_capability=nonwide],
518 [AC_MSG_RESULT(no)
519 htop_curses_status=1])
520 fi
Explorer095d1948b2024-09-19 06:27:31 +0800521
Explorer093b66b202024-10-29 07:59:14 +0800522 # htop calls mvadd_wchnstr(), which might be implemented as a macro.
523 # It is more reliable to test linking with wadd_wchnstr().
Explorer095d1948b2024-09-19 06:27:31 +0800524 if test "x$htop_curses_status$enable_unicode" = x0yes; then
Explorer093b66b202024-10-29 07:59:14 +0800525 AC_MSG_CHECKING([for wadd_wchnstr in $htop_msg_linker_flags])
Explorer095d1948b2024-09-19 06:27:31 +0800526 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer093b66b202024-10-29 07:59:14 +0800527/* int wadd_wchnstr(WINDOW* win, const cchar_t* wchstr, int n); */
528int wadd_wchnstr(void* win, const void* wchstr, int n);
Explorer095d1948b2024-09-19 06:27:31 +0800529 ]], [[
Explorer093b66b202024-10-29 07:59:14 +0800530static char dummy1;
531static char dummy2;
532wadd_wchnstr((void*)&dummy1, (void*)&dummy2, 0);
Explorer095d1948b2024-09-19 06:27:31 +0800533 ]])],
534 [AC_MSG_RESULT(yes)
535 htop_curses_capability=wide],
536 [AC_MSG_RESULT(no)
537 htop_curses_status=1])
538 fi
539
540 if test "$htop_curses_status" -eq 0; then
541 AM_CFLAGS="$AM_CFLAGS $htop_curses_cflags"
542 if test "$htop_curses_capability" = wide; then
543 AC_DEFINE([HAVE_LIBNCURSESW], 1, [libncursesw is present])
544 else
545 AC_DEFINE([HAVE_LIBNCURSES], 1, [libcurses is present])
546 fi
547 else
548 LIBS=$htop_save_LIBS
549 fi
550 CFLAGS=$htop_save_CFLAGS
551 return "$htop_curses_status"
552} # htop_check_curses_capability
553
554htop_curses_capability=none
555
556if test "x${CURSES_CFLAGS+y}${CURSES_LIBS+y}" = xyy; then
557 curses_pkg_names=""
558 htop_check_curses_capability "$CURSES_CFLAGS" "$CURSES_LIBS"
559fi
560
561# Prioritize $PKG_CONFIG over ncurses*-config, as users might need to
562# cross-compile htop.
563if test "x$PKG_CONFIG" != x; then
564 pkg_config_static_flag=""
565 if test "$enable_static" = yes; then
566 pkg_config_static_flag=--static
567 fi
568
569 for curses_name in $curses_pkg_names; do
570 echo retrieving $curses_name information through $PKG_CONFIG >&AS_MESSAGE_LOG_FD
571 $PKG_CONFIG --exists --print-errors $curses_name >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD || continue
572
573 : # Resets "$?" to 0
574 htop_config_cflags=`$PKG_CONFIG --cflags $pkg_config_static_flag $curses_name 2>/dev/null` || continue
575 : # Resets "$?" to 0
576 htop_config_libs=`$PKG_CONFIG --libs $pkg_config_static_flag $curses_name 2>/dev/null` || continue
577
578 AC_MSG_RESULT([found $curses_name information through $PKG_CONFIG])
579
580 if htop_check_curses_capability "$htop_config_cflags" "$htop_config_libs"; then
581 break
582 fi
583 done
584fi
585
586case ${htop_curses_capability}-$enable_unicode in
587none-*|nonwide-yes)
588 for curses_name in $curses_pkg_names; do
589 echo retrieving $curses_name information through ${curses_name}-config >&AS_MESSAGE_LOG_FD
590
591 ${curses_name}-config --cflags >/dev/null 2>&AS_MESSAGE_LOG_FD || continue
592
593 : # Resets "$?" to 0
594 htop_config_cflags=`${curses_name}-config --cflags 2>/dev/null` || continue
595 : # Resets "$?" to 0
596 htop_config_libs=`${curses_name}-config --libs 2>/dev/null` || continue
597
598 AC_MSG_RESULT([found $curses_name information through ${curses_name}-config])
599
600 if htop_check_curses_capability "$htop_config_cflags" "$htop_config_libs"; then
601 break
602 fi
603 done
604 ;;
605esac
606
607case ${htop_curses_capability}-$enable_unicode in
608none-*|nonwide-yes)
Explorer09082b9772024-09-19 06:28:42 +0800609 if test "x$PKG_CONFIG" = x; then (
610 # Friendly warning to advise user to install pkg-config.
611 # The local variables get discarded when done.
612 list=""
613 echo "" >conftest.c
614 if test "$cross_compiling" != yes; then
615 # "-print-multi-directory" supported in GCC 3.0 or later
616 name=""
617 if $CC $CPPFLAGS $CFLAGS -print-multi-directory -E conftest.c >/dev/null 2>&1; then
618 name=`$CC $CPPFLAGS $CFLAGS -print-multi-directory -E conftest.c 2>/dev/null |
619 sed '/^ *#/ d; s/^\.$//; q'`
620 fi
621 list="/usr/lib${name}/pkgconfig $list"
622 case $host_os in
623 darwin*)
624 list="/opt/homebrew/Library/Homebrew/os/mac/pkgconfig $list"
625 ;;
626 freebsd*)
627 list="/usr/libdata/pkgconfig $list"
628 ;;
629 netbsd*)
630 list="/usr/pkg/lib/pkgconfig $list"
631 ;;
632 esac
633 fi
634 if test "x$host_alias" != x; then
635 list="/usr/lib/${host_alias}/pkgconfig $list"
636 fi
637 # "-print-multiarch" supported in GCC 4.6 or later
638 if $CC $CPPFLAGS $CFLAGS -print-multiarch -E conftest.c >/dev/null 2>&1; then
639 name=`$CC $CPPFLAGS $CFLAGS -print-multiarch -E conftest.c 2>/dev/null |
640 sed '/^ *#/ d; q'`
641 if test "x$name" != x; then
642 list="/usr/lib/${name}/pkgconfig $list"
643 fi
644 fi
645 rm -f conftest.*
646
647 for d in $list; do
648 result=`find "$d" -name '*curses*.pc' 2>/dev/null | sed '1 q'`
649 if test "x$result" != x; then
Explorer09d464ad12024-10-28 17:04:21 +0800650 echo detected a .pc file: "$result" >&AS_MESSAGE_LOG_FD
Explorer09082b9772024-09-19 06:28:42 +0800651 AC_MSG_WARN([your system supports pkg-config; installing pkg-config is recommended before configuring htop])
Explorer0976e7dd42024-10-29 07:57:54 +0800652 m4_ifdef([PKG_PROG_PKG_CONFIG], [], [
653 AC_MSG_WARN([this configure script would also need to be regenerated])
654 ])
Explorer09082b9772024-09-19 06:28:42 +0800655 break
656 fi
657 done
658 ) fi
659
Explorer095d1948b2024-09-19 06:27:31 +0800660 # OpenBSD and Solaris are known to not provide '*curses*.pc' files.
661 AC_MSG_RESULT([no curses information found through '*-config' utilities; will guess the linker flags])
662 for curses_name in $curses_pkg_names; do
663 if htop_check_curses_capability "" "-l$curses_name"; then
664 break
665 fi
Explorer09e3bdb102024-10-29 07:59:30 +0800666 # For ncurses implementation, an extra terminfo library might be
667 # needed. Guess the terminfo library name based on the ncurses
668 # library file name (e.g. "-ltinfow" for "-lncursesw"), before
669 # trying the "-ltinfo" name.
670 tinfo_name=`echo x$curses_name | sed 's/^xncurses/tinfo/p; d'`
671 case x$tinfo_name in
672 x|xtinfo)
673 ;;
674 *)
675 if htop_check_curses_capability "" "-l$curses_name -l$tinfo_name"; then
676 break
677 fi
678 ;;
679 esac
Explorer09d5f24d22024-08-21 19:56:21 +0800680 if htop_check_curses_capability "" "-l$curses_name -ltinfo"; then
681 break
682 fi
Explorer095d1948b2024-09-19 06:27:31 +0800683 done
684 ;;
685esac
686
687case ${htop_curses_capability}-$enable_unicode in
688nonwide-yes)
689 AC_MSG_ERROR([cannot find required ncursesw library; you may want to use --disable-unicode])
690 ;;
691none-*)
692 AC_MSG_ERROR([cannot find required curses/ncurses library])
693 ;;
694esac
695
696htop_save_CFLAGS=$CFLAGS
697CFLAGS="$AM_CFLAGS $CFLAGS"
Explorer09a2d90f42024-10-29 07:59:23 +0800698
Explorer095d1948b2024-09-19 06:27:31 +0800699if test "x$enable_unicode" = xyes; then
Christian Göttsche759a3402021-01-22 19:14:55 +0100700 AC_CHECK_HEADERS([ncursesw/curses.h], [],
701 [AC_CHECK_HEADERS([ncurses/ncurses.h], [],
702 [AC_CHECK_HEADERS([ncurses/curses.h], [],
703 [AC_CHECK_HEADERS([ncurses.h], [],
704 [AC_MSG_ERROR([can not find required ncurses header file])])])])])
Christian Göttscheead978b2020-12-07 15:30:56 +0100705
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530706 AC_CHECK_HEADERS([ncursesw/term.h], [],
707 [AC_CHECK_HEADERS([ncurses/term.h], [],
708 [AC_CHECK_HEADERS([term.h], [],
709 [AC_MSG_ERROR([can not find required term header file])])])])
Hisham Muhammad8fa33dc2008-03-09 02:33:23 +0000710else
Christian Göttsche759a3402021-01-22 19:14:55 +0100711 AC_CHECK_HEADERS([curses.h], [],
712 [AC_CHECK_HEADERS([ncurses/curses.h], [],
713 [AC_CHECK_HEADERS([ncurses/ncurses.h], [],
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530714 [AC_CHECK_HEADERS([ncurses.h], [],
Christian Göttsche759a3402021-01-22 19:14:55 +0100715 [AC_MSG_ERROR([can not find required ncurses header file])])])])])
Christian Göttscheead978b2020-12-07 15:30:56 +0100716
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530717 AC_CHECK_HEADERS([ncurses/term.h], [],
718 [AC_CHECK_HEADERS([term.h], [],
719 [AC_MSG_ERROR([can not find required term header file])])])
Hisham Muhammad4c51ad02007-08-10 05:07:14 +0000720fi
Explorer09a2d90f42024-10-29 07:59:23 +0800721
722CFLAGS="-I$srcdir $CFLAGS"
723
724# Check for things that might be macros.
725# "stdscr" is a macro in ncursest (reentrant version of ncurses).
726AC_MSG_CHECKING([whether the curses header works])
727AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer09f0237902024-10-29 07:59:30 +0800728/* Checks if the "bool" definition in curses is ISO C compatible */
729#include <stdbool.h>
730
Explorer09a2d90f42024-10-29 07:59:23 +0800731#include "ProvideCurses.h"
732 ]], [[
Explorer09f0237902024-10-29 07:59:30 +0800733keypad(stdscr, false);
Explorer09a2d90f42024-10-29 07:59:23 +0800734
735refresh();
736
737#if defined(HAVE_LIBNCURSESW)
738{
739 static cchar_t dummy;
740 mvadd_wchnstr(0, 0, &dummy, 0);
741}
742#endif
743 ]])],
744 [AC_MSG_RESULT(yes)],
745 [AC_MSG_RESULT(no)
746 AC_MSG_FAILURE([there are problems with the curses header])]
747)
748
Explorer095d1948b2024-09-19 06:27:31 +0800749CFLAGS=$htop_save_CFLAGS
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530750
Christian Göttsche575edff2021-01-22 19:14:59 +0100751if test "$enable_static" = yes; then
752 AC_SEARCH_LIBS([Gpm_GetEvent], [gpm])
753fi
Christian Göttscheee9e7ed2021-05-20 18:27:10 +0200754if test "$my_htop_platform" = "solaris"; then
755 # On OmniOS /usr/include/sys/regset.h redefines ERR to 13 - \r, breaking the Enter key.
Nathan Scottca06e682021-09-08 12:11:51 +1000756 # Since ncurses macros use the ERR macro, we can not use another name.
Christian Göttscheee9e7ed2021-05-20 18:27:10 +0200757 AC_DEFINE([ERR], [(-1)], [Predefine ncurses macro.])
758fi
Benny Baumann18e3fd52021-07-04 16:50:41 +0200759AC_CHECK_FUNCS( [set_escdelay] )
nia2ab8fb82021-07-14 20:17:13 +0200760AC_CHECK_FUNCS( [getmouse] )
Benny Baumann04d0a542024-12-09 22:18:08 +0100761AC_DEFINE([NCURSES_ENABLE_STDBOOL_H], [1], [Define to enable stdbool.h in ncurses])
Hisham Muhammad4c51ad02007-08-10 05:07:14 +0000762
gmbroome697f5bb2018-03-02 16:20:46 -0500763
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200764AC_ARG_ENABLE([affinity],
765 [AS_HELP_STRING([--enable-affinity],
766 [enable sched_setaffinity and sched_getaffinity for affinity support, conflicts with hwloc @<:@default=check@:>@])],
767 [],
768 [enable_affinity=check])
769if test "x$enable_affinity" = xcheck; then
770 if test "x$enable_hwloc" = xyes; then
771 enable_affinity=no
772 else
773 AC_MSG_CHECKING([for usable sched_setaffinity])
774 AC_RUN_IFELSE([
775 AC_LANG_PROGRAM([[
776 #include <sched.h>
777 #include <errno.h>
778 static cpu_set_t cpuset;
779 ]], [[
780 CPU_ZERO(&cpuset);
781 sched_setaffinity(0, sizeof(cpu_set_t), &cpuset);
782 if (errno == ENOSYS) return 1;
783 ]])],
784 [enable_affinity=yes
785 AC_MSG_RESULT([yes])],
786 [enable_affinity=no
787 AC_MSG_RESULT([no])],
Explorer0947ae9662023-07-29 03:11:54 +0800788 [AC_MSG_RESULT([assume yes (cross compiling)])])
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200789 fi
790fi
791if test "x$enable_affinity" = xyes; then
792 if test "x$enable_hwloc" = xyes; then
793 AC_MSG_ERROR([--enable-hwloc and --enable-affinity are mutual exclusive. Specify at most one of them.])
794 fi
795 AC_DEFINE([HAVE_AFFINITY], [1], [Define if sched_setaffinity and sched_getaffinity are to be used.])
796fi
797
798
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200799AC_ARG_ENABLE([unwind],
800 [AS_HELP_STRING([--enable-unwind],
801 [enable unwind support for printing backtraces; requires libunwind @<:@default=check@:>@])],
802 [],
803 [enable_unwind=check])
804case "$enable_unwind" in
805 check)
806 enable_unwind=yes
807 if test "$enable_static" = yes; then
808 AC_CHECK_LIB([lzma], [lzma_index_buffer_decode])
809 fi
810 AC_CHECK_LIB([unwind], [backtrace], [], [enable_unwind=no])
Christian Göttsche63880332021-12-14 17:36:57 +0100811 AC_CHECK_HEADERS([libunwind.h], [], [
812 old_CFLAGS="$CFLAGS"
813 CFLAGS="$CFLAGS -I/usr/include/libunwind"
814 AC_CHECK_HEADERS([libunwind/libunwind.h], [], [
815 enable_unwind=no
816 CFLAGS="$old_CFLAGS"
817 ])
818 ])
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200819 ;;
820 no)
821 ;;
822 yes)
823 AC_CHECK_LIB([unwind], [backtrace], [], [AC_MSG_ERROR([can not find required library libunwind])])
Christian Göttsche63880332021-12-14 17:36:57 +0100824 AC_CHECK_HEADERS([libunwind.h], [], [
Benny Baumann5c7cb912023-11-28 17:42:04 +0100825 AM_CFLAGS="$AM_CFLAGS -I/usr/include/libunwind"
Christian Göttsche63880332021-12-14 17:36:57 +0100826 AC_CHECK_HEADERS([libunwind/libunwind.h], [], [AC_MSG_ERROR([can not find required header file libunwind.h])])
827 ])
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200828 ;;
829 *)
830 AC_MSG_ERROR([bad value '$enable_unwind' for --enable-unwind])
831 ;;
832esac
833if test "x$enable_unwind" = xno; then
834 # Fall back to backtrace(3) and add -lexecinfo if needed
835 AC_SEARCH_LIBS([backtrace], [execinfo])
836fi
837
838
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100839AC_ARG_ENABLE([hwloc],
840 [AS_HELP_STRING([--enable-hwloc],
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200841 [enable hwloc support for CPU affinity; disables affinity support; requires libhwloc @<:@default=no@:>@])],
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100842 [],
843 [enable_hwloc=no])
844case "$enable_hwloc" in
845 no)
846 ;;
847 yes)
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200848 m4_ifdef([PKG_PROG_PKG_CONFIG], [
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200849 PKG_CHECK_MODULES(HWLOC, hwloc, [
Benny Baumann5c7cb912023-11-28 17:42:04 +0100850 AM_CFLAGS="$AM_CFLAGS $HWLOC_CFLAGS"
Christian Göttschec8a61852023-04-05 01:21:14 +0200851 LIBS="$LIBS $HWLOC_LIBS"
Explorer0947ae9662023-07-29 03:11:54 +0800852 AC_DEFINE([HAVE_LIBHWLOC], [1], [Define to 1 if you have the 'hwloc' library (-lhwloc).])
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200853 ], [
854 AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [AC_MSG_ERROR([can not find required library libhwloc])])
855 AC_CHECK_HEADERS([hwloc.h], [], [AC_MSG_ERROR([can not find require header file hwloc.h])])
856 ])
857 ], [
858 AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [AC_MSG_ERROR([can not find required library libhwloc])])
859 AC_CHECK_HEADERS([hwloc.h], [], [AC_MSG_ERROR([can not find require header file hwloc.h])])
860 ])
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100861 ;;
862 *)
863 AC_MSG_ERROR([bad value '$enable_hwloc' for --enable-hwloc])
864 ;;
865esac
Christian Göttsche005c4d12020-09-08 16:25:22 +0200866
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200867
Nathan Scott5b50ae32021-03-02 15:58:11 +1100868AC_ARG_WITH([os-release],
869 [AS_HELP_STRING([--with-os-release=FILE],
Christian Göttsche8ba4ef32021-03-12 16:37:17 +0100870 [location of an os-release file @<:@default=/etc/os-release@:>@])],
Nathan Scott5b50ae32021-03-02 15:58:11 +1100871 [],
872 [with_os_release=/etc/os-release])
Christian Göttsche8ba4ef32021-03-12 16:37:17 +0100873if test -n "$with_os_release" && test ! -f "$with_os_release"; then
Nathan Scott5b50ae32021-03-02 15:58:11 +1100874 if test -f "/usr/lib/os-release"; then
875 with_os_release="/usr/lib/os-release"
876 fi
877fi
878AC_DEFINE_UNQUOTED([OSRELEASEFILE], ["$with_os_release"], [File with OS release details.])
879
Nathan Scott1a7b6d42024-07-22 08:51:29 +1000880AC_ARG_WITH([config],
881 [AS_HELP_STRING([--with-config=DIR],
Explorer09c802dc42024-09-19 06:37:00 +0800882 [configuration path @<:@default=/.config@:>@])],
Nathan Scott1a7b6d42024-07-22 08:51:29 +1000883 [],
884 [with_config="/.config"])
885dnl Performance Co-Pilot configuration location to prevent overwrite
886if test "$my_htop_platform" = pcp -a "$with_config" = /.config; then
887 with_config="/.pcp"
888elif test -z "$with_config"; then
889 AC_MSG_ERROR([bad empty value for --with-config option])
890fi
891AC_DEFINE_UNQUOTED([CONFIGDIR], ["$with_config"], [Configuration path.])
892
Christian Göttschef3623b72021-01-22 19:14:50 +0100893# ----------------------------------------------------------------------
894
895
896# ----------------------------------------------------------------------
897# Checks for Linux features and flags.
898# ----------------------------------------------------------------------
899
900AC_ARG_WITH([proc],
901 [AS_HELP_STRING([--with-proc=DIR],
902 [location of a Linux-compatible proc filesystem @<:@default=/proc@:>@])],
903 [],
904 [with_proc=/proc])
905if test -z "$with_proc"; then
906 AC_MSG_ERROR([bad empty value for --with-proc option])
907fi
908AC_DEFINE_UNQUOTED([PROCDIR], ["$with_proc"], [Path of proc filesystem.])
909
910
911AC_ARG_ENABLE([openvz],
912 [AS_HELP_STRING([--enable-openvz],
913 [enable OpenVZ support @<:@default=no@:>@])],
914 [],
915 [enable_openvz=no])
916if test "x$enable_openvz" = xyes; then
917 AC_DEFINE([HAVE_OPENVZ], [1], [Define if openvz support enabled.])
918fi
919
920
921AC_ARG_ENABLE([vserver],
922 [AS_HELP_STRING([--enable-vserver],
923 [enable VServer support @<:@default=no@:>@])],
924 [],
925 [enable_vserver=no])
926if test "x$enable_vserver" = xyes; then
Christian Göttsche284f8c52021-09-02 22:32:46 +0200927 AC_DEFINE([HAVE_VSERVER], [1], [Define if VServer support enabled.])
Christian Göttschef3623b72021-01-22 19:14:50 +0100928fi
929
930
931AC_ARG_ENABLE([ancient_vserver],
932 [AS_HELP_STRING([--enable-ancient-vserver],
933 [enable ancient VServer support (implies --enable-vserver) @<:@default=no@:>@])],
934 [],
935 [enable_ancient_vserver=no])
936if test "x$enable_ancient_vserver" = xyes; then
Christian Göttsche284f8c52021-09-02 22:32:46 +0200937 if test "x$enable_vserver" != xyes; then
938 enable_vserver=implied
939 fi
940 AC_DEFINE([HAVE_VSERVER], [1], [Define if VServer support enabled.])
941 AC_DEFINE([HAVE_ANCIENT_VSERVER], [1], [Define if ancient vserver support enabled.])
Christian Göttschef3623b72021-01-22 19:14:50 +0100942fi
943
944
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100945AC_ARG_ENABLE([capabilities],
946 [AS_HELP_STRING([--enable-capabilities],
947 [enable Linux capabilities support; requires libcap @<:@default=check@:>@])],
948 [],
949 [enable_capabilities=check])
950case "$enable_capabilities" in
951 no)
952 ;;
953 check)
954 enable_capabilities=yes
955 AC_CHECK_LIB([cap], [cap_init], [], [enable_capabilities=no])
956 AC_CHECK_HEADERS([sys/capability.h], [], [enable_capabilities=no])
957 ;;
958 yes)
Christian Göttsche759a3402021-01-22 19:14:55 +0100959 AC_CHECK_LIB([cap], [cap_init], [], [AC_MSG_ERROR([can not find required library libcap])])
960 AC_CHECK_HEADERS([sys/capability.h], [], [AC_MSG_ERROR([can not find required header file sys/capability.h])])
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100961 ;;
962 *)
963 AC_MSG_ERROR([bad value '$enable_capabilities' for --enable-capabilities])
964 ;;
965esac
Christian Göttschef4404ef2020-09-02 14:39:25 +0200966
Christian Göttschef3623b72021-01-22 19:14:50 +0100967
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100968AC_ARG_ENABLE([delayacct],
969 [AS_HELP_STRING([--enable-delayacct],
970 [enable Linux delay accounting support; requires pkg-config, libnl-3 and libnl-genl-3 @<:@default=check@:>@])],
971 [],
972 [enable_delayacct=check])
973case "$enable_delayacct" in
974 no)
975 ;;
976 check)
Christian Göttsche69cfaf22021-05-16 20:01:25 +0200977 if test "$my_htop_platform" != linux; then
978 enable_delayacct=no
979 elif test "$enable_static" = yes; then
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100980 enable_delayacct=no
Christian Göttsche575edff2021-01-22 19:14:59 +0100981 else
Christian Göttsche24b15132024-03-30 13:47:14 +0100982 old_CFLAGS="$CFLAGS"
983 CFLAGS="$CFLAGS -I/usr/include/libnl3"
984 AC_CHECK_HEADERS([netlink/attr.h netlink/handlers.h netlink/msg.h], [enable_delayacct=yes], [enable_delayacct=no])
985 CFLAGS="$old_CFLAGS"
Christian Göttsche575edff2021-01-22 19:14:59 +0100986 fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100987 ;;
988 yes)
Christian Göttsche24b15132024-03-30 13:47:14 +0100989 old_CFLAGS="$CFLAGS"
990 CFLAGS="$CFLAGS -I/usr/include/libnl3"
991 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])])
992 CFLAGS="$old_CFLAGS"
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100993 ;;
994 *)
995 AC_MSG_ERROR([bad value '$enable_delayacct' for --enable-delayacct])
996 ;;
997esac
Christian Göttsche24b15132024-03-30 13:47:14 +0100998if test "$enable_delayacct" = yes; then
999 AC_DEFINE([HAVE_DELAYACCT], [1], [Define if delay accounting support should be enabled.])
1000 AM_CFLAGS="$AM_CFLAGS -I/usr/include/libnl3"
1001fi
Christian Göttschea782ef32024-03-30 13:47:10 +01001002AM_CONDITIONAL([HAVE_DELAYACCT], [test "$enable_delayacct" = yes])
André Carvalhob7b66b72017-12-04 00:15:29 -02001003
Christian Göttschef3623b72021-01-22 19:14:50 +01001004
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001005AC_ARG_ENABLE([sensors],
1006 [AS_HELP_STRING([--enable-sensors],
1007 [enable libsensors support for reading temperature data; requires only libsensors headers at compile time, at runtime libsensors is loaded via dlopen @<:@default=check@:>@])],
1008 [],
1009 [enable_sensors=check])
1010case "$enable_sensors" in
1011 no)
1012 ;;
1013 check)
1014 enable_sensors=yes
Christian Göttsche575edff2021-01-22 19:14:59 +01001015 if test "$enable_static" = yes; then
1016 AC_CHECK_LIB([sensors], [sensors_init], [], [enable_sensors=no])
1017 fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001018 AC_CHECK_HEADERS([sensors/sensors.h], [], [enable_sensors=no])
1019 ;;
1020 yes)
Christian Göttsche575edff2021-01-22 19:14:59 +01001021 if test "$enable_static" = yes; then
1022 AC_CHECK_LIB([sensors], [sensors_init], [], [AC_MSG_ERROR([can not find required library libsensors])])
1023 fi
1024 AC_CHECK_HEADERS([sensors/sensors.h], [], [AC_MSG_ERROR([can not find required header file sensors/sensors.h])])
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001025 ;;
1026 *)
1027 AC_MSG_ERROR([bad value '$enable_sensors' for --enable-sensors])
1028 ;;
1029esac
Christian Göttschefd2a0cf2020-12-22 20:02:01 +01001030if test "$enable_sensors" = yes || test "$my_htop_platform" = freebsd; then
1031 AC_DEFINE([BUILD_WITH_CPU_TEMP], [1], [Define if CPU temperature option should be enabled.])
1032fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001033
Christian Göttschef3623b72021-01-22 19:14:50 +01001034# ----------------------------------------------------------------------
1035
1036
1037# ----------------------------------------------------------------------
1038# Checks for compiler warnings.
1039# ----------------------------------------------------------------------
Christian Göttsche1b225cd2020-09-10 19:56:33 +02001040
Benny Baumann5c7cb912023-11-28 17:42:04 +01001041AM_CFLAGS="$AM_CFLAGS\
Christian Göttschef4602f72020-09-08 14:25:46 +02001042 -Wall\
1043 -Wcast-align\
Christian Göttschedb472072020-10-04 14:30:35 +02001044 -Wcast-qual\
Christian Göttschef4602f72020-09-08 14:25:46 +02001045 -Wextra\
Benny Baumannba0fca12020-09-18 16:58:03 +02001046 -Wfloat-equal\
Christian Göttschec150e4b2020-12-18 15:49:37 +01001047 -Wformat=2\
Christian Göttsche4dadbe32021-01-21 19:49:07 +01001048 -Winit-self\
Christian Göttschef4602f72020-09-08 14:25:46 +02001049 -Wmissing-format-attribute\
1050 -Wmissing-noreturn\
Christian Göttsche4e282eb2020-09-25 14:03:55 +02001051 -Wmissing-prototypes\
Christian Göttschef4602f72020-09-08 14:25:46 +02001052 -Wpointer-arith\
1053 -Wshadow\
1054 -Wstrict-prototypes\
1055 -Wundef\
1056 -Wunused\
1057 -Wwrite-strings"
1058
Christian Göttschef3623b72021-01-22 19:14:50 +01001059dnl https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
1060AC_DEFUN([AX_CHECK_COMPILE_FLAG],
Christian Göttsche38b6a012021-01-22 19:14:53 +01001061[
Christian Göttschef3623b72021-01-22 19:14:50 +01001062AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
1063AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
1064 ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
1065 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
1066 AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
1067 [AS_VAR_SET(CACHEVAR,[yes])],
1068 [AS_VAR_SET(CACHEVAR,[no])])
1069 _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
1070AS_VAR_IF(CACHEVAR,yes,
1071 [m4_default([$2], :)],
1072 [m4_default([$3], :)])
1073AS_VAR_POPDEF([CACHEVAR])dnl
1074])dnl AX_CHECK_COMPILE_FLAGS
1075
Christian Göttsche970885e2021-08-14 11:21:54 +02001076AX_CHECK_COMPILE_FLAG([-Wextra-semi-stmt], [AM_CFLAGS="$AM_CFLAGS -Wextra-semi-stmt"], , [-Werror=unknown-warning-option]) dnl the autoconf check itself generates -Wextra-semi-stmt
Christian Göttsche53732ab2021-08-14 11:26:43 +02001077AX_CHECK_COMPILE_FLAG([-Wimplicit-int-conversion], [AM_CFLAGS="$AM_CFLAGS -Wimplicit-int-conversion"], , [-Werror])
1078AX_CHECK_COMPILE_FLAG([-Wnull-dereference], [AM_CFLAGS="$AM_CFLAGS -Wnull-dereference"], , [-Werror])
Benny Baumann2cde4a72020-09-18 19:32:41 +02001079
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001080AC_ARG_ENABLE([werror],
1081 [AS_HELP_STRING([--enable-werror],
1082 [Treat warnings as errors @<:@default=no@:>@])],
1083 [],
1084 [enable_werror=no])
1085if test "x$enable_werror" = xyes; then
1086 AM_CFLAGS="$AM_CFLAGS -Werror"
1087fi
1088
1089AC_ARG_ENABLE([debug],
1090 [AS_HELP_STRING([--enable-debug],
Daniel Lange135efd52021-02-16 11:22:02 +01001091 [Enable compiling with maximum debug info, asserts and internal sanity checks @<:@default=no@:>@])],
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001092 [],
1093 [enable_debug=no])
1094if test "x$enable_debug" != xyes; then
1095 AM_CPPFLAGS="$AM_CPPFLAGS -DNDEBUG"
Explorer0993d76fd2023-07-31 05:05:43 +08001096
1097 AC_COMPILE_IFELSE([
1098 AC_LANG_SOURCE([[
1099#ifdef __SUPPORT_SNAN__
1100#error "signaling NaN support not recommended"
1101#endif
1102 ]])],
1103 :,
1104 [warning_msg="signaling NaN support is enabled; not recommended for htop"
1105 case "$CC" in
1106 *gcc*)
1107 warning_msg="$warning_msg (use '-fno-signaling-nans' compiler flag to disable)"
1108 ;;
1109 esac
1110 AC_MSG_WARN([$warning_msg])
1111 ])
Daniel Lange135efd52021-02-16 11:22:02 +01001112else
1113 AM_CPPFLAGS="$AM_CPPFLAGS -ggdb3"
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001114fi
Christian Göttscheb7f63292020-09-17 22:23:05 +02001115
Christian Göttschef3623b72021-01-22 19:14:50 +01001116
Christian Göttsche57254cd2020-08-21 10:37:20 +02001117AC_SUBST([AM_CFLAGS])
Christian Göttscheb7f63292020-09-17 22:23:05 +02001118AC_SUBST([AM_CPPFLAGS])
1119
Christian Göttschef3623b72021-01-22 19:14:50 +01001120# ----------------------------------------------------------------------
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001121
Christian Göttschef3623b72021-01-22 19:14:50 +01001122
1123# ----------------------------------------------------------------------
Hisham Muhammad300af4b2014-11-19 23:17:16 -02001124# We're done, let's go!
1125# ----------------------------------------------------------------------
Christian Göttschef3623b72021-01-22 19:14:50 +01001126
Daniel Lange1f242502025-01-01 02:45:10 +01001127AC_DEFINE_UNQUOTED([COPYRIGHT], ["(C) 2004-2019 Hisham Muhammad. (C) 2020-2025 htop dev team."], [Copyright message.])
Christian Göttschef3623b72021-01-22 19:14:50 +01001128
Hisham Muhammada75161f2014-11-24 20:11:33 -02001129AM_CONDITIONAL([HTOP_LINUX], [test "$my_htop_platform" = linux])
Hisham Muhammad8915b292014-11-27 16:27:34 -02001130AM_CONDITIONAL([HTOP_FREEBSD], [test "$my_htop_platform" = freebsd])
Diederik de Grootb258d6e2017-04-19 16:12:17 +02001131AM_CONDITIONAL([HTOP_DRAGONFLYBSD], [test "$my_htop_platform" = dragonflybsd])
fraggerfox4b49de42021-03-15 13:14:39 +05301132AM_CONDITIONAL([HTOP_NETBSD], [test "$my_htop_platform" = netbsd])
Michael McConvillea9a5a532015-09-18 00:46:48 -04001133AM_CONDITIONAL([HTOP_OPENBSD], [test "$my_htop_platform" = openbsd])
David Hunt70e7c8d2015-07-12 13:47:43 -05001134AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin])
gmbroome697f5bb2018-03-02 16:20:46 -05001135AM_CONDITIONAL([HTOP_SOLARIS], [test "$my_htop_platform" = solaris])
Nathan Scottc14a45b2021-02-17 14:43:56 +11001136AM_CONDITIONAL([HTOP_PCP], [test "$my_htop_platform" = pcp])
Hisham Muhammada75161f2014-11-24 20:11:33 -02001137AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported])
Christian Göttsche38b6a012021-01-22 19:14:53 +01001138
Hisham Muhammadeb229d92014-11-24 18:55:03 -02001139AC_SUBST(my_htop_platform)
Daniel Langefc2377f2021-08-14 10:35:11 +02001140AC_CONFIG_FILES([Makefile htop.1])
Hisham Muhammadd6231ba2006-03-04 18:16:49 +00001141AC_OUTPUT
Hisham Muhammadc39f18a2017-07-10 20:14:25 -03001142
Christian Göttschef3623b72021-01-22 19:14:50 +01001143if test "$my_htop_platform" = unsupported; then
Hisham Muhammadc39f18a2017-07-10 20:14:25 -03001144 echo ""
1145 echo "****************************************************************"
1146 echo "WARNING! This platform is not currently supported by htop."
1147 echo ""
1148 echo "The code will build, but it will produce a dummy version of htop"
1149 echo "which shows no processes, using the files from the unsupported/"
1150 echo "directory. This is meant to be a skeleton, to be used as a"
1151 echo "starting point if you are porting htop to a new platform."
1152 echo "****************************************************************"
1153 echo ""
1154fi
Christian Göttsche3b084db2020-08-28 12:10:31 +02001155
1156AC_MSG_RESULT([
1157 ${PACKAGE_NAME} ${VERSION}
1158
Benny Baumannd74e67d2025-03-03 19:06:52 +01001159 platform: $my_htop_platform ($host_os)
Nathan Scott5b50ae32021-03-02 15:58:11 +11001160 os-release file: $with_os_release
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001161 (Linux) proc directory: $with_proc
Christian Göttscheffd90c22020-10-05 12:29:31 +02001162 (Linux) openvz: $enable_openvz
Christian Göttscheffd90c22020-10-05 12:29:31 +02001163 (Linux) vserver: $enable_vserver
1164 (Linux) ancient vserver: $enable_ancient_vserver
Christian Göttscheffd90c22020-10-05 12:29:31 +02001165 (Linux) delay accounting: $enable_delayacct
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001166 (Linux) sensors: $enable_sensors
1167 (Linux) capabilities: $enable_capabilities
Christian Göttscheffd90c22020-10-05 12:29:31 +02001168 unicode: $enable_unicode
Christian Göttsche1fb0c722021-06-13 11:29:39 +02001169 affinity: $enable_affinity
Christian Göttsche29e1fcf2021-05-16 20:45:09 +02001170 unwind: $enable_unwind
Daniel Lange309f1d72020-11-16 13:29:37 +01001171 hwloc: $enable_hwloc
Daniel Langea8a723f2020-11-16 17:01:51 +01001172 debug: $enable_debug
Christian Göttsche575edff2021-01-22 19:14:59 +01001173 static: $enable_static
Christian Göttsche3b084db2020-08-28 12:10:31 +02001174])