3 AC_INIT([tmux], next-3.6)
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.
47 m4_version_prereq(2.70, [AC_PROG_CC], [AC_PROG_CC_C99])
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?
61 AS_HELP_STRING(--enable-debug, enable debug build flags),
63 [case "x$VERSION" in xnext*) enable_debug=yes;; esac]
65 AM_CONDITIONAL(IS_DEBUG, test "x$enable_debug" = xyes)
67 # Is this a static build?
70 AS_HELP_STRING(--enable-static, create a static build)
72 if test "x$enable_static" = xyes; then
75 AC_MSG_ERROR([static linking is not supported on macOS])
78 test "x$PKG_CONFIG" != x && PKG_CONFIG="$PKG_CONFIG --static"
79 AM_LDFLAGS="-static $AM_LDFLAGS"
80 LDFLAGS="$AM_LDFLAGS $SAVED_LDFLAGS"
83 # Allow default TERM to be set.
86 AS_HELP_STRING(--with-TERM, set default TERM),
87 [DEFAULT_TERM=$withval],
90 case "x$DEFAULT_TERM" in
94 AC_MSG_ERROR("unsuitable TERM (must be screen* or tmux*)")
99 AM_CONDITIONAL(NEED_FUZZING, test "x$enable_fuzzing" = xyes)
102 AM_CONDITIONAL(IS_GCC, test "x$GCC" = xyes -a "x$enable_fuzzing" != xyes)
115 AM_CONDITIONAL(IS_SUNCC, test "x$found_suncc" = xyes)
117 # Check for various headers. Alternatives included from compat.h.
136 # Look for sys_signame.
137 AC_SEARCH_LIBS(sys_signame, , AC_DEFINE(HAVE_SYS_SIGNAME))
140 AC_CHECK_LIB(m, fmod)
142 # Look for library needed for flock.
143 AC_SEARCH_LIBS(flock, bsd)
145 # Check for functions that are replaced or omitted.
155 # Check for functions with a compatibility implementation.
182 # Check if strtonum works.
183 AC_MSG_CHECKING([for working strtonum])
184 AC_RUN_IFELSE([AC_LANG_PROGRAM(
185 [#include <stdlib.h>],
186 [return (strtonum("0", 0, 1, NULL) == 0 ? 0 : 1);]
188 [AC_DEFINE(HAVE_STRTONUM) AC_MSG_RESULT(yes)],
189 [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)],
190 [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)]
193 # Clang sanitizers wrap reallocarray even if it isn't available on the target
194 # system. When compiled it always returns NULL and crashes the program. To
195 # detect this we need a more complicated test.
196 AC_MSG_CHECKING([for working reallocarray])
197 AC_RUN_IFELSE([AC_LANG_PROGRAM(
198 [#include <stdlib.h>],
199 [return (reallocarray(NULL, 1, 1) == NULL);]
202 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
203 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
205 AC_MSG_CHECKING([for working recallocarray])
206 AC_RUN_IFELSE([AC_LANG_PROGRAM(
207 [#include <stdlib.h>],
208 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
211 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
212 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
215 # Look for clock_gettime. Must come before event_init.
216 AC_SEARCH_LIBS(clock_gettime, rt)
218 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
219 # musl does not set optarg to NULL for flags without arguments (although it is
220 # not required to, but it is helpful) 3) there are probably other weird
224 # Look for libevent. Try libevent_core or libevent with pkg-config first then
225 # look for the library.
228 [libevent_core >= 2],
230 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
231 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
232 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
237 if test x$found_libevent = xno; then
242 AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
243 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
244 LIBS="$LIBEVENT_LIBS $LIBS"
250 if test x$found_libevent = xno; then
253 [event_core event event-1.4],
260 AC_DEFINE(HAVE_EVENT2_EVENT_H),
264 AC_DEFINE(HAVE_EVENT_H),
269 if test "x$found_libevent" = xno; then
270 AC_MSG_ERROR("libevent not found")
274 AC_CHECK_PROG(found_yacc, $YACC, yes, no)
275 if test "x$found_yacc" = xno; then
276 AC_MSG_ERROR("yacc not found")
279 # Look for ncurses or curses. Try pkg-config first then directly for the
285 AM_CPPFLAGS="$LIBTINFO_CFLAGS $AM_CPPFLAGS"
286 CPPFLAGS="$LIBTINFO_CFLAGS $SAVED_CPPFLAGS"
287 LIBS="$LIBTINFO_LIBS $LIBS"
292 if test "x$found_ncurses" = xno; then
297 AM_CPPFLAGS="$LIBNCURSES_CFLAGS $AM_CPPFLAGS"
298 CPPFLAGS="$LIBNCURSES_CFLAGS $SAVED_CPPFLAGS"
299 LIBS="$LIBNCURSES_LIBS $LIBS"
305 if test "x$found_ncurses" = xno; then
310 AM_CPPFLAGS="$LIBNCURSESW_CFLAGS $AM_CPPFLAGS"
311 CPPFLAGS="$LIBNCURSESW_CFLAGS $SAVED_CPPFLAGS"
312 LIBS="$LIBNCURSESW_LIBS $LIBS"
318 if test "x$found_ncurses" = xno; then
321 [tinfo terminfo ncurses ncursesw],
325 if test "x$found_ncurses" = xyes; then
328 LIBS="$LIBS -lncurses",
333 if test "x$found_ncurses" = xyes; then
334 CPPFLAGS="$CPPFLAGS -DHAVE_NCURSES_H"
335 AC_DEFINE(HAVE_NCURSES_H)
348 if test "x$found_curses" = xyes; then
349 LIBS="$LIBS -lcurses"
350 CPPFLAGS="$CPPFLAGS -DHAVE_CURSES_H"
351 AC_DEFINE(HAVE_CURSES_H)
353 AC_MSG_ERROR("curses not found")
364 AS_HELP_STRING(--enable-utempter, use utempter if it is installed)
366 if test "x$enable_utempter" = xyes; then
367 AC_CHECK_HEADER(utempter.h, enable_utempter=yes, enable_utempter=no)
368 if test "x$enable_utempter" = xyes; then
376 if test "x$enable_utempter" = xyes; then
377 AC_DEFINE(HAVE_UTEMPTER)
379 AC_MSG_ERROR("utempter not found")
386 AS_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
388 if test "x$enable_utf8proc" = xyes; then
393 AM_CPPFLAGS="$LIBUTF8PROC_CFLAGS $AM_CPPFLAGS"
394 CPPFLAGS="$LIBUTF8PROC_CFLAGS $SAVED_CPPFLAGS"
395 LIBS="$LIBUTF8PROC_LIBS $LIBS"
398 AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no)
399 if test "x$enable_utf8proc" = xyes; then
407 if test "x$enable_utf8proc" = xyes; then
408 AC_DEFINE(HAVE_UTF8PROC)
410 AC_MSG_ERROR("utf8proc not found")
413 AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes])
415 # Check for systemd support.
418 AS_HELP_STRING(--enable-systemd, enable systemd integration)
420 if test x"$enable_systemd" = xyes; then
425 AM_CPPFLAGS="$SYSTEMD_CFLAGS $AM_CPPFLAGS"
426 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
427 LIBS="$SYSTEMD_LIBS $LIBS"
432 if test "x$found_systemd" = xyes; then
433 AC_DEFINE(HAVE_SYSTEMD)
435 AC_MSG_ERROR("systemd not found")
438 AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$found_systemd" = xyes])
441 AS_HELP_STRING(--disable-cgroups, disable adding panes to new cgroups with systemd)
443 if test "x$enable_cgroups" = x; then
444 # Default to the same as $enable_systemd.
445 enable_cgroups=$enable_systemd
447 if test "x$enable_cgroups" = xyes; then
448 if test "x$found_systemd" = xyes; then
449 AC_DEFINE(ENABLE_CGROUPS)
451 AC_MSG_ERROR("cgroups requires systemd to be enabled")
455 # Enable sixel support.
458 AS_HELP_STRING(--enable-sixel, enable sixel images)
460 if test "x$enable_sixel" = xyes; then
461 AC_DEFINE(ENABLE_SIXEL)
463 AM_CONDITIONAL(ENABLE_SIXEL, [test "x$enable_sixel" = xyes])
465 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
466 AC_MSG_CHECKING(for b64_ntop)
467 AC_LINK_IFELSE([AC_LANG_PROGRAM(
469 #include <sys/types.h>
470 #include <netinet/in.h>
474 b64_ntop(NULL, 0, NULL, 0);
479 AC_MSG_RESULT($found_b64_ntop)
481 if test "x$found_b64_ntop" = xno; then
482 AC_MSG_CHECKING(for b64_ntop with -lresolv)
483 LIBS="$OLD_LIBS -lresolv"
484 AC_LINK_IFELSE([AC_LANG_PROGRAM(
486 #include <sys/types.h>
487 #include <netinet/in.h>
491 b64_ntop(NULL, 0, NULL, 0);
496 AC_MSG_RESULT($found_b64_ntop)
498 if test "x$found_b64_ntop" = xno; then
499 AC_MSG_CHECKING(for b64_ntop with -lnetwork)
500 LIBS="$OLD_LIBS -lnetwork"
501 AC_LINK_IFELSE([AC_LANG_PROGRAM(
503 #include <sys/types.h>
504 #include <netinet/in.h>
508 b64_ntop(NULL, 0, NULL, 0);
513 AC_MSG_RESULT($found_b64_ntop)
515 if test "x$found_b64_ntop" = xyes; then
516 AC_DEFINE(HAVE_B64_NTOP)
522 # Look for networking libraries.
523 AC_SEARCH_LIBS(inet_ntoa, nsl)
524 AC_SEARCH_LIBS(socket, socket)
525 AC_CHECK_LIB(xnet, socket)
527 # Check if using glibc and have malloc_trim(3). The glibc free(3) is pretty bad
528 # about returning memory to the kernel unless the application tells it when to
529 # with malloc_trim(3).
530 AC_MSG_CHECKING(if free doesn't work very well)
531 AC_LINK_IFELSE([AC_LANG_SOURCE(
544 found_malloc_trim=yes,
547 AC_MSG_RESULT($found_malloc_trim)
548 if test "x$found_malloc_trim" = xyes; then
549 AC_DEFINE(HAVE_MALLOC_TRIM)
552 # Build against jemalloc if requested.
555 AS_HELP_STRING(--enable-jemalloc, use jemalloc if it is installed)
557 if test "x$enable_jemalloc" = xyes; then
562 AM_CPPFLAGS="$JEMALLOC_CFLAGS $AM_CPPFLAGS"
563 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
564 LIBS="$LIBS $JEMALLOC_LIBS"
566 AC_MSG_ERROR("jemalloc not found")
570 # Check for CMSG_DATA. On some platforms like HP-UX this requires UNIX 95
571 # (_XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED) (see xopen_networking(7)). On
572 # others, UNIX 03 (_XOPEN_SOURCE 600, see standards(7) on Solaris).
574 AC_MSG_CHECKING(for CMSG_DATA)
578 #include <sys/socket.h>
586 AC_MSG_RESULT($found_cmsg_data)
587 if test "x$found_cmsg_data" = xno; then
588 AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE_EXTENDED)
592 #define _XOPEN_SOURCE 1
593 #define _XOPEN_SOURCE_EXTENDED 1
594 #include <sys/socket.h>
602 AC_MSG_RESULT($found_cmsg_data)
603 if test "x$found_cmsg_data" = xyes; then
604 XOPEN_DEFINES="-D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED"
607 if test "x$found_cmsg_data" = xno; then
608 AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE 600)
612 #define _XOPEN_SOURCE 600
613 #include <sys/socket.h>
621 AC_MSG_RESULT($found_cmsg_data)
622 if test "x$found_cmsg_data" = xyes; then
623 XOPEN_DEFINES="-D_XOPEN_SOURCE=600"
625 AC_MSG_ERROR("CMSG_DATA not found")
628 AC_SUBST(XOPEN_DEFINES)
630 # Look for err and friends in err.h.
631 AC_CHECK_FUNC(err, found_err_h=yes, found_err_h=no)
632 AC_CHECK_FUNC(errx, , found_err_h=no)
633 AC_CHECK_FUNC(warn, , found_err_h=no)
634 AC_CHECK_FUNC(warnx, , found_err_h=no)
635 if test "x$found_err_h" = xyes; then
636 AC_CHECK_HEADER(err.h, , found_err_h=no)
641 # Look for imsg_init in libutil.
642 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
643 if test "x$found_imsg_init" = xyes; then
647 AC_LIBOBJ(imsg-buffer)
650 # Look for daemon, compat/daemon.c used if missing. Solaris 10 has it in
651 # libresolv, but no declaration anywhere, so check for declaration as well as
653 AC_CHECK_FUNC(daemon, found_daemon=yes, found_daemon=no)
663 if test "x$found_daemon" = xyes; then
664 AC_DEFINE(HAVE_DAEMON)
669 # Look for stravis, compat/{vis,unvis}.c used if missing.
670 AC_CHECK_FUNC(stravis, found_stravis=yes, found_stravis=no)
671 if test "x$found_stravis" = xyes; then
672 AC_MSG_CHECKING(if strnvis is broken)
673 AC_EGREP_HEADER([strnvis\(char \*, const char \*, size_t, int\)],
677 if test "x$found_stravis" = xno; then
681 if test "x$found_stravis" = xyes; then
692 if test "x$found_stravis" = xyes; then
699 # Look for fdforkpty and forkpty in libutil.
700 AC_SEARCH_LIBS(fdforkpty, util, found_fdforkpty=yes, found_fdforkpty=no)
701 if test "x$found_fdforkpty" = xyes; then
702 AC_DEFINE(HAVE_FDFORKPTY)
706 AC_SEARCH_LIBS(forkpty, util, found_forkpty=yes, found_forkpty=no)
707 if test "x$found_forkpty" = xyes; then
708 AC_DEFINE(HAVE_FORKPTY)
710 AM_CONDITIONAL(NEED_FORKPTY, test "x$found_forkpty" = xno)
712 # Look for kinfo_getfile in libutil.
713 AC_SEARCH_LIBS(kinfo_getfile, [util util-freebsd])
715 # Look for a suitable queue.h.
720 [#include <sys/queue.h>]
726 [#include <sys/queue.h>]
732 [#include <sys/queue.h>]
734 if test "x$found_queue_h" = xyes; then
735 AC_DEFINE(HAVE_QUEUE_H)
738 # Look for __progname.
739 AC_MSG_CHECKING(for __progname)
740 AC_LINK_IFELSE([AC_LANG_SOURCE(
744 extern char *__progname;
746 const char *cp = __progname;
751 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
755 # Look for program_invocation_short_name.
756 AC_MSG_CHECKING(for program_invocation_short_name)
757 AC_LINK_IFELSE([AC_LANG_SOURCE(
763 const char *cp = program_invocation_short_name;
768 [AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME) AC_MSG_RESULT(yes)],
772 # Look for prctl(PR_SET_NAME).
775 AC_DEFINE(HAVE_PR_SET_NAME),
777 [#include <sys/prctl.h>]
780 # Look for setsockopt(SO_PEERCRED).
783 AC_DEFINE(HAVE_SO_PEERCRED),
785 [#include <sys/socket.h>]
788 # Look for fcntl(F_CLOSEM).
791 AC_DEFINE(HAVE_FCNTL_CLOSEM),
797 AC_MSG_CHECKING(for /proc/\$\$)
798 if test -d /proc/$$; then
799 AC_DEFINE(HAVE_PROC_PID)
805 # Try to figure out what the best value for TERM might be.
806 if test "x$DEFAULT_TERM" = x; then
808 AC_MSG_CHECKING(TERM)
809 AC_RUN_IFELSE([AC_LANG_SOURCE(
813 #if defined(HAVE_CURSES_H)
815 #elif defined(HAVE_NCURSES_H)
820 if (setupterm("screen-256color", -1, NULL) != OK)
825 [DEFAULT_TERM=screen-256color],
827 [DEFAULT_TERM=screen]
829 AC_RUN_IFELSE([AC_LANG_SOURCE(
833 #if defined(HAVE_CURSES_H)
835 #elif defined(HAVE_NCURSES_H)
840 if (setupterm("tmux", -1, NULL) != OK)
847 [DEFAULT_TERM=screen]
849 AC_RUN_IFELSE([AC_LANG_SOURCE(
853 #if defined(HAVE_CURSES_H)
855 #elif defined(HAVE_NCURSES_H)
860 if (setupterm("tmux-256color", -1, NULL) != OK)
865 [DEFAULT_TERM=tmux-256color],
867 [DEFAULT_TERM=screen]
869 AC_MSG_RESULT($DEFAULT_TERM)
871 AC_SUBST(DEFAULT_TERM)
873 # Man page defaults to mdoc.
877 # Figure out the platform.
878 AC_MSG_CHECKING(platform)
885 AC_MSG_RESULT(darwin)
888 # macOS uses __dead2 instead of __dead, like FreeBSD. But it defines
889 # __dead away so it needs to be removed before we can replace it.
891 AC_DEFINE(BROKEN___DEAD)
893 # macOS CMSG_FIRSTHDR is broken, so redefine it with a working one.
894 # daemon works but has some stupid side effects, so use our internal
895 # version which has a workaround.
897 AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
899 AC_LIBOBJ(daemon-darwin)
901 # macOS wcwidth(3) is bad, so complain and suggest using utf8proc
904 if test "x$enable_utf8proc" = x; then
906 AC_MSG_NOTICE([ macOS library support for Unicode is very poor,])
907 AC_MSG_NOTICE([ particularly for complex codepoints like emojis;])
908 AC_MSG_NOTICE([ to use these correctly, configuring with])
909 AC_MSG_NOTICE([ --enable-utf8proc is recommended. To build])
910 AC_MSG_NOTICE([ without anyway, use --disable-utf8proc])
912 AC_MSG_ERROR([must give --enable-utf8proc or --disable-utf8proc])
916 AC_MSG_RESULT(dragonfly)
924 AC_MSG_RESULT(freebsd)
928 AC_MSG_RESULT(netbsd)
932 AC_MSG_RESULT(openbsd)
942 case `/usr/bin/nroff --version 2>&1` in
944 # Solaris 11.4 and later use GNU groff.
948 if test `uname -o 2>/dev/null` = illumos; then
949 # Illumos uses mandoc.
952 # Solaris 2.0 to 11.3 use AT&T nroff.
963 AC_MSG_RESULT(cygwin)
971 AC_MSG_RESULT(unknown)
976 AM_CONDITIONAL(IS_AIX, test "x$PLATFORM" = xaix)
977 AM_CONDITIONAL(IS_DARWIN, test "x$PLATFORM" = xdarwin)
978 AM_CONDITIONAL(IS_DRAGONFLY, test "x$PLATFORM" = xdragonfly)
979 AM_CONDITIONAL(IS_LINUX, test "x$PLATFORM" = xlinux)
980 AM_CONDITIONAL(IS_FREEBSD, test "x$PLATFORM" = xfreebsd)
981 AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd)
982 AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd)
983 AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos)
984 AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
985 AM_CONDITIONAL(IS_CYGWIN, test "x$PLATFORM" = xcygwin)
986 AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
987 AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
989 # Set the default lock command
990 DEFAULT_LOCK_CMD="lock -np"
991 AC_MSG_CHECKING(lock-command)
992 if test "x$PLATFORM" = xlinux; then
993 AC_CHECK_PROG(found_vlock, vlock, yes, no)
994 if test "x$found_vlock" = xyes; then
995 DEFAULT_LOCK_CMD="vlock"
998 AC_MSG_RESULT($DEFAULT_LOCK_CMD)
999 AC_SUBST(DEFAULT_LOCK_CMD)
1002 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
1004 AC_SUBST(AM_CPPFLAGS)
1005 CPPFLAGS="$SAVED_CPPFLAGS"
1007 CFLAGS="$SAVED_CFLAGS"
1008 AC_SUBST(AM_LDFLAGS)
1009 LDFLAGS="$SAVED_LDFLAGS"
1011 # autoconf should create a Makefile.
1012 AC_CONFIG_FILES(Makefile)