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.
134 # Look for sys_signame.
135 AC_SEARCH_LIBS(sys_signame, , AC_DEFINE(HAVE_SYS_SIGNAME))
138 AC_CHECK_LIB(m, fmod)
140 # Look for library needed for flock.
141 AC_SEARCH_LIBS(flock, bsd)
143 # Check for functions that are replaced or omitted.
152 # Check for functions with a compatibility implementation.
176 # Check if strtonum works.
177 AC_MSG_CHECKING([for working strtonum])
178 AC_RUN_IFELSE([AC_LANG_PROGRAM(
179 [#include <stdlib.h>],
180 [return (strtonum("0", 0, 1, NULL) == 0 ? 0 : 1);]
182 [AC_DEFINE(HAVE_STRTONUM) AC_MSG_RESULT(yes)],
183 [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)],
184 [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)]
187 # Clang sanitizers wrap reallocarray even if it isn't available on the target
188 # system. When compiled it always returns NULL and crashes the program. To
189 # detect this we need a more complicated test.
190 AC_MSG_CHECKING([for working reallocarray])
191 AC_RUN_IFELSE([AC_LANG_PROGRAM(
192 [#include <stdlib.h>],
193 [return (reallocarray(NULL, 1, 1) == NULL);]
196 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
197 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
199 AC_MSG_CHECKING([for working recallocarray])
200 AC_RUN_IFELSE([AC_LANG_PROGRAM(
201 [#include <stdlib.h>],
202 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
205 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
206 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
209 # Look for clock_gettime. Must come before event_init.
210 AC_SEARCH_LIBS(clock_gettime, rt)
212 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
213 # musl does not set optarg to NULL for flags without arguments (although it is
214 # not required to, but it is helpful) 3) there are probably other weird
218 # Look for libevent. Try libevent_core or libevent with pkg-config first then
219 # look for the library.
222 [libevent_core >= 2],
224 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
225 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
226 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
231 if test x$found_libevent = xno; then
236 AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
237 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
238 LIBS="$LIBEVENT_LIBS $LIBS"
244 if test x$found_libevent = xno; then
247 [event_core event event-1.4],
254 AC_DEFINE(HAVE_EVENT2_EVENT_H),
258 AC_DEFINE(HAVE_EVENT_H),
263 if test "x$found_libevent" = xno; then
264 AC_MSG_ERROR("libevent not found")
267 # Look for ncurses or curses. Try pkg-config first then directly for the
273 AM_CPPFLAGS="$LIBTINFO_CFLAGS $AM_CPPFLAGS"
274 CPPFLAGS="$LIBTINFO_CFLAGS $SAVED_CPPFLAGS"
275 LIBS="$LIBTINFO_LIBS $LIBS"
280 if test "x$found_ncurses" = xno; then
285 AM_CPPFLAGS="$LIBNCURSES_CFLAGS $AM_CPPFLAGS"
286 CPPFLAGS="$LIBNCURSES_CFLAGS $SAVED_CPPFLAGS"
287 LIBS="$LIBNCURSES_LIBS $LIBS"
293 if test "x$found_ncurses" = xno; then
298 AM_CPPFLAGS="$LIBNCURSESW_CFLAGS $AM_CPPFLAGS"
299 CPPFLAGS="$LIBNCURSESW_CFLAGS $SAVED_CPPFLAGS"
300 LIBS="$LIBNCURSESW_LIBS $LIBS"
306 if test "x$found_ncurses" = xno; then
309 [tinfo ncurses ncursesw],
313 if test "x$found_ncurses" = xyes; then
316 LIBS="$LIBS -lncurses",
321 if test "x$found_ncurses" = xyes; then
322 CPPFLAGS="$CPPFLAGS -DHAVE_NCURSES_H"
323 AC_DEFINE(HAVE_NCURSES_H)
336 if test "x$found_curses" = xyes; then
337 LIBS="$LIBS -lcurses"
338 CPPFLAGS="$CPPFLAGS -DHAVE_CURSES_H"
339 AC_DEFINE(HAVE_CURSES_H)
341 AC_MSG_ERROR("curses not found")
348 AS_HELP_STRING(--enable-utempter, use utempter if it is installed)
350 if test "x$enable_utempter" = xyes; then
351 AC_CHECK_HEADER(utempter.h, enable_utempter=yes, enable_utempter=no)
352 if test "x$enable_utempter" = xyes; then
360 if test "x$enable_utempter" = xyes; then
361 AC_DEFINE(HAVE_UTEMPTER)
363 AC_MSG_ERROR("utempter not found")
370 AS_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
372 if test "x$enable_utf8proc" = xyes; then
373 AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no)
374 if test "x$enable_utf8proc" = xyes; then
382 if test "x$enable_utf8proc" = xyes; then
383 AC_DEFINE(HAVE_UTF8PROC)
385 AC_MSG_ERROR("utf8proc not found")
388 AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes])
390 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
391 AC_MSG_CHECKING(for b64_ntop)
392 AC_LINK_IFELSE([AC_LANG_PROGRAM(
394 #include <sys/types.h>
395 #include <netinet/in.h>
399 b64_ntop(NULL, 0, NULL, 0);
404 AC_MSG_RESULT($found_b64_ntop)
406 if test "x$found_b64_ntop" = xno; then
407 AC_MSG_CHECKING(for b64_ntop with -lresolv)
408 LIBS="$OLD_LIBS -lresolv"
409 AC_LINK_IFELSE([AC_LANG_PROGRAM(
411 #include <sys/types.h>
412 #include <netinet/in.h>
416 b64_ntop(NULL, 0, NULL, 0);
421 AC_MSG_RESULT($found_b64_ntop)
423 if test "x$found_b64_ntop" = xno; then
424 AC_MSG_CHECKING(for b64_ntop with -lnetwork)
425 LIBS="$OLD_LIBS -lnetwork"
426 AC_LINK_IFELSE([AC_LANG_PROGRAM(
428 #include <sys/types.h>
429 #include <netinet/in.h>
433 b64_ntop(NULL, 0, NULL, 0);
438 AC_MSG_RESULT($found_b64_ntop)
440 if test "x$found_b64_ntop" = xyes; then
441 AC_DEFINE(HAVE_B64_NTOP)
447 # Look for networking libraries.
448 AC_SEARCH_LIBS(inet_ntoa, nsl)
449 AC_SEARCH_LIBS(socket, socket)
450 AC_CHECK_LIB(xnet, socket)
452 # Check if using glibc and have malloc_trim(3). The glibc free(3) is pretty bad
453 # about returning memory to the kernel unless the application tells it when to
454 # with malloc_trim(3).
455 AC_MSG_CHECKING(if free doesn't work very well)
456 AC_LINK_IFELSE([AC_LANG_SOURCE(
469 found_malloc_trim=yes,
472 AC_MSG_RESULT($found_malloc_trim)
473 if test "x$found_malloc_trim" = xyes; then
474 AC_DEFINE(HAVE_MALLOC_TRIM)
477 # Check for CMSG_DATA. On some platforms like HP-UX this requires UNIX 95
478 # (_XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED) (see xopen_networking(7)). On
479 # others, UNIX 03 (_XOPEN_SOURCE 600, see standards(7) on Solaris).
481 AC_MSG_CHECKING(for CMSG_DATA)
485 #include <sys/socket.h>
493 AC_MSG_RESULT($found_cmsg_data)
494 if test "x$found_cmsg_data" = xno; then
495 AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE_EXTENDED)
499 #define _XOPEN_SOURCE 1
500 #define _XOPEN_SOURCE_EXTENDED 1
501 #include <sys/socket.h>
509 AC_MSG_RESULT($found_cmsg_data)
510 if test "x$found_cmsg_data" = xyes; then
511 XOPEN_DEFINES="-D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED"
514 if test "x$found_cmsg_data" = xno; then
515 AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE 600)
519 #define _XOPEN_SOURCE 600
520 #include <sys/socket.h>
528 AC_MSG_RESULT($found_cmsg_data)
529 if test "x$found_cmsg_data" = xyes; then
530 XOPEN_DEFINES="-D_XOPEN_SOURCE=600"
532 AC_MSG_ERROR("CMSG_DATA not found")
535 AC_SUBST(XOPEN_DEFINES)
537 # Look for err and friends in err.h.
538 AC_CHECK_FUNC(err, found_err_h=yes, found_err_h=no)
539 AC_CHECK_FUNC(errx, , found_err_h=no)
540 AC_CHECK_FUNC(warn, , found_err_h=no)
541 AC_CHECK_FUNC(warnx, , found_err_h=no)
542 if test "x$found_err_h" = xyes; then
543 AC_CHECK_HEADER(err.h, , found_err_h=no)
548 # Look for imsg_init in libutil.
549 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
550 if test "x$found_imsg_init" = xyes; then
554 AC_LIBOBJ(imsg-buffer)
557 # Look for daemon, compat/daemon.c used if missing. Solaris 10 has it in
558 # libresolv, but no declaration anywhere, so check for declaration as well as
560 AC_CHECK_FUNC(daemon, found_daemon=yes, found_daemon=no)
570 if test "x$found_daemon" = xyes; then
571 AC_DEFINE(HAVE_DAEMON)
576 # Look for stravis, compat/{vis,unvis}.c used if missing.
577 AC_CHECK_FUNC(stravis, found_stravis=yes, found_stravis=no)
578 if test "x$found_stravis" = xyes; then
579 AC_MSG_CHECKING(if strnvis is broken)
580 AC_EGREP_HEADER([strnvis\(char \*, const char \*, size_t, int\)],
584 if test "x$found_stravis" = xno; then
588 if test "x$found_stravis" = xyes; then
599 if test "x$found_stravis" = xyes; then
606 # Look for fdforkpty and forkpty in libutil.
607 AC_SEARCH_LIBS(fdforkpty, util, found_fdforkpty=yes, found_fdforkpty=no)
608 if test "x$found_fdforkpty" = xyes; then
609 AC_DEFINE(HAVE_FDFORKPTY)
613 AC_SEARCH_LIBS(forkpty, util, found_forkpty=yes, found_forkpty=no)
614 if test "x$found_forkpty" = xyes; then
615 AC_DEFINE(HAVE_FORKPTY)
617 AM_CONDITIONAL(NEED_FORKPTY, test "x$found_forkpty" = xno)
619 # Look for kinfo_getfile in libutil.
620 AC_SEARCH_LIBS(kinfo_getfile, [util util-freebsd])
622 # Look for a suitable queue.h.
627 [#include <sys/queue.h>]
633 [#include <sys/queue.h>]
639 [#include <sys/queue.h>]
641 if test "x$found_queue_h" = xyes; then
642 AC_DEFINE(HAVE_QUEUE_H)
645 # Look for __progname.
646 AC_MSG_CHECKING(for __progname)
647 AC_LINK_IFELSE([AC_LANG_SOURCE(
651 extern char *__progname;
653 const char *cp = __progname;
658 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
662 # Look for program_invocation_short_name.
663 AC_MSG_CHECKING(for program_invocation_short_name)
664 AC_LINK_IFELSE([AC_LANG_SOURCE(
670 const char *cp = program_invocation_short_name;
675 [AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME) AC_MSG_RESULT(yes)],
679 # Look for prctl(PR_SET_NAME).
682 AC_DEFINE(HAVE_PR_SET_NAME),
684 [#include <sys/prctl.h>]
687 # Look for fcntl(F_CLOSEM).
690 AC_DEFINE(HAVE_FCNTL_CLOSEM),
696 AC_MSG_CHECKING(for /proc/\$\$)
697 if test -d /proc/$$; then
698 AC_DEFINE(HAVE_PROC_PID)
704 # Try to figure out what the best value for TERM might be.
705 if test "x$DEFAULT_TERM" = x; then
707 AC_MSG_CHECKING(TERM)
708 AC_RUN_IFELSE([AC_LANG_SOURCE(
712 #if defined(HAVE_CURSES_H)
714 #elif defined(HAVE_NCURSES_H)
719 if (setupterm("screen-256color", -1, NULL) != OK)
724 [DEFAULT_TERM=screen-256color],
726 [DEFAULT_TERM=screen]
728 AC_RUN_IFELSE([AC_LANG_SOURCE(
732 #if defined(HAVE_CURSES_H)
734 #elif defined(HAVE_NCURSES_H)
739 if (setupterm("tmux", -1, NULL) != OK)
746 [DEFAULT_TERM=screen]
748 AC_RUN_IFELSE([AC_LANG_SOURCE(
752 #if defined(HAVE_CURSES_H)
754 #elif defined(HAVE_NCURSES_H)
759 if (setupterm("tmux-256color", -1, NULL) != OK)
764 [DEFAULT_TERM=tmux-256color],
766 [DEFAULT_TERM=screen]
768 AC_MSG_RESULT($DEFAULT_TERM)
770 AC_SUBST(DEFAULT_TERM)
772 # Man page defaults to mdoc.
776 # Figure out the platform.
777 AC_MSG_CHECKING(platform)
784 AC_MSG_RESULT(darwin)
787 # macOS uses __dead2 instead of __dead, like FreeBSD. But it defines
788 # __dead away so it needs to be removed before we can replace it.
790 AC_DEFINE(BROKEN___DEAD)
792 # macOS CMSG_FIRSTHDR is broken, so redefine it with a working one.
793 # daemon works but has some stupid side effects, so use our internal
794 # version which has a workaround.
796 AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
798 AC_LIBOBJ(daemon-darwin)
800 # macOS wcwidth(3) is bad, so complain and suggest using utf8proc
803 if test "x$enable_utf8proc" = x; then
805 AC_MSG_NOTICE([ macOS library support for Unicode is very poor,])
806 AC_MSG_NOTICE([ particularly for complex codepoints like emojis;])
807 AC_MSG_NOTICE([ to use these correctly, configuring with])
808 AC_MSG_NOTICE([ --enable-utf8proc is recommended. To build])
809 AC_MSG_NOTICE([ without anyway, use --disable-utf8proc])
811 AC_MSG_ERROR([must give --enable-utf8proc or --disable-utf8proc])
815 AC_MSG_RESULT(dragonfly)
823 AC_MSG_RESULT(freebsd)
827 AC_MSG_RESULT(netbsd)
831 AC_MSG_RESULT(openbsd)
841 case `/usr/bin/nroff --version 2>&1` in
843 # Solaris 11.4 and later use GNU groff.
847 # Solaris 2.0 to 11.3 use AT&T nroff.
857 AC_MSG_RESULT(cygwin)
865 AC_MSG_RESULT(unknown)
870 AM_CONDITIONAL(IS_AIX, test "x$PLATFORM" = xaix)
871 AM_CONDITIONAL(IS_DARWIN, test "x$PLATFORM" = xdarwin)
872 AM_CONDITIONAL(IS_DRAGONFLY, test "x$PLATFORM" = xdragonfly)
873 AM_CONDITIONAL(IS_LINUX, test "x$PLATFORM" = xlinux)
874 AM_CONDITIONAL(IS_FREEBSD, test "x$PLATFORM" = xfreebsd)
875 AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd)
876 AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd)
877 AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos)
878 AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
879 AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
880 AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
882 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
884 AC_SUBST(AM_CPPFLAGS)
885 CPPFLAGS="$SAVED_CPPFLAGS"
887 CFLAGS="$SAVED_CFLAGS"
889 LDFLAGS="$SAVED_LDFLAGS"
891 # autoconf should create a Makefile.
892 AC_CONFIG_FILES(Makefile)