blob: 6db80ac1e6602896b051bb23035d95dea4fd1046 [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>]])
Christian Göttschef3623b72021-01-22 19:14:50 +0100381fi
Christian Goettschec2fdfd92020-10-21 17:06:32 +0200382
Nathan Scottd58180b2022-09-13 12:14:40 +1000383if test "$my_htop_platform" = pcp; then
384 AC_CHECK_FUNCS([pmLookupDescs])
385fi
386
Christian Göttsche575edff2021-01-22 19:14:59 +0100387if test "$my_htop_platform" = linux && test "x$enable_static" = xyes; then
Christian Göttschee59176f2024-01-10 17:12:18 +0100388 AC_CHECK_LIB([systemd], [sd_bus_open_system], [], [], [-lcap])
Christian Göttsche575edff2021-01-22 19:14:59 +0100389fi
390
Hisham Muhammad300af4b2014-11-19 23:17:16 -0200391# ----------------------------------------------------------------------
Hisham Muhammadeb229d92014-11-24 18:55:03 -0200392
Hisham Muhammadd6231ba2006-03-04 18:16:49 +0000393
Christian Göttschef3623b72021-01-22 19:14:50 +0100394# ----------------------------------------------------------------------
395# Checks for cross-platform features and flags.
396# ----------------------------------------------------------------------
Hisham Muhammada5dfaa22008-09-23 04:31:13 +0000397
Explorer09fd083142024-09-19 06:08:41 +0800398dnl PKG_PROG_PKG_CONFIG initializes $PKG_CONFIG and related variables.
399dnl If the macro is not called, some pkg-config checks might be skipped
400dnl and $PKG_CONFIG might be unset.
401m4_ifdef([PKG_PROG_PKG_CONFIG], [
402 PKG_PROG_PKG_CONFIG()
Explorer0976e7dd42024-10-29 07:57:54 +0800403 pkg_m4_included=1 # Makefile might grep this keyword. Don't remove.
Explorer09baf70412024-09-19 06:15:08 +0800404], [
Explorer09baf70412024-09-19 06:15:08 +0800405 m4_warn(
406 [syntax],
407 [pkg.m4 is absent or older than version 0.16; this 'configure' would have incomplete pkg-config support])
Explorer09fd083142024-09-19 06:08:41 +0800408])
409
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100410AC_ARG_ENABLE([unicode],
411 [AS_HELP_STRING([--enable-unicode],
412 [enable Unicode support @<:@default=yes@:>@])],
413 [],
414 [enable_unicode=yes])
Hisham Muhammaddb682862015-12-09 17:17:30 -0200415
Explorer095d1948b2024-09-19 06:27:31 +0800416AC_ARG_VAR([CURSES_CFLAGS], [C compiler flags for curses; this overrides auto detected values])
417AC_ARG_VAR([CURSES_LIBS], [linker flags for curses; this overrides auto detected values])
418
419curses_pkg_names="ncurses6 ncurses5 ncurses curses"
420
421if test "x$enable_unicode" = xyes; then
422 curses_pkg_names="ncursesw6 ncursesw5 ncursesw $curses_pkg_names"
423fi
424
425AC_ARG_WITH([curses],
426 [AS_HELP_STRING([--with-curses=NAME],
427 [select curses package NAME to link with; e.g. ncursesw6])],
428 [],
429 [with_curses=check])
430case $with_curses in
Explorer0952c9e3d2024-10-26 21:00:57 +0800431check|yes)
Explorer095d1948b2024-09-19 06:27:31 +0800432 : # No-op. Use default list.
433 ;;
Explorer0952c9e3d2024-10-26 21:00:57 +0800434no)
Explorer095d1948b2024-09-19 06:27:31 +0800435 AC_MSG_ERROR([bad value '$with_curses' for --with-curses option])
436 ;;
437*)
438 if test "x${CURSES_CFLAGS+y}${CURSES_LIBS+y}" = xyy; then
439 AC_MSG_WARN([ignoring --with-curses value due to override])
440 fi
441 curses_pkg_names=`echo "x$with_curses" | sed 's/^x\(lib\)\{0,1\}//'`
442 ;;
443esac
444
445# $1: C preprocessor and compiler flags for curses library
446# $2: linker flags for curses library
447htop_check_curses_capability () {
448 htop_curses_cflags=${CURSES_CFLAGS-"$1"}
449 htop_curses_libs=${CURSES_LIBS-"$2"}
450
451 echo "curses cflags${CURSES_CFLAGS+ (override)}: $htop_curses_cflags" >&AS_MESSAGE_LOG_FD
452 echo "curses libs${CURSES_LIBS+ (override)}: $htop_curses_libs" >&AS_MESSAGE_LOG_FD
453
454 htop_msg_linker_flags=$htop_curses_libs
455 if test "`echo x $htop_msg_linker_flags`" = x; then
456 htop_msg_linker_flags="(no linker flags)"
457 fi
458
459 htop_curses_status=0 # 0 for success; nonzero for failure
460
461 htop_save_CFLAGS=$CFLAGS
462 htop_save_LIBS=$LIBS
463 CFLAGS="$AM_CFLAGS $htop_curses_cflags $CFLAGS"
464 LIBS="$htop_curses_libs $LIBS"
465
466 # At this point we have not checked the name of curses header, so
467 # use forward declaration for the linking tests below.
468
Explorer09b4582992024-10-29 07:59:08 +0800469 # htop uses keypad(), but for ncurses implementation, the symbol is
470 # in "-ltinfo" and not "-lncurses".
Explorer09d5f24d22024-08-21 19:56:21 +0800471 # Check "-ltinfo" symbols first, as libncurses might require
472 # explicit "-ltinfo" to link (for internal dependency).
473 AC_MSG_CHECKING([for keypad in $htop_msg_linker_flags])
474 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer09d5f24d22024-08-21 19:56:21 +0800475/* int keypad(WINDOW* win, bool enable); */
Explorer09d5f24d22024-08-21 19:56:21 +0800476int keypad(void* win, int enable);
477 ]], [[
Explorer09b4582992024-10-29 07:59:08 +0800478static char dummy;
479keypad((void*)&dummy, 0);
Explorer09d5f24d22024-08-21 19:56:21 +0800480 ]])],
481 [AC_MSG_RESULT(yes)],
482 [AC_MSG_RESULT(no)
483 htop_curses_status=1])
484
Explorer095d1948b2024-09-19 06:27:31 +0800485 # htop calls refresh(), which might be implemented as a macro.
486 # It is more reliable to test linking with doupdate(), which
487 # refresh() would call internally.
Explorer09d5f24d22024-08-21 19:56:21 +0800488 if test "$htop_curses_status" -eq 0; then
489 AC_MSG_CHECKING([for doupdate in $htop_msg_linker_flags])
490 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer095d1948b2024-09-19 06:27:31 +0800491int doupdate(void);
Explorer09d5f24d22024-08-21 19:56:21 +0800492 ]], [[
Explorer095d1948b2024-09-19 06:27:31 +0800493doupdate();
Explorer09d5f24d22024-08-21 19:56:21 +0800494 ]])],
495 [AC_MSG_RESULT(yes)
496 htop_curses_capability=nonwide],
497 [AC_MSG_RESULT(no)
498 htop_curses_status=1])
499 fi
Explorer095d1948b2024-09-19 06:27:31 +0800500
Explorer093b66b202024-10-29 07:59:14 +0800501 # htop calls mvadd_wchnstr(), which might be implemented as a macro.
502 # It is more reliable to test linking with wadd_wchnstr().
Explorer095d1948b2024-09-19 06:27:31 +0800503 if test "x$htop_curses_status$enable_unicode" = x0yes; then
Explorer093b66b202024-10-29 07:59:14 +0800504 AC_MSG_CHECKING([for wadd_wchnstr in $htop_msg_linker_flags])
Explorer095d1948b2024-09-19 06:27:31 +0800505 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Explorer093b66b202024-10-29 07:59:14 +0800506/* int wadd_wchnstr(WINDOW* win, const cchar_t* wchstr, int n); */
507int wadd_wchnstr(void* win, const void* wchstr, int n);
Explorer095d1948b2024-09-19 06:27:31 +0800508 ]], [[
Explorer093b66b202024-10-29 07:59:14 +0800509static char dummy1;
510static char dummy2;
511wadd_wchnstr((void*)&dummy1, (void*)&dummy2, 0);
Explorer095d1948b2024-09-19 06:27:31 +0800512 ]])],
513 [AC_MSG_RESULT(yes)
514 htop_curses_capability=wide],
515 [AC_MSG_RESULT(no)
516 htop_curses_status=1])
517 fi
518
519 if test "$htop_curses_status" -eq 0; then
520 AM_CFLAGS="$AM_CFLAGS $htop_curses_cflags"
521 if test "$htop_curses_capability" = wide; then
522 AC_DEFINE([HAVE_LIBNCURSESW], 1, [libncursesw is present])
523 else
524 AC_DEFINE([HAVE_LIBNCURSES], 1, [libcurses is present])
525 fi
526 else
527 LIBS=$htop_save_LIBS
528 fi
529 CFLAGS=$htop_save_CFLAGS
530 return "$htop_curses_status"
531} # htop_check_curses_capability
532
533htop_curses_capability=none
534
535if test "x${CURSES_CFLAGS+y}${CURSES_LIBS+y}" = xyy; then
536 curses_pkg_names=""
537 htop_check_curses_capability "$CURSES_CFLAGS" "$CURSES_LIBS"
538fi
539
540# Prioritize $PKG_CONFIG over ncurses*-config, as users might need to
541# cross-compile htop.
542if test "x$PKG_CONFIG" != x; then
543 pkg_config_static_flag=""
544 if test "$enable_static" = yes; then
545 pkg_config_static_flag=--static
546 fi
547
548 for curses_name in $curses_pkg_names; do
549 echo retrieving $curses_name information through $PKG_CONFIG >&AS_MESSAGE_LOG_FD
550 $PKG_CONFIG --exists --print-errors $curses_name >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD || continue
551
552 : # Resets "$?" to 0
553 htop_config_cflags=`$PKG_CONFIG --cflags $pkg_config_static_flag $curses_name 2>/dev/null` || continue
554 : # Resets "$?" to 0
555 htop_config_libs=`$PKG_CONFIG --libs $pkg_config_static_flag $curses_name 2>/dev/null` || continue
556
557 AC_MSG_RESULT([found $curses_name information through $PKG_CONFIG])
558
559 if htop_check_curses_capability "$htop_config_cflags" "$htop_config_libs"; then
560 break
561 fi
562 done
563fi
564
565case ${htop_curses_capability}-$enable_unicode in
566none-*|nonwide-yes)
567 for curses_name in $curses_pkg_names; do
568 echo retrieving $curses_name information through ${curses_name}-config >&AS_MESSAGE_LOG_FD
569
570 ${curses_name}-config --cflags >/dev/null 2>&AS_MESSAGE_LOG_FD || continue
571
572 : # Resets "$?" to 0
573 htop_config_cflags=`${curses_name}-config --cflags 2>/dev/null` || continue
574 : # Resets "$?" to 0
575 htop_config_libs=`${curses_name}-config --libs 2>/dev/null` || continue
576
577 AC_MSG_RESULT([found $curses_name information through ${curses_name}-config])
578
579 if htop_check_curses_capability "$htop_config_cflags" "$htop_config_libs"; then
580 break
581 fi
582 done
583 ;;
584esac
585
586case ${htop_curses_capability}-$enable_unicode in
587none-*|nonwide-yes)
Explorer09082b9772024-09-19 06:28:42 +0800588 if test "x$PKG_CONFIG" = x; then (
589 # Friendly warning to advise user to install pkg-config.
590 # The local variables get discarded when done.
591 list=""
592 echo "" >conftest.c
593 if test "$cross_compiling" != yes; then
594 # "-print-multi-directory" supported in GCC 3.0 or later
595 name=""
596 if $CC $CPPFLAGS $CFLAGS -print-multi-directory -E conftest.c >/dev/null 2>&1; then
597 name=`$CC $CPPFLAGS $CFLAGS -print-multi-directory -E conftest.c 2>/dev/null |
598 sed '/^ *#/ d; s/^\.$//; q'`
599 fi
600 list="/usr/lib${name}/pkgconfig $list"
601 case $host_os in
602 darwin*)
603 list="/opt/homebrew/Library/Homebrew/os/mac/pkgconfig $list"
604 ;;
605 freebsd*)
606 list="/usr/libdata/pkgconfig $list"
607 ;;
608 netbsd*)
609 list="/usr/pkg/lib/pkgconfig $list"
610 ;;
611 esac
612 fi
613 if test "x$host_alias" != x; then
614 list="/usr/lib/${host_alias}/pkgconfig $list"
615 fi
616 # "-print-multiarch" supported in GCC 4.6 or later
617 if $CC $CPPFLAGS $CFLAGS -print-multiarch -E conftest.c >/dev/null 2>&1; then
618 name=`$CC $CPPFLAGS $CFLAGS -print-multiarch -E conftest.c 2>/dev/null |
619 sed '/^ *#/ d; q'`
620 if test "x$name" != x; then
621 list="/usr/lib/${name}/pkgconfig $list"
622 fi
623 fi
624 rm -f conftest.*
625
626 for d in $list; do
627 result=`find "$d" -name '*curses*.pc' 2>/dev/null | sed '1 q'`
628 if test "x$result" != x; then
Explorer09d464ad12024-10-28 17:04:21 +0800629 echo detected a .pc file: "$result" >&AS_MESSAGE_LOG_FD
Explorer09082b9772024-09-19 06:28:42 +0800630 AC_MSG_WARN([your system supports pkg-config; installing pkg-config is recommended before configuring htop])
Explorer0976e7dd42024-10-29 07:57:54 +0800631 m4_ifdef([PKG_PROG_PKG_CONFIG], [], [
632 AC_MSG_WARN([this configure script would also need to be regenerated])
633 ])
Explorer09082b9772024-09-19 06:28:42 +0800634 break
635 fi
636 done
637 ) fi
638
Explorer095d1948b2024-09-19 06:27:31 +0800639 # OpenBSD and Solaris are known to not provide '*curses*.pc' files.
640 AC_MSG_RESULT([no curses information found through '*-config' utilities; will guess the linker flags])
641 for curses_name in $curses_pkg_names; do
642 if htop_check_curses_capability "" "-l$curses_name"; then
643 break
644 fi
Explorer09d5f24d22024-08-21 19:56:21 +0800645 # For ncurses implementation, an extra "-ltinfo" or "-ltinfow"
646 # flag might be needed to link.
647 if test "x$enable_unicode" = xyes &&
648 htop_check_curses_capability "" "-l$curses_name -ltinfow"; then
649 break
650 fi
651 if htop_check_curses_capability "" "-l$curses_name -ltinfo"; then
652 break
653 fi
Explorer095d1948b2024-09-19 06:27:31 +0800654 done
655 ;;
656esac
657
658case ${htop_curses_capability}-$enable_unicode in
659nonwide-yes)
660 AC_MSG_ERROR([cannot find required ncursesw library; you may want to use --disable-unicode])
661 ;;
662none-*)
663 AC_MSG_ERROR([cannot find required curses/ncurses library])
664 ;;
665esac
666
667htop_save_CFLAGS=$CFLAGS
668CFLAGS="$AM_CFLAGS $CFLAGS"
Explorer09a2d90f42024-10-29 07:59:23 +0800669
Explorer095d1948b2024-09-19 06:27:31 +0800670if test "x$enable_unicode" = xyes; then
Christian Göttsche759a3402021-01-22 19:14:55 +0100671 AC_CHECK_HEADERS([ncursesw/curses.h], [],
672 [AC_CHECK_HEADERS([ncurses/ncurses.h], [],
673 [AC_CHECK_HEADERS([ncurses/curses.h], [],
674 [AC_CHECK_HEADERS([ncurses.h], [],
675 [AC_MSG_ERROR([can not find required ncurses header file])])])])])
Christian Göttscheead978b2020-12-07 15:30:56 +0100676
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530677 AC_CHECK_HEADERS([ncursesw/term.h], [],
678 [AC_CHECK_HEADERS([ncurses/term.h], [],
679 [AC_CHECK_HEADERS([term.h], [],
680 [AC_MSG_ERROR([can not find required term header file])])])])
Hisham Muhammad8fa33dc2008-03-09 02:33:23 +0000681else
Christian Göttsche759a3402021-01-22 19:14:55 +0100682 AC_CHECK_HEADERS([curses.h], [],
683 [AC_CHECK_HEADERS([ncurses/curses.h], [],
684 [AC_CHECK_HEADERS([ncurses/ncurses.h], [],
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530685 [AC_CHECK_HEADERS([ncurses.h], [],
Christian Göttsche759a3402021-01-22 19:14:55 +0100686 [AC_MSG_ERROR([can not find required ncurses header file])])])])])
Christian Göttscheead978b2020-12-07 15:30:56 +0100687
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530688 AC_CHECK_HEADERS([ncurses/term.h], [],
689 [AC_CHECK_HEADERS([term.h], [],
690 [AC_MSG_ERROR([can not find required term header file])])])
Hisham Muhammad4c51ad02007-08-10 05:07:14 +0000691fi
Explorer09a2d90f42024-10-29 07:59:23 +0800692
693CFLAGS="-I$srcdir $CFLAGS"
694
695# Check for things that might be macros.
696# "stdscr" is a macro in ncursest (reentrant version of ncurses).
697AC_MSG_CHECKING([whether the curses header works])
698AC_LINK_IFELSE([AC_LANG_PROGRAM([[
699#include "ProvideCurses.h"
700 ]], [[
701keypad(stdscr, 0);
702
703refresh();
704
705#if defined(HAVE_LIBNCURSESW)
706{
707 static cchar_t dummy;
708 mvadd_wchnstr(0, 0, &dummy, 0);
709}
710#endif
711 ]])],
712 [AC_MSG_RESULT(yes)],
713 [AC_MSG_RESULT(no)
714 AC_MSG_FAILURE([there are problems with the curses header])]
715)
716
Explorer095d1948b2024-09-19 06:27:31 +0800717CFLAGS=$htop_save_CFLAGS
Sahil Siddiq3fc28622023-02-07 22:56:57 +0530718
Christian Göttsche575edff2021-01-22 19:14:59 +0100719if test "$enable_static" = yes; then
720 AC_SEARCH_LIBS([Gpm_GetEvent], [gpm])
721fi
Christian Göttscheee9e7ed2021-05-20 18:27:10 +0200722if test "$my_htop_platform" = "solaris"; then
723 # On OmniOS /usr/include/sys/regset.h redefines ERR to 13 - \r, breaking the Enter key.
Nathan Scottca06e682021-09-08 12:11:51 +1000724 # Since ncurses macros use the ERR macro, we can not use another name.
Christian Göttscheee9e7ed2021-05-20 18:27:10 +0200725 AC_DEFINE([ERR], [(-1)], [Predefine ncurses macro.])
726fi
Benny Baumann18e3fd52021-07-04 16:50:41 +0200727AC_CHECK_FUNCS( [set_escdelay] )
nia2ab8fb82021-07-14 20:17:13 +0200728AC_CHECK_FUNCS( [getmouse] )
Benny Baumann04d0a542024-12-09 22:18:08 +0100729AC_DEFINE([NCURSES_ENABLE_STDBOOL_H], [1], [Define to enable stdbool.h in ncurses])
Hisham Muhammad4c51ad02007-08-10 05:07:14 +0000730
gmbroome697f5bb2018-03-02 16:20:46 -0500731
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200732AC_ARG_ENABLE([affinity],
733 [AS_HELP_STRING([--enable-affinity],
734 [enable sched_setaffinity and sched_getaffinity for affinity support, conflicts with hwloc @<:@default=check@:>@])],
735 [],
736 [enable_affinity=check])
737if test "x$enable_affinity" = xcheck; then
738 if test "x$enable_hwloc" = xyes; then
739 enable_affinity=no
740 else
741 AC_MSG_CHECKING([for usable sched_setaffinity])
742 AC_RUN_IFELSE([
743 AC_LANG_PROGRAM([[
744 #include <sched.h>
745 #include <errno.h>
746 static cpu_set_t cpuset;
747 ]], [[
748 CPU_ZERO(&cpuset);
749 sched_setaffinity(0, sizeof(cpu_set_t), &cpuset);
750 if (errno == ENOSYS) return 1;
751 ]])],
752 [enable_affinity=yes
753 AC_MSG_RESULT([yes])],
754 [enable_affinity=no
755 AC_MSG_RESULT([no])],
Explorer0947ae9662023-07-29 03:11:54 +0800756 [AC_MSG_RESULT([assume yes (cross compiling)])])
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200757 fi
758fi
759if test "x$enable_affinity" = xyes; then
760 if test "x$enable_hwloc" = xyes; then
761 AC_MSG_ERROR([--enable-hwloc and --enable-affinity are mutual exclusive. Specify at most one of them.])
762 fi
763 AC_DEFINE([HAVE_AFFINITY], [1], [Define if sched_setaffinity and sched_getaffinity are to be used.])
764fi
765
766
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200767AC_ARG_ENABLE([unwind],
768 [AS_HELP_STRING([--enable-unwind],
769 [enable unwind support for printing backtraces; requires libunwind @<:@default=check@:>@])],
770 [],
771 [enable_unwind=check])
772case "$enable_unwind" in
773 check)
774 enable_unwind=yes
775 if test "$enable_static" = yes; then
776 AC_CHECK_LIB([lzma], [lzma_index_buffer_decode])
777 fi
778 AC_CHECK_LIB([unwind], [backtrace], [], [enable_unwind=no])
Christian Göttsche63880332021-12-14 17:36:57 +0100779 AC_CHECK_HEADERS([libunwind.h], [], [
780 old_CFLAGS="$CFLAGS"
781 CFLAGS="$CFLAGS -I/usr/include/libunwind"
782 AC_CHECK_HEADERS([libunwind/libunwind.h], [], [
783 enable_unwind=no
784 CFLAGS="$old_CFLAGS"
785 ])
786 ])
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200787 ;;
788 no)
789 ;;
790 yes)
791 AC_CHECK_LIB([unwind], [backtrace], [], [AC_MSG_ERROR([can not find required library libunwind])])
Christian Göttsche63880332021-12-14 17:36:57 +0100792 AC_CHECK_HEADERS([libunwind.h], [], [
Benny Baumann5c7cb912023-11-28 17:42:04 +0100793 AM_CFLAGS="$AM_CFLAGS -I/usr/include/libunwind"
Christian Göttsche63880332021-12-14 17:36:57 +0100794 AC_CHECK_HEADERS([libunwind/libunwind.h], [], [AC_MSG_ERROR([can not find required header file libunwind.h])])
795 ])
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200796 ;;
797 *)
798 AC_MSG_ERROR([bad value '$enable_unwind' for --enable-unwind])
799 ;;
800esac
801if test "x$enable_unwind" = xno; then
802 # Fall back to backtrace(3) and add -lexecinfo if needed
803 AC_SEARCH_LIBS([backtrace], [execinfo])
804fi
805
806
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100807AC_ARG_ENABLE([hwloc],
808 [AS_HELP_STRING([--enable-hwloc],
Christian Göttsche1fb0c722021-06-13 11:29:39 +0200809 [enable hwloc support for CPU affinity; disables affinity support; requires libhwloc @<:@default=no@:>@])],
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100810 [],
811 [enable_hwloc=no])
812case "$enable_hwloc" in
813 no)
814 ;;
815 yes)
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200816 m4_ifdef([PKG_PROG_PKG_CONFIG], [
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200817 PKG_CHECK_MODULES(HWLOC, hwloc, [
Benny Baumann5c7cb912023-11-28 17:42:04 +0100818 AM_CFLAGS="$AM_CFLAGS $HWLOC_CFLAGS"
Christian Göttschec8a61852023-04-05 01:21:14 +0200819 LIBS="$LIBS $HWLOC_LIBS"
Explorer0947ae9662023-07-29 03:11:54 +0800820 AC_DEFINE([HAVE_LIBHWLOC], [1], [Define to 1 if you have the 'hwloc' library (-lhwloc).])
Fabrice Fontaine4ccad462022-04-02 17:27:01 +0200821 ], [
822 AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [AC_MSG_ERROR([can not find required library libhwloc])])
823 AC_CHECK_HEADERS([hwloc.h], [], [AC_MSG_ERROR([can not find require header file hwloc.h])])
824 ])
825 ], [
826 AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [AC_MSG_ERROR([can not find required library libhwloc])])
827 AC_CHECK_HEADERS([hwloc.h], [], [AC_MSG_ERROR([can not find require header file hwloc.h])])
828 ])
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100829 ;;
830 *)
831 AC_MSG_ERROR([bad value '$enable_hwloc' for --enable-hwloc])
832 ;;
833esac
Christian Göttsche005c4d12020-09-08 16:25:22 +0200834
Christian Göttsche29e1fcf2021-05-16 20:45:09 +0200835
Nathan Scott5b50ae32021-03-02 15:58:11 +1100836AC_ARG_WITH([os-release],
837 [AS_HELP_STRING([--with-os-release=FILE],
Christian Göttsche8ba4ef32021-03-12 16:37:17 +0100838 [location of an os-release file @<:@default=/etc/os-release@:>@])],
Nathan Scott5b50ae32021-03-02 15:58:11 +1100839 [],
840 [with_os_release=/etc/os-release])
Christian Göttsche8ba4ef32021-03-12 16:37:17 +0100841if test -n "$with_os_release" && test ! -f "$with_os_release"; then
Nathan Scott5b50ae32021-03-02 15:58:11 +1100842 if test -f "/usr/lib/os-release"; then
843 with_os_release="/usr/lib/os-release"
844 fi
845fi
846AC_DEFINE_UNQUOTED([OSRELEASEFILE], ["$with_os_release"], [File with OS release details.])
847
Nathan Scott1a7b6d42024-07-22 08:51:29 +1000848AC_ARG_WITH([config],
849 [AS_HELP_STRING([--with-config=DIR],
Explorer09c802dc42024-09-19 06:37:00 +0800850 [configuration path @<:@default=/.config@:>@])],
Nathan Scott1a7b6d42024-07-22 08:51:29 +1000851 [],
852 [with_config="/.config"])
853dnl Performance Co-Pilot configuration location to prevent overwrite
854if test "$my_htop_platform" = pcp -a "$with_config" = /.config; then
855 with_config="/.pcp"
856elif test -z "$with_config"; then
857 AC_MSG_ERROR([bad empty value for --with-config option])
858fi
859AC_DEFINE_UNQUOTED([CONFIGDIR], ["$with_config"], [Configuration path.])
860
Christian Göttschef3623b72021-01-22 19:14:50 +0100861# ----------------------------------------------------------------------
862
863
864# ----------------------------------------------------------------------
865# Checks for Linux features and flags.
866# ----------------------------------------------------------------------
867
868AC_ARG_WITH([proc],
869 [AS_HELP_STRING([--with-proc=DIR],
870 [location of a Linux-compatible proc filesystem @<:@default=/proc@:>@])],
871 [],
872 [with_proc=/proc])
873if test -z "$with_proc"; then
874 AC_MSG_ERROR([bad empty value for --with-proc option])
875fi
876AC_DEFINE_UNQUOTED([PROCDIR], ["$with_proc"], [Path of proc filesystem.])
877
878
879AC_ARG_ENABLE([openvz],
880 [AS_HELP_STRING([--enable-openvz],
881 [enable OpenVZ support @<:@default=no@:>@])],
882 [],
883 [enable_openvz=no])
884if test "x$enable_openvz" = xyes; then
885 AC_DEFINE([HAVE_OPENVZ], [1], [Define if openvz support enabled.])
886fi
887
888
889AC_ARG_ENABLE([vserver],
890 [AS_HELP_STRING([--enable-vserver],
891 [enable VServer support @<:@default=no@:>@])],
892 [],
893 [enable_vserver=no])
894if test "x$enable_vserver" = xyes; then
Christian Göttsche284f8c52021-09-02 22:32:46 +0200895 AC_DEFINE([HAVE_VSERVER], [1], [Define if VServer support enabled.])
Christian Göttschef3623b72021-01-22 19:14:50 +0100896fi
897
898
899AC_ARG_ENABLE([ancient_vserver],
900 [AS_HELP_STRING([--enable-ancient-vserver],
901 [enable ancient VServer support (implies --enable-vserver) @<:@default=no@:>@])],
902 [],
903 [enable_ancient_vserver=no])
904if test "x$enable_ancient_vserver" = xyes; then
Christian Göttsche284f8c52021-09-02 22:32:46 +0200905 if test "x$enable_vserver" != xyes; then
906 enable_vserver=implied
907 fi
908 AC_DEFINE([HAVE_VSERVER], [1], [Define if VServer support enabled.])
909 AC_DEFINE([HAVE_ANCIENT_VSERVER], [1], [Define if ancient vserver support enabled.])
Christian Göttschef3623b72021-01-22 19:14:50 +0100910fi
911
912
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100913AC_ARG_ENABLE([capabilities],
914 [AS_HELP_STRING([--enable-capabilities],
915 [enable Linux capabilities support; requires libcap @<:@default=check@:>@])],
916 [],
917 [enable_capabilities=check])
918case "$enable_capabilities" in
919 no)
920 ;;
921 check)
922 enable_capabilities=yes
923 AC_CHECK_LIB([cap], [cap_init], [], [enable_capabilities=no])
924 AC_CHECK_HEADERS([sys/capability.h], [], [enable_capabilities=no])
925 ;;
926 yes)
Christian Göttsche759a3402021-01-22 19:14:55 +0100927 AC_CHECK_LIB([cap], [cap_init], [], [AC_MSG_ERROR([can not find required library libcap])])
928 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 +0100929 ;;
930 *)
931 AC_MSG_ERROR([bad value '$enable_capabilities' for --enable-capabilities])
932 ;;
933esac
Christian Göttschef4404ef2020-09-02 14:39:25 +0200934
Christian Göttschef3623b72021-01-22 19:14:50 +0100935
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100936AC_ARG_ENABLE([delayacct],
937 [AS_HELP_STRING([--enable-delayacct],
938 [enable Linux delay accounting support; requires pkg-config, libnl-3 and libnl-genl-3 @<:@default=check@:>@])],
939 [],
940 [enable_delayacct=check])
941case "$enable_delayacct" in
942 no)
943 ;;
944 check)
Christian Göttsche69cfaf22021-05-16 20:01:25 +0200945 if test "$my_htop_platform" != linux; then
946 enable_delayacct=no
947 elif test "$enable_static" = yes; then
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100948 enable_delayacct=no
Christian Göttsche575edff2021-01-22 19:14:59 +0100949 else
Christian Göttsche24b15132024-03-30 13:47:14 +0100950 old_CFLAGS="$CFLAGS"
951 CFLAGS="$CFLAGS -I/usr/include/libnl3"
952 AC_CHECK_HEADERS([netlink/attr.h netlink/handlers.h netlink/msg.h], [enable_delayacct=yes], [enable_delayacct=no])
953 CFLAGS="$old_CFLAGS"
Christian Göttsche575edff2021-01-22 19:14:59 +0100954 fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100955 ;;
956 yes)
Christian Göttsche24b15132024-03-30 13:47:14 +0100957 old_CFLAGS="$CFLAGS"
958 CFLAGS="$CFLAGS -I/usr/include/libnl3"
959 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])])
960 CFLAGS="$old_CFLAGS"
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100961 ;;
962 *)
963 AC_MSG_ERROR([bad value '$enable_delayacct' for --enable-delayacct])
964 ;;
965esac
Christian Göttsche24b15132024-03-30 13:47:14 +0100966if test "$enable_delayacct" = yes; then
967 AC_DEFINE([HAVE_DELAYACCT], [1], [Define if delay accounting support should be enabled.])
968 AM_CFLAGS="$AM_CFLAGS -I/usr/include/libnl3"
969fi
Christian Göttschea782ef32024-03-30 13:47:10 +0100970AM_CONDITIONAL([HAVE_DELAYACCT], [test "$enable_delayacct" = yes])
André Carvalhob7b66b72017-12-04 00:15:29 -0200971
Christian Göttschef3623b72021-01-22 19:14:50 +0100972
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100973AC_ARG_ENABLE([sensors],
974 [AS_HELP_STRING([--enable-sensors],
975 [enable libsensors support for reading temperature data; requires only libsensors headers at compile time, at runtime libsensors is loaded via dlopen @<:@default=check@:>@])],
976 [],
977 [enable_sensors=check])
978case "$enable_sensors" in
979 no)
980 ;;
981 check)
982 enable_sensors=yes
Christian Göttsche575edff2021-01-22 19:14:59 +0100983 if test "$enable_static" = yes; then
984 AC_CHECK_LIB([sensors], [sensors_init], [], [enable_sensors=no])
985 fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +0100986 AC_CHECK_HEADERS([sensors/sensors.h], [], [enable_sensors=no])
987 ;;
988 yes)
Christian Göttsche575edff2021-01-22 19:14:59 +0100989 if test "$enable_static" = yes; then
990 AC_CHECK_LIB([sensors], [sensors_init], [], [AC_MSG_ERROR([can not find required library libsensors])])
991 fi
992 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 +0100993 ;;
994 *)
995 AC_MSG_ERROR([bad value '$enable_sensors' for --enable-sensors])
996 ;;
997esac
Christian Göttschefd2a0cf2020-12-22 20:02:01 +0100998if test "$enable_sensors" = yes || test "$my_htop_platform" = freebsd; then
999 AC_DEFINE([BUILD_WITH_CPU_TEMP], [1], [Define if CPU temperature option should be enabled.])
1000fi
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001001
Christian Göttschef3623b72021-01-22 19:14:50 +01001002# ----------------------------------------------------------------------
1003
1004
1005# ----------------------------------------------------------------------
1006# Checks for compiler warnings.
1007# ----------------------------------------------------------------------
Christian Göttsche1b225cd2020-09-10 19:56:33 +02001008
Benny Baumann5c7cb912023-11-28 17:42:04 +01001009AM_CFLAGS="$AM_CFLAGS\
Christian Göttschef4602f72020-09-08 14:25:46 +02001010 -Wall\
1011 -Wcast-align\
Christian Göttschedb472072020-10-04 14:30:35 +02001012 -Wcast-qual\
Christian Göttschef4602f72020-09-08 14:25:46 +02001013 -Wextra\
Benny Baumannba0fca12020-09-18 16:58:03 +02001014 -Wfloat-equal\
Christian Göttschec150e4b2020-12-18 15:49:37 +01001015 -Wformat=2\
Christian Göttsche4dadbe32021-01-21 19:49:07 +01001016 -Winit-self\
Christian Göttschef4602f72020-09-08 14:25:46 +02001017 -Wmissing-format-attribute\
1018 -Wmissing-noreturn\
Christian Göttsche4e282eb2020-09-25 14:03:55 +02001019 -Wmissing-prototypes\
Christian Göttschef4602f72020-09-08 14:25:46 +02001020 -Wpointer-arith\
1021 -Wshadow\
1022 -Wstrict-prototypes\
1023 -Wundef\
1024 -Wunused\
1025 -Wwrite-strings"
1026
Christian Göttschef3623b72021-01-22 19:14:50 +01001027dnl https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
1028AC_DEFUN([AX_CHECK_COMPILE_FLAG],
Christian Göttsche38b6a012021-01-22 19:14:53 +01001029[
Christian Göttschef3623b72021-01-22 19:14:50 +01001030AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
1031AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
1032 ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
1033 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
1034 AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
1035 [AS_VAR_SET(CACHEVAR,[yes])],
1036 [AS_VAR_SET(CACHEVAR,[no])])
1037 _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
1038AS_VAR_IF(CACHEVAR,yes,
1039 [m4_default([$2], :)],
1040 [m4_default([$3], :)])
1041AS_VAR_POPDEF([CACHEVAR])dnl
1042])dnl AX_CHECK_COMPILE_FLAGS
1043
Christian Göttsche970885e2021-08-14 11:21:54 +02001044AX_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 +02001045AX_CHECK_COMPILE_FLAG([-Wimplicit-int-conversion], [AM_CFLAGS="$AM_CFLAGS -Wimplicit-int-conversion"], , [-Werror])
1046AX_CHECK_COMPILE_FLAG([-Wnull-dereference], [AM_CFLAGS="$AM_CFLAGS -Wnull-dereference"], , [-Werror])
Benny Baumann2cde4a72020-09-18 19:32:41 +02001047
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001048AC_ARG_ENABLE([werror],
1049 [AS_HELP_STRING([--enable-werror],
1050 [Treat warnings as errors @<:@default=no@:>@])],
1051 [],
1052 [enable_werror=no])
1053if test "x$enable_werror" = xyes; then
1054 AM_CFLAGS="$AM_CFLAGS -Werror"
1055fi
1056
1057AC_ARG_ENABLE([debug],
1058 [AS_HELP_STRING([--enable-debug],
Daniel Lange135efd52021-02-16 11:22:02 +01001059 [Enable compiling with maximum debug info, asserts and internal sanity checks @<:@default=no@:>@])],
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001060 [],
1061 [enable_debug=no])
1062if test "x$enable_debug" != xyes; then
1063 AM_CPPFLAGS="$AM_CPPFLAGS -DNDEBUG"
Explorer0993d76fd2023-07-31 05:05:43 +08001064
1065 AC_COMPILE_IFELSE([
1066 AC_LANG_SOURCE([[
1067#ifdef __SUPPORT_SNAN__
1068#error "signaling NaN support not recommended"
1069#endif
1070 ]])],
1071 :,
1072 [warning_msg="signaling NaN support is enabled; not recommended for htop"
1073 case "$CC" in
1074 *gcc*)
1075 warning_msg="$warning_msg (use '-fno-signaling-nans' compiler flag to disable)"
1076 ;;
1077 esac
1078 AC_MSG_WARN([$warning_msg])
1079 ])
Daniel Lange135efd52021-02-16 11:22:02 +01001080else
1081 AM_CPPFLAGS="$AM_CPPFLAGS -ggdb3"
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001082fi
Christian Göttscheb7f63292020-09-17 22:23:05 +02001083
Christian Göttschef3623b72021-01-22 19:14:50 +01001084
Christian Göttsche57254cd2020-08-21 10:37:20 +02001085AC_SUBST([AM_CFLAGS])
Christian Göttscheb7f63292020-09-17 22:23:05 +02001086AC_SUBST([AM_CPPFLAGS])
1087
Christian Göttschef3623b72021-01-22 19:14:50 +01001088# ----------------------------------------------------------------------
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001089
Christian Göttschef3623b72021-01-22 19:14:50 +01001090
1091# ----------------------------------------------------------------------
Hisham Muhammad300af4b2014-11-19 23:17:16 -02001092# We're done, let's go!
1093# ----------------------------------------------------------------------
Christian Göttschef3623b72021-01-22 19:14:50 +01001094
Daniel Langec3b4a772024-01-01 02:12:06 +01001095AC_DEFINE_UNQUOTED([COPYRIGHT], ["(C) 2004-2019 Hisham Muhammad. (C) 2020-2024 htop dev team."], [Copyright message.])
Christian Göttschef3623b72021-01-22 19:14:50 +01001096
Hisham Muhammada75161f2014-11-24 20:11:33 -02001097AM_CONDITIONAL([HTOP_LINUX], [test "$my_htop_platform" = linux])
Hisham Muhammad8915b292014-11-27 16:27:34 -02001098AM_CONDITIONAL([HTOP_FREEBSD], [test "$my_htop_platform" = freebsd])
Diederik de Grootb258d6e2017-04-19 16:12:17 +02001099AM_CONDITIONAL([HTOP_DRAGONFLYBSD], [test "$my_htop_platform" = dragonflybsd])
fraggerfox4b49de42021-03-15 13:14:39 +05301100AM_CONDITIONAL([HTOP_NETBSD], [test "$my_htop_platform" = netbsd])
Michael McConvillea9a5a532015-09-18 00:46:48 -04001101AM_CONDITIONAL([HTOP_OPENBSD], [test "$my_htop_platform" = openbsd])
David Hunt70e7c8d2015-07-12 13:47:43 -05001102AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin])
gmbroome697f5bb2018-03-02 16:20:46 -05001103AM_CONDITIONAL([HTOP_SOLARIS], [test "$my_htop_platform" = solaris])
Nathan Scottc14a45b2021-02-17 14:43:56 +11001104AM_CONDITIONAL([HTOP_PCP], [test "$my_htop_platform" = pcp])
Hisham Muhammada75161f2014-11-24 20:11:33 -02001105AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported])
Christian Göttsche38b6a012021-01-22 19:14:53 +01001106
Hisham Muhammadeb229d92014-11-24 18:55:03 -02001107AC_SUBST(my_htop_platform)
Daniel Langefc2377f2021-08-14 10:35:11 +02001108AC_CONFIG_FILES([Makefile htop.1])
Hisham Muhammadd6231ba2006-03-04 18:16:49 +00001109AC_OUTPUT
Hisham Muhammadc39f18a2017-07-10 20:14:25 -03001110
Christian Göttschef3623b72021-01-22 19:14:50 +01001111if test "$my_htop_platform" = unsupported; then
Hisham Muhammadc39f18a2017-07-10 20:14:25 -03001112 echo ""
1113 echo "****************************************************************"
1114 echo "WARNING! This platform is not currently supported by htop."
1115 echo ""
1116 echo "The code will build, but it will produce a dummy version of htop"
1117 echo "which shows no processes, using the files from the unsupported/"
1118 echo "directory. This is meant to be a skeleton, to be used as a"
1119 echo "starting point if you are porting htop to a new platform."
1120 echo "****************************************************************"
1121 echo ""
1122fi
Christian Göttsche3b084db2020-08-28 12:10:31 +02001123
1124AC_MSG_RESULT([
1125 ${PACKAGE_NAME} ${VERSION}
1126
Christian Göttscheffd90c22020-10-05 12:29:31 +02001127 platform: $my_htop_platform
Nathan Scott5b50ae32021-03-02 15:58:11 +11001128 os-release file: $with_os_release
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001129 (Linux) proc directory: $with_proc
Christian Göttscheffd90c22020-10-05 12:29:31 +02001130 (Linux) openvz: $enable_openvz
Christian Göttscheffd90c22020-10-05 12:29:31 +02001131 (Linux) vserver: $enable_vserver
1132 (Linux) ancient vserver: $enable_ancient_vserver
Christian Göttscheffd90c22020-10-05 12:29:31 +02001133 (Linux) delay accounting: $enable_delayacct
Christian Göttsche5e103ff2021-01-22 19:14:46 +01001134 (Linux) sensors: $enable_sensors
1135 (Linux) capabilities: $enable_capabilities
Christian Göttscheffd90c22020-10-05 12:29:31 +02001136 unicode: $enable_unicode
Christian Göttsche1fb0c722021-06-13 11:29:39 +02001137 affinity: $enable_affinity
Christian Göttsche29e1fcf2021-05-16 20:45:09 +02001138 unwind: $enable_unwind
Daniel Lange309f1d72020-11-16 13:29:37 +01001139 hwloc: $enable_hwloc
Daniel Langea8a723f2020-11-16 17:01:51 +01001140 debug: $enable_debug
Christian Göttsche575edff2021-01-22 19:14:59 +01001141 static: $enable_static
Christian Göttsche3b084db2020-08-28 12:10:31 +02001142])