3 AC_INIT([tmux], 3.3-rc)
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")
270 # Look for ncurses or curses. Try pkg-config first then directly for the
276 AM_CPPFLAGS="$LIBTINFO_CFLAGS $AM_CPPFLAGS"
277 CPPFLAGS="$LIBTINFO_CFLAGS $SAVED_CPPFLAGS"
278 LIBS="$LIBTINFO_LIBS $LIBS"
283 if test "x$found_ncurses" = xno; then
288 AM_CPPFLAGS="$LIBNCURSES_CFLAGS $AM_CPPFLAGS"
289 CPPFLAGS="$LIBNCURSES_CFLAGS $SAVED_CPPFLAGS"
290 LIBS="$LIBNCURSES_LIBS $LIBS"
296 if test "x$found_ncurses" = xno; then
301 AM_CPPFLAGS="$LIBNCURSESW_CFLAGS $AM_CPPFLAGS"
302 CPPFLAGS="$LIBNCURSESW_CFLAGS $SAVED_CPPFLAGS"
303 LIBS="$LIBNCURSESW_LIBS $LIBS"
309 if test "x$found_ncurses" = xno; then
312 [tinfo ncurses ncursesw],
316 if test "x$found_ncurses" = xyes; then
319 LIBS="$LIBS -lncurses",
324 if test "x$found_ncurses" = xyes; then
325 CPPFLAGS="$CPPFLAGS -DHAVE_NCURSES_H"
326 AC_DEFINE(HAVE_NCURSES_H)
339 if test "x$found_curses" = xyes; then
340 LIBS="$LIBS -lcurses"
341 CPPFLAGS="$CPPFLAGS -DHAVE_CURSES_H"
342 AC_DEFINE(HAVE_CURSES_H)
344 AC_MSG_ERROR("curses not found")
351 AS_HELP_STRING(--enable-utempter, use utempter if it is installed)
353 if test "x$enable_utempter" = xyes; then
354 AC_CHECK_HEADER(utempter.h, enable_utempter=yes, enable_utempter=no)
355 if test "x$enable_utempter" = xyes; then
363 if test "x$enable_utempter" = xyes; then
364 AC_DEFINE(HAVE_UTEMPTER)
366 AC_MSG_ERROR("utempter not found")
373 AS_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
375 if test "x$enable_utf8proc" = xyes; then
376 AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no)
377 if test "x$enable_utf8proc" = xyes; then
385 if test "x$enable_utf8proc" = xyes; then
386 AC_DEFINE(HAVE_UTF8PROC)
388 AC_MSG_ERROR("utf8proc not found")
391 AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes])
393 # Check for systemd support.
396 AS_HELP_STRING(--enable-systemd, enable systemd integration)
398 if test x"$enable_systemd" = xyes; then
403 AM_CPPFLAGS="$SYSTEMD_CFLAGS $AM_CPPFLAGS"
404 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
405 LIBS="$SYSTEMD_LIBS $LIBS"
410 if test "x$found_systemd" = xyes; then
411 AC_DEFINE(HAVE_SYSTEMD)
413 AC_MSG_ERROR("systemd not found")
416 AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$found_systemd" = xyes])
418 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
419 AC_MSG_CHECKING(for b64_ntop)
420 AC_LINK_IFELSE([AC_LANG_PROGRAM(
422 #include <sys/types.h>
423 #include <netinet/in.h>
427 b64_ntop(NULL, 0, NULL, 0);
432 AC_MSG_RESULT($found_b64_ntop)
434 if test "x$found_b64_ntop" = xno; then
435 AC_MSG_CHECKING(for b64_ntop with -lresolv)
436 LIBS="$OLD_LIBS -lresolv"
437 AC_LINK_IFELSE([AC_LANG_PROGRAM(
439 #include <sys/types.h>
440 #include <netinet/in.h>
444 b64_ntop(NULL, 0, NULL, 0);
449 AC_MSG_RESULT($found_b64_ntop)
451 if test "x$found_b64_ntop" = xno; then
452 AC_MSG_CHECKING(for b64_ntop with -lnetwork)
453 LIBS="$OLD_LIBS -lnetwork"
454 AC_LINK_IFELSE([AC_LANG_PROGRAM(
456 #include <sys/types.h>
457 #include <netinet/in.h>
461 b64_ntop(NULL, 0, NULL, 0);
466 AC_MSG_RESULT($found_b64_ntop)
468 if test "x$found_b64_ntop" = xyes; then
469 AC_DEFINE(HAVE_B64_NTOP)
475 # Look for networking libraries.
476 AC_SEARCH_LIBS(inet_ntoa, nsl)
477 AC_SEARCH_LIBS(socket, socket)
478 AC_CHECK_LIB(xnet, socket)
480 # Check if using glibc and have malloc_trim(3). The glibc free(3) is pretty bad
481 # about returning memory to the kernel unless the application tells it when to
482 # with malloc_trim(3).
483 AC_MSG_CHECKING(if free doesn't work very well)
484 AC_LINK_IFELSE([AC_LANG_SOURCE(
497 found_malloc_trim=yes,
500 AC_MSG_RESULT($found_malloc_trim)
501 if test "x$found_malloc_trim" = xyes; then
502 AC_DEFINE(HAVE_MALLOC_TRIM)
505 # Check for CMSG_DATA. On some platforms like HP-UX this requires UNIX 95
506 # (_XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED) (see xopen_networking(7)). On
507 # others, UNIX 03 (_XOPEN_SOURCE 600, see standards(7) on Solaris).
509 AC_MSG_CHECKING(for CMSG_DATA)
513 #include <sys/socket.h>
521 AC_MSG_RESULT($found_cmsg_data)
522 if test "x$found_cmsg_data" = xno; then
523 AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE_EXTENDED)
527 #define _XOPEN_SOURCE 1
528 #define _XOPEN_SOURCE_EXTENDED 1
529 #include <sys/socket.h>
537 AC_MSG_RESULT($found_cmsg_data)
538 if test "x$found_cmsg_data" = xyes; then
539 XOPEN_DEFINES="-D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED"
542 if test "x$found_cmsg_data" = xno; then
543 AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE 600)
547 #define _XOPEN_SOURCE 600
548 #include <sys/socket.h>
556 AC_MSG_RESULT($found_cmsg_data)
557 if test "x$found_cmsg_data" = xyes; then
558 XOPEN_DEFINES="-D_XOPEN_SOURCE=600"
560 AC_MSG_ERROR("CMSG_DATA not found")
563 AC_SUBST(XOPEN_DEFINES)
565 # Look for err and friends in err.h.
566 AC_CHECK_FUNC(err, found_err_h=yes, found_err_h=no)
567 AC_CHECK_FUNC(errx, , found_err_h=no)
568 AC_CHECK_FUNC(warn, , found_err_h=no)
569 AC_CHECK_FUNC(warnx, , found_err_h=no)
570 if test "x$found_err_h" = xyes; then
571 AC_CHECK_HEADER(err.h, , found_err_h=no)
576 # Look for imsg_init in libutil.
577 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
578 if test "x$found_imsg_init" = xyes; then
582 AC_LIBOBJ(imsg-buffer)
585 # Look for daemon, compat/daemon.c used if missing. Solaris 10 has it in
586 # libresolv, but no declaration anywhere, so check for declaration as well as
588 AC_CHECK_FUNC(daemon, found_daemon=yes, found_daemon=no)
598 if test "x$found_daemon" = xyes; then
599 AC_DEFINE(HAVE_DAEMON)
604 # Look for stravis, compat/{vis,unvis}.c used if missing.
605 AC_CHECK_FUNC(stravis, found_stravis=yes, found_stravis=no)
606 if test "x$found_stravis" = xyes; then
607 AC_MSG_CHECKING(if strnvis is broken)
608 AC_EGREP_HEADER([strnvis\(char \*, const char \*, size_t, int\)],
612 if test "x$found_stravis" = xno; then
616 if test "x$found_stravis" = xyes; then
627 if test "x$found_stravis" = xyes; then
634 # Look for fdforkpty and forkpty in libutil.
635 AC_SEARCH_LIBS(fdforkpty, util, found_fdforkpty=yes, found_fdforkpty=no)
636 if test "x$found_fdforkpty" = xyes; then
637 AC_DEFINE(HAVE_FDFORKPTY)
641 AC_SEARCH_LIBS(forkpty, util, found_forkpty=yes, found_forkpty=no)
642 if test "x$found_forkpty" = xyes; then
643 AC_DEFINE(HAVE_FORKPTY)
645 AM_CONDITIONAL(NEED_FORKPTY, test "x$found_forkpty" = xno)
647 # Look for kinfo_getfile in libutil.
648 AC_SEARCH_LIBS(kinfo_getfile, [util util-freebsd])
650 # Look for a suitable queue.h.
655 [#include <sys/queue.h>]
661 [#include <sys/queue.h>]
667 [#include <sys/queue.h>]
669 if test "x$found_queue_h" = xyes; then
670 AC_DEFINE(HAVE_QUEUE_H)
673 # Look for __progname.
674 AC_MSG_CHECKING(for __progname)
675 AC_LINK_IFELSE([AC_LANG_SOURCE(
679 extern char *__progname;
681 const char *cp = __progname;
686 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
690 # Look for program_invocation_short_name.
691 AC_MSG_CHECKING(for program_invocation_short_name)
692 AC_LINK_IFELSE([AC_LANG_SOURCE(
698 const char *cp = program_invocation_short_name;
703 [AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME) AC_MSG_RESULT(yes)],
707 # Look for prctl(PR_SET_NAME).
710 AC_DEFINE(HAVE_PR_SET_NAME),
712 [#include <sys/prctl.h>]
715 # Look for setsockopt(SO_PEERCRED).
718 AC_DEFINE(HAVE_SO_PEERCRED),
720 [#include <sys/socket.h>]
723 # Look for fcntl(F_CLOSEM).
726 AC_DEFINE(HAVE_FCNTL_CLOSEM),
732 AC_MSG_CHECKING(for /proc/\$\$)
733 if test -d /proc/$$; then
734 AC_DEFINE(HAVE_PROC_PID)
740 # Try to figure out what the best value for TERM might be.
741 if test "x$DEFAULT_TERM" = x; then
743 AC_MSG_CHECKING(TERM)
744 AC_RUN_IFELSE([AC_LANG_SOURCE(
748 #if defined(HAVE_CURSES_H)
750 #elif defined(HAVE_NCURSES_H)
755 if (setupterm("screen-256color", -1, NULL) != OK)
760 [DEFAULT_TERM=screen-256color],
762 [DEFAULT_TERM=screen]
764 AC_RUN_IFELSE([AC_LANG_SOURCE(
768 #if defined(HAVE_CURSES_H)
770 #elif defined(HAVE_NCURSES_H)
775 if (setupterm("tmux", -1, NULL) != OK)
782 [DEFAULT_TERM=screen]
784 AC_RUN_IFELSE([AC_LANG_SOURCE(
788 #if defined(HAVE_CURSES_H)
790 #elif defined(HAVE_NCURSES_H)
795 if (setupterm("tmux-256color", -1, NULL) != OK)
800 [DEFAULT_TERM=tmux-256color],
802 [DEFAULT_TERM=screen]
804 AC_MSG_RESULT($DEFAULT_TERM)
806 AC_SUBST(DEFAULT_TERM)
808 # Man page defaults to mdoc.
812 # Figure out the platform.
813 AC_MSG_CHECKING(platform)
820 AC_MSG_RESULT(darwin)
823 # macOS uses __dead2 instead of __dead, like FreeBSD. But it defines
824 # __dead away so it needs to be removed before we can replace it.
826 AC_DEFINE(BROKEN___DEAD)
828 # macOS CMSG_FIRSTHDR is broken, so redefine it with a working one.
829 # daemon works but has some stupid side effects, so use our internal
830 # version which has a workaround.
832 AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
834 AC_LIBOBJ(daemon-darwin)
836 # macOS wcwidth(3) is bad, so complain and suggest using utf8proc
839 if test "x$enable_utf8proc" = x; then
841 AC_MSG_NOTICE([ macOS library support for Unicode is very poor,])
842 AC_MSG_NOTICE([ particularly for complex codepoints like emojis;])
843 AC_MSG_NOTICE([ to use these correctly, configuring with])
844 AC_MSG_NOTICE([ --enable-utf8proc is recommended. To build])
845 AC_MSG_NOTICE([ without anyway, use --disable-utf8proc])
847 AC_MSG_ERROR([must give --enable-utf8proc or --disable-utf8proc])
851 AC_MSG_RESULT(dragonfly)
859 AC_MSG_RESULT(freebsd)
863 AC_MSG_RESULT(netbsd)
867 AC_MSG_RESULT(openbsd)
877 case `/usr/bin/nroff --version 2>&1` in
879 # Solaris 11.4 and later use GNU groff.
883 # Solaris 2.0 to 11.3 use AT&T nroff.
893 AC_MSG_RESULT(cygwin)
901 AC_MSG_RESULT(unknown)
906 AM_CONDITIONAL(IS_AIX, test "x$PLATFORM" = xaix)
907 AM_CONDITIONAL(IS_DARWIN, test "x$PLATFORM" = xdarwin)
908 AM_CONDITIONAL(IS_DRAGONFLY, test "x$PLATFORM" = xdragonfly)
909 AM_CONDITIONAL(IS_LINUX, test "x$PLATFORM" = xlinux)
910 AM_CONDITIONAL(IS_FREEBSD, test "x$PLATFORM" = xfreebsd)
911 AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd)
912 AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd)
913 AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos)
914 AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
915 AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
916 AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
918 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
920 AC_SUBST(AM_CPPFLAGS)
921 CPPFLAGS="$SAVED_CPPFLAGS"
923 CFLAGS="$SAVED_CFLAGS"
925 LDFLAGS="$SAVED_LDFLAGS"
927 # autoconf should create a Makefile.
928 AC_CONFIG_FILES(Makefile)