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