Merge branch 'obsd-master'
[tmux.git] / configure.ac
blobca9b9473a71c7d194487e03702dcffd9b5b1d174
1 # configure.ac
3 AC_INIT([tmux], next-3.4)
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 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         memmem \
169         setenv \
170         setproctitle \
171         strcasestr \
172         strlcat \
173         strlcpy \
174         strndup \
175         strsep \
177 AC_FUNC_STRNLEN
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);]
184         )],
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);]
197         )],
198         AC_MSG_RESULT(yes),
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);]
206         )],
207         AC_MSG_RESULT(yes),
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
218 # implementations.
219 AC_LIBOBJ(getopt)
221 # Look for libevent. Try libevent_core or libevent with pkg-config first then
222 # look for the library.
223 PKG_CHECK_MODULES(
224         LIBEVENT_CORE,
225         [libevent_core >= 2],
226         [
227                 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
228                 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
229                 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
230                 found_libevent=yes
231         ],
232         found_libevent=no
234 if test x$found_libevent = xno; then
235         PKG_CHECK_MODULES(
236                 LIBEVENT,
237                 [libevent >= 2],
238                 [
239                         AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
240                         CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
241                         LIBS="$LIBEVENT_LIBS $LIBS"
242                         found_libevent=yes
243                 ],
244                 found_libevent=no
245         )
247 if test x$found_libevent = xno; then
248         AC_SEARCH_LIBS(
249                 event_init,
250                 [event_core event event-1.4],
251                 found_libevent=yes,
252                 found_libevent=no
253         )
255 AC_CHECK_HEADER(
256         event2/event.h,
257         AC_DEFINE(HAVE_EVENT2_EVENT_H),
258         [
259                 AC_CHECK_HEADER(
260                         event.h,
261                         AC_DEFINE(HAVE_EVENT_H),
262                         found_libevent=no
263                 )
264         ]
266 if test "x$found_libevent" = xno; then
267         AC_MSG_ERROR("libevent not found")
270 # Look for yacc.
271 AC_CHECK_PROG(found_yacc, $YACC, yes, no)
272 if test "x$found_yacc" = xno; then
273         AC_MSG_ERROR("yacc not found")
276 # Look for ncurses or curses. Try pkg-config first then directly for the
277 # library.
278 PKG_CHECK_MODULES(
279         LIBTINFO,
280         tinfo,
281         [
282                 AM_CPPFLAGS="$LIBTINFO_CFLAGS $AM_CPPFLAGS"
283                 CPPFLAGS="$LIBTINFO_CFLAGS $SAVED_CPPFLAGS"
284                 LIBS="$LIBTINFO_LIBS $LIBS"
285                 found_ncurses=yes
286         ],
287         found_ncurses=no
289 if test "x$found_ncurses" = xno; then
290         PKG_CHECK_MODULES(
291                 LIBNCURSES,
292                 ncurses,
293                 [
294                         AM_CPPFLAGS="$LIBNCURSES_CFLAGS $AM_CPPFLAGS"
295                         CPPFLAGS="$LIBNCURSES_CFLAGS $SAVED_CPPFLAGS"
296                         LIBS="$LIBNCURSES_LIBS $LIBS"
297                         found_ncurses=yes
298                 ],
299                 found_ncurses=no
300         )
302 if test "x$found_ncurses" = xno; then
303         PKG_CHECK_MODULES(
304                 LIBNCURSESW,
305                 ncursesw,
306                 [
307                         AM_CPPFLAGS="$LIBNCURSESW_CFLAGS $AM_CPPFLAGS"
308                         CPPFLAGS="$LIBNCURSESW_CFLAGS $SAVED_CPPFLAGS"
309                         LIBS="$LIBNCURSESW_LIBS $LIBS"
310                         found_ncurses=yes
311                 ],
312                 found_ncurses=no
313         )
315 if test "x$found_ncurses" = xno; then
316         AC_SEARCH_LIBS(
317                 setupterm,
318                 [tinfo terminfo ncurses ncursesw],
319                 found_ncurses=yes,
320                 found_ncurses=no
321         )
322         if test "x$found_ncurses" = xyes; then
323                 AC_CHECK_HEADER(
324                         ncurses.h,
325                         LIBS="$LIBS -lncurses",
326                         found_ncurses=no
327                 )
328         fi
330 if test "x$found_ncurses" = xyes; then
331         CPPFLAGS="$CPPFLAGS -DHAVE_NCURSES_H"
332         AC_DEFINE(HAVE_NCURSES_H)
333 else
334         AC_CHECK_LIB(
335                 curses,
336                 setupterm,
337                 found_curses=yes,
338                 found_curses=no
339         )
340         AC_CHECK_HEADER(
341                 curses.h,
342                 ,
343                 found_curses=no
344         )
345         if test "x$found_curses" = xyes; then
346                 LIBS="$LIBS -lcurses"
347                 CPPFLAGS="$CPPFLAGS -DHAVE_CURSES_H"
348                 AC_DEFINE(HAVE_CURSES_H)
349         else
350                 AC_MSG_ERROR("curses not found")
351         fi
353 AC_CHECK_FUNCS([ \
354         tiparm \
355         tiparm_s \
358 # Look for utempter.
359 AC_ARG_ENABLE(
360         utempter,
361         AS_HELP_STRING(--enable-utempter, use utempter if it is installed)
363 if test "x$enable_utempter" = xyes; then
364         AC_CHECK_HEADER(utempter.h, enable_utempter=yes, enable_utempter=no)
365         if test "x$enable_utempter" = xyes; then
366                 AC_SEARCH_LIBS(
367                         utempter_add_record,
368                         utempter,
369                         enable_utempter=yes,
370                         enable_utempter=no
371                 )
372         fi
373         if test "x$enable_utempter" = xyes; then
374                 AC_DEFINE(HAVE_UTEMPTER)
375         else
376                 AC_MSG_ERROR("utempter not found")
377         fi
380 # Look for utf8proc.
381 AC_ARG_ENABLE(
382         utf8proc,
383         AS_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
385 if test "x$enable_utf8proc" = xyes; then
386         PKG_CHECK_MODULES(
387                 LIBUTF8PROC,
388                 libutf8proc,
389                 [
390                         AM_CPPFLAGS="$LIBUTF8PROC_CFLAGS $AM_CPPFLAGS"
391                         CPPFLAGS="$LIBUTF8PROC_CFLAGS $SAVED_CPPFLAGS"
392                         LIBS="$LIBUTF8PROC_LIBS $LIBS"
393                 ]
394         )
395         AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no)
396         if test "x$enable_utf8proc" = xyes; then
397                 AC_SEARCH_LIBS(
398                         utf8proc_charwidth,
399                         utf8proc,
400                         enable_utf8proc=yes,
401                         enable_utf8proc=no
402                 )
403         fi
404         if test "x$enable_utf8proc" = xyes; then
405                 AC_DEFINE(HAVE_UTF8PROC)
406         else
407                 AC_MSG_ERROR("utf8proc not found")
408         fi
410 AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes])
412 # Check for systemd support.
413 AC_ARG_ENABLE(
414         systemd,
415         AS_HELP_STRING(--enable-systemd, enable systemd integration)
417 if test x"$enable_systemd" = xyes; then
418         PKG_CHECK_MODULES(
419                 SYSTEMD,
420                 libsystemd,
421                 [
422                         AM_CPPFLAGS="$SYSTEMD_CFLAGS $AM_CPPFLAGS"
423                         CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
424                         LIBS="$SYSTEMD_LIBS $LIBS"
425                         found_systemd=yes
426                 ],
427                 found_systemd=no
428         )
429         if test "x$found_systemd" = xyes; then
430                 AC_DEFINE(HAVE_SYSTEMD)
431         else
432                 AC_MSG_ERROR("systemd not found")
433         fi
435 AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$found_systemd" = xyes])
436 AC_ARG_ENABLE(
437         cgroups,
438         AS_HELP_STRING(--disable-cgroups, disable adding panes to new cgroups with systemd)
440 if test "x$enable_cgroups" = x; then
441         # Default to the same as $enable_systemd.
442         enable_cgroups=$enable_systemd
444 if test "x$enable_cgroups" = xyes; then
445         if test "x$found_systemd" = xyes; then
446                 AC_DEFINE(ENABLE_CGROUPS)
447         else
448                 AC_MSG_ERROR("cgroups requires systemd to be enabled")
449         fi
452 # Enable sixel support.
453 AC_ARG_ENABLE(
454         sixel,
455         AS_HELP_STRING(--enable-sixel, enable sixel images)
457 if test "x$enable_sixel" = xyes; then
458         AC_DEFINE(ENABLE_SIXEL)
460 AM_CONDITIONAL(ENABLE_SIXEL, [test "x$enable_sixel" = xyes])
462 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
463 AC_MSG_CHECKING(for b64_ntop)
464 AC_LINK_IFELSE([AC_LANG_PROGRAM(
465         [
466                 #include <sys/types.h>
467                 #include <netinet/in.h>
468                 #include <resolv.h>
469         ],
470         [
471                 b64_ntop(NULL, 0, NULL, 0);
472         ])],
473         found_b64_ntop=yes,
474         found_b64_ntop=no
476 AC_MSG_RESULT($found_b64_ntop)
477 OLD_LIBS="$LIBS"
478 if test "x$found_b64_ntop" = xno; then
479         AC_MSG_CHECKING(for b64_ntop with -lresolv)
480         LIBS="$OLD_LIBS -lresolv"
481         AC_LINK_IFELSE([AC_LANG_PROGRAM(
482                 [
483                         #include <sys/types.h>
484                         #include <netinet/in.h>
485                         #include <resolv.h>
486                 ],
487                 [
488                         b64_ntop(NULL, 0, NULL, 0);
489                 ])],
490                 found_b64_ntop=yes,
491                 found_b64_ntop=no
492         )
493         AC_MSG_RESULT($found_b64_ntop)
495 if test "x$found_b64_ntop" = xno; then
496         AC_MSG_CHECKING(for b64_ntop with -lnetwork)
497         LIBS="$OLD_LIBS -lnetwork"
498         AC_LINK_IFELSE([AC_LANG_PROGRAM(
499                 [
500                         #include <sys/types.h>
501                         #include <netinet/in.h>
502                         #include <resolv.h>
503                 ],
504                 [
505                         b64_ntop(NULL, 0, NULL, 0);
506                 ])],
507                 found_b64_ntop=yes,
508                 found_b64_ntop=no
509         )
510         AC_MSG_RESULT($found_b64_ntop)
512 if test "x$found_b64_ntop" = xyes; then
513         AC_DEFINE(HAVE_B64_NTOP)
514 else
515         LIBS="$OLD_LIBS"
516         AC_LIBOBJ(base64)
519 # Look for networking libraries.
520 AC_SEARCH_LIBS(inet_ntoa, nsl)
521 AC_SEARCH_LIBS(socket, socket)
522 AC_CHECK_LIB(xnet, socket)
524 # Check if using glibc and have malloc_trim(3). The glibc free(3) is pretty bad
525 # about returning memory to the kernel unless the application tells it when to
526 # with malloc_trim(3).
527 AC_MSG_CHECKING(if free doesn't work very well)
528 AC_LINK_IFELSE([AC_LANG_SOURCE(
529         [
530                 #include <stdlib.h>
531                 #ifdef __GLIBC__
532                 #include <malloc.h>
533                 int main(void) {
534                         malloc_trim (0);
535                         exit(0);
536                 }
537                 #else
538                 no
539                 #endif
540         ])],
541         found_malloc_trim=yes,
542         found_malloc_trim=no
544 AC_MSG_RESULT($found_malloc_trim)
545 if test "x$found_malloc_trim" = xyes; then
546         AC_DEFINE(HAVE_MALLOC_TRIM)
549 # Check for CMSG_DATA. On some platforms like HP-UX this requires UNIX 95
550 # (_XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED) (see xopen_networking(7)). On
551 # others, UNIX 03 (_XOPEN_SOURCE 600, see standards(7) on Solaris).
552 XOPEN_DEFINES=
553 AC_MSG_CHECKING(for CMSG_DATA)
554 AC_EGREP_CPP(
555         yes,
556         [
557                 #include <sys/socket.h>
558                 #ifdef CMSG_DATA
559                 yes
560                 #endif
561         ],
562         found_cmsg_data=yes,
563         found_cmsg_data=no
565 AC_MSG_RESULT($found_cmsg_data)
566 if test "x$found_cmsg_data" = xno; then
567         AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE_EXTENDED)
568         AC_EGREP_CPP(
569                 yes,
570                 [
571                         #define _XOPEN_SOURCE 1
572                         #define _XOPEN_SOURCE_EXTENDED 1
573                         #include <sys/socket.h>
574                         #ifdef CMSG_DATA
575                         yes
576                         #endif
577                 ],
578                 found_cmsg_data=yes,
579                 found_cmsg_data=no
580         )
581         AC_MSG_RESULT($found_cmsg_data)
582         if test "x$found_cmsg_data" = xyes; then
583                 XOPEN_DEFINES="-D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED"
584         fi
586 if test "x$found_cmsg_data" = xno; then
587         AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE 600)
588         AC_EGREP_CPP(
589                 yes,
590                 [
591                         #define _XOPEN_SOURCE 600
592                         #include <sys/socket.h>
593                         #ifdef CMSG_DATA
594                         yes
595                         #endif
596                 ],
597                 found_cmsg_data=yes,
598                 found_cmsg_data=no
599         )
600         AC_MSG_RESULT($found_cmsg_data)
601         if test "x$found_cmsg_data" = xyes; then
602                 XOPEN_DEFINES="-D_XOPEN_SOURCE=600"
603         else
604                 AC_MSG_ERROR("CMSG_DATA not found")
605         fi
607 AC_SUBST(XOPEN_DEFINES)
609 # Look for err and friends in err.h.
610 AC_CHECK_FUNC(err, found_err_h=yes, found_err_h=no)
611 AC_CHECK_FUNC(errx, , found_err_h=no)
612 AC_CHECK_FUNC(warn, , found_err_h=no)
613 AC_CHECK_FUNC(warnx, , found_err_h=no)
614 if test "x$found_err_h" = xyes; then
615         AC_CHECK_HEADER(err.h, , found_err_h=no)
616 else
617         AC_LIBOBJ(err)
620 # Look for imsg_init in libutil.
621 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
622 if test "x$found_imsg_init" = xyes; then
623         AC_DEFINE(HAVE_IMSG)
624 else
625         AC_LIBOBJ(imsg)
626         AC_LIBOBJ(imsg-buffer)
629 # Look for daemon, compat/daemon.c used if missing. Solaris 10 has it in
630 # libresolv, but no declaration anywhere, so check for declaration as well as
631 # function.
632 AC_CHECK_FUNC(daemon, found_daemon=yes, found_daemon=no)
633 AC_CHECK_DECL(
634         daemon,
635         ,
636         found_daemon=no,
637         [
638                 #include <stdlib.h>
639                 #include <unistd.h>
640         ]
642 if test "x$found_daemon" = xyes; then
643         AC_DEFINE(HAVE_DAEMON)
644 else
645         AC_LIBOBJ(daemon)
648 # Look for stravis, compat/{vis,unvis}.c used if missing.
649 AC_CHECK_FUNC(stravis, found_stravis=yes, found_stravis=no)
650 if test "x$found_stravis" = xyes; then
651         AC_MSG_CHECKING(if strnvis is broken)
652         AC_EGREP_HEADER([strnvis\(char \*, const char \*, size_t, int\)],
653                         vis.h,
654                         AC_MSG_RESULT(no),
655                         [found_stravis=no])
656         if test "x$found_stravis" = xno; then
657                 AC_MSG_RESULT(yes)
658         fi
660 if test "x$found_stravis" = xyes; then
661         AC_CHECK_DECL(
662                 VIS_DQ,
663                 ,
664                 found_stravis=no,
665                 [
666                         #include <stdlib.h>
667                         #include <vis.h>
668                 ]
671 if test "x$found_stravis" = xyes; then
672         AC_DEFINE(HAVE_VIS)
673 else
674         AC_LIBOBJ(vis)
675         AC_LIBOBJ(unvis)
678 # Look for fdforkpty and forkpty in libutil.
679 AC_SEARCH_LIBS(fdforkpty, util, found_fdforkpty=yes, found_fdforkpty=no)
680 if test "x$found_fdforkpty" = xyes; then
681         AC_DEFINE(HAVE_FDFORKPTY)
682 else
683         AC_LIBOBJ(fdforkpty)
685 AC_SEARCH_LIBS(forkpty, util, found_forkpty=yes, found_forkpty=no)
686 if test "x$found_forkpty" = xyes; then
687         AC_DEFINE(HAVE_FORKPTY)
689 AM_CONDITIONAL(NEED_FORKPTY, test "x$found_forkpty" = xno)
691 # Look for kinfo_getfile in libutil.
692 AC_SEARCH_LIBS(kinfo_getfile, [util util-freebsd])
694 # Look for a suitable queue.h.
695 AC_CHECK_DECL(
696         TAILQ_CONCAT,
697         found_queue_h=yes,
698         found_queue_h=no,
699         [#include <sys/queue.h>]
701 AC_CHECK_DECL(
702         TAILQ_PREV,
703         ,
704         found_queue_h=no,
705         [#include <sys/queue.h>]
707 AC_CHECK_DECL(
708         TAILQ_REPLACE,
709         ,
710         found_queue_h=no,
711         [#include <sys/queue.h>]
713 if test "x$found_queue_h" = xyes; then
714         AC_DEFINE(HAVE_QUEUE_H)
717 # Look for __progname.
718 AC_MSG_CHECKING(for __progname)
719 AC_LINK_IFELSE([AC_LANG_SOURCE(
720         [
721                 #include <stdio.h>
722                 #include <stdlib.h>
723                 extern char *__progname;
724                 int main(void) {
725                         const char *cp = __progname;
726                         printf("%s\n", cp);
727                         exit(0);
728                 }
729         ])],
730         [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
731         AC_MSG_RESULT(no)
734 # Look for program_invocation_short_name.
735 AC_MSG_CHECKING(for program_invocation_short_name)
736 AC_LINK_IFELSE([AC_LANG_SOURCE(
737         [
738                 #include <errno.h>
739                 #include <stdio.h>
740                 #include <stdlib.h>
741                 int main(void) {
742                         const char *cp = program_invocation_short_name;
743                         printf("%s\n", cp);
744                         exit(0);
745                 }
746         ])],
747         [AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME) AC_MSG_RESULT(yes)],
748         AC_MSG_RESULT(no)
751 # Look for prctl(PR_SET_NAME).
752 AC_CHECK_DECL(
753         PR_SET_NAME,
754         AC_DEFINE(HAVE_PR_SET_NAME),
755         ,
756         [#include <sys/prctl.h>]
759 # Look for setsockopt(SO_PEERCRED).
760 AC_CHECK_DECL(
761         SO_PEERCRED,
762         AC_DEFINE(HAVE_SO_PEERCRED),
763         ,
764         [#include <sys/socket.h>]
767 # Look for fcntl(F_CLOSEM).
768 AC_CHECK_DECL(
769         F_CLOSEM,
770         AC_DEFINE(HAVE_FCNTL_CLOSEM),
771         ,
772         [#include <fcntl.h>]
775 # Look for /proc/$$.
776 AC_MSG_CHECKING(for /proc/\$\$)
777 if test -d /proc/$$; then
778         AC_DEFINE(HAVE_PROC_PID)
779         AC_MSG_RESULT(yes)
780 else
781         AC_MSG_RESULT(no)
784 # Try to figure out what the best value for TERM might be.
785 if test "x$DEFAULT_TERM" = x; then
786         DEFAULT_TERM=screen
787         AC_MSG_CHECKING(TERM)
788         AC_RUN_IFELSE([AC_LANG_SOURCE(
789                 [
790                         #include <stdio.h>
791                         #include <stdlib.h>
792                         #if defined(HAVE_CURSES_H)
793                         #include <curses.h>
794                         #elif defined(HAVE_NCURSES_H)
795                         #include <ncurses.h>
796                         #endif
797                         #include <term.h>
798                         int main(void) {
799                                 if (setupterm("screen-256color", -1, NULL) != OK)
800                                         exit(1);
801                                 exit(0);
802                         }
803                  ])],
804                  [DEFAULT_TERM=screen-256color],
805                  ,
806                  [DEFAULT_TERM=screen]
807         )
808         AC_RUN_IFELSE([AC_LANG_SOURCE(
809                 [
810                         #include <stdio.h>
811                         #include <stdlib.h>
812                         #if defined(HAVE_CURSES_H)
813                         #include <curses.h>
814                         #elif defined(HAVE_NCURSES_H)
815                         #include <ncurses.h>
816                         #endif
817                         #include <term.h>
818                         int main(void) {
819                                 if (setupterm("tmux", -1, NULL) != OK)
820                                         exit(1);
821                                 exit(0);
822                         }
823                  ])],
824                  [DEFAULT_TERM=tmux],
825                  ,
826                  [DEFAULT_TERM=screen]
827         )
828         AC_RUN_IFELSE([AC_LANG_SOURCE(
829                 [
830                         #include <stdio.h>
831                         #include <stdlib.h>
832                         #if defined(HAVE_CURSES_H)
833                         #include <curses.h>
834                         #elif defined(HAVE_NCURSES_H)
835                         #include <ncurses.h>
836                         #endif
837                         #include <term.h>
838                         int main(void) {
839                                 if (setupterm("tmux-256color", -1, NULL) != OK)
840                                         exit(1);
841                                 exit(0);
842                         }
843                  ])],
844                  [DEFAULT_TERM=tmux-256color],
845                  ,
846                  [DEFAULT_TERM=screen]
847         )
848         AC_MSG_RESULT($DEFAULT_TERM)
850 AC_SUBST(DEFAULT_TERM)
852 # Man page defaults to mdoc.
853 MANFORMAT=mdoc
854 AC_SUBST(MANFORMAT)
856 # Figure out the platform.
857 AC_MSG_CHECKING(platform)
858 case "$host_os" in
859         *aix*)
860                 AC_MSG_RESULT(aix)
861                 PLATFORM=aix
862                 ;;
863         *darwin*)
864                 AC_MSG_RESULT(darwin)
865                 PLATFORM=darwin
866                 #
867                 # macOS uses __dead2 instead of __dead, like FreeBSD. But it defines
868                 # __dead away so it needs to be removed before we can replace it.
869                 #
870                 AC_DEFINE(BROKEN___DEAD)
871                 #
872                 # macOS CMSG_FIRSTHDR is broken, so redefine it with a working one.
873                 # daemon works but has some stupid side effects, so use our internal
874                 # version which has a workaround.
875                 #
876                 AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
877                 AC_LIBOBJ(daemon)
878                 AC_LIBOBJ(daemon-darwin)
879                 #
880                 # macOS wcwidth(3) is bad, so complain and suggest using utf8proc
881                 # instead.
882                 #
883                 if test "x$enable_utf8proc" = x; then
884                         AC_MSG_NOTICE([])
885                         AC_MSG_NOTICE([    macOS library support for Unicode is very poor,])
886                         AC_MSG_NOTICE([    particularly for complex codepoints like emojis;])
887                         AC_MSG_NOTICE([    to use these correctly, configuring with])
888                         AC_MSG_NOTICE([    --enable-utf8proc is recommended. To build])
889                         AC_MSG_NOTICE([    without anyway, use --disable-utf8proc])
890                         AC_MSG_NOTICE([])
891                         AC_MSG_ERROR([must give --enable-utf8proc or --disable-utf8proc])
892                 fi
893                 ;;
894         *dragonfly*)
895                 AC_MSG_RESULT(dragonfly)
896                 PLATFORM=dragonfly
897                 ;;
898         *linux*)
899                 AC_MSG_RESULT(linux)
900                 PLATFORM=linux
901                 ;;
902         *freebsd*)
903                 AC_MSG_RESULT(freebsd)
904                 PLATFORM=freebsd
905                 ;;
906         *netbsd*)
907                 AC_MSG_RESULT(netbsd)
908                 PLATFORM=netbsd
909                 ;;
910         *openbsd*)
911                 AC_MSG_RESULT(openbsd)
912                 PLATFORM=openbsd
913                 ;;
914         *sunos*)
915                 AC_MSG_RESULT(sunos)
916                 PLATFORM=sunos
917                 ;;
918         *solaris*)
919                 AC_MSG_RESULT(sunos)
920                 PLATFORM=sunos
921                 case `/usr/bin/nroff --version 2>&1` in
922                         *GNU*)
923                                 # Solaris 11.4 and later use GNU groff.
924                                 MANFORMAT=mdoc
925                                 ;;
926                         *)
927                                 # Solaris 2.0 to 11.3 use AT&T nroff.
928                                 MANFORMAT=man
929                                 ;;
930                 esac
931                 ;;
932         *hpux*)
933                 AC_MSG_RESULT(hpux)
934                 PLATFORM=hpux
935                 ;;
936         *cygwin*|*msys*)
937                 AC_MSG_RESULT(cygwin)
938                 PLATFORM=cygwin
939                 ;;
940         *haiku*)
941                 AC_MSG_RESULT(haiku)
942                 PLATFORM=haiku
943                 ;;
944         *)
945                 AC_MSG_RESULT(unknown)
946                 PLATFORM=unknown
947                 ;;
948 esac
949 AC_SUBST(PLATFORM)
950 AM_CONDITIONAL(IS_AIX, test "x$PLATFORM" = xaix)
951 AM_CONDITIONAL(IS_DARWIN, test "x$PLATFORM" = xdarwin)
952 AM_CONDITIONAL(IS_DRAGONFLY, test "x$PLATFORM" = xdragonfly)
953 AM_CONDITIONAL(IS_LINUX, test "x$PLATFORM" = xlinux)
954 AM_CONDITIONAL(IS_FREEBSD, test "x$PLATFORM" = xfreebsd)
955 AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd)
956 AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd)
957 AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos)
958 AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
959 AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
960 AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
962 # Set the default lock command
963 DEFAULT_LOCK_CMD="lock -np"
964 AC_MSG_CHECKING(lock-command)
965 if test "x$PLATFORM" = xlinux; then
966         AC_CHECK_PROG(found_vlock, vlock, yes, no)
967         if test "x$found_vlock" = xyes; then
968                 DEFAULT_LOCK_CMD="vlock"
969         fi
971 AC_MSG_RESULT($DEFAULT_LOCK_CMD)
972 AC_SUBST(DEFAULT_LOCK_CMD)
975 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
976 # variables.
977 AC_SUBST(AM_CPPFLAGS)
978 CPPFLAGS="$SAVED_CPPFLAGS"
979 AC_SUBST(AM_CFLAGS)
980 CFLAGS="$SAVED_CFLAGS"
981 AC_SUBST(AM_LDFLAGS)
982 LDFLAGS="$SAVED_LDFLAGS"
984 # autoconf should create a Makefile.
985 AC_CONFIG_FILES(Makefile)
986 AC_OUTPUT