Merge branch 'obsd-master'
[tmux.git] / configure.ac
blob956a182d13494769b93d481a0e9e1f83c42a1d25
1 # configure.ac
3 AC_INIT([tmux], next-3.5)
4 AC_PREREQ([2.60])
6 AC_CONFIG_AUX_DIR(etc)
7 AC_CONFIG_LIBOBJ_DIR(compat)
8 AM_INIT_AUTOMAKE([foreign subdir-objects])
10 AC_CANONICAL_HOST
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
14 # empty default.
15 : ${CFLAGS=""}
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?
25 AC_ARG_ENABLE(
26         fuzzing,
27         AS_HELP_STRING(--enable-fuzzing, build fuzzers)
29 AC_ARG_VAR(
30         FUZZING_LIBS,
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.
45 AC_PROG_CC
46 AM_PROG_CC_C_O
47 m4_version_prereq(2.70, [AC_PROG_CC], [AC_PROG_CC_C99])
48 AC_PROG_CPP
49 AC_PROG_EGREP
50 AC_PROG_INSTALL
51 AC_PROG_YACC
52 PKG_PROG_PKG_CONFIG
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
60 AC_ARG_ENABLE(
61         debug,
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?
67 AC_ARG_ENABLE(
68         static,
69         AS_HELP_STRING(--enable-static, create a static build)
71 if test "x$enable_static" = xyes; then
72         case "$host_os" in
73                 *darwin*)
74                         AC_MSG_ERROR([static linking is not supported on macOS])
75                         ;;
76         esac
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.
83 AC_ARG_WITH(
84         TERM,
85         AS_HELP_STRING(--with-TERM, set default TERM),
86         [DEFAULT_TERM=$withval],
87         [DEFAULT_TERM=]
89 case "x$DEFAULT_TERM" in
90         xscreen*|xtmux*|x)
91         ;;
92         *)
93                 AC_MSG_ERROR("unsuitable TERM (must be screen* or tmux*)")
94         ;;
95 esac
97 # Do we need fuzzers?
98 AM_CONDITIONAL(NEED_FUZZING, test "x$enable_fuzzing" = xyes)
100 # Is this gcc?
101 AM_CONDITIONAL(IS_GCC, test "x$GCC" = xyes -a "x$enable_fuzzing" != xyes)
103 # Is this Sun CC?
104 AC_EGREP_CPP(
105         yes,
106         [
107                 #ifdef __SUNPRO_C
108                 yes
109                 #endif
110         ],
111         found_suncc=yes,
112         found_suncc=no
114 AM_CONDITIONAL(IS_SUNCC, test "x$found_suncc" = xyes)
116 # Check for various headers. Alternatives included from compat.h.
117 AC_CHECK_HEADERS([ \
118         bitstring.h \
119         dirent.h \
120         fcntl.h \
121         inttypes.h \
122         libproc.h \
123         libutil.h \
124         ndir.h \
125         paths.h \
126         pty.h \
127         stdint.h \
128         sys/dir.h \
129         sys/ndir.h \
130         sys/tree.h \
131         ucred.h \
132         util.h \
135 # Look for sys_signame.
136 AC_SEARCH_LIBS(sys_signame, , AC_DEFINE(HAVE_SYS_SIGNAME))
138 # Look for fmod.
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.
145 AC_CHECK_FUNCS([ \
146         dirfd \
147         flock \
148         prctl \
149         proc_pidinfo \
150         getpeerucred \
151         sysconf
154 # Check for functions with a compatibility implementation.
155 AC_REPLACE_FUNCS([ \
156         asprintf \
157         cfmakeraw \
158         clock_gettime \
159         closefrom \
160         explicit_bzero \
161         fgetln \
162         freezero \
163         getdtablecount \
164         getdtablesize \
165         getpeereid \
166         getline \
167         getprogname \
168         htonll \
169         memmem \
170         ntohll \
171         setenv \
172         setproctitle \
173         strcasestr \
174         strlcat \
175         strlcpy \
176         strndup \
177         strsep \
179 AC_FUNC_STRNLEN
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);]
186         )],
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);]
199         )],
200         AC_MSG_RESULT(yes),
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);]
208         )],
209         AC_MSG_RESULT(yes),
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
220 # implementations.
221 AC_LIBOBJ(getopt)
223 # Look for libevent. Try libevent_core or libevent with pkg-config first then
224 # look for the library.
225 PKG_CHECK_MODULES(
226         LIBEVENT_CORE,
227         [libevent_core >= 2],
228         [
229                 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
230                 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
231                 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
232                 found_libevent=yes
233         ],
234         found_libevent=no
236 if test x$found_libevent = xno; then
237         PKG_CHECK_MODULES(
238                 LIBEVENT,
239                 [libevent >= 2],
240                 [
241                         AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
242                         CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
243                         LIBS="$LIBEVENT_LIBS $LIBS"
244                         found_libevent=yes
245                 ],
246                 found_libevent=no
247         )
249 if test x$found_libevent = xno; then
250         AC_SEARCH_LIBS(
251                 event_init,
252                 [event_core event event-1.4],
253                 found_libevent=yes,
254                 found_libevent=no
255         )
257 AC_CHECK_HEADER(
258         event2/event.h,
259         AC_DEFINE(HAVE_EVENT2_EVENT_H),
260         [
261                 AC_CHECK_HEADER(
262                         event.h,
263                         AC_DEFINE(HAVE_EVENT_H),
264                         found_libevent=no
265                 )
266         ]
268 if test "x$found_libevent" = xno; then
269         AC_MSG_ERROR("libevent not found")
272 # Look for yacc.
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
279 # library.
280 PKG_CHECK_MODULES(
281         LIBTINFO,
282         tinfo,
283         [
284                 AM_CPPFLAGS="$LIBTINFO_CFLAGS $AM_CPPFLAGS"
285                 CPPFLAGS="$LIBTINFO_CFLAGS $SAVED_CPPFLAGS"
286                 LIBS="$LIBTINFO_LIBS $LIBS"
287                 found_ncurses=yes
288         ],
289         found_ncurses=no
291 if test "x$found_ncurses" = xno; then
292         PKG_CHECK_MODULES(
293                 LIBNCURSES,
294                 ncurses,
295                 [
296                         AM_CPPFLAGS="$LIBNCURSES_CFLAGS $AM_CPPFLAGS"
297                         CPPFLAGS="$LIBNCURSES_CFLAGS $SAVED_CPPFLAGS"
298                         LIBS="$LIBNCURSES_LIBS $LIBS"
299                         found_ncurses=yes
300                 ],
301                 found_ncurses=no
302         )
304 if test "x$found_ncurses" = xno; then
305         PKG_CHECK_MODULES(
306                 LIBNCURSESW,
307                 ncursesw,
308                 [
309                         AM_CPPFLAGS="$LIBNCURSESW_CFLAGS $AM_CPPFLAGS"
310                         CPPFLAGS="$LIBNCURSESW_CFLAGS $SAVED_CPPFLAGS"
311                         LIBS="$LIBNCURSESW_LIBS $LIBS"
312                         found_ncurses=yes
313                 ],
314                 found_ncurses=no
315         )
317 if test "x$found_ncurses" = xno; then
318         AC_SEARCH_LIBS(
319                 setupterm,
320                 [tinfo terminfo ncurses ncursesw],
321                 found_ncurses=yes,
322                 found_ncurses=no
323         )
324         if test "x$found_ncurses" = xyes; then
325                 AC_CHECK_HEADER(
326                         ncurses.h,
327                         LIBS="$LIBS -lncurses",
328                         found_ncurses=no
329                 )
330         fi
332 if test "x$found_ncurses" = xyes; then
333         CPPFLAGS="$CPPFLAGS -DHAVE_NCURSES_H"
334         AC_DEFINE(HAVE_NCURSES_H)
335 else
336         AC_CHECK_LIB(
337                 curses,
338                 setupterm,
339                 found_curses=yes,
340                 found_curses=no
341         )
342         AC_CHECK_HEADER(
343                 curses.h,
344                 ,
345                 found_curses=no
346         )
347         if test "x$found_curses" = xyes; then
348                 LIBS="$LIBS -lcurses"
349                 CPPFLAGS="$CPPFLAGS -DHAVE_CURSES_H"
350                 AC_DEFINE(HAVE_CURSES_H)
351         else
352                 AC_MSG_ERROR("curses not found")
353         fi
355 AC_CHECK_FUNCS([ \
356         tiparm \
357         tiparm_s \
360 # Look for utempter.
361 AC_ARG_ENABLE(
362         utempter,
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
368                 AC_SEARCH_LIBS(
369                         utempter_add_record,
370                         utempter,
371                         enable_utempter=yes,
372                         enable_utempter=no
373                 )
374         fi
375         if test "x$enable_utempter" = xyes; then
376                 AC_DEFINE(HAVE_UTEMPTER)
377         else
378                 AC_MSG_ERROR("utempter not found")
379         fi
382 # Look for utf8proc.
383 AC_ARG_ENABLE(
384         utf8proc,
385         AS_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
387 if test "x$enable_utf8proc" = xyes; then
388         PKG_CHECK_MODULES(
389                 LIBUTF8PROC,
390                 libutf8proc,
391                 [
392                         AM_CPPFLAGS="$LIBUTF8PROC_CFLAGS $AM_CPPFLAGS"
393                         CPPFLAGS="$LIBUTF8PROC_CFLAGS $SAVED_CPPFLAGS"
394                         LIBS="$LIBUTF8PROC_LIBS $LIBS"
395                 ]
396         )
397         AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no)
398         if test "x$enable_utf8proc" = xyes; then
399                 AC_SEARCH_LIBS(
400                         utf8proc_charwidth,
401                         utf8proc,
402                         enable_utf8proc=yes,
403                         enable_utf8proc=no
404                 )
405         fi
406         if test "x$enable_utf8proc" = xyes; then
407                 AC_DEFINE(HAVE_UTF8PROC)
408         else
409                 AC_MSG_ERROR("utf8proc not found")
410         fi
412 AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes])
414 # Check for systemd support.
415 AC_ARG_ENABLE(
416         systemd,
417         AS_HELP_STRING(--enable-systemd, enable systemd integration)
419 if test x"$enable_systemd" = xyes; then
420         PKG_CHECK_MODULES(
421                 SYSTEMD,
422                 libsystemd,
423                 [
424                         AM_CPPFLAGS="$SYSTEMD_CFLAGS $AM_CPPFLAGS"
425                         CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
426                         LIBS="$SYSTEMD_LIBS $LIBS"
427                         found_systemd=yes
428                 ],
429                 found_systemd=no
430         )
431         if test "x$found_systemd" = xyes; then
432                 AC_DEFINE(HAVE_SYSTEMD)
433         else
434                 AC_MSG_ERROR("systemd not found")
435         fi
437 AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$found_systemd" = xyes])
438 AC_ARG_ENABLE(
439         cgroups,
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)
449         else
450                 AC_MSG_ERROR("cgroups requires systemd to be enabled")
451         fi
454 # Enable sixel support.
455 AC_ARG_ENABLE(
456         sixel,
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(
467         [
468                 #include <sys/types.h>
469                 #include <netinet/in.h>
470                 #include <resolv.h>
471         ],
472         [
473                 b64_ntop(NULL, 0, NULL, 0);
474         ])],
475         found_b64_ntop=yes,
476         found_b64_ntop=no
478 AC_MSG_RESULT($found_b64_ntop)
479 OLD_LIBS="$LIBS"
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(
484                 [
485                         #include <sys/types.h>
486                         #include <netinet/in.h>
487                         #include <resolv.h>
488                 ],
489                 [
490                         b64_ntop(NULL, 0, NULL, 0);
491                 ])],
492                 found_b64_ntop=yes,
493                 found_b64_ntop=no
494         )
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(
501                 [
502                         #include <sys/types.h>
503                         #include <netinet/in.h>
504                         #include <resolv.h>
505                 ],
506                 [
507                         b64_ntop(NULL, 0, NULL, 0);
508                 ])],
509                 found_b64_ntop=yes,
510                 found_b64_ntop=no
511         )
512         AC_MSG_RESULT($found_b64_ntop)
514 if test "x$found_b64_ntop" = xyes; then
515         AC_DEFINE(HAVE_B64_NTOP)
516 else
517         LIBS="$OLD_LIBS"
518         AC_LIBOBJ(base64)
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(
531         [
532                 #include <stdlib.h>
533                 #ifdef __GLIBC__
534                 #include <malloc.h>
535                 int main(void) {
536                         malloc_trim (0);
537                         exit(0);
538                 }
539                 #else
540                 no
541                 #endif
542         ])],
543         found_malloc_trim=yes,
544         found_malloc_trim=no
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).
554 XOPEN_DEFINES=
555 AC_MSG_CHECKING(for CMSG_DATA)
556 AC_EGREP_CPP(
557         yes,
558         [
559                 #include <sys/socket.h>
560                 #ifdef CMSG_DATA
561                 yes
562                 #endif
563         ],
564         found_cmsg_data=yes,
565         found_cmsg_data=no
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)
570         AC_EGREP_CPP(
571                 yes,
572                 [
573                         #define _XOPEN_SOURCE 1
574                         #define _XOPEN_SOURCE_EXTENDED 1
575                         #include <sys/socket.h>
576                         #ifdef CMSG_DATA
577                         yes
578                         #endif
579                 ],
580                 found_cmsg_data=yes,
581                 found_cmsg_data=no
582         )
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"
586         fi
588 if test "x$found_cmsg_data" = xno; then
589         AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE 600)
590         AC_EGREP_CPP(
591                 yes,
592                 [
593                         #define _XOPEN_SOURCE 600
594                         #include <sys/socket.h>
595                         #ifdef CMSG_DATA
596                         yes
597                         #endif
598                 ],
599                 found_cmsg_data=yes,
600                 found_cmsg_data=no
601         )
602         AC_MSG_RESULT($found_cmsg_data)
603         if test "x$found_cmsg_data" = xyes; then
604                 XOPEN_DEFINES="-D_XOPEN_SOURCE=600"
605         else
606                 AC_MSG_ERROR("CMSG_DATA not found")
607         fi
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)
618 else
619         AC_LIBOBJ(err)
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
625         AC_DEFINE(HAVE_IMSG)
626 else
627         AC_LIBOBJ(imsg)
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
633 # function.
634 AC_CHECK_FUNC(daemon, found_daemon=yes, found_daemon=no)
635 AC_CHECK_DECL(
636         daemon,
637         ,
638         found_daemon=no,
639         [
640                 #include <stdlib.h>
641                 #include <unistd.h>
642         ]
644 if test "x$found_daemon" = xyes; then
645         AC_DEFINE(HAVE_DAEMON)
646 else
647         AC_LIBOBJ(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\)],
655                         vis.h,
656                         AC_MSG_RESULT(no),
657                         [found_stravis=no])
658         if test "x$found_stravis" = xno; then
659                 AC_MSG_RESULT(yes)
660         fi
662 if test "x$found_stravis" = xyes; then
663         AC_CHECK_DECL(
664                 VIS_DQ,
665                 ,
666                 found_stravis=no,
667                 [
668                         #include <stdlib.h>
669                         #include <vis.h>
670                 ]
673 if test "x$found_stravis" = xyes; then
674         AC_DEFINE(HAVE_VIS)
675 else
676         AC_LIBOBJ(vis)
677         AC_LIBOBJ(unvis)
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)
684 else
685         AC_LIBOBJ(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.
697 AC_CHECK_DECL(
698         TAILQ_CONCAT,
699         found_queue_h=yes,
700         found_queue_h=no,
701         [#include <sys/queue.h>]
703 AC_CHECK_DECL(
704         TAILQ_PREV,
705         ,
706         found_queue_h=no,
707         [#include <sys/queue.h>]
709 AC_CHECK_DECL(
710         TAILQ_REPLACE,
711         ,
712         found_queue_h=no,
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(
722         [
723                 #include <stdio.h>
724                 #include <stdlib.h>
725                 extern char *__progname;
726                 int main(void) {
727                         const char *cp = __progname;
728                         printf("%s\n", cp);
729                         exit(0);
730                 }
731         ])],
732         [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
733         AC_MSG_RESULT(no)
736 # Look for program_invocation_short_name.
737 AC_MSG_CHECKING(for program_invocation_short_name)
738 AC_LINK_IFELSE([AC_LANG_SOURCE(
739         [
740                 #include <errno.h>
741                 #include <stdio.h>
742                 #include <stdlib.h>
743                 int main(void) {
744                         const char *cp = program_invocation_short_name;
745                         printf("%s\n", cp);
746                         exit(0);
747                 }
748         ])],
749         [AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME) AC_MSG_RESULT(yes)],
750         AC_MSG_RESULT(no)
753 # Look for prctl(PR_SET_NAME).
754 AC_CHECK_DECL(
755         PR_SET_NAME,
756         AC_DEFINE(HAVE_PR_SET_NAME),
757         ,
758         [#include <sys/prctl.h>]
761 # Look for setsockopt(SO_PEERCRED).
762 AC_CHECK_DECL(
763         SO_PEERCRED,
764         AC_DEFINE(HAVE_SO_PEERCRED),
765         ,
766         [#include <sys/socket.h>]
769 # Look for fcntl(F_CLOSEM).
770 AC_CHECK_DECL(
771         F_CLOSEM,
772         AC_DEFINE(HAVE_FCNTL_CLOSEM),
773         ,
774         [#include <fcntl.h>]
777 # Look for /proc/$$.
778 AC_MSG_CHECKING(for /proc/\$\$)
779 if test -d /proc/$$; then
780         AC_DEFINE(HAVE_PROC_PID)
781         AC_MSG_RESULT(yes)
782 else
783         AC_MSG_RESULT(no)
786 # Try to figure out what the best value for TERM might be.
787 if test "x$DEFAULT_TERM" = x; then
788         DEFAULT_TERM=screen
789         AC_MSG_CHECKING(TERM)
790         AC_RUN_IFELSE([AC_LANG_SOURCE(
791                 [
792                         #include <stdio.h>
793                         #include <stdlib.h>
794                         #if defined(HAVE_CURSES_H)
795                         #include <curses.h>
796                         #elif defined(HAVE_NCURSES_H)
797                         #include <ncurses.h>
798                         #endif
799                         #include <term.h>
800                         int main(void) {
801                                 if (setupterm("screen-256color", -1, NULL) != OK)
802                                         exit(1);
803                                 exit(0);
804                         }
805                  ])],
806                  [DEFAULT_TERM=screen-256color],
807                  ,
808                  [DEFAULT_TERM=screen]
809         )
810         AC_RUN_IFELSE([AC_LANG_SOURCE(
811                 [
812                         #include <stdio.h>
813                         #include <stdlib.h>
814                         #if defined(HAVE_CURSES_H)
815                         #include <curses.h>
816                         #elif defined(HAVE_NCURSES_H)
817                         #include <ncurses.h>
818                         #endif
819                         #include <term.h>
820                         int main(void) {
821                                 if (setupterm("tmux", -1, NULL) != OK)
822                                         exit(1);
823                                 exit(0);
824                         }
825                  ])],
826                  [DEFAULT_TERM=tmux],
827                  ,
828                  [DEFAULT_TERM=screen]
829         )
830         AC_RUN_IFELSE([AC_LANG_SOURCE(
831                 [
832                         #include <stdio.h>
833                         #include <stdlib.h>
834                         #if defined(HAVE_CURSES_H)
835                         #include <curses.h>
836                         #elif defined(HAVE_NCURSES_H)
837                         #include <ncurses.h>
838                         #endif
839                         #include <term.h>
840                         int main(void) {
841                                 if (setupterm("tmux-256color", -1, NULL) != OK)
842                                         exit(1);
843                                 exit(0);
844                         }
845                  ])],
846                  [DEFAULT_TERM=tmux-256color],
847                  ,
848                  [DEFAULT_TERM=screen]
849         )
850         AC_MSG_RESULT($DEFAULT_TERM)
852 AC_SUBST(DEFAULT_TERM)
854 # Man page defaults to mdoc.
855 MANFORMAT=mdoc
856 AC_SUBST(MANFORMAT)
858 # Figure out the platform.
859 AC_MSG_CHECKING(platform)
860 case "$host_os" in
861         *aix*)
862                 AC_MSG_RESULT(aix)
863                 PLATFORM=aix
864                 ;;
865         *darwin*)
866                 AC_MSG_RESULT(darwin)
867                 PLATFORM=darwin
868                 #
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.
871                 #
872                 AC_DEFINE(BROKEN___DEAD)
873                 #
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.
877                 #
878                 AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
879                 AC_LIBOBJ(daemon)
880                 AC_LIBOBJ(daemon-darwin)
881                 #
882                 # macOS wcwidth(3) is bad, so complain and suggest using utf8proc
883                 # instead.
884                 #
885                 if test "x$enable_utf8proc" = x; then
886                         AC_MSG_NOTICE([])
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])
892                         AC_MSG_NOTICE([])
893                         AC_MSG_ERROR([must give --enable-utf8proc or --disable-utf8proc])
894                 fi
895                 ;;
896         *dragonfly*)
897                 AC_MSG_RESULT(dragonfly)
898                 PLATFORM=dragonfly
899                 ;;
900         *linux*)
901                 AC_MSG_RESULT(linux)
902                 PLATFORM=linux
903                 ;;
904         *freebsd*)
905                 AC_MSG_RESULT(freebsd)
906                 PLATFORM=freebsd
907                 ;;
908         *netbsd*)
909                 AC_MSG_RESULT(netbsd)
910                 PLATFORM=netbsd
911                 ;;
912         *openbsd*)
913                 AC_MSG_RESULT(openbsd)
914                 PLATFORM=openbsd
915                 ;;
916         *sunos*)
917                 AC_MSG_RESULT(sunos)
918                 PLATFORM=sunos
919                 ;;
920         *solaris*)
921                 AC_MSG_RESULT(sunos)
922                 PLATFORM=sunos
923                 case `/usr/bin/nroff --version 2>&1` in
924                         *GNU*)
925                                 # Solaris 11.4 and later use GNU groff.
926                                 MANFORMAT=mdoc
927                                 ;;
928                         *)
929                                 # Solaris 2.0 to 11.3 use AT&T nroff.
930                                 MANFORMAT=man
931                                 ;;
932                 esac
933                 ;;
934         *hpux*)
935                 AC_MSG_RESULT(hpux)
936                 PLATFORM=hpux
937                 ;;
938         *cygwin*|*msys*)
939                 AC_MSG_RESULT(cygwin)
940                 PLATFORM=cygwin
941                 ;;
942         *haiku*)
943                 AC_MSG_RESULT(haiku)
944                 PLATFORM=haiku
945                 ;;
946         *)
947                 AC_MSG_RESULT(unknown)
948                 PLATFORM=unknown
949                 ;;
950 esac
951 AC_SUBST(PLATFORM)
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"
971         fi
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
978 # variables.
979 AC_SUBST(AM_CPPFLAGS)
980 CPPFLAGS="$SAVED_CPPFLAGS"
981 AC_SUBST(AM_CFLAGS)
982 CFLAGS="$SAVED_CFLAGS"
983 AC_SUBST(AM_LDFLAGS)
984 LDFLAGS="$SAVED_LDFLAGS"
986 # autoconf should create a Makefile.
987 AC_CONFIG_FILES(Makefile)
988 AC_OUTPUT