Initialize copy_width before adjusting it, GitHub issue 3079.
[tmux.git] / configure.ac
blobfb0ee239dce62d726c7b9aa99052aee50a59bc8c
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         util.h \
134 # Look for sys_signame.
135 AC_SEARCH_LIBS(sys_signame, , AC_DEFINE(HAVE_SYS_SIGNAME))
137 # Look for fmod.
138 AC_CHECK_LIB(m, fmod)
140 # Look for library needed for flock.
141 AC_SEARCH_LIBS(flock, bsd)
143 # Check for functions that are replaced or omitted.
144 AC_CHECK_FUNCS([ \
145         dirfd \
146         flock \
147         prctl \
148         proc_pidinfo \
149         sysconf
152 # Check for functions with a compatibility implementation.
153 AC_REPLACE_FUNCS([ \
154         asprintf \
155         cfmakeraw \
156         clock_gettime \
157         closefrom \
158         explicit_bzero \
159         fgetln \
160         freezero \
161         getdtablecount \
162         getdtablesize \
163         getline \
164         getprogname \
165         memmem \
166         setenv \
167         setproctitle \
168         strcasestr \
169         strlcat \
170         strlcpy \
171         strndup \
172         strsep \
174 AC_FUNC_STRNLEN
176 # Check if strtonum works.
177 AC_MSG_CHECKING([for working strtonum])
178 AC_RUN_IFELSE([AC_LANG_PROGRAM(
179                 [#include <stdlib.h>],
180                 [return (strtonum("0", 0, 1, NULL) == 0 ? 0 : 1);]
181         )],
182         [AC_DEFINE(HAVE_STRTONUM) AC_MSG_RESULT(yes)],
183         [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)],
184         [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)]
187 # Clang sanitizers wrap reallocarray even if it isn't available on the target
188 # system. When compiled it always returns NULL and crashes the program. To
189 # detect this we need a more complicated test.
190 AC_MSG_CHECKING([for working reallocarray])
191 AC_RUN_IFELSE([AC_LANG_PROGRAM(
192                 [#include <stdlib.h>],
193                 [return (reallocarray(NULL, 1, 1) == NULL);]
194         )],
195         AC_MSG_RESULT(yes),
196         [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
197         [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
199 AC_MSG_CHECKING([for working recallocarray])
200 AC_RUN_IFELSE([AC_LANG_PROGRAM(
201                 [#include <stdlib.h>],
202                 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
203         )],
204         AC_MSG_RESULT(yes),
205         [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
206         [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
209 # Look for clock_gettime. Must come before event_init.
210 AC_SEARCH_LIBS(clock_gettime, rt)
212 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
213 # musl does not set optarg to NULL for flags without arguments (although it is
214 # not required to, but it is helpful) 3) there are probably other weird
215 # implementations.
216 AC_LIBOBJ(getopt)
218 # Look for libevent. Try libevent_core or libevent with pkg-config first then
219 # look for the library.
220 PKG_CHECK_MODULES(
221         LIBEVENT_CORE,
222         [libevent_core >= 2],
223         [
224                 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
225                 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
226                 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
227                 found_libevent=yes
228         ],
229         found_libevent=no
231 if test x$found_libevent = xno; then
232         PKG_CHECK_MODULES(
233                 LIBEVENT,
234                 [libevent >= 2],
235                 [
236                         AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
237                         CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
238                         LIBS="$LIBEVENT_LIBS $LIBS"
239                         found_libevent=yes
240                 ],
241                 found_libevent=no
242         )
244 if test x$found_libevent = xno; then
245         AC_SEARCH_LIBS(
246                 event_init,
247                 [event_core event event-1.4],
248                 found_libevent=yes,
249                 found_libevent=no
250         )
252 AC_CHECK_HEADER(
253         event2/event.h,
254         AC_DEFINE(HAVE_EVENT2_EVENT_H),
255         [
256                 AC_CHECK_HEADER(
257                         event.h,
258                         AC_DEFINE(HAVE_EVENT_H),
259                         found_libevent=no
260                 )
261         ]
263 if test "x$found_libevent" = xno; then
264         AC_MSG_ERROR("libevent not found")
267 # Look for ncurses or curses. Try pkg-config first then directly for the
268 # library.
269 PKG_CHECK_MODULES(
270         LIBTINFO,
271         tinfo,
272         [
273                 AM_CPPFLAGS="$LIBTINFO_CFLAGS $AM_CPPFLAGS"
274                 CPPFLAGS="$LIBTINFO_CFLAGS $SAVED_CPPFLAGS"
275                 LIBS="$LIBTINFO_LIBS $LIBS"
276                 found_ncurses=yes
277         ],
278         found_ncurses=no
280 if test "x$found_ncurses" = xno; then
281         PKG_CHECK_MODULES(
282                 LIBNCURSES,
283                 ncurses,
284                 [
285                         AM_CPPFLAGS="$LIBNCURSES_CFLAGS $AM_CPPFLAGS"
286                         CPPFLAGS="$LIBNCURSES_CFLAGS $SAVED_CPPFLAGS"
287                         LIBS="$LIBNCURSES_LIBS $LIBS"
288                         found_ncurses=yes
289                 ],
290                 found_ncurses=no
291         )
293 if test "x$found_ncurses" = xno; then
294         PKG_CHECK_MODULES(
295                 LIBNCURSESW,
296                 ncursesw,
297                 [
298                         AM_CPPFLAGS="$LIBNCURSESW_CFLAGS $AM_CPPFLAGS"
299                         CPPFLAGS="$LIBNCURSESW_CFLAGS $SAVED_CPPFLAGS"
300                         LIBS="$LIBNCURSESW_LIBS $LIBS"
301                         found_ncurses=yes
302                 ],
303                 found_ncurses=no
304         )
306 if test "x$found_ncurses" = xno; then
307         AC_SEARCH_LIBS(
308                 setupterm,
309                 [tinfo ncurses ncursesw],
310                 found_ncurses=yes,
311                 found_ncurses=no
312         )
313         if test "x$found_ncurses" = xyes; then
314                 AC_CHECK_HEADER(
315                         ncurses.h,
316                         LIBS="$LIBS -lncurses",
317                         found_ncurses=no
318                 )
319         fi
321 if test "x$found_ncurses" = xyes; then
322         CPPFLAGS="$CPPFLAGS -DHAVE_NCURSES_H"
323         AC_DEFINE(HAVE_NCURSES_H)
324 else
325         AC_CHECK_LIB(
326                 curses,
327                 setupterm,
328                 found_curses=yes,
329                 found_curses=no
330         )
331         AC_CHECK_HEADER(
332                 curses.h,
333                 ,
334                 found_curses=no
335         )
336         if test "x$found_curses" = xyes; then
337                 LIBS="$LIBS -lcurses"
338                 CPPFLAGS="$CPPFLAGS -DHAVE_CURSES_H"
339                 AC_DEFINE(HAVE_CURSES_H)
340         else
341                 AC_MSG_ERROR("curses not found")
342         fi
345 # Look for utempter.
346 AC_ARG_ENABLE(
347         utempter,
348         AS_HELP_STRING(--enable-utempter, use utempter if it is installed)
350 if test "x$enable_utempter" = xyes; then
351         AC_CHECK_HEADER(utempter.h, enable_utempter=yes, enable_utempter=no)
352         if test "x$enable_utempter" = xyes; then
353                 AC_SEARCH_LIBS(
354                         utempter_add_record,
355                         utempter,
356                         enable_utempter=yes,
357                         enable_utempter=no
358                 )
359         fi
360         if test "x$enable_utempter" = xyes; then
361                 AC_DEFINE(HAVE_UTEMPTER)
362         else
363                 AC_MSG_ERROR("utempter not found")
364         fi
367 # Look for utf8proc.
368 AC_ARG_ENABLE(
369         utf8proc,
370         AS_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
372 if test "x$enable_utf8proc" = xyes; then
373         AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no)
374         if test "x$enable_utf8proc" = xyes; then
375                 AC_SEARCH_LIBS(
376                         utf8proc_charwidth,
377                         utf8proc,
378                         enable_utf8proc=yes,
379                         enable_utf8proc=no
380                 )
381         fi
382         if test "x$enable_utf8proc" = xyes; then
383                 AC_DEFINE(HAVE_UTF8PROC)
384         else
385                 AC_MSG_ERROR("utf8proc not found")
386         fi
388 AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes])
390 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
391 AC_MSG_CHECKING(for b64_ntop)
392         AC_LINK_IFELSE([AC_LANG_PROGRAM(
393         [
394                 #include <sys/types.h>
395                 #include <netinet/in.h>
396                 #include <resolv.h>
397         ],
398         [
399                 b64_ntop(NULL, 0, NULL, 0);
400         ])],
401         found_b64_ntop=yes,
402         found_b64_ntop=no
404 AC_MSG_RESULT($found_b64_ntop)
405 OLD_LIBS="$LIBS"
406 if test "x$found_b64_ntop" = xno; then
407         AC_MSG_CHECKING(for b64_ntop with -lresolv)
408         LIBS="$OLD_LIBS -lresolv"
409         AC_LINK_IFELSE([AC_LANG_PROGRAM(
410                 [
411                         #include <sys/types.h>
412                         #include <netinet/in.h>
413                         #include <resolv.h>
414                 ],
415                 [
416                         b64_ntop(NULL, 0, NULL, 0);
417                 ])],
418                 found_b64_ntop=yes,
419                 found_b64_ntop=no
420         )
421         AC_MSG_RESULT($found_b64_ntop)
423 if test "x$found_b64_ntop" = xno; then
424         AC_MSG_CHECKING(for b64_ntop with -lnetwork)
425         LIBS="$OLD_LIBS -lnetwork"
426         AC_LINK_IFELSE([AC_LANG_PROGRAM(
427                 [
428                         #include <sys/types.h>
429                         #include <netinet/in.h>
430                         #include <resolv.h>
431                 ],
432                 [
433                         b64_ntop(NULL, 0, NULL, 0);
434                 ])],
435                 found_b64_ntop=yes,
436                 found_b64_ntop=no
437         )
438         AC_MSG_RESULT($found_b64_ntop)
440 if test "x$found_b64_ntop" = xyes; then
441         AC_DEFINE(HAVE_B64_NTOP)
442 else
443         LIBS="$OLD_LIBS"
444         AC_LIBOBJ(base64)
447 # Look for networking libraries.
448 AC_SEARCH_LIBS(inet_ntoa, nsl)
449 AC_SEARCH_LIBS(socket, socket)
450 AC_CHECK_LIB(xnet, socket)
452 # Check if using glibc and have malloc_trim(3). The glibc free(3) is pretty bad
453 # about returning memory to the kernel unless the application tells it when to
454 # with malloc_trim(3).
455 AC_MSG_CHECKING(if free doesn't work very well)
456 AC_LINK_IFELSE([AC_LANG_SOURCE(
457         [
458                 #include <stdlib.h>
459                 #ifdef __GLIBC__
460                 #include <malloc.h>
461                 int main(void) {
462                         malloc_trim (0);
463                         exit(0);
464                 }
465                 #else
466                 no
467                 #endif
468         ])],
469         found_malloc_trim=yes,
470         found_malloc_trim=no
472 AC_MSG_RESULT($found_malloc_trim)
473 if test "x$found_malloc_trim" = xyes; then
474         AC_DEFINE(HAVE_MALLOC_TRIM)
477 # Check for CMSG_DATA. On some platforms like HP-UX this requires UNIX 95
478 # (_XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED) (see xopen_networking(7)). On
479 # others, UNIX 03 (_XOPEN_SOURCE 600, see standards(7) on Solaris).
480 XOPEN_DEFINES=
481 AC_MSG_CHECKING(for CMSG_DATA)
482 AC_EGREP_CPP(
483         yes,
484         [
485                 #include <sys/socket.h>
486                 #ifdef CMSG_DATA
487                 yes
488                 #endif
489         ],
490         found_cmsg_data=yes,
491         found_cmsg_data=no
493 AC_MSG_RESULT($found_cmsg_data)
494 if test "x$found_cmsg_data" = xno; then
495         AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE_EXTENDED)
496         AC_EGREP_CPP(
497                 yes,
498                 [
499                         #define _XOPEN_SOURCE 1
500                         #define _XOPEN_SOURCE_EXTENDED 1
501                         #include <sys/socket.h>
502                         #ifdef CMSG_DATA
503                         yes
504                         #endif
505                 ],
506                 found_cmsg_data=yes,
507                 found_cmsg_data=no
508         )
509         AC_MSG_RESULT($found_cmsg_data)
510         if test "x$found_cmsg_data" = xyes; then
511                 XOPEN_DEFINES="-D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED"
512         fi
514 if test "x$found_cmsg_data" = xno; then
515         AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE 600)
516         AC_EGREP_CPP(
517                 yes,
518                 [
519                         #define _XOPEN_SOURCE 600
520                         #include <sys/socket.h>
521                         #ifdef CMSG_DATA
522                         yes
523                         #endif
524                 ],
525                 found_cmsg_data=yes,
526                 found_cmsg_data=no
527         )
528         AC_MSG_RESULT($found_cmsg_data)
529         if test "x$found_cmsg_data" = xyes; then
530                 XOPEN_DEFINES="-D_XOPEN_SOURCE=600"
531         else
532                 AC_MSG_ERROR("CMSG_DATA not found")
533         fi
535 AC_SUBST(XOPEN_DEFINES)
537 # Look for err and friends in err.h.
538 AC_CHECK_FUNC(err, found_err_h=yes, found_err_h=no)
539 AC_CHECK_FUNC(errx, , found_err_h=no)
540 AC_CHECK_FUNC(warn, , found_err_h=no)
541 AC_CHECK_FUNC(warnx, , found_err_h=no)
542 if test "x$found_err_h" = xyes; then
543         AC_CHECK_HEADER(err.h, , found_err_h=no)
544 else
545         AC_LIBOBJ(err)
548 # Look for imsg_init in libutil.
549 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
550 if test "x$found_imsg_init" = xyes; then
551         AC_DEFINE(HAVE_IMSG)
552 else
553         AC_LIBOBJ(imsg)
554         AC_LIBOBJ(imsg-buffer)
557 # Look for daemon, compat/daemon.c used if missing. Solaris 10 has it in
558 # libresolv, but no declaration anywhere, so check for declaration as well as
559 # function.
560 AC_CHECK_FUNC(daemon, found_daemon=yes, found_daemon=no)
561 AC_CHECK_DECL(
562         daemon,
563         ,
564         found_daemon=no,
565         [
566                 #include <stdlib.h>
567                 #include <unistd.h>
568         ]
570 if test "x$found_daemon" = xyes; then
571         AC_DEFINE(HAVE_DAEMON)
572 else
573         AC_LIBOBJ(daemon)
576 # Look for stravis, compat/{vis,unvis}.c used if missing.
577 AC_CHECK_FUNC(stravis, found_stravis=yes, found_stravis=no)
578 if test "x$found_stravis" = xyes; then
579         AC_MSG_CHECKING(if strnvis is broken)
580         AC_EGREP_HEADER([strnvis\(char \*, const char \*, size_t, int\)],
581                         vis.h,
582                         AC_MSG_RESULT(no),
583                         [found_stravis=no])
584         if test "x$found_stravis" = xno; then
585                 AC_MSG_RESULT(yes)
586         fi
588 if test "x$found_stravis" = xyes; then
589         AC_CHECK_DECL(
590                 VIS_DQ,
591                 ,
592                 found_stravis=no,
593                 [
594                         #include <stdlib.h>
595                         #include <vis.h>
596                 ]
599 if test "x$found_stravis" = xyes; then
600         AC_DEFINE(HAVE_VIS)
601 else
602         AC_LIBOBJ(vis)
603         AC_LIBOBJ(unvis)
606 # Look for fdforkpty and forkpty in libutil.
607 AC_SEARCH_LIBS(fdforkpty, util, found_fdforkpty=yes, found_fdforkpty=no)
608 if test "x$found_fdforkpty" = xyes; then
609         AC_DEFINE(HAVE_FDFORKPTY)
610 else
611         AC_LIBOBJ(fdforkpty)
613 AC_SEARCH_LIBS(forkpty, util, found_forkpty=yes, found_forkpty=no)
614 if test "x$found_forkpty" = xyes; then
615         AC_DEFINE(HAVE_FORKPTY)
617 AM_CONDITIONAL(NEED_FORKPTY, test "x$found_forkpty" = xno)
619 # Look for kinfo_getfile in libutil.
620 AC_SEARCH_LIBS(kinfo_getfile, [util util-freebsd])
622 # Look for a suitable queue.h.
623 AC_CHECK_DECL(
624         TAILQ_CONCAT,
625         found_queue_h=yes,
626         found_queue_h=no,
627         [#include <sys/queue.h>]
629 AC_CHECK_DECL(
630         TAILQ_PREV,
631         ,
632         found_queue_h=no,
633         [#include <sys/queue.h>]
635 AC_CHECK_DECL(
636         TAILQ_REPLACE,
637         ,
638         found_queue_h=no,
639         [#include <sys/queue.h>]
641 if test "x$found_queue_h" = xyes; then
642         AC_DEFINE(HAVE_QUEUE_H)
645 # Look for __progname.
646 AC_MSG_CHECKING(for __progname)
647 AC_LINK_IFELSE([AC_LANG_SOURCE(
648         [
649                 #include <stdio.h>
650                 #include <stdlib.h>
651                 extern char *__progname;
652                 int main(void) {
653                         const char *cp = __progname;
654                         printf("%s\n", cp);
655                         exit(0);
656                 }
657         ])],
658         [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
659         AC_MSG_RESULT(no)
662 # Look for program_invocation_short_name.
663 AC_MSG_CHECKING(for program_invocation_short_name)
664 AC_LINK_IFELSE([AC_LANG_SOURCE(
665         [
666                 #include <errno.h>
667                 #include <stdio.h>
668                 #include <stdlib.h>
669                 int main(void) {
670                         const char *cp = program_invocation_short_name;
671                         printf("%s\n", cp);
672                         exit(0);
673                 }
674         ])],
675         [AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME) AC_MSG_RESULT(yes)],
676         AC_MSG_RESULT(no)
679 # Look for prctl(PR_SET_NAME).
680 AC_CHECK_DECL(
681         PR_SET_NAME,
682         AC_DEFINE(HAVE_PR_SET_NAME),
683         ,
684         [#include <sys/prctl.h>]
687 # Look for fcntl(F_CLOSEM).
688 AC_CHECK_DECL(
689         F_CLOSEM,
690         AC_DEFINE(HAVE_FCNTL_CLOSEM),
691         ,
692         [#include <fcntl.h>]
695 # Look for /proc/$$.
696 AC_MSG_CHECKING(for /proc/\$\$)
697 if test -d /proc/$$; then
698         AC_DEFINE(HAVE_PROC_PID)
699         AC_MSG_RESULT(yes)
700 else
701         AC_MSG_RESULT(no)
704 # Try to figure out what the best value for TERM might be.
705 if test "x$DEFAULT_TERM" = x; then
706         DEFAULT_TERM=screen
707         AC_MSG_CHECKING(TERM)
708         AC_RUN_IFELSE([AC_LANG_SOURCE(
709                 [
710                         #include <stdio.h>
711                         #include <stdlib.h>
712                         #if defined(HAVE_CURSES_H)
713                         #include <curses.h>
714                         #elif defined(HAVE_NCURSES_H)
715                         #include <ncurses.h>
716                         #endif
717                         #include <term.h>
718                         int main(void) {
719                                 if (setupterm("screen-256color", -1, NULL) != OK)
720                                         exit(1);
721                                 exit(0);
722                         }
723                  ])],
724                  [DEFAULT_TERM=screen-256color],
725                  ,
726                  [DEFAULT_TERM=screen]
727         )
728         AC_RUN_IFELSE([AC_LANG_SOURCE(
729                 [
730                         #include <stdio.h>
731                         #include <stdlib.h>
732                         #if defined(HAVE_CURSES_H)
733                         #include <curses.h>
734                         #elif defined(HAVE_NCURSES_H)
735                         #include <ncurses.h>
736                         #endif
737                         #include <term.h>
738                         int main(void) {
739                                 if (setupterm("tmux", -1, NULL) != OK)
740                                         exit(1);
741                                 exit(0);
742                         }
743                  ])],
744                  [DEFAULT_TERM=tmux],
745                  ,
746                  [DEFAULT_TERM=screen]
747         )
748         AC_RUN_IFELSE([AC_LANG_SOURCE(
749                 [
750                         #include <stdio.h>
751                         #include <stdlib.h>
752                         #if defined(HAVE_CURSES_H)
753                         #include <curses.h>
754                         #elif defined(HAVE_NCURSES_H)
755                         #include <ncurses.h>
756                         #endif
757                         #include <term.h>
758                         int main(void) {
759                                 if (setupterm("tmux-256color", -1, NULL) != OK)
760                                         exit(1);
761                                 exit(0);
762                         }
763                  ])],
764                  [DEFAULT_TERM=tmux-256color],
765                  ,
766                  [DEFAULT_TERM=screen]
767         )
768         AC_MSG_RESULT($DEFAULT_TERM)
770 AC_SUBST(DEFAULT_TERM)
772 # Man page defaults to mdoc.
773 MANFORMAT=mdoc
774 AC_SUBST(MANFORMAT)
776 # Figure out the platform.
777 AC_MSG_CHECKING(platform)
778 case "$host_os" in
779         *aix*)
780                 AC_MSG_RESULT(aix)
781                 PLATFORM=aix
782                 ;;
783         *darwin*)
784                 AC_MSG_RESULT(darwin)
785                 PLATFORM=darwin
786                 #
787                 # macOS uses __dead2 instead of __dead, like FreeBSD. But it defines
788                 # __dead away so it needs to be removed before we can replace it.
789                 #
790                 AC_DEFINE(BROKEN___DEAD)
791                 #
792                 # macOS CMSG_FIRSTHDR is broken, so redefine it with a working one.
793                 # daemon works but has some stupid side effects, so use our internal
794                 # version which has a workaround.
795                 #
796                 AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
797                 AC_LIBOBJ(daemon)
798                 AC_LIBOBJ(daemon-darwin)
799                 #
800                 # macOS wcwidth(3) is bad, so complain and suggest using utf8proc
801                 # instead.
802                 #
803                 if test "x$enable_utf8proc" = x; then
804                         AC_MSG_NOTICE([])
805                         AC_MSG_NOTICE([    macOS library support for Unicode is very poor,])
806                         AC_MSG_NOTICE([    particularly for complex codepoints like emojis;])
807                         AC_MSG_NOTICE([    to use these correctly, configuring with])
808                         AC_MSG_NOTICE([    --enable-utf8proc is recommended. To build])
809                         AC_MSG_NOTICE([    without anyway, use --disable-utf8proc])
810                         AC_MSG_NOTICE([])
811                         AC_MSG_ERROR([must give --enable-utf8proc or --disable-utf8proc])
812                 fi
813                 ;;
814         *dragonfly*)
815                 AC_MSG_RESULT(dragonfly)
816                 PLATFORM=dragonfly
817                 ;;
818         *linux*)
819                 AC_MSG_RESULT(linux)
820                 PLATFORM=linux
821                 ;;
822         *freebsd*)
823                 AC_MSG_RESULT(freebsd)
824                 PLATFORM=freebsd
825                 ;;
826         *netbsd*)
827                 AC_MSG_RESULT(netbsd)
828                 PLATFORM=netbsd
829                 ;;
830         *openbsd*)
831                 AC_MSG_RESULT(openbsd)
832                 PLATFORM=openbsd
833                 ;;
834         *sunos*)
835                 AC_MSG_RESULT(sunos)
836                 PLATFORM=sunos
837                 ;;
838         *solaris*)
839                 AC_MSG_RESULT(sunos)
840                 PLATFORM=sunos
841                 case `/usr/bin/nroff --version 2>&1` in
842                         *GNU*)
843                                 # Solaris 11.4 and later use GNU groff.
844                                 MANFORMAT=mdoc
845                                 ;;
846                         *)
847                                 # Solaris 2.0 to 11.3 use AT&T nroff.
848                                 MANFORMAT=man
849                                 ;;
850                 esac
851                 ;;
852         *hpux*)
853                 AC_MSG_RESULT(hpux)
854                 PLATFORM=hpux
855                 ;;
856         *cygwin*|*msys*)
857                 AC_MSG_RESULT(cygwin)
858                 PLATFORM=cygwin
859                 ;;
860         *haiku*)
861                 AC_MSG_RESULT(haiku)
862                 PLATFORM=haiku
863                 ;;
864         *)
865                 AC_MSG_RESULT(unknown)
866                 PLATFORM=unknown
867                 ;;
868 esac
869 AC_SUBST(PLATFORM)
870 AM_CONDITIONAL(IS_AIX, test "x$PLATFORM" = xaix)
871 AM_CONDITIONAL(IS_DARWIN, test "x$PLATFORM" = xdarwin)
872 AM_CONDITIONAL(IS_DRAGONFLY, test "x$PLATFORM" = xdragonfly)
873 AM_CONDITIONAL(IS_LINUX, test "x$PLATFORM" = xlinux)
874 AM_CONDITIONAL(IS_FREEBSD, test "x$PLATFORM" = xfreebsd)
875 AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd)
876 AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd)
877 AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos)
878 AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
879 AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
880 AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
882 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
883 # variables.
884 AC_SUBST(AM_CPPFLAGS)
885 CPPFLAGS="$SAVED_CPPFLAGS"
886 AC_SUBST(AM_CFLAGS)
887 CFLAGS="$SAVED_CFLAGS"
888 AC_SUBST(AM_LDFLAGS)
889 LDFLAGS="$SAVED_LDFLAGS"
891 # autoconf should create a Makefile.
892 AC_CONFIG_FILES(Makefile)
893 AC_OUTPUT