1dnl***************************************************************************
2dnl Copyright 2018-2020,2021 Thomas E. Dickey                                *
3dnl Copyright 1998-2017,2018 Free Software Foundation, Inc.                  *
4dnl                                                                          *
5dnl Permission is hereby granted, free of charge, to any person obtaining a  *
6dnl copy of this software and associated documentation files (the            *
7dnl "Software"), to deal in the Software without restriction, including      *
8dnl without limitation the rights to use, copy, modify, merge, publish,      *
9dnl distribute, distribute with modifications, sublicense, and/or sell       *
10dnl copies of the Software, and to permit persons to whom the Software is    *
11dnl furnished to do so, subject to the following conditions:                 *
12dnl                                                                          *
13dnl The above copyright notice and this permission notice shall be included  *
14dnl in all copies or substantial portions of the Software.                   *
15dnl                                                                          *
16dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17dnl OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18dnl MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19dnl IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20dnl DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21dnl OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22dnl THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23dnl                                                                          *
24dnl Except as contained in this notice, the name(s) of the above copyright   *
25dnl holders shall not be used in advertising or otherwise to promote the     *
26dnl sale, use or other dealings in this Software without prior written       *
27dnl authorization.                                                           *
28dnl***************************************************************************
29dnl
30dnl Author: Thomas E. Dickey 1996-on
31dnl
32dnl $Id: configure.in,v 1.163 2021/07/03 20:21:07 tom Exp $
33dnl This is a simple configuration-script for the ncurses test programs that
34dnl allows the test-directory to be separately configured against a reference
35dnl system (i.e., sysvr4 curses)
36dnl
37dnl If you're configuring ncurses, you shouldn't need to use this script.
38dnl It's only for testing purposes.
39dnl
40dnl For additional information, see
41dnl		https://invisible-island.net/autoconf/
42dnl		https://invisible-island.net/autoconf/my-autoconf.html
43dnl		https://invisible-island.net/ncurses/ncurses-examples.html
44dnl ---------------------------------------------------------------------------
45AC_PREREQ(2.52.20210509)
46AC_INIT(ncurses.c)
47AC_CONFIG_HEADER(ncurses_cfg.h:ncurses_tst.hin)
48
49CF_INHERIT_SCRIPT(config.guess)
50CF_INHERIT_SCRIPT(config.sub)
51CF_CHECK_CACHE
52
53AC_ARG_PROGRAM
54
55CF_HELP_MESSAGE(General Options:)
56
57AC_PROG_MAKE_SET
58CF_PROG_CC
59AC_C_INLINE
60AC_PROG_CPP
61AC_PROG_AWK
62CF_PROG_INSTALL
63CF_INSTALL_OPTS
64CF_PROG_LINT
65CF_MAKE_PHONY
66CF_MAKE_TAGS
67
68CF_MATH_LIB(MATH_LIB,pow(sin(x),x))
69AC_SUBST(MATH_LIB)
70
71dnl Things that we don't need (or must override) if we're not building ncurses
72CF_TOP_BUILDDIR
73CC_G_OPT="-g"					AC_SUBST(CC_G_OPT)
74CC_SHARED_OPTS=unknown			AC_SUBST(CC_SHARED_OPTS)
75CPPFLAGS="$CPPFLAGS"			AC_SUBST(CPPFLAGS)
76DFT_DEP_SUFFIX=""				AC_SUBST(DFT_DEP_SUFFIX)
77DFT_OBJ_SUBDIR=`pwd|sed -e's:.*/::'`	AC_SUBST(DFT_OBJ_SUBDIR)
78DFT_UPR_MODEL="NORMAL"			AC_SUBST(DFT_UPR_MODEL)
79LD="ld"							AC_SUBST(LD)
80LDFLAGS_SHARED=""				AC_SUBST(LDFLAGS_SHARED)
81LDFLAGS_STATIC=""				AC_SUBST(LDFLAGS_STATIC)
82LD_MODEL=""						AC_SUBST(LD_MODEL)
83LD_SHARED_OPTS=""				AC_SUBST(LD_SHARED_OPTS)
84LIBTOOL=""						AC_SUBST(LIBTOOL)
85LIBTOOL_OPTS=""					AC_SUBST(LIBTOOL_OPTS)
86LIB_CLEAN=""					AC_SUBST(LIB_CLEAN)
87LIB_COMPILE=""					AC_SUBST(LIB_COMPILE)
88LIB_LINK='${CC}'				AC_SUBST(LIB_LINK)
89LINK_TESTS=""					AC_SUBST(LINK_TESTS)
90LOCAL_LDFLAGS=""				AC_SUBST(LOCAL_LDFLAGS)
91PACKAGE="ncurses-examples"		AC_SUBST(PACKAGE)
92PTHREAD="-lm"					AC_SUBST(PTHREAD)
93TEST_ARGS=""					AC_SUBST(TEST_ARGS)
94TEST_DEPS=""					AC_SUBST(TEST_DEPS)
95TEST_LIBS=""					AC_SUBST(TEST_LIBS)
96TINFO_LDFLAGS=''				AC_SUBST(TINFO_LDFLAGS)
97TINFO_LIBS='$(LIBS_CURSES)'		AC_SUBST(TINFO_LIBS)
98cf_cv_abi_version=""			AC_SUBST(cf_cv_abi_version)
99cf_cv_rel_version=""			AC_SUBST(cf_cv_rel_version)
100includesubdir=""				AC_SUBST(includesubdir)
101
102cf_cv_screen=curses
103cf_cv_libtype=
104
105AC_EXEEXT
106AC_OBJEXT
107
108CF_GCC_ATTRIBUTES
109CF_ENABLE_STRING_HACKS
110CF_XOPEN_SOURCE(600)
111CF_SIG_ATOMIC_T
112
113# Work around breakage on OS X
114CF_SIGWINCH
115
116# Checks for CODESET support.
117AM_LANGINFO_CODESET
118
119dnl ---------------------------------------------------------------------------
120CF_PKG_CONFIG
121CF_DISABLE_ECHO
122
123dnl ---------------------------------------------------------------------------
124CF_HELP_MESSAGE(Curses Version-dependent Options:)
125CF_NCURSES_WRAP_PREFIX
126
127AC_MSG_CHECKING(if you want to check for wide-character functions)
128CF_ARG_DISABLE(widec,
129	[  --disable-widec         disable checks for wide-character functions],
130	cf_enable_widec=no,
131	cf_enable_widec=yes,
132	yes)
133AC_MSG_RESULT($cf_enable_widec)
134
135dnl ---------------------------------------------------------------------------
136CF_HELP_MESSAGE(Curses Version-dependent Options:)
137CF_WITH_NCURSES_ETC
138
139case $cf_cv_screen in
140(ncurses*)
141	cf_cv_libtype=`echo "$cf_cv_screen" | sed -e 's/^ncurses//'`
142	;;
143esac
144
145CF_WITH_X11_RGB
146
147dnl If we've not specified a library, assume we're using sysvr4 libraries
148dnl installed conventionally (e.g., SunOS 5.x - solaris).
149
150dnl Autoconf builds up the $LIBS in reverse order
151
152cf_curses_headers=
153
154case $cf_cv_screen in
155(pdcurses)
156	cf_default_panel=no
157	cf_default_form=no
158	cf_default_menu=no
159	cf_default_tinfo=no
160	;;
161(xcurses|bsdcurses)
162	cf_default_panel=no
163	cf_default_form=no
164	cf_default_menu=no
165	cf_default_tinfo=yes
166	;;
167(*)
168	cf_default_panel=yes
169	cf_default_form=yes
170	cf_default_menu=yes
171	cf_default_tinfo=yes
172	case $cf_cv_screen in
173	(ncurses*)
174		cf_curses_headers="nc_alloc.h nomacros.h term_entry.h"
175		;;
176	esac
177	;;
178esac
179
180CF_WITH_LIB_BASENAME(FORM_NAME,form)
181CF_WITH_LIB_BASENAME(MENU_NAME,menu)
182CF_WITH_LIB_BASENAME(PANEL_NAME,panel)
183
184AC_MSG_CHECKING(if you want to check for panel functions)
185CF_ARG_DISABLE(panel,
186	[  --disable-panel         disable checks for panel functions],
187	cf_enable_panel=no,
188	cf_enable_panel=$cf_default_panel,
189	yes)
190AC_MSG_RESULT($cf_enable_panel)
191if test $cf_enable_panel = yes
192then
193	CF_CHECK_CURSES_LIB($PANEL_NAME,$cf_cv_libtype,new_panel,0)
194	cf_curses_headers="$cf_curses_headers panel.h"
195fi
196
197AC_MSG_CHECKING(if you want to check for menu functions)
198CF_ARG_DISABLE(menu,
199	[  --disable-menu          disable checks for menu functions],
200	cf_enable_menu=no,
201	cf_enable_menu=$cf_default_menu,
202	yes)
203AC_MSG_RESULT($cf_enable_menu)
204if test $cf_enable_menu = yes
205then
206	case $cf_cv_screen in
207	(ncurses*)
208		;;
209	(curses*)
210		CF_NETBSD_MENU_H
211		;;
212	esac
213	CF_CHECK_CURSES_LIB($MENU_NAME,$cf_cv_libtype,menu_driver,[0,0])
214	cf_curses_headers="$cf_curses_headers menu.h"
215fi
216
217AC_MSG_CHECKING(if you want to check for form functions)
218CF_ARG_DISABLE(form,
219	[  --disable-form          disable checks for form functions],
220	cf_enable_form=no,
221	cf_enable_form=$cf_default_form,
222	yes)
223AC_MSG_RESULT($cf_enable_form)
224if test $cf_enable_form = yes
225then
226	case $cf_cv_screen in
227	(ncurses*)
228		;;
229	(curses*)
230		CF_NETBSD_FORM_H
231		;;
232	esac
233	CF_CHECK_CURSES_LIB($FORM_NAME,$cf_cv_libtype,form_driver,[0,0])
234	cf_curses_headers="$cf_curses_headers form.h"
235fi
236
237# look for curses-related headers
238AC_CHECK_HEADERS( $cf_curses_headers )
239
240AC_STDC_HEADERS
241AC_HEADER_TIME
242AC_CHECK_HEADERS( \
243getopt.h \
244locale.h \
245math.h \
246stdarg.h \
247stdint.h \
248sys/ioctl.h \
249sys/select.h \
250sys/time.h \
251termios.h \
252unistd.h \
253)
254
255CF_GETOPT_HEADER
256
257AC_CHECK_FUNCS( \
258getopt \
259gettimeofday \
260snprintf \
261strdup \
262strstr \
263tsearch \
264)
265
266# use a compile-check to work with ncurses*-config and subdirectory includes
267AC_CACHE_CHECK(if we can use termcap.h,cf_cv_have_termcap_h,[
268	AC_TRY_COMPILE([
269#include <curses.h>
270#ifdef NCURSES_VERSION
271#undef NCURSES_VERSION
272#endif
273#include <termcap.h>
274#ifndef NCURSES_VERSION
275#error wrong header
276#endif
277],
278	[return 0;],
279	[cf_cv_have_termcap_h=yes],
280	[cf_cv_have_termcap_h=no])])
281if test "x$cf_cv_have_termcap_h" = xyes
282then
283	AC_DEFINE(HAVE_TERMCAP_H,1,[Define to 1 if we can use termcap.h])
284else
285AC_CACHE_CHECK(if we can use ncurses/termcap.h,cf_cv_have_ncurses_termcap_h,[
286	AC_TRY_COMPILE([
287#include <ncurses/curses.h>
288#ifdef NCURSES_VERSION
289#undef NCURSES_VERSION
290#endif
291#include <ncurses/termcap.h>
292#ifndef NCURSES_VERSION
293#error wrong header
294#endif
295],
296	[return 0;],
297	[cf_cv_have_ncurses_termcap_h=yes],
298	[cf_cv_have_ncurses_termcap_h=no])])
299test "x$cf_cv_have_ncurses_termcap_h" = xyes && AC_DEFINE(HAVE_NCURSES_TERMCAP_H,1,[Define to 1 if we can use ncurses/termcap.h])
300fi
301
302if test "x$ac_cv_func_getopt" = xno; then
303	AC_MSG_ERROR(getopt is required for building programs)
304fi
305
306if test "$cf_enable_widec" = yes; then
307AC_CHECK_FUNCS( \
308mblen \
309mbrlen \
310mbrtowc \
311mbsrtowcs \
312mbstowcs \
313mbtowc \
314wcsrtombs \
315wcstombs \
316)
317fi
318
319CF_CURSES_FUNCS( \
320alloc_pair \
321assume_default_colors \
322chgat \
323color_content \
324color_set \
325copywin \
326delscreen \
327dupwin \
328exit_curses \
329exit_terminfo \
330filter \
331getbegx \
332getcurx \
333getmaxx \
334getnstr \
335getparx \
336getwin \
337halfdelay \
338init_extended_color \
339mvderwin \
340mvvline \
341mvwin \
342mvwvline \
343napms \
344newpad \
345putwin \
346reset_color_pairs \
347resize_term \
348resizeterm \
349restartterm \
350ripoffline \
351scr_dump \
352setupterm \
353slk_color \
354slk_init \
355termattrs \
356termname \
357tgetent \
358tigetnum \
359tigetstr \
360tputs_sp \
361typeahead \
362use_default_colors \
363use_env \
364use_extended_names \
365use_screen \
366use_window \
367vid_puts \
368vidputs \
369vsscanf \
370vw_printw \
371wchgat \
372winsdelln \
373winsstr \
374wresize \
375wsyncdown \
376_tracef \
377)
378
379CF_TPUTS_PROTO
380CF_NCURSES_EXT_FUNCS
381
382if test "$cf_enable_widec" = yes
383then
384	# workaround for systems with ncurses before 20111029, due to change of
385	# feature test macro from _XPG5 to _XOPEN_SOURCE
386	if test -n "$cf_cv_ncurses_version" && test "x$cf_cv_ncurses_version" != xno
387	then
388		cf_define_xpg5=no
389		AC_MSG_CHECKING(if _XPG5 should be defined to enable wide-characters)
390
391		AC_TRY_COMPILE([
392#include <${cf_cv_ncurses_header:-curses.h}>],
393			[int x = _XPG5],,
394			[cf_save_cppflags="$CPPFLAGS"
395			 CPPFLAGS="$CPPFLAGS -D_XPG5"
396			 AC_TRY_COMPILE([
397#include <${cf_cv_ncurses_header:-curses.h}>],
398				[int x = _XPG5],
399				[cf_define_xpg5=yes])
400			 CPPFLAGS="$cf_save_cppflags"])
401		AC_MSG_RESULT($cf_define_xpg5)
402
403		if test "$cf_define_xpg5" = yes
404		then
405			CPPFLAGS="$CPPFLAGS -D_XPG5"
406		fi
407	fi
408
409	AC_CACHE_CHECK(for wide-character functions,cf_cv_widechar_funcs,[
410	AC_TRY_LINK([
411#include <${cf_cv_ncurses_header:-curses.h}>],
412	[
413		static wchar_t src_wchar[2];
414		static cchar_t dst_cchar;
415		setcchar(&dst_cchar, src_wchar, A_NORMAL, 0, (void *) 0);
416		],
417		[cf_cv_widechar_funcs=yes],
418		[cf_cv_widechar_funcs=no])
419	])
420	if test "$cf_cv_widechar_funcs" != no ; then
421		AC_DEFINE(USE_WIDEC_SUPPORT,1,[Define to 1 to enable wide-character support in (n)curses])
422	else
423		AC_DEFINE(USE_WIDEC_SUPPORT,0)
424	fi
425else
426	AC_DEFINE(USE_WIDEC_SUPPORT,0)
427fi
428
429AC_CACHE_CHECK(if $cf_cv_screen library uses pthreads,cf_cv_use_pthreads,[
430AC_TRY_LINK([
431#include <${cf_cv_ncurses_header:-curses.h}>
432extern void _nc_init_pthreads(void);
433],
434[
435	initscr();
436	_nc_init_pthreads();
437	],
438	[cf_cv_use_pthreads=yes],
439	[cf_cv_use_pthreads=no])
440])
441test $cf_cv_use_pthreads = yes && AC_DEFINE(USE_PTHREADS,1,[Define to 1 if $cf_cv_screen library uses pthreads])
442
443CF_SYS_TIME_SELECT
444
445# special check for test/ditto.c
446CF_FUNC_OPENPTY
447if test "$cf_cv_func_openpty" != no ; then
448	AC_DEFINE_UNQUOTED(USE_OPENPTY_HEADER,<$cf_cv_func_openpty>,[Define to actual header for openpty function])
449	AC_DEFINE(USE_XTERM_PTY,1,[Define to 1 if we should assume xterm pseudoterminal interface])
450	if test "x$cf_cv_lib_util" = xyes ; then
451		CF_ADD_LIB(util,TEST_LIBS)
452	fi
453fi
454
455CF_FUNC_CURSES_VERSION
456
457CF_CURSES_ACS_MAP
458if test "$cf_enable_widec" = yes; then
459	CF_CURSES_WACS_MAP
460	CF_CURSES_WACS_SYMBOLS
461fi
462
463CF_CURSES_CHECK_TYPE(attr_t,long)
464
465if test "$cf_enable_widec" = yes; then
466	CF_WCHAR_TYPE(mbstate_t, NCURSES_MBSTATE_T, NCURSES_OK_MBSTATE_T)
467	CF_WCHAR_TYPE(wchar_t,   NCURSES_WCHAR_T,   NCURSES_OK_WCHAR_T)
468	CF_WCHAR_TYPE(wint_t,    NCURSES_WINT_T,    NCURSES_OK_WINT_T)
469
470	if test "$NCURSES_OK_MBSTATE_T" = 0 ; then
471		CF_CURSES_CHECK_TYPE(mbstate_t,long)
472	fi
473
474	if test "$NCURSES_OK_WCHAR_T" = 0 ; then
475		CF_CURSES_CHECK_TYPE(wchar_t,long)
476	fi
477
478	if test "$NCURSES_OK_WINT_T" = 0 ; then
479		CF_CURSES_CHECK_TYPE(wint_t,long)
480	fi
481fi
482
483CF_CURSES_CHECK_DATA(\
484TABSIZE \
485curscr \
486ospeed \
487boolnames \
488boolfnames \
489ttytype)
490
491dnl ---------------------------------------------------------------------------
492CF_HELP_MESSAGE(Testing/development Options:)
493CF_WITH_SCREEN_PDCURSES
494CF_ENABLE_WARNINGS(Wno-unknown-pragmas)
495CF_DISABLE_LEAKS
496CF_DISABLE_RPATH_HACK
497
498TEST_ARGS="$LIBS"
499LIBS=
500
501dnl ---------------------------------------------------------------------------
502
503AC_OUTPUT(Makefile,[
504CF_PRG_RULES([$srcdir/mk-test.awk INSTALL=yes ECHO_LINK="$ECHO_LD"], .)
505	cat >>Makefile <<TEST_EOF
506
507# These rules are generated so we do not rely on suffix rules, which do not
508# work consistently for different make-programs (the '\$(MODEL)/' confuses
509# some, and the '\$x' confuses others).
510TEST_EOF
511
512LIST=`sed -e 's/[[ 	]].*//' -e '/^[[#@]]/d' $srcdir/modules`
513for N in $LIST
514do
515	cat >>Makefile <<TEST_EOF
516
517\$(MODEL)/$N.o : \$(srcdir)/$N.c \\
518	\$(srcdir)/test.priv.h \\
519	ncurses_cfg.h
520	$SHOW_CC
521	$ECHO_CC\$(CC) -c \$(CFLAGS_DEFAULT) -DMODULE_NAME="$N" \$(srcdir)/$N.c
522TEST_EOF
523done
524
525if test -f ../config.guess && test -f ../config.sub
526then
527	cat >>Makefile <<TEST_EOF
528
529# if we used CF_INHERIT for getting these files, we can remove them
530distclean::
531	rm -f config.guess config.sub
532TEST_EOF
533fi
534],[
535AWK="$AWK"
536ECHO_CC="$ECHO_CC"
537ECHO_LD="$ECHO_LD"
538SHOW_CC="$SHOW_LD"
539],cat)
540