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 b64_ntop. If we have b64_ntop, we assume b64_pton as well.
394 AC_MSG_CHECKING(for b64_ntop)
395 AC_LINK_IFELSE([AC_LANG_PROGRAM(
397 #include <sys/types.h>
398 #include <netinet/in.h>
402 b64_ntop(NULL, 0, NULL, 0);
407 AC_MSG_RESULT($found_b64_ntop)
409 if test "x$found_b64_ntop" = xno; then
410 AC_MSG_CHECKING(for b64_ntop with -lresolv)
411 LIBS="$OLD_LIBS -lresolv"
412 AC_LINK_IFELSE([AC_LANG_PROGRAM(
414 #include <sys/types.h>
415 #include <netinet/in.h>
419 b64_ntop(NULL, 0, NULL, 0);
424 AC_MSG_RESULT($found_b64_ntop)
426 if test "x$found_b64_ntop" = xno; then
427 AC_MSG_CHECKING(for b64_ntop with -lnetwork)
428 LIBS="$OLD_LIBS -lnetwork"
429 AC_LINK_IFELSE([AC_LANG_PROGRAM(
431 #include <sys/types.h>
432 #include <netinet/in.h>
436 b64_ntop(NULL, 0, NULL, 0);
441 AC_MSG_RESULT($found_b64_ntop)
443 if test "x$found_b64_ntop" = xyes; then
444 AC_DEFINE(HAVE_B64_NTOP)
450 # Look for networking libraries.
451 AC_SEARCH_LIBS(inet_ntoa, nsl)
452 AC_SEARCH_LIBS(socket, socket)
453 AC_CHECK_LIB(xnet, socket)
455 # Check if using glibc and have malloc_trim(3). The glibc free(3) is pretty bad
456 # about returning memory to the kernel unless the application tells it when to
457 # with malloc_trim(3).
458 AC_MSG_CHECKING(if free doesn't work very well)
459 AC_LINK_IFELSE([AC_LANG_SOURCE(
472 found_malloc_trim=yes,
475 AC_MSG_RESULT($found_malloc_trim)
476 if test "x$found_malloc_trim" = xyes; then
477 AC_DEFINE(HAVE_MALLOC_TRIM)
480 # Check for CMSG_DATA. On some platforms like HP-UX this requires UNIX 95
481 # (_XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED) (see xopen_networking(7)). On
482 # others, UNIX 03 (_XOPEN_SOURCE 600, see standards(7) on Solaris).
484 AC_MSG_CHECKING(for CMSG_DATA)
488 #include <sys/socket.h>
496 AC_MSG_RESULT($found_cmsg_data)
497 if test "x$found_cmsg_data" = xno; then
498 AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE_EXTENDED)
502 #define _XOPEN_SOURCE 1
503 #define _XOPEN_SOURCE_EXTENDED 1
504 #include <sys/socket.h>
512 AC_MSG_RESULT($found_cmsg_data)
513 if test "x$found_cmsg_data" = xyes; then
514 XOPEN_DEFINES="-D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED"
517 if test "x$found_cmsg_data" = xno; then
518 AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE 600)
522 #define _XOPEN_SOURCE 600
523 #include <sys/socket.h>
531 AC_MSG_RESULT($found_cmsg_data)
532 if test "x$found_cmsg_data" = xyes; then
533 XOPEN_DEFINES="-D_XOPEN_SOURCE=600"
535 AC_MSG_ERROR("CMSG_DATA not found")
538 AC_SUBST(XOPEN_DEFINES)
540 # Look for err and friends in err.h.
541 AC_CHECK_FUNC(err, found_err_h=yes, found_err_h=no)
542 AC_CHECK_FUNC(errx, , found_err_h=no)
543 AC_CHECK_FUNC(warn, , found_err_h=no)
544 AC_CHECK_FUNC(warnx, , found_err_h=no)
545 if test "x$found_err_h" = xyes; then
546 AC_CHECK_HEADER(err.h, , found_err_h=no)
551 # Look for imsg_init in libutil.
552 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
553 if test "x$found_imsg_init" = xyes; then
557 AC_LIBOBJ(imsg-buffer)
560 # Look for daemon, compat/daemon.c used if missing. Solaris 10 has it in
561 # libresolv, but no declaration anywhere, so check for declaration as well as
563 AC_CHECK_FUNC(daemon, found_daemon=yes, found_daemon=no)
573 if test "x$found_daemon" = xyes; then
574 AC_DEFINE(HAVE_DAEMON)
579 # Look for stravis, compat/{vis,unvis}.c used if missing.
580 AC_CHECK_FUNC(stravis, found_stravis=yes, found_stravis=no)
581 if test "x$found_stravis" = xyes; then
582 AC_MSG_CHECKING(if strnvis is broken)
583 AC_EGREP_HEADER([strnvis\(char \*, const char \*, size_t, int\)],
587 if test "x$found_stravis" = xno; then
591 if test "x$found_stravis" = xyes; then
602 if test "x$found_stravis" = xyes; then
609 # Look for fdforkpty and forkpty in libutil.
610 AC_SEARCH_LIBS(fdforkpty, util, found_fdforkpty=yes, found_fdforkpty=no)
611 if test "x$found_fdforkpty" = xyes; then
612 AC_DEFINE(HAVE_FDFORKPTY)
616 AC_SEARCH_LIBS(forkpty, util, found_forkpty=yes, found_forkpty=no)
617 if test "x$found_forkpty" = xyes; then
618 AC_DEFINE(HAVE_FORKPTY)
620 AM_CONDITIONAL(NEED_FORKPTY, test "x$found_forkpty" = xno)
622 # Look for kinfo_getfile in libutil.
623 AC_SEARCH_LIBS(kinfo_getfile, [util util-freebsd])
625 # Look for a suitable queue.h.
630 [#include <sys/queue.h>]
636 [#include <sys/queue.h>]
642 [#include <sys/queue.h>]
644 if test "x$found_queue_h" = xyes; then
645 AC_DEFINE(HAVE_QUEUE_H)
648 # Look for __progname.
649 AC_MSG_CHECKING(for __progname)
650 AC_LINK_IFELSE([AC_LANG_SOURCE(
654 extern char *__progname;
656 const char *cp = __progname;
661 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
665 # Look for program_invocation_short_name.
666 AC_MSG_CHECKING(for program_invocation_short_name)
667 AC_LINK_IFELSE([AC_LANG_SOURCE(
673 const char *cp = program_invocation_short_name;
678 [AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME) AC_MSG_RESULT(yes)],
682 # Look for prctl(PR_SET_NAME).
685 AC_DEFINE(HAVE_PR_SET_NAME),
687 [#include <sys/prctl.h>]
690 # Look for setsockopt(SO_PEERCRED).
693 AC_DEFINE(HAVE_SO_PEERCRED),
695 [#include <sys/socket.h>]
698 # Look for fcntl(F_CLOSEM).
701 AC_DEFINE(HAVE_FCNTL_CLOSEM),
707 AC_MSG_CHECKING(for /proc/\$\$)
708 if test -d /proc/$$; then
709 AC_DEFINE(HAVE_PROC_PID)
715 # Try to figure out what the best value for TERM might be.
716 if test "x$DEFAULT_TERM" = x; then
718 AC_MSG_CHECKING(TERM)
719 AC_RUN_IFELSE([AC_LANG_SOURCE(
723 #if defined(HAVE_CURSES_H)
725 #elif defined(HAVE_NCURSES_H)
730 if (setupterm("screen-256color", -1, NULL) != OK)
735 [DEFAULT_TERM=screen-256color],
737 [DEFAULT_TERM=screen]
739 AC_RUN_IFELSE([AC_LANG_SOURCE(
743 #if defined(HAVE_CURSES_H)
745 #elif defined(HAVE_NCURSES_H)
750 if (setupterm("tmux", -1, NULL) != OK)
757 [DEFAULT_TERM=screen]
759 AC_RUN_IFELSE([AC_LANG_SOURCE(
763 #if defined(HAVE_CURSES_H)
765 #elif defined(HAVE_NCURSES_H)
770 if (setupterm("tmux-256color", -1, NULL) != OK)
775 [DEFAULT_TERM=tmux-256color],
777 [DEFAULT_TERM=screen]
779 AC_MSG_RESULT($DEFAULT_TERM)
781 AC_SUBST(DEFAULT_TERM)
783 # Man page defaults to mdoc.
787 # Figure out the platform.
788 AC_MSG_CHECKING(platform)
795 AC_MSG_RESULT(darwin)
798 # macOS uses __dead2 instead of __dead, like FreeBSD. But it defines
799 # __dead away so it needs to be removed before we can replace it.
801 AC_DEFINE(BROKEN___DEAD)
803 # macOS CMSG_FIRSTHDR is broken, so redefine it with a working one.
804 # daemon works but has some stupid side effects, so use our internal
805 # version which has a workaround.
807 AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
809 AC_LIBOBJ(daemon-darwin)
811 # macOS wcwidth(3) is bad, so complain and suggest using utf8proc
814 if test "x$enable_utf8proc" = x; then
816 AC_MSG_NOTICE([ macOS library support for Unicode is very poor,])
817 AC_MSG_NOTICE([ particularly for complex codepoints like emojis;])
818 AC_MSG_NOTICE([ to use these correctly, configuring with])
819 AC_MSG_NOTICE([ --enable-utf8proc is recommended. To build])
820 AC_MSG_NOTICE([ without anyway, use --disable-utf8proc])
822 AC_MSG_ERROR([must give --enable-utf8proc or --disable-utf8proc])
826 AC_MSG_RESULT(dragonfly)
834 AC_MSG_RESULT(freebsd)
838 AC_MSG_RESULT(netbsd)
842 AC_MSG_RESULT(openbsd)
852 case `/usr/bin/nroff --version 2>&1` in
854 # Solaris 11.4 and later use GNU groff.
858 # Solaris 2.0 to 11.3 use AT&T nroff.
868 AC_MSG_RESULT(cygwin)
876 AC_MSG_RESULT(unknown)
881 AM_CONDITIONAL(IS_AIX, test "x$PLATFORM" = xaix)
882 AM_CONDITIONAL(IS_DARWIN, test "x$PLATFORM" = xdarwin)
883 AM_CONDITIONAL(IS_DRAGONFLY, test "x$PLATFORM" = xdragonfly)
884 AM_CONDITIONAL(IS_LINUX, test "x$PLATFORM" = xlinux)
885 AM_CONDITIONAL(IS_FREEBSD, test "x$PLATFORM" = xfreebsd)
886 AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd)
887 AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd)
888 AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos)
889 AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
890 AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
891 AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
893 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
895 AC_SUBST(AM_CPPFLAGS)
896 CPPFLAGS="$SAVED_CPPFLAGS"
898 CFLAGS="$SAVED_CFLAGS"
900 LDFLAGS="$SAVED_LDFLAGS"
902 # autoconf should create a Makefile.
903 AC_CONFIG_FILES(Makefile)