xref: /freebsd/contrib/ncurses/aclocal.m4 (revision c17d43407fe04133a94055b0dbc7ea8965654a9f)
1dnl***************************************************************************
2dnl Copyright (c) 1998-2000 Free Software Foundation, Inc.                   *
3dnl                                                                          *
4dnl Permission is hereby granted, free of charge, to any person obtaining a  *
5dnl copy of this software and associated documentation files (the            *
6dnl "Software"), to deal in the Software without restriction, including      *
7dnl without limitation the rights to use, copy, modify, merge, publish,      *
8dnl distribute, distribute with modifications, sublicense, and/or sell       *
9dnl copies of the Software, and to permit persons to whom the Software is    *
10dnl furnished to do so, subject to the following conditions:                 *
11dnl                                                                          *
12dnl The above copyright notice and this permission notice shall be included  *
13dnl in all copies or substantial portions of the Software.                   *
14dnl                                                                          *
15dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16dnl OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17dnl MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18dnl IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19dnl DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20dnl OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21dnl THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22dnl                                                                          *
23dnl Except as contained in this notice, the name(s) of the above copyright   *
24dnl holders shall not be used in advertising or otherwise to promote the     *
25dnl sale, use or other dealings in this Software without prior written       *
26dnl authorization.                                                           *
27dnl***************************************************************************
28dnl
29dnl Author: Thomas E. Dickey 1996,1997,1998,1999,2000
30dnl
31dnl $Id: aclocal.m4,v 1.248 2001/04/21 19:40:04 tom Exp $
32dnl Macros used in NCURSES auto-configuration script.
33dnl
34dnl See http://dickey.his.com/autoconf/ for additional information.
35dnl
36dnl ---------------------------------------------------------------------------
37dnl ---------------------------------------------------------------------------
38dnl Construct the list of include-options for the C programs in the Ada95
39dnl binding.
40AC_DEFUN([CF_ADA_INCLUDE_DIRS],
41[
42ACPPFLAGS="$ACPPFLAGS -I. -I../../include"
43if test "$srcdir" != "."; then
44	ACPPFLAGS="$ACPPFLAGS -I\$(srcdir)/../../include"
45fi
46if test "$GCC" != yes; then
47	ACPPFLAGS="$ACPPFLAGS -I\$(includedir)"
48elif test "$includedir" != "/usr/include"; then
49	if test "$includedir" = '${prefix}/include' ; then
50		if test $prefix != /usr ; then
51			ACPPFLAGS="$ACPPFLAGS -I\$(includedir)"
52		fi
53	else
54		ACPPFLAGS="$ACPPFLAGS -I\$(includedir)"
55	fi
56fi
57AC_SUBST(ACPPFLAGS)
58])dnl
59dnl ---------------------------------------------------------------------------
60dnl Copy non-preprocessor flags to $CFLAGS, preprocessor flags to $CPPFLAGS
61AC_DEFUN([CF_ADD_CFLAGS],
62[
63for cf_add_cflags in $1
64do
65	case $cf_add_cflags in #(vi
66	-undef|-nostdinc*|-I*|-D*|-U*|-E|-P|-C) #(vi
67		case "$CPPFLAGS" in
68		*$cf_add_cflags)
69			;;
70		*)
71			CPPFLAGS="$CPPFLAGS $cf_add_cflags"
72			;;
73		esac
74		;;
75	*)
76		CFLAGS="$CFLAGS $cf_add_cflags"
77		;;
78	esac
79done
80])dnl
81dnl ---------------------------------------------------------------------------
82dnl This is adapted from the macros 'fp_PROG_CC_STDC' and 'fp_C_PROTOTYPES'
83dnl in the sharutils 4.2 distribution.
84AC_DEFUN([CF_ANSI_CC_CHECK],
85[
86AC_MSG_CHECKING(for ${CC-cc} option to accept ANSI C)
87AC_CACHE_VAL(cf_cv_ansi_cc,[
88cf_cv_ansi_cc=no
89cf_save_CFLAGS="$CFLAGS"
90cf_save_CPPFLAGS="$CPPFLAGS"
91# Don't try gcc -ansi; that turns off useful extensions and
92# breaks some systems' header files.
93# AIX			-qlanglvl=ansi
94# Ultrix and OSF/1	-std1
95# HP-UX			-Aa -D_HPUX_SOURCE
96# SVR4			-Xc
97# UnixWare 1.2		(cannot use -Xc, since ANSI/POSIX clashes)
98for cf_arg in "-DCC_HAS_PROTOS" \
99	"" \
100	-qlanglvl=ansi \
101	-std1 \
102	-Ae \
103	"-Aa -D_HPUX_SOURCE" \
104	-Xc
105do
106	CF_ADD_CFLAGS($cf_arg)
107	AC_TRY_COMPILE(
108[
109#ifndef CC_HAS_PROTOS
110#if !defined(__STDC__) || (__STDC__ != 1)
111choke me
112#endif
113#endif
114],[
115	int test (int i, double x);
116	struct s1 {int (*f) (int a);};
117	struct s2 {int (*f) (double a);};],
118	[cf_cv_ansi_cc="$cf_arg"; break])
119done
120CFLAGS="$cf_save_CFLAGS"
121CPPFLAGS="$cf_save_CPPFLAGS"
122])
123AC_MSG_RESULT($cf_cv_ansi_cc)
124
125if test "$cf_cv_ansi_cc" != "no"; then
126if test ".$cf_cv_ansi_cc" != ".-DCC_HAS_PROTOS"; then
127	CF_ADD_CFLAGS($cf_cv_ansi_cc)
128else
129	AC_DEFINE(CC_HAS_PROTOS)
130fi
131fi
132])dnl
133dnl ---------------------------------------------------------------------------
134dnl For programs that must use an ANSI compiler, obtain compiler options that
135dnl will make it recognize prototypes.  We'll do preprocessor checks in other
136dnl macros, since tools such as unproto can fake prototypes, but only part of
137dnl the preprocessor.
138AC_DEFUN([CF_ANSI_CC_REQD],
139[AC_REQUIRE([CF_ANSI_CC_CHECK])
140if test "$cf_cv_ansi_cc" = "no"; then
141	AC_ERROR(
142[Your compiler does not appear to recognize prototypes.
143You have the following choices:
144	a. adjust your compiler options
145	b. get an up-to-date compiler
146	c. use a wrapper such as unproto])
147fi
148])dnl
149dnl ---------------------------------------------------------------------------
150dnl Test if 'bool' is a builtin type in the configured C++ compiler.  Some
151dnl older compilers (e.g., gcc 2.5.8) don't support 'bool' directly; gcc
152dnl 2.6.3 does, in anticipation of the ANSI C++ standard.
153dnl
154dnl Treat the configuration-variable specially here, since we're directly
155dnl substituting its value (i.e., 1/0).
156AC_DEFUN([CF_BOOL_DECL],
157[
158AC_MSG_CHECKING([for builtin bool type])
159AC_CACHE_VAL(ifelse($1,,cf_cv_builtin_bool,[$1]),[
160	AC_TRY_COMPILE([
161#include <stdio.h>
162#include <sys/types.h>
163],[bool x = false],
164		[ifelse($1,,cf_cv_builtin_bool,[$1])=1],
165		[ifelse($1,,cf_cv_builtin_bool,[$1])=0])
166	])
167if test "$ifelse($1,,cf_cv_builtin_bool,[$1])" = 1
168then	AC_MSG_RESULT(yes)
169else	AC_MSG_RESULT(no)
170fi
171])dnl
172dnl ---------------------------------------------------------------------------
173dnl Test for the size of 'bool' in the configured C++ compiler (e.g., a type).
174dnl Don't bother looking for bool.h, since it's been deprecated.
175AC_DEFUN([CF_BOOL_SIZE],
176[
177AC_MSG_CHECKING([for size of bool])
178AC_CACHE_VAL(cf_cv_type_of_bool,[
179	rm -f cf_test.out
180	AC_TRY_RUN([
181#include <stdlib.h>
182#include <stdio.h>
183#ifdef HAVE_GXX_BUILTIN_H
184#include <g++/builtin.h>
185#elif HAVE_GPP_BUILTIN_H
186#include <gpp/builtin.h>
187#elif HAVE_BUILTIN_H
188#include <builtin.h>
189#endif
190main()
191{
192	FILE *fp = fopen("cf_test.out", "w");
193	if (fp != 0) {
194		bool x = true;
195		if ((bool)(-x) >= 0)
196			fputs("unsigned ", fp);
197		if (sizeof(x) == sizeof(int))       fputs("int",  fp);
198		else if (sizeof(x) == sizeof(char)) fputs("char", fp);
199		else if (sizeof(x) == sizeof(short))fputs("short",fp);
200		else if (sizeof(x) == sizeof(long)) fputs("long", fp);
201		fclose(fp);
202	}
203	exit(0);
204}
205		],
206		[cf_cv_type_of_bool=`cat cf_test.out`],
207		[cf_cv_type_of_bool=unknown],
208		[cf_cv_type_of_bool=unknown])
209	])
210	rm -f cf_test.out
211AC_MSG_RESULT($cf_cv_type_of_bool)
212if test "$cf_cv_type_of_bool" = unknown ; then
213	AC_MSG_WARN(Assuming unsigned for type of bool)
214	cf_cv_type_of_bool=unsigned
215fi
216])dnl
217dnl ---------------------------------------------------------------------------
218dnl Determine the default configuration into which we'll install ncurses.  This
219dnl can be overridden by the user's command-line options.  There's two items to
220dnl look for:
221dnl	1. the prefix (e.g., /usr)
222dnl	2. the header files (e.g., /usr/include/ncurses)
223dnl We'll look for a previous installation of ncurses and use the same defaults.
224dnl
225dnl We don't use AC_PREFIX_DEFAULT, because it gets evaluated too soon, and
226dnl we don't use AC_PREFIX_PROGRAM, because we cannot distinguish ncurses's
227dnl programs from a vendor's.
228AC_DEFUN([CF_CFG_DEFAULTS],
229[
230AC_MSG_CHECKING(for prefix)
231if test "x$prefix" = "xNONE" ; then
232	case "$cf_cv_system_name" in
233		# non-vendor systems don't have a conflict
234	openbsd*|netbsd*|freebsd*|linux*|cygwin*)
235		prefix=/usr
236		;;
237	*)	prefix=$ac_default_prefix
238		;;
239	esac
240fi
241AC_MSG_RESULT($prefix)
242
243if test "x$prefix" = "xNONE" ; then
244AC_MSG_CHECKING(for default include-directory)
245test -n "$verbose" && echo 1>&AC_FD_MSG
246for cf_symbol in \
247	$includedir \
248	$includedir/ncurses \
249	$prefix/include \
250	$prefix/include/ncurses \
251	/usr/local/include \
252	/usr/local/include/ncurses \
253	/usr/include \
254	/usr/include/ncurses
255do
256	cf_dir=`eval echo $cf_symbol`
257	if test -f $cf_dir/curses.h ; then
258	if ( fgrep NCURSES_VERSION $cf_dir/curses.h 2>&1 >/dev/null ) ; then
259		includedir="$cf_symbol"
260		test -n "$verbose"  && echo $ac_n "	found " 1>&AC_FD_MSG
261		break
262	fi
263	fi
264	test -n "$verbose"  && echo "	tested $cf_dir" 1>&AC_FD_MSG
265done
266AC_MSG_RESULT($includedir)
267fi
268])dnl
269dnl ---------------------------------------------------------------------------
270dnl Check if the terminal-capability database functions are available.  If not,
271dnl ncurses has a much-reduced version.
272AC_DEFUN([CF_CGETENT],[
273AC_MSG_CHECKING(for terminal-capability database functions)
274AC_CACHE_VAL(cf_cv_cgetent,[
275AC_TRY_LINK([
276#include <stdlib.h>],[
277	char temp[128];
278	char *buf = temp;
279	char *db_array = temp;
280	cgetent(&buf, /* int *, */ &db_array, "vt100");
281	cgetcap(buf, "tc", '=');
282	cgetmatch(buf, "tc");
283	],
284	[cf_cv_cgetent=yes],
285	[cf_cv_cgetent=no])
286])
287AC_MSG_RESULT($cf_cv_cgetent)
288test "$cf_cv_cgetent" = yes && AC_DEFINE(HAVE_BSD_CGETENT)
289])dnl
290dnl ---------------------------------------------------------------------------
291dnl Check if we're accidentally using a cache from a different machine.
292dnl Derive the system name, as a check for reusing the autoconf cache.
293dnl
294dnl If we've packaged config.guess and config.sub, run that (since it does a
295dnl better job than uname).  Normally we'll use AC_CANONICAL_HOST, but allow
296dnl an extra parameter that we may override, e.g., for AC_CANONICAL_SYSTEM
297dnl which is useful in cross-compiles.
298AC_DEFUN([CF_CHECK_CACHE],
299[
300if test -f $srcdir/config.guess ; then
301	ifelse([$1],,[AC_CANONICAL_HOST],[$1])
302	system_name="$host_os"
303else
304	system_name="`(uname -s -r) 2>/dev/null`"
305	if test -z "$system_name" ; then
306		system_name="`(hostname) 2>/dev/null`"
307	fi
308fi
309test -n "$system_name" && AC_DEFINE_UNQUOTED(SYSTEM_NAME,"$system_name")
310AC_CACHE_VAL(cf_cv_system_name,[cf_cv_system_name="$system_name"])
311
312test -z "$system_name" && system_name="$cf_cv_system_name"
313test -n "$cf_cv_system_name" && AC_MSG_RESULT("Configuring for $cf_cv_system_name")
314
315if test ".$system_name" != ".$cf_cv_system_name" ; then
316	AC_MSG_RESULT(Cached system name ($system_name) does not agree with actual ($cf_cv_system_name))
317	AC_ERROR("Please remove config.cache and try again.")
318fi
319])dnl
320dnl ---------------------------------------------------------------------------
321dnl Check for data that is usually declared in <stdio.h> or <errno.h>, e.g.,
322dnl the 'errno' variable.  Define a DECL_xxx symbol if we must declare it
323dnl ourselves.
324dnl
325dnl (I would use AC_CACHE_CHECK here, but it will not work when called in a
326dnl loop from CF_SYS_ERRLIST).
327dnl
328dnl $1 = the name to check
329AC_DEFUN([CF_CHECK_ERRNO],
330[
331AC_MSG_CHECKING(if external $1 is declared)
332AC_CACHE_VAL(cf_cv_dcl_$1,[
333    AC_TRY_COMPILE([
334#ifdef HAVE_STDLIB_H
335#include <stdlib.h>
336#endif
337#include <stdio.h>
338#include <sys/types.h>
339#include <errno.h> ],
340    [long x = (long) $1],
341    [eval 'cf_cv_dcl_'$1'=yes'],
342    [eval 'cf_cv_dcl_'$1'=no'])
343])
344
345eval 'cf_result=$cf_cv_dcl_'$1
346AC_MSG_RESULT($cf_result)
347
348if test "$cf_result" = no ; then
349    eval 'cf_result=DECL_'$1
350    CF_UPPER(cf_result,$cf_result)
351    AC_DEFINE_UNQUOTED($cf_result)
352fi
353
354# It's possible (for near-UNIX clones) that the data doesn't exist
355CF_CHECK_EXTERN_DATA($1,int)
356])dnl
357dnl ---------------------------------------------------------------------------
358dnl Check for existence of external data in the current set of libraries.  If
359dnl we can modify it, it's real enough.
360dnl $1 = the name to check
361dnl $2 = its type
362AC_DEFUN([CF_CHECK_EXTERN_DATA],
363[
364AC_MSG_CHECKING(if external $1 exists)
365AC_CACHE_VAL(cf_cv_have_$1,[
366    AC_TRY_LINK([
367#undef $1
368extern $2 $1;
369],
370    [$1 = 2],
371    [eval 'cf_cv_have_'$1'=yes'],
372    [eval 'cf_cv_have_'$1'=no'])])
373
374eval 'cf_result=$cf_cv_have_'$1
375AC_MSG_RESULT($cf_result)
376
377if test "$cf_result" = yes ; then
378    eval 'cf_result=HAVE_'$1
379    CF_UPPER(cf_result,$cf_result)
380    AC_DEFINE_UNQUOTED($cf_result)
381fi
382
383])dnl
384dnl ---------------------------------------------------------------------------
385dnl Check if the C++ compiler accepts duplicate parameter initialization.  This
386dnl is a late feature for the standard and is not in some recent compilers
387dnl (1999/9/11).
388AC_DEFUN([CF_CPP_PARAM_INIT],
389[
390if test -n "$CXX"; then
391AC_CACHE_CHECK(if $CXX accepts parameter initialization,cf_cv_cpp_param_init,[
392	AC_LANG_SAVE
393	AC_LANG_CPLUSPLUS
394	AC_TRY_RUN([
395class TEST {
396private:
397	int value;
398public:
399	TEST(int x = 1);
400	~TEST();
401};
402
403TEST::TEST(int x = 1)	// some compilers do not like second initializer
404{
405	value = x;
406}
407void main() { }
408],
409	[cf_cv_cpp_param_init=yes],
410	[cf_cv_cpp_param_init=no],
411	[cf_cv_cpp_param_init=unknown])
412	AC_LANG_RESTORE
413])
414fi
415test "$cf_cv_cpp_param_init" = yes && AC_DEFINE(CPP_HAS_PARAM_INIT)
416])dnl
417dnl ---------------------------------------------------------------------------
418dnl Check if the g++ compiler supports vscan function (not a standard feature).
419AC_DEFUN([CF_CPP_VSCAN_FUNC],
420[
421if test -n "$CXX"; then
422
423AC_LANG_SAVE
424AC_LANG_CPLUSPLUS
425AC_CHECK_HEADERS(strstream.h)
426
427AC_CACHE_CHECK(if $CXX supports vscan function,cf_cv_cpp_vscan_func,[
428	for cf_vscan_func in strstream stdio
429	do
430	case $cf_vscan_func in #(vi
431	stdio)		cf_vscan_defs=USE_STDIO_VSCAN ;; #(vi
432	strstream)	cf_vscan_defs=USE_STRSTREAM_VSCAN ;;
433	esac
434	AC_TRY_LINK([
435#include <stdio.h>
436#include <stdarg.h>
437#define $cf_vscan_defs 1
438#if defined(USE_STDIO_VSCAN)
439#elif defined(HAVE_STRSTREAM_H) && defined(USE_STRSTREAM_VSCAN)
440#include <strstream.h>
441#endif
442
443int scanw(const char* fmt, ...)
444{
445    int result = -1;
446#if defined(__GNUG__)
447    char buf[BUFSIZ];
448
449    va_list args;
450    va_start(args, fmt);
451#if defined(USE_STDIO_VSCAN)
452    if (::vscanf(fmt, args) != -1)
453	result = 0;
454#elif defined(USE_STRSTREAM_VSCAN)
455    strstreambuf ss(buf, sizeof(buf));
456    if (ss.vscan(fmt, (_IO_va_list)args) != -1)
457	result = 0;
458#else
459#error case $cf_vscan_func failed
460#endif
461    va_end(args);
462#else
463#error sorry, we only know about the GNU compiler case
464#endif
465    return result;
466}
467],[int tmp, foo = scanw("%d", &tmp)],
468	[cf_cv_cpp_vscan_func=$cf_vscan_func; break],
469	[cf_cv_cpp_vscan_func=no])
470	test "$cf_cv_cpp_vscan_func" != no && break
471	done
472])
473
474AC_LANG_RESTORE
475fi
476
477case $cf_cv_cpp_vscan_func in #(vi
478stdio) #(vi
479	AC_DEFINE(CPP_HAS_VSCAN_FUNC)
480	AC_DEFINE(USE_STDIO_VSCAN)
481	;;
482strstream)
483	AC_DEFINE(CPP_HAS_VSCAN_FUNC)
484	AC_DEFINE(USE_STRSTREAM_VSCAN)
485	;;
486esac
487])dnl
488dnl ---------------------------------------------------------------------------
489dnl "dirname" is not portable, so we fake it with a shell script.
490AC_DEFUN([CF_DIRNAME],[$1=`echo $2 | sed -e 's:/[[^/]]*$::'`])dnl
491dnl ---------------------------------------------------------------------------
492AC_DEFUN([CF_DIRS_TO_MAKE],
493[
494DIRS_TO_MAKE="lib"
495for cf_item in $cf_list_models
496do
497	CF_OBJ_SUBDIR($cf_item,cf_subdir)
498	DIRS_TO_MAKE="$DIRS_TO_MAKE $cf_subdir"
499done
500for cf_dir in $DIRS_TO_MAKE
501do
502	test ! -d $cf_dir && mkdir $cf_dir
503done
504AC_SUBST(DIRS_TO_MAKE)
505])dnl
506dnl ---------------------------------------------------------------------------
507dnl Check if 'errno' is declared in <errno.h>
508AC_DEFUN([CF_ERRNO],
509[
510CF_CHECK_ERRNO(errno)
511])dnl
512dnl ---------------------------------------------------------------------------
513dnl Test for conflicting definitions of exception in gcc 2.8.0, etc., between
514dnl math.h and builtin.h, only for ncurses
515AC_DEFUN([CF_ETIP_DEFINES],
516[
517AC_MSG_CHECKING(for special defines needed for etip.h)
518cf_save_CXXFLAGS="$CXXFLAGS"
519cf_result="none"
520for cf_math in "" MATH_H
521do
522for cf_excp in "" MATH_EXCEPTION
523do
524	CXXFLAGS="$cf_save_CXXFLAGS -I${srcdir}/c++ -I${srcdir}/menu"
525	test -n "$cf_math" && CXXFLAGS="$CXXFLAGS -DETIP_NEEDS_${cf_math}"
526	test -n "$cf_excp" && CXXFLAGS="$CXXFLAGS -DETIP_NEEDS_${cf_excp}"
527AC_TRY_COMPILE([
528#include <etip.h.in>
529],[],[
530	test -n "$cf_math" && AC_DEFINE_UNQUOTED(ETIP_NEEDS_${cf_math})
531	test -n "$cf_excp" && AC_DEFINE_UNQUOTED(ETIP_NEEDS_${cf_excp})
532	cf_result="$cf_math $cf_excp"
533	break
534],[])
535done
536done
537AC_MSG_RESULT($cf_result)
538CXXFLAGS="$cf_save_CXXFLAGS"
539])
540dnl ---------------------------------------------------------------------------
541dnl Check for memmove, or a bcopy that can handle overlapping copy.  If neither
542dnl is found, add our own version of memmove to the list of objects.
543AC_DEFUN([CF_FUNC_MEMMOVE],
544[
545AC_CHECK_FUNC(memmove,,[
546AC_CHECK_FUNC(bcopy,[
547	AC_CACHE_CHECK(if bcopy does overlapping moves,cf_cv_good_bcopy,[
548		AC_TRY_RUN([
549int main() {
550	static char data[] = "abcdefghijklmnopqrstuwwxyz";
551	char temp[40];
552	bcopy(data, temp, sizeof(data));
553	bcopy(temp+10, temp, 15);
554	bcopy(temp+5, temp+15, 10);
555	exit (strcmp(temp, "klmnopqrstuwwxypqrstuwwxyz"));
556}
557		],
558		[cf_cv_good_bcopy=yes],
559		[cf_cv_good_bcopy=no],
560		[cf_cv_good_bcopy=unknown])
561		])
562	],[cf_cv_good_bcopy=no])
563	if test "$cf_cv_good_bcopy" = yes ; then
564		AC_DEFINE(USE_OK_BCOPY)
565	else
566		AC_DEFINE(USE_MY_MEMMOVE)
567	fi
568])])dnl
569dnl ---------------------------------------------------------------------------
570dnl See if the poll function really works.  Some platforms have poll(), but
571dnl it does not work for terminals or files.
572AC_DEFUN([CF_FUNC_POLL],[
573AC_CACHE_CHECK(if poll really works,cf_cv_working_poll,[
574AC_TRY_RUN([
575#include <stdio.h>
576#ifdef HAVE_POLL_H
577#include <poll.h>
578#else
579#include <sys/poll.h>
580#endif
581int main() {
582	struct pollfd myfds;
583	int ret;
584
585	myfds.fd = 0;
586	myfds.events = POLLIN;
587
588	ret = poll(&myfds, 1, 100);
589	exit(ret != 0);
590}],
591	[cf_cv_working_poll=yes],
592	[cf_cv_working_poll=no],
593	[cf_cv_working_poll=unknown])])
594test "$cf_cv_working_poll" = "yes" && AC_DEFINE(HAVE_WORKING_POLL)
595])dnl
596dnl ---------------------------------------------------------------------------
597dnl Some old/broken variations define tcgetattr() only as a macro in
598dnl termio(s).h
599AC_DEFUN([CF_FUNC_TERMIOS],[
600AC_REQUIRE([CF_STRUCT_TERMIOS])
601AC_CACHE_CHECK(for tcgetattr, cf_cv_have_tcgetattr,[
602AC_TRY_LINK([
603#include <sys/types.h>
604#ifdef HAVE_UNISTD_H
605#include <unistd.h>
606#endif
607#ifdef HAVE_TERMIOS_H
608#include <termios.h>
609#define TTY struct termios
610#else
611#ifdef HAVE_TERMIO_H
612#include <termio.h>
613#define TTY struct termio
614#endif
615#endif
616],[
617TTY foo;
618tcgetattr(1, &foo);],
619[cf_cv_have_tcgetattr=yes],
620[cf_cv_have_tcgetattr=no])])
621test "$cf_cv_have_tcgetattr" = yes && AC_DEFINE(HAVE_TCGETATTR)
622])dnl
623dnl ---------------------------------------------------------------------------
624dnl Test for availability of useful gcc __attribute__ directives to quiet
625dnl compiler warnings.  Though useful, not all are supported -- and contrary
626dnl to documentation, unrecognized directives cause older compilers to barf.
627AC_DEFUN([CF_GCC_ATTRIBUTES],
628[
629if test "$GCC" = yes
630then
631cat > conftest.i <<EOF
632#ifndef GCC_PRINTF
633#define GCC_PRINTF 0
634#endif
635#ifndef GCC_SCANF
636#define GCC_SCANF 0
637#endif
638#ifndef GCC_NORETURN
639#define GCC_NORETURN /* nothing */
640#endif
641#ifndef GCC_UNUSED
642#define GCC_UNUSED /* nothing */
643#endif
644EOF
645if test "$GCC" = yes
646then
647	AC_CHECKING([for $CC __attribute__ directives])
648cat > conftest.$ac_ext <<EOF
649#line __oline__ "configure"
650#include "confdefs.h"
651#include "conftest.h"
652#include "conftest.i"
653#if	GCC_PRINTF
654#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
655#else
656#define GCC_PRINTFLIKE(fmt,var) /*nothing*/
657#endif
658#if	GCC_SCANF
659#define GCC_SCANFLIKE(fmt,var)  __attribute__((format(scanf,fmt,var)))
660#else
661#define GCC_SCANFLIKE(fmt,var)  /*nothing*/
662#endif
663extern void wow(char *,...) GCC_SCANFLIKE(1,2);
664extern void oops(char *,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN;
665extern void foo(void) GCC_NORETURN;
666int main(int argc GCC_UNUSED, char *argv[[]] GCC_UNUSED) { return 0; }
667EOF
668	for cf_attribute in scanf printf unused noreturn
669	do
670		CF_UPPER(CF_ATTRIBUTE,$cf_attribute)
671		cf_directive="__attribute__(($cf_attribute))"
672		echo "checking for $CC $cf_directive" 1>&AC_FD_CC
673		case $cf_attribute in
674		scanf|printf)
675		cat >conftest.h <<EOF
676#define GCC_$CF_ATTRIBUTE 1
677EOF
678			;;
679		*)
680		cat >conftest.h <<EOF
681#define GCC_$CF_ATTRIBUTE $cf_directive
682EOF
683			;;
684		esac
685		if AC_TRY_EVAL(ac_compile); then
686			test -n "$verbose" && AC_MSG_RESULT(... $cf_attribute)
687			cat conftest.h >>confdefs.h
688#		else
689#			sed -e 's/__attr.*/\/*nothing*\//' conftest.h >>confdefs.h
690		fi
691	done
692else
693	fgrep define conftest.i >>confdefs.h
694fi
695rm -rf conftest*
696fi
697])dnl
698dnl ---------------------------------------------------------------------------
699dnl Check if the compiler supports useful warning options.  There's a few that
700dnl we don't use, simply because they're too noisy:
701dnl
702dnl	-Wconversion (useful in older versions of gcc, but not in gcc 2.7.x)
703dnl	-Wredundant-decls (system headers make this too noisy)
704dnl	-Wtraditional (combines too many unrelated messages, only a few useful)
705dnl	-Wwrite-strings (too noisy, but should review occasionally)
706dnl	-pedantic
707dnl
708AC_DEFUN([CF_GCC_WARNINGS],
709[
710if test "$GCC" = yes
711then
712	cat > conftest.$ac_ext <<EOF
713#line __oline__ "configure"
714int main(int argc, char *argv[[]]) { return (argv[[argc-1]] == 0) ; }
715EOF
716	AC_CHECKING([for $CC warning options])
717	cf_save_CFLAGS="$CFLAGS"
718	EXTRA_CFLAGS="-W -Wall"
719	cf_warn_CONST=""
720	test "$with_ext_const" = yes && cf_warn_CONST="Wwrite-strings"
721	for cf_opt in \
722		Wbad-function-cast \
723		Wcast-align \
724		Wcast-qual \
725		Winline \
726		Wmissing-declarations \
727		Wmissing-prototypes \
728		Wnested-externs \
729		Wpointer-arith \
730		Wshadow \
731		Wstrict-prototypes $cf_warn_CONST
732	do
733		CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
734		if AC_TRY_EVAL(ac_compile); then
735			test -n "$verbose" && AC_MSG_RESULT(... -$cf_opt)
736			EXTRA_CFLAGS="$EXTRA_CFLAGS -$cf_opt"
737			test "$cf_opt" = Wcast-qual && EXTRA_CFLAGS="$EXTRA_CFLAGS -DXTSTRINGDEFINES"
738		fi
739	done
740	rm -f conftest*
741	CFLAGS="$cf_save_CFLAGS"
742fi
743AC_SUBST(EXTRA_CFLAGS)
744])dnl
745dnl ---------------------------------------------------------------------------
746dnl Verify that a test program compiles and runs with GNAT
747dnl $cf_ada_make is set to the program that compiles/links
748AC_DEFUN([CF_GNAT_TRY_RUN],
749[
750rm -f conftest*
751cat >>conftest.ads <<CF_EOF
752$1
753CF_EOF
754cat >>conftest.adb <<CF_EOF
755$2
756CF_EOF
757if ( $cf_ada_make conftest 1>&AC_FD_CC 2>&1 ) ; then
758   if ( ./conftest 1>&AC_FD_CC 2>&1 ) ; then
759ifelse($3,,      :,[      $3])
760ifelse($4,,,[   else
761      $4])
762   fi
763ifelse($4,,,[else
764   $4])
765fi
766rm -f conftest*
767])dnl
768dnl ---------------------------------------------------------------------------
769dnl Verify Version of GNAT.
770AC_DEFUN([CF_GNAT_VERSION],
771[
772cf_cv_gnat_version=`$cf_ada_make -v 2>&1 | grep '[[0-9]].[[0-9]][[0-9]]*' |\
773  sed -e 's/[[^0-9 \.]]//g' | $AWK '{print $[1];}'`
774case $cf_cv_gnat_version in
775  3.1[[1-9]]*|3.[[2-9]]*|[[4-9]].*)
776    cf_cv_prog_gnat_correct=yes
777    ;;
778  *) echo Unsupported GNAT version $cf_cv_gnat_version. Required is 3.11 or better. Disabling Ada95 binding.
779     cf_cv_prog_gnat_correct=no
780     ;;
781esac
782case $cf_cv_gnat_version in
783  3.1*|[[4-9]].*)
784      cf_compile_generics=generics
785      cf_generic_objects="\$(GENOBJS)"
786      ;;
787  *)  cf_compile_generics=
788      cf_generic_objects=
789      ;;
790esac
791])
792dnl ---------------------------------------------------------------------------
793dnl If we're trying to use g++, test if libg++ is installed (a rather common
794dnl problem :-).  If we have the compiler but no library, we'll be able to
795dnl configure, but won't be able to build the c++ demo program.
796AC_DEFUN([CF_GPP_LIBRARY],
797[
798cf_cxx_library=unknown
799case $cf_cv_system_name in #(vi
800os2*) #(vi
801	cf_gpp_libname=gpp
802	;;
803*)
804	cf_gpp_libname=g++
805	;;
806esac
807if test "$ac_cv_prog_gxx" = yes; then
808	AC_MSG_CHECKING([for lib$cf_gpp_libname])
809	cf_save="$LIBS"
810	LIBS="$LIBS -l$cf_gpp_libname"
811	AC_TRY_LINK([
812#include <$cf_gpp_libname/builtin.h>
813	],
814	[two_arg_error_handler_t foo2 = lib_error_handler],
815	[cf_cxx_library=yes
816	 CXXLIBS="$CXXLIBS -l$cf_gpp_libname"
817	 if test "$cf_gpp_libname" = cpp ; then
818	    AC_DEFINE(HAVE_GPP_BUILTIN_H)
819	 else
820	    AC_DEFINE(HAVE_GXX_BUILTIN_H)
821	 fi],
822	[AC_TRY_LINK([
823#include <builtin.h>
824	],
825	[two_arg_error_handler_t foo2 = lib_error_handler],
826	[cf_cxx_library=yes
827	 CXXLIBS="$CXXLIBS -l$cf_gpp_libname"
828	 AC_DEFINE(HAVE_BUILTIN_H)],
829	[cf_cxx_library=no])])
830	LIBS="$cf_save"
831	AC_MSG_RESULT($cf_cxx_library)
832fi
833])dnl
834dnl ---------------------------------------------------------------------------
835dnl Insert text into the help-message, for readability, from AC_ARG_WITH.
836AC_DEFUN([CF_HELP_MESSAGE],
837[AC_DIVERT_HELP([$1])dnl
838])dnl
839dnl ---------------------------------------------------------------------------
840dnl Construct the list of include-options according to whether we're building
841dnl in the source directory or using '--srcdir=DIR' option.  If we're building
842dnl with gcc, don't append the includedir if it happens to be /usr/include,
843dnl since that usually breaks gcc's shadow-includes.
844AC_DEFUN([CF_INCLUDE_DIRS],
845[
846CPPFLAGS="$CPPFLAGS -I. -I../include"
847if test "$srcdir" != "."; then
848	CPPFLAGS="$CPPFLAGS -I\$(srcdir)/../include"
849fi
850if test "$GCC" != yes; then
851	CPPFLAGS="$CPPFLAGS -I\$(includedir)"
852elif test "$includedir" != "/usr/include"; then
853	if test "$includedir" = '${prefix}/include' ; then
854		if test $prefix != /usr ; then
855			CPPFLAGS="$CPPFLAGS -I\$(includedir)"
856		fi
857	else
858		CPPFLAGS="$CPPFLAGS -I\$(includedir)"
859	fi
860fi
861AC_SUBST(CPPFLAGS)
862])dnl
863dnl ---------------------------------------------------------------------------
864dnl Check if we have either a function or macro for 'isascii()'.
865AC_DEFUN([CF_ISASCII],
866[
867AC_MSG_CHECKING(for isascii)
868AC_CACHE_VAL(cf_cv_have_isascii,[
869	AC_TRY_LINK([#include <ctype.h>],[int x = isascii(' ')],
870	[cf_cv_have_isascii=yes],
871	[cf_cv_have_isascii=no])
872])dnl
873AC_MSG_RESULT($cf_cv_have_isascii)
874test "$cf_cv_have_isascii" = yes && AC_DEFINE(HAVE_ISASCII)
875])dnl
876dnl ---------------------------------------------------------------------------
877dnl Compute the library-prefix for the given host system
878dnl $1 = variable to set
879AC_DEFUN([CF_LIB_PREFIX],
880[
881	case $cf_cv_system_name in
882	OS/2*)	LIB_PREFIX=''     ;;
883	os2*)	LIB_PREFIX=''     ;;
884	*)	LIB_PREFIX='lib'  ;;
885	esac
886ifelse($1,,,[$1=$LIB_PREFIX])
887	AC_SUBST(LIB_PREFIX)
888])dnl
889dnl ---------------------------------------------------------------------------
890dnl Append definitions and rules for the given models to the subdirectory
891dnl Makefiles, and the recursion rule for the top-level Makefile.  If the
892dnl subdirectory is a library-source directory, modify the LIBRARIES list in
893dnl the corresponding makefile to list the models that we'll generate.
894dnl
895dnl For shared libraries, make a list of symbolic links to construct when
896dnl generating each library.  The convention used for Linux is the simplest
897dnl one:
898dnl	lib<name>.so	->
899dnl	lib<name>.so.<major>	->
900dnl	lib<name>.so.<maj>.<minor>
901AC_DEFUN([CF_LIB_RULES],
902[
903CF_LIB_PREFIX(cf_prefix)
904AC_REQUIRE([CF_SUBST_NCURSES_VERSION])
905for cf_dir in $SRC_SUBDIRS
906do
907	if test -f $srcdir/$cf_dir/modules; then
908
909		cf_libs_to_make=
910		for cf_item in $CF_LIST_MODELS
911		do
912			CF_LIB_SUFFIX($cf_item,cf_suffix)
913			if test $cf_item = shared ; then
914			if test "$cf_cv_do_symlinks" = yes ; then
915				case "$cf_cv_shlib_version" in #(vi
916				rel) cf_suffix="$cf_suffix"'.$(REL_VERSION)' ;; #(vi
917				abi) cf_suffix="$cf_suffix"'.$(ABI_VERSION)' ;;
918				esac
919			fi
920			fi
921			cf_libs_to_make="$cf_libs_to_make ../lib/${cf_prefix}${cf_dir}${cf_suffix}"
922		done
923
924		if test $cf_dir = ncurses ; then
925			case "$LIB_SUBSETS" in #(vi
926			termlib+*) #(vi
927				;;
928			*) #(vi
929				cf_item=`echo $cf_libs_to_make |sed -e s/$LIB_NAME/$TINFO_NAME/g`
930				cf_libs_to_make="$cf_item $cf_libs_to_make"
931				;;
932			esac
933		fi
934
935		sed -e "s@\@LIBS_TO_MAKE\@@$cf_libs_to_make@" \
936			$cf_dir/Makefile >$cf_dir/Makefile.out
937		mv $cf_dir/Makefile.out $cf_dir/Makefile
938
939		$AWK -f $srcdir/mk-0th.awk \
940			name=$cf_dir \
941			$srcdir/$cf_dir/modules >>$cf_dir/Makefile
942
943		for cf_item in $CF_LIST_MODELS
944		do
945			echo 'Appending rules for '$cf_item' model ('$cf_dir')'
946			CF_UPPER(CF_ITEM,$cf_item)
947			CF_LIB_SUFFIX($cf_item,cf_suffix)
948			CF_OBJ_SUBDIR($cf_item,cf_subdir)
949
950			# These dependencies really are for development, not
951			# builds, but they are useful in porting, too.
952			cf_depend="../include/ncurses_cfg.h"
953			if test "$srcdir" = "."; then
954				cf_reldir="."
955			else
956				cf_reldir="\$(srcdir)"
957			fi
958
959			if test -f $srcdir/$cf_dir/$cf_dir.priv.h; then
960				cf_depend="$cf_depend $cf_reldir/$cf_dir.priv.h"
961			elif test -f $srcdir/$cf_dir/curses.priv.h; then
962				cf_depend="$cf_depend $cf_reldir/curses.priv.h"
963			fi
964
965			for cf_subset in $LIB_SUBSETS
966			do
967			$AWK -f $srcdir/mk-1st.awk \
968				name=$cf_dir \
969				traces=$LIB_TRACING \
970				MODEL=$CF_ITEM \
971				model=$cf_subdir \
972				prefix=$cf_prefix \
973				suffix=$cf_suffix \
974				subset=$cf_subset \
975				ShlibVer=$cf_cv_shlib_version \
976				DoLinks=$cf_cv_do_symlinks \
977				rmSoLocs=$cf_cv_rm_so_locs \
978				ldconfig="$LDCONFIG" \
979				overwrite=$WITH_OVERWRITE \
980				depend="$cf_depend" \
981				target="$target" \
982				$srcdir/$cf_dir/modules >>$cf_dir/Makefile
983			test $cf_dir = ncurses && WITH_OVERWRITE=no
984			$AWK -f $srcdir/mk-2nd.awk \
985				name=$cf_dir \
986				traces=$LIB_TRACING \
987				MODEL=$CF_ITEM \
988				model=$cf_subdir \
989				subset=$cf_subset \
990				srcdir=$srcdir \
991				echo=$WITH_ECHO \
992				$srcdir/$cf_dir/modules >>$cf_dir/Makefile
993			done
994		done
995	fi
996
997	echo '	cd '$cf_dir' && $(MAKE) $(CF_MFLAGS) [$]@' >>Makefile
998done
999
1000for cf_dir in $SRC_SUBDIRS
1001do
1002	if test -f $cf_dir/Makefile ; then
1003		case "$cf_dir" in
1004		Ada95) #(vi
1005			echo 'libs \' >> Makefile
1006			echo 'install.libs \' >> Makefile
1007			echo 'uninstall.libs ::' >> Makefile
1008			echo '	cd '$cf_dir' && $(MAKE) $(CF_MFLAGS) [$]@' >> Makefile
1009			;;
1010		esac
1011	fi
1012
1013	if test -f $srcdir/$cf_dir/modules; then
1014		echo >> Makefile
1015		if test -f $srcdir/$cf_dir/headers; then
1016cat >> Makefile <<CF_EOF
1017install.includes \\
1018uninstall.includes \\
1019CF_EOF
1020		fi
1021if test "$cf_dir" != "c++" ; then
1022echo 'lint \' >> Makefile
1023fi
1024cat >> Makefile <<CF_EOF
1025libs \\
1026lintlib \\
1027install.libs \\
1028uninstall.libs \\
1029install.$cf_dir \\
1030uninstall.$cf_dir ::
1031	cd $cf_dir && \$(MAKE) \$(CF_MFLAGS) \[$]@
1032CF_EOF
1033	elif test -f $srcdir/$cf_dir/headers; then
1034cat >> Makefile <<CF_EOF
1035
1036libs \\
1037install.libs \\
1038uninstall.libs \\
1039install.includes \\
1040uninstall.includes ::
1041	cd $cf_dir && \$(MAKE) \$(CF_MFLAGS) \[$]@
1042CF_EOF
1043fi
1044done
1045
1046cat >> Makefile <<CF_EOF
1047
1048install.data \
1049uninstall.data ::
1050	cd misc && \$(MAKE) \$(CF_MFLAGS) \[$]@
1051
1052install.man \
1053uninstall.man ::
1054	cd man && \$(MAKE) \$(CF_MFLAGS) \[$]@
1055
1056distclean ::
1057	rm -f config.cache config.log config.status Makefile include/ncurses_cfg.h
1058	rm -f headers.sh headers.sed
1059	rm -rf \$(DIRS_TO_MAKE)
1060CF_EOF
1061
1062# Special case: tack's manpage lives in its own directory.
1063if test -d tack ; then
1064if test -f $srcdir/$tack.h; then
1065cat >> Makefile <<CF_EOF
1066
1067install.man \
1068uninstall.man ::
1069	cd tack && \$(MAKE) \$(CF_MFLAGS) \[$]@
1070CF_EOF
1071fi
1072fi
1073
1074dnl If we're installing into a subdirectory of /usr/include, etc., we should
1075dnl prepend the subdirectory's name to the "#include" paths.  It won't hurt
1076dnl anything, and will make it more standardized.  It's awkward to decide this
1077dnl at configuration because of quoting, so we'll simply make all headers
1078dnl installed via a script that can do the right thing.
1079
1080rm -f headers.sed headers.sh
1081
1082dnl ( generating this script makes the makefiles a little tidier :-)
1083echo creating headers.sh
1084cat >headers.sh <<CF_EOF
1085#! /bin/sh
1086# This shell script is generated by the 'configure' script.  It is invoked in a
1087# subdirectory of the build tree.  It generates a sed-script in the parent
1088# directory that is used to adjust includes for header files that reside in a
1089# subdirectory of /usr/include, etc.
1090PRG=""
1091while test \[$]# != 3
1092do
1093PRG="\$PRG \[$]1"; shift
1094done
1095DST=\[$]1
1096REF=\[$]2
1097SRC=\[$]3
1098TMPSRC=\${TMPDIR-/tmp}/\`basename \$SRC\`\$\$
1099TMPSED=\${TMPDIR-/tmp}/headers.sed\$\$
1100echo installing \$SRC in \$DST
1101CF_EOF
1102if test $WITH_CURSES_H = yes; then
1103	cat >>headers.sh <<CF_EOF
1104case \$DST in
1105/*/include/*)
1106	END=\`basename \$DST\`
1107	for i in \`cat \$REF/../*/headers |fgrep -v "#"\`
1108	do
1109		NAME=\`basename \$i\`
1110		echo "s/<\$NAME>/<\$END\/\$NAME>/" >> \$TMPSED
1111	done
1112	;;
1113*)
1114	echo "" >> \$TMPSED
1115	;;
1116esac
1117CF_EOF
1118else
1119	cat >>headers.sh <<CF_EOF
1120case \$DST in
1121/*/include/*)
1122	END=\`basename \$DST\`
1123	for i in \`cat \$REF/../*/headers |fgrep -v "#"\`
1124	do
1125		NAME=\`basename \$i\`
1126		if test "\$NAME" = "curses.h"
1127		then
1128			echo "s/<curses.h>/<ncurses.h>/" >> \$TMPSED
1129			NAME=ncurses.h
1130		fi
1131		echo "s/<\$NAME>/<\$END\/\$NAME>/" >> \$TMPSED
1132	done
1133	;;
1134*)
1135	echo "s/<curses.h>/<ncurses.h>/" >> \$TMPSED
1136	;;
1137esac
1138CF_EOF
1139fi
1140cat >>headers.sh <<CF_EOF
1141rm -f \$TMPSRC
1142sed -f \$TMPSED \$SRC > \$TMPSRC
1143NAME=\`basename \$SRC\`
1144CF_EOF
1145if test $WITH_CURSES_H != yes; then
1146	cat >>headers.sh <<CF_EOF
1147test "\$NAME" = "curses.h" && NAME=ncurses.h
1148CF_EOF
1149fi
1150cat >>headers.sh <<CF_EOF
1151eval \$PRG \$TMPSRC \$DST/\$NAME
1152rm -f \$TMPSRC \$TMPSED
1153CF_EOF
1154
1155chmod 0755 headers.sh
1156
1157for cf_dir in $SRC_SUBDIRS
1158do
1159	if test -f $srcdir/$cf_dir/headers; then
1160	cat >>$cf_dir/Makefile <<CF_EOF
1161\$(DESTDIR)\$(includedir) :
1162	\$(srcdir)/../mkinstalldirs \[$]@
1163
1164install \\
1165install.libs \\
1166install.includes :: \$(AUTO_SRC) \$(DESTDIR)\$(includedir) \\
1167CF_EOF
1168		j=""
1169		for i in `cat $srcdir/$cf_dir/headers |fgrep -v "#"`
1170		do
1171			test -n "$j" && echo "		$j \\" >>$cf_dir/Makefile
1172			j=$i
1173		done
1174		echo "		$j" >>$cf_dir/Makefile
1175		for i in `cat $srcdir/$cf_dir/headers |fgrep -v "#"`
1176		do
1177			echo "	@ (cd \$(DESTDIR)\$(includedir) && rm -f `basename $i`) ; ../headers.sh \$(INSTALL_DATA) \$(DESTDIR)\$(includedir) \$(srcdir) $i" >>$cf_dir/Makefile
1178			test $i = curses.h && test $WITH_CURSES_H = yes && echo "	@ (cd \$(DESTDIR)\$(includedir) && rm -f ncurses.h && \$(LN_S) curses.h ncurses.h)" >>$cf_dir/Makefile
1179		done
1180
1181	cat >>$cf_dir/Makefile <<CF_EOF
1182
1183uninstall \\
1184uninstall.libs \\
1185uninstall.includes ::
1186CF_EOF
1187		for i in `cat $srcdir/$cf_dir/headers |fgrep -v "#"`
1188		do
1189			i=`basename $i`
1190			echo "	-@ (cd \$(DESTDIR)\$(includedir) && rm -f $i)" >>$cf_dir/Makefile
1191			test $i = curses.h && echo "	-@ (cd \$(DESTDIR)\$(includedir) && rm -f ncurses.h)" >>$cf_dir/Makefile
1192		done
1193	fi
1194done
1195
1196])dnl
1197dnl ---------------------------------------------------------------------------
1198dnl Compute the library file-suffix from the given model name
1199dnl $1 = model name
1200dnl $2 = variable to set
1201dnl The variable $LIB_SUFFIX, if set, prepends the variable to set.
1202AC_DEFUN([CF_LIB_SUFFIX],
1203[
1204	AC_REQUIRE([CF_SUBST_NCURSES_VERSION])
1205	case $1 in
1206	libtool) $2='.la'  ;;
1207	normal)  $2='.a'   ;;
1208	debug)   $2='_g.a' ;;
1209	profile) $2='_p.a' ;;
1210	shared)
1211		case $cf_cv_system_name in
1212		hpux*)	$2='.sl'  ;;
1213		*)	$2='.so'  ;;
1214		esac
1215	esac
1216	test -n "$LIB_SUFFIX" && $2="${LIB_SUFFIX}[$]{$2}"
1217])dnl
1218dnl ---------------------------------------------------------------------------
1219dnl Compute the string to append to -library from the given model name
1220dnl $1 = model name
1221dnl $2 = variable to set
1222dnl The variable $LIB_SUFFIX, if set, prepends the variable to set.
1223AC_DEFUN([CF_LIB_TYPE],
1224[
1225	case $1 in
1226	libtool) $2=''   ;;
1227	normal)  $2=''   ;;
1228	debug)   $2='_g' ;;
1229	profile) $2='_p' ;;
1230	shared)  $2=''   ;;
1231	esac
1232	test -n "$LIB_SUFFIX" && $2="${LIB_SUFFIX}[$]{$2}"
1233])dnl
1234dnl ---------------------------------------------------------------------------
1235dnl Some systems have a non-ANSI linker that doesn't pull in modules that have
1236dnl only data (i.e., no functions), for example NeXT.  On those systems we'll
1237dnl have to provide wrappers for global tables to ensure they're linked
1238dnl properly.
1239AC_DEFUN([CF_LINK_DATAONLY],
1240[
1241AC_MSG_CHECKING([if data-only library module links])
1242AC_CACHE_VAL(cf_cv_link_dataonly,[
1243	rm -f conftest.a
1244	cat >conftest.$ac_ext <<EOF
1245#line __oline__ "configure"
1246int	testdata[[3]] = { 123, 456, 789 };
1247EOF
1248	if AC_TRY_EVAL(ac_compile) ; then
1249		mv conftest.o data.o && \
1250		( $AR $AR_OPTS conftest.a data.o ) 2>&5 1>/dev/null
1251	fi
1252	rm -f conftest.$ac_ext data.o
1253	cat >conftest.$ac_ext <<EOF
1254#line __oline__ "configure"
1255int	testfunc()
1256{
1257#if defined(NeXT)
1258	exit(1);	/* I'm told this linker is broken */
1259#else
1260	extern int testdata[[3]];
1261	return testdata[[0]] == 123
1262	   &&  testdata[[1]] == 456
1263	   &&  testdata[[2]] == 789;
1264#endif
1265}
1266EOF
1267	if AC_TRY_EVAL(ac_compile); then
1268		mv conftest.o func.o && \
1269		( $AR $AR_OPTS conftest.a func.o ) 2>&5 1>/dev/null
1270	fi
1271	rm -f conftest.$ac_ext func.o
1272	( eval $ac_cv_prog_RANLIB conftest.a ) 2>&5 >/dev/null
1273	cf_saveLIBS="$LIBS"
1274	LIBS="conftest.a $LIBS"
1275	AC_TRY_RUN([
1276	int main()
1277	{
1278		extern int testfunc();
1279		exit (!testfunc());
1280	}
1281	],
1282	[cf_cv_link_dataonly=yes],
1283	[cf_cv_link_dataonly=no],
1284	[cf_cv_link_dataonly=unknown])
1285	LIBS="$cf_saveLIBS"
1286	])
1287AC_MSG_RESULT($cf_cv_link_dataonly)
1288test "$cf_cv_link_dataonly" = no && AC_DEFINE(BROKEN_LINKER)
1289])dnl
1290dnl ---------------------------------------------------------------------------
1291dnl Most Unix systems have both link and symlink, a few don't have symlink.
1292dnl A few non-Unix systems implement symlink, but not link.
1293dnl A few non-systems implement neither (or have nonfunctional versions).
1294AC_DEFUN([CF_LINK_FUNCS],
1295[
1296AC_CHECK_FUNCS( \
1297	remove \
1298	unlink )
1299
1300if test "$ac_cv_prog_cc_cross" = yes ; then
1301	AC_CHECK_FUNCS( \
1302		link \
1303		symlink )
1304else
1305	AC_CACHE_CHECK(if link/symlink functions work,cf_cv_link_funcs,[
1306		cf_cv_link_funcs=
1307		for cf_func in link symlink ; do
1308			AC_TRY_RUN([
1309#include <sys/types.h>
1310#include <sys/stat.h>
1311#ifdef HAVE_UNISTD_H
1312#include <unistd.h>
1313#endif
1314int main()
1315{
1316	int fail = 0;
1317	char *src = "config.log";
1318	char *dst = "conftest.chk";
1319	struct stat src_sb;
1320	struct stat dst_sb;
1321
1322	stat(src, &src_sb);
1323	fail = ($cf_func("config.log", "conftest.chk") < 0)
1324	    || (stat(dst, &dst_sb) < 0)
1325	    || (dst_sb.st_mtime != src_sb.st_mtime);
1326#ifdef HAVE_UNLINK
1327	unlink(dst);
1328#else
1329	remove(dst);
1330#endif
1331	exit (fail);
1332}
1333			],[
1334			cf_cv_link_funcs="$cf_cv_link_funcs $cf_func"
1335			eval 'ac_cv_func_'$cf_func'=yes'],[
1336			eval 'ac_cv_func_'$cf_func'=no'],[
1337			eval 'ac_cv_func_'$cf_func'=error'])
1338		done
1339		test -z "$cf_cv_link_funcs" && cf_cv_link_funcs=no
1340	])
1341	test "$ac_cv_func_link"    = yes && AC_DEFINE(HAVE_LINK)
1342	test "$ac_cv_func_symlink" = yes && AC_DEFINE(HAVE_SYMLINK)
1343fi
1344])dnl
1345dnl ---------------------------------------------------------------------------
1346dnl Some 'make' programs support $(MAKEFLAGS), some $(MFLAGS), to pass 'make'
1347dnl options to lower-levels.  It's very useful for "make -n" -- if we have it.
1348dnl (GNU 'make' does both, something POSIX 'make', which happens to make the
1349dnl $(MAKEFLAGS) variable incompatible because it adds the assignments :-)
1350AC_DEFUN([CF_MAKEFLAGS],
1351[
1352AC_MSG_CHECKING([for makeflags variable])
1353AC_CACHE_VAL(cf_cv_makeflags,[
1354	cf_cv_makeflags=''
1355	for cf_option in '-$(MAKEFLAGS)' '$(MFLAGS)'
1356	do
1357		cat >cf_makeflags.tmp <<CF_EOF
1358all :
1359	@ echo '.$cf_option'
1360CF_EOF
1361		cf_result=`${MAKE-make} -k -f cf_makeflags.tmp 2>/dev/null`
1362		case "$cf_result" in
1363		.*k)
1364			cf_result=`${MAKE-make} -k -f cf_makeflags.tmp CC=cc 2>/dev/null`
1365			case "$cf_result" in
1366			.*CC=*)	cf_cv_makeflags=
1367				;;
1368			*)	cf_cv_makeflags=$cf_option
1369				;;
1370			esac
1371			break
1372			;;
1373		*)	echo no match "$cf_result"
1374			;;
1375		esac
1376	done
1377	rm -f cf_makeflags.tmp])
1378AC_MSG_RESULT($cf_cv_makeflags)
1379AC_SUBST(cf_cv_makeflags)
1380])dnl
1381dnl ---------------------------------------------------------------------------
1382dnl Generate tags/TAGS targets for makefiles.  Do not generate TAGS if we have
1383dnl a monocase filesystem.
1384AC_DEFUN([CF_MAKE_TAGS],[
1385AC_REQUIRE([CF_MIXEDCASE_FILENAMES])
1386AC_CHECK_PROG(MAKE_LOWER_TAGS, ctags, yes, no)
1387
1388if test "$cf_cv_mixedcase" = yes ; then
1389	AC_CHECK_PROG(MAKE_UPPER_TAGS, etags, yes, no)
1390else
1391	MAKE_UPPER_TAGS=no
1392fi
1393
1394if test "$MAKE_UPPER_TAGS" = yes ; then
1395	MAKE_UPPER_TAGS=
1396else
1397	MAKE_UPPER_TAGS="#"
1398fi
1399AC_SUBST(MAKE_UPPER_TAGS)
1400
1401if test "$MAKE_LOWER_TAGS" = yes ; then
1402	MAKE_LOWER_TAGS=
1403else
1404	MAKE_LOWER_TAGS="#"
1405fi
1406AC_SUBST(MAKE_LOWER_TAGS)
1407])dnl
1408dnl ---------------------------------------------------------------------------
1409dnl Option to allow user to override automatic configuration of manpage format.
1410dnl There are several special cases.
1411AC_DEFUN([CF_MANPAGE_FORMAT],
1412[
1413AC_REQUIRE([CF_PATHSEP])
1414AC_MSG_CHECKING(format of man-pages)
1415
1416AC_ARG_WITH(manpage-format,
1417	[  --with-manpage-format   specify manpage-format: gzip/compress/BSDI/normal and
1418                          optionally formatted, e.g., gzip,formatted],
1419	[cf_manpage_form=$withval],
1420	[cf_manpage_form=unknown])
1421
1422case ".$cf_manpage_form" in
1423.gzip|.compress|.BSDI|.normal|.formatted) # (vi
1424  ;;
1425.unknown|.) # (vi
1426  if test -z "$MANPATH" ; then
1427    MANPATH="/usr/man:/usr/share/man"
1428  fi
1429  # look for the 'date' man-page (it's most likely to be installed!)
1430  IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS="${IFS}${PATHSEP}"
1431  cf_manpage_form=unknown
1432  for cf_dir in $MANPATH; do
1433    test -z "$cf_dir" && cf_dir=/usr/man
1434    for cf_name in $cf_dir/*/date.[[01]]* $cf_dir/*/date
1435    do
1436       cf_test=`echo $cf_name | sed -e 's/*//'`
1437       if test "x$cf_test" = "x$cf_name" ; then
1438	  case "$cf_name" in
1439	  *.gz) cf_manpage_form=gzip;;
1440	  *.Z)  cf_manpage_form=compress;;
1441	  *.0)	cf_manpage_form=BSDI,formatted;;
1442	  *)    cf_manpage_form=normal;;
1443	  esac
1444	  break
1445       fi
1446    done
1447    if test "$cf_manpage_form" != "unknown" ; then
1448       break
1449    fi
1450  done
1451  IFS="$ac_save_ifs"
1452  ;;
1453.*) # (vi
1454  AC_MSG_WARN(Unexpected manpage-format)
1455  ;;
1456esac
1457
1458AC_MSG_RESULT($cf_manpage_form)
1459])dnl
1460dnl ---------------------------------------------------------------------------
1461dnl The Debian people have their own naming convention for manpages.  This
1462dnl option lets us override the name of the file containing renaming, or
1463dnl disable it altogether.
1464AC_DEFUN([CF_MANPAGE_RENAMES],
1465[
1466AC_MSG_CHECKING(for manpage renaming)
1467
1468AC_ARG_WITH(manpage-renames,
1469	[  --with-manpage-renames  specify manpage-renaming],
1470	[cf_manpage_renames=$withval],
1471	[cf_manpage_renames=yes])
1472
1473case ".$cf_manpage_renames" in #(vi
1474.no) #(vi
1475  ;;
1476.|.yes)
1477  # Debian 'man' program?
1478  if test -f /etc/debian_version ; then
1479    cf_manpage_renames=`cd $srcdir && pwd`/man/man_db.renames
1480  else
1481    cf_manpage_renames=no
1482  fi
1483  ;;
1484esac
1485
1486if test "$cf_manpage_renames" != no ; then
1487  if test ! -f $cf_manpage_renames ; then
1488    AC_MSG_ERROR(not a filename: $cf_manpage_renames)
1489  fi
1490
1491  test ! -d man && mkdir man
1492
1493  # Construct a sed-script to perform renaming within man-pages
1494  if test -n "$cf_manpage_renames" ; then
1495    test ! -d man && mkdir man
1496    $srcdir/man/make_sed.sh $cf_manpage_renames >man/edit_man.sed
1497  fi
1498fi
1499
1500AC_MSG_RESULT($cf_manpage_renames)
1501])dnl
1502dnl ---------------------------------------------------------------------------
1503dnl Some people expect each tool to make all aliases for manpages in the
1504dnl man-directory.  This accommodates the older, less-capable implementations
1505dnl of 'man', and is optional.
1506AC_DEFUN([CF_MANPAGE_SYMLINKS],
1507[
1508AC_MSG_CHECKING(for manpage symlinks)
1509
1510AC_ARG_WITH(manpage-symlinks,
1511	[  --with-manpage-symlinks specify manpage-symlinks],
1512	[cf_manpage_symlinks=$withval],
1513	[cf_manpage_symlinks=yes])
1514
1515AC_MSG_RESULT($cf_manpage_symlinks)
1516])dnl
1517dnl ---------------------------------------------------------------------------
1518dnl This option causes manpages to be run through tbl(1) to generate tables
1519dnl correctly.
1520AC_DEFUN([CF_MANPAGE_TBL],
1521[
1522AC_MSG_CHECKING(for manpage tbl)
1523
1524AC_ARG_WITH(manpage-tbl,
1525	[  --with-manpage-tbl      specify manpage processing with tbl],
1526	[cf_manpage_tbl=$withval],
1527	[cf_manpage_tbl=no])
1528
1529AC_MSG_RESULT($cf_manpage_tbl)
1530])dnl
1531dnl ---------------------------------------------------------------------------
1532dnl Try to determine if the man-pages on the system are compressed, and if
1533dnl so, what format is used.  Use this information to construct a script that
1534dnl will install man-pages.
1535AC_DEFUN([CF_MAN_PAGES],
1536[
1537CF_HELP_MESSAGE(Options to Specify How Manpages are Installed:)
1538CF_MANPAGE_FORMAT
1539CF_MANPAGE_RENAMES
1540CF_MANPAGE_SYMLINKS
1541CF_MANPAGE_TBL
1542
1543  if test "$prefix" = "NONE" ; then
1544     cf_prefix="$ac_default_prefix"
1545  else
1546     cf_prefix="$prefix"
1547  fi
1548
1549  case "$cf_manpage_form" in # (vi
1550  *formatted*) # (vi
1551    cf_subdir='$mandir/cat'
1552    cf_format=yes
1553    ;;
1554  *)
1555    cf_subdir='$mandir/man'
1556    cf_format=no
1557    ;;
1558  esac
1559
1560test ! -d man && mkdir man
1561cat >man/edit_man.sh <<CF_EOF
1562#! /bin/sh
1563# this script is generated by the configure-script
1564prefix="$cf_prefix"
1565datadir="$datadir"
1566TERMINFO="$TERMINFO"
1567MKDIRS="`cd $srcdir && pwd`/mkinstalldirs"
1568INSTALL="$INSTALL"
1569INSTALL_DATA="$INSTALL_DATA"
1570transform="$program_transform_name"
1571
1572TMP=\${TMPDIR-/tmp}/man\$\$
1573trap "rm -f \$TMP" 0 1 2 5 15
1574
1575verb=\[$]1
1576shift
1577
1578mandir=\[$]1
1579shift
1580
1581srcdir=\[$]1
1582shift
1583
1584for i in \[$]* ; do
1585case \$i in #(vi
1586*.orig|*.rej) ;; #(vi
1587*.[[0-9]]*)
1588	section=\`expr "\$i" : '.*\\.\\([[0-9]]\\)[[xm]]*'\`;
1589	if test \$verb = installing ; then
1590	if test ! -d $cf_subdir\${section} ; then
1591		\$MKDIRS $cf_subdir\$section
1592	fi
1593	fi
1594	aliases=
1595	source=\`basename \$i\`
1596	inalias=\$source
1597	test ! -f \$inalias && inalias="\$srcdir/\$inalias"
1598	if test ! -f \$inalias ; then
1599		echo .. skipped \$source
1600		continue
1601	fi
1602CF_EOF
1603if test "$cf_manpage_symlinks" = yes ; then
1604cat >>man/edit_man.sh <<CF_EOF
1605	aliases=\`sed -f \$srcdir/manlinks.sed \$inalias | sort -u\`
1606CF_EOF
1607fi
1608
1609if test "$cf_manpage_renames" = no ; then
1610cat >>man/edit_man.sh <<CF_EOF
1611	# perform program transformations for section 1 man pages
1612	if test \$section = 1 ; then
1613		target=$cf_subdir\${section}/\`echo \$source|sed "\${transform}"\`
1614	else
1615		target=$cf_subdir\${section}/\$source
1616	fi
1617CF_EOF
1618else
1619cat >>man/edit_man.sh <<CF_EOF
1620	target=\`grep "^\$source" $cf_manpage_renames | $AWK '{print \[$]2}'\`
1621	if test -z "\$target" ; then
1622		echo '? missing rename for '\$source
1623		target="\$source"
1624	fi
1625	target="$cf_subdir\${section}/\${target}"
1626CF_EOF
1627fi
1628
1629	# replace variables in man page
1630	ifelse($1,,,[
1631	for cf_name in $1
1632	do
1633cat >>man/edit_man.sh <<CF_EOF
1634	prog_$cf_name=\`echo $cf_name|sed "\${transform}"\`
1635CF_EOF
1636	done
1637	])
1638cat >>man/edit_man.sh <<CF_EOF
1639	sed	-e "s,@DATADIR@,\$datadir," \\
1640		-e "s,@TERMINFO@,\$TERMINFO," \\
1641CF_EOF
1642	ifelse($1,,,[
1643	for cf_name in $1
1644	do
1645		cf_NAME=`echo "$cf_name" | sed y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%`
1646cat >>man/edit_man.sh <<CF_EOF
1647		-e "s,@$cf_NAME@,\$prog_$cf_name," \\
1648CF_EOF
1649	done
1650	])
1651cat >>man/edit_man.sh <<CF_EOF
1652		< \$i >\$TMP
1653CF_EOF
1654if test $cf_manpage_tbl = yes ; then
1655cat >>man/edit_man.sh <<CF_EOF
1656	tbl \$TMP >\$TMP.out
1657	mv \$TMP.out \$TMP
1658CF_EOF
1659fi
1660if test $with_curses_h != yes ; then
1661cat >>man/edit_man.sh <<CF_EOF
1662	sed -e "/\#[    ]*include/s,curses.h,ncurses.h," < \$TMP >\$TMP.out
1663	mv \$TMP.out \$TMP
1664CF_EOF
1665fi
1666if test $cf_format = yes ; then
1667cat >>man/edit_man.sh <<CF_EOF
1668	nroff -man \$TMP >\$TMP.out
1669	mv \$TMP.out \$TMP
1670CF_EOF
1671fi
1672case "$cf_manpage_form" in #(vi
1673*compress*) #(vi
1674cat >>man/edit_man.sh <<CF_EOF
1675	if test \$verb = installing ; then
1676	if ( compress -f \$TMP )
1677	then
1678		mv \$TMP.Z \$TMP
1679	fi
1680	fi
1681	target="\$target.Z"
1682CF_EOF
1683  ;;
1684*gzip*) #(vi
1685cat >>man/edit_man.sh <<CF_EOF
1686	if test \$verb = installing ; then
1687	if ( gzip -f \$TMP )
1688	then
1689		mv \$TMP.gz \$TMP
1690	fi
1691	fi
1692	target="\$target.gz"
1693CF_EOF
1694  ;;
1695*BSDI*)
1696cat >>man/edit_man.sh <<CF_EOF
1697	# BSDI installs only .0 suffixes in the cat directories
1698	target="\`echo \$target|sed -e 's/\.[[1-9]]\+.\?/.0/'\`"
1699CF_EOF
1700  ;;
1701esac
1702cat >>man/edit_man.sh <<CF_EOF
1703	suffix=\`basename \$target | sed -e 's/^[[^.]]*//'\`
1704	if test \$verb = installing ; then
1705		echo \$verb \$target
1706		\$INSTALL_DATA \$TMP \$target
1707		test -n "\$aliases" && (
1708			cd $cf_subdir\${section} && (
1709				target=\`basename \$target\`
1710				for cf_alias in \$aliases
1711				do
1712					if test \$section = 1 ; then
1713						cf_alias=\`echo \$cf_alias|sed "\${transform}"\`
1714					fi
1715
1716					if test -f \$cf_alias\${suffix} ; then
1717						if ( cmp -s \$target \$cf_alias\${suffix} )
1718						then
1719							:
1720						else
1721							echo .. \$verb alias \$cf_alias\${suffix}
1722							rm -f \$cf_alias\${suffix}
1723							$LN_S \$target \$cf_alias\${suffix}
1724						fi
1725					else
1726						echo .. \$verb alias \$cf_alias\${suffix}
1727						rm -f \$cf_alias\${suffix}
1728						$LN_S \$target \$cf_alias\${suffix}
1729					fi
1730				done
1731			)
1732		)
1733	elif test \$verb = removing ; then
1734		echo \$verb \$target
1735		rm -f \$target
1736		test -n "\$aliases" && (
1737			cd $cf_subdir\${section} && (
1738				for cf_alias in \$aliases
1739				do
1740					if test \$section = 1 ; then
1741						cf_alias=\`echo \$cf_alias|sed "\${transform}"\`
1742					fi
1743
1744					echo .. \$verb alias \$cf_alias\${suffix}
1745					rm -f \$cf_alias\${suffix}
1746				done
1747			)
1748		)
1749	else
1750#		echo ".hy 0"
1751		cat \$TMP
1752	fi
1753	;;
1754esac
1755done
1756exit 0
1757CF_EOF
1758chmod 755 man/edit_man.sh
1759
1760])dnl
1761dnl ---------------------------------------------------------------------------
1762dnl Checks for libraries.  At least one UNIX system, Apple Macintosh
1763dnl Rhapsody 5.5, does not have -lm.  We cannot use the simpler
1764dnl AC_CHECK_LIB(m,sin), because that fails for C++.
1765AC_DEFUN([CF_MATH_LIB],
1766[
1767AC_CACHE_CHECK(if -lm needed for math functions,
1768	cf_cv_need_libm,[
1769	AC_TRY_LINK([
1770	#include <stdio.h>
1771	#include <math.h>
1772	],
1773	[double x = rand(); printf("result = %g\n", ]ifelse($2,,sin(x),$2)[)],
1774	[cf_cv_need_libm=no],
1775	[cf_cv_need_libm=yes])])
1776if test "$cf_cv_need_libm" = yes
1777then
1778ifelse($1,,[
1779	LIBS="$LIBS -lm"
1780],[$1=-lm])
1781fi
1782])
1783dnl ---------------------------------------------------------------------------
1784dnl Check if the file-system supports mixed-case filenames.  If we're able to
1785dnl create a lowercase name and see it as uppercase, it doesn't support that.
1786AC_DEFUN([CF_MIXEDCASE_FILENAMES],
1787[
1788AC_CACHE_CHECK(if filesystem supports mixed-case filenames,cf_cv_mixedcase,[
1789	rm -f conftest CONFTEST
1790	echo test >conftest
1791	if test -f CONFTEST ; then
1792		cf_cv_mixedcase=no
1793	else
1794		cf_cv_mixedcase=yes
1795	fi
1796	rm -f conftest CONFTEST
1797])
1798test "$cf_cv_mixedcase" = yes && AC_DEFINE(MIXEDCASE_FILENAMES)
1799])dnl
1800dnl ---------------------------------------------------------------------------
1801dnl Compute the object-directory name from the given model name
1802AC_DEFUN([CF_OBJ_SUBDIR],
1803[
1804	case $1 in
1805	libtool) $2='obj_lo'  ;;
1806	normal)  $2='objects' ;;
1807	debug)   $2='obj_g' ;;
1808	profile) $2='obj_p' ;;
1809	shared)  $2='obj_s' ;;
1810	esac
1811])dnl
1812dnl ---------------------------------------------------------------------------
1813dnl Provide a value for the $PATH and similar separator
1814AC_DEFUN([CF_PATHSEP],
1815[
1816	case $cf_cv_system_name in
1817	os2*)	PATHSEP=';'  ;;
1818	*)	PATHSEP=':'  ;;
1819	esac
1820ifelse($1,,,[$1=$PATHSEP])
1821	AC_SUBST(PATHSEP)
1822])dnl
1823dnl ---------------------------------------------------------------------------
1824dnl Check the argument to see that it looks like a pathname.  Rewrite it if it
1825dnl begins with one of the prefix/exec_prefix variables, and then again if the
1826dnl result begins with 'NONE'.  This is necessary to workaround autoconf's
1827dnl delayed evaluation of those symbols.
1828AC_DEFUN([CF_PATH_SYNTAX],[
1829case ".[$]$1" in #(vi
1830./*) #(vi
1831  ;;
1832.[[a-zA-Z]]:[[\\/]]*) #(vi OS/2 EMX
1833  ;;
1834.\[$]{*prefix}*) #(vi
1835  eval $1="[$]$1"
1836  case ".[$]$1" in #(vi
1837  .NONE/*)
1838    $1=`echo [$]$1 | sed -e s@NONE@$ac_default_prefix@`
1839    ;;
1840  esac
1841  ;; #(vi
1842.NONE/*)
1843  $1=`echo [$]$1 | sed -e s@NONE@$ac_default_prefix@`
1844  ;;
1845*)
1846  AC_ERROR(expected a pathname, not "[$]$1")
1847  ;;
1848esac
1849])dnl
1850dnl ---------------------------------------------------------------------------
1851dnl Compute $PROG_EXT, used for non-Unix ports, such as OS/2 EMX.
1852AC_DEFUN([CF_PROG_EXT],
1853[
1854AC_REQUIRE([CF_CHECK_CACHE])
1855PROG_EXT=
1856case $cf_cv_system_name in
1857os2*)
1858    # We make sure -Zexe is not used -- it would interfere with @PROG_EXT@
1859    CFLAGS="$CFLAGS -Zmt"
1860    CPPFLAGS="$CPPFLAGS -D__ST_MT_ERRNO__"
1861    CXXFLAGS="$CXXFLAGS -Zmt"
1862    LDFLAGS=`echo "$LDFLAGS -Zmt -Zcrtdll" | sed "s/-Zexe//g"`
1863    PROG_EXT=".exe"
1864    ;;
1865cygwin*)
1866    PROG_EXT=".exe"
1867    ;;
1868esac
1869AC_SUBST(PROG_EXT)
1870])dnl
1871dnl ---------------------------------------------------------------------------
1872dnl Force $INSTALL to be an absolute-path.  Otherwise, edit_man.sh and the
1873dnl misc/tabset install won't work properly.  Usually this happens only when
1874dnl using the fallback mkinstalldirs script
1875AC_DEFUN([CF_PROG_INSTALL],
1876[AC_PROG_INSTALL
1877case $INSTALL in
1878/*)
1879  ;;
1880*)
1881  CF_DIRNAME(cf_dir,$INSTALL)
1882  test -z "$cf_dir" && cf_dir=.
1883  INSTALL=`cd $cf_dir && pwd`/`echo $INSTALL | sed -e 's:^.*/::'`
1884  ;;
1885esac
1886])dnl
1887dnl ---------------------------------------------------------------------------
1888dnl Attempt to determine if we've got one of the flavors of regular-expression
1889dnl code that we can support.
1890AC_DEFUN([CF_REGEX],
1891[
1892AC_MSG_CHECKING([for regular-expression headers])
1893AC_CACHE_VAL(cf_cv_regex,[
1894AC_TRY_LINK([#include <sys/types.h>
1895#include <regex.h>],[
1896	regex_t *p;
1897	int x = regcomp(p, "", 0);
1898	int y = regexec(p, "", 0, 0, 0);
1899	regfree(p);
1900	],[cf_cv_regex="regex.h"],[
1901	AC_TRY_LINK([#include <regexp.h>],[
1902		char *p = compile("", "", "", 0);
1903		int x = step("", "");
1904	],[cf_cv_regex="regexp.h"],[
1905		cf_save_LIBS="$LIBS"
1906		LIBS="-lgen $LIBS"
1907		AC_TRY_LINK([#include <regexpr.h>],[
1908			char *p = compile("", "", "");
1909			int x = step("", "");
1910		],[cf_cv_regex="regexpr.h"],[LIBS="$cf_save_LIBS"])])])
1911])
1912AC_MSG_RESULT($cf_cv_regex)
1913case $cf_cv_regex in
1914	regex.h)   AC_DEFINE(HAVE_REGEX_H_FUNCS) ;;
1915	regexp.h)  AC_DEFINE(HAVE_REGEXP_H_FUNCS) ;;
1916	regexpr.h) AC_DEFINE(HAVE_REGEXPR_H_FUNCS) ;;
1917esac
1918])dnl
1919dnl ---------------------------------------------------------------------------
1920dnl Attempt to determine the appropriate CC/LD options for creating a shared
1921dnl library.
1922dnl
1923dnl Note: $(LOCAL_LDFLAGS) is used to link executables that will run within the
1924dnl build-tree, i.e., by making use of the libraries that are compiled in ../lib
1925dnl We avoid compiling-in a ../lib path for the shared library since that can
1926dnl lead to unexpected results at runtime.
1927dnl $(LOCAL_LDFLAGS2) has the same intention but assumes that the shared libraries
1928dnl are compiled in ../../lib
1929dnl
1930dnl The variable 'cf_cv_do_symlinks' is used to control whether we configure
1931dnl to install symbolic links to the rel/abi versions of shared libraries.
1932dnl
1933dnl The variable 'cf_cv_shlib_version' controls whether we use the rel or abi
1934dnl version when making symbolic links.
1935dnl
1936dnl Some loaders leave 'so_locations' lying around.  It's nice to clean up.
1937AC_DEFUN([CF_SHARED_OPTS],
1938[
1939	AC_REQUIRE([CF_SUBST_NCURSES_VERSION])
1940 	LOCAL_LDFLAGS=
1941 	LOCAL_LDFLAGS2=
1942	LD_SHARED_OPTS=
1943	INSTALL_LIB="-m 644"
1944
1945	cf_cv_do_symlinks=no
1946
1947	AC_MSG_CHECKING(if release/abi version should be used for shared libs)
1948	AC_ARG_WITH(shlib-version,
1949	[  --with-shlib-version=X  Specify rel or abi version for shared libs],
1950	[test -z "$withval" && withval=auto
1951	case $withval in #(vi
1952	yes) #(vi
1953		cf_cv_shlib_version=auto
1954		;;
1955	rel|abi|auto|no) #(vi
1956		cf_cv_shlib_version=$withval
1957		;;
1958	*)
1959		AC_ERROR([option value must be one of: rel, abi, auto or no])
1960		;;
1961	esac
1962	],[cf_cv_shlib_version=auto])
1963	AC_MSG_RESULT($cf_cv_shlib_version)
1964
1965	cf_cv_rm_so_locs=no
1966
1967	# Some less-capable ports of gcc support only -fpic
1968	CC_SHARED_OPTS=
1969	if test "$GCC" = yes
1970	then
1971		AC_MSG_CHECKING(which $CC option to use)
1972		cf_save_CFLAGS="$CFLAGS"
1973		for CC_SHARED_OPTS in -fPIC -fpic ''
1974		do
1975			CFLAGS="$cf_save_CFLAGS $CC_SHARED_OPTS"
1976			AC_TRY_COMPILE([#include <stdio.h>],[int x = 1],[break],[])
1977		done
1978		AC_MSG_RESULT($CC_SHARED_OPTS)
1979		CFLAGS="$cf_save_CFLAGS"
1980	fi
1981
1982	case $cf_cv_system_name in
1983	beos*)
1984		MK_SHARED_LIB='$(CC) -o $[@] -Xlinker -soname=`basename $[@]` -nostart -e 0'
1985		;;
1986	hpux*)
1987		# (tested with gcc 2.7.2 -- I don't have c89)
1988		if test "$GCC" = yes; then
1989			LD_SHARED_OPTS='-Xlinker +b -Xlinker $(libdir)'
1990		else
1991			CC_SHARED_OPTS='+Z'
1992			LD_SHARED_OPTS='-Wl,+b,$(libdir)'
1993		fi
1994		MK_SHARED_LIB='$(LD) +b $(libdir) -b -o $[@]'
1995		# HP-UX shared libraries must be executable, and should be
1996		# readonly to exploit a quirk in the memory manager.
1997		INSTALL_LIB="-m 555"
1998		;;
1999	irix*)
2000		if test "$cf_cv_ld_rpath" = yes ; then
2001			cf_ld_rpath_opt="-Wl,-rpath,"
2002			EXTRA_LDFLAGS="-Wl,-rpath,\$(libdir) $EXTRA_LDFLAGS"
2003		fi
2004		# tested with IRIX 5.2 and 'cc'.
2005		if test "$GCC" != yes; then
2006			CC_SHARED_OPTS='-KPIC'
2007		fi
2008		MK_SHARED_LIB='$(LD) -shared -rdata_shared -soname `basename $[@]` -o $[@]'
2009		cf_cv_rm_so_locs=yes
2010		;;
2011	linux*|gnu*)
2012		if test "$DFT_LWR_MODEL" = "shared" ; then
2013 			LOCAL_LDFLAGS="-Wl,-rpath,`pwd`/lib"
2014 			LOCAL_LDFLAGS2="$LOCAL_LDFLAGS"
2015		fi
2016		if test "$cf_cv_ld_rpath" = yes ; then
2017			cf_ld_rpath_opt="-Wl,-rpath,"
2018			EXTRA_LDFLAGS="$LOCAL_LDFLAGS $EXTRA_LDFLAGS"
2019		fi
2020		test "$cf_cv_shlib_version" = auto && cf_cv_shlib_version=rel
2021		MK_SHARED_LIB='$(CC) -shared -Wl,-soname,`basename $[@] .$(REL_VERSION)`.$(ABI_VERSION),-stats,-lc -o $[@]'
2022		;;
2023	openbsd2*)
2024		CC_SHARED_OPTS="$CC_SHARED_OPTS -DPIC"
2025		MK_SHARED_LIB='$(LD) -Bshareable -soname,`basename $[@].$(ABI_VERSION)` -o $[@]'
2026		;;
2027	openbsd*|freebsd*)
2028		CC_SHARED_OPTS="$CC_SHARED_OPTS -DPIC"
2029		MK_SHARED_LIB='$(LD) -Bshareable -o $[@]'
2030		test "$cf_cv_shlib_version" = auto && cf_cv_shlib_version=rel
2031		;;
2032	netbsd*)
2033		CC_SHARED_OPTS="$CC_SHARED_OPTS -DPIC"
2034		test "$cf_cv_ld_rpath" = yes && cf_ld_rpath_opt="-Wl,-rpath,"
2035		if test "$DFT_LWR_MODEL" = "shared" && test "$cf_cv_ld_rpath" = yes ; then
2036 			LOCAL_LDFLAGS="-Wl,-rpath,`pwd`/lib"
2037 			LOCAL_LDFLAGS2="$LOCAL_LDFLAGS"
2038			EXTRA_LDFLAGS="-Wl,-rpath,\$(libdir) $EXTRA_LDFLAGS"
2039			MK_SHARED_LIB='$(CC) -shared -Wl,-soname,`basename $[@] .$(REL_VERSION)`.$(ABI_VERSION) -o $[@]'
2040			if test "$cf_cv_shlib_version" = auto; then
2041			if test ! -f /usr/libexec/ld.elf_so; then
2042				cf_cv_shlib_version=rel
2043			fi
2044			fi
2045		else
2046			MK_SHARED_LIB='$(LD) -Bshareable -o $[@]'
2047		fi
2048		;;
2049	osf*|mls+*)
2050		# tested with OSF/1 V3.2 and 'cc'
2051		# tested with OSF/1 V3.2 and gcc 2.6.3 (but the c++ demo didn't
2052		# link with shared libs).
2053 		MK_SHARED_LIB='$(LD) -set_version $(REL_VERSION):$(ABI_VERSION) -expect_unresolved "*" -shared -soname `basename $[@]`'
2054		case $host_os in
2055		osf4*)
2056 			MK_SHARED_LIB="${MK_SHARED_LIB} -msym"
2057			;;
2058		esac
2059		MK_SHARED_LIB="${MK_SHARED_LIB}"' -o $[@]'
2060		if test "$DFT_LWR_MODEL" = "shared" ; then
2061 			LOCAL_LDFLAGS="-Wl,-rpath,`pwd`/lib"
2062 			LOCAL_LDFLAGS2="$LOCAL_LDFLAGS"
2063		fi
2064		if test "$cf_cv_ld_rpath" = yes ; then
2065			cf_ld_rpath_opt="-rpath"
2066			# EXTRA_LDFLAGS="$LOCAL_LDFLAGS $EXTRA_LDFLAGS"
2067		fi
2068		cf_cv_rm_so_locs=yes
2069		;;
2070	sco3.2v5*)  # (also uw2* and UW7) hops 13-Apr-98
2071		# tested with osr5.0.5
2072		if test "$ac_cv_prog_gcc" != yes; then
2073			CC_SHARED_OPTS='-belf -KPIC'
2074		fi
2075		MK_SHARED_LIB='$(LD) -dy -G -h `basename $[@] .$(REL_VERSION)`.$(ABI_VERSION) -o [$]@'
2076		if test "$cf_cv_ld_rpath" = yes ; then
2077			# only way is to set LD_RUN_PATH but no switch for it
2078			RUN_PATH=$libdir
2079		fi
2080		test "$cf_cv_shlib_version" = auto && cf_cv_shlib_version=rel
2081		LINK_PROGS='LD_RUN_PATH=$(libdir)'
2082		LINK_TESTS='Pwd=`pwd`;LD_RUN_PATH=`dirname $${Pwd}`/lib'
2083		;;
2084	sunos4*)
2085		# tested with SunOS 4.1.1 and gcc 2.7.0
2086		if test "$ac_cv_prog_gcc" != yes; then
2087			CC_SHARED_OPTS='-KPIC'
2088		fi
2089		MK_SHARED_LIB='$(LD) -assert pure-text -o $[@]'
2090		test "$cf_cv_shlib_version" = auto && cf_cv_shlib_version=rel
2091		;;
2092	solaris2*)
2093		# tested with SunOS 5.5.1 (solaris 2.5.1) and gcc 2.7.2
2094		if test "$ac_cv_prog_gcc" != yes; then
2095			CC_SHARED_OPTS='-KPIC'
2096		fi
2097		MK_SHARED_LIB='$(LD) -dy -G -h `basename $[@] .$(REL_VERSION)`.$(ABI_VERSION) -o $[@]'
2098		if test "$DFT_LWR_MODEL" = "shared" ; then
2099			LOCAL_LDFLAGS="-R `pwd`/lib:\$(libdir)"
2100 			LOCAL_LDFLAGS2="$LOCAL_LDFLAGS"
2101		fi
2102		if test "$cf_cv_ld_rpath" = yes ; then
2103			cf_ld_rpath_opt="-R"
2104			EXTRA_LDFLAGS="$LOCAL_LDFLAGS $EXTRA_LDFLAGS"
2105		fi
2106		test "$cf_cv_shlib_version" = auto && cf_cv_shlib_version=rel
2107		;;
2108	sysv5uw7*|unix_sv*)
2109		# tested with UnixWare 7.1.0 (gcc 2.95.2 and cc)
2110		if test "$ac_cv_prog_gcc" != yes; then
2111			CC_SHARED_OPTS='-KPIC'
2112		fi
2113		MK_SHARED_LIB='$(LD) -d y -G -o [$]@'
2114		;;
2115	*)
2116		CC_SHARED_OPTS='unknown'
2117		MK_SHARED_LIB='echo unknown'
2118		;;
2119	esac
2120
2121	# This works if the last tokens in $MK_SHARED_LIB are the -o target.
2122	case "$cf_cv_shlib_version" in #(vi
2123	rel|abi)
2124		case "$MK_SHARED_LIB" in #(vi
2125		*'-o $[@]')
2126			test "$cf_cv_do_symlinks" = no && cf_cv_do_symlinks=yes
2127			;;
2128		*)
2129			AC_MSG_WARN(ignored --with-shlib-version)
2130			;;
2131		esac
2132		;;
2133	esac
2134
2135	if test -n "$cf_ld_rpath_opt" ; then
2136		AC_MSG_CHECKING(if we need a space after rpath option)
2137		cf_save_LIBS="$LIBS"
2138		LIBS="$LIBS ${cf_ld_rpath_opt}$libdir"
2139		AC_TRY_LINK(, , cf_rpath_space=no, cf_rpath_space=yes)
2140		LIBS="$cf_save_LIBS"
2141		AC_MSG_RESULT($cf_rpath_space)
2142		test "$cf_rpath_space" = yes && cf_ld_rpath_opt="$cf_ld_rpath_opt "
2143		MK_SHARED_LIB="$MK_SHARED_LIB $cf_ld_rpath_opt\$(libdir)"
2144	fi
2145
2146	AC_SUBST(CC_SHARED_OPTS)
2147	AC_SUBST(LD_SHARED_OPTS)
2148	AC_SUBST(MK_SHARED_LIB)
2149	AC_SUBST(LINK_PROGS)
2150	AC_SUBST(LINK_TESTS)
2151	AC_SUBST(EXTRA_LDFLAGS)
2152	AC_SUBST(LOCAL_LDFLAGS)
2153	AC_SUBST(LOCAL_LDFLAGS2)
2154	AC_SUBST(INSTALL_LIB)
2155])dnl
2156dnl ---------------------------------------------------------------------------
2157dnl Check for definitions & structures needed for window size-changing
2158dnl FIXME: check that this works with "snake" (HP-UX 10.x)
2159AC_DEFUN([CF_SIZECHANGE],
2160[
2161AC_REQUIRE([CF_STRUCT_TERMIOS])
2162AC_CACHE_CHECK(declaration of size-change, cf_cv_sizechange,[
2163    cf_cv_sizechange=unknown
2164    cf_save_CPPFLAGS="$CPPFLAGS"
2165
2166for cf_opts in "" "NEED_PTEM_H"
2167do
2168
2169    CPPFLAGS="$cf_save_CPPFLAGS"
2170    test -n "$cf_opts" && CPPFLAGS="$CPPFLAGS -D$cf_opts"
2171    AC_TRY_COMPILE([#include <sys/types.h>
2172#ifdef HAVE_TERMIOS_H
2173#include <termios.h>
2174#else
2175#ifdef HAVE_TERMIO_H
2176#include <termio.h>
2177#endif
2178#endif
2179#ifdef NEED_PTEM_H
2180/* This is a workaround for SCO:  they neglected to define struct winsize in
2181 * termios.h -- it's only in termio.h and ptem.h
2182 */
2183#include        <sys/stream.h>
2184#include        <sys/ptem.h>
2185#endif
2186#if !defined(sun) || !defined(HAVE_TERMIOS_H)
2187#include <sys/ioctl.h>
2188#endif
2189],[
2190#ifdef TIOCGSIZE
2191	struct ttysize win;	/* FIXME: what system is this? */
2192	int y = win.ts_lines;
2193	int x = win.ts_cols;
2194#else
2195#ifdef TIOCGWINSZ
2196	struct winsize win;
2197	int y = win.ws_row;
2198	int x = win.ws_col;
2199#else
2200	no TIOCGSIZE or TIOCGWINSZ
2201#endif /* TIOCGWINSZ */
2202#endif /* TIOCGSIZE */
2203	],
2204	[cf_cv_sizechange=yes],
2205	[cf_cv_sizechange=no])
2206
2207	CPPFLAGS="$cf_save_CPPFLAGS"
2208	if test "$cf_cv_sizechange" = yes ; then
2209		echo "size-change succeeded ($cf_opts)" >&AC_FD_CC
2210		test -n "$cf_opts" && cf_cv_sizechange="$cf_opts"
2211		break
2212	fi
2213done
2214])
2215if test "$cf_cv_sizechange" != no ; then
2216	AC_DEFINE(HAVE_SIZECHANGE)
2217	case $cf_cv_sizechange in #(vi
2218	NEED*)
2219		AC_DEFINE_UNQUOTED($cf_cv_sizechange )
2220		;;
2221	esac
2222fi
2223])dnl
2224dnl ---------------------------------------------------------------------------
2225dnl For each parameter, test if the source-directory exists, and if it contains
2226dnl a 'modules' file.  If so, add to the list $cf_cv_src_modules which we'll
2227dnl use in CF_LIB_RULES.
2228dnl
2229dnl This uses the configured value to make the lists SRC_SUBDIRS and
2230dnl SUB_MAKEFILES which are used in the makefile-generation scheme.
2231AC_DEFUN([CF_SRC_MODULES],
2232[
2233AC_MSG_CHECKING(for src modules)
2234
2235# dependencies and linker-arguments for test-programs
2236TEST_DEPS="${LIB_DIR}/${LIB_PREFIX}${LIB_NAME}${DFT_DEP_SUFFIX} $TEST_DEPS"
2237if test "$DFT_LWR_MODEL" = "libtool"; then
2238	TEST_ARGS="${TEST_DEPS}"
2239else
2240	TEST_ARGS="-l${LIB_NAME}${DFT_ARG_SUFFIX} $TEST_ARGS"
2241fi
2242
2243# dependencies and linker-arguments for utility-programs
2244PROG_ARGS="$TEST_ARGS"
2245
2246cf_cv_src_modules=
2247for cf_dir in $1
2248do
2249	if test -f $srcdir/$cf_dir/modules; then
2250
2251		# We may/may not have tack in the distribution, though the
2252		# makefile is.
2253		if test $cf_dir = tack ; then
2254			if test ! -f $srcdir/${cf_dir}/${cf_dir}.h; then
2255				continue
2256			fi
2257		fi
2258
2259		if test -z "$cf_cv_src_modules"; then
2260			cf_cv_src_modules=$cf_dir
2261		else
2262			cf_cv_src_modules="$cf_cv_src_modules $cf_dir"
2263		fi
2264
2265		# Make the ncurses_cfg.h file record the library interface files as
2266		# well.  These are header files that are the same name as their
2267		# directory.  Ncurses is the only library that does not follow
2268		# that pattern.
2269		if test $cf_dir = tack ; then
2270			continue
2271		elif test -f $srcdir/${cf_dir}/${cf_dir}.h; then
2272			CF_UPPER(cf_have_include,$cf_dir)
2273			AC_DEFINE_UNQUOTED(HAVE_${cf_have_include}_H)
2274			AC_DEFINE_UNQUOTED(HAVE_LIB${cf_have_include})
2275			TEST_DEPS="${LIB_DIR}/${LIB_PREFIX}${cf_dir}${DFT_DEP_SUFFIX} $TEST_DEPS"
2276			if test "$DFT_LWR_MODEL" = "libtool"; then
2277				TEST_ARGS="${TEST_DEPS}"
2278			else
2279				TEST_ARGS="-l${cf_dir}${DFT_ARG_SUFFIX} $TEST_ARGS"
2280			fi
2281		fi
2282	fi
2283done
2284AC_MSG_RESULT($cf_cv_src_modules)
2285TEST_ARGS="-L${LIB_DIR} -L\$(libdir) $TEST_ARGS"
2286AC_SUBST(TEST_DEPS)
2287AC_SUBST(TEST_ARGS)
2288
2289PROG_ARGS="-L${LIB_DIR} -L\$(libdir) $PROG_ARGS"
2290AC_SUBST(PROG_ARGS)
2291
2292SRC_SUBDIRS="man include"
2293for cf_dir in $cf_cv_src_modules
2294do
2295	SRC_SUBDIRS="$SRC_SUBDIRS $cf_dir"
2296done
2297SRC_SUBDIRS="$SRC_SUBDIRS misc test"
2298test "$cf_with_cxx_binding" != no && SRC_SUBDIRS="$SRC_SUBDIRS c++"
2299
2300ADA_SUBDIRS=
2301if test "$cf_cv_prog_gnat_correct" = yes && test -f $srcdir/Ada95/Makefile.in; then
2302   SRC_SUBDIRS="$SRC_SUBDIRS Ada95"
2303   ADA_SUBDIRS="gen src samples"
2304fi
2305
2306SUB_MAKEFILES=
2307for cf_dir in $SRC_SUBDIRS
2308do
2309	SUB_MAKEFILES="$SUB_MAKEFILES $cf_dir/Makefile"
2310done
2311
2312if test -n "$ADA_SUBDIRS"; then
2313   for cf_dir in $ADA_SUBDIRS
2314   do
2315      SUB_MAKEFILES="$SUB_MAKEFILES Ada95/$cf_dir/Makefile"
2316   done
2317   AC_SUBST(ADA_SUBDIRS)
2318fi
2319])dnl
2320dnl ---------------------------------------------------------------------------
2321dnl Check for -lstdc++, which is GNU's standard C++ library.
2322AC_DEFUN([CF_STDCPP_LIBRARY],
2323[
2324if test -n "$GXX" ; then
2325case $cf_cv_system_name in #(vi
2326os2*) #(vi
2327	cf_stdcpp_libname=stdcpp
2328	;;
2329*)
2330	cf_stdcpp_libname=stdc++
2331	;;
2332esac
2333AC_CACHE_CHECK(for library $cf_stdcpp_libname,cf_cv_libstdcpp,[
2334	cf_save="$LIBS"
2335	LIBS="$LIBS -l$cf_stdcpp_libname"
2336AC_TRY_LINK([
2337#include <strstream.h>],[
2338char buf[80];
2339strstreambuf foo(buf, sizeof(buf))
2340],
2341	[cf_cv_libstdcpp=yes],
2342	[cf_cv_libstdcpp=no])
2343	LIBS="$cf_save"
2344])
2345test "$cf_cv_libstdcpp" = yes && CXXLIBS="$CXXLIBS -l$cf_stdcpp_libname"
2346fi
2347])dnl
2348dnl ---------------------------------------------------------------------------
2349dnl	Remove "-g" option from the compiler options
2350AC_DEFUN([CF_STRIP_G_OPT],
2351[$1=`echo ${$1} | sed -e 's/-g //' -e 's/-g$//'`])dnl
2352dnl ---------------------------------------------------------------------------
2353dnl Check if we need _POSIX_SOURCE defined to use struct sigaction.  We'll only
2354dnl do this if we've found the sigaction function.
2355dnl
2356dnl If needed, define SVR4_ACTION.
2357AC_DEFUN([CF_STRUCT_SIGACTION],[
2358if test "$ac_cv_func_sigaction" = yes; then
2359AC_MSG_CHECKING(whether sigaction needs _POSIX_SOURCE)
2360AC_TRY_COMPILE([
2361#include <sys/types.h>
2362#include <signal.h>],
2363	[struct sigaction act],
2364	[sigact_bad=no],
2365	[
2366AC_TRY_COMPILE([
2367#define _POSIX_SOURCE
2368#include <sys/types.h>
2369#include <signal.h>],
2370	[struct sigaction act],
2371	[sigact_bad=yes
2372	 AC_DEFINE(SVR4_ACTION)],
2373	 [sigact_bad=unknown])])
2374AC_MSG_RESULT($sigact_bad)
2375fi
2376])dnl
2377dnl ---------------------------------------------------------------------------
2378dnl Some machines require _POSIX_SOURCE to completely define struct termios.
2379dnl If so, define SVR4_TERMIO
2380AC_DEFUN([CF_STRUCT_TERMIOS],[
2381AC_CHECK_HEADERS( \
2382termio.h \
2383termios.h \
2384unistd.h \
2385)
2386if test "$ISC" = yes ; then
2387	AC_CHECK_HEADERS( sys/termio.h )
2388fi
2389if test "$ac_cv_header_termios_h" = yes ; then
2390	case "$CFLAGS $CPPFLAGS" in
2391	*-D_POSIX_SOURCE*)
2392		termios_bad=dunno ;;
2393	*)	termios_bad=maybe ;;
2394	esac
2395	if test "$termios_bad" = maybe ; then
2396	AC_MSG_CHECKING(whether termios.h needs _POSIX_SOURCE)
2397	AC_TRY_COMPILE([#include <termios.h>],
2398		[struct termios foo; int x = foo.c_iflag],
2399		termios_bad=no, [
2400		AC_TRY_COMPILE([
2401#define _POSIX_SOURCE
2402#include <termios.h>],
2403			[struct termios foo; int x = foo.c_iflag],
2404			termios_bad=unknown,
2405			termios_bad=yes AC_DEFINE(SVR4_TERMIO))
2406			])
2407	AC_MSG_RESULT($termios_bad)
2408	fi
2409fi
2410])dnl
2411dnl ---------------------------------------------------------------------------
2412dnl	Shorthand macro for substituting things that the user may override
2413dnl	with an environment variable.
2414dnl
2415dnl	$1 = long/descriptive name
2416dnl	$2 = environment variable
2417dnl	$3 = default value
2418AC_DEFUN([CF_SUBST],
2419[AC_CACHE_VAL(cf_cv_subst_$2,[
2420AC_MSG_CHECKING(for $1 (symbol $2))
2421test -z "[$]$2" && $2=$3
2422AC_MSG_RESULT([$]$2)
2423AC_SUBST($2)
2424cf_cv_subst_$2=[$]$2])
2425$2=${cf_cv_subst_$2}
2426])dnl
2427dnl ---------------------------------------------------------------------------
2428dnl Get the version-number for use in shared-library naming, etc.
2429AC_DEFUN([CF_SUBST_NCURSES_VERSION],
2430[
2431NCURSES_MAJOR="`egrep '^NCURSES_MAJOR[[ 	]]*=' $srcdir/dist.mk | sed -e 's/^[[^0-9]]*//'`"
2432NCURSES_MINOR="`egrep '^NCURSES_MINOR[[ 	]]*=' $srcdir/dist.mk | sed -e 's/^[[^0-9]]*//'`"
2433NCURSES_PATCH="`egrep '^NCURSES_PATCH[[ 	]]*=' $srcdir/dist.mk | sed -e 's/^[[^0-9]]*//'`"
2434cf_cv_abi_version=${NCURSES_MAJOR}
2435cf_cv_rel_version=${NCURSES_MAJOR}.${NCURSES_MINOR}
2436dnl Show the computed version, for logging
2437AC_MSG_RESULT(Configuring NCURSES $cf_cv_rel_version ABI $cf_cv_abi_version (`date`))
2438dnl We need these values in the generated headers
2439AC_SUBST(NCURSES_MAJOR)
2440AC_SUBST(NCURSES_MINOR)
2441AC_SUBST(NCURSES_PATCH)
2442dnl We need these values in the generated makefiles
2443AC_SUBST(cf_cv_rel_version)
2444AC_SUBST(cf_cv_abi_version)
2445AC_SUBST(cf_cv_cc_bool_type)
2446AC_SUBST(cf_cv_builtin_bool)
2447AC_SUBST(cf_cv_type_of_bool)dnl
2448])dnl
2449dnl ---------------------------------------------------------------------------
2450dnl Check if we can include <sys/time.h> with <sys/select.h>; this breaks on
2451dnl older SCO configurations.
2452AC_DEFUN([CF_SYS_TIME_SELECT],
2453[
2454AC_MSG_CHECKING(if sys/time.h works with sys/select.h)
2455AC_CACHE_VAL(cf_cv_sys_time_select,[
2456AC_TRY_COMPILE([
2457#include <sys/types.h>
2458#ifdef HAVE_SYS_TIME_H
2459#include <sys/time.h>
2460#endif
2461#ifdef HAVE_SYS_SELECT_H
2462#include <sys/select.h>
2463#endif
2464],[],[cf_cv_sys_time_select=yes],
2465     [cf_cv_sys_time_select=no])
2466     ])
2467AC_MSG_RESULT($cf_cv_sys_time_select)
2468test "$cf_cv_sys_time_select" = yes && AC_DEFINE(HAVE_SYS_TIME_SELECT)
2469])dnl
2470dnl ---------------------------------------------------------------------------
2471dnl Determine the type we should use for chtype (and attr_t, which is treated
2472dnl as the same thing).  We want around 32 bits, so on most machines want a
2473dnl long, but on newer 64-bit machines, probably want an int.  If we're using
2474dnl wide characters, we have to have a type compatible with that, as well.
2475AC_DEFUN([CF_TYPEOF_CHTYPE],
2476[
2477AC_REQUIRE([CF_UNSIGNED_LITERALS])
2478AC_MSG_CHECKING([for type of chtype])
2479AC_CACHE_VAL(cf_cv_typeof_chtype,[
2480		AC_TRY_RUN([
2481#ifdef USE_WIDEC_SUPPORT
2482#include <stddef.h>	/* we want wchar_t */
2483#define WANT_BITS 39
2484#else
2485#define WANT_BITS 31
2486#endif
2487#include <stdio.h>
2488int main()
2489{
2490	FILE *fp = fopen("cf_test.out", "w");
2491	if (fp != 0) {
2492		char *result = "long";
2493#ifdef USE_WIDEC_SUPPORT
2494		/*
2495		 * If wchar_t is smaller than a long, it must be an int or a
2496		 * short.  We prefer not to use a short anyway.
2497		 */
2498		if (sizeof(unsigned long) > sizeof(wchar_t))
2499			result = "int";
2500#endif
2501		if (sizeof(unsigned long) > sizeof(unsigned int)) {
2502			int n;
2503			unsigned int x;
2504			for (n = 0; n < WANT_BITS; n++) {
2505				unsigned int y = (x >> n);
2506				if (y != 1 || x == 0) {
2507					x = 0;
2508					break;
2509				}
2510			}
2511			/*
2512			 * If x is nonzero, an int is big enough for the bits
2513			 * that we want.
2514			 */
2515			result = (x != 0) ? "int" : "long";
2516		}
2517		fputs(result, fp);
2518		fclose(fp);
2519	}
2520	exit(0);
2521}
2522		],
2523		[cf_cv_typeof_chtype=`cat cf_test.out`],
2524		[cf_cv_typeof_chtype=long],
2525		[cf_cv_typeof_chtype=long])
2526		rm -f cf_test.out
2527	])
2528AC_MSG_RESULT($cf_cv_typeof_chtype)
2529
2530AC_SUBST(cf_cv_typeof_chtype)
2531AC_DEFINE_UNQUOTED(TYPEOF_CHTYPE,$cf_cv_typeof_chtype)
2532
2533cf_cv_1UL="1"
2534test "$cf_cv_unsigned_literals" = yes && cf_cv_1UL="${cf_cv_1UL}U"
2535test "$cf_cv_typeof_chtype"    = long && cf_cv_1UL="${cf_cv_1UL}L"
2536AC_SUBST(cf_cv_1UL)
2537
2538])dnl
2539dnl ---------------------------------------------------------------------------
2540dnl
2541AC_DEFUN([CF_TYPE_SIGACTION],
2542[
2543AC_MSG_CHECKING([for type sigaction_t])
2544AC_CACHE_VAL(cf_cv_type_sigaction,[
2545	AC_TRY_COMPILE([
2546#include <signal.h>],
2547		[sigaction_t x],
2548		[cf_cv_type_sigaction=yes],
2549		[cf_cv_type_sigaction=no])])
2550AC_MSG_RESULT($cf_cv_type_sigaction)
2551test "$cf_cv_type_sigaction" = yes && AC_DEFINE(HAVE_TYPE_SIGACTION)
2552])dnl
2553dnl ---------------------------------------------------------------------------
2554dnl Test if the compiler supports 'U' and 'L' suffixes.  Only old compilers
2555dnl won't, but they're still there.
2556AC_DEFUN([CF_UNSIGNED_LITERALS],
2557[
2558AC_MSG_CHECKING([if unsigned literals are legal])
2559AC_CACHE_VAL(cf_cv_unsigned_literals,[
2560	AC_TRY_COMPILE([],[long x = 1L + 1UL + 1U + 1],
2561		[cf_cv_unsigned_literals=yes],
2562		[cf_cv_unsigned_literals=no])
2563	])
2564AC_MSG_RESULT($cf_cv_unsigned_literals)
2565])dnl
2566dnl ---------------------------------------------------------------------------
2567dnl Make an uppercase version of a variable
2568dnl $1=uppercase($2)
2569AC_DEFUN([CF_UPPER],
2570[
2571$1=`echo "$2" | sed y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%`
2572])dnl
2573dnl ---------------------------------------------------------------------------
2574dnl Compute the shift-mask that we'll use for wide-character indices.  We use
2575dnl all but the index portion of chtype for storing attributes.
2576AC_DEFUN([CF_WIDEC_SHIFT],
2577[
2578AC_REQUIRE([CF_TYPEOF_CHTYPE])
2579AC_MSG_CHECKING([for number of bits in chtype])
2580AC_CACHE_VAL(cf_cv_shift_limit,[
2581	AC_TRY_RUN([
2582#include <stdio.h>
2583int main()
2584{
2585	FILE *fp = fopen("cf_test.out", "w");
2586	if (fp != 0) {
2587		int n;
2588		unsigned TYPEOF_CHTYPE x = 1L;
2589		for (n = 0; ; n++) {
2590			unsigned long y = (x >> n);
2591			if (y != 1 || x == 0)
2592				break;
2593			x <<= 1;
2594		}
2595		fprintf(fp, "%d", n);
2596		fclose(fp);
2597	}
2598	exit(0);
2599}
2600		],
2601		[cf_cv_shift_limit=`cat cf_test.out`],
2602		[cf_cv_shift_limit=32],
2603		[cf_cv_shift_limit=32])
2604		rm -f cf_test.out
2605	])
2606AC_MSG_RESULT($cf_cv_shift_limit)
2607AC_SUBST(cf_cv_shift_limit)
2608
2609AC_MSG_CHECKING([for width of character-index])
2610AC_CACHE_VAL(cf_cv_widec_shift,[
2611if test ".$with_widec" = ".yes" ; then
2612	cf_attrs_width=39
2613	if ( expr $cf_cv_shift_limit \> $cf_attrs_width >/dev/null )
2614	then
2615		cf_cv_widec_shift=`expr 16 + $cf_cv_shift_limit - $cf_attrs_width`
2616	else
2617		cf_cv_widec_shift=16
2618	fi
2619else
2620	cf_cv_widec_shift=8
2621fi
2622])
2623AC_MSG_RESULT($cf_cv_widec_shift)
2624AC_SUBST(cf_cv_widec_shift)
2625])dnl
2626dnl ---------------------------------------------------------------------------
2627dnl Wrapper for AC_ARG_WITH to ensure that user supplies a pathname, not just
2628dnl defaulting to yes/no.
2629dnl
2630dnl $1 = option name
2631dnl $2 = help-text
2632dnl $3 = environment variable to set
2633dnl $4 = default value, shown in the help-message, must be a constant
2634dnl $5 = default value, if it's an expression & cannot be in the help-message
2635dnl
2636AC_DEFUN([CF_WITH_PATH],
2637[AC_ARG_WITH($1,[$2 ](default: ifelse($4,,empty,$4)),,
2638ifelse($4,,[withval="${$3}"],[withval="${$3-ifelse($5,,$4,$5)}"]))dnl
2639CF_PATH_SYNTAX(withval)
2640eval $3="$withval"
2641AC_SUBST($3)dnl
2642])dnl
2643dnl ---------------------------------------------------------------------------
2644dnl Process an option specifying a list of colon-separated paths.
2645dnl
2646dnl $1 = option name
2647dnl $2 = help-text
2648dnl $3 = environment variable to set
2649dnl $4 = default value, shown in the help-message, must be a constant
2650dnl $5 = default value, if it's an expression & cannot be in the help-message
2651dnl
2652AC_DEFUN([CF_WITH_PATHLIST],[
2653AC_REQUIRE([CF_PATHSEP])
2654AC_ARG_WITH($1,[$2 ](default: ifelse($4,,empty,$4)),,
2655ifelse($4,,[withval="${$3}"],[withval="${$3-ifelse($5,,$4,$5)}"]))dnl
2656
2657IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS="${IFS}${PATHSEP}"
2658cf_dst_path=
2659for cf_src_path in $withval
2660do
2661  CF_PATH_SYNTAX(cf_src_path)
2662  test -n "$cf_dst_path" && cf_dst_path="${cf_dst_path}:"
2663  cf_dst_path="${cf_dst_path}${cf_src_path}"
2664done
2665IFS="$ac_save_ifs"
2666
2667eval $3="$cf_dst_path"
2668AC_SUBST($3)dnl
2669])dnl
2670