blob: 54f6e0e28f9b57016da1f553eae7a2a8aa818480 [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
Benny Baumanna98fc472023-11-29 20:39:25 +010071# Activate some more of the missing global defines
72AC_SYS_LARGEFILE
73
Hisham Muhammadeb229d92014-11-24 18:55:03 -020074# ----------------------------------------------------------------------
Hisham Muhammadeb229d92014-11-24 18:55:03 -020075
Christian Göttschef3623b72021-01-22 19:14:50 +010076
Hisham Muhammad300af4b2014-11-19 23:17:16 -020077# ----------------------------------------------------------------------
Christian Göttschef3623b72021-01-22 19:14:50 +010078# Checks for compiler.
Hisham Muhammad300af4b2014-11-19 23:17:16 -020079# ----------------------------------------------------------------------
Hisham Muhammade46f1422006-07-12 01:15:14 +000080
Christian Göttschef3623b72021-01-22 19:14:50 +010081AC_PROG_CC
82AM_PROG_CC_C_O
Christian Göttschea5e2eff2021-08-25 10:23:30 +020083m4_version_prereq([2.70], [], [AC_PROG_CC_C99])
Christian Göttsche38b6a012021-01-22 19:14:53 +010084AS_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 +010085AM_CFLAGS="-std=c99 -pedantic"
Hisham Muhammadd6231ba2006-03-04 18:16:49 +000086
Christian Göttschef3623b72021-01-22 19:14:50 +010087# ----------------------------------------------------------------------
88
89
90# ----------------------------------------------------------------------
Christian Göttsche575edff2021-01-22 19:14:59 +010091# Checks for static build.
92# ----------------------------------------------------------------------
93
94AC_ARG_ENABLE([static],
95 [AS_HELP_STRING([--enable-static],
96 [build a static htop binary @<:@default=no@:>@])],
97 [],
98 [enable_static=no])
99case "$enable_static" in
100 no)
101 ;;
102 yes)
103 AC_DEFINE([BUILD_STATIC], [1], [Define if building static binary.])
104 CFLAGS="$CFLAGS -static"
105 LDFLAGS="$LDFLAGS -static"
106 ;;
107 *)
108 AC_MSG_ERROR([bad value '$enable_static' for --enable-static option])
109 ;;
110esac
111
112# ----------------------------------------------------------------------
113
Nathan Scottc14a45b2021-02-17 14:43:56 +1100114# ----------------------------------------------------------------------
115# Checks for a PCP-based htop build. (https://pcp.io)
116# ----------------------------------------------------------------------
117
118AC_ARG_ENABLE([pcp],
119 [AS_HELP_STRING([--enable-pcp],
Nathan Scott9ce95572021-04-14 11:34:47 +1000120 [build a pcp-htop binary @<:@default=no@:>@])],
Nathan Scottc14a45b2021-02-17 14:43:56 +1100121 [],
122 [enable_pcp=no])
123case "$enable_pcp" in
124 no)
125 ;;
126 yes)
127 AC_CHECK_HEADERS([pcp/pmapi.h], [my_htop_platform=pcp],
Benny Baumann92324d32021-06-13 19:46:13 +0200128 [AC_MSG_ERROR([can not find PCP header file])])
Nathan Scott94d37982021-06-08 09:46:02 +1000129 AC_SEARCH_LIBS([pmNewContext], [pcp], [], [AC_MSG_ERROR([can not find PCP library])])
130 AC_DEFINE([HTOP_PCP], [1], [Define if building pcp-htop binary.])
Daniel Langefc2377f2021-08-14 10:35:11 +0200131 AC_CONFIG_FILES([pcp-htop.5])
Nathan Scottc14a45b2021-02-17 14:43:56 +1100132 ;;
133 *)
Nathan Scott6bb59f82021-02-19 14:13:27 +1100134 AC_MSG_ERROR([bad value '$enable_pcp' for --enable-pcp option])
Nathan Scottc14a45b2021-02-17 14:43:56 +1100135 ;;
136esac
137
138# ----------------------------------------------------------------------
139
Christian Göttsche575edff2021-01-22 19:14:59 +0100140
141# ----------------------------------------------------------------------
Christian Göttschef3623b72021-01-22 19:14:50 +0100142# Checks for generic header files.
143# ----------------------------------------------------------------------
144
145AC_HEADER_DIRENT
Christian Göttschea5e2eff2021-08-25 10:23:30 +0200146m4_version_prereq([2.70], [AC_CHECK_INCLUDES_DEFAULT], [AC_HEADER_STDC])
Christian Göttschef3623b72021-01-22 19:14:50 +0100147AC_CHECK_HEADERS([ \
148 stdlib.h \
149 string.h \
150 strings.h \
151 sys/param.h \
152 sys/time.h \
Nathan Scott5b50ae32021-03-02 15:58:11 +1100153 sys/utsname.h \
Christian Göttschef3623b72021-01-22 19:14:50 +0100154 unistd.h
Christian Göttsche759a3402021-01-22 19:14:55 +0100155 ], [], [AC_MSG_ERROR([can not find required generic header files])])
Christian Göttschef3623b72021-01-22 19:14:50 +0100156
157AC_HEADER_MAJOR
158dnl glibc 2.25 deprecates 'major' and 'minor' in <sys/types.h> and requires to
159dnl include <sys/sysmacros.h>. However the logic in AC_HEADER_MAJOR has not yet
160dnl been updated in Autoconf 2.69, so use a workaround:
161m4_version_prereq([2.70], [],
162[if test "x$ac_cv_header_sys_mkdev_h" != xyes; then
163 AC_CHECK_HEADER([sys/sysmacros.h], [AC_DEFINE([MAJOR_IN_SYSMACROS], [1],
Explorer0947ae9662023-07-29 03:11:54 +0800164 [Define to 1 if 'major', 'minor', and 'makedev' are declared in <sys/sysmacros.h>.])])
Christian Göttschef3623b72021-01-22 19:14:50 +0100165fi])
166
167# Optional Section
168
169AC_CHECK_HEADERS([execinfo.h])
170
171if test "$my_htop_platform" = darwin; then
172 AC_CHECK_HEADERS([mach/mach_time.h])
173fi
174
175# ----------------------------------------------------------------------
176
177
178# ----------------------------------------------------------------------
179# Checks for typedefs, structures, and compiler characteristics.
180# ----------------------------------------------------------------------
181
Benny Baumanna98fc472023-11-29 20:39:25 +0100182AC_TYPE_MBSTATE_T
183AC_TYPE_MODE_T
184AC_TYPE_OFF_T
Christian Göttschef3623b72021-01-22 19:14:50 +0100185AC_TYPE_PID_T
Benny Baumanna98fc472023-11-29 20:39:25 +0100186AC_TYPE_SIZE_T
187AC_TYPE_SSIZE_T
Christian Göttschef3623b72021-01-22 19:14:50 +0100188AC_TYPE_UID_T
189AC_TYPE_UINT8_T
190AC_TYPE_UINT16_T
191AC_TYPE_UINT32_T
192AC_TYPE_UINT64_T
193
Benny Baumann44d12002021-06-27 12:44:01 +0200194AC_MSG_CHECKING(for alloc_size)
195old_CFLAGS="$CFLAGS"
196CFLAGS="$CFLAGS -Wno-error -Werror=attributes"
197AC_COMPILE_IFELSE([
198 AC_LANG_SOURCE(
199 [
Explorer0978acd632024-08-13 04:30:53 +0800200 /* Attribute supported in GCC 4.3 or later */
Benny Baumann44d12002021-06-27 12:44:01 +0200201 __attribute__((alloc_size(1))) char* my_alloc(int size) { return 0; }
202 ],[]
203 )],
204 AC_DEFINE([HAVE_ATTR_ALLOC_SIZE], 1, [The alloc_size attribute is supported.])
205 AC_MSG_RESULT(yes),
206 AC_MSG_RESULT(no))
207CFLAGS="$old_CFLAGS"
208
Christian Göttsche8387df12023-02-04 17:34:08 +0100209AC_MSG_CHECKING(for access)
210old_CFLAGS="$CFLAGS"
211CFLAGS="$CFLAGS -Wno-error -Werror=attributes"
212AC_COMPILE_IFELSE([
213 AC_LANG_SOURCE(
214 [
Explorer0978acd632024-08-13 04:30:53 +0800215 /* Attribute supported in GCC 10 or later */
Christian Göttsche8387df12023-02-04 17:34:08 +0100216 __attribute__((access(read_only, 1, 2))) extern int foo(const char* str, unsigned len);
217 ],[]
218 )],
219 AC_DEFINE([HAVE_ATTR_ACCESS], 1, [The access attribute is supported.])
220 AC_MSG_RESULT(yes),
221 AC_MSG_RESULT(no))
222CFLAGS="$old_CFLAGS"
223
Explorer09f541f702023-10-11 03:37:39 +0800224AC_MSG_CHECKING(for nonnull)
225old_CFLAGS="$CFLAGS"
226CFLAGS="$CFLAGS -Wno-error -Werror=attributes"
227AC_COMPILE_IFELSE([
228 AC_LANG_SOURCE(
229 [[
230 /* Attribute supported in GCC 3.3 or later */
231 __attribute__((nonnull)) int my_strcmp(const char* a, const char* b);
232 __attribute__((nonnull(1))) long my_strtol(const char* str, char** endptr, int base);
233 ]]
234 )],
235 AC_DEFINE([HAVE_ATTR_NONNULL], 1, [The nonnull attribute is supported.])
236 AC_MSG_RESULT(yes),
237 AC_MSG_RESULT(no))
238CFLAGS="$old_CFLAGS"
239
Benny Baumann0720b102024-07-10 10:53:43 +0200240AC_MSG_CHECKING(for returns_nonnull)
241old_CFLAGS="$CFLAGS"
242CFLAGS="$CFLAGS -Wno-error -Werror=attributes"
243AC_COMPILE_IFELSE([
244 AC_LANG_SOURCE(
245 [[
246 /* Attribute supported in GCC 4.9 or later */
247 __attribute__((returns_nonnull)) void* foo(void);
248 ]]
249 )],
250 AC_DEFINE([HAVE_ATTR_RETNONNULL], 1, [The returns_nonnull attribute is supported.])
251 AC_MSG_RESULT(yes),
252 AC_MSG_RESULT(no))
253CFLAGS="$old_CFLAGS"
254
Christian Göttscheaa0424a2021-08-08 16:54:20 +0200255AC_MSG_CHECKING(for NaN support)
Explorer09b4164332023-07-29 16:24:12 +0800256dnl Note: AC_RUN_IFELSE does not try compiling the program at all when
257dnl $cross_compiling is 'yes'.
258AC_LINK_IFELSE([
Christian Göttscheaa0424a2021-08-08 16:54:20 +0200259 AC_LANG_PROGRAM(
260 [[
Explorer09b4164332023-07-29 16:24:12 +0800261#include <math.h>
Christian Göttscheaa0424a2021-08-08 16:54:20 +0200262 ]],
263 [[
Explorer09b4164332023-07-29 16:24:12 +0800264 double x = NAN;
265 /* Both should evaluate to false -> 0 (exit success) */
266 return isgreater(x, x) || isgreaterequal(x, x);
Christian Göttscheaa0424a2021-08-08 16:54:20 +0200267 ]]
268 )],
Explorer09b4164332023-07-29 16:24:12 +0800269 [flag_finite_math_only=unknown
270 if test "$cross_compiling" = yes; then
271 AC_COMPILE_IFELSE([
272 AC_LANG_SOURCE([[
273/* __FINITE_MATH_ONLY__ is documented in Clang. */
274#ifdef __FINITE_MATH_ONLY__
275#error "should not enable -ffinite-math-only"
276#endif
277 ]])],
278 AC_MSG_RESULT([assume yes (cross compiling)]),
Benny Baumann6aa9ef22023-11-23 12:22:02 +0100279 flag_finite_math_only=yes)
Explorer09b4164332023-07-29 16:24:12 +0800280 elif ./conftest$EXEEXT >&AS_MESSAGE_LOG_FD; then
281 flag_finite_math_only=no
282 AC_MSG_RESULT(yes)
283 else
284 flag_finite_math_only=yes
285 fi
286 if test "$flag_finite_math_only" = yes; then
Christian Göttscheaa0424a2021-08-08 16:54:20 +0200287 AC_MSG_RESULT(no)
Explorer09b4164332023-07-29 16:24:12 +0800288 AC_MSG_WARN([runtime behavior with NaN is not compliant - some functionality might break; consider using '-fno-finite-math-only'])
289 fi],
290 [AC_MSG_RESULT(no)
291 AC_MSG_ERROR([can not find required macros: NAN, isgreater() and isgreaterequal()])])
Christian Göttscheaa0424a2021-08-08 16:54:20 +0200292
Benny Baumanna3951862024-01-22 10:39:28 +0100293AC_MSG_CHECKING(for __builtin_ctz)
294AC_COMPILE_IFELSE([
295 AC_LANG_PROGRAM([], [[__builtin_ctz(1); /* Supported in GCC 3.4 or later */]])],
296 [AC_DEFINE([HAVE_BUILTIN_CTZ], 1, [Define to 1 if the compiler supports '__builtin_ctz' function.])
297 AC_MSG_RESULT(yes)],
298 AC_MSG_RESULT(no))
299
Christian Göttschef3623b72021-01-22 19:14:50 +0100300# ----------------------------------------------------------------------
301
302
303# ----------------------------------------------------------------------
304# Checks for generic library functions.
305# ----------------------------------------------------------------------
306
Christian Göttschee34c3872022-08-09 21:37:14 +0200307AC_SEARCH_LIBS([ceil], [m], [], [AC_MSG_ERROR([can not find required function ceil()])])
Christian Göttschef3623b72021-01-22 19:14:50 +0100308
309if test "$my_htop_platform" = dragonflybsd; then
Christian Göttsche759a3402021-01-22 19:14:55 +0100310 AC_SEARCH_LIBS([kvm_open], [kvm], [], [AC_MSG_ERROR([can not find required function kvm_open()])])
Christian Göttsche2f67a2b2024-01-19 21:06:14 +0100311 AC_SEARCH_LIBS([getdevs], [devstat], [], [AC_MSG_ERROR([can not find required function getdevs()])])
Christian Göttschef3623b72021-01-22 19:14:50 +0100312fi
313
314if test "$my_htop_platform" = freebsd; then
Christian Göttschecae47bb2021-02-05 15:15:01 +0100315 if test "$enable_static" = yes; then
316 AC_SEARCH_LIBS([elf_version], [elf], [], [AC_MSG_ERROR([can not find required function elf_version()])])
317 fi
Christian Göttsche759a3402021-01-22 19:14:55 +0100318 AC_SEARCH_LIBS([kvm_open], [kvm], [], [AC_MSG_ERROR([can not find required function kvm_open()])])
319 AC_SEARCH_LIBS([devstat_checkversion], [devstat], [], [AC_MSG_ERROR([can not find required function devstat_checkversion()])])
Christian Göttschef3623b72021-01-22 19:14:50 +0100320fi
321
322if test "$my_htop_platform" = linux; then
Christian Göttsche575edff2021-01-22 19:14:59 +0100323 if test "$enable_static" != yes; then
324 AC_SEARCH_LIBS([dlopen], [dl dld], [], [AC_MSG_ERROR([can not find required function dlopen()])])
325 fi
Christian Göttschef3623b72021-01-22 19:14:50 +0100326fi
327
fraggerfox4b49de42021-03-15 13:14:39 +0530328if test "$my_htop_platform" = netbsd; then
329 AC_SEARCH_LIBS([kvm_open], [kvm], [], [AC_MSG_ERROR([can not find required function kvm_open()])])
niafdcdc542021-07-26 19:04:44 +0200330 AC_SEARCH_LIBS([prop_dictionary_get], [prop], [], [AC_MSG_ERROR([can not find required function prop_dictionary_get()])])
fraggerfox4b49de42021-03-15 13:14:39 +0530331fi
332
Christian Göttschef3623b72021-01-22 19:14:50 +0100333if test "$my_htop_platform" = openbsd; then
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()])])
Christian Göttschef3623b72021-01-22 19:14:50 +0100335fi
336
337if test "$my_htop_platform" = solaris; then
Christian Göttsche759a3402021-01-22 19:14:55 +0100338 AC_SEARCH_LIBS([kstat_open], [kstat], [], [AC_MSG_ERROR([can not find required function kstat_open()])])
339 AC_SEARCH_LIBS([Pgrab_error], [proc], [], [AC_MSG_ERROR([can not find required function Pgrab_error()])])
340 AC_SEARCH_LIBS([free], [malloc], [], [AC_MSG_ERROR([can not find required function free()])])
Christian Göttschef3623b72021-01-22 19:14:50 +0100341fi
342
343# Optional Section
344
345AC_SEARCH_LIBS([clock_gettime], [rt])
346
347AC_CHECK_FUNCS([ \
348 clock_gettime \
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200349 dladdr \
Christian Göttschef3623b72021-01-22 19:14:50 +0100350 faccessat \
351 fstatat \
352 host_get_clock_service \
Christian Göttsche7b1fa1b2020-12-25 11:03:15 +0100353 memfd_create\
Christian Göttschef3623b72021-01-22 19:14:50 +0100354 openat \
355 readlinkat \
Christian Göttscheda494892023-01-10 19:40:04 +0100356 sched_getscheduler \
357 sched_setscheduler \
Nathan Scott4103c232023-10-09 10:48:38 +1100358 strchrnul \
Christian Göttschef3623b72021-01-22 19:14:50 +0100359 ])
360
Christian Göttschef3623b72021-01-22 19:14:50 +0100361if test "$my_htop_platform" = darwin; then
362 AC_CHECK_FUNCS([mach_timebase_info])
UeiWanged7eac52023-04-16 23:11:20 +0800363 AC_CHECK_DECLS([IOMainPort], [], [], [[#include <IOKit/IOKitLib.h>]])
364 AC_CHECK_DECLS([IOMasterPort], [], [], [[#include <IOKit/IOKitLib.h>]])
Christian Göttschef3623b72021-01-22 19:14:50 +0100365fi
Christian Goettschec2fdfd92020-10-21 17:06:32 +0200366
Nathan Scottd58180b2022-09-13 12:14:40 +1000367if test "$my_htop_platform" = pcp; then
368 AC_CHECK_FUNCS([pmLookupDescs])
369fi
370
Christian Göttsche575edff2021-01-22 19:14:59 +0100371if test "$my_htop_platform" = linux && test "x$enable_static" = xyes; then
Christian Göttschee59176f2024-01-10 17:12:18 +0100372 AC_CHECK_LIB([systemd], [sd_bus_open_system], [], [], [-lcap])
Christian Göttsche575edff2021-01-22 19:14:59 +0100373fi
374
Hisham Muhammad300af4b2014-11-19 23:17:16 -0200375# ----------------------------------------------------------------------
Hisham Muhammadeb229d92014-11-24 18:55:03 -0200376
Hisham Muhammadd6231ba2006-03-04 18:16:49 +0000377
Christian Göttschef3623b72021-01-22 19:14:50 +0100378# ----------------------------------------------------------------------
379# Checks for cross-platform features and flags.
380# ----------------------------------------------------------------------
Hisham Muhammada5dfaa22008-09-23 04:31:13 +0000381
Explorer09fd083142024-09-19 06:08:41 +0800382dnl PKG_PROG_PKG_CONFIG initializes $PKG_CONFIG and related variables.
383dnl If the macro is not called, some pkg-config checks might be skipped
384dnl and $PKG_CONFIG might be unset.
385m4_ifdef([PKG_PROG_PKG_CONFIG], [
386 PKG_PROG_PKG_CONFIG()
Explorer09baf70412024-09-19 06:15:08 +0800387], [
388 pkg_m4_absent=1 # Makefile might grep this keyword. Don't remove.
389 m4_warn(
390 [syntax],
391 [pkg.m4 is absent or older than version 0.16; this 'configure' would have incomplete pkg-config support])
Explorer09fd083142024-09-19 06:08:41 +0800392])
393
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100394AC_ARG_ENABLE([unicode],
395 [AS_HELP_STRING([--enable-unicode],
396 [enable Unicode support @<:@default=yes@:>@])],
397 [],
398 [enable_unicode=yes])
Hisham Muhammaddb682862015-12-09 17:17:30 -0200399
Explorer095d1948b2024-09-19 06:27:31 +0800400AC_ARG_VAR([CURSES_CFLAGS], [C compiler flags for curses; this overrides auto detected values])
401AC_ARG_VAR([CURSES_LIBS], [linker flags for curses; this overrides auto detected values])
402
403curses_pkg_names="ncurses6 ncurses5 ncurses curses"
404
405if test "x$enable_unicode" = xyes; then
406 curses_pkg_names="ncursesw6 ncursesw5 ncursesw $curses_pkg_names"
407fi
408
409AC_ARG_WITH([curses],
410 [AS_HELP_STRING([--with-curses=NAME],
411 [select curses package NAME to link with; e.g. ncursesw6])],
412 [],
413 [with_curses=check])
414case $with_curses in
415check)
416 : # No-op. Use default list.
417 ;;
418yes|no)
419 AC_MSG_ERROR([bad value '$with_curses' for --with-curses option])
420 ;;
421*)
422 if test "x${CURSES_CFLAGS+y}${CURSES_LIBS+y}" = xyy; then
423 AC_MSG_WARN([ignoring --with-curses value due to override])
424 fi
425 curses_pkg_names=`echo "x$with_curses" | sed 's/^x\(lib\)\{0,1\}//'`
426 ;;
427esac
428
429# $1: C preprocessor and compiler flags for curses library
430# $2: linker flags for curses library
431htop_check_curses_capability () {
432 htop_curses_cflags=${CURSES_CFLAGS-"$1"}
433 htop_curses_libs=${CURSES_LIBS-"$2"}
434
435 echo "curses cflags${CURSES_CFLAGS+ (override)}: $htop_curses_cflags" >&AS_MESSAGE_LOG_FD
436 echo "curses libs${CURSES_LIBS+ (override)}: $htop_curses_libs" >&AS_MESSAGE_LOG_FD
437
438 htop_msg_linker_flags=$htop_curses_libs
439 if test "`echo x $htop_msg_linker_flags`" = x; then
440 htop_msg_linker_flags="(no linker flags)"
441 fi
442
443 htop_curses_status=0 # 0 for success; nonzero for failure
444
445 htop_save_CFLAGS=$CFLAGS
446 htop_save_LIBS=$LIBS
447 CFLAGS="$AM_CFLAGS $htop_curses_cflags $CFLAGS"
448 LIBS="$htop_curses_libs $LIBS"
449
450 # At this point we have not checked the name of curses header, so
451 # use forward declaration for the linking tests below.
452
Explorer09d5f24d22024-08-21 19:56:21 +0800453 # htop uses keypad() and "stdscr", but for ncurses implementation,
454 # the symbols are in "-ltinfo" and not "-lncurses".
455 # Check "-ltinfo" symbols first, as libncurses might require
456 # explicit "-ltinfo" to link (for internal dependency).
457 AC_MSG_CHECKING([for keypad in $htop_msg_linker_flags])
458 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
459/* extern WINDOW* stdscr; */
460/* int keypad(WINDOW* win, bool enable); */
461extern void* stdscr;
462int keypad(void* win, int enable);
463 ]], [[
464keypad(stdscr, 0);
465 ]])],
466 [AC_MSG_RESULT(yes)],
467 [AC_MSG_RESULT(no)
468 htop_curses_status=1])
469
Explorer095d1948b2024-09-19 06:27:31 +0800470 # htop calls refresh(), which might be implemented as a macro.
471 # It is more reliable to test linking with doupdate(), which
472 # refresh() would call internally.
Explorer09d5f24d22024-08-21 19:56:21 +0800473 if test "$htop_curses_status" -eq 0; then
474 AC_MSG_CHECKING([for doupdate in $htop_msg_linker_flags])
475 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer095d1948b2024-09-19 06:27:31 +0800476int doupdate(void);
Explorer09d5f24d22024-08-21 19:56:21 +0800477 ]], [[
Explorer095d1948b2024-09-19 06:27:31 +0800478doupdate();
Explorer09d5f24d22024-08-21 19:56:21 +0800479 ]])],
480 [AC_MSG_RESULT(yes)
481 htop_curses_capability=nonwide],
482 [AC_MSG_RESULT(no)
483 htop_curses_status=1])
484 fi
Explorer095d1948b2024-09-19 06:27:31 +0800485
486 if test "x$htop_curses_status$enable_unicode" = x0yes; then
487 AC_MSG_CHECKING([for mvadd_wchnstr in $htop_msg_linker_flags])
488 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
489/* int mvadd_wchnstr(int y, int x, const cchar_t* wchstr, int n); */
490int mvadd_wchnstr(int y, int x, const void* wchstr, int n);
491 ]], [[
492mvadd_wchnstr(0, 0, (void*)0, 0);
493 ]])],
494 [AC_MSG_RESULT(yes)
495 htop_curses_capability=wide],
496 [AC_MSG_RESULT(no)
497 htop_curses_status=1])
498 fi
499
500 if test "$htop_curses_status" -eq 0; then
501 AM_CFLAGS="$AM_CFLAGS $htop_curses_cflags"
502 if test "$htop_curses_capability" = wide; then
503 AC_DEFINE([HAVE_LIBNCURSESW], 1, [libncursesw is present])
504 else
505 AC_DEFINE([HAVE_LIBNCURSES], 1, [libcurses is present])
506 fi
507 else
508 LIBS=$htop_save_LIBS
509 fi
510 CFLAGS=$htop_save_CFLAGS
511 return "$htop_curses_status"
512} # htop_check_curses_capability
513
514htop_curses_capability=none
515
516if test "x${CURSES_CFLAGS+y}${CURSES_LIBS+y}" = xyy; then
517 curses_pkg_names=""
518 htop_check_curses_capability "$CURSES_CFLAGS" "$CURSES_LIBS"
519fi
520
521# Prioritize $PKG_CONFIG over ncurses*-config, as users might need to
522# cross-compile htop.
523if test "x$PKG_CONFIG" != x; then
524 pkg_config_static_flag=""
525 if test "$enable_static" = yes; then
526 pkg_config_static_flag=--static
527 fi
528
529 for curses_name in $curses_pkg_names; do
530 echo retrieving $curses_name information through $PKG_CONFIG >&AS_MESSAGE_LOG_FD
531 $PKG_CONFIG --exists --print-errors $curses_name >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD || continue
532
533 : # Resets "$?" to 0
534 htop_config_cflags=`$PKG_CONFIG --cflags $pkg_config_static_flag $curses_name 2>/dev/null` || continue
535 : # Resets "$?" to 0
536 htop_config_libs=`$PKG_CONFIG --libs $pkg_config_static_flag $curses_name 2>/dev/null` || continue
537
538 AC_MSG_RESULT([found $curses_name information through $PKG_CONFIG])
539
540 if htop_check_curses_capability "$htop_config_cflags" "$htop_config_libs"; then
541 break
542 fi
543 done
544fi
545
546case ${htop_curses_capability}-$enable_unicode in
547none-*|nonwide-yes)
548 for curses_name in $curses_pkg_names; do
549 echo retrieving $curses_name information through ${curses_name}-config >&AS_MESSAGE_LOG_FD
550
551 ${curses_name}-config --cflags >/dev/null 2>&AS_MESSAGE_LOG_FD || continue
552
553 : # Resets "$?" to 0
554 htop_config_cflags=`${curses_name}-config --cflags 2>/dev/null` || continue
555 : # Resets "$?" to 0
556 htop_config_libs=`${curses_name}-config --libs 2>/dev/null` || continue
557
558 AC_MSG_RESULT([found $curses_name information through ${curses_name}-config])
559
560 if htop_check_curses_capability "$htop_config_cflags" "$htop_config_libs"; then
561 break
562 fi
563 done
564 ;;
565esac
566
567case ${htop_curses_capability}-$enable_unicode in
568none-*|nonwide-yes)
Explorer09082b9772024-09-19 06:28:42 +0800569 if test "x$PKG_CONFIG" = x; then (
570 # Friendly warning to advise user to install pkg-config.
571 # The local variables get discarded when done.
572 list=""
573 echo "" >conftest.c
574 if test "$cross_compiling" != yes; then
575 # "-print-multi-directory" supported in GCC 3.0 or later
576 name=""
577 if $CC $CPPFLAGS $CFLAGS -print-multi-directory -E conftest.c >/dev/null 2>&1; then
578 name=`$CC $CPPFLAGS $CFLAGS -print-multi-directory -E conftest.c 2>/dev/null |
579 sed '/^ *#/ d; s/^\.$//; q'`
580 fi
581 list="/usr/lib${name}/pkgconfig $list"
582 case $host_os in
583 darwin*)
584 list="/opt/homebrew/Library/Homebrew/os/mac/pkgconfig $list"
585 ;;
586 freebsd*)
587 list="/usr/libdata/pkgconfig $list"
588 ;;
589 netbsd*)
590 list="/usr/pkg/lib/pkgconfig $list"
591 ;;
592 esac
593 fi
594 if test "x$host_alias" != x; then
595 list="/usr/lib/${host_alias}/pkgconfig $list"
596 fi
597 # "-print-multiarch" supported in GCC 4.6 or later
598 if $CC $CPPFLAGS $CFLAGS -print-multiarch -E conftest.c >/dev/null 2>&1; then
599 name=`$CC $CPPFLAGS $CFLAGS -print-multiarch -E conftest.c 2>/dev/null |
600 sed '/^ *#/ d; q'`
601 if test "x$name" != x; then
602 list="/usr/lib/${name}/pkgconfig $list"
603 fi
604 fi
605 rm -f conftest.*
606
607 for d in $list; do
608 result=`find "$d" -name '*curses*.pc' 2>/dev/null | sed '1 q'`
609 if test "x$result" != x; then
610 AC_MSG_WARN([your system supports pkg-config; installing pkg-config is recommended before configuring htop])
611 break
612 fi
613 done
614 ) fi
615
Explorer095d1948b2024-09-19 06:27:31 +0800616 # OpenBSD and Solaris are known to not provide '*curses*.pc' files.
617 AC_MSG_RESULT([no curses information found through '*-config' utilities; will guess the linker flags])
618 for curses_name in $curses_pkg_names; do
619 if htop_check_curses_capability "" "-l$curses_name"; then
620 break
621 fi
Explorer09d5f24d22024-08-21 19:56:21 +0800622 # For ncurses implementation, an extra "-ltinfo" or "-ltinfow"
623 # flag might be needed to link.
624 if test "x$enable_unicode" = xyes &&
625 htop_check_curses_capability "" "-l$curses_name -ltinfow"; then
626 break
627 fi
628 if htop_check_curses_capability "" "-l$curses_name -ltinfo"; then
629 break
630 fi
Explorer095d1948b2024-09-19 06:27:31 +0800631 done
632 ;;
633esac
634
635case ${htop_curses_capability}-$enable_unicode in
636nonwide-yes)
637 AC_MSG_ERROR([cannot find required ncursesw library; you may want to use --disable-unicode])
638 ;;
639none-*)
640 AC_MSG_ERROR([cannot find required curses/ncurses library])
641 ;;
642esac
643
644htop_save_CFLAGS=$CFLAGS
645CFLAGS="$AM_CFLAGS $CFLAGS"
646if test "x$enable_unicode" = xyes; then
Christian Göttsche759a3402021-01-22 19:14:55 +0100647 AC_CHECK_HEADERS([ncursesw/curses.h], [],
648 [AC_CHECK_HEADERS([ncurses/ncurses.h], [],
649 [AC_CHECK_HEADERS([ncurses/curses.h], [],
650 [AC_CHECK_HEADERS([ncurses.h], [],
651 [AC_MSG_ERROR([can not find required ncurses header file])])])])])
Christian Göttscheead978b2020-12-07 15:30:56 +0100652
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530653 AC_CHECK_HEADERS([ncursesw/term.h], [],
654 [AC_CHECK_HEADERS([ncurses/term.h], [],
655 [AC_CHECK_HEADERS([term.h], [],
656 [AC_MSG_ERROR([can not find required term header file])])])])
Hisham Muhammad8fa33dc2008-03-09 02:33:23 +0000657else
Christian Göttsche759a3402021-01-22 19:14:55 +0100658 AC_CHECK_HEADERS([curses.h], [],
659 [AC_CHECK_HEADERS([ncurses/curses.h], [],
660 [AC_CHECK_HEADERS([ncurses/ncurses.h], [],
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530661 [AC_CHECK_HEADERS([ncurses.h], [],
Christian Göttsche759a3402021-01-22 19:14:55 +0100662 [AC_MSG_ERROR([can not find required ncurses header file])])])])])
Christian Göttscheead978b2020-12-07 15:30:56 +0100663
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530664 AC_CHECK_HEADERS([ncurses/term.h], [],
665 [AC_CHECK_HEADERS([term.h], [],
666 [AC_MSG_ERROR([can not find required term header file])])])
Hisham Muhammad4c51ad02007-08-10 05:07:14 +0000667fi
Explorer095d1948b2024-09-19 06:27:31 +0800668CFLAGS=$htop_save_CFLAGS
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530669
Christian Göttsche575edff2021-01-22 19:14:59 +0100670if test "$enable_static" = yes; then
671 AC_SEARCH_LIBS([Gpm_GetEvent], [gpm])
672fi
Christian Göttscheee9e7ed2021-05-20 18:27:10 +0200673if test "$my_htop_platform" = "solaris"; then
674 # On OmniOS /usr/include/sys/regset.h redefines ERR to 13 - \r, breaking the Enter key.
Nathan Scottca06e682021-09-08 12:11:51 +1000675 # Since ncurses macros use the ERR macro, we can not use another name.
Christian Göttscheee9e7ed2021-05-20 18:27:10 +0200676 AC_DEFINE([ERR], [(-1)], [Predefine ncurses macro.])
677fi
Benny Baumann18e3fd52021-07-04 16:50:41 +0200678AC_CHECK_FUNCS( [set_escdelay] )
nia2ab8fb82021-07-14 20:17:13 +0200679AC_CHECK_FUNCS( [getmouse] )
Hisham Muhammad4c51ad02007-08-10 05:07:14 +0000680
gmbroome697f5bb2018-03-02 16:20:46 -0500681
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200682AC_ARG_ENABLE([affinity],
683 [AS_HELP_STRING([--enable-affinity],
684 [enable sched_setaffinity and sched_getaffinity for affinity support, conflicts with hwloc @<:@default=check@:>@])],
685 [],
686 [enable_affinity=check])
687if test "x$enable_affinity" = xcheck; then
688 if test "x$enable_hwloc" = xyes; then
689 enable_affinity=no
690 else
691 AC_MSG_CHECKING([for usable sched_setaffinity])
692 AC_RUN_IFELSE([
693 AC_LANG_PROGRAM([[
694 #include <sched.h>
695 #include <errno.h>
696 static cpu_set_t cpuset;
697 ]], [[
698 CPU_ZERO(&cpuset);
699 sched_setaffinity(0, sizeof(cpu_set_t), &cpuset);
700 if (errno == ENOSYS) return 1;
701 ]])],
702 [enable_affinity=yes
703 AC_MSG_RESULT([yes])],
704 [enable_affinity=no
705 AC_MSG_RESULT([no])],
Explorer0947ae9662023-07-29 03:11:54 +0800706 [AC_MSG_RESULT([assume yes (cross compiling)])])
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200707 fi
708fi
709if test "x$enable_affinity" = xyes; then
710 if test "x$enable_hwloc" = xyes; then
711 AC_MSG_ERROR([--enable-hwloc and --enable-affinity are mutual exclusive. Specify at most one of them.])
712 fi
713 AC_DEFINE([HAVE_AFFINITY], [1], [Define if sched_setaffinity and sched_getaffinity are to be used.])
714fi
715
716
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200717AC_ARG_ENABLE([unwind],
718 [AS_HELP_STRING([--enable-unwind],
719 [enable unwind support for printing backtraces; requires libunwind @<:@default=check@:>@])],
720 [],
721 [enable_unwind=check])
722case "$enable_unwind" in
723 check)
724 enable_unwind=yes
725 if test "$enable_static" = yes; then
726 AC_CHECK_LIB([lzma], [lzma_index_buffer_decode])
727 fi
728 AC_CHECK_LIB([unwind], [backtrace], [], [enable_unwind=no])
Christian Göttsche63880332021-12-14 17:36:57 +0100729 AC_CHECK_HEADERS([libunwind.h], [], [
730 old_CFLAGS="$CFLAGS"
731 CFLAGS="$CFLAGS -I/usr/include/libunwind"
732 AC_CHECK_HEADERS([libunwind/libunwind.h], [], [
733 enable_unwind=no
734 CFLAGS="$old_CFLAGS"
735 ])
736 ])
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200737 ;;
738 no)
739 ;;
740 yes)
741 AC_CHECK_LIB([unwind], [backtrace], [], [AC_MSG_ERROR([can not find required library libunwind])])
Christian Göttsche63880332021-12-14 17:36:57 +0100742 AC_CHECK_HEADERS([libunwind.h], [], [
Benny Baumann5c7cb912023-11-28 17:42:04 +0100743 AM_CFLAGS="$AM_CFLAGS -I/usr/include/libunwind"
Christian Göttsche63880332021-12-14 17:36:57 +0100744 AC_CHECK_HEADERS([libunwind/libunwind.h], [], [AC_MSG_ERROR([can not find required header file libunwind.h])])
745 ])
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200746 ;;
747 *)
748 AC_MSG_ERROR([bad value '$enable_unwind' for --enable-unwind])
749 ;;
750esac
751if test "x$enable_unwind" = xno; then
752 # Fall back to backtrace(3) and add -lexecinfo if needed
753 AC_SEARCH_LIBS([backtrace], [execinfo])
754fi
755
756
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100757AC_ARG_ENABLE([hwloc],
758 [AS_HELP_STRING([--enable-hwloc],
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200759 [enable hwloc support for CPU affinity; disables affinity support; requires libhwloc @<:@default=no@:>@])],
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100760 [],
761 [enable_hwloc=no])
762case "$enable_hwloc" in
763 no)
764 ;;
765 yes)
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200766 m4_ifdef([PKG_PROG_PKG_CONFIG], [
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200767 PKG_CHECK_MODULES(HWLOC, hwloc, [
Benny Baumann5c7cb912023-11-28 17:42:04 +0100768 AM_CFLAGS="$AM_CFLAGS $HWLOC_CFLAGS"
Christian Göttschec8a61852023-04-05 01:21:14 +0200769 LIBS="$LIBS $HWLOC_LIBS"
Explorer0947ae9662023-07-29 03:11:54 +0800770 AC_DEFINE([HAVE_LIBHWLOC], [1], [Define to 1 if you have the 'hwloc' library (-lhwloc).])
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200771 ], [
772 AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [AC_MSG_ERROR([can not find required library libhwloc])])
773 AC_CHECK_HEADERS([hwloc.h], [], [AC_MSG_ERROR([can not find require header file hwloc.h])])
774 ])
775 ], [
776 AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [AC_MSG_ERROR([can not find required library libhwloc])])
777 AC_CHECK_HEADERS([hwloc.h], [], [AC_MSG_ERROR([can not find require header file hwloc.h])])
778 ])
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100779 ;;
780 *)
781 AC_MSG_ERROR([bad value '$enable_hwloc' for --enable-hwloc])
782 ;;
783esac
Christian Göttsche005c4d12020-09-08 16:25:22 +0200784
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200785
Nathan Scott5b50ae32021-03-02 15:58:11 +1100786AC_ARG_WITH([os-release],
787 [AS_HELP_STRING([--with-os-release=FILE],
Christian Göttsche8ba4ef32021-03-12 16:37:17 +0100788 [location of an os-release file @<:@default=/etc/os-release@:>@])],
Nathan Scott5b50ae32021-03-02 15:58:11 +1100789 [],
790 [with_os_release=/etc/os-release])
Christian Göttsche8ba4ef32021-03-12 16:37:17 +0100791if test -n "$with_os_release" && test ! -f "$with_os_release"; then
Nathan Scott5b50ae32021-03-02 15:58:11 +1100792 if test -f "/usr/lib/os-release"; then
793 with_os_release="/usr/lib/os-release"
794 fi
795fi
796AC_DEFINE_UNQUOTED([OSRELEASEFILE], ["$with_os_release"], [File with OS release details.])
797
Nathan Scott1a7b6d42024-07-22 08:51:29 +1000798AC_ARG_WITH([config],
799 [AS_HELP_STRING([--with-config=DIR],
Explorer09c802dc42024-09-19 06:37:00 +0800800 [configuration path @<:@default=/.config@:>@])],
Nathan Scott1a7b6d42024-07-22 08:51:29 +1000801 [],
802 [with_config="/.config"])
803dnl Performance Co-Pilot configuration location to prevent overwrite
804if test "$my_htop_platform" = pcp -a "$with_config" = /.config; then
805 with_config="/.pcp"
806elif test -z "$with_config"; then
807 AC_MSG_ERROR([bad empty value for --with-config option])
808fi
809AC_DEFINE_UNQUOTED([CONFIGDIR], ["$with_config"], [Configuration path.])
810
Christian Göttschef3623b72021-01-22 19:14:50 +0100811# ----------------------------------------------------------------------
812
813
814# ----------------------------------------------------------------------
815# Checks for Linux features and flags.
816# ----------------------------------------------------------------------
817
818AC_ARG_WITH([proc],
819 [AS_HELP_STRING([--with-proc=DIR],
820 [location of a Linux-compatible proc filesystem @<:@default=/proc@:>@])],
821 [],
822 [with_proc=/proc])
823if test -z "$with_proc"; then
824 AC_MSG_ERROR([bad empty value for --with-proc option])
825fi
826AC_DEFINE_UNQUOTED([PROCDIR], ["$with_proc"], [Path of proc filesystem.])
827
828
829AC_ARG_ENABLE([openvz],
830 [AS_HELP_STRING([--enable-openvz],
831 [enable OpenVZ support @<:@default=no@:>@])],
832 [],
833 [enable_openvz=no])
834if test "x$enable_openvz" = xyes; then
835 AC_DEFINE([HAVE_OPENVZ], [1], [Define if openvz support enabled.])
836fi
837
838
839AC_ARG_ENABLE([vserver],
840 [AS_HELP_STRING([--enable-vserver],
841 [enable VServer support @<:@default=no@:>@])],
842 [],
843 [enable_vserver=no])
844if test "x$enable_vserver" = xyes; then
Christian Göttsche284f8c52021-09-02 22:32:46 +0200845 AC_DEFINE([HAVE_VSERVER], [1], [Define if VServer support enabled.])
Christian Göttschef3623b72021-01-22 19:14:50 +0100846fi
847
848
849AC_ARG_ENABLE([ancient_vserver],
850 [AS_HELP_STRING([--enable-ancient-vserver],
851 [enable ancient VServer support (implies --enable-vserver) @<:@default=no@:>@])],
852 [],
853 [enable_ancient_vserver=no])
854if test "x$enable_ancient_vserver" = xyes; then
Christian Göttsche284f8c52021-09-02 22:32:46 +0200855 if test "x$enable_vserver" != xyes; then
856 enable_vserver=implied
857 fi
858 AC_DEFINE([HAVE_VSERVER], [1], [Define if VServer support enabled.])
859 AC_DEFINE([HAVE_ANCIENT_VSERVER], [1], [Define if ancient vserver support enabled.])
Christian Göttschef3623b72021-01-22 19:14:50 +0100860fi
861
862
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100863AC_ARG_ENABLE([capabilities],
864 [AS_HELP_STRING([--enable-capabilities],
865 [enable Linux capabilities support; requires libcap @<:@default=check@:>@])],
866 [],
867 [enable_capabilities=check])
868case "$enable_capabilities" in
869 no)
870 ;;
871 check)
872 enable_capabilities=yes
873 AC_CHECK_LIB([cap], [cap_init], [], [enable_capabilities=no])
874 AC_CHECK_HEADERS([sys/capability.h], [], [enable_capabilities=no])
875 ;;
876 yes)
Christian Göttsche759a3402021-01-22 19:14:55 +0100877 AC_CHECK_LIB([cap], [cap_init], [], [AC_MSG_ERROR([can not find required library libcap])])
878 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 +0100879 ;;
880 *)
881 AC_MSG_ERROR([bad value '$enable_capabilities' for --enable-capabilities])
882 ;;
883esac
Christian Göttschef4404ef2020-09-02 14:39:25 +0200884
Christian Göttschef3623b72021-01-22 19:14:50 +0100885
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100886AC_ARG_ENABLE([delayacct],
887 [AS_HELP_STRING([--enable-delayacct],
888 [enable Linux delay accounting support; requires pkg-config, libnl-3 and libnl-genl-3 @<:@default=check@:>@])],
889 [],
890 [enable_delayacct=check])
891case "$enable_delayacct" in
892 no)
893 ;;
894 check)
Christian Göttsche69cfaf22021-05-16 20:01:25 +0200895 if test "$my_htop_platform" != linux; then
896 enable_delayacct=no
897 elif test "$enable_static" = yes; then
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100898 enable_delayacct=no
Christian Göttsche575edff2021-01-22 19:14:59 +0100899 else
Christian Göttsche24b15132024-03-30 13:47:14 +0100900 old_CFLAGS="$CFLAGS"
901 CFLAGS="$CFLAGS -I/usr/include/libnl3"
902 AC_CHECK_HEADERS([netlink/attr.h netlink/handlers.h netlink/msg.h], [enable_delayacct=yes], [enable_delayacct=no])
903 CFLAGS="$old_CFLAGS"
Christian Göttsche575edff2021-01-22 19:14:59 +0100904 fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100905 ;;
906 yes)
Christian Göttsche24b15132024-03-30 13:47:14 +0100907 old_CFLAGS="$CFLAGS"
908 CFLAGS="$CFLAGS -I/usr/include/libnl3"
909 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])])
910 CFLAGS="$old_CFLAGS"
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100911 ;;
912 *)
913 AC_MSG_ERROR([bad value '$enable_delayacct' for --enable-delayacct])
914 ;;
915esac
Christian Göttsche24b15132024-03-30 13:47:14 +0100916if test "$enable_delayacct" = yes; then
917 AC_DEFINE([HAVE_DELAYACCT], [1], [Define if delay accounting support should be enabled.])
918 AM_CFLAGS="$AM_CFLAGS -I/usr/include/libnl3"
919fi
Christian Göttschea782ef32024-03-30 13:47:10 +0100920AM_CONDITIONAL([HAVE_DELAYACCT], [test "$enable_delayacct" = yes])
André Carvalhob7b66b72017-12-04 00:15:29 -0200921
Christian Göttschef3623b72021-01-22 19:14:50 +0100922
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100923AC_ARG_ENABLE([sensors],
924 [AS_HELP_STRING([--enable-sensors],
925 [enable libsensors support for reading temperature data; requires only libsensors headers at compile time, at runtime libsensors is loaded via dlopen @<:@default=check@:>@])],
926 [],
927 [enable_sensors=check])
928case "$enable_sensors" in
929 no)
930 ;;
931 check)
932 enable_sensors=yes
Christian Göttsche575edff2021-01-22 19:14:59 +0100933 if test "$enable_static" = yes; then
934 AC_CHECK_LIB([sensors], [sensors_init], [], [enable_sensors=no])
935 fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100936 AC_CHECK_HEADERS([sensors/sensors.h], [], [enable_sensors=no])
937 ;;
938 yes)
Christian Göttsche575edff2021-01-22 19:14:59 +0100939 if test "$enable_static" = yes; then
940 AC_CHECK_LIB([sensors], [sensors_init], [], [AC_MSG_ERROR([can not find required library libsensors])])
941 fi
942 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 +0100943 ;;
944 *)
945 AC_MSG_ERROR([bad value '$enable_sensors' for --enable-sensors])
946 ;;
947esac
Christian Göttschefd2a0cf2020-12-22 20:02:01 +0100948if test "$enable_sensors" = yes || test "$my_htop_platform" = freebsd; then
949 AC_DEFINE([BUILD_WITH_CPU_TEMP], [1], [Define if CPU temperature option should be enabled.])
950fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100951
Christian Göttschef3623b72021-01-22 19:14:50 +0100952# ----------------------------------------------------------------------
953
954
955# ----------------------------------------------------------------------
956# Checks for compiler warnings.
957# ----------------------------------------------------------------------
Christian Göttsche1b225cd2020-09-10 19:56:33 +0200958
Benny Baumann5c7cb912023-11-28 17:42:04 +0100959AM_CFLAGS="$AM_CFLAGS\
Christian Göttschef4602f72020-09-08 14:25:46 +0200960 -Wall\
961 -Wcast-align\
Christian Göttschedb472072020-10-04 14:30:35 +0200962 -Wcast-qual\
Christian Göttschef4602f72020-09-08 14:25:46 +0200963 -Wextra\
Benny Baumannba0fca12020-09-18 16:58:03 +0200964 -Wfloat-equal\
Christian Göttschec150e4b2020-12-18 15:49:37 +0100965 -Wformat=2\
Christian Göttsche4dadbe32021-01-21 19:49:07 +0100966 -Winit-self\
Christian Göttschef4602f72020-09-08 14:25:46 +0200967 -Wmissing-format-attribute\
968 -Wmissing-noreturn\
Christian Göttsche4e282eb2020-09-25 14:03:55 +0200969 -Wmissing-prototypes\
Christian Göttschef4602f72020-09-08 14:25:46 +0200970 -Wpointer-arith\
971 -Wshadow\
972 -Wstrict-prototypes\
973 -Wundef\
974 -Wunused\
975 -Wwrite-strings"
976
Christian Göttschef3623b72021-01-22 19:14:50 +0100977dnl https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
978AC_DEFUN([AX_CHECK_COMPILE_FLAG],
Christian Göttsche38b6a012021-01-22 19:14:53 +0100979[
Christian Göttschef3623b72021-01-22 19:14:50 +0100980AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
981AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
982 ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
983 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
984 AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
985 [AS_VAR_SET(CACHEVAR,[yes])],
986 [AS_VAR_SET(CACHEVAR,[no])])
987 _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
988AS_VAR_IF(CACHEVAR,yes,
989 [m4_default([$2], :)],
990 [m4_default([$3], :)])
991AS_VAR_POPDEF([CACHEVAR])dnl
992])dnl AX_CHECK_COMPILE_FLAGS
993
Christian Göttsche970885e2021-08-14 11:21:54 +0200994AX_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 +0200995AX_CHECK_COMPILE_FLAG([-Wimplicit-int-conversion], [AM_CFLAGS="$AM_CFLAGS -Wimplicit-int-conversion"], , [-Werror])
996AX_CHECK_COMPILE_FLAG([-Wnull-dereference], [AM_CFLAGS="$AM_CFLAGS -Wnull-dereference"], , [-Werror])
Benny Baumann2cde4a72020-09-18 19:32:41 +0200997
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100998AC_ARG_ENABLE([werror],
999 [AS_HELP_STRING([--enable-werror],
1000 [Treat warnings as errors @<:@default=no@:>@])],
1001 [],
1002 [enable_werror=no])
1003if test "x$enable_werror" = xyes; then
1004 AM_CFLAGS="$AM_CFLAGS -Werror"
1005fi
1006
1007AC_ARG_ENABLE([debug],
1008 [AS_HELP_STRING([--enable-debug],
Daniel Lange135efd52021-02-16 11:22:02 +01001009 [Enable compiling with maximum debug info, asserts and internal sanity checks @<:@default=no@:>@])],
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001010 [],
1011 [enable_debug=no])
1012if test "x$enable_debug" != xyes; then
1013 AM_CPPFLAGS="$AM_CPPFLAGS -DNDEBUG"
Explorer0993d76fd2023-07-31 05:05:43 +08001014
1015 AC_COMPILE_IFELSE([
1016 AC_LANG_SOURCE([[
1017#ifdef __SUPPORT_SNAN__
1018#error "signaling NaN support not recommended"
1019#endif
1020 ]])],
1021 :,
1022 [warning_msg="signaling NaN support is enabled; not recommended for htop"
1023 case "$CC" in
1024 *gcc*)
1025 warning_msg="$warning_msg (use '-fno-signaling-nans' compiler flag to disable)"
1026 ;;
1027 esac
1028 AC_MSG_WARN([$warning_msg])
1029 ])
Daniel Lange135efd52021-02-16 11:22:02 +01001030else
1031 AM_CPPFLAGS="$AM_CPPFLAGS -ggdb3"
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001032fi
Christian Göttscheb7f63292020-09-17 22:23:05 +02001033
Christian Göttschef3623b72021-01-22 19:14:50 +01001034
Christian Göttsche57254cd2020-08-21 10:37:20 +02001035AC_SUBST([AM_CFLAGS])
Christian Göttscheb7f63292020-09-17 22:23:05 +02001036AC_SUBST([AM_CPPFLAGS])
1037
Christian Göttschef3623b72021-01-22 19:14:50 +01001038# ----------------------------------------------------------------------
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001039
Christian Göttschef3623b72021-01-22 19:14:50 +01001040
1041# ----------------------------------------------------------------------
Hisham Muhammad300af4b2014-11-19 23:17:16 -02001042# We're done, let's go!
1043# ----------------------------------------------------------------------
Christian Göttschef3623b72021-01-22 19:14:50 +01001044
Daniel Langec3b4a772024-01-01 02:12:06 +01001045AC_DEFINE_UNQUOTED([COPYRIGHT], ["(C) 2004-2019 Hisham Muhammad. (C) 2020-2024 htop dev team."], [Copyright message.])
Christian Göttschef3623b72021-01-22 19:14:50 +01001046
Hisham Muhammada75161f2014-11-24 20:11:33 -02001047AM_CONDITIONAL([HTOP_LINUX], [test "$my_htop_platform" = linux])
Hisham Muhammad8915b292014-11-27 16:27:34 -02001048AM_CONDITIONAL([HTOP_FREEBSD], [test "$my_htop_platform" = freebsd])
Diederik de Grootb258d6e2017-04-19 16:12:17 +02001049AM_CONDITIONAL([HTOP_DRAGONFLYBSD], [test "$my_htop_platform" = dragonflybsd])
fraggerfox4b49de42021-03-15 13:14:39 +05301050AM_CONDITIONAL([HTOP_NETBSD], [test "$my_htop_platform" = netbsd])
Michael McConvillea9a5a532015-09-18 00:46:48 -04001051AM_CONDITIONAL([HTOP_OPENBSD], [test "$my_htop_platform" = openbsd])
David Hunt70e7c8d2015-07-12 13:47:43 -05001052AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin])
gmbroome697f5bb2018-03-02 16:20:46 -05001053AM_CONDITIONAL([HTOP_SOLARIS], [test "$my_htop_platform" = solaris])
Nathan Scottc14a45b2021-02-17 14:43:56 +11001054AM_CONDITIONAL([HTOP_PCP], [test "$my_htop_platform" = pcp])
Hisham Muhammada75161f2014-11-24 20:11:33 -02001055AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported])
Christian Göttsche38b6a012021-01-22 19:14:53 +01001056
Hisham Muhammadeb229d92014-11-24 18:55:03 -02001057AC_SUBST(my_htop_platform)
Daniel Langefc2377f2021-08-14 10:35:11 +02001058AC_CONFIG_FILES([Makefile htop.1])
Hisham Muhammadd6231ba2006-03-04 18:16:49 +00001059AC_OUTPUT
Hisham Muhammadc39f18a2017-07-10 20:14:25 -03001060
Christian Göttschef3623b72021-01-22 19:14:50 +01001061if test "$my_htop_platform" = unsupported; then
Hisham Muhammadc39f18a2017-07-10 20:14:25 -03001062 echo ""
1063 echo "****************************************************************"
1064 echo "WARNING! This platform is not currently supported by htop."
1065 echo ""
1066 echo "The code will build, but it will produce a dummy version of htop"
1067 echo "which shows no processes, using the files from the unsupported/"
1068 echo "directory. This is meant to be a skeleton, to be used as a"
1069 echo "starting point if you are porting htop to a new platform."
1070 echo "****************************************************************"
1071 echo ""
1072fi
Christian Göttsche3b084db2020-08-28 12:10:31 +02001073
1074AC_MSG_RESULT([
1075 ${PACKAGE_NAME} ${VERSION}
1076
Christian Göttscheffd90c22020-10-05 12:29:31 +02001077 platform: $my_htop_platform
Nathan Scott5b50ae32021-03-02 15:58:11 +11001078 os-release file: $with_os_release
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001079 (Linux) proc directory: $with_proc
Christian Göttscheffd90c22020-10-05 12:29:31 +02001080 (Linux) openvz: $enable_openvz
Christian Göttscheffd90c22020-10-05 12:29:31 +02001081 (Linux) vserver: $enable_vserver
1082 (Linux) ancient vserver: $enable_ancient_vserver
Christian Göttscheffd90c22020-10-05 12:29:31 +02001083 (Linux) delay accounting: $enable_delayacct
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001084 (Linux) sensors: $enable_sensors
1085 (Linux) capabilities: $enable_capabilities
Christian Göttscheffd90c22020-10-05 12:29:31 +02001086 unicode: $enable_unicode
Christian Göttsche1fb0c722021-06-13 11:29:39 +02001087 affinity: $enable_affinity
Christian Göttsche29e1fcf2021-05-16 20:45:09 +02001088 unwind: $enable_unwind
Daniel Lange309f1d72020-11-16 13:29:37 +01001089 hwloc: $enable_hwloc
Daniel Langea8a723f2020-11-16 17:01:51 +01001090 debug: $enable_debug
Christian Göttsche575edff2021-01-22 19:14:59 +01001091 static: $enable_static
Christian Göttsche3b084db2020-08-28 12:10:31 +02001092])