Fix user hooks (which are strings not arrays).
[tmux.git] / configure.ac
bloba9c035d71ab7aca8eb0841b9d0d262eaa1de69fd
1 # configure.ac
3 AC_INIT([tmux], 3.3-rc)
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 ncurses or curses. Try pkg-config first then directly for the
271 # library.
272 PKG_CHECK_MODULES(
273         LIBTINFO,
274         tinfo,
275         [
276                 AM_CPPFLAGS="$LIBTINFO_CFLAGS $AM_CPPFLAGS"
277                 CPPFLAGS="$LIBTINFO_CFLAGS $SAVED_CPPFLAGS"
278                 LIBS="$LIBTINFO_LIBS $LIBS"
279                 found_ncurses=yes
280         ],
281         found_ncurses=no
283 if test "x$found_ncurses" = xno; then
284         PKG_CHECK_MODULES(
285                 LIBNCURSES,
286                 ncurses,
287                 [
288                         AM_CPPFLAGS="$LIBNCURSES_CFLAGS $AM_CPPFLAGS"
289                         CPPFLAGS="$LIBNCURSES_CFLAGS $SAVED_CPPFLAGS"
290                         LIBS="$LIBNCURSES_LIBS $LIBS"
291                         found_ncurses=yes
292                 ],
293                 found_ncurses=no
294         )
296 if test "x$found_ncurses" = xno; then
297         PKG_CHECK_MODULES(
298                 LIBNCURSESW,
299                 ncursesw,
300                 [
301                         AM_CPPFLAGS="$LIBNCURSESW_CFLAGS $AM_CPPFLAGS"
302                         CPPFLAGS="$LIBNCURSESW_CFLAGS $SAVED_CPPFLAGS"
303                         LIBS="$LIBNCURSESW_LIBS $LIBS"
304                         found_ncurses=yes
305                 ],
306                 found_ncurses=no
307         )
309 if test "x$found_ncurses" = xno; then
310         AC_SEARCH_LIBS(
311                 setupterm,
312                 [tinfo ncurses ncursesw],
313                 found_ncurses=yes,
314                 found_ncurses=no
315         )
316         if test "x$found_ncurses" = xyes; then
317                 AC_CHECK_HEADER(
318                         ncurses.h,
319                         LIBS="$LIBS -lncurses",
320                         found_ncurses=no
321                 )
322         fi
324 if test "x$found_ncurses" = xyes; then
325         CPPFLAGS="$CPPFLAGS -DHAVE_NCURSES_H"
326         AC_DEFINE(HAVE_NCURSES_H)
327 else
328         AC_CHECK_LIB(
329                 curses,
330                 setupterm,
331                 found_curses=yes,
332                 found_curses=no
333         )
334         AC_CHECK_HEADER(
335                 curses.h,
336                 ,
337                 found_curses=no
338         )
339         if test "x$found_curses" = xyes; then
340                 LIBS="$LIBS -lcurses"
341                 CPPFLAGS="$CPPFLAGS -DHAVE_CURSES_H"
342                 AC_DEFINE(HAVE_CURSES_H)
343         else
344                 AC_MSG_ERROR("curses not found")
345         fi
348 # Look for utempter.
349 AC_ARG_ENABLE(
350         utempter,
351         AS_HELP_STRING(--enable-utempter, use utempter if it is installed)
353 if test "x$enable_utempter" = xyes; then
354         AC_CHECK_HEADER(utempter.h, enable_utempter=yes, enable_utempter=no)
355         if test "x$enable_utempter" = xyes; then
356                 AC_SEARCH_LIBS(
357                         utempter_add_record,
358                         utempter,
359                         enable_utempter=yes,
360                         enable_utempter=no
361                 )
362         fi
363         if test "x$enable_utempter" = xyes; then
364                 AC_DEFINE(HAVE_UTEMPTER)
365         else
366                 AC_MSG_ERROR("utempter not found")
367         fi
370 # Look for utf8proc.
371 AC_ARG_ENABLE(
372         utf8proc,
373         AS_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
375 if test "x$enable_utf8proc" = xyes; then
376         AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no)
377         if test "x$enable_utf8proc" = xyes; then
378                 AC_SEARCH_LIBS(
379                         utf8proc_charwidth,
380                         utf8proc,
381                         enable_utf8proc=yes,
382                         enable_utf8proc=no
383                 )
384         fi
385         if test "x$enable_utf8proc" = xyes; then
386                 AC_DEFINE(HAVE_UTF8PROC)
387         else
388                 AC_MSG_ERROR("utf8proc not found")
389         fi
391 AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes])
393 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
394 AC_MSG_CHECKING(for b64_ntop)
395         AC_LINK_IFELSE([AC_LANG_PROGRAM(
396         [
397                 #include <sys/types.h>
398                 #include <netinet/in.h>
399                 #include <resolv.h>
400         ],
401         [
402                 b64_ntop(NULL, 0, NULL, 0);
403         ])],
404         found_b64_ntop=yes,
405         found_b64_ntop=no
407 AC_MSG_RESULT($found_b64_ntop)
408 OLD_LIBS="$LIBS"
409 if test "x$found_b64_ntop" = xno; then
410         AC_MSG_CHECKING(for b64_ntop with -lresolv)
411         LIBS="$OLD_LIBS -lresolv"
412         AC_LINK_IFELSE([AC_LANG_PROGRAM(
413                 [
414                         #include <sys/types.h>
415                         #include <netinet/in.h>
416                         #include <resolv.h>
417                 ],
418                 [
419                         b64_ntop(NULL, 0, NULL, 0);
420                 ])],
421                 found_b64_ntop=yes,
422                 found_b64_ntop=no
423         )
424         AC_MSG_RESULT($found_b64_ntop)
426 if test "x$found_b64_ntop" = xno; then
427         AC_MSG_CHECKING(for b64_ntop with -lnetwork)
428         LIBS="$OLD_LIBS -lnetwork"
429         AC_LINK_IFELSE([AC_LANG_PROGRAM(
430                 [
431                         #include <sys/types.h>
432                         #include <netinet/in.h>
433                         #include <resolv.h>
434                 ],
435                 [
436                         b64_ntop(NULL, 0, NULL, 0);
437                 ])],
438                 found_b64_ntop=yes,
439                 found_b64_ntop=no
440         )
441         AC_MSG_RESULT($found_b64_ntop)
443 if test "x$found_b64_ntop" = xyes; then
444         AC_DEFINE(HAVE_B64_NTOP)
445 else
446         LIBS="$OLD_LIBS"
447         AC_LIBOBJ(base64)
450 # Look for networking libraries.
451 AC_SEARCH_LIBS(inet_ntoa, nsl)
452 AC_SEARCH_LIBS(socket, socket)
453 AC_CHECK_LIB(xnet, socket)
455 # Check if using glibc and have malloc_trim(3). The glibc free(3) is pretty bad
456 # about returning memory to the kernel unless the application tells it when to
457 # with malloc_trim(3).
458 AC_MSG_CHECKING(if free doesn't work very well)
459 AC_LINK_IFELSE([AC_LANG_SOURCE(
460         [
461                 #include <stdlib.h>
462                 #ifdef __GLIBC__
463                 #include <malloc.h>
464                 int main(void) {
465                         malloc_trim (0);
466                         exit(0);
467                 }
468                 #else
469                 no
470                 #endif
471         ])],
472         found_malloc_trim=yes,
473         found_malloc_trim=no
475 AC_MSG_RESULT($found_malloc_trim)
476 if test "x$found_malloc_trim" = xyes; then
477         AC_DEFINE(HAVE_MALLOC_TRIM)
480 # Check for CMSG_DATA. On some platforms like HP-UX this requires UNIX 95
481 # (_XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED) (see xopen_networking(7)). On
482 # others, UNIX 03 (_XOPEN_SOURCE 600, see standards(7) on Solaris).
483 XOPEN_DEFINES=
484 AC_MSG_CHECKING(for CMSG_DATA)
485 AC_EGREP_CPP(
486         yes,
487         [
488                 #include <sys/socket.h>
489                 #ifdef CMSG_DATA
490                 yes
491                 #endif
492         ],
493         found_cmsg_data=yes,
494         found_cmsg_data=no
496 AC_MSG_RESULT($found_cmsg_data)
497 if test "x$found_cmsg_data" = xno; then
498         AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE_EXTENDED)
499         AC_EGREP_CPP(
500                 yes,
501                 [
502                         #define _XOPEN_SOURCE 1
503                         #define _XOPEN_SOURCE_EXTENDED 1
504                         #include <sys/socket.h>
505                         #ifdef CMSG_DATA
506                         yes
507                         #endif
508                 ],
509                 found_cmsg_data=yes,
510                 found_cmsg_data=no
511         )
512         AC_MSG_RESULT($found_cmsg_data)
513         if test "x$found_cmsg_data" = xyes; then
514                 XOPEN_DEFINES="-D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED"
515         fi
517 if test "x$found_cmsg_data" = xno; then
518         AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE 600)
519         AC_EGREP_CPP(
520                 yes,
521                 [
522                         #define _XOPEN_SOURCE 600
523                         #include <sys/socket.h>
524                         #ifdef CMSG_DATA
525                         yes
526                         #endif
527                 ],
528                 found_cmsg_data=yes,
529                 found_cmsg_data=no
530         )
531         AC_MSG_RESULT($found_cmsg_data)
532         if test "x$found_cmsg_data" = xyes; then
533                 XOPEN_DEFINES="-D_XOPEN_SOURCE=600"
534         else
535                 AC_MSG_ERROR("CMSG_DATA not found")
536         fi
538 AC_SUBST(XOPEN_DEFINES)
540 # Look for err and friends in err.h.
541 AC_CHECK_FUNC(err, found_err_h=yes, found_err_h=no)
542 AC_CHECK_FUNC(errx, , found_err_h=no)
543 AC_CHECK_FUNC(warn, , found_err_h=no)
544 AC_CHECK_FUNC(warnx, , found_err_h=no)
545 if test "x$found_err_h" = xyes; then
546         AC_CHECK_HEADER(err.h, , found_err_h=no)
547 else
548         AC_LIBOBJ(err)
551 # Look for imsg_init in libutil.
552 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
553 if test "x$found_imsg_init" = xyes; then
554         AC_DEFINE(HAVE_IMSG)
555 else
556         AC_LIBOBJ(imsg)
557         AC_LIBOBJ(imsg-buffer)
560 # Look for daemon, compat/daemon.c used if missing. Solaris 10 has it in
561 # libresolv, but no declaration anywhere, so check for declaration as well as
562 # function.
563 AC_CHECK_FUNC(daemon, found_daemon=yes, found_daemon=no)
564 AC_CHECK_DECL(
565         daemon,
566         ,
567         found_daemon=no,
568         [
569                 #include <stdlib.h>
570                 #include <unistd.h>
571         ]
573 if test "x$found_daemon" = xyes; then
574         AC_DEFINE(HAVE_DAEMON)
575 else
576         AC_LIBOBJ(daemon)
579 # Look for stravis, compat/{vis,unvis}.c used if missing.
580 AC_CHECK_FUNC(stravis, found_stravis=yes, found_stravis=no)
581 if test "x$found_stravis" = xyes; then
582         AC_MSG_CHECKING(if strnvis is broken)
583         AC_EGREP_HEADER([strnvis\(char \*, const char \*, size_t, int\)],
584                         vis.h,
585                         AC_MSG_RESULT(no),
586                         [found_stravis=no])
587         if test "x$found_stravis" = xno; then
588                 AC_MSG_RESULT(yes)
589         fi
591 if test "x$found_stravis" = xyes; then
592         AC_CHECK_DECL(
593                 VIS_DQ,
594                 ,
595                 found_stravis=no,
596                 [
597                         #include <stdlib.h>
598                         #include <vis.h>
599                 ]
602 if test "x$found_stravis" = xyes; then
603         AC_DEFINE(HAVE_VIS)
604 else
605         AC_LIBOBJ(vis)
606         AC_LIBOBJ(unvis)
609 # Look for fdforkpty and forkpty in libutil.
610 AC_SEARCH_LIBS(fdforkpty, util, found_fdforkpty=yes, found_fdforkpty=no)
611 if test "x$found_fdforkpty" = xyes; then
612         AC_DEFINE(HAVE_FDFORKPTY)
613 else
614         AC_LIBOBJ(fdforkpty)
616 AC_SEARCH_LIBS(forkpty, util, found_forkpty=yes, found_forkpty=no)
617 if test "x$found_forkpty" = xyes; then
618         AC_DEFINE(HAVE_FORKPTY)
620 AM_CONDITIONAL(NEED_FORKPTY, test "x$found_forkpty" = xno)
622 # Look for kinfo_getfile in libutil.
623 AC_SEARCH_LIBS(kinfo_getfile, [util util-freebsd])
625 # Look for a suitable queue.h.
626 AC_CHECK_DECL(
627         TAILQ_CONCAT,
628         found_queue_h=yes,
629         found_queue_h=no,
630         [#include <sys/queue.h>]
632 AC_CHECK_DECL(
633         TAILQ_PREV,
634         ,
635         found_queue_h=no,
636         [#include <sys/queue.h>]
638 AC_CHECK_DECL(
639         TAILQ_REPLACE,
640         ,
641         found_queue_h=no,
642         [#include <sys/queue.h>]
644 if test "x$found_queue_h" = xyes; then
645         AC_DEFINE(HAVE_QUEUE_H)
648 # Look for __progname.
649 AC_MSG_CHECKING(for __progname)
650 AC_LINK_IFELSE([AC_LANG_SOURCE(
651         [
652                 #include <stdio.h>
653                 #include <stdlib.h>
654                 extern char *__progname;
655                 int main(void) {
656                         const char *cp = __progname;
657                         printf("%s\n", cp);
658                         exit(0);
659                 }
660         ])],
661         [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
662         AC_MSG_RESULT(no)
665 # Look for program_invocation_short_name.
666 AC_MSG_CHECKING(for program_invocation_short_name)
667 AC_LINK_IFELSE([AC_LANG_SOURCE(
668         [
669                 #include <errno.h>
670                 #include <stdio.h>
671                 #include <stdlib.h>
672                 int main(void) {
673                         const char *cp = program_invocation_short_name;
674                         printf("%s\n", cp);
675                         exit(0);
676                 }
677         ])],
678         [AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME) AC_MSG_RESULT(yes)],
679         AC_MSG_RESULT(no)
682 # Look for prctl(PR_SET_NAME).
683 AC_CHECK_DECL(
684         PR_SET_NAME,
685         AC_DEFINE(HAVE_PR_SET_NAME),
686         ,
687         [#include <sys/prctl.h>]
690 # Look for setsockopt(SO_PEERCRED).
691 AC_CHECK_DECL(
692         SO_PEERCRED,
693         AC_DEFINE(HAVE_SO_PEERCRED),
694         ,
695         [#include <sys/socket.h>]
698 # Look for fcntl(F_CLOSEM).
699 AC_CHECK_DECL(
700         F_CLOSEM,
701         AC_DEFINE(HAVE_FCNTL_CLOSEM),
702         ,
703         [#include <fcntl.h>]
706 # Look for /proc/$$.
707 AC_MSG_CHECKING(for /proc/\$\$)
708 if test -d /proc/$$; then
709         AC_DEFINE(HAVE_PROC_PID)
710         AC_MSG_RESULT(yes)
711 else
712         AC_MSG_RESULT(no)
715 # Try to figure out what the best value for TERM might be.
716 if test "x$DEFAULT_TERM" = x; then
717         DEFAULT_TERM=screen
718         AC_MSG_CHECKING(TERM)
719         AC_RUN_IFELSE([AC_LANG_SOURCE(
720                 [
721                         #include <stdio.h>
722                         #include <stdlib.h>
723                         #if defined(HAVE_CURSES_H)
724                         #include <curses.h>
725                         #elif defined(HAVE_NCURSES_H)
726                         #include <ncurses.h>
727                         #endif
728                         #include <term.h>
729                         int main(void) {
730                                 if (setupterm("screen-256color", -1, NULL) != OK)
731                                         exit(1);
732                                 exit(0);
733                         }
734                  ])],
735                  [DEFAULT_TERM=screen-256color],
736                  ,
737                  [DEFAULT_TERM=screen]
738         )
739         AC_RUN_IFELSE([AC_LANG_SOURCE(
740                 [
741                         #include <stdio.h>
742                         #include <stdlib.h>
743                         #if defined(HAVE_CURSES_H)
744                         #include <curses.h>
745                         #elif defined(HAVE_NCURSES_H)
746                         #include <ncurses.h>
747                         #endif
748                         #include <term.h>
749                         int main(void) {
750                                 if (setupterm("tmux", -1, NULL) != OK)
751                                         exit(1);
752                                 exit(0);
753                         }
754                  ])],
755                  [DEFAULT_TERM=tmux],
756                  ,
757                  [DEFAULT_TERM=screen]
758         )
759         AC_RUN_IFELSE([AC_LANG_SOURCE(
760                 [
761                         #include <stdio.h>
762                         #include <stdlib.h>
763                         #if defined(HAVE_CURSES_H)
764                         #include <curses.h>
765                         #elif defined(HAVE_NCURSES_H)
766                         #include <ncurses.h>
767                         #endif
768                         #include <term.h>
769                         int main(void) {
770                                 if (setupterm("tmux-256color", -1, NULL) != OK)
771                                         exit(1);
772                                 exit(0);
773                         }
774                  ])],
775                  [DEFAULT_TERM=tmux-256color],
776                  ,
777                  [DEFAULT_TERM=screen]
778         )
779         AC_MSG_RESULT($DEFAULT_TERM)
781 AC_SUBST(DEFAULT_TERM)
783 # Man page defaults to mdoc.
784 MANFORMAT=mdoc
785 AC_SUBST(MANFORMAT)
787 # Figure out the platform.
788 AC_MSG_CHECKING(platform)
789 case "$host_os" in
790         *aix*)
791                 AC_MSG_RESULT(aix)
792                 PLATFORM=aix
793                 ;;
794         *darwin*)
795                 AC_MSG_RESULT(darwin)
796                 PLATFORM=darwin
797                 #
798                 # macOS uses __dead2 instead of __dead, like FreeBSD. But it defines
799                 # __dead away so it needs to be removed before we can replace it.
800                 #
801                 AC_DEFINE(BROKEN___DEAD)
802                 #
803                 # macOS CMSG_FIRSTHDR is broken, so redefine it with a working one.
804                 # daemon works but has some stupid side effects, so use our internal
805                 # version which has a workaround.
806                 #
807                 AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
808                 AC_LIBOBJ(daemon)
809                 AC_LIBOBJ(daemon-darwin)
810                 #
811                 # macOS wcwidth(3) is bad, so complain and suggest using utf8proc
812                 # instead.
813                 #
814                 if test "x$enable_utf8proc" = x; then
815                         AC_MSG_NOTICE([])
816                         AC_MSG_NOTICE([    macOS library support for Unicode is very poor,])
817                         AC_MSG_NOTICE([    particularly for complex codepoints like emojis;])
818                         AC_MSG_NOTICE([    to use these correctly, configuring with])
819                         AC_MSG_NOTICE([    --enable-utf8proc is recommended. To build])
820                         AC_MSG_NOTICE([    without anyway, use --disable-utf8proc])
821                         AC_MSG_NOTICE([])
822                         AC_MSG_ERROR([must give --enable-utf8proc or --disable-utf8proc])
823                 fi
824                 ;;
825         *dragonfly*)
826                 AC_MSG_RESULT(dragonfly)
827                 PLATFORM=dragonfly
828                 ;;
829         *linux*)
830                 AC_MSG_RESULT(linux)
831                 PLATFORM=linux
832                 ;;
833         *freebsd*)
834                 AC_MSG_RESULT(freebsd)
835                 PLATFORM=freebsd
836                 ;;
837         *netbsd*)
838                 AC_MSG_RESULT(netbsd)
839                 PLATFORM=netbsd
840                 ;;
841         *openbsd*)
842                 AC_MSG_RESULT(openbsd)
843                 PLATFORM=openbsd
844                 ;;
845         *sunos*)
846                 AC_MSG_RESULT(sunos)
847                 PLATFORM=sunos
848                 ;;
849         *solaris*)
850                 AC_MSG_RESULT(sunos)
851                 PLATFORM=sunos
852                 case `/usr/bin/nroff --version 2>&1` in
853                         *GNU*)
854                                 # Solaris 11.4 and later use GNU groff.
855                                 MANFORMAT=mdoc
856                                 ;;
857                         *)
858                                 # Solaris 2.0 to 11.3 use AT&T nroff.
859                                 MANFORMAT=man
860                                 ;;
861                 esac
862                 ;;
863         *hpux*)
864                 AC_MSG_RESULT(hpux)
865                 PLATFORM=hpux
866                 ;;
867         *cygwin*|*msys*)
868                 AC_MSG_RESULT(cygwin)
869                 PLATFORM=cygwin
870                 ;;
871         *haiku*)
872                 AC_MSG_RESULT(haiku)
873                 PLATFORM=haiku
874                 ;;
875         *)
876                 AC_MSG_RESULT(unknown)
877                 PLATFORM=unknown
878                 ;;
879 esac
880 AC_SUBST(PLATFORM)
881 AM_CONDITIONAL(IS_AIX, test "x$PLATFORM" = xaix)
882 AM_CONDITIONAL(IS_DARWIN, test "x$PLATFORM" = xdarwin)
883 AM_CONDITIONAL(IS_DRAGONFLY, test "x$PLATFORM" = xdragonfly)
884 AM_CONDITIONAL(IS_LINUX, test "x$PLATFORM" = xlinux)
885 AM_CONDITIONAL(IS_FREEBSD, test "x$PLATFORM" = xfreebsd)
886 AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd)
887 AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd)
888 AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos)
889 AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
890 AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
891 AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
893 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
894 # variables.
895 AC_SUBST(AM_CPPFLAGS)
896 CPPFLAGS="$SAVED_CPPFLAGS"
897 AC_SUBST(AM_CFLAGS)
898 CFLAGS="$SAVED_CFLAGS"
899 AC_SUBST(AM_LDFLAGS)
900 LDFLAGS="$SAVED_LDFLAGS"
902 # autoconf should create a Makefile.
903 AC_CONFIG_FILES(Makefile)
904 AC_OUTPUT