3 AC_INIT([tmux], next-3.4)
7 AC_CONFIG_LIBOBJ_DIR(compat)
8 AM_INIT_AUTOMAKE([foreign subdir-objects])
12 # When CFLAGS isn't set at this stage and gcc is detected by the macro below,
13 # autoconf will automatically use CFLAGS="-O2 -g". Prevent that by using an
17 # Save user CPPFLAGS, CFLAGS and LDFLAGS. We need to change them because
18 # AC_CHECK_HEADER doesn't give us any other way to update the include
19 # paths. But for Makefile.am we want to use AM_CPPFLAGS and friends.
20 SAVED_CFLAGS="$CFLAGS"
21 SAVED_CPPFLAGS="$CPPFLAGS"
22 SAVED_LDFLAGS="$LDFLAGS"
24 # Is this oss-fuzz build?
27 AS_HELP_STRING(--enable-fuzzing, build fuzzers)
31 AS_HELP_STRING(libraries to link fuzzing targets with)
34 # Set up convenient fuzzing defaults before initializing compiler.
35 if test "x$enable_fuzzing" = xyes; then
36 AC_DEFINE(NEED_FUZZING)
37 test "x$CC" = x && CC=clang
38 test "x$FUZZING_LIBS" = x && \
39 FUZZING_LIBS="-fsanitize=fuzzer"
40 test "x$SAVED_CFLAGS" = x && \
41 AM_CFLAGS="-g -fsanitize=fuzzer-no-link,address"
44 # Set up the compiler in two different ways and say yes we may want to install.
53 AC_USE_SYSTEM_EXTENSIONS
55 # Default tmux.conf goes in /etc not ${prefix}/etc.
56 test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
58 # Is this --enable-debug?
59 case "x$VERSION" in xnext*) enable_debug=yes;; esac
62 AS_HELP_STRING(--enable-debug, enable debug build flags),
64 AM_CONDITIONAL(IS_DEBUG, test "x$enable_debug" = xyes)
66 # Is this a static build?
69 AS_HELP_STRING(--enable-static, create a static build)
71 if test "x$enable_static" = xyes; then
74 AC_MSG_ERROR([static linking is not supported on macOS])
77 test "x$PKG_CONFIG" != x && PKG_CONFIG="$PKG_CONFIG --static"
78 AM_LDFLAGS="-static $AM_LDFLAGS"
79 LDFLAGS="$AM_LDFLAGS $SAVED_LDFLAGS"
82 # Allow default TERM to be set.
85 AS_HELP_STRING(--with-TERM, set default TERM),
86 [DEFAULT_TERM=$withval],
89 case "x$DEFAULT_TERM" in
93 AC_MSG_ERROR("unsuitable TERM (must be screen* or tmux*)")
98 AM_CONDITIONAL(NEED_FUZZING, test "x$enable_fuzzing" = xyes)
101 AM_CONDITIONAL(IS_GCC, test "x$GCC" = xyes -a "x$enable_fuzzing" != xyes)
114 AM_CONDITIONAL(IS_SUNCC, test "x$found_suncc" = xyes)
116 # Check for various headers. Alternatives included from compat.h.
135 # Look for sys_signame.
136 AC_SEARCH_LIBS(sys_signame, , AC_DEFINE(HAVE_SYS_SIGNAME))
139 AC_CHECK_LIB(m, fmod)
141 # Look for library needed for flock.
142 AC_SEARCH_LIBS(flock, bsd)
144 # Check for functions that are replaced or omitted.
154 # Check for functions with a compatibility implementation.
179 # Check if strtonum works.
180 AC_MSG_CHECKING([for working strtonum])
181 AC_RUN_IFELSE([AC_LANG_PROGRAM(
182 [#include <stdlib.h>],
183 [return (strtonum("0", 0, 1, NULL) == 0 ? 0 : 1);]
185 [AC_DEFINE(HAVE_STRTONUM) AC_MSG_RESULT(yes)],
186 [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)],
187 [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)]
190 # Clang sanitizers wrap reallocarray even if it isn't available on the target
191 # system. When compiled it always returns NULL and crashes the program. To
192 # detect this we need a more complicated test.
193 AC_MSG_CHECKING([for working reallocarray])
194 AC_RUN_IFELSE([AC_LANG_PROGRAM(
195 [#include <stdlib.h>],
196 [return (reallocarray(NULL, 1, 1) == NULL);]
199 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
200 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
202 AC_MSG_CHECKING([for working recallocarray])
203 AC_RUN_IFELSE([AC_LANG_PROGRAM(
204 [#include <stdlib.h>],
205 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
208 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
209 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
212 # Look for clock_gettime. Must come before event_init.
213 AC_SEARCH_LIBS(clock_gettime, rt)
215 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
216 # musl does not set optarg to NULL for flags without arguments (although it is
217 # not required to, but it is helpful) 3) there are probably other weird
221 # Look for libevent. Try libevent_core or libevent with pkg-config first then
222 # look for the library.
225 [libevent_core >= 2],
227 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
228 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
229 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
234 if test x$found_libevent = xno; then
239 AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
240 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
241 LIBS="$LIBEVENT_LIBS $LIBS"
247 if test x$found_libevent = xno; then
250 [event_core event event-1.4],
257 AC_DEFINE(HAVE_EVENT2_EVENT_H),
261 AC_DEFINE(HAVE_EVENT_H),
266 if test "x$found_libevent" = xno; then
267 AC_MSG_ERROR("libevent not found")
271 AC_CHECK_PROG(found_yacc, $YACC, yes, no)
272 if test "x$found_yacc" = xno; then
273 AC_MSG_ERROR("yacc not found")
276 # Look for ncurses or curses. Try pkg-config first then directly for the
282 AM_CPPFLAGS="$LIBTINFO_CFLAGS $AM_CPPFLAGS"
283 CPPFLAGS="$LIBTINFO_CFLAGS $SAVED_CPPFLAGS"
284 LIBS="$LIBTINFO_LIBS $LIBS"
289 if test "x$found_ncurses" = xno; then
294 AM_CPPFLAGS="$LIBNCURSES_CFLAGS $AM_CPPFLAGS"
295 CPPFLAGS="$LIBNCURSES_CFLAGS $SAVED_CPPFLAGS"
296 LIBS="$LIBNCURSES_LIBS $LIBS"
302 if test "x$found_ncurses" = xno; then
307 AM_CPPFLAGS="$LIBNCURSESW_CFLAGS $AM_CPPFLAGS"
308 CPPFLAGS="$LIBNCURSESW_CFLAGS $SAVED_CPPFLAGS"
309 LIBS="$LIBNCURSESW_LIBS $LIBS"
315 if test "x$found_ncurses" = xno; then
318 [tinfo terminfo ncurses ncursesw],
322 if test "x$found_ncurses" = xyes; then
325 LIBS="$LIBS -lncurses",
330 if test "x$found_ncurses" = xyes; then
331 CPPFLAGS="$CPPFLAGS -DHAVE_NCURSES_H"
332 AC_DEFINE(HAVE_NCURSES_H)
345 if test "x$found_curses" = xyes; then
346 LIBS="$LIBS -lcurses"
347 CPPFLAGS="$CPPFLAGS -DHAVE_CURSES_H"
348 AC_DEFINE(HAVE_CURSES_H)
350 AC_MSG_ERROR("curses not found")
361 AS_HELP_STRING(--enable-utempter, use utempter if it is installed)
363 if test "x$enable_utempter" = xyes; then
364 AC_CHECK_HEADER(utempter.h, enable_utempter=yes, enable_utempter=no)
365 if test "x$enable_utempter" = xyes; then
373 if test "x$enable_utempter" = xyes; then
374 AC_DEFINE(HAVE_UTEMPTER)
376 AC_MSG_ERROR("utempter not found")
383 AS_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
385 if test "x$enable_utf8proc" = xyes; then
390 AM_CPPFLAGS="$LIBUTF8PROC_CFLAGS $AM_CPPFLAGS"
391 CPPFLAGS="$LIBUTF8PROC_CFLAGS $SAVED_CPPFLAGS"
392 LIBS="$LIBUTF8PROC_LIBS $LIBS"
395 AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no)
396 if test "x$enable_utf8proc" = xyes; then
404 if test "x$enable_utf8proc" = xyes; then
405 AC_DEFINE(HAVE_UTF8PROC)
407 AC_MSG_ERROR("utf8proc not found")
410 AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes])
412 # Check for systemd support.
415 AS_HELP_STRING(--enable-systemd, enable systemd integration)
417 if test x"$enable_systemd" = xyes; then
422 AM_CPPFLAGS="$SYSTEMD_CFLAGS $AM_CPPFLAGS"
423 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
424 LIBS="$SYSTEMD_LIBS $LIBS"
429 if test "x$found_systemd" = xyes; then
430 AC_DEFINE(HAVE_SYSTEMD)
432 AC_MSG_ERROR("systemd not found")
435 AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$found_systemd" = xyes])
438 AS_HELP_STRING(--disable-cgroups, disable adding panes to new cgroups with systemd)
440 if test "x$enable_cgroups" = x; then
441 # Default to the same as $enable_systemd.
442 enable_cgroups=$enable_systemd
444 if test "x$enable_cgroups" = xyes; then
445 if test "x$found_systemd" = xyes; then
446 AC_DEFINE(ENABLE_CGROUPS)
448 AC_MSG_ERROR("cgroups requires systemd to be enabled")
452 # Enable sixel support.
455 AS_HELP_STRING(--enable-sixel, enable sixel images)
457 if test "x$enable_sixel" = xyes; then
458 AC_DEFINE(ENABLE_SIXEL)
460 AM_CONDITIONAL(ENABLE_SIXEL, [test "x$enable_sixel" = xyes])
462 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
463 AC_MSG_CHECKING(for b64_ntop)
464 AC_LINK_IFELSE([AC_LANG_PROGRAM(
466 #include <sys/types.h>
467 #include <netinet/in.h>
471 b64_ntop(NULL, 0, NULL, 0);
476 AC_MSG_RESULT($found_b64_ntop)
478 if test "x$found_b64_ntop" = xno; then
479 AC_MSG_CHECKING(for b64_ntop with -lresolv)
480 LIBS="$OLD_LIBS -lresolv"
481 AC_LINK_IFELSE([AC_LANG_PROGRAM(
483 #include <sys/types.h>
484 #include <netinet/in.h>
488 b64_ntop(NULL, 0, NULL, 0);
493 AC_MSG_RESULT($found_b64_ntop)
495 if test "x$found_b64_ntop" = xno; then
496 AC_MSG_CHECKING(for b64_ntop with -lnetwork)
497 LIBS="$OLD_LIBS -lnetwork"
498 AC_LINK_IFELSE([AC_LANG_PROGRAM(
500 #include <sys/types.h>
501 #include <netinet/in.h>
505 b64_ntop(NULL, 0, NULL, 0);
510 AC_MSG_RESULT($found_b64_ntop)
512 if test "x$found_b64_ntop" = xyes; then
513 AC_DEFINE(HAVE_B64_NTOP)
519 # Look for networking libraries.
520 AC_SEARCH_LIBS(inet_ntoa, nsl)
521 AC_SEARCH_LIBS(socket, socket)
522 AC_CHECK_LIB(xnet, socket)
524 # Check if using glibc and have malloc_trim(3). The glibc free(3) is pretty bad
525 # about returning memory to the kernel unless the application tells it when to
526 # with malloc_trim(3).
527 AC_MSG_CHECKING(if free doesn't work very well)
528 AC_LINK_IFELSE([AC_LANG_SOURCE(
541 found_malloc_trim=yes,
544 AC_MSG_RESULT($found_malloc_trim)
545 if test "x$found_malloc_trim" = xyes; then
546 AC_DEFINE(HAVE_MALLOC_TRIM)
549 # Check for CMSG_DATA. On some platforms like HP-UX this requires UNIX 95
550 # (_XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED) (see xopen_networking(7)). On
551 # others, UNIX 03 (_XOPEN_SOURCE 600, see standards(7) on Solaris).
553 AC_MSG_CHECKING(for CMSG_DATA)
557 #include <sys/socket.h>
565 AC_MSG_RESULT($found_cmsg_data)
566 if test "x$found_cmsg_data" = xno; then
567 AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE_EXTENDED)
571 #define _XOPEN_SOURCE 1
572 #define _XOPEN_SOURCE_EXTENDED 1
573 #include <sys/socket.h>
581 AC_MSG_RESULT($found_cmsg_data)
582 if test "x$found_cmsg_data" = xyes; then
583 XOPEN_DEFINES="-D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED"
586 if test "x$found_cmsg_data" = xno; then
587 AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE 600)
591 #define _XOPEN_SOURCE 600
592 #include <sys/socket.h>
600 AC_MSG_RESULT($found_cmsg_data)
601 if test "x$found_cmsg_data" = xyes; then
602 XOPEN_DEFINES="-D_XOPEN_SOURCE=600"
604 AC_MSG_ERROR("CMSG_DATA not found")
607 AC_SUBST(XOPEN_DEFINES)
609 # Look for err and friends in err.h.
610 AC_CHECK_FUNC(err, found_err_h=yes, found_err_h=no)
611 AC_CHECK_FUNC(errx, , found_err_h=no)
612 AC_CHECK_FUNC(warn, , found_err_h=no)
613 AC_CHECK_FUNC(warnx, , found_err_h=no)
614 if test "x$found_err_h" = xyes; then
615 AC_CHECK_HEADER(err.h, , found_err_h=no)
620 # Look for imsg_init in libutil.
621 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
622 if test "x$found_imsg_init" = xyes; then
626 AC_LIBOBJ(imsg-buffer)
629 # Look for daemon, compat/daemon.c used if missing. Solaris 10 has it in
630 # libresolv, but no declaration anywhere, so check for declaration as well as
632 AC_CHECK_FUNC(daemon, found_daemon=yes, found_daemon=no)
642 if test "x$found_daemon" = xyes; then
643 AC_DEFINE(HAVE_DAEMON)
648 # Look for stravis, compat/{vis,unvis}.c used if missing.
649 AC_CHECK_FUNC(stravis, found_stravis=yes, found_stravis=no)
650 if test "x$found_stravis" = xyes; then
651 AC_MSG_CHECKING(if strnvis is broken)
652 AC_EGREP_HEADER([strnvis\(char \*, const char \*, size_t, int\)],
656 if test "x$found_stravis" = xno; then
660 if test "x$found_stravis" = xyes; then
671 if test "x$found_stravis" = xyes; then
678 # Look for fdforkpty and forkpty in libutil.
679 AC_SEARCH_LIBS(fdforkpty, util, found_fdforkpty=yes, found_fdforkpty=no)
680 if test "x$found_fdforkpty" = xyes; then
681 AC_DEFINE(HAVE_FDFORKPTY)
685 AC_SEARCH_LIBS(forkpty, util, found_forkpty=yes, found_forkpty=no)
686 if test "x$found_forkpty" = xyes; then
687 AC_DEFINE(HAVE_FORKPTY)
689 AM_CONDITIONAL(NEED_FORKPTY, test "x$found_forkpty" = xno)
691 # Look for kinfo_getfile in libutil.
692 AC_SEARCH_LIBS(kinfo_getfile, [util util-freebsd])
694 # Look for a suitable queue.h.
699 [#include <sys/queue.h>]
705 [#include <sys/queue.h>]
711 [#include <sys/queue.h>]
713 if test "x$found_queue_h" = xyes; then
714 AC_DEFINE(HAVE_QUEUE_H)
717 # Look for __progname.
718 AC_MSG_CHECKING(for __progname)
719 AC_LINK_IFELSE([AC_LANG_SOURCE(
723 extern char *__progname;
725 const char *cp = __progname;
730 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
734 # Look for program_invocation_short_name.
735 AC_MSG_CHECKING(for program_invocation_short_name)
736 AC_LINK_IFELSE([AC_LANG_SOURCE(
742 const char *cp = program_invocation_short_name;
747 [AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME) AC_MSG_RESULT(yes)],
751 # Look for prctl(PR_SET_NAME).
754 AC_DEFINE(HAVE_PR_SET_NAME),
756 [#include <sys/prctl.h>]
759 # Look for setsockopt(SO_PEERCRED).
762 AC_DEFINE(HAVE_SO_PEERCRED),
764 [#include <sys/socket.h>]
767 # Look for fcntl(F_CLOSEM).
770 AC_DEFINE(HAVE_FCNTL_CLOSEM),
776 AC_MSG_CHECKING(for /proc/\$\$)
777 if test -d /proc/$$; then
778 AC_DEFINE(HAVE_PROC_PID)
784 # Try to figure out what the best value for TERM might be.
785 if test "x$DEFAULT_TERM" = x; then
787 AC_MSG_CHECKING(TERM)
788 AC_RUN_IFELSE([AC_LANG_SOURCE(
792 #if defined(HAVE_CURSES_H)
794 #elif defined(HAVE_NCURSES_H)
799 if (setupterm("screen-256color", -1, NULL) != OK)
804 [DEFAULT_TERM=screen-256color],
806 [DEFAULT_TERM=screen]
808 AC_RUN_IFELSE([AC_LANG_SOURCE(
812 #if defined(HAVE_CURSES_H)
814 #elif defined(HAVE_NCURSES_H)
819 if (setupterm("tmux", -1, NULL) != OK)
826 [DEFAULT_TERM=screen]
828 AC_RUN_IFELSE([AC_LANG_SOURCE(
832 #if defined(HAVE_CURSES_H)
834 #elif defined(HAVE_NCURSES_H)
839 if (setupterm("tmux-256color", -1, NULL) != OK)
844 [DEFAULT_TERM=tmux-256color],
846 [DEFAULT_TERM=screen]
848 AC_MSG_RESULT($DEFAULT_TERM)
850 AC_SUBST(DEFAULT_TERM)
852 # Man page defaults to mdoc.
856 # Figure out the platform.
857 AC_MSG_CHECKING(platform)
864 AC_MSG_RESULT(darwin)
867 # macOS uses __dead2 instead of __dead, like FreeBSD. But it defines
868 # __dead away so it needs to be removed before we can replace it.
870 AC_DEFINE(BROKEN___DEAD)
872 # macOS CMSG_FIRSTHDR is broken, so redefine it with a working one.
873 # daemon works but has some stupid side effects, so use our internal
874 # version which has a workaround.
876 AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
878 AC_LIBOBJ(daemon-darwin)
880 # macOS wcwidth(3) is bad, so complain and suggest using utf8proc
883 if test "x$enable_utf8proc" = x; then
885 AC_MSG_NOTICE([ macOS library support for Unicode is very poor,])
886 AC_MSG_NOTICE([ particularly for complex codepoints like emojis;])
887 AC_MSG_NOTICE([ to use these correctly, configuring with])
888 AC_MSG_NOTICE([ --enable-utf8proc is recommended. To build])
889 AC_MSG_NOTICE([ without anyway, use --disable-utf8proc])
891 AC_MSG_ERROR([must give --enable-utf8proc or --disable-utf8proc])
895 AC_MSG_RESULT(dragonfly)
903 AC_MSG_RESULT(freebsd)
907 AC_MSG_RESULT(netbsd)
911 AC_MSG_RESULT(openbsd)
921 case `/usr/bin/nroff --version 2>&1` in
923 # Solaris 11.4 and later use GNU groff.
927 # Solaris 2.0 to 11.3 use AT&T nroff.
937 AC_MSG_RESULT(cygwin)
945 AC_MSG_RESULT(unknown)
950 AM_CONDITIONAL(IS_AIX, test "x$PLATFORM" = xaix)
951 AM_CONDITIONAL(IS_DARWIN, test "x$PLATFORM" = xdarwin)
952 AM_CONDITIONAL(IS_DRAGONFLY, test "x$PLATFORM" = xdragonfly)
953 AM_CONDITIONAL(IS_LINUX, test "x$PLATFORM" = xlinux)
954 AM_CONDITIONAL(IS_FREEBSD, test "x$PLATFORM" = xfreebsd)
955 AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd)
956 AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd)
957 AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos)
958 AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
959 AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
960 AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
962 # Set the default lock command
963 DEFAULT_LOCK_CMD="lock -np"
964 AC_MSG_CHECKING(lock-command)
965 if test "x$PLATFORM" = xlinux; then
966 AC_CHECK_PROG(found_vlock, vlock, yes, no)
967 if test "x$found_vlock" = xyes; then
968 DEFAULT_LOCK_CMD="vlock"
971 AC_MSG_RESULT($DEFAULT_LOCK_CMD)
972 AC_SUBST(DEFAULT_LOCK_CMD)
975 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
977 AC_SUBST(AM_CPPFLAGS)
978 CPPFLAGS="$SAVED_CPPFLAGS"
980 CFLAGS="$SAVED_CFLAGS"
982 LDFLAGS="$SAVED_LDFLAGS"
984 # autoconf should create a Makefile.
985 AC_CONFIG_FILES(Makefile)