3 AC_INIT([tmux], next-3.5)
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?
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.
181 # Check if strtonum works.
182 AC_MSG_CHECKING([for working strtonum])
183 AC_RUN_IFELSE([AC_LANG_PROGRAM(
184 [#include <stdlib.h>],
185 [return (strtonum("0", 0, 1, NULL) == 0 ? 0 : 1);]
187 [AC_DEFINE(HAVE_STRTONUM) AC_MSG_RESULT(yes)],
188 [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)],
189 [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)]
192 # Clang sanitizers wrap reallocarray even if it isn't available on the target
193 # system. When compiled it always returns NULL and crashes the program. To
194 # detect this we need a more complicated test.
195 AC_MSG_CHECKING([for working reallocarray])
196 AC_RUN_IFELSE([AC_LANG_PROGRAM(
197 [#include <stdlib.h>],
198 [return (reallocarray(NULL, 1, 1) == NULL);]
201 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
202 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
204 AC_MSG_CHECKING([for working recallocarray])
205 AC_RUN_IFELSE([AC_LANG_PROGRAM(
206 [#include <stdlib.h>],
207 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
210 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
211 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
214 # Look for clock_gettime. Must come before event_init.
215 AC_SEARCH_LIBS(clock_gettime, rt)
217 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
218 # musl does not set optarg to NULL for flags without arguments (although it is
219 # not required to, but it is helpful) 3) there are probably other weird
223 # Look for libevent. Try libevent_core or libevent with pkg-config first then
224 # look for the library.
227 [libevent_core >= 2],
229 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
230 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
231 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
236 if test x$found_libevent = xno; then
241 AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
242 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
243 LIBS="$LIBEVENT_LIBS $LIBS"
249 if test x$found_libevent = xno; then
252 [event_core event event-1.4],
259 AC_DEFINE(HAVE_EVENT2_EVENT_H),
263 AC_DEFINE(HAVE_EVENT_H),
268 if test "x$found_libevent" = xno; then
269 AC_MSG_ERROR("libevent not found")
273 AC_CHECK_PROG(found_yacc, $YACC, yes, no)
274 if test "x$found_yacc" = xno; then
275 AC_MSG_ERROR("yacc not found")
278 # Look for ncurses or curses. Try pkg-config first then directly for the
284 AM_CPPFLAGS="$LIBTINFO_CFLAGS $AM_CPPFLAGS"
285 CPPFLAGS="$LIBTINFO_CFLAGS $SAVED_CPPFLAGS"
286 LIBS="$LIBTINFO_LIBS $LIBS"
291 if test "x$found_ncurses" = xno; then
296 AM_CPPFLAGS="$LIBNCURSES_CFLAGS $AM_CPPFLAGS"
297 CPPFLAGS="$LIBNCURSES_CFLAGS $SAVED_CPPFLAGS"
298 LIBS="$LIBNCURSES_LIBS $LIBS"
304 if test "x$found_ncurses" = xno; then
309 AM_CPPFLAGS="$LIBNCURSESW_CFLAGS $AM_CPPFLAGS"
310 CPPFLAGS="$LIBNCURSESW_CFLAGS $SAVED_CPPFLAGS"
311 LIBS="$LIBNCURSESW_LIBS $LIBS"
317 if test "x$found_ncurses" = xno; then
320 [tinfo terminfo ncurses ncursesw],
324 if test "x$found_ncurses" = xyes; then
327 LIBS="$LIBS -lncurses",
332 if test "x$found_ncurses" = xyes; then
333 CPPFLAGS="$CPPFLAGS -DHAVE_NCURSES_H"
334 AC_DEFINE(HAVE_NCURSES_H)
347 if test "x$found_curses" = xyes; then
348 LIBS="$LIBS -lcurses"
349 CPPFLAGS="$CPPFLAGS -DHAVE_CURSES_H"
350 AC_DEFINE(HAVE_CURSES_H)
352 AC_MSG_ERROR("curses not found")
363 AS_HELP_STRING(--enable-utempter, use utempter if it is installed)
365 if test "x$enable_utempter" = xyes; then
366 AC_CHECK_HEADER(utempter.h, enable_utempter=yes, enable_utempter=no)
367 if test "x$enable_utempter" = xyes; then
375 if test "x$enable_utempter" = xyes; then
376 AC_DEFINE(HAVE_UTEMPTER)
378 AC_MSG_ERROR("utempter not found")
385 AS_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
387 if test "x$enable_utf8proc" = xyes; then
392 AM_CPPFLAGS="$LIBUTF8PROC_CFLAGS $AM_CPPFLAGS"
393 CPPFLAGS="$LIBUTF8PROC_CFLAGS $SAVED_CPPFLAGS"
394 LIBS="$LIBUTF8PROC_LIBS $LIBS"
397 AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no)
398 if test "x$enable_utf8proc" = xyes; then
406 if test "x$enable_utf8proc" = xyes; then
407 AC_DEFINE(HAVE_UTF8PROC)
409 AC_MSG_ERROR("utf8proc not found")
412 AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes])
414 # Check for systemd support.
417 AS_HELP_STRING(--enable-systemd, enable systemd integration)
419 if test x"$enable_systemd" = xyes; then
424 AM_CPPFLAGS="$SYSTEMD_CFLAGS $AM_CPPFLAGS"
425 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
426 LIBS="$SYSTEMD_LIBS $LIBS"
431 if test "x$found_systemd" = xyes; then
432 AC_DEFINE(HAVE_SYSTEMD)
434 AC_MSG_ERROR("systemd not found")
437 AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$found_systemd" = xyes])
440 AS_HELP_STRING(--disable-cgroups, disable adding panes to new cgroups with systemd)
442 if test "x$enable_cgroups" = x; then
443 # Default to the same as $enable_systemd.
444 enable_cgroups=$enable_systemd
446 if test "x$enable_cgroups" = xyes; then
447 if test "x$found_systemd" = xyes; then
448 AC_DEFINE(ENABLE_CGROUPS)
450 AC_MSG_ERROR("cgroups requires systemd to be enabled")
454 # Enable sixel support.
457 AS_HELP_STRING(--enable-sixel, enable sixel images)
459 if test "x$enable_sixel" = xyes; then
460 AC_DEFINE(ENABLE_SIXEL)
462 AM_CONDITIONAL(ENABLE_SIXEL, [test "x$enable_sixel" = xyes])
464 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
465 AC_MSG_CHECKING(for b64_ntop)
466 AC_LINK_IFELSE([AC_LANG_PROGRAM(
468 #include <sys/types.h>
469 #include <netinet/in.h>
473 b64_ntop(NULL, 0, NULL, 0);
478 AC_MSG_RESULT($found_b64_ntop)
480 if test "x$found_b64_ntop" = xno; then
481 AC_MSG_CHECKING(for b64_ntop with -lresolv)
482 LIBS="$OLD_LIBS -lresolv"
483 AC_LINK_IFELSE([AC_LANG_PROGRAM(
485 #include <sys/types.h>
486 #include <netinet/in.h>
490 b64_ntop(NULL, 0, NULL, 0);
495 AC_MSG_RESULT($found_b64_ntop)
497 if test "x$found_b64_ntop" = xno; then
498 AC_MSG_CHECKING(for b64_ntop with -lnetwork)
499 LIBS="$OLD_LIBS -lnetwork"
500 AC_LINK_IFELSE([AC_LANG_PROGRAM(
502 #include <sys/types.h>
503 #include <netinet/in.h>
507 b64_ntop(NULL, 0, NULL, 0);
512 AC_MSG_RESULT($found_b64_ntop)
514 if test "x$found_b64_ntop" = xyes; then
515 AC_DEFINE(HAVE_B64_NTOP)
521 # Look for networking libraries.
522 AC_SEARCH_LIBS(inet_ntoa, nsl)
523 AC_SEARCH_LIBS(socket, socket)
524 AC_CHECK_LIB(xnet, socket)
526 # Check if using glibc and have malloc_trim(3). The glibc free(3) is pretty bad
527 # about returning memory to the kernel unless the application tells it when to
528 # with malloc_trim(3).
529 AC_MSG_CHECKING(if free doesn't work very well)
530 AC_LINK_IFELSE([AC_LANG_SOURCE(
543 found_malloc_trim=yes,
546 AC_MSG_RESULT($found_malloc_trim)
547 if test "x$found_malloc_trim" = xyes; then
548 AC_DEFINE(HAVE_MALLOC_TRIM)
551 # Check for CMSG_DATA. On some platforms like HP-UX this requires UNIX 95
552 # (_XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED) (see xopen_networking(7)). On
553 # others, UNIX 03 (_XOPEN_SOURCE 600, see standards(7) on Solaris).
555 AC_MSG_CHECKING(for CMSG_DATA)
559 #include <sys/socket.h>
567 AC_MSG_RESULT($found_cmsg_data)
568 if test "x$found_cmsg_data" = xno; then
569 AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE_EXTENDED)
573 #define _XOPEN_SOURCE 1
574 #define _XOPEN_SOURCE_EXTENDED 1
575 #include <sys/socket.h>
583 AC_MSG_RESULT($found_cmsg_data)
584 if test "x$found_cmsg_data" = xyes; then
585 XOPEN_DEFINES="-D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED"
588 if test "x$found_cmsg_data" = xno; then
589 AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE 600)
593 #define _XOPEN_SOURCE 600
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=600"
606 AC_MSG_ERROR("CMSG_DATA not found")
609 AC_SUBST(XOPEN_DEFINES)
611 # Look for err and friends in err.h.
612 AC_CHECK_FUNC(err, found_err_h=yes, found_err_h=no)
613 AC_CHECK_FUNC(errx, , found_err_h=no)
614 AC_CHECK_FUNC(warn, , found_err_h=no)
615 AC_CHECK_FUNC(warnx, , found_err_h=no)
616 if test "x$found_err_h" = xyes; then
617 AC_CHECK_HEADER(err.h, , found_err_h=no)
622 # Look for imsg_init in libutil.
623 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
624 if test "x$found_imsg_init" = xyes; then
628 AC_LIBOBJ(imsg-buffer)
631 # Look for daemon, compat/daemon.c used if missing. Solaris 10 has it in
632 # libresolv, but no declaration anywhere, so check for declaration as well as
634 AC_CHECK_FUNC(daemon, found_daemon=yes, found_daemon=no)
644 if test "x$found_daemon" = xyes; then
645 AC_DEFINE(HAVE_DAEMON)
650 # Look for stravis, compat/{vis,unvis}.c used if missing.
651 AC_CHECK_FUNC(stravis, found_stravis=yes, found_stravis=no)
652 if test "x$found_stravis" = xyes; then
653 AC_MSG_CHECKING(if strnvis is broken)
654 AC_EGREP_HEADER([strnvis\(char \*, const char \*, size_t, int\)],
658 if test "x$found_stravis" = xno; then
662 if test "x$found_stravis" = xyes; then
673 if test "x$found_stravis" = xyes; then
680 # Look for fdforkpty and forkpty in libutil.
681 AC_SEARCH_LIBS(fdforkpty, util, found_fdforkpty=yes, found_fdforkpty=no)
682 if test "x$found_fdforkpty" = xyes; then
683 AC_DEFINE(HAVE_FDFORKPTY)
687 AC_SEARCH_LIBS(forkpty, util, found_forkpty=yes, found_forkpty=no)
688 if test "x$found_forkpty" = xyes; then
689 AC_DEFINE(HAVE_FORKPTY)
691 AM_CONDITIONAL(NEED_FORKPTY, test "x$found_forkpty" = xno)
693 # Look for kinfo_getfile in libutil.
694 AC_SEARCH_LIBS(kinfo_getfile, [util util-freebsd])
696 # Look for a suitable queue.h.
701 [#include <sys/queue.h>]
707 [#include <sys/queue.h>]
713 [#include <sys/queue.h>]
715 if test "x$found_queue_h" = xyes; then
716 AC_DEFINE(HAVE_QUEUE_H)
719 # Look for __progname.
720 AC_MSG_CHECKING(for __progname)
721 AC_LINK_IFELSE([AC_LANG_SOURCE(
725 extern char *__progname;
727 const char *cp = __progname;
732 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
736 # Look for program_invocation_short_name.
737 AC_MSG_CHECKING(for program_invocation_short_name)
738 AC_LINK_IFELSE([AC_LANG_SOURCE(
744 const char *cp = program_invocation_short_name;
749 [AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME) AC_MSG_RESULT(yes)],
753 # Look for prctl(PR_SET_NAME).
756 AC_DEFINE(HAVE_PR_SET_NAME),
758 [#include <sys/prctl.h>]
761 # Look for setsockopt(SO_PEERCRED).
764 AC_DEFINE(HAVE_SO_PEERCRED),
766 [#include <sys/socket.h>]
769 # Look for fcntl(F_CLOSEM).
772 AC_DEFINE(HAVE_FCNTL_CLOSEM),
778 AC_MSG_CHECKING(for /proc/\$\$)
779 if test -d /proc/$$; then
780 AC_DEFINE(HAVE_PROC_PID)
786 # Try to figure out what the best value for TERM might be.
787 if test "x$DEFAULT_TERM" = x; then
789 AC_MSG_CHECKING(TERM)
790 AC_RUN_IFELSE([AC_LANG_SOURCE(
794 #if defined(HAVE_CURSES_H)
796 #elif defined(HAVE_NCURSES_H)
801 if (setupterm("screen-256color", -1, NULL) != OK)
806 [DEFAULT_TERM=screen-256color],
808 [DEFAULT_TERM=screen]
810 AC_RUN_IFELSE([AC_LANG_SOURCE(
814 #if defined(HAVE_CURSES_H)
816 #elif defined(HAVE_NCURSES_H)
821 if (setupterm("tmux", -1, NULL) != OK)
828 [DEFAULT_TERM=screen]
830 AC_RUN_IFELSE([AC_LANG_SOURCE(
834 #if defined(HAVE_CURSES_H)
836 #elif defined(HAVE_NCURSES_H)
841 if (setupterm("tmux-256color", -1, NULL) != OK)
846 [DEFAULT_TERM=tmux-256color],
848 [DEFAULT_TERM=screen]
850 AC_MSG_RESULT($DEFAULT_TERM)
852 AC_SUBST(DEFAULT_TERM)
854 # Man page defaults to mdoc.
858 # Figure out the platform.
859 AC_MSG_CHECKING(platform)
866 AC_MSG_RESULT(darwin)
869 # macOS uses __dead2 instead of __dead, like FreeBSD. But it defines
870 # __dead away so it needs to be removed before we can replace it.
872 AC_DEFINE(BROKEN___DEAD)
874 # macOS CMSG_FIRSTHDR is broken, so redefine it with a working one.
875 # daemon works but has some stupid side effects, so use our internal
876 # version which has a workaround.
878 AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
880 AC_LIBOBJ(daemon-darwin)
882 # macOS wcwidth(3) is bad, so complain and suggest using utf8proc
885 if test "x$enable_utf8proc" = x; then
887 AC_MSG_NOTICE([ macOS library support for Unicode is very poor,])
888 AC_MSG_NOTICE([ particularly for complex codepoints like emojis;])
889 AC_MSG_NOTICE([ to use these correctly, configuring with])
890 AC_MSG_NOTICE([ --enable-utf8proc is recommended. To build])
891 AC_MSG_NOTICE([ without anyway, use --disable-utf8proc])
893 AC_MSG_ERROR([must give --enable-utf8proc or --disable-utf8proc])
897 AC_MSG_RESULT(dragonfly)
905 AC_MSG_RESULT(freebsd)
909 AC_MSG_RESULT(netbsd)
913 AC_MSG_RESULT(openbsd)
923 case `/usr/bin/nroff --version 2>&1` in
925 # Solaris 11.4 and later use GNU groff.
929 # Solaris 2.0 to 11.3 use AT&T nroff.
939 AC_MSG_RESULT(cygwin)
947 AC_MSG_RESULT(unknown)
952 AM_CONDITIONAL(IS_AIX, test "x$PLATFORM" = xaix)
953 AM_CONDITIONAL(IS_DARWIN, test "x$PLATFORM" = xdarwin)
954 AM_CONDITIONAL(IS_DRAGONFLY, test "x$PLATFORM" = xdragonfly)
955 AM_CONDITIONAL(IS_LINUX, test "x$PLATFORM" = xlinux)
956 AM_CONDITIONAL(IS_FREEBSD, test "x$PLATFORM" = xfreebsd)
957 AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd)
958 AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd)
959 AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos)
960 AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
961 AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
962 AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
964 # Set the default lock command
965 DEFAULT_LOCK_CMD="lock -np"
966 AC_MSG_CHECKING(lock-command)
967 if test "x$PLATFORM" = xlinux; then
968 AC_CHECK_PROG(found_vlock, vlock, yes, no)
969 if test "x$found_vlock" = xyes; then
970 DEFAULT_LOCK_CMD="vlock"
973 AC_MSG_RESULT($DEFAULT_LOCK_CMD)
974 AC_SUBST(DEFAULT_LOCK_CMD)
977 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
979 AC_SUBST(AM_CPPFLAGS)
980 CPPFLAGS="$SAVED_CPPFLAGS"
982 CFLAGS="$SAVED_CFLAGS"
984 LDFLAGS="$SAVED_LDFLAGS"
986 # autoconf should create a Makefile.
987 AC_CONFIG_FILES(Makefile)