blob: b843aa728afacbe9968122cfbc5e7d32c80eeb9e [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 ''])))
10m4_define([htop_release_version], [3.4.0-dev])
11
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 \
Nathan Scott4103c232023-10-09 10:48:38 +1100374 strchrnul \
Christian Göttschef3623b72021-01-22 19:14:50 +0100375 ])
376
Christian Göttschef3623b72021-01-22 19:14:50 +0100377if test "$my_htop_platform" = darwin; then
SuCicada731812d2024-04-08 18:28:32 +0900378 AC_CHECK_FUNCS([host_statistics64], [
379 AC_CHECK_TYPES([struct vm_statistics64], [], [], [[#include <mach/vm_statistics.h>]])
380 ], [])
Christian Göttschef3623b72021-01-22 19:14:50 +0100381fi
Christian Goettschec2fdfd92020-10-21 17:06:32 +0200382
Nathan Scottd58180b2022-09-13 12:14:40 +1000383if test "$my_htop_platform" = pcp; then
384 AC_CHECK_FUNCS([pmLookupDescs])
385fi
386
Christian Göttsche575edff2021-01-22 19:14:59 +0100387if test "$my_htop_platform" = linux && test "x$enable_static" = xyes; then
Christian Göttschee59176f2024-01-10 17:12:18 +0100388 AC_CHECK_LIB([systemd], [sd_bus_open_system], [], [], [-lcap])
Christian Göttsche575edff2021-01-22 19:14:59 +0100389fi
390
Hisham Muhammad300af4b2014-11-19 23:17:16 -0200391# ----------------------------------------------------------------------
Hisham Muhammadeb229d92014-11-24 18:55:03 -0200392
Hisham Muhammadd6231ba2006-03-04 18:16:49 +0000393
Christian Göttschef3623b72021-01-22 19:14:50 +0100394# ----------------------------------------------------------------------
395# Checks for cross-platform features and flags.
396# ----------------------------------------------------------------------
Hisham Muhammada5dfaa22008-09-23 04:31:13 +0000397
Explorer09fd083142024-09-19 06:08:41 +0800398dnl PKG_PROG_PKG_CONFIG initializes $PKG_CONFIG and related variables.
399dnl If the macro is not called, some pkg-config checks might be skipped
400dnl and $PKG_CONFIG might be unset.
401m4_ifdef([PKG_PROG_PKG_CONFIG], [
402 PKG_PROG_PKG_CONFIG()
Explorer0976e7dd42024-10-29 07:57:54 +0800403 pkg_m4_included=1 # Makefile might grep this keyword. Don't remove.
Explorer09baf70412024-09-19 06:15:08 +0800404], [
Explorer09baf70412024-09-19 06:15:08 +0800405 m4_warn(
406 [syntax],
407 [pkg.m4 is absent or older than version 0.16; this 'configure' would have incomplete pkg-config support])
Explorer09fd083142024-09-19 06:08:41 +0800408])
409
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100410AC_ARG_ENABLE([unicode],
411 [AS_HELP_STRING([--enable-unicode],
412 [enable Unicode support @<:@default=yes@:>@])],
413 [],
414 [enable_unicode=yes])
Hisham Muhammaddb682862015-12-09 17:17:30 -0200415
Explorer095d1948b2024-09-19 06:27:31 +0800416AC_ARG_VAR([CURSES_CFLAGS], [C compiler flags for curses; this overrides auto detected values])
417AC_ARG_VAR([CURSES_LIBS], [linker flags for curses; this overrides auto detected values])
418
Explorer097ad9ec22024-10-29 07:59:30 +0800419curses_pkg_names="ncurses6 ncurses5 ncurses ncursest6 ncursest5 \
420 ncursest curses"
Explorer095d1948b2024-09-19 06:27:31 +0800421
422if test "x$enable_unicode" = xyes; then
Explorer097ad9ec22024-10-29 07:59:30 +0800423 curses_pkg_names="ncursesw6 ncursesw5 ncursesw ncursestw6 ncursestw5 \
424 ncursestw $curses_pkg_names"
Explorer095d1948b2024-09-19 06:27:31 +0800425fi
426
427AC_ARG_WITH([curses],
428 [AS_HELP_STRING([--with-curses=NAME],
429 [select curses package NAME to link with; e.g. ncursesw6])],
430 [],
431 [with_curses=check])
432case $with_curses in
Explorer0952c9e3d2024-10-26 21:00:57 +0800433check|yes)
Explorer095d1948b2024-09-19 06:27:31 +0800434 : # No-op. Use default list.
435 ;;
Explorer0952c9e3d2024-10-26 21:00:57 +0800436no)
Explorer095d1948b2024-09-19 06:27:31 +0800437 AC_MSG_ERROR([bad value '$with_curses' for --with-curses option])
438 ;;
439*)
440 if test "x${CURSES_CFLAGS+y}${CURSES_LIBS+y}" = xyy; then
441 AC_MSG_WARN([ignoring --with-curses value due to override])
442 fi
443 curses_pkg_names=`echo "x$with_curses" | sed 's/^x\(lib\)\{0,1\}//'`
444 ;;
445esac
446
447# $1: C preprocessor and compiler flags for curses library
448# $2: linker flags for curses library
449htop_check_curses_capability () {
450 htop_curses_cflags=${CURSES_CFLAGS-"$1"}
451 htop_curses_libs=${CURSES_LIBS-"$2"}
452
453 echo "curses cflags${CURSES_CFLAGS+ (override)}: $htop_curses_cflags" >&AS_MESSAGE_LOG_FD
454 echo "curses libs${CURSES_LIBS+ (override)}: $htop_curses_libs" >&AS_MESSAGE_LOG_FD
455
456 htop_msg_linker_flags=$htop_curses_libs
457 if test "`echo x $htop_msg_linker_flags`" = x; then
458 htop_msg_linker_flags="(no linker flags)"
459 fi
460
461 htop_curses_status=0 # 0 for success; nonzero for failure
462
463 htop_save_CFLAGS=$CFLAGS
464 htop_save_LIBS=$LIBS
465 CFLAGS="$AM_CFLAGS $htop_curses_cflags $CFLAGS"
466 LIBS="$htop_curses_libs $LIBS"
467
468 # At this point we have not checked the name of curses header, so
469 # use forward declaration for the linking tests below.
470
Explorer09b4582992024-10-29 07:59:08 +0800471 # htop uses keypad(), but for ncurses implementation, the symbol is
472 # in "-ltinfo" and not "-lncurses".
Explorer09d5f24d22024-08-21 19:56:21 +0800473 # Check "-ltinfo" symbols first, as libncurses might require
474 # explicit "-ltinfo" to link (for internal dependency).
475 AC_MSG_CHECKING([for keypad in $htop_msg_linker_flags])
476 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer09d5f24d22024-08-21 19:56:21 +0800477/* int keypad(WINDOW* win, bool enable); */
Explorer09d5f24d22024-08-21 19:56:21 +0800478int keypad(void* win, int enable);
479 ]], [[
Explorer09b4582992024-10-29 07:59:08 +0800480static char dummy;
481keypad((void*)&dummy, 0);
Explorer09d5f24d22024-08-21 19:56:21 +0800482 ]])],
483 [AC_MSG_RESULT(yes)],
484 [AC_MSG_RESULT(no)
485 htop_curses_status=1])
486
Explorer095d1948b2024-09-19 06:27:31 +0800487 # htop calls refresh(), which might be implemented as a macro.
488 # It is more reliable to test linking with doupdate(), which
489 # refresh() would call internally.
Explorer09d5f24d22024-08-21 19:56:21 +0800490 if test "$htop_curses_status" -eq 0; then
491 AC_MSG_CHECKING([for doupdate in $htop_msg_linker_flags])
492 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer095d1948b2024-09-19 06:27:31 +0800493int doupdate(void);
Explorer09d5f24d22024-08-21 19:56:21 +0800494 ]], [[
Explorer095d1948b2024-09-19 06:27:31 +0800495doupdate();
Explorer09d5f24d22024-08-21 19:56:21 +0800496 ]])],
497 [AC_MSG_RESULT(yes)
498 htop_curses_capability=nonwide],
499 [AC_MSG_RESULT(no)
500 htop_curses_status=1])
501 fi
Explorer095d1948b2024-09-19 06:27:31 +0800502
Explorer093b66b202024-10-29 07:59:14 +0800503 # htop calls mvadd_wchnstr(), which might be implemented as a macro.
504 # It is more reliable to test linking with wadd_wchnstr().
Explorer095d1948b2024-09-19 06:27:31 +0800505 if test "x$htop_curses_status$enable_unicode" = x0yes; then
Explorer093b66b202024-10-29 07:59:14 +0800506 AC_MSG_CHECKING([for wadd_wchnstr in $htop_msg_linker_flags])
Explorer095d1948b2024-09-19 06:27:31 +0800507 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer093b66b202024-10-29 07:59:14 +0800508/* int wadd_wchnstr(WINDOW* win, const cchar_t* wchstr, int n); */
509int wadd_wchnstr(void* win, const void* wchstr, int n);
Explorer095d1948b2024-09-19 06:27:31 +0800510 ]], [[
Explorer093b66b202024-10-29 07:59:14 +0800511static char dummy1;
512static char dummy2;
513wadd_wchnstr((void*)&dummy1, (void*)&dummy2, 0);
Explorer095d1948b2024-09-19 06:27:31 +0800514 ]])],
515 [AC_MSG_RESULT(yes)
516 htop_curses_capability=wide],
517 [AC_MSG_RESULT(no)
518 htop_curses_status=1])
519 fi
520
521 if test "$htop_curses_status" -eq 0; then
522 AM_CFLAGS="$AM_CFLAGS $htop_curses_cflags"
523 if test "$htop_curses_capability" = wide; then
524 AC_DEFINE([HAVE_LIBNCURSESW], 1, [libncursesw is present])
525 else
526 AC_DEFINE([HAVE_LIBNCURSES], 1, [libcurses is present])
527 fi
528 else
529 LIBS=$htop_save_LIBS
530 fi
531 CFLAGS=$htop_save_CFLAGS
532 return "$htop_curses_status"
533} # htop_check_curses_capability
534
535htop_curses_capability=none
536
537if test "x${CURSES_CFLAGS+y}${CURSES_LIBS+y}" = xyy; then
538 curses_pkg_names=""
539 htop_check_curses_capability "$CURSES_CFLAGS" "$CURSES_LIBS"
540fi
541
542# Prioritize $PKG_CONFIG over ncurses*-config, as users might need to
543# cross-compile htop.
544if test "x$PKG_CONFIG" != x; then
545 pkg_config_static_flag=""
546 if test "$enable_static" = yes; then
547 pkg_config_static_flag=--static
548 fi
549
550 for curses_name in $curses_pkg_names; do
551 echo retrieving $curses_name information through $PKG_CONFIG >&AS_MESSAGE_LOG_FD
552 $PKG_CONFIG --exists --print-errors $curses_name >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD || continue
553
554 : # Resets "$?" to 0
555 htop_config_cflags=`$PKG_CONFIG --cflags $pkg_config_static_flag $curses_name 2>/dev/null` || continue
556 : # Resets "$?" to 0
557 htop_config_libs=`$PKG_CONFIG --libs $pkg_config_static_flag $curses_name 2>/dev/null` || continue
558
559 AC_MSG_RESULT([found $curses_name information through $PKG_CONFIG])
560
561 if htop_check_curses_capability "$htop_config_cflags" "$htop_config_libs"; then
562 break
563 fi
564 done
565fi
566
567case ${htop_curses_capability}-$enable_unicode in
568none-*|nonwide-yes)
569 for curses_name in $curses_pkg_names; do
570 echo retrieving $curses_name information through ${curses_name}-config >&AS_MESSAGE_LOG_FD
571
572 ${curses_name}-config --cflags >/dev/null 2>&AS_MESSAGE_LOG_FD || continue
573
574 : # Resets "$?" to 0
575 htop_config_cflags=`${curses_name}-config --cflags 2>/dev/null` || continue
576 : # Resets "$?" to 0
577 htop_config_libs=`${curses_name}-config --libs 2>/dev/null` || continue
578
579 AC_MSG_RESULT([found $curses_name information through ${curses_name}-config])
580
581 if htop_check_curses_capability "$htop_config_cflags" "$htop_config_libs"; then
582 break
583 fi
584 done
585 ;;
586esac
587
588case ${htop_curses_capability}-$enable_unicode in
589none-*|nonwide-yes)
Explorer09082b9772024-09-19 06:28:42 +0800590 if test "x$PKG_CONFIG" = x; then (
591 # Friendly warning to advise user to install pkg-config.
592 # The local variables get discarded when done.
593 list=""
594 echo "" >conftest.c
595 if test "$cross_compiling" != yes; then
596 # "-print-multi-directory" supported in GCC 3.0 or later
597 name=""
598 if $CC $CPPFLAGS $CFLAGS -print-multi-directory -E conftest.c >/dev/null 2>&1; then
599 name=`$CC $CPPFLAGS $CFLAGS -print-multi-directory -E conftest.c 2>/dev/null |
600 sed '/^ *#/ d; s/^\.$//; q'`
601 fi
602 list="/usr/lib${name}/pkgconfig $list"
603 case $host_os in
604 darwin*)
605 list="/opt/homebrew/Library/Homebrew/os/mac/pkgconfig $list"
606 ;;
607 freebsd*)
608 list="/usr/libdata/pkgconfig $list"
609 ;;
610 netbsd*)
611 list="/usr/pkg/lib/pkgconfig $list"
612 ;;
613 esac
614 fi
615 if test "x$host_alias" != x; then
616 list="/usr/lib/${host_alias}/pkgconfig $list"
617 fi
618 # "-print-multiarch" supported in GCC 4.6 or later
619 if $CC $CPPFLAGS $CFLAGS -print-multiarch -E conftest.c >/dev/null 2>&1; then
620 name=`$CC $CPPFLAGS $CFLAGS -print-multiarch -E conftest.c 2>/dev/null |
621 sed '/^ *#/ d; q'`
622 if test "x$name" != x; then
623 list="/usr/lib/${name}/pkgconfig $list"
624 fi
625 fi
626 rm -f conftest.*
627
628 for d in $list; do
629 result=`find "$d" -name '*curses*.pc' 2>/dev/null | sed '1 q'`
630 if test "x$result" != x; then
Explorer09d464ad12024-10-28 17:04:21 +0800631 echo detected a .pc file: "$result" >&AS_MESSAGE_LOG_FD
Explorer09082b9772024-09-19 06:28:42 +0800632 AC_MSG_WARN([your system supports pkg-config; installing pkg-config is recommended before configuring htop])
Explorer0976e7dd42024-10-29 07:57:54 +0800633 m4_ifdef([PKG_PROG_PKG_CONFIG], [], [
634 AC_MSG_WARN([this configure script would also need to be regenerated])
635 ])
Explorer09082b9772024-09-19 06:28:42 +0800636 break
637 fi
638 done
639 ) fi
640
Explorer095d1948b2024-09-19 06:27:31 +0800641 # OpenBSD and Solaris are known to not provide '*curses*.pc' files.
642 AC_MSG_RESULT([no curses information found through '*-config' utilities; will guess the linker flags])
643 for curses_name in $curses_pkg_names; do
644 if htop_check_curses_capability "" "-l$curses_name"; then
645 break
646 fi
Explorer09e3bdb102024-10-29 07:59:30 +0800647 # For ncurses implementation, an extra terminfo library might be
648 # needed. Guess the terminfo library name based on the ncurses
649 # library file name (e.g. "-ltinfow" for "-lncursesw"), before
650 # trying the "-ltinfo" name.
651 tinfo_name=`echo x$curses_name | sed 's/^xncurses/tinfo/p; d'`
652 case x$tinfo_name in
653 x|xtinfo)
654 ;;
655 *)
656 if htop_check_curses_capability "" "-l$curses_name -l$tinfo_name"; then
657 break
658 fi
659 ;;
660 esac
Explorer09d5f24d22024-08-21 19:56:21 +0800661 if htop_check_curses_capability "" "-l$curses_name -ltinfo"; then
662 break
663 fi
Explorer095d1948b2024-09-19 06:27:31 +0800664 done
665 ;;
666esac
667
668case ${htop_curses_capability}-$enable_unicode in
669nonwide-yes)
670 AC_MSG_ERROR([cannot find required ncursesw library; you may want to use --disable-unicode])
671 ;;
672none-*)
673 AC_MSG_ERROR([cannot find required curses/ncurses library])
674 ;;
675esac
676
677htop_save_CFLAGS=$CFLAGS
678CFLAGS="$AM_CFLAGS $CFLAGS"
Explorer09a2d90f42024-10-29 07:59:23 +0800679
Explorer095d1948b2024-09-19 06:27:31 +0800680if test "x$enable_unicode" = xyes; then
Christian Göttsche759a3402021-01-22 19:14:55 +0100681 AC_CHECK_HEADERS([ncursesw/curses.h], [],
682 [AC_CHECK_HEADERS([ncurses/ncurses.h], [],
683 [AC_CHECK_HEADERS([ncurses/curses.h], [],
684 [AC_CHECK_HEADERS([ncurses.h], [],
685 [AC_MSG_ERROR([can not find required ncurses header file])])])])])
Christian Göttscheead978b2020-12-07 15:30:56 +0100686
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530687 AC_CHECK_HEADERS([ncursesw/term.h], [],
688 [AC_CHECK_HEADERS([ncurses/term.h], [],
689 [AC_CHECK_HEADERS([term.h], [],
690 [AC_MSG_ERROR([can not find required term header file])])])])
Hisham Muhammad8fa33dc2008-03-09 02:33:23 +0000691else
Christian Göttsche759a3402021-01-22 19:14:55 +0100692 AC_CHECK_HEADERS([curses.h], [],
693 [AC_CHECK_HEADERS([ncurses/curses.h], [],
694 [AC_CHECK_HEADERS([ncurses/ncurses.h], [],
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530695 [AC_CHECK_HEADERS([ncurses.h], [],
Christian Göttsche759a3402021-01-22 19:14:55 +0100696 [AC_MSG_ERROR([can not find required ncurses header file])])])])])
Christian Göttscheead978b2020-12-07 15:30:56 +0100697
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530698 AC_CHECK_HEADERS([ncurses/term.h], [],
699 [AC_CHECK_HEADERS([term.h], [],
700 [AC_MSG_ERROR([can not find required term header file])])])
Hisham Muhammad4c51ad02007-08-10 05:07:14 +0000701fi
Explorer09a2d90f42024-10-29 07:59:23 +0800702
703CFLAGS="-I$srcdir $CFLAGS"
704
705# Check for things that might be macros.
706# "stdscr" is a macro in ncursest (reentrant version of ncurses).
707AC_MSG_CHECKING([whether the curses header works])
708AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer09f0237902024-10-29 07:59:30 +0800709/* Checks if the "bool" definition in curses is ISO C compatible */
710#include <stdbool.h>
711
Explorer09a2d90f42024-10-29 07:59:23 +0800712#include "ProvideCurses.h"
713 ]], [[
Explorer09f0237902024-10-29 07:59:30 +0800714keypad(stdscr, false);
Explorer09a2d90f42024-10-29 07:59:23 +0800715
716refresh();
717
718#if defined(HAVE_LIBNCURSESW)
719{
720 static cchar_t dummy;
721 mvadd_wchnstr(0, 0, &dummy, 0);
722}
723#endif
724 ]])],
725 [AC_MSG_RESULT(yes)],
726 [AC_MSG_RESULT(no)
727 AC_MSG_FAILURE([there are problems with the curses header])]
728)
729
Explorer095d1948b2024-09-19 06:27:31 +0800730CFLAGS=$htop_save_CFLAGS
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530731
Christian Göttsche575edff2021-01-22 19:14:59 +0100732if test "$enable_static" = yes; then
733 AC_SEARCH_LIBS([Gpm_GetEvent], [gpm])
734fi
Christian Göttscheee9e7ed2021-05-20 18:27:10 +0200735if test "$my_htop_platform" = "solaris"; then
736 # On OmniOS /usr/include/sys/regset.h redefines ERR to 13 - \r, breaking the Enter key.
Nathan Scottca06e682021-09-08 12:11:51 +1000737 # Since ncurses macros use the ERR macro, we can not use another name.
Christian Göttscheee9e7ed2021-05-20 18:27:10 +0200738 AC_DEFINE([ERR], [(-1)], [Predefine ncurses macro.])
739fi
Benny Baumann18e3fd52021-07-04 16:50:41 +0200740AC_CHECK_FUNCS( [set_escdelay] )
nia2ab8fb82021-07-14 20:17:13 +0200741AC_CHECK_FUNCS( [getmouse] )
Benny Baumann04d0a542024-12-09 22:18:08 +0100742AC_DEFINE([NCURSES_ENABLE_STDBOOL_H], [1], [Define to enable stdbool.h in ncurses])
Hisham Muhammad4c51ad02007-08-10 05:07:14 +0000743
gmbroome697f5bb2018-03-02 16:20:46 -0500744
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200745AC_ARG_ENABLE([affinity],
746 [AS_HELP_STRING([--enable-affinity],
747 [enable sched_setaffinity and sched_getaffinity for affinity support, conflicts with hwloc @<:@default=check@:>@])],
748 [],
749 [enable_affinity=check])
750if test "x$enable_affinity" = xcheck; then
751 if test "x$enable_hwloc" = xyes; then
752 enable_affinity=no
753 else
754 AC_MSG_CHECKING([for usable sched_setaffinity])
755 AC_RUN_IFELSE([
756 AC_LANG_PROGRAM([[
757 #include <sched.h>
758 #include <errno.h>
759 static cpu_set_t cpuset;
760 ]], [[
761 CPU_ZERO(&cpuset);
762 sched_setaffinity(0, sizeof(cpu_set_t), &cpuset);
763 if (errno == ENOSYS) return 1;
764 ]])],
765 [enable_affinity=yes
766 AC_MSG_RESULT([yes])],
767 [enable_affinity=no
768 AC_MSG_RESULT([no])],
Explorer0947ae9662023-07-29 03:11:54 +0800769 [AC_MSG_RESULT([assume yes (cross compiling)])])
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200770 fi
771fi
772if test "x$enable_affinity" = xyes; then
773 if test "x$enable_hwloc" = xyes; then
774 AC_MSG_ERROR([--enable-hwloc and --enable-affinity are mutual exclusive. Specify at most one of them.])
775 fi
776 AC_DEFINE([HAVE_AFFINITY], [1], [Define if sched_setaffinity and sched_getaffinity are to be used.])
777fi
778
779
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200780AC_ARG_ENABLE([unwind],
781 [AS_HELP_STRING([--enable-unwind],
782 [enable unwind support for printing backtraces; requires libunwind @<:@default=check@:>@])],
783 [],
784 [enable_unwind=check])
785case "$enable_unwind" in
786 check)
787 enable_unwind=yes
788 if test "$enable_static" = yes; then
789 AC_CHECK_LIB([lzma], [lzma_index_buffer_decode])
790 fi
791 AC_CHECK_LIB([unwind], [backtrace], [], [enable_unwind=no])
Christian Göttsche63880332021-12-14 17:36:57 +0100792 AC_CHECK_HEADERS([libunwind.h], [], [
793 old_CFLAGS="$CFLAGS"
794 CFLAGS="$CFLAGS -I/usr/include/libunwind"
795 AC_CHECK_HEADERS([libunwind/libunwind.h], [], [
796 enable_unwind=no
797 CFLAGS="$old_CFLAGS"
798 ])
799 ])
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200800 ;;
801 no)
802 ;;
803 yes)
804 AC_CHECK_LIB([unwind], [backtrace], [], [AC_MSG_ERROR([can not find required library libunwind])])
Christian Göttsche63880332021-12-14 17:36:57 +0100805 AC_CHECK_HEADERS([libunwind.h], [], [
Benny Baumann5c7cb912023-11-28 17:42:04 +0100806 AM_CFLAGS="$AM_CFLAGS -I/usr/include/libunwind"
Christian Göttsche63880332021-12-14 17:36:57 +0100807 AC_CHECK_HEADERS([libunwind/libunwind.h], [], [AC_MSG_ERROR([can not find required header file libunwind.h])])
808 ])
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200809 ;;
810 *)
811 AC_MSG_ERROR([bad value '$enable_unwind' for --enable-unwind])
812 ;;
813esac
814if test "x$enable_unwind" = xno; then
815 # Fall back to backtrace(3) and add -lexecinfo if needed
816 AC_SEARCH_LIBS([backtrace], [execinfo])
817fi
818
819
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100820AC_ARG_ENABLE([hwloc],
821 [AS_HELP_STRING([--enable-hwloc],
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200822 [enable hwloc support for CPU affinity; disables affinity support; requires libhwloc @<:@default=no@:>@])],
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100823 [],
824 [enable_hwloc=no])
825case "$enable_hwloc" in
826 no)
827 ;;
828 yes)
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200829 m4_ifdef([PKG_PROG_PKG_CONFIG], [
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200830 PKG_CHECK_MODULES(HWLOC, hwloc, [
Benny Baumann5c7cb912023-11-28 17:42:04 +0100831 AM_CFLAGS="$AM_CFLAGS $HWLOC_CFLAGS"
Christian Göttschec8a61852023-04-05 01:21:14 +0200832 LIBS="$LIBS $HWLOC_LIBS"
Explorer0947ae9662023-07-29 03:11:54 +0800833 AC_DEFINE([HAVE_LIBHWLOC], [1], [Define to 1 if you have the 'hwloc' library (-lhwloc).])
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200834 ], [
835 AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [AC_MSG_ERROR([can not find required library libhwloc])])
836 AC_CHECK_HEADERS([hwloc.h], [], [AC_MSG_ERROR([can not find require header file hwloc.h])])
837 ])
838 ], [
839 AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [AC_MSG_ERROR([can not find required library libhwloc])])
840 AC_CHECK_HEADERS([hwloc.h], [], [AC_MSG_ERROR([can not find require header file hwloc.h])])
841 ])
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100842 ;;
843 *)
844 AC_MSG_ERROR([bad value '$enable_hwloc' for --enable-hwloc])
845 ;;
846esac
Christian Göttsche005c4d12020-09-08 16:25:22 +0200847
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200848
Nathan Scott5b50ae32021-03-02 15:58:11 +1100849AC_ARG_WITH([os-release],
850 [AS_HELP_STRING([--with-os-release=FILE],
Christian Göttsche8ba4ef32021-03-12 16:37:17 +0100851 [location of an os-release file @<:@default=/etc/os-release@:>@])],
Nathan Scott5b50ae32021-03-02 15:58:11 +1100852 [],
853 [with_os_release=/etc/os-release])
Christian Göttsche8ba4ef32021-03-12 16:37:17 +0100854if test -n "$with_os_release" && test ! -f "$with_os_release"; then
Nathan Scott5b50ae32021-03-02 15:58:11 +1100855 if test -f "/usr/lib/os-release"; then
856 with_os_release="/usr/lib/os-release"
857 fi
858fi
859AC_DEFINE_UNQUOTED([OSRELEASEFILE], ["$with_os_release"], [File with OS release details.])
860
Nathan Scott1a7b6d42024-07-22 08:51:29 +1000861AC_ARG_WITH([config],
862 [AS_HELP_STRING([--with-config=DIR],
Explorer09c802dc42024-09-19 06:37:00 +0800863 [configuration path @<:@default=/.config@:>@])],
Nathan Scott1a7b6d42024-07-22 08:51:29 +1000864 [],
865 [with_config="/.config"])
866dnl Performance Co-Pilot configuration location to prevent overwrite
867if test "$my_htop_platform" = pcp -a "$with_config" = /.config; then
868 with_config="/.pcp"
869elif test -z "$with_config"; then
870 AC_MSG_ERROR([bad empty value for --with-config option])
871fi
872AC_DEFINE_UNQUOTED([CONFIGDIR], ["$with_config"], [Configuration path.])
873
Christian Göttschef3623b72021-01-22 19:14:50 +0100874# ----------------------------------------------------------------------
875
876
877# ----------------------------------------------------------------------
878# Checks for Linux features and flags.
879# ----------------------------------------------------------------------
880
881AC_ARG_WITH([proc],
882 [AS_HELP_STRING([--with-proc=DIR],
883 [location of a Linux-compatible proc filesystem @<:@default=/proc@:>@])],
884 [],
885 [with_proc=/proc])
886if test -z "$with_proc"; then
887 AC_MSG_ERROR([bad empty value for --with-proc option])
888fi
889AC_DEFINE_UNQUOTED([PROCDIR], ["$with_proc"], [Path of proc filesystem.])
890
891
892AC_ARG_ENABLE([openvz],
893 [AS_HELP_STRING([--enable-openvz],
894 [enable OpenVZ support @<:@default=no@:>@])],
895 [],
896 [enable_openvz=no])
897if test "x$enable_openvz" = xyes; then
898 AC_DEFINE([HAVE_OPENVZ], [1], [Define if openvz support enabled.])
899fi
900
901
902AC_ARG_ENABLE([vserver],
903 [AS_HELP_STRING([--enable-vserver],
904 [enable VServer support @<:@default=no@:>@])],
905 [],
906 [enable_vserver=no])
907if test "x$enable_vserver" = xyes; then
Christian Göttsche284f8c52021-09-02 22:32:46 +0200908 AC_DEFINE([HAVE_VSERVER], [1], [Define if VServer support enabled.])
Christian Göttschef3623b72021-01-22 19:14:50 +0100909fi
910
911
912AC_ARG_ENABLE([ancient_vserver],
913 [AS_HELP_STRING([--enable-ancient-vserver],
914 [enable ancient VServer support (implies --enable-vserver) @<:@default=no@:>@])],
915 [],
916 [enable_ancient_vserver=no])
917if test "x$enable_ancient_vserver" = xyes; then
Christian Göttsche284f8c52021-09-02 22:32:46 +0200918 if test "x$enable_vserver" != xyes; then
919 enable_vserver=implied
920 fi
921 AC_DEFINE([HAVE_VSERVER], [1], [Define if VServer support enabled.])
922 AC_DEFINE([HAVE_ANCIENT_VSERVER], [1], [Define if ancient vserver support enabled.])
Christian Göttschef3623b72021-01-22 19:14:50 +0100923fi
924
925
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100926AC_ARG_ENABLE([capabilities],
927 [AS_HELP_STRING([--enable-capabilities],
928 [enable Linux capabilities support; requires libcap @<:@default=check@:>@])],
929 [],
930 [enable_capabilities=check])
931case "$enable_capabilities" in
932 no)
933 ;;
934 check)
935 enable_capabilities=yes
936 AC_CHECK_LIB([cap], [cap_init], [], [enable_capabilities=no])
937 AC_CHECK_HEADERS([sys/capability.h], [], [enable_capabilities=no])
938 ;;
939 yes)
Christian Göttsche759a3402021-01-22 19:14:55 +0100940 AC_CHECK_LIB([cap], [cap_init], [], [AC_MSG_ERROR([can not find required library libcap])])
941 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 +0100942 ;;
943 *)
944 AC_MSG_ERROR([bad value '$enable_capabilities' for --enable-capabilities])
945 ;;
946esac
Christian Göttschef4404ef2020-09-02 14:39:25 +0200947
Christian Göttschef3623b72021-01-22 19:14:50 +0100948
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100949AC_ARG_ENABLE([delayacct],
950 [AS_HELP_STRING([--enable-delayacct],
951 [enable Linux delay accounting support; requires pkg-config, libnl-3 and libnl-genl-3 @<:@default=check@:>@])],
952 [],
953 [enable_delayacct=check])
954case "$enable_delayacct" in
955 no)
956 ;;
957 check)
Christian Göttsche69cfaf22021-05-16 20:01:25 +0200958 if test "$my_htop_platform" != linux; then
959 enable_delayacct=no
960 elif test "$enable_static" = yes; then
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100961 enable_delayacct=no
Christian Göttsche575edff2021-01-22 19:14:59 +0100962 else
Christian Göttsche24b15132024-03-30 13:47:14 +0100963 old_CFLAGS="$CFLAGS"
964 CFLAGS="$CFLAGS -I/usr/include/libnl3"
965 AC_CHECK_HEADERS([netlink/attr.h netlink/handlers.h netlink/msg.h], [enable_delayacct=yes], [enable_delayacct=no])
966 CFLAGS="$old_CFLAGS"
Christian Göttsche575edff2021-01-22 19:14:59 +0100967 fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100968 ;;
969 yes)
Christian Göttsche24b15132024-03-30 13:47:14 +0100970 old_CFLAGS="$CFLAGS"
971 CFLAGS="$CFLAGS -I/usr/include/libnl3"
972 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])])
973 CFLAGS="$old_CFLAGS"
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100974 ;;
975 *)
976 AC_MSG_ERROR([bad value '$enable_delayacct' for --enable-delayacct])
977 ;;
978esac
Christian Göttsche24b15132024-03-30 13:47:14 +0100979if test "$enable_delayacct" = yes; then
980 AC_DEFINE([HAVE_DELAYACCT], [1], [Define if delay accounting support should be enabled.])
981 AM_CFLAGS="$AM_CFLAGS -I/usr/include/libnl3"
982fi
Christian Göttschea782ef32024-03-30 13:47:10 +0100983AM_CONDITIONAL([HAVE_DELAYACCT], [test "$enable_delayacct" = yes])
André Carvalhob7b66b72017-12-04 00:15:29 -0200984
Christian Göttschef3623b72021-01-22 19:14:50 +0100985
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100986AC_ARG_ENABLE([sensors],
987 [AS_HELP_STRING([--enable-sensors],
988 [enable libsensors support for reading temperature data; requires only libsensors headers at compile time, at runtime libsensors is loaded via dlopen @<:@default=check@:>@])],
989 [],
990 [enable_sensors=check])
991case "$enable_sensors" in
992 no)
993 ;;
994 check)
995 enable_sensors=yes
Christian Göttsche575edff2021-01-22 19:14:59 +0100996 if test "$enable_static" = yes; then
997 AC_CHECK_LIB([sensors], [sensors_init], [], [enable_sensors=no])
998 fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100999 AC_CHECK_HEADERS([sensors/sensors.h], [], [enable_sensors=no])
1000 ;;
1001 yes)
Christian Göttsche575edff2021-01-22 19:14:59 +01001002 if test "$enable_static" = yes; then
1003 AC_CHECK_LIB([sensors], [sensors_init], [], [AC_MSG_ERROR([can not find required library libsensors])])
1004 fi
1005 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 +01001006 ;;
1007 *)
1008 AC_MSG_ERROR([bad value '$enable_sensors' for --enable-sensors])
1009 ;;
1010esac
Christian Göttschefd2a0cf2020-12-22 20:02:01 +01001011if test "$enable_sensors" = yes || test "$my_htop_platform" = freebsd; then
1012 AC_DEFINE([BUILD_WITH_CPU_TEMP], [1], [Define if CPU temperature option should be enabled.])
1013fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001014
Christian Göttschef3623b72021-01-22 19:14:50 +01001015# ----------------------------------------------------------------------
1016
1017
1018# ----------------------------------------------------------------------
1019# Checks for compiler warnings.
1020# ----------------------------------------------------------------------
Christian Göttsche1b225cd2020-09-10 19:56:33 +02001021
Benny Baumann5c7cb912023-11-28 17:42:04 +01001022AM_CFLAGS="$AM_CFLAGS\
Christian Göttschef4602f72020-09-08 14:25:46 +02001023 -Wall\
1024 -Wcast-align\
Christian Göttschedb472072020-10-04 14:30:35 +02001025 -Wcast-qual\
Christian Göttschef4602f72020-09-08 14:25:46 +02001026 -Wextra\
Benny Baumannba0fca12020-09-18 16:58:03 +02001027 -Wfloat-equal\
Christian Göttschec150e4b2020-12-18 15:49:37 +01001028 -Wformat=2\
Christian Göttsche4dadbe32021-01-21 19:49:07 +01001029 -Winit-self\
Christian Göttschef4602f72020-09-08 14:25:46 +02001030 -Wmissing-format-attribute\
1031 -Wmissing-noreturn\
Christian Göttsche4e282eb2020-09-25 14:03:55 +02001032 -Wmissing-prototypes\
Christian Göttschef4602f72020-09-08 14:25:46 +02001033 -Wpointer-arith\
1034 -Wshadow\
1035 -Wstrict-prototypes\
1036 -Wundef\
1037 -Wunused\
1038 -Wwrite-strings"
1039
Christian Göttschef3623b72021-01-22 19:14:50 +01001040dnl https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
1041AC_DEFUN([AX_CHECK_COMPILE_FLAG],
Christian Göttsche38b6a012021-01-22 19:14:53 +01001042[
Christian Göttschef3623b72021-01-22 19:14:50 +01001043AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
1044AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
1045 ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
1046 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
1047 AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
1048 [AS_VAR_SET(CACHEVAR,[yes])],
1049 [AS_VAR_SET(CACHEVAR,[no])])
1050 _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
1051AS_VAR_IF(CACHEVAR,yes,
1052 [m4_default([$2], :)],
1053 [m4_default([$3], :)])
1054AS_VAR_POPDEF([CACHEVAR])dnl
1055])dnl AX_CHECK_COMPILE_FLAGS
1056
Christian Göttsche970885e2021-08-14 11:21:54 +02001057AX_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 +02001058AX_CHECK_COMPILE_FLAG([-Wimplicit-int-conversion], [AM_CFLAGS="$AM_CFLAGS -Wimplicit-int-conversion"], , [-Werror])
1059AX_CHECK_COMPILE_FLAG([-Wnull-dereference], [AM_CFLAGS="$AM_CFLAGS -Wnull-dereference"], , [-Werror])
Benny Baumann2cde4a72020-09-18 19:32:41 +02001060
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001061AC_ARG_ENABLE([werror],
1062 [AS_HELP_STRING([--enable-werror],
1063 [Treat warnings as errors @<:@default=no@:>@])],
1064 [],
1065 [enable_werror=no])
1066if test "x$enable_werror" = xyes; then
1067 AM_CFLAGS="$AM_CFLAGS -Werror"
1068fi
1069
1070AC_ARG_ENABLE([debug],
1071 [AS_HELP_STRING([--enable-debug],
Daniel Lange135efd52021-02-16 11:22:02 +01001072 [Enable compiling with maximum debug info, asserts and internal sanity checks @<:@default=no@:>@])],
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001073 [],
1074 [enable_debug=no])
1075if test "x$enable_debug" != xyes; then
1076 AM_CPPFLAGS="$AM_CPPFLAGS -DNDEBUG"
Explorer0993d76fd2023-07-31 05:05:43 +08001077
1078 AC_COMPILE_IFELSE([
1079 AC_LANG_SOURCE([[
1080#ifdef __SUPPORT_SNAN__
1081#error "signaling NaN support not recommended"
1082#endif
1083 ]])],
1084 :,
1085 [warning_msg="signaling NaN support is enabled; not recommended for htop"
1086 case "$CC" in
1087 *gcc*)
1088 warning_msg="$warning_msg (use '-fno-signaling-nans' compiler flag to disable)"
1089 ;;
1090 esac
1091 AC_MSG_WARN([$warning_msg])
1092 ])
Daniel Lange135efd52021-02-16 11:22:02 +01001093else
1094 AM_CPPFLAGS="$AM_CPPFLAGS -ggdb3"
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001095fi
Christian Göttscheb7f63292020-09-17 22:23:05 +02001096
Christian Göttschef3623b72021-01-22 19:14:50 +01001097
Christian Göttsche57254cd2020-08-21 10:37:20 +02001098AC_SUBST([AM_CFLAGS])
Christian Göttscheb7f63292020-09-17 22:23:05 +02001099AC_SUBST([AM_CPPFLAGS])
1100
Christian Göttschef3623b72021-01-22 19:14:50 +01001101# ----------------------------------------------------------------------
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001102
Christian Göttschef3623b72021-01-22 19:14:50 +01001103
1104# ----------------------------------------------------------------------
Hisham Muhammad300af4b2014-11-19 23:17:16 -02001105# We're done, let's go!
1106# ----------------------------------------------------------------------
Christian Göttschef3623b72021-01-22 19:14:50 +01001107
Daniel Lange1f242502025-01-01 02:45:10 +01001108AC_DEFINE_UNQUOTED([COPYRIGHT], ["(C) 2004-2019 Hisham Muhammad. (C) 2020-2025 htop dev team."], [Copyright message.])
Christian Göttschef3623b72021-01-22 19:14:50 +01001109
Hisham Muhammada75161f2014-11-24 20:11:33 -02001110AM_CONDITIONAL([HTOP_LINUX], [test "$my_htop_platform" = linux])
Hisham Muhammad8915b292014-11-27 16:27:34 -02001111AM_CONDITIONAL([HTOP_FREEBSD], [test "$my_htop_platform" = freebsd])
Diederik de Grootb258d6e2017-04-19 16:12:17 +02001112AM_CONDITIONAL([HTOP_DRAGONFLYBSD], [test "$my_htop_platform" = dragonflybsd])
fraggerfox4b49de42021-03-15 13:14:39 +05301113AM_CONDITIONAL([HTOP_NETBSD], [test "$my_htop_platform" = netbsd])
Michael McConvillea9a5a532015-09-18 00:46:48 -04001114AM_CONDITIONAL([HTOP_OPENBSD], [test "$my_htop_platform" = openbsd])
David Hunt70e7c8d2015-07-12 13:47:43 -05001115AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin])
gmbroome697f5bb2018-03-02 16:20:46 -05001116AM_CONDITIONAL([HTOP_SOLARIS], [test "$my_htop_platform" = solaris])
Nathan Scottc14a45b2021-02-17 14:43:56 +11001117AM_CONDITIONAL([HTOP_PCP], [test "$my_htop_platform" = pcp])
Hisham Muhammada75161f2014-11-24 20:11:33 -02001118AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported])
Christian Göttsche38b6a012021-01-22 19:14:53 +01001119
Hisham Muhammadeb229d92014-11-24 18:55:03 -02001120AC_SUBST(my_htop_platform)
Daniel Langefc2377f2021-08-14 10:35:11 +02001121AC_CONFIG_FILES([Makefile htop.1])
Hisham Muhammadd6231ba2006-03-04 18:16:49 +00001122AC_OUTPUT
Hisham Muhammadc39f18a2017-07-10 20:14:25 -03001123
Christian Göttschef3623b72021-01-22 19:14:50 +01001124if test "$my_htop_platform" = unsupported; then
Hisham Muhammadc39f18a2017-07-10 20:14:25 -03001125 echo ""
1126 echo "****************************************************************"
1127 echo "WARNING! This platform is not currently supported by htop."
1128 echo ""
1129 echo "The code will build, but it will produce a dummy version of htop"
1130 echo "which shows no processes, using the files from the unsupported/"
1131 echo "directory. This is meant to be a skeleton, to be used as a"
1132 echo "starting point if you are porting htop to a new platform."
1133 echo "****************************************************************"
1134 echo ""
1135fi
Christian Göttsche3b084db2020-08-28 12:10:31 +02001136
1137AC_MSG_RESULT([
1138 ${PACKAGE_NAME} ${VERSION}
1139
Benny Baumannd74e67d2025-03-03 19:06:52 +01001140 platform: $my_htop_platform ($host_os)
Nathan Scott5b50ae32021-03-02 15:58:11 +11001141 os-release file: $with_os_release
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001142 (Linux) proc directory: $with_proc
Christian Göttscheffd90c22020-10-05 12:29:31 +02001143 (Linux) openvz: $enable_openvz
Christian Göttscheffd90c22020-10-05 12:29:31 +02001144 (Linux) vserver: $enable_vserver
1145 (Linux) ancient vserver: $enable_ancient_vserver
Christian Göttscheffd90c22020-10-05 12:29:31 +02001146 (Linux) delay accounting: $enable_delayacct
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001147 (Linux) sensors: $enable_sensors
1148 (Linux) capabilities: $enable_capabilities
Christian Göttscheffd90c22020-10-05 12:29:31 +02001149 unicode: $enable_unicode
Christian Göttsche1fb0c722021-06-13 11:29:39 +02001150 affinity: $enable_affinity
Christian Göttsche29e1fcf2021-05-16 20:45:09 +02001151 unwind: $enable_unwind
Daniel Lange309f1d72020-11-16 13:29:37 +01001152 hwloc: $enable_hwloc
Daniel Langea8a723f2020-11-16 17:01:51 +01001153 debug: $enable_debug
Christian Göttsche575edff2021-01-22 19:14:59 +01001154 static: $enable_static
Christian Göttsche3b084db2020-08-28 12:10:31 +02001155])