Merge branch 'obsd-master'
[tmux.git] / configure.ac
blob4f90fcd51dcd63c5d37247c10f87acd21ddd02a9
1 # configure.ac
3 AC_INIT([tmux], next-3.6)
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 AC_ARG_ENABLE(
60         debug,
61         AS_HELP_STRING(--enable-debug, enable debug build flags),
62         ,
63         [case "x$VERSION" in xnext*) enable_debug=yes;; esac]
65 AM_CONDITIONAL(IS_DEBUG, test "x$enable_debug" = xyes)
67 # Is this a static build?
68 AC_ARG_ENABLE(
69         static,
70         AS_HELP_STRING(--enable-static, create a static build)
72 if test "x$enable_static" = xyes; then
73         case "$host_os" in
74                 *darwin*)
75                         AC_MSG_ERROR([static linking is not supported on macOS])
76                         ;;
77         esac
78         test "x$PKG_CONFIG" != x && PKG_CONFIG="$PKG_CONFIG --static"
79         AM_LDFLAGS="-static $AM_LDFLAGS"
80         LDFLAGS="$AM_LDFLAGS $SAVED_LDFLAGS"
83 # Allow default TERM to be set.
84 AC_ARG_WITH(
85         TERM,
86         AS_HELP_STRING(--with-TERM, set default TERM),
87         [DEFAULT_TERM=$withval],
88         [DEFAULT_TERM=]
90 case "x$DEFAULT_TERM" in
91         xscreen*|xtmux*|x)
92         ;;
93         *)
94                 AC_MSG_ERROR("unsuitable TERM (must be screen* or tmux*)")
95         ;;
96 esac
98 # Do we need fuzzers?
99 AM_CONDITIONAL(NEED_FUZZING, test "x$enable_fuzzing" = xyes)
101 # Is this gcc?
102 AM_CONDITIONAL(IS_GCC, test "x$GCC" = xyes -a "x$enable_fuzzing" != xyes)
104 # Is this Sun CC?
105 AC_EGREP_CPP(
106         yes,
107         [
108                 #ifdef __SUNPRO_C
109                 yes
110                 #endif
111         ],
112         found_suncc=yes,
113         found_suncc=no
115 AM_CONDITIONAL(IS_SUNCC, test "x$found_suncc" = xyes)
117 # Check for various headers. Alternatives included from compat.h.
118 AC_CHECK_HEADERS([ \
119         bitstring.h \
120         dirent.h \
121         fcntl.h \
122         inttypes.h \
123         libproc.h \
124         libutil.h \
125         ndir.h \
126         paths.h \
127         pty.h \
128         stdint.h \
129         sys/dir.h \
130         sys/ndir.h \
131         sys/tree.h \
132         ucred.h \
133         util.h \
136 # Look for sys_signame.
137 AC_SEARCH_LIBS(sys_signame, , AC_DEFINE(HAVE_SYS_SIGNAME))
139 # Look for fmod.
140 AC_CHECK_LIB(m, fmod)
142 # Look for library needed for flock.
143 AC_SEARCH_LIBS(flock, bsd)
145 # Check for functions that are replaced or omitted.
146 AC_CHECK_FUNCS([ \
147         dirfd \
148         flock \
149         prctl \
150         proc_pidinfo \
151         getpeerucred \
152         sysconf
155 # Check for functions with a compatibility implementation.
156 AC_REPLACE_FUNCS([ \
157         asprintf \
158         cfmakeraw \
159         clock_gettime \
160         closefrom \
161         explicit_bzero \
162         fgetln \
163         freezero \
164         getdtablecount \
165         getdtablesize \
166         getpeereid \
167         getline \
168         getprogname \
169         htonll \
170         memmem \
171         ntohll \
172         setenv \
173         setproctitle \
174         strcasestr \
175         strlcat \
176         strlcpy \
177         strndup \
178         strsep \
180 AC_FUNC_STRNLEN
182 # Check if strtonum works.
183 AC_MSG_CHECKING([for working strtonum])
184 AC_RUN_IFELSE([AC_LANG_PROGRAM(
185                 [#include <stdlib.h>],
186                 [return (strtonum("0", 0, 1, NULL) == 0 ? 0 : 1);]
187         )],
188         [AC_DEFINE(HAVE_STRTONUM) AC_MSG_RESULT(yes)],
189         [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)],
190         [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)]
193 # Clang sanitizers wrap reallocarray even if it isn't available on the target
194 # system. When compiled it always returns NULL and crashes the program. To
195 # detect this we need a more complicated test.
196 AC_MSG_CHECKING([for working reallocarray])
197 AC_RUN_IFELSE([AC_LANG_PROGRAM(
198                 [#include <stdlib.h>],
199                 [return (reallocarray(NULL, 1, 1) == NULL);]
200         )],
201         AC_MSG_RESULT(yes),
202         [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
203         [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
205 AC_MSG_CHECKING([for working recallocarray])
206 AC_RUN_IFELSE([AC_LANG_PROGRAM(
207                 [#include <stdlib.h>],
208                 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
209         )],
210         AC_MSG_RESULT(yes),
211         [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
212         [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
215 # Look for clock_gettime. Must come before event_init.
216 AC_SEARCH_LIBS(clock_gettime, rt)
218 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
219 # musl does not set optarg to NULL for flags without arguments (although it is
220 # not required to, but it is helpful) 3) there are probably other weird
221 # implementations.
222 AC_LIBOBJ(getopt)
224 # Look for libevent. Try libevent_core or libevent with pkg-config first then
225 # look for the library.
226 PKG_CHECK_MODULES(
227         LIBEVENT_CORE,
228         [libevent_core >= 2],
229         [
230                 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
231                 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
232                 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
233                 found_libevent=yes
234         ],
235         found_libevent=no
237 if test x$found_libevent = xno; then
238         PKG_CHECK_MODULES(
239                 LIBEVENT,
240                 [libevent >= 2],
241                 [
242                         AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
243                         CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
244                         LIBS="$LIBEVENT_LIBS $LIBS"
245                         found_libevent=yes
246                 ],
247                 found_libevent=no
248         )
250 if test x$found_libevent = xno; then
251         AC_SEARCH_LIBS(
252                 event_init,
253                 [event_core event event-1.4],
254                 found_libevent=yes,
255                 found_libevent=no
256         )
258 AC_CHECK_HEADER(
259         event2/event.h,
260         AC_DEFINE(HAVE_EVENT2_EVENT_H),
261         [
262                 AC_CHECK_HEADER(
263                         event.h,
264                         AC_DEFINE(HAVE_EVENT_H),
265                         found_libevent=no
266                 )
267         ]
269 if test "x$found_libevent" = xno; then
270         AC_MSG_ERROR("libevent not found")
273 # Look for yacc.
274 AC_CHECK_PROG(found_yacc, $YACC, yes, no)
275 if test "x$found_yacc" = xno; then
276         AC_MSG_ERROR("yacc not found")
279 # Look for ncurses or curses. Try pkg-config first then directly for the
280 # library.
281 PKG_CHECK_MODULES(
282         LIBTINFO,
283         tinfo,
284         [
285                 AM_CPPFLAGS="$LIBTINFO_CFLAGS $AM_CPPFLAGS"
286                 CPPFLAGS="$LIBTINFO_CFLAGS $SAVED_CPPFLAGS"
287                 LIBS="$LIBTINFO_LIBS $LIBS"
288                 found_ncurses=yes
289         ],
290         found_ncurses=no
292 if test "x$found_ncurses" = xno; then
293         PKG_CHECK_MODULES(
294                 LIBNCURSES,
295                 ncurses,
296                 [
297                         AM_CPPFLAGS="$LIBNCURSES_CFLAGS $AM_CPPFLAGS"
298                         CPPFLAGS="$LIBNCURSES_CFLAGS $SAVED_CPPFLAGS"
299                         LIBS="$LIBNCURSES_LIBS $LIBS"
300                         found_ncurses=yes
301                 ],
302                 found_ncurses=no
303         )
305 if test "x$found_ncurses" = xno; then
306         PKG_CHECK_MODULES(
307                 LIBNCURSESW,
308                 ncursesw,
309                 [
310                         AM_CPPFLAGS="$LIBNCURSESW_CFLAGS $AM_CPPFLAGS"
311                         CPPFLAGS="$LIBNCURSESW_CFLAGS $SAVED_CPPFLAGS"
312                         LIBS="$LIBNCURSESW_LIBS $LIBS"
313                         found_ncurses=yes
314                 ],
315                 found_ncurses=no
316         )
318 if test "x$found_ncurses" = xno; then
319         AC_SEARCH_LIBS(
320                 setupterm,
321                 [tinfo terminfo ncurses ncursesw],
322                 found_ncurses=yes,
323                 found_ncurses=no
324         )
325         if test "x$found_ncurses" = xyes; then
326                 AC_CHECK_HEADER(
327                         ncurses.h,
328                         LIBS="$LIBS -lncurses",
329                         found_ncurses=no
330                 )
331         fi
333 if test "x$found_ncurses" = xyes; then
334         CPPFLAGS="$CPPFLAGS -DHAVE_NCURSES_H"
335         AC_DEFINE(HAVE_NCURSES_H)
336 else
337         AC_CHECK_LIB(
338                 curses,
339                 setupterm,
340                 found_curses=yes,
341                 found_curses=no
342         )
343         AC_CHECK_HEADER(
344                 curses.h,
345                 ,
346                 found_curses=no
347         )
348         if test "x$found_curses" = xyes; then
349                 LIBS="$LIBS -lcurses"
350                 CPPFLAGS="$CPPFLAGS -DHAVE_CURSES_H"
351                 AC_DEFINE(HAVE_CURSES_H)
352         else
353                 AC_MSG_ERROR("curses not found")
354         fi
356 AC_CHECK_FUNCS([ \
357         tiparm \
358         tiparm_s \
361 # Look for utempter.
362 AC_ARG_ENABLE(
363         utempter,
364         AS_HELP_STRING(--enable-utempter, use utempter if it is installed)
366 if test "x$enable_utempter" = xyes; then
367         AC_CHECK_HEADER(utempter.h, enable_utempter=yes, enable_utempter=no)
368         if test "x$enable_utempter" = xyes; then
369                 AC_SEARCH_LIBS(
370                         utempter_add_record,
371                         utempter,
372                         enable_utempter=yes,
373                         enable_utempter=no
374                 )
375         fi
376         if test "x$enable_utempter" = xyes; then
377                 AC_DEFINE(HAVE_UTEMPTER)
378         else
379                 AC_MSG_ERROR("utempter not found")
380         fi
383 # Look for utf8proc.
384 AC_ARG_ENABLE(
385         utf8proc,
386         AS_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
388 if test "x$enable_utf8proc" = xyes; then
389         PKG_CHECK_MODULES(
390                 LIBUTF8PROC,
391                 libutf8proc,
392                 [
393                         AM_CPPFLAGS="$LIBUTF8PROC_CFLAGS $AM_CPPFLAGS"
394                         CPPFLAGS="$LIBUTF8PROC_CFLAGS $SAVED_CPPFLAGS"
395                         LIBS="$LIBUTF8PROC_LIBS $LIBS"
396                 ]
397         )
398         AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no)
399         if test "x$enable_utf8proc" = xyes; then
400                 AC_SEARCH_LIBS(
401                         utf8proc_charwidth,
402                         utf8proc,
403                         enable_utf8proc=yes,
404                         enable_utf8proc=no
405                 )
406         fi
407         if test "x$enable_utf8proc" = xyes; then
408                 AC_DEFINE(HAVE_UTF8PROC)
409         else
410                 AC_MSG_ERROR("utf8proc not found")
411         fi
413 AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes])
415 # Check for systemd support.
416 AC_ARG_ENABLE(
417         systemd,
418         AS_HELP_STRING(--enable-systemd, enable systemd integration)
420 if test x"$enable_systemd" = xyes; then
421         PKG_CHECK_MODULES(
422                 SYSTEMD,
423                 libsystemd,
424                 [
425                         AM_CPPFLAGS="$SYSTEMD_CFLAGS $AM_CPPFLAGS"
426                         CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
427                         LIBS="$SYSTEMD_LIBS $LIBS"
428                         found_systemd=yes
429                 ],
430                 found_systemd=no
431         )
432         if test "x$found_systemd" = xyes; then
433                 AC_DEFINE(HAVE_SYSTEMD)
434         else
435                 AC_MSG_ERROR("systemd not found")
436         fi
438 AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$found_systemd" = xyes])
439 AC_ARG_ENABLE(
440         cgroups,
441         AS_HELP_STRING(--disable-cgroups, disable adding panes to new cgroups with systemd)
443 if test "x$enable_cgroups" = x; then
444         # Default to the same as $enable_systemd.
445         enable_cgroups=$enable_systemd
447 if test "x$enable_cgroups" = xyes; then
448         if test "x$found_systemd" = xyes; then
449                 AC_DEFINE(ENABLE_CGROUPS)
450         else
451                 AC_MSG_ERROR("cgroups requires systemd to be enabled")
452         fi
455 # Enable sixel support.
456 AC_ARG_ENABLE(
457         sixel,
458         AS_HELP_STRING(--enable-sixel, enable sixel images)
460 if test "x$enable_sixel" = xyes; then
461         AC_DEFINE(ENABLE_SIXEL)
463 AM_CONDITIONAL(ENABLE_SIXEL, [test "x$enable_sixel" = xyes])
465 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
466 AC_MSG_CHECKING(for b64_ntop)
467 AC_LINK_IFELSE([AC_LANG_PROGRAM(
468         [
469                 #include <sys/types.h>
470                 #include <netinet/in.h>
471                 #include <resolv.h>
472         ],
473         [
474                 b64_ntop(NULL, 0, NULL, 0);
475         ])],
476         found_b64_ntop=yes,
477         found_b64_ntop=no
479 AC_MSG_RESULT($found_b64_ntop)
480 OLD_LIBS="$LIBS"
481 if test "x$found_b64_ntop" = xno; then
482         AC_MSG_CHECKING(for b64_ntop with -lresolv)
483         LIBS="$OLD_LIBS -lresolv"
484         AC_LINK_IFELSE([AC_LANG_PROGRAM(
485                 [
486                         #include <sys/types.h>
487                         #include <netinet/in.h>
488                         #include <resolv.h>
489                 ],
490                 [
491                         b64_ntop(NULL, 0, NULL, 0);
492                 ])],
493                 found_b64_ntop=yes,
494                 found_b64_ntop=no
495         )
496         AC_MSG_RESULT($found_b64_ntop)
498 if test "x$found_b64_ntop" = xno; then
499         AC_MSG_CHECKING(for b64_ntop with -lnetwork)
500         LIBS="$OLD_LIBS -lnetwork"
501         AC_LINK_IFELSE([AC_LANG_PROGRAM(
502                 [
503                         #include <sys/types.h>
504                         #include <netinet/in.h>
505                         #include <resolv.h>
506                 ],
507                 [
508                         b64_ntop(NULL, 0, NULL, 0);
509                 ])],
510                 found_b64_ntop=yes,
511                 found_b64_ntop=no
512         )
513         AC_MSG_RESULT($found_b64_ntop)
515 if test "x$found_b64_ntop" = xyes; then
516         AC_DEFINE(HAVE_B64_NTOP)
517 else
518         LIBS="$OLD_LIBS"
519         AC_LIBOBJ(base64)
522 # Look for networking libraries.
523 AC_SEARCH_LIBS(inet_ntoa, nsl)
524 AC_SEARCH_LIBS(socket, socket)
525 AC_CHECK_LIB(xnet, socket)
527 # Check if using glibc and have malloc_trim(3). The glibc free(3) is pretty bad
528 # about returning memory to the kernel unless the application tells it when to
529 # with malloc_trim(3).
530 AC_MSG_CHECKING(if free doesn't work very well)
531 AC_LINK_IFELSE([AC_LANG_SOURCE(
532         [
533                 #include <stdlib.h>
534                 #ifdef __GLIBC__
535                 #include <malloc.h>
536                 int main(void) {
537                         malloc_trim (0);
538                         exit(0);
539                 }
540                 #else
541                 no
542                 #endif
543         ])],
544         found_malloc_trim=yes,
545         found_malloc_trim=no
547 AC_MSG_RESULT($found_malloc_trim)
548 if test "x$found_malloc_trim" = xyes; then
549         AC_DEFINE(HAVE_MALLOC_TRIM)
552 # Build against jemalloc if requested.
553 AC_ARG_ENABLE(
554         jemalloc,
555         AS_HELP_STRING(--enable-jemalloc, use jemalloc if it is installed)
557 if test "x$enable_jemalloc" = xyes; then
558         PKG_CHECK_MODULES(
559                 JEMALLOC,
560                 jemalloc,
561                 [
562                         AM_CPPFLAGS="$JEMALLOC_CFLAGS $AM_CPPFLAGS"
563                         CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
564                         LIBS="$LIBS $JEMALLOC_LIBS"
565                 ],
566                 AC_MSG_ERROR("jemalloc not found")
567         )
570 # Check for CMSG_DATA. On some platforms like HP-UX this requires UNIX 95
571 # (_XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED) (see xopen_networking(7)). On
572 # others, UNIX 03 (_XOPEN_SOURCE 600, see standards(7) on Solaris).
573 XOPEN_DEFINES=
574 AC_MSG_CHECKING(for CMSG_DATA)
575 AC_EGREP_CPP(
576         yes,
577         [
578                 #include <sys/socket.h>
579                 #ifdef CMSG_DATA
580                 yes
581                 #endif
582         ],
583         found_cmsg_data=yes,
584         found_cmsg_data=no
586 AC_MSG_RESULT($found_cmsg_data)
587 if test "x$found_cmsg_data" = xno; then
588         AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE_EXTENDED)
589         AC_EGREP_CPP(
590                 yes,
591                 [
592                         #define _XOPEN_SOURCE 1
593                         #define _XOPEN_SOURCE_EXTENDED 1
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 -D_XOPEN_SOURCE_EXTENDED"
605         fi
607 if test "x$found_cmsg_data" = xno; then
608         AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE 600)
609         AC_EGREP_CPP(
610                 yes,
611                 [
612                         #define _XOPEN_SOURCE 600
613                         #include <sys/socket.h>
614                         #ifdef CMSG_DATA
615                         yes
616                         #endif
617                 ],
618                 found_cmsg_data=yes,
619                 found_cmsg_data=no
620         )
621         AC_MSG_RESULT($found_cmsg_data)
622         if test "x$found_cmsg_data" = xyes; then
623                 XOPEN_DEFINES="-D_XOPEN_SOURCE=600"
624         else
625                 AC_MSG_ERROR("CMSG_DATA not found")
626         fi
628 AC_SUBST(XOPEN_DEFINES)
630 # Look for err and friends in err.h.
631 AC_CHECK_FUNC(err, found_err_h=yes, found_err_h=no)
632 AC_CHECK_FUNC(errx, , found_err_h=no)
633 AC_CHECK_FUNC(warn, , found_err_h=no)
634 AC_CHECK_FUNC(warnx, , found_err_h=no)
635 if test "x$found_err_h" = xyes; then
636         AC_CHECK_HEADER(err.h, , found_err_h=no)
637 else
638         AC_LIBOBJ(err)
641 # Look for imsg_init in libutil.
642 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
643 if test "x$found_imsg_init" = xyes; then
644         AC_DEFINE(HAVE_IMSG)
645 else
646         AC_LIBOBJ(imsg)
647         AC_LIBOBJ(imsg-buffer)
650 # Look for daemon, compat/daemon.c used if missing. Solaris 10 has it in
651 # libresolv, but no declaration anywhere, so check for declaration as well as
652 # function.
653 AC_CHECK_FUNC(daemon, found_daemon=yes, found_daemon=no)
654 AC_CHECK_DECL(
655         daemon,
656         ,
657         found_daemon=no,
658         [
659                 #include <stdlib.h>
660                 #include <unistd.h>
661         ]
663 if test "x$found_daemon" = xyes; then
664         AC_DEFINE(HAVE_DAEMON)
665 else
666         AC_LIBOBJ(daemon)
669 # Look for stravis, compat/{vis,unvis}.c used if missing.
670 AC_CHECK_FUNC(stravis, found_stravis=yes, found_stravis=no)
671 if test "x$found_stravis" = xyes; then
672         AC_MSG_CHECKING(if strnvis is broken)
673         AC_EGREP_HEADER([strnvis\(char \*, const char \*, size_t, int\)],
674                         vis.h,
675                         AC_MSG_RESULT(no),
676                         [found_stravis=no])
677         if test "x$found_stravis" = xno; then
678                 AC_MSG_RESULT(yes)
679         fi
681 if test "x$found_stravis" = xyes; then
682         AC_CHECK_DECL(
683                 VIS_DQ,
684                 ,
685                 found_stravis=no,
686                 [
687                         #include <stdlib.h>
688                         #include <vis.h>
689                 ]
692 if test "x$found_stravis" = xyes; then
693         AC_DEFINE(HAVE_VIS)
694 else
695         AC_LIBOBJ(vis)
696         AC_LIBOBJ(unvis)
699 # Look for fdforkpty and forkpty in libutil.
700 AC_SEARCH_LIBS(fdforkpty, util, found_fdforkpty=yes, found_fdforkpty=no)
701 if test "x$found_fdforkpty" = xyes; then
702         AC_DEFINE(HAVE_FDFORKPTY)
703 else
704         AC_LIBOBJ(fdforkpty)
706 AC_SEARCH_LIBS(forkpty, util, found_forkpty=yes, found_forkpty=no)
707 if test "x$found_forkpty" = xyes; then
708         AC_DEFINE(HAVE_FORKPTY)
710 AM_CONDITIONAL(NEED_FORKPTY, test "x$found_forkpty" = xno)
712 # Look for kinfo_getfile in libutil.
713 AC_SEARCH_LIBS(kinfo_getfile, [util util-freebsd])
715 # Look for a suitable queue.h.
716 AC_CHECK_DECL(
717         TAILQ_CONCAT,
718         found_queue_h=yes,
719         found_queue_h=no,
720         [#include <sys/queue.h>]
722 AC_CHECK_DECL(
723         TAILQ_PREV,
724         ,
725         found_queue_h=no,
726         [#include <sys/queue.h>]
728 AC_CHECK_DECL(
729         TAILQ_REPLACE,
730         ,
731         found_queue_h=no,
732         [#include <sys/queue.h>]
734 if test "x$found_queue_h" = xyes; then
735         AC_DEFINE(HAVE_QUEUE_H)
738 # Look for __progname.
739 AC_MSG_CHECKING(for __progname)
740 AC_LINK_IFELSE([AC_LANG_SOURCE(
741         [
742                 #include <stdio.h>
743                 #include <stdlib.h>
744                 extern char *__progname;
745                 int main(void) {
746                         const char *cp = __progname;
747                         printf("%s\n", cp);
748                         exit(0);
749                 }
750         ])],
751         [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
752         AC_MSG_RESULT(no)
755 # Look for program_invocation_short_name.
756 AC_MSG_CHECKING(for program_invocation_short_name)
757 AC_LINK_IFELSE([AC_LANG_SOURCE(
758         [
759                 #include <errno.h>
760                 #include <stdio.h>
761                 #include <stdlib.h>
762                 int main(void) {
763                         const char *cp = program_invocation_short_name;
764                         printf("%s\n", cp);
765                         exit(0);
766                 }
767         ])],
768         [AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME) AC_MSG_RESULT(yes)],
769         AC_MSG_RESULT(no)
772 # Look for prctl(PR_SET_NAME).
773 AC_CHECK_DECL(
774         PR_SET_NAME,
775         AC_DEFINE(HAVE_PR_SET_NAME),
776         ,
777         [#include <sys/prctl.h>]
780 # Look for setsockopt(SO_PEERCRED).
781 AC_CHECK_DECL(
782         SO_PEERCRED,
783         AC_DEFINE(HAVE_SO_PEERCRED),
784         ,
785         [#include <sys/socket.h>]
788 # Look for fcntl(F_CLOSEM).
789 AC_CHECK_DECL(
790         F_CLOSEM,
791         AC_DEFINE(HAVE_FCNTL_CLOSEM),
792         ,
793         [#include <fcntl.h>]
796 # Look for /proc/$$.
797 AC_MSG_CHECKING(for /proc/\$\$)
798 if test -d /proc/$$; then
799         AC_DEFINE(HAVE_PROC_PID)
800         AC_MSG_RESULT(yes)
801 else
802         AC_MSG_RESULT(no)
805 # Try to figure out what the best value for TERM might be.
806 if test "x$DEFAULT_TERM" = x; then
807         DEFAULT_TERM=screen
808         AC_MSG_CHECKING(TERM)
809         AC_RUN_IFELSE([AC_LANG_SOURCE(
810                 [
811                         #include <stdio.h>
812                         #include <stdlib.h>
813                         #if defined(HAVE_CURSES_H)
814                         #include <curses.h>
815                         #elif defined(HAVE_NCURSES_H)
816                         #include <ncurses.h>
817                         #endif
818                         #include <term.h>
819                         int main(void) {
820                                 if (setupterm("screen-256color", -1, NULL) != OK)
821                                         exit(1);
822                                 exit(0);
823                         }
824                  ])],
825                  [DEFAULT_TERM=screen-256color],
826                  ,
827                  [DEFAULT_TERM=screen]
828         )
829         AC_RUN_IFELSE([AC_LANG_SOURCE(
830                 [
831                         #include <stdio.h>
832                         #include <stdlib.h>
833                         #if defined(HAVE_CURSES_H)
834                         #include <curses.h>
835                         #elif defined(HAVE_NCURSES_H)
836                         #include <ncurses.h>
837                         #endif
838                         #include <term.h>
839                         int main(void) {
840                                 if (setupterm("tmux", -1, NULL) != OK)
841                                         exit(1);
842                                 exit(0);
843                         }
844                  ])],
845                  [DEFAULT_TERM=tmux],
846                  ,
847                  [DEFAULT_TERM=screen]
848         )
849         AC_RUN_IFELSE([AC_LANG_SOURCE(
850                 [
851                         #include <stdio.h>
852                         #include <stdlib.h>
853                         #if defined(HAVE_CURSES_H)
854                         #include <curses.h>
855                         #elif defined(HAVE_NCURSES_H)
856                         #include <ncurses.h>
857                         #endif
858                         #include <term.h>
859                         int main(void) {
860                                 if (setupterm("tmux-256color", -1, NULL) != OK)
861                                         exit(1);
862                                 exit(0);
863                         }
864                  ])],
865                  [DEFAULT_TERM=tmux-256color],
866                  ,
867                  [DEFAULT_TERM=screen]
868         )
869         AC_MSG_RESULT($DEFAULT_TERM)
871 AC_SUBST(DEFAULT_TERM)
873 # Man page defaults to mdoc.
874 MANFORMAT=mdoc
875 AC_SUBST(MANFORMAT)
877 # Figure out the platform.
878 AC_MSG_CHECKING(platform)
879 case "$host_os" in
880         *aix*)
881                 AC_MSG_RESULT(aix)
882                 PLATFORM=aix
883                 ;;
884         *darwin*)
885                 AC_MSG_RESULT(darwin)
886                 PLATFORM=darwin
887                 #
888                 # macOS uses __dead2 instead of __dead, like FreeBSD. But it defines
889                 # __dead away so it needs to be removed before we can replace it.
890                 #
891                 AC_DEFINE(BROKEN___DEAD)
892                 #
893                 # macOS CMSG_FIRSTHDR is broken, so redefine it with a working one.
894                 # daemon works but has some stupid side effects, so use our internal
895                 # version which has a workaround.
896                 #
897                 AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
898                 AC_LIBOBJ(daemon)
899                 AC_LIBOBJ(daemon-darwin)
900                 #
901                 # macOS wcwidth(3) is bad, so complain and suggest using utf8proc
902                 # instead.
903                 #
904                 if test "x$enable_utf8proc" = x; then
905                         AC_MSG_NOTICE([])
906                         AC_MSG_NOTICE([    macOS library support for Unicode is very poor,])
907                         AC_MSG_NOTICE([    particularly for complex codepoints like emojis;])
908                         AC_MSG_NOTICE([    to use these correctly, configuring with])
909                         AC_MSG_NOTICE([    --enable-utf8proc is recommended. To build])
910                         AC_MSG_NOTICE([    without anyway, use --disable-utf8proc])
911                         AC_MSG_NOTICE([])
912                         AC_MSG_ERROR([must give --enable-utf8proc or --disable-utf8proc])
913                 fi
914                 ;;
915         *dragonfly*)
916                 AC_MSG_RESULT(dragonfly)
917                 PLATFORM=dragonfly
918                 ;;
919         *linux*)
920                 AC_MSG_RESULT(linux)
921                 PLATFORM=linux
922                 ;;
923         *freebsd*)
924                 AC_MSG_RESULT(freebsd)
925                 PLATFORM=freebsd
926                 ;;
927         *netbsd*)
928                 AC_MSG_RESULT(netbsd)
929                 PLATFORM=netbsd
930                 ;;
931         *openbsd*)
932                 AC_MSG_RESULT(openbsd)
933                 PLATFORM=openbsd
934                 ;;
935         *sunos*)
936                 AC_MSG_RESULT(sunos)
937                 PLATFORM=sunos
938                 ;;
939         *solaris*)
940                 AC_MSG_RESULT(sunos)
941                 PLATFORM=sunos
942                 case `/usr/bin/nroff --version 2>&1` in
943                         *GNU*)
944                                 # Solaris 11.4 and later use GNU groff.
945                                 MANFORMAT=mdoc
946                                 ;;
947                         *)
948                                 if test `uname -o 2>/dev/null` = illumos; then
949                                         # Illumos uses mandoc.
950                                         MANFORMAT=mdoc
951                                 else
952                                         # Solaris 2.0 to 11.3 use AT&T nroff.
953                                         MANFORMAT=man
954                                 fi
955                                 ;;
956                 esac
957                 ;;
958         *hpux*)
959                 AC_MSG_RESULT(hpux)
960                 PLATFORM=hpux
961                 ;;
962         *cygwin*|*msys*)
963                 AC_MSG_RESULT(cygwin)
964                 PLATFORM=cygwin
965                 ;;
966         *haiku*)
967                 AC_MSG_RESULT(haiku)
968                 PLATFORM=haiku
969                 ;;
970         *)
971                 AC_MSG_RESULT(unknown)
972                 PLATFORM=unknown
973                 ;;
974 esac
975 AC_SUBST(PLATFORM)
976 AM_CONDITIONAL(IS_AIX, test "x$PLATFORM" = xaix)
977 AM_CONDITIONAL(IS_DARWIN, test "x$PLATFORM" = xdarwin)
978 AM_CONDITIONAL(IS_DRAGONFLY, test "x$PLATFORM" = xdragonfly)
979 AM_CONDITIONAL(IS_LINUX, test "x$PLATFORM" = xlinux)
980 AM_CONDITIONAL(IS_FREEBSD, test "x$PLATFORM" = xfreebsd)
981 AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd)
982 AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd)
983 AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos)
984 AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
985 AM_CONDITIONAL(IS_CYGWIN, test "x$PLATFORM" = xcygwin)
986 AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
987 AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
989 # Set the default lock command
990 DEFAULT_LOCK_CMD="lock -np"
991 AC_MSG_CHECKING(lock-command)
992 if test "x$PLATFORM" = xlinux; then
993         AC_CHECK_PROG(found_vlock, vlock, yes, no)
994         if test "x$found_vlock" = xyes; then
995                 DEFAULT_LOCK_CMD="vlock"
996         fi
998 AC_MSG_RESULT($DEFAULT_LOCK_CMD)
999 AC_SUBST(DEFAULT_LOCK_CMD)
1002 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
1003 # variables.
1004 AC_SUBST(AM_CPPFLAGS)
1005 CPPFLAGS="$SAVED_CPPFLAGS"
1006 AC_SUBST(AM_CFLAGS)
1007 CFLAGS="$SAVED_CFLAGS"
1008 AC_SUBST(AM_LDFLAGS)
1009 LDFLAGS="$SAVED_LDFLAGS"
1011 # autoconf should create a Makefile.
1012 AC_CONFIG_FILES(Makefile)
1013 AC_OUTPUT