xref: /netbsd-src/external/bsd/tmux/dist/configure.ac (revision f8cf1a9151c7af1cb0bd8b09c13c66bca599c027)
1# configure.ac
2
3AC_INIT([tmux], 3.5a)
4AC_PREREQ([2.60])
5
6AC_CONFIG_AUX_DIR(etc)
7AC_CONFIG_LIBOBJ_DIR(compat)
8AM_INIT_AUTOMAKE([foreign subdir-objects])
9
10AC_CANONICAL_HOST
11
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=""}
16
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.
20SAVED_CFLAGS="$CFLAGS"
21SAVED_CPPFLAGS="$CPPFLAGS"
22SAVED_LDFLAGS="$LDFLAGS"
23
24# Is this oss-fuzz build?
25AC_ARG_ENABLE(
26	fuzzing,
27	AS_HELP_STRING(--enable-fuzzing, build fuzzers)
28)
29AC_ARG_VAR(
30	FUZZING_LIBS,
31	AS_HELP_STRING(libraries to link fuzzing targets with)
32)
33
34# Set up convenient fuzzing defaults before initializing compiler.
35if 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"
42fi
43
44# Set up the compiler in two different ways and say yes we may want to install.
45AC_PROG_CC
46AM_PROG_CC_C_O
47m4_version_prereq(2.70, [AC_PROG_CC], [AC_PROG_CC_C99])
48AC_PROG_CPP
49AC_PROG_EGREP
50AC_PROG_INSTALL
51AC_PROG_YACC
52PKG_PROG_PKG_CONFIG
53AC_USE_SYSTEM_EXTENSIONS
54
55# Default tmux.conf goes in /etc not ${prefix}/etc.
56test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
57
58# Is this --enable-debug?
59AC_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]
64)
65AM_CONDITIONAL(IS_DEBUG, test "x$enable_debug" = xyes)
66
67# Is this a static build?
68AC_ARG_ENABLE(
69	static,
70	AS_HELP_STRING(--enable-static, create a static build)
71)
72if 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"
81fi
82
83# Allow default TERM to be set.
84AC_ARG_WITH(
85	TERM,
86	AS_HELP_STRING(--with-TERM, set default TERM),
87	[DEFAULT_TERM=$withval],
88	[DEFAULT_TERM=]
89)
90case "x$DEFAULT_TERM" in
91	xscreen*|xtmux*|x)
92	;;
93	*)
94		AC_MSG_ERROR("unsuitable TERM (must be screen* or tmux*)")
95	;;
96esac
97
98# Do we need fuzzers?
99AM_CONDITIONAL(NEED_FUZZING, test "x$enable_fuzzing" = xyes)
100
101# Is this gcc?
102AM_CONDITIONAL(IS_GCC, test "x$GCC" = xyes -a "x$enable_fuzzing" != xyes)
103
104# Is this Sun CC?
105AC_EGREP_CPP(
106	yes,
107	[
108		#ifdef __SUNPRO_C
109		yes
110		#endif
111	],
112	found_suncc=yes,
113	found_suncc=no
114)
115AM_CONDITIONAL(IS_SUNCC, test "x$found_suncc" = xyes)
116
117# Check for various headers. Alternatives included from compat.h.
118AC_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 \
134])
135
136# Look for sys_signame.
137AC_SEARCH_LIBS(sys_signame, , AC_DEFINE(HAVE_SYS_SIGNAME))
138
139# Look for fmod.
140AC_CHECK_LIB(m, fmod)
141
142# Look for library needed for flock.
143AC_SEARCH_LIBS(flock, bsd)
144
145# Check for functions that are replaced or omitted.
146AC_CHECK_FUNCS([ \
147	dirfd \
148	flock \
149	prctl \
150	proc_pidinfo \
151	getpeerucred \
152	sysconf
153])
154
155# Check for functions with a compatibility implementation.
156AC_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 \
179])
180AC_FUNC_STRNLEN
181
182# Check if strtonum works.
183AC_MSG_CHECKING([for working strtonum])
184AC_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)]
191)
192
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.
196AC_MSG_CHECKING([for working reallocarray])
197AC_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])]
204)
205AC_MSG_CHECKING([for working recallocarray])
206AC_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])]
213)
214
215# Look for clock_gettime. Must come before event_init.
216AC_SEARCH_LIBS(clock_gettime, rt)
217
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.
222AC_LIBOBJ(getopt)
223
224# Look for libevent. Try libevent_core or libevent with pkg-config first then
225# look for the library.
226PKG_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
236)
237if 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	)
249fi
250if 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	)
257fi
258AC_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	]
268)
269if test "x$found_libevent" = xno; then
270	AC_MSG_ERROR("libevent not found")
271fi
272
273# Look for yacc.
274AC_CHECK_PROG(found_yacc, $YACC, yes, no)
275if test "x$found_yacc" = xno; then
276	AC_MSG_ERROR("yacc not found")
277fi
278
279# Look for ncurses or curses. Try pkg-config first then directly for the
280# library.
281PKG_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
291)
292if 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	)
304fi
305if 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	)
317fi
318if 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
332fi
333if test "x$found_ncurses" = xyes; then
334	CPPFLAGS="$CPPFLAGS -DHAVE_NCURSES_H"
335	AC_DEFINE(HAVE_NCURSES_H)
336else
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
355fi
356AC_CHECK_FUNCS([ \
357	tiparm \
358	tiparm_s \
359])
360
361# Look for utempter.
362AC_ARG_ENABLE(
363	utempter,
364	AS_HELP_STRING(--enable-utempter, use utempter if it is installed)
365)
366if 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
381fi
382
383# Look for utf8proc.
384AC_ARG_ENABLE(
385	utf8proc,
386	AS_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
387)
388if 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
412fi
413AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes])
414
415# Check for systemd support.
416AC_ARG_ENABLE(
417	systemd,
418	AS_HELP_STRING(--enable-systemd, enable systemd integration)
419)
420if 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
437fi
438AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$found_systemd" = xyes])
439AC_ARG_ENABLE(
440	cgroups,
441	AS_HELP_STRING(--disable-cgroups, disable adding panes to new cgroups with systemd)
442)
443if test "x$enable_cgroups" = x; then
444	# Default to the same as $enable_systemd.
445	enable_cgroups=$enable_systemd
446fi
447if 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
453fi
454
455# Enable sixel support.
456AC_ARG_ENABLE(
457	sixel,
458	AS_HELP_STRING(--enable-sixel, enable sixel images)
459)
460if test "x$enable_sixel" = xyes; then
461	AC_DEFINE(ENABLE_SIXEL)
462fi
463AM_CONDITIONAL(ENABLE_SIXEL, [test "x$enable_sixel" = xyes])
464
465# Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
466AC_MSG_CHECKING(for b64_ntop)
467AC_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
478)
479AC_MSG_RESULT($found_b64_ntop)
480OLD_LIBS="$LIBS"
481if 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)
497fi
498if 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)
514fi
515if test "x$found_b64_ntop" = xyes; then
516	AC_DEFINE(HAVE_B64_NTOP)
517else
518	LIBS="$OLD_LIBS"
519	AC_LIBOBJ(base64)
520fi
521
522# Look for networking libraries.
523AC_SEARCH_LIBS(inet_ntoa, nsl)
524AC_SEARCH_LIBS(socket, socket)
525AC_CHECK_LIB(xnet, socket)
526
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).
530AC_MSG_CHECKING(if free doesn't work very well)
531AC_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
546)
547AC_MSG_RESULT($found_malloc_trim)
548if test "x$found_malloc_trim" = xyes; then
549	AC_DEFINE(HAVE_MALLOC_TRIM)
550fi
551
552# Build against jemalloc if requested.
553AC_ARG_ENABLE(
554	jemalloc,
555	AS_HELP_STRING(--enable-jemalloc, use jemalloc if it is installed)
556)
557if 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	)
568fi
569
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).
573XOPEN_DEFINES=
574AC_MSG_CHECKING(for CMSG_DATA)
575AC_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
585)
586AC_MSG_RESULT($found_cmsg_data)
587if 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
606fi
607if 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
627fi
628AC_SUBST(XOPEN_DEFINES)
629
630# Look for err and friends in err.h.
631AC_CHECK_FUNC(err, found_err_h=yes, found_err_h=no)
632AC_CHECK_FUNC(errx, , found_err_h=no)
633AC_CHECK_FUNC(warn, , found_err_h=no)
634AC_CHECK_FUNC(warnx, , found_err_h=no)
635if test "x$found_err_h" = xyes; then
636	AC_CHECK_HEADER(err.h, , found_err_h=no)
637else
638	AC_LIBOBJ(err)
639fi
640
641# Look for imsg_init in libutil.
642AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
643if test "x$found_imsg_init" = xyes; then
644	AC_DEFINE(HAVE_IMSG)
645else
646	AC_LIBOBJ(imsg)
647	AC_LIBOBJ(imsg-buffer)
648fi
649
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.
653AC_CHECK_FUNC(daemon, found_daemon=yes, found_daemon=no)
654AC_CHECK_DECL(
655	daemon,
656	,
657	found_daemon=no,
658	[
659		#include <stdlib.h>
660		#include <unistd.h>
661	]
662)
663if test "x$found_daemon" = xyes; then
664	AC_DEFINE(HAVE_DAEMON)
665else
666	AC_LIBOBJ(daemon)
667fi
668
669# Look for stravis, compat/{vis,unvis}.c used if missing.
670AC_CHECK_FUNC(stravis, found_stravis=yes, found_stravis=no)
671if 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
680fi
681if 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		]
690)
691fi
692if test "x$found_stravis" = xyes; then
693	AC_DEFINE(HAVE_VIS)
694else
695	AC_LIBOBJ(vis)
696	AC_LIBOBJ(unvis)
697fi
698
699# Look for fdforkpty and forkpty in libutil.
700AC_SEARCH_LIBS(fdforkpty, util, found_fdforkpty=yes, found_fdforkpty=no)
701if test "x$found_fdforkpty" = xyes; then
702	AC_DEFINE(HAVE_FDFORKPTY)
703else
704	AC_LIBOBJ(fdforkpty)
705fi
706AC_SEARCH_LIBS(forkpty, util, found_forkpty=yes, found_forkpty=no)
707if test "x$found_forkpty" = xyes; then
708	AC_DEFINE(HAVE_FORKPTY)
709fi
710AM_CONDITIONAL(NEED_FORKPTY, test "x$found_forkpty" = xno)
711
712# Look for kinfo_getfile in libutil.
713AC_SEARCH_LIBS(kinfo_getfile, [util util-freebsd])
714
715# Look for a suitable queue.h.
716AC_CHECK_DECL(
717	TAILQ_CONCAT,
718	found_queue_h=yes,
719	found_queue_h=no,
720	[#include <sys/queue.h>]
721)
722AC_CHECK_DECL(
723	TAILQ_PREV,
724	,
725	found_queue_h=no,
726	[#include <sys/queue.h>]
727)
728AC_CHECK_DECL(
729	TAILQ_REPLACE,
730	,
731	found_queue_h=no,
732	[#include <sys/queue.h>]
733)
734if test "x$found_queue_h" = xyes; then
735	AC_DEFINE(HAVE_QUEUE_H)
736fi
737
738# Look for __progname.
739AC_MSG_CHECKING(for __progname)
740AC_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)
753)
754
755# Look for program_invocation_short_name.
756AC_MSG_CHECKING(for program_invocation_short_name)
757AC_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)
770)
771
772# Look for prctl(PR_SET_NAME).
773AC_CHECK_DECL(
774	PR_SET_NAME,
775	AC_DEFINE(HAVE_PR_SET_NAME),
776	,
777	[#include <sys/prctl.h>]
778)
779
780# Look for setsockopt(SO_PEERCRED).
781AC_CHECK_DECL(
782	SO_PEERCRED,
783	AC_DEFINE(HAVE_SO_PEERCRED),
784	,
785	[#include <sys/socket.h>]
786)
787
788# Look for fcntl(F_CLOSEM).
789AC_CHECK_DECL(
790	F_CLOSEM,
791	AC_DEFINE(HAVE_FCNTL_CLOSEM),
792	,
793	[#include <fcntl.h>]
794)
795
796# Look for /proc/$$.
797AC_MSG_CHECKING(for /proc/\$\$)
798if test -d /proc/$$; then
799	AC_DEFINE(HAVE_PROC_PID)
800	AC_MSG_RESULT(yes)
801else
802	AC_MSG_RESULT(no)
803fi
804
805# Try to figure out what the best value for TERM might be.
806if 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)
870fi
871AC_SUBST(DEFAULT_TERM)
872
873# Man page defaults to mdoc.
874MANFORMAT=mdoc
875AC_SUBST(MANFORMAT)
876
877# Figure out the platform.
878AC_MSG_CHECKING(platform)
879case "$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		;;
974esac
975AC_SUBST(PLATFORM)
976AM_CONDITIONAL(IS_AIX, test "x$PLATFORM" = xaix)
977AM_CONDITIONAL(IS_DARWIN, test "x$PLATFORM" = xdarwin)
978AM_CONDITIONAL(IS_DRAGONFLY, test "x$PLATFORM" = xdragonfly)
979AM_CONDITIONAL(IS_LINUX, test "x$PLATFORM" = xlinux)
980AM_CONDITIONAL(IS_FREEBSD, test "x$PLATFORM" = xfreebsd)
981AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd)
982AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd)
983AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos)
984AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
985AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
986AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
987
988# Set the default lock command
989DEFAULT_LOCK_CMD="lock -np"
990AC_MSG_CHECKING(lock-command)
991if test "x$PLATFORM" = xlinux; then
992	AC_CHECK_PROG(found_vlock, vlock, yes, no)
993	if test "x$found_vlock" = xyes; then
994		DEFAULT_LOCK_CMD="vlock"
995	fi
996fi
997AC_MSG_RESULT($DEFAULT_LOCK_CMD)
998AC_SUBST(DEFAULT_LOCK_CMD)
999
1000
1001# Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
1002# variables.
1003AC_SUBST(AM_CPPFLAGS)
1004CPPFLAGS="$SAVED_CPPFLAGS"
1005AC_SUBST(AM_CFLAGS)
1006CFLAGS="$SAVED_CFLAGS"
1007AC_SUBST(AM_LDFLAGS)
1008LDFLAGS="$SAVED_LDFLAGS"
1009
1010# autoconf should create a Makefile.
1011AC_CONFIG_FILES(Makefile)
1012AC_OUTPUT
1013