blob: bc98008b0293679ab3c22e5f6fa0631b6d312fad [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
378 AC_CHECK_FUNCS([mach_timebase_info])
UeiWanged7eac52023-04-16 23:11:20 +0800379 AC_CHECK_DECLS([IOMainPort], [], [], [[#include <IOKit/IOKitLib.h>]])
380 AC_CHECK_DECLS([IOMasterPort], [], [], [[#include <IOKit/IOKitLib.h>]])
SuCicada731812d2024-04-08 18:28:32 +0900381
382 AC_CHECK_FUNCS([host_statistics64], [
383 AC_CHECK_TYPES([struct vm_statistics64], [], [], [[#include <mach/vm_statistics.h>]])
384 ], [])
Christian Göttschef3623b72021-01-22 19:14:50 +0100385fi
Christian Goettschec2fdfd92020-10-21 17:06:32 +0200386
Nathan Scottd58180b2022-09-13 12:14:40 +1000387if test "$my_htop_platform" = pcp; then
388 AC_CHECK_FUNCS([pmLookupDescs])
389fi
390
Christian Göttsche575edff2021-01-22 19:14:59 +0100391if test "$my_htop_platform" = linux && test "x$enable_static" = xyes; then
Christian Göttschee59176f2024-01-10 17:12:18 +0100392 AC_CHECK_LIB([systemd], [sd_bus_open_system], [], [], [-lcap])
Christian Göttsche575edff2021-01-22 19:14:59 +0100393fi
394
Hisham Muhammad300af4b2014-11-19 23:17:16 -0200395# ----------------------------------------------------------------------
Hisham Muhammadeb229d92014-11-24 18:55:03 -0200396
Hisham Muhammadd6231ba2006-03-04 18:16:49 +0000397
Christian Göttschef3623b72021-01-22 19:14:50 +0100398# ----------------------------------------------------------------------
399# Checks for cross-platform features and flags.
400# ----------------------------------------------------------------------
Hisham Muhammada5dfaa22008-09-23 04:31:13 +0000401
Explorer09fd083142024-09-19 06:08:41 +0800402dnl PKG_PROG_PKG_CONFIG initializes $PKG_CONFIG and related variables.
403dnl If the macro is not called, some pkg-config checks might be skipped
404dnl and $PKG_CONFIG might be unset.
405m4_ifdef([PKG_PROG_PKG_CONFIG], [
406 PKG_PROG_PKG_CONFIG()
Explorer0976e7dd42024-10-29 07:57:54 +0800407 pkg_m4_included=1 # Makefile might grep this keyword. Don't remove.
Explorer09baf70412024-09-19 06:15:08 +0800408], [
Explorer09baf70412024-09-19 06:15:08 +0800409 m4_warn(
410 [syntax],
411 [pkg.m4 is absent or older than version 0.16; this 'configure' would have incomplete pkg-config support])
Explorer09fd083142024-09-19 06:08:41 +0800412])
413
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100414AC_ARG_ENABLE([unicode],
415 [AS_HELP_STRING([--enable-unicode],
416 [enable Unicode support @<:@default=yes@:>@])],
417 [],
418 [enable_unicode=yes])
Hisham Muhammaddb682862015-12-09 17:17:30 -0200419
Explorer095d1948b2024-09-19 06:27:31 +0800420AC_ARG_VAR([CURSES_CFLAGS], [C compiler flags for curses; this overrides auto detected values])
421AC_ARG_VAR([CURSES_LIBS], [linker flags for curses; this overrides auto detected values])
422
Explorer097ad9ec22024-10-29 07:59:30 +0800423curses_pkg_names="ncurses6 ncurses5 ncurses ncursest6 ncursest5 \
424 ncursest curses"
Explorer095d1948b2024-09-19 06:27:31 +0800425
426if test "x$enable_unicode" = xyes; then
Explorer097ad9ec22024-10-29 07:59:30 +0800427 curses_pkg_names="ncursesw6 ncursesw5 ncursesw ncursestw6 ncursestw5 \
428 ncursestw $curses_pkg_names"
Explorer095d1948b2024-09-19 06:27:31 +0800429fi
430
431AC_ARG_WITH([curses],
432 [AS_HELP_STRING([--with-curses=NAME],
433 [select curses package NAME to link with; e.g. ncursesw6])],
434 [],
435 [with_curses=check])
436case $with_curses in
Explorer0952c9e3d2024-10-26 21:00:57 +0800437check|yes)
Explorer095d1948b2024-09-19 06:27:31 +0800438 : # No-op. Use default list.
439 ;;
Explorer0952c9e3d2024-10-26 21:00:57 +0800440no)
Explorer095d1948b2024-09-19 06:27:31 +0800441 AC_MSG_ERROR([bad value '$with_curses' for --with-curses option])
442 ;;
443*)
444 if test "x${CURSES_CFLAGS+y}${CURSES_LIBS+y}" = xyy; then
445 AC_MSG_WARN([ignoring --with-curses value due to override])
446 fi
447 curses_pkg_names=`echo "x$with_curses" | sed 's/^x\(lib\)\{0,1\}//'`
448 ;;
449esac
450
451# $1: C preprocessor and compiler flags for curses library
452# $2: linker flags for curses library
453htop_check_curses_capability () {
454 htop_curses_cflags=${CURSES_CFLAGS-"$1"}
455 htop_curses_libs=${CURSES_LIBS-"$2"}
456
457 echo "curses cflags${CURSES_CFLAGS+ (override)}: $htop_curses_cflags" >&AS_MESSAGE_LOG_FD
458 echo "curses libs${CURSES_LIBS+ (override)}: $htop_curses_libs" >&AS_MESSAGE_LOG_FD
459
460 htop_msg_linker_flags=$htop_curses_libs
461 if test "`echo x $htop_msg_linker_flags`" = x; then
462 htop_msg_linker_flags="(no linker flags)"
463 fi
464
465 htop_curses_status=0 # 0 for success; nonzero for failure
466
467 htop_save_CFLAGS=$CFLAGS
468 htop_save_LIBS=$LIBS
469 CFLAGS="$AM_CFLAGS $htop_curses_cflags $CFLAGS"
470 LIBS="$htop_curses_libs $LIBS"
471
472 # At this point we have not checked the name of curses header, so
473 # use forward declaration for the linking tests below.
474
Explorer09b4582992024-10-29 07:59:08 +0800475 # htop uses keypad(), but for ncurses implementation, the symbol is
476 # in "-ltinfo" and not "-lncurses".
Explorer09d5f24d22024-08-21 19:56:21 +0800477 # Check "-ltinfo" symbols first, as libncurses might require
478 # explicit "-ltinfo" to link (for internal dependency).
479 AC_MSG_CHECKING([for keypad in $htop_msg_linker_flags])
480 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer09d5f24d22024-08-21 19:56:21 +0800481/* int keypad(WINDOW* win, bool enable); */
Explorer09d5f24d22024-08-21 19:56:21 +0800482int keypad(void* win, int enable);
483 ]], [[
Explorer09b4582992024-10-29 07:59:08 +0800484static char dummy;
485keypad((void*)&dummy, 0);
Explorer09d5f24d22024-08-21 19:56:21 +0800486 ]])],
487 [AC_MSG_RESULT(yes)],
488 [AC_MSG_RESULT(no)
489 htop_curses_status=1])
490
Explorer095d1948b2024-09-19 06:27:31 +0800491 # htop calls refresh(), which might be implemented as a macro.
492 # It is more reliable to test linking with doupdate(), which
493 # refresh() would call internally.
Explorer09d5f24d22024-08-21 19:56:21 +0800494 if test "$htop_curses_status" -eq 0; then
495 AC_MSG_CHECKING([for doupdate in $htop_msg_linker_flags])
496 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer095d1948b2024-09-19 06:27:31 +0800497int doupdate(void);
Explorer09d5f24d22024-08-21 19:56:21 +0800498 ]], [[
Explorer095d1948b2024-09-19 06:27:31 +0800499doupdate();
Explorer09d5f24d22024-08-21 19:56:21 +0800500 ]])],
501 [AC_MSG_RESULT(yes)
502 htop_curses_capability=nonwide],
503 [AC_MSG_RESULT(no)
504 htop_curses_status=1])
505 fi
Explorer095d1948b2024-09-19 06:27:31 +0800506
Explorer093b66b202024-10-29 07:59:14 +0800507 # htop calls mvadd_wchnstr(), which might be implemented as a macro.
508 # It is more reliable to test linking with wadd_wchnstr().
Explorer095d1948b2024-09-19 06:27:31 +0800509 if test "x$htop_curses_status$enable_unicode" = x0yes; then
Explorer093b66b202024-10-29 07:59:14 +0800510 AC_MSG_CHECKING([for wadd_wchnstr in $htop_msg_linker_flags])
Explorer095d1948b2024-09-19 06:27:31 +0800511 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer093b66b202024-10-29 07:59:14 +0800512/* int wadd_wchnstr(WINDOW* win, const cchar_t* wchstr, int n); */
513int wadd_wchnstr(void* win, const void* wchstr, int n);
Explorer095d1948b2024-09-19 06:27:31 +0800514 ]], [[
Explorer093b66b202024-10-29 07:59:14 +0800515static char dummy1;
516static char dummy2;
517wadd_wchnstr((void*)&dummy1, (void*)&dummy2, 0);
Explorer095d1948b2024-09-19 06:27:31 +0800518 ]])],
519 [AC_MSG_RESULT(yes)
520 htop_curses_capability=wide],
521 [AC_MSG_RESULT(no)
522 htop_curses_status=1])
523 fi
524
525 if test "$htop_curses_status" -eq 0; then
526 AM_CFLAGS="$AM_CFLAGS $htop_curses_cflags"
527 if test "$htop_curses_capability" = wide; then
528 AC_DEFINE([HAVE_LIBNCURSESW], 1, [libncursesw is present])
529 else
530 AC_DEFINE([HAVE_LIBNCURSES], 1, [libcurses is present])
531 fi
532 else
533 LIBS=$htop_save_LIBS
534 fi
535 CFLAGS=$htop_save_CFLAGS
536 return "$htop_curses_status"
537} # htop_check_curses_capability
538
539htop_curses_capability=none
540
541if test "x${CURSES_CFLAGS+y}${CURSES_LIBS+y}" = xyy; then
542 curses_pkg_names=""
543 htop_check_curses_capability "$CURSES_CFLAGS" "$CURSES_LIBS"
544fi
545
546# Prioritize $PKG_CONFIG over ncurses*-config, as users might need to
547# cross-compile htop.
548if test "x$PKG_CONFIG" != x; then
549 pkg_config_static_flag=""
550 if test "$enable_static" = yes; then
551 pkg_config_static_flag=--static
552 fi
553
554 for curses_name in $curses_pkg_names; do
555 echo retrieving $curses_name information through $PKG_CONFIG >&AS_MESSAGE_LOG_FD
556 $PKG_CONFIG --exists --print-errors $curses_name >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD || continue
557
558 : # Resets "$?" to 0
559 htop_config_cflags=`$PKG_CONFIG --cflags $pkg_config_static_flag $curses_name 2>/dev/null` || continue
560 : # Resets "$?" to 0
561 htop_config_libs=`$PKG_CONFIG --libs $pkg_config_static_flag $curses_name 2>/dev/null` || continue
562
563 AC_MSG_RESULT([found $curses_name information through $PKG_CONFIG])
564
565 if htop_check_curses_capability "$htop_config_cflags" "$htop_config_libs"; then
566 break
567 fi
568 done
569fi
570
571case ${htop_curses_capability}-$enable_unicode in
572none-*|nonwide-yes)
573 for curses_name in $curses_pkg_names; do
574 echo retrieving $curses_name information through ${curses_name}-config >&AS_MESSAGE_LOG_FD
575
576 ${curses_name}-config --cflags >/dev/null 2>&AS_MESSAGE_LOG_FD || continue
577
578 : # Resets "$?" to 0
579 htop_config_cflags=`${curses_name}-config --cflags 2>/dev/null` || continue
580 : # Resets "$?" to 0
581 htop_config_libs=`${curses_name}-config --libs 2>/dev/null` || continue
582
583 AC_MSG_RESULT([found $curses_name information through ${curses_name}-config])
584
585 if htop_check_curses_capability "$htop_config_cflags" "$htop_config_libs"; then
586 break
587 fi
588 done
589 ;;
590esac
591
592case ${htop_curses_capability}-$enable_unicode in
593none-*|nonwide-yes)
Explorer09082b9772024-09-19 06:28:42 +0800594 if test "x$PKG_CONFIG" = x; then (
595 # Friendly warning to advise user to install pkg-config.
596 # The local variables get discarded when done.
597 list=""
598 echo "" >conftest.c
599 if test "$cross_compiling" != yes; then
600 # "-print-multi-directory" supported in GCC 3.0 or later
601 name=""
602 if $CC $CPPFLAGS $CFLAGS -print-multi-directory -E conftest.c >/dev/null 2>&1; then
603 name=`$CC $CPPFLAGS $CFLAGS -print-multi-directory -E conftest.c 2>/dev/null |
604 sed '/^ *#/ d; s/^\.$//; q'`
605 fi
606 list="/usr/lib${name}/pkgconfig $list"
607 case $host_os in
608 darwin*)
609 list="/opt/homebrew/Library/Homebrew/os/mac/pkgconfig $list"
610 ;;
611 freebsd*)
612 list="/usr/libdata/pkgconfig $list"
613 ;;
614 netbsd*)
615 list="/usr/pkg/lib/pkgconfig $list"
616 ;;
617 esac
618 fi
619 if test "x$host_alias" != x; then
620 list="/usr/lib/${host_alias}/pkgconfig $list"
621 fi
622 # "-print-multiarch" supported in GCC 4.6 or later
623 if $CC $CPPFLAGS $CFLAGS -print-multiarch -E conftest.c >/dev/null 2>&1; then
624 name=`$CC $CPPFLAGS $CFLAGS -print-multiarch -E conftest.c 2>/dev/null |
625 sed '/^ *#/ d; q'`
626 if test "x$name" != x; then
627 list="/usr/lib/${name}/pkgconfig $list"
628 fi
629 fi
630 rm -f conftest.*
631
632 for d in $list; do
633 result=`find "$d" -name '*curses*.pc' 2>/dev/null | sed '1 q'`
634 if test "x$result" != x; then
Explorer09d464ad12024-10-28 17:04:21 +0800635 echo detected a .pc file: "$result" >&AS_MESSAGE_LOG_FD
Explorer09082b9772024-09-19 06:28:42 +0800636 AC_MSG_WARN([your system supports pkg-config; installing pkg-config is recommended before configuring htop])
Explorer0976e7dd42024-10-29 07:57:54 +0800637 m4_ifdef([PKG_PROG_PKG_CONFIG], [], [
638 AC_MSG_WARN([this configure script would also need to be regenerated])
639 ])
Explorer09082b9772024-09-19 06:28:42 +0800640 break
641 fi
642 done
643 ) fi
644
Explorer095d1948b2024-09-19 06:27:31 +0800645 # OpenBSD and Solaris are known to not provide '*curses*.pc' files.
646 AC_MSG_RESULT([no curses information found through '*-config' utilities; will guess the linker flags])
647 for curses_name in $curses_pkg_names; do
648 if htop_check_curses_capability "" "-l$curses_name"; then
649 break
650 fi
Explorer09e3bdb102024-10-29 07:59:30 +0800651 # For ncurses implementation, an extra terminfo library might be
652 # needed. Guess the terminfo library name based on the ncurses
653 # library file name (e.g. "-ltinfow" for "-lncursesw"), before
654 # trying the "-ltinfo" name.
655 tinfo_name=`echo x$curses_name | sed 's/^xncurses/tinfo/p; d'`
656 case x$tinfo_name in
657 x|xtinfo)
658 ;;
659 *)
660 if htop_check_curses_capability "" "-l$curses_name -l$tinfo_name"; then
661 break
662 fi
663 ;;
664 esac
Explorer09d5f24d22024-08-21 19:56:21 +0800665 if htop_check_curses_capability "" "-l$curses_name -ltinfo"; then
666 break
667 fi
Explorer095d1948b2024-09-19 06:27:31 +0800668 done
669 ;;
670esac
671
672case ${htop_curses_capability}-$enable_unicode in
673nonwide-yes)
674 AC_MSG_ERROR([cannot find required ncursesw library; you may want to use --disable-unicode])
675 ;;
676none-*)
677 AC_MSG_ERROR([cannot find required curses/ncurses library])
678 ;;
679esac
680
681htop_save_CFLAGS=$CFLAGS
682CFLAGS="$AM_CFLAGS $CFLAGS"
Explorer09a2d90f42024-10-29 07:59:23 +0800683
Explorer095d1948b2024-09-19 06:27:31 +0800684if test "x$enable_unicode" = xyes; then
Christian Göttsche759a3402021-01-22 19:14:55 +0100685 AC_CHECK_HEADERS([ncursesw/curses.h], [],
686 [AC_CHECK_HEADERS([ncurses/ncurses.h], [],
687 [AC_CHECK_HEADERS([ncurses/curses.h], [],
688 [AC_CHECK_HEADERS([ncurses.h], [],
689 [AC_MSG_ERROR([can not find required ncurses header file])])])])])
Christian Göttscheead978b2020-12-07 15:30:56 +0100690
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530691 AC_CHECK_HEADERS([ncursesw/term.h], [],
692 [AC_CHECK_HEADERS([ncurses/term.h], [],
693 [AC_CHECK_HEADERS([term.h], [],
694 [AC_MSG_ERROR([can not find required term header file])])])])
Hisham Muhammad8fa33dc2008-03-09 02:33:23 +0000695else
Christian Göttsche759a3402021-01-22 19:14:55 +0100696 AC_CHECK_HEADERS([curses.h], [],
697 [AC_CHECK_HEADERS([ncurses/curses.h], [],
698 [AC_CHECK_HEADERS([ncurses/ncurses.h], [],
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530699 [AC_CHECK_HEADERS([ncurses.h], [],
Christian Göttsche759a3402021-01-22 19:14:55 +0100700 [AC_MSG_ERROR([can not find required ncurses header file])])])])])
Christian Göttscheead978b2020-12-07 15:30:56 +0100701
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530702 AC_CHECK_HEADERS([ncurses/term.h], [],
703 [AC_CHECK_HEADERS([term.h], [],
704 [AC_MSG_ERROR([can not find required term header file])])])
Hisham Muhammad4c51ad02007-08-10 05:07:14 +0000705fi
Explorer09a2d90f42024-10-29 07:59:23 +0800706
707CFLAGS="-I$srcdir $CFLAGS"
708
709# Check for things that might be macros.
710# "stdscr" is a macro in ncursest (reentrant version of ncurses).
711AC_MSG_CHECKING([whether the curses header works])
712AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer09f0237902024-10-29 07:59:30 +0800713/* Checks if the "bool" definition in curses is ISO C compatible */
714#include <stdbool.h>
715
Explorer09a2d90f42024-10-29 07:59:23 +0800716#include "ProvideCurses.h"
717 ]], [[
Explorer09f0237902024-10-29 07:59:30 +0800718keypad(stdscr, false);
Explorer09a2d90f42024-10-29 07:59:23 +0800719
720refresh();
721
722#if defined(HAVE_LIBNCURSESW)
723{
724 static cchar_t dummy;
725 mvadd_wchnstr(0, 0, &dummy, 0);
726}
727#endif
728 ]])],
729 [AC_MSG_RESULT(yes)],
730 [AC_MSG_RESULT(no)
731 AC_MSG_FAILURE([there are problems with the curses header])]
732)
733
Explorer095d1948b2024-09-19 06:27:31 +0800734CFLAGS=$htop_save_CFLAGS
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530735
Christian Göttsche575edff2021-01-22 19:14:59 +0100736if test "$enable_static" = yes; then
737 AC_SEARCH_LIBS([Gpm_GetEvent], [gpm])
738fi
Christian Göttscheee9e7ed2021-05-20 18:27:10 +0200739if test "$my_htop_platform" = "solaris"; then
740 # On OmniOS /usr/include/sys/regset.h redefines ERR to 13 - \r, breaking the Enter key.
Nathan Scottca06e682021-09-08 12:11:51 +1000741 # Since ncurses macros use the ERR macro, we can not use another name.
Christian Göttscheee9e7ed2021-05-20 18:27:10 +0200742 AC_DEFINE([ERR], [(-1)], [Predefine ncurses macro.])
743fi
Benny Baumann18e3fd52021-07-04 16:50:41 +0200744AC_CHECK_FUNCS( [set_escdelay] )
nia2ab8fb82021-07-14 20:17:13 +0200745AC_CHECK_FUNCS( [getmouse] )
Benny Baumann04d0a542024-12-09 22:18:08 +0100746AC_DEFINE([NCURSES_ENABLE_STDBOOL_H], [1], [Define to enable stdbool.h in ncurses])
Hisham Muhammad4c51ad02007-08-10 05:07:14 +0000747
gmbroome697f5bb2018-03-02 16:20:46 -0500748
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200749AC_ARG_ENABLE([affinity],
750 [AS_HELP_STRING([--enable-affinity],
751 [enable sched_setaffinity and sched_getaffinity for affinity support, conflicts with hwloc @<:@default=check@:>@])],
752 [],
753 [enable_affinity=check])
754if test "x$enable_affinity" = xcheck; then
755 if test "x$enable_hwloc" = xyes; then
756 enable_affinity=no
757 else
758 AC_MSG_CHECKING([for usable sched_setaffinity])
759 AC_RUN_IFELSE([
760 AC_LANG_PROGRAM([[
761 #include <sched.h>
762 #include <errno.h>
763 static cpu_set_t cpuset;
764 ]], [[
765 CPU_ZERO(&cpuset);
766 sched_setaffinity(0, sizeof(cpu_set_t), &cpuset);
767 if (errno == ENOSYS) return 1;
768 ]])],
769 [enable_affinity=yes
770 AC_MSG_RESULT([yes])],
771 [enable_affinity=no
772 AC_MSG_RESULT([no])],
Explorer0947ae9662023-07-29 03:11:54 +0800773 [AC_MSG_RESULT([assume yes (cross compiling)])])
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200774 fi
775fi
776if test "x$enable_affinity" = xyes; then
777 if test "x$enable_hwloc" = xyes; then
778 AC_MSG_ERROR([--enable-hwloc and --enable-affinity are mutual exclusive. Specify at most one of them.])
779 fi
780 AC_DEFINE([HAVE_AFFINITY], [1], [Define if sched_setaffinity and sched_getaffinity are to be used.])
781fi
782
783
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200784AC_ARG_ENABLE([unwind],
785 [AS_HELP_STRING([--enable-unwind],
786 [enable unwind support for printing backtraces; requires libunwind @<:@default=check@:>@])],
787 [],
788 [enable_unwind=check])
789case "$enable_unwind" in
790 check)
791 enable_unwind=yes
792 if test "$enable_static" = yes; then
793 AC_CHECK_LIB([lzma], [lzma_index_buffer_decode])
794 fi
795 AC_CHECK_LIB([unwind], [backtrace], [], [enable_unwind=no])
Christian Göttsche63880332021-12-14 17:36:57 +0100796 AC_CHECK_HEADERS([libunwind.h], [], [
797 old_CFLAGS="$CFLAGS"
798 CFLAGS="$CFLAGS -I/usr/include/libunwind"
799 AC_CHECK_HEADERS([libunwind/libunwind.h], [], [
800 enable_unwind=no
801 CFLAGS="$old_CFLAGS"
802 ])
803 ])
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200804 ;;
805 no)
806 ;;
807 yes)
808 AC_CHECK_LIB([unwind], [backtrace], [], [AC_MSG_ERROR([can not find required library libunwind])])
Christian Göttsche63880332021-12-14 17:36:57 +0100809 AC_CHECK_HEADERS([libunwind.h], [], [
Benny Baumann5c7cb912023-11-28 17:42:04 +0100810 AM_CFLAGS="$AM_CFLAGS -I/usr/include/libunwind"
Christian Göttsche63880332021-12-14 17:36:57 +0100811 AC_CHECK_HEADERS([libunwind/libunwind.h], [], [AC_MSG_ERROR([can not find required header file libunwind.h])])
812 ])
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200813 ;;
814 *)
815 AC_MSG_ERROR([bad value '$enable_unwind' for --enable-unwind])
816 ;;
817esac
818if test "x$enable_unwind" = xno; then
819 # Fall back to backtrace(3) and add -lexecinfo if needed
820 AC_SEARCH_LIBS([backtrace], [execinfo])
821fi
822
823
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100824AC_ARG_ENABLE([hwloc],
825 [AS_HELP_STRING([--enable-hwloc],
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200826 [enable hwloc support for CPU affinity; disables affinity support; requires libhwloc @<:@default=no@:>@])],
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100827 [],
828 [enable_hwloc=no])
829case "$enable_hwloc" in
830 no)
831 ;;
832 yes)
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200833 m4_ifdef([PKG_PROG_PKG_CONFIG], [
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200834 PKG_CHECK_MODULES(HWLOC, hwloc, [
Benny Baumann5c7cb912023-11-28 17:42:04 +0100835 AM_CFLAGS="$AM_CFLAGS $HWLOC_CFLAGS"
Christian Göttschec8a61852023-04-05 01:21:14 +0200836 LIBS="$LIBS $HWLOC_LIBS"
Explorer0947ae9662023-07-29 03:11:54 +0800837 AC_DEFINE([HAVE_LIBHWLOC], [1], [Define to 1 if you have the 'hwloc' library (-lhwloc).])
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200838 ], [
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 ])
842 ], [
843 AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [AC_MSG_ERROR([can not find required library libhwloc])])
844 AC_CHECK_HEADERS([hwloc.h], [], [AC_MSG_ERROR([can not find require header file hwloc.h])])
845 ])
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100846 ;;
847 *)
848 AC_MSG_ERROR([bad value '$enable_hwloc' for --enable-hwloc])
849 ;;
850esac
Christian Göttsche005c4d12020-09-08 16:25:22 +0200851
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200852
Nathan Scott5b50ae32021-03-02 15:58:11 +1100853AC_ARG_WITH([os-release],
854 [AS_HELP_STRING([--with-os-release=FILE],
Christian Göttsche8ba4ef32021-03-12 16:37:17 +0100855 [location of an os-release file @<:@default=/etc/os-release@:>@])],
Nathan Scott5b50ae32021-03-02 15:58:11 +1100856 [],
857 [with_os_release=/etc/os-release])
Christian Göttsche8ba4ef32021-03-12 16:37:17 +0100858if test -n "$with_os_release" && test ! -f "$with_os_release"; then
Nathan Scott5b50ae32021-03-02 15:58:11 +1100859 if test -f "/usr/lib/os-release"; then
860 with_os_release="/usr/lib/os-release"
861 fi
862fi
863AC_DEFINE_UNQUOTED([OSRELEASEFILE], ["$with_os_release"], [File with OS release details.])
864
Nathan Scott1a7b6d42024-07-22 08:51:29 +1000865AC_ARG_WITH([config],
866 [AS_HELP_STRING([--with-config=DIR],
Explorer09c802dc42024-09-19 06:37:00 +0800867 [configuration path @<:@default=/.config@:>@])],
Nathan Scott1a7b6d42024-07-22 08:51:29 +1000868 [],
869 [with_config="/.config"])
870dnl Performance Co-Pilot configuration location to prevent overwrite
871if test "$my_htop_platform" = pcp -a "$with_config" = /.config; then
872 with_config="/.pcp"
873elif test -z "$with_config"; then
874 AC_MSG_ERROR([bad empty value for --with-config option])
875fi
876AC_DEFINE_UNQUOTED([CONFIGDIR], ["$with_config"], [Configuration path.])
877
Christian Göttschef3623b72021-01-22 19:14:50 +0100878# ----------------------------------------------------------------------
879
880
881# ----------------------------------------------------------------------
882# Checks for Linux features and flags.
883# ----------------------------------------------------------------------
884
885AC_ARG_WITH([proc],
886 [AS_HELP_STRING([--with-proc=DIR],
887 [location of a Linux-compatible proc filesystem @<:@default=/proc@:>@])],
888 [],
889 [with_proc=/proc])
890if test -z "$with_proc"; then
891 AC_MSG_ERROR([bad empty value for --with-proc option])
892fi
893AC_DEFINE_UNQUOTED([PROCDIR], ["$with_proc"], [Path of proc filesystem.])
894
895
896AC_ARG_ENABLE([openvz],
897 [AS_HELP_STRING([--enable-openvz],
898 [enable OpenVZ support @<:@default=no@:>@])],
899 [],
900 [enable_openvz=no])
901if test "x$enable_openvz" = xyes; then
902 AC_DEFINE([HAVE_OPENVZ], [1], [Define if openvz support enabled.])
903fi
904
905
906AC_ARG_ENABLE([vserver],
907 [AS_HELP_STRING([--enable-vserver],
908 [enable VServer support @<:@default=no@:>@])],
909 [],
910 [enable_vserver=no])
911if test "x$enable_vserver" = xyes; then
Christian Göttsche284f8c52021-09-02 22:32:46 +0200912 AC_DEFINE([HAVE_VSERVER], [1], [Define if VServer support enabled.])
Christian Göttschef3623b72021-01-22 19:14:50 +0100913fi
914
915
916AC_ARG_ENABLE([ancient_vserver],
917 [AS_HELP_STRING([--enable-ancient-vserver],
918 [enable ancient VServer support (implies --enable-vserver) @<:@default=no@:>@])],
919 [],
920 [enable_ancient_vserver=no])
921if test "x$enable_ancient_vserver" = xyes; then
Christian Göttsche284f8c52021-09-02 22:32:46 +0200922 if test "x$enable_vserver" != xyes; then
923 enable_vserver=implied
924 fi
925 AC_DEFINE([HAVE_VSERVER], [1], [Define if VServer support enabled.])
926 AC_DEFINE([HAVE_ANCIENT_VSERVER], [1], [Define if ancient vserver support enabled.])
Christian Göttschef3623b72021-01-22 19:14:50 +0100927fi
928
929
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100930AC_ARG_ENABLE([capabilities],
931 [AS_HELP_STRING([--enable-capabilities],
932 [enable Linux capabilities support; requires libcap @<:@default=check@:>@])],
933 [],
934 [enable_capabilities=check])
935case "$enable_capabilities" in
936 no)
937 ;;
938 check)
939 enable_capabilities=yes
940 AC_CHECK_LIB([cap], [cap_init], [], [enable_capabilities=no])
941 AC_CHECK_HEADERS([sys/capability.h], [], [enable_capabilities=no])
942 ;;
943 yes)
Christian Göttsche759a3402021-01-22 19:14:55 +0100944 AC_CHECK_LIB([cap], [cap_init], [], [AC_MSG_ERROR([can not find required library libcap])])
945 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 +0100946 ;;
947 *)
948 AC_MSG_ERROR([bad value '$enable_capabilities' for --enable-capabilities])
949 ;;
950esac
Christian Göttschef4404ef2020-09-02 14:39:25 +0200951
Christian Göttschef3623b72021-01-22 19:14:50 +0100952
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100953AC_ARG_ENABLE([delayacct],
954 [AS_HELP_STRING([--enable-delayacct],
955 [enable Linux delay accounting support; requires pkg-config, libnl-3 and libnl-genl-3 @<:@default=check@:>@])],
956 [],
957 [enable_delayacct=check])
958case "$enable_delayacct" in
959 no)
960 ;;
961 check)
Christian Göttsche69cfaf22021-05-16 20:01:25 +0200962 if test "$my_htop_platform" != linux; then
963 enable_delayacct=no
964 elif test "$enable_static" = yes; then
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100965 enable_delayacct=no
Christian Göttsche575edff2021-01-22 19:14:59 +0100966 else
Christian Göttsche24b15132024-03-30 13:47:14 +0100967 old_CFLAGS="$CFLAGS"
968 CFLAGS="$CFLAGS -I/usr/include/libnl3"
969 AC_CHECK_HEADERS([netlink/attr.h netlink/handlers.h netlink/msg.h], [enable_delayacct=yes], [enable_delayacct=no])
970 CFLAGS="$old_CFLAGS"
Christian Göttsche575edff2021-01-22 19:14:59 +0100971 fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100972 ;;
973 yes)
Christian Göttsche24b15132024-03-30 13:47:14 +0100974 old_CFLAGS="$CFLAGS"
975 CFLAGS="$CFLAGS -I/usr/include/libnl3"
976 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])])
977 CFLAGS="$old_CFLAGS"
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100978 ;;
979 *)
980 AC_MSG_ERROR([bad value '$enable_delayacct' for --enable-delayacct])
981 ;;
982esac
Christian Göttsche24b15132024-03-30 13:47:14 +0100983if test "$enable_delayacct" = yes; then
984 AC_DEFINE([HAVE_DELAYACCT], [1], [Define if delay accounting support should be enabled.])
985 AM_CFLAGS="$AM_CFLAGS -I/usr/include/libnl3"
986fi
Christian Göttschea782ef32024-03-30 13:47:10 +0100987AM_CONDITIONAL([HAVE_DELAYACCT], [test "$enable_delayacct" = yes])
André Carvalhob7b66b72017-12-04 00:15:29 -0200988
Christian Göttschef3623b72021-01-22 19:14:50 +0100989
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100990AC_ARG_ENABLE([sensors],
991 [AS_HELP_STRING([--enable-sensors],
992 [enable libsensors support for reading temperature data; requires only libsensors headers at compile time, at runtime libsensors is loaded via dlopen @<:@default=check@:>@])],
993 [],
994 [enable_sensors=check])
995case "$enable_sensors" in
996 no)
997 ;;
998 check)
999 enable_sensors=yes
Christian Göttsche575edff2021-01-22 19:14:59 +01001000 if test "$enable_static" = yes; then
1001 AC_CHECK_LIB([sensors], [sensors_init], [], [enable_sensors=no])
1002 fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001003 AC_CHECK_HEADERS([sensors/sensors.h], [], [enable_sensors=no])
1004 ;;
1005 yes)
Christian Göttsche575edff2021-01-22 19:14:59 +01001006 if test "$enable_static" = yes; then
1007 AC_CHECK_LIB([sensors], [sensors_init], [], [AC_MSG_ERROR([can not find required library libsensors])])
1008 fi
1009 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 +01001010 ;;
1011 *)
1012 AC_MSG_ERROR([bad value '$enable_sensors' for --enable-sensors])
1013 ;;
1014esac
Christian Göttschefd2a0cf2020-12-22 20:02:01 +01001015if test "$enable_sensors" = yes || test "$my_htop_platform" = freebsd; then
1016 AC_DEFINE([BUILD_WITH_CPU_TEMP], [1], [Define if CPU temperature option should be enabled.])
1017fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001018
Christian Göttschef3623b72021-01-22 19:14:50 +01001019# ----------------------------------------------------------------------
1020
1021
1022# ----------------------------------------------------------------------
1023# Checks for compiler warnings.
1024# ----------------------------------------------------------------------
Christian Göttsche1b225cd2020-09-10 19:56:33 +02001025
Benny Baumann5c7cb912023-11-28 17:42:04 +01001026AM_CFLAGS="$AM_CFLAGS\
Christian Göttschef4602f72020-09-08 14:25:46 +02001027 -Wall\
1028 -Wcast-align\
Christian Göttschedb472072020-10-04 14:30:35 +02001029 -Wcast-qual\
Christian Göttschef4602f72020-09-08 14:25:46 +02001030 -Wextra\
Benny Baumannba0fca12020-09-18 16:58:03 +02001031 -Wfloat-equal\
Christian Göttschec150e4b2020-12-18 15:49:37 +01001032 -Wformat=2\
Christian Göttsche4dadbe32021-01-21 19:49:07 +01001033 -Winit-self\
Christian Göttschef4602f72020-09-08 14:25:46 +02001034 -Wmissing-format-attribute\
1035 -Wmissing-noreturn\
Christian Göttsche4e282eb2020-09-25 14:03:55 +02001036 -Wmissing-prototypes\
Christian Göttschef4602f72020-09-08 14:25:46 +02001037 -Wpointer-arith\
1038 -Wshadow\
1039 -Wstrict-prototypes\
1040 -Wundef\
1041 -Wunused\
1042 -Wwrite-strings"
1043
Christian Göttschef3623b72021-01-22 19:14:50 +01001044dnl https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
1045AC_DEFUN([AX_CHECK_COMPILE_FLAG],
Christian Göttsche38b6a012021-01-22 19:14:53 +01001046[
Christian Göttschef3623b72021-01-22 19:14:50 +01001047AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
1048AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
1049 ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
1050 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
1051 AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
1052 [AS_VAR_SET(CACHEVAR,[yes])],
1053 [AS_VAR_SET(CACHEVAR,[no])])
1054 _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
1055AS_VAR_IF(CACHEVAR,yes,
1056 [m4_default([$2], :)],
1057 [m4_default([$3], :)])
1058AS_VAR_POPDEF([CACHEVAR])dnl
1059])dnl AX_CHECK_COMPILE_FLAGS
1060
Christian Göttsche970885e2021-08-14 11:21:54 +02001061AX_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 +02001062AX_CHECK_COMPILE_FLAG([-Wimplicit-int-conversion], [AM_CFLAGS="$AM_CFLAGS -Wimplicit-int-conversion"], , [-Werror])
1063AX_CHECK_COMPILE_FLAG([-Wnull-dereference], [AM_CFLAGS="$AM_CFLAGS -Wnull-dereference"], , [-Werror])
Benny Baumann2cde4a72020-09-18 19:32:41 +02001064
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001065AC_ARG_ENABLE([werror],
1066 [AS_HELP_STRING([--enable-werror],
1067 [Treat warnings as errors @<:@default=no@:>@])],
1068 [],
1069 [enable_werror=no])
1070if test "x$enable_werror" = xyes; then
1071 AM_CFLAGS="$AM_CFLAGS -Werror"
1072fi
1073
1074AC_ARG_ENABLE([debug],
1075 [AS_HELP_STRING([--enable-debug],
Daniel Lange135efd52021-02-16 11:22:02 +01001076 [Enable compiling with maximum debug info, asserts and internal sanity checks @<:@default=no@:>@])],
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001077 [],
1078 [enable_debug=no])
1079if test "x$enable_debug" != xyes; then
1080 AM_CPPFLAGS="$AM_CPPFLAGS -DNDEBUG"
Explorer0993d76fd2023-07-31 05:05:43 +08001081
1082 AC_COMPILE_IFELSE([
1083 AC_LANG_SOURCE([[
1084#ifdef __SUPPORT_SNAN__
1085#error "signaling NaN support not recommended"
1086#endif
1087 ]])],
1088 :,
1089 [warning_msg="signaling NaN support is enabled; not recommended for htop"
1090 case "$CC" in
1091 *gcc*)
1092 warning_msg="$warning_msg (use '-fno-signaling-nans' compiler flag to disable)"
1093 ;;
1094 esac
1095 AC_MSG_WARN([$warning_msg])
1096 ])
Daniel Lange135efd52021-02-16 11:22:02 +01001097else
1098 AM_CPPFLAGS="$AM_CPPFLAGS -ggdb3"
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001099fi
Christian Göttscheb7f63292020-09-17 22:23:05 +02001100
Christian Göttschef3623b72021-01-22 19:14:50 +01001101
Christian Göttsche57254cd2020-08-21 10:37:20 +02001102AC_SUBST([AM_CFLAGS])
Christian Göttscheb7f63292020-09-17 22:23:05 +02001103AC_SUBST([AM_CPPFLAGS])
1104
Christian Göttschef3623b72021-01-22 19:14:50 +01001105# ----------------------------------------------------------------------
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001106
Christian Göttschef3623b72021-01-22 19:14:50 +01001107
1108# ----------------------------------------------------------------------
Hisham Muhammad300af4b2014-11-19 23:17:16 -02001109# We're done, let's go!
1110# ----------------------------------------------------------------------
Christian Göttschef3623b72021-01-22 19:14:50 +01001111
Daniel Lange1f242502025-01-01 02:45:10 +01001112AC_DEFINE_UNQUOTED([COPYRIGHT], ["(C) 2004-2019 Hisham Muhammad. (C) 2020-2025 htop dev team."], [Copyright message.])
Christian Göttschef3623b72021-01-22 19:14:50 +01001113
Hisham Muhammada75161f2014-11-24 20:11:33 -02001114AM_CONDITIONAL([HTOP_LINUX], [test "$my_htop_platform" = linux])
Hisham Muhammad8915b292014-11-27 16:27:34 -02001115AM_CONDITIONAL([HTOP_FREEBSD], [test "$my_htop_platform" = freebsd])
Diederik de Grootb258d6e2017-04-19 16:12:17 +02001116AM_CONDITIONAL([HTOP_DRAGONFLYBSD], [test "$my_htop_platform" = dragonflybsd])
fraggerfox4b49de42021-03-15 13:14:39 +05301117AM_CONDITIONAL([HTOP_NETBSD], [test "$my_htop_platform" = netbsd])
Michael McConvillea9a5a532015-09-18 00:46:48 -04001118AM_CONDITIONAL([HTOP_OPENBSD], [test "$my_htop_platform" = openbsd])
David Hunt70e7c8d2015-07-12 13:47:43 -05001119AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin])
gmbroome697f5bb2018-03-02 16:20:46 -05001120AM_CONDITIONAL([HTOP_SOLARIS], [test "$my_htop_platform" = solaris])
Nathan Scottc14a45b2021-02-17 14:43:56 +11001121AM_CONDITIONAL([HTOP_PCP], [test "$my_htop_platform" = pcp])
Hisham Muhammada75161f2014-11-24 20:11:33 -02001122AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported])
Christian Göttsche38b6a012021-01-22 19:14:53 +01001123
Hisham Muhammadeb229d92014-11-24 18:55:03 -02001124AC_SUBST(my_htop_platform)
Daniel Langefc2377f2021-08-14 10:35:11 +02001125AC_CONFIG_FILES([Makefile htop.1])
Hisham Muhammadd6231ba2006-03-04 18:16:49 +00001126AC_OUTPUT
Hisham Muhammadc39f18a2017-07-10 20:14:25 -03001127
Christian Göttschef3623b72021-01-22 19:14:50 +01001128if test "$my_htop_platform" = unsupported; then
Hisham Muhammadc39f18a2017-07-10 20:14:25 -03001129 echo ""
1130 echo "****************************************************************"
1131 echo "WARNING! This platform is not currently supported by htop."
1132 echo ""
1133 echo "The code will build, but it will produce a dummy version of htop"
1134 echo "which shows no processes, using the files from the unsupported/"
1135 echo "directory. This is meant to be a skeleton, to be used as a"
1136 echo "starting point if you are porting htop to a new platform."
1137 echo "****************************************************************"
1138 echo ""
1139fi
Christian Göttsche3b084db2020-08-28 12:10:31 +02001140
1141AC_MSG_RESULT([
1142 ${PACKAGE_NAME} ${VERSION}
1143
Christian Göttscheffd90c22020-10-05 12:29:31 +02001144 platform: $my_htop_platform
Nathan Scott5b50ae32021-03-02 15:58:11 +11001145 os-release file: $with_os_release
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001146 (Linux) proc directory: $with_proc
Christian Göttscheffd90c22020-10-05 12:29:31 +02001147 (Linux) openvz: $enable_openvz
Christian Göttscheffd90c22020-10-05 12:29:31 +02001148 (Linux) vserver: $enable_vserver
1149 (Linux) ancient vserver: $enable_ancient_vserver
Christian Göttscheffd90c22020-10-05 12:29:31 +02001150 (Linux) delay accounting: $enable_delayacct
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001151 (Linux) sensors: $enable_sensors
1152 (Linux) capabilities: $enable_capabilities
Christian Göttscheffd90c22020-10-05 12:29:31 +02001153 unicode: $enable_unicode
Christian Göttsche1fb0c722021-06-13 11:29:39 +02001154 affinity: $enable_affinity
Christian Göttsche29e1fcf2021-05-16 20:45:09 +02001155 unwind: $enable_unwind
Daniel Lange309f1d72020-11-16 13:29:37 +01001156 hwloc: $enable_hwloc
Daniel Langea8a723f2020-11-16 17:01:51 +01001157 debug: $enable_debug
Christian Göttsche575edff2021-01-22 19:14:59 +01001158 static: $enable_static
Christian Göttsche3b084db2020-08-28 12:10:31 +02001159])