ncurses 5.1
[ncurses.git] / aclocal.m4
1 dnl***************************************************************************
2 dnl Copyright (c) 1998-2000 Free Software Foundation, Inc.                   *
3 dnl                                                                          *
4 dnl Permission is hereby granted, free of charge, to any person obtaining a  *
5 dnl copy of this software and associated documentation files (the            *
6 dnl "Software"), to deal in the Software without restriction, including      *
7 dnl without limitation the rights to use, copy, modify, merge, publish,      *
8 dnl distribute, distribute with modifications, sublicense, and/or sell       *
9 dnl copies of the Software, and to permit persons to whom the Software is    *
10 dnl furnished to do so, subject to the following conditions:                 *
11 dnl                                                                          *
12 dnl The above copyright notice and this permission notice shall be included  *
13 dnl in all copies or substantial portions of the Software.                   *
14 dnl                                                                          *
15 dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16 dnl OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17 dnl MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18 dnl IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19 dnl DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20 dnl OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21 dnl THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22 dnl                                                                          *
23 dnl Except as contained in this notice, the name(s) of the above copyright   *
24 dnl holders shall not be used in advertising or otherwise to promote the     *
25 dnl sale, use or other dealings in this Software without prior written       *
26 dnl authorization.                                                           *
27 dnl***************************************************************************
28 dnl
29 dnl Author: Thomas E. Dickey <dickey@clark.net> 1996,1997,1998
30 dnl
31 dnl $Id: aclocal.m4,v 1.214 2000/07/07 15:11:34 tom Exp $
32 dnl Macros used in NCURSES auto-configuration script.
33 dnl
34 dnl ---------------------------------------------------------------------------
35 dnl ---------------------------------------------------------------------------
36 dnl Construct the list of include-options for the C programs in the Ada95
37 dnl binding.
38 AC_DEFUN([CF_ADA_INCLUDE_DIRS],
39 [
40 ACPPFLAGS="$ACPPFLAGS -I. -I../../include"
41 if test "$srcdir" != "."; then
42         ACPPFLAGS="$ACPPFLAGS -I\$(srcdir)/../../include"
43 fi
44 if test -z "$GCC"; then
45         ACPPFLAGS="$ACPPFLAGS -I\$(includedir)"
46 elif 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
54 fi
55 AC_SUBST(ACPPFLAGS)
56 ])dnl
57 dnl ---------------------------------------------------------------------------
58 dnl This is adapted from the macros 'fp_PROG_CC_STDC' and 'fp_C_PROTOTYPES'
59 dnl in the sharutils 4.2 distribution.
60 AC_DEFUN([CF_ANSI_CC_CHECK],
61 [
62 AC_MSG_CHECKING(for ${CC-cc} option to accept ANSI C)
63 AC_CACHE_VAL(cf_cv_ansi_cc,[
64 cf_cv_ansi_cc=no
65 cf_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)
73 for cf_arg in "-DCC_HAS_PROTOS" \
74         "" \
75         -qlanglvl=ansi \
76         -std1 \
77         -Ae \
78         "-Aa -D_HPUX_SOURCE" \
79         -Xc
80 do
81         CFLAGS="$cf_save_CFLAGS $cf_arg"
82         AC_TRY_COMPILE(
83 [
84 #ifndef CC_HAS_PROTOS
85 #if !defined(__STDC__) || (__STDC__ != 1)
86 choke 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])
94 done
95 CFLAGS="$cf_save_CFLAGS"
96 ])
97 AC_MSG_RESULT($cf_cv_ansi_cc)
98
99 if test "$cf_cv_ansi_cc" != "no"; then
100 if test ".$cf_cv_ansi_cc" != ".-DCC_HAS_PROTOS"; then
101         CFLAGS="$CFLAGS $cf_cv_ansi_cc"
102 else
103         AC_DEFINE(CC_HAS_PROTOS)
104 fi
105 fi
106 ])dnl
107 dnl ---------------------------------------------------------------------------
108 dnl For programs that must use an ANSI compiler, obtain compiler options that
109 dnl will make it recognize prototypes.  We'll do preprocessor checks in other
110 dnl macros, since tools such as unproto can fake prototypes, but only part of
111 dnl the preprocessor.
112 AC_DEFUN([CF_ANSI_CC_REQD],
113 [AC_REQUIRE([CF_ANSI_CC_CHECK])
114 if test "$cf_cv_ansi_cc" = "no"; then
115         AC_ERROR(
116 [Your compiler does not appear to recognize prototypes.
117 You 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])
121 fi
122 ])dnl
123 dnl ---------------------------------------------------------------------------
124 dnl Test if 'bool' is a builtin type in the configured C++ compiler.  Some
125 dnl older compilers (e.g., gcc 2.5.8) don't support 'bool' directly; gcc
126 dnl 2.6.3 does, in anticipation of the ANSI C++ standard.
127 dnl
128 dnl Treat the configuration-variable specially here, since we're directly
129 dnl substituting its value (i.e., 1/0).
130 AC_DEFUN([CF_BOOL_DECL],
131 [
132 AC_MSG_CHECKING([for builtin ifelse(AC_LANG,[C],$CC,$CXX) bool type])
133 AC_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         ])
141 if test $ifelse($1,,cf_cv_builtin_bool,[$1]) = 1
142 then    AC_MSG_RESULT(yes)
143 else    AC_MSG_RESULT(no)
144 fi
145 ])dnl
146 dnl ---------------------------------------------------------------------------
147 dnl Test for the size of 'bool' in the configured C++ compiler (e.g., a type).
148 dnl Don't bother looking for bool.h, since it's been deprecated.
149 AC_DEFUN([CF_BOOL_SIZE],
150 [
151 AC_MSG_CHECKING([for size of ifelse(AC_LANG,[C],$CC,$CXX) bool])
152 AC_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
164 main()
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
185 AC_MSG_RESULT($cf_cv_type_of_bool)
186 if 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
189 fi
190 ])dnl
191 dnl ---------------------------------------------------------------------------
192 dnl Determine the default configuration into which we'll install ncurses.  This
193 dnl can be overridden by the user's command-line options.  There's two items to
194 dnl look for:
195 dnl     1. the prefix (e.g., /usr)
196 dnl     2. the header files (e.g., /usr/include/ncurses)
197 dnl We'll look for a previous installation of ncurses and use the same defaults.
198 dnl
199 dnl We don't use AC_PREFIX_DEFAULT, because it gets evaluated too soon, and
200 dnl we don't use AC_PREFIX_PROGRAM, because we cannot distinguish ncurses's
201 dnl programs from a vendor's.
202 AC_DEFUN([CF_CFG_DEFAULTS],
203 [
204 AC_MSG_CHECKING(for prefix)
205 if 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
214 fi
215 AC_MSG_RESULT($prefix)
216
217 if test "x$prefix" = "xNONE" ; then
218 AC_MSG_CHECKING(for default include-directory)
219 test -n "$verbose" && echo 1>&AC_FD_MSG
220 for 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
229 do
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
239 done
240 AC_MSG_RESULT($includedir)
241 fi
242 ])dnl
243 dnl ---------------------------------------------------------------------------
244 dnl Check if the terminal-capability database functions are available.  If not,
245 dnl ncurses has a much-reduced version.
246 AC_DEFUN([CF_CGETENT],[
247 AC_MSG_CHECKING(for terminal-capability database functions)
248 AC_CACHE_VAL(cf_cv_cgetent,[
249 AC_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 ])
261 AC_MSG_RESULT($cf_cv_cgetent)
262 test $cf_cv_cgetent = yes && AC_DEFINE(HAVE_BSD_CGETENT)
263 ])dnl
264 dnl ---------------------------------------------------------------------------
265 dnl Check if we're accidentally using a cache from a different machine.
266 dnl Derive the system name, as a check for reusing the autoconf cache.
267 dnl
268 dnl If we've packaged config.guess and config.sub, run that (since it does a
269 dnl better job than uname).
270 AC_DEFUN([CF_CHECK_CACHE],
271 [
272 if test -f $srcdir/config.guess ; then
273         AC_CANONICAL_HOST
274         system_name="$host_os"
275 else
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
280 fi
281 test -n "$system_name" && AC_DEFINE_UNQUOTED(SYSTEM_NAME,"$system_name")
282 AC_CACHE_VAL(cf_cv_system_name,[cf_cv_system_name="$system_name"])
283
284 test -z "$system_name" && system_name="$cf_cv_system_name"
285 test -n "$cf_cv_system_name" && AC_MSG_RESULT("Configuring for $cf_cv_system_name")
286
287 if 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.")
290 fi
291 ])dnl
292 dnl ---------------------------------------------------------------------------
293 dnl Check for data that is usually declared in <stdio.h> or <errno.h>, e.g.,
294 dnl the 'errno' variable.  Define a DECL_xxx symbol if we must declare it
295 dnl ourselves.
296 dnl
297 dnl (I would use AC_CACHE_CHECK here, but it will not work when called in a
298 dnl loop from CF_SYS_ERRLIST).
299 dnl
300 dnl $1 = the name to check
301 AC_DEFUN([CF_CHECK_ERRNO],
302 [
303 AC_MSG_CHECKING(if external $1 is declared)
304 AC_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
317 eval 'cf_result=$cf_cv_dcl_'$1
318 AC_MSG_RESULT($cf_result)
319
320 if test "$cf_result" = no ; then
321     eval 'cf_result=DECL_'$1
322     CF_UPPER(cf_result,$cf_result)
323     AC_DEFINE_UNQUOTED($cf_result)
324 fi
325
326 # It's possible (for near-UNIX clones) that the data doesn't exist
327 CF_CHECK_EXTERN_DATA($1,int)
328 ])dnl
329 dnl ---------------------------------------------------------------------------
330 dnl Check for existence of external data in the current set of libraries.  If
331 dnl we can modify it, it's real enough.
332 dnl $1 = the name to check
333 dnl $2 = its type
334 AC_DEFUN([CF_CHECK_EXTERN_DATA],
335 [
336 AC_MSG_CHECKING(if external $1 exists)
337 AC_CACHE_VAL(cf_cv_have_$1,[
338     AC_TRY_LINK([
339 #undef $1
340 extern $2 $1;
341 ],
342     [$1 = 2],
343     [eval 'cf_cv_have_'$1'=yes'],
344     [eval 'cf_cv_have_'$1'=no'])])
345
346 eval 'cf_result=$cf_cv_have_'$1
347 AC_MSG_RESULT($cf_result)
348
349 if test "$cf_result" = yes ; then
350     eval 'cf_result=HAVE_'$1
351     CF_UPPER(cf_result,$cf_result)
352     AC_DEFINE_UNQUOTED($cf_result)
353 fi
354
355 ])dnl
356 dnl ---------------------------------------------------------------------------
357 dnl Check if the C++ compiler accepts duplicate parameter initialization.  This
358 dnl is a late feature for the standard and is not in some recent compilers
359 dnl (1999/9/11).
360 AC_DEFUN([CF_CPP_PARAM_INIT],
361 [
362 if test -n "$CXX" ; then
363 AC_CACHE_CHECK(if $CXX accepts parameter initialization,cf_cv_cpp_param_init,[
364         AC_LANG_CPLUSPLUS
365         AC_TRY_RUN([
366 class TEST {
367 private:
368         int value;
369 public:
370         TEST(int x = 1);
371         ~TEST();
372 };
373
374 TEST::TEST(int x = 1)   // some compilers do not like second initializer
375 {
376         value = x;
377 }
378 void main() { }
379 ],
380         [cf_cv_cpp_param_init=yes],
381         [cf_cv_cpp_param_init=no],
382         [cf_cv_cpp_param_init=unknown])
383 ])
384 fi
385 test "$cf_cv_cpp_param_init" = yes && AC_DEFINE(CPP_HAS_PARAM_INIT)
386 ])dnl
387 dnl ---------------------------------------------------------------------------
388 AC_DEFUN([CF_DIRS_TO_MAKE],
389 [
390 DIRS_TO_MAKE="lib"
391 for cf_item in $cf_list_models
392 do
393         CF_OBJ_SUBDIR($cf_item,cf_subdir)
394         DIRS_TO_MAKE="$DIRS_TO_MAKE $cf_subdir"
395 done
396 for cf_dir in $DIRS_TO_MAKE
397 do
398         test ! -d $cf_dir && mkdir $cf_dir
399 done
400 AC_SUBST(DIRS_TO_MAKE)
401 ])dnl
402 dnl ---------------------------------------------------------------------------
403 dnl Check if 'errno' is declared in <errno.h>
404 AC_DEFUN([CF_ERRNO],
405 [
406 CF_CHECK_ERRNO(errno)
407 ])dnl
408 dnl ---------------------------------------------------------------------------
409 dnl Test for conflicting definitions of exception in gcc 2.8.0, etc., between
410 dnl math.h and builtin.h, only for ncurses
411 AC_DEFUN([CF_ETIP_DEFINES],
412 [
413 AC_MSG_CHECKING(for special defines needed for etip.h)
414 cf_save_CXXFLAGS="$CXXFLAGS"
415 cf_result="none"
416 for cf_math in "" MATH_H
417 do
418 for cf_excp in "" MATH_EXCEPTION
419 do
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}"
423 AC_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 ],[])
431 done
432 done
433 AC_MSG_RESULT($cf_result)
434 CXXFLAGS="$cf_save_CXXFLAGS"
435 ])
436 dnl ---------------------------------------------------------------------------
437 dnl Check for memmove, or a bcopy that can handle overlapping copy.  If neither
438 dnl is found, add our own version of memmove to the list of objects.
439 AC_DEFUN([CF_FUNC_MEMMOVE],
440 [
441 AC_CHECK_FUNC(memmove,,[
442 AC_CHECK_FUNC(bcopy,[
443         AC_CACHE_CHECK(if bcopy does overlapping moves,cf_cv_good_bcopy,[
444                 AC_TRY_RUN([
445 int 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
465 dnl ---------------------------------------------------------------------------
466 dnl See if the poll function really works.  Some platforms have poll(), but
467 dnl it does not work for terminals or files.
468 AC_DEFUN([CF_FUNC_POLL],[
469 AC_CACHE_CHECK(if poll really works,cf_cv_working_poll,[
470 AC_TRY_RUN([
471 #include <stdio.h>
472 #ifdef HAVE_POLL_H
473 #include <poll.h>
474 #else
475 #include <sys/poll.h>
476 #endif
477 int 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])])
490 test "$cf_cv_working_poll" = "yes" && AC_DEFINE(HAVE_WORKING_POLL)
491 ])dnl
492 dnl ---------------------------------------------------------------------------
493 dnl Test for availability of useful gcc __attribute__ directives to quiet
494 dnl compiler warnings.  Though useful, not all are supported -- and contrary
495 dnl to documentation, unrecognized directives cause older compilers to barf.
496 AC_DEFUN([CF_GCC_ATTRIBUTES],
497 [
498 if test -n "$GCC"
499 then
500 cat > 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
513 EOF
514 if test -n "$GCC"
515 then
516         AC_CHECKING([for $CC __attribute__ directives])
517         changequote(,)dnl
518 cat > 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
533 extern void wow(char *,...) GCC_SCANFLIKE(1,2);
534 extern void oops(char *,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN;
535 extern void foo(void) GCC_NORETURN;
536 int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) { return 0; }
537 EOF
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
548 EOF
549                         ;;
550                 *)
551                 cat >conftest.h <<EOF
552 #define GCC_$CF_ATTRIBUTE $cf_directive
553 EOF
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
563 else
564         fgrep define conftest.i >>confdefs.h
565 fi
566 rm -rf conftest*
567 fi
568 ])dnl
569 dnl ---------------------------------------------------------------------------
570 dnl Check if the compiler supports useful warning options.  There's a few that
571 dnl we don't use, simply because they're too noisy:
572 dnl
573 dnl     -Wconversion (useful in older versions of gcc, but not in gcc 2.7.x)
574 dnl     -Wredundant-decls (system headers make this too noisy)
575 dnl     -Wtraditional (combines too many unrelated messages, only a few useful)
576 dnl     -Wwrite-strings (too noisy, but should review occasionally)
577 dnl     -pedantic
578 dnl
579 AC_DEFUN([CF_GCC_WARNINGS],
580 [
581 if test -n "$GCC"
582 then
583         changequote(,)dnl
584         cat > conftest.$ac_ext <<EOF
585 #line __oline__ "configure"
586 int main(int argc, char *argv[]) { return (argv[argc-1] == 0) ; }
587 EOF
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"
615 fi
616 AC_SUBST(EXTRA_CFLAGS)
617 ])dnl
618 dnl ---------------------------------------------------------------------------
619 dnl Verify that a test program compiles and runs with GNAT
620 dnl $cf_ada_make is set to the program that compiles/links
621 AC_DEFUN([CF_GNAT_TRY_RUN],
622 [
623 rm -f conftest*
624 cat >>conftest.ads <<CF_EOF
625 $1
626 CF_EOF
627 cat >>conftest.adb <<CF_EOF
628 $2
629 CF_EOF
630 if ( $cf_ada_make conftest 1>&AC_FD_CC 2>&1 ) ; then
631    if ( ./conftest 1>&AC_FD_CC 2>&1 ) ; then
632 ifelse($3,,      :,[      $3])
633 ifelse($4,,,[   else
634       $4])
635    fi
636 ifelse($4,,,[else
637    $4])
638 fi
639 rm -f conftest*
640 ])dnl
641 dnl ---------------------------------------------------------------------------
642 dnl Verify Version of GNAT.
643 AC_DEFUN([CF_GNAT_VERSION],
644 [
645 changequote(<<, >>)dnl
646 cf_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>>;}'`
648 case $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      ;;
655 esac
656 case $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       ;;
664 esac
665 changequote([, ])dnl
666 ])
667 dnl ---------------------------------------------------------------------------
668 dnl If we're trying to use g++, test if libg++ is installed (a rather common
669 dnl problem :-).  If we have the compiler but no library, we'll be able to
670 dnl configure, but won't be able to build the c++ demo program.
671 AC_DEFUN([CF_GPP_LIBRARY],
672 [
673 cf_cxx_library=unknown
674 case $cf_cv_system_name in #(vi
675 os2*) #(vi
676         cf_gpp_libname=gpp
677         ;;
678 *)
679         cf_gpp_libname=g++
680         ;;
681 esac
682 if 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)
707 fi
708 ])dnl
709 dnl ---------------------------------------------------------------------------
710 dnl Insert text into the help-message, for readability, from AC_ARG_WITH.
711 AC_DEFUN([CF_HELP_MESSAGE],
712 [AC_DIVERT_HELP([$1])dnl
713 ])dnl
714 dnl ---------------------------------------------------------------------------
715 dnl Construct the list of include-options according to whether we're building
716 dnl in the source directory or using '--srcdir=DIR' option.  If we're building
717 dnl with gcc, don't append the includedir if it happens to be /usr/include,
718 dnl since that usually breaks gcc's shadow-includes.
719 AC_DEFUN([CF_INCLUDE_DIRS],
720 [
721 CPPFLAGS="$CPPFLAGS -I. -I../include"
722 if test "$srcdir" != "."; then
723         CPPFLAGS="$CPPFLAGS -I\$(srcdir)/../include"
724 fi
725 if test -z "$GCC"; then
726         CPPFLAGS="$CPPFLAGS -I\$(includedir)"
727 elif 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
735 fi
736 AC_SUBST(CPPFLAGS)
737 ])dnl
738 dnl ---------------------------------------------------------------------------
739 dnl Check if we have either a function or macro for 'isascii()'.
740 AC_DEFUN([CF_ISASCII],
741 [
742 AC_MSG_CHECKING(for isascii)
743 AC_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
748 AC_MSG_RESULT($cf_cv_have_isascii)
749 test $cf_cv_have_isascii = yes && AC_DEFINE(HAVE_ISASCII)
750 ])dnl
751 dnl ---------------------------------------------------------------------------
752 dnl Compute the library-prefix for the given host system
753 dnl $1 = variable to set
754 AC_DEFUN([CF_LIB_PREFIX],
755 [
756         case $cf_cv_system_name in
757         os2)    LIB_PREFIX=''     ;;
758         *)      LIB_PREFIX='lib'  ;;
759         esac
760 ifelse($1,,,[$1=$LIB_PREFIX])
761         AC_SUBST(LIB_PREFIX)
762 ])dnl
763 dnl ---------------------------------------------------------------------------
764 dnl Append definitions and rules for the given models to the subdirectory
765 dnl Makefiles, and the recursion rule for the top-level Makefile.  If the
766 dnl subdirectory is a library-source directory, modify the LIBRARIES list in
767 dnl the corresponding makefile to list the models that we'll generate.
768 dnl
769 dnl For shared libraries, make a list of symbolic links to construct when
770 dnl generating each library.  The convention used for Linux is the simplest
771 dnl one:
772 dnl     lib<name>.so    ->
773 dnl     lib<name>.so.<major>    ->
774 dnl     lib<name>.so.<maj>.<minor>
775 AC_DEFUN([CF_LIB_RULES],
776 [
777 CF_LIB_PREFIX(cf_prefix)
778 AC_REQUIRE([CF_SUBST_NCURSES_VERSION])
779 for cf_dir in $SRC_SUBDIRS
780 do
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                         if test $cf_item = shared ; then
788                         if test $cf_cv_do_symlinks = yes ; then
789                                 case "$cf_cv_shlib_version" in #(vi
790                                 rel) cf_suffix="$cf_suffix"'.$(REL_VERSION)' ;; #(vi
791                                 abi) cf_suffix="$cf_suffix"'.$(ABI_VERSION)' ;;
792                                 esac
793                         fi
794                         fi
795                         cf_libs_to_make="$cf_libs_to_make ../lib/${cf_prefix}${cf_dir}${cf_suffix}"
796                 done
797
798                 if test $cf_dir = ncurses ; then
799                         case "$LIB_SUBSETS" in #(vi
800                         termlib+*) #(vi
801                                 ;;
802                         *) #(vi
803                                 cf_item=`echo $cf_libs_to_make |sed -e s/$LIB_NAME/$TINFO_NAME/g`
804                                 cf_libs_to_make="$cf_item $cf_libs_to_make"
805                                 ;;
806                         esac
807                 fi
808
809                 sed -e "s@\@LIBS_TO_MAKE\@@$cf_libs_to_make@" \
810                         $cf_dir/Makefile >$cf_dir/Makefile.out
811                 mv $cf_dir/Makefile.out $cf_dir/Makefile
812
813                 $AWK -f $srcdir/mk-0th.awk \
814                         name=$cf_dir \
815                         $srcdir/$cf_dir/modules >>$cf_dir/Makefile
816
817                 for cf_item in $CF_LIST_MODELS
818                 do
819                         echo 'Appending rules for '$cf_item' model ('$cf_dir')'
820                         CF_UPPER(CF_ITEM,$cf_item)
821                         CF_LIB_SUFFIX($cf_item,cf_suffix)
822                         CF_OBJ_SUBDIR($cf_item,cf_subdir)
823
824                         # These dependencies really are for development, not
825                         # builds, but they are useful in porting, too.
826                         cf_depend="../include/ncurses_cfg.h"
827                         if test "$srcdir" = "."; then
828                                 cf_reldir="."
829                         else
830                                 cf_reldir="\$(srcdir)"
831                         fi
832
833                         if test -f $srcdir/$cf_dir/$cf_dir.priv.h; then
834                                 cf_depend="$cf_depend $cf_reldir/$cf_dir.priv.h"
835                         elif test -f $srcdir/$cf_dir/curses.priv.h; then
836                                 cf_depend="$cf_depend $cf_reldir/curses.priv.h"
837                         fi
838
839                         for cf_subset in $LIB_SUBSETS
840                         do
841                         $AWK -f $srcdir/mk-1st.awk \
842                                 name=$cf_dir \
843                                 traces=$LIB_TRACING \
844                                 MODEL=$CF_ITEM \
845                                 model=$cf_subdir \
846                                 prefix=$cf_prefix \
847                                 suffix=$cf_suffix \
848                                 subset=$cf_subset \
849                                 ShlibVer=$cf_cv_shlib_version \
850                                 DoLinks=$cf_cv_do_symlinks \
851                                 rmSoLocs=$cf_cv_rm_so_locs \
852                                 ldconfig="$LDCONFIG" \
853                                 overwrite=$WITH_OVERWRITE \
854                                 depend="$cf_depend" \
855                                 target="$target" \
856                                 $srcdir/$cf_dir/modules >>$cf_dir/Makefile
857                         test $cf_dir = ncurses && WITH_OVERWRITE=no
858                         $AWK -f $srcdir/mk-2nd.awk \
859                                 name=$cf_dir \
860                                 traces=$LIB_TRACING \
861                                 MODEL=$CF_ITEM \
862                                 model=$cf_subdir \
863                                 subset=$cf_subset \
864                                 srcdir=$srcdir \
865                                 echo=$WITH_ECHO \
866                                 $srcdir/$cf_dir/modules >>$cf_dir/Makefile
867                         done
868                 done
869         fi
870
871         echo '  cd '$cf_dir' && $(MAKE) $(CF_MFLAGS) [$]@' >>Makefile
872 done
873
874 for cf_dir in $SRC_SUBDIRS
875 do
876         if test -f $cf_dir/Makefile ; then
877                 case "$cf_dir" in
878                 Ada95) #(vi
879                         echo 'libs \' >> Makefile
880                         echo 'install.libs \' >> Makefile
881                         echo 'uninstall.libs ::' >> Makefile
882                         echo '  cd '$cf_dir' && $(MAKE) $(CF_MFLAGS) [$]@' >> Makefile
883                         ;;
884                 esac
885         fi
886
887         if test -f $srcdir/$cf_dir/modules; then
888                 echo >> Makefile
889                 if test -f $srcdir/$cf_dir/headers; then
890 cat >> Makefile <<CF_EOF
891 install.includes \\
892 uninstall.includes \\
893 CF_EOF
894                 fi
895 if test "$cf_dir" != "c++" ; then
896 echo 'lint \' >> Makefile
897 fi
898 cat >> Makefile <<CF_EOF
899 libs \\
900 lintlib \\
901 install.libs \\
902 uninstall.libs \\
903 install.$cf_dir \\
904 uninstall.$cf_dir ::
905         cd $cf_dir && \$(MAKE) \$(CF_MFLAGS) \[$]@
906 CF_EOF
907         elif test -f $srcdir/$cf_dir/headers; then
908 cat >> Makefile <<CF_EOF
909
910 libs \\
911 install.libs \\
912 uninstall.libs \\
913 install.includes \\
914 uninstall.includes ::
915         cd $cf_dir && \$(MAKE) \$(CF_MFLAGS) \[$]@
916 CF_EOF
917 fi
918 done
919
920 cat >> Makefile <<CF_EOF
921
922 install.data \
923 uninstall.data ::
924         cd misc && \$(MAKE) \$(CF_MFLAGS) \[$]@
925
926 install.man \
927 uninstall.man ::
928         cd man && \$(MAKE) \$(CF_MFLAGS) \[$]@
929
930 distclean ::
931         rm -f config.cache config.log config.status Makefile include/ncurses_cfg.h
932         rm -f headers.sh headers.sed
933         rm -rf \$(DIRS_TO_MAKE)
934 CF_EOF
935
936 dnl If we're installing into a subdirectory of /usr/include, etc., we should
937 dnl prepend the subdirectory's name to the "#include" paths.  It won't hurt
938 dnl anything, and will make it more standardized.  It's awkward to decide this
939 dnl at configuration because of quoting, so we'll simply make all headers
940 dnl installed via a script that can do the right thing.
941
942 rm -f headers.sed headers.sh
943
944 dnl ( generating this script makes the makefiles a little tidier :-)
945 echo creating headers.sh
946 cat >headers.sh <<CF_EOF
947 #! /bin/sh
948 # This shell script is generated by the 'configure' script.  It is invoked in a
949 # subdirectory of the build tree.  It generates a sed-script in the parent
950 # directory that is used to adjust includes for header files that reside in a
951 # subdirectory of /usr/include, etc.
952 PRG=""
953 while test \[$]# != 3
954 do
955 PRG="\$PRG \[$]1"; shift
956 done
957 DST=\[$]1
958 REF=\[$]2
959 SRC=\[$]3
960 echo installing \$SRC in \$DST
961 case \$DST in
962 /*/include/*)
963         TMPSRC=\${TMPDIR-/tmp}/\`basename \$SRC\`\$\$
964         TMPSED=\${TMPDIR-/tmp}/headers.sed\$\$
965         END=\`basename \$DST\`
966         for i in \`cat \$REF/../*/headers |fgrep -v "#"\`
967         do
968                 NAME=\`basename \$i\`
969                 echo "s/<\$NAME>/<\$END\/\$NAME>/" >> \$TMPSED
970         done
971         rm -f \$TMPSRC
972         sed -f \$TMPSED \$SRC > \$TMPSRC
973         eval \$PRG \$TMPSRC \$DST/\$SRC
974         rm -f \$TMPSRC \$TMPSED
975         ;;
976 *)
977         eval \$PRG \$SRC \$DST
978         ;;
979 esac
980 CF_EOF
981
982 chmod 0755 headers.sh
983
984 for cf_dir in $SRC_SUBDIRS
985 do
986         if test -f $srcdir/$cf_dir/headers; then
987         cat >>$cf_dir/Makefile <<CF_EOF
988 \$(INSTALL_PREFIX)\$(includedir) :
989         \$(srcdir)/../mkinstalldirs \[$]@
990
991 install \\
992 install.libs \\
993 install.includes :: \$(INSTALL_PREFIX)\$(includedir) \\
994 CF_EOF
995                 j=""
996                 for i in `cat $srcdir/$cf_dir/headers |fgrep -v "#"`
997                 do
998                         test -n "$j" && echo "          $j \\" >>$cf_dir/Makefile
999                         j=$i
1000                 done
1001                 echo "          $j" >>$cf_dir/Makefile
1002                 for i in `cat $srcdir/$cf_dir/headers |fgrep -v "#"`
1003                 do
1004                         echo "  @ (cd \$(INSTALL_PREFIX)\$(includedir) && rm -f `basename $i`) ; ../headers.sh \$(INSTALL_DATA) \$(INSTALL_PREFIX)\$(includedir) \$(srcdir) $i" >>$cf_dir/Makefile
1005                         test $i = curses.h && echo "    @ (cd \$(INSTALL_PREFIX)\$(includedir) && rm -f ncurses.h && \$(LN_S) curses.h ncurses.h)" >>$cf_dir/Makefile
1006                 done
1007
1008         cat >>$cf_dir/Makefile <<CF_EOF
1009
1010 uninstall \\
1011 uninstall.libs \\
1012 uninstall.includes ::
1013 CF_EOF
1014                 for i in `cat $srcdir/$cf_dir/headers |fgrep -v "#"`
1015                 do
1016                         i=`basename $i`
1017                         echo "  -@ (cd \$(INSTALL_PREFIX)\$(includedir) && rm -f $i)" >>$cf_dir/Makefile
1018                         test $i = curses.h && echo "    -@ (cd \$(INSTALL_PREFIX)\$(includedir) && rm -f ncurses.h)" >>$cf_dir/Makefile
1019                 done
1020         fi
1021 done
1022
1023 ])dnl
1024 dnl ---------------------------------------------------------------------------
1025 dnl Compute the library file-suffix from the given model name
1026 dnl $1 = model name
1027 dnl $2 = variable to set
1028 dnl The variable $LIB_SUFFIX, if set, prepends the variable to set.
1029 AC_DEFUN([CF_LIB_SUFFIX],
1030 [
1031         AC_REQUIRE([CF_SUBST_NCURSES_VERSION])
1032         case $1 in
1033         normal)  $2='.a'   ;;
1034         debug)   $2='_g.a' ;;
1035         profile) $2='_p.a' ;;
1036         shared)
1037                 case $cf_cv_system_name in
1038                 hpux*)  $2='.sl'  ;;
1039                 *)      $2='.so'  ;;
1040                 esac
1041         esac
1042         test -n "$LIB_SUFFIX" && $2="${LIB_SUFFIX}[$]{$2}"
1043 ])dnl
1044 dnl ---------------------------------------------------------------------------
1045 dnl Compute the string to append to -library from the given model name
1046 dnl $1 = model name
1047 dnl $2 = variable to set
1048 dnl The variable $LIB_SUFFIX, if set, prepends the variable to set.
1049 AC_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
1059 dnl ---------------------------------------------------------------------------
1060 dnl Some systems have a non-ANSI linker that doesn't pull in modules that have
1061 dnl only data (i.e., no functions), for example NeXT.  On those systems we'll
1062 dnl have to provide wrappers for global tables to ensure they're linked
1063 dnl properly.
1064 AC_DEFUN([CF_LINK_DATAONLY],
1065 [
1066 AC_MSG_CHECKING([if data-only library module links])
1067 AC_CACHE_VAL(cf_cv_link_dataonly,[
1068         rm -f conftest.a
1069         changequote(,)dnl
1070         cat >conftest.$ac_ext <<EOF
1071 #line __oline__ "configure"
1072 int     testdata[3] = { 123, 456, 789 };
1073 EOF
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"
1083 int     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 }
1094 EOF
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         ])
1116 AC_MSG_RESULT($cf_cv_link_dataonly)
1117 test $cf_cv_link_dataonly = no && AC_DEFINE(BROKEN_LINKER)
1118 ])dnl
1119 dnl ---------------------------------------------------------------------------
1120 dnl Most Unix systems have both link and symlink, a few don't have symlink.
1121 dnl A few non-Unix systems implement symlink, but not link.
1122 dnl A few non-systems implement neither (or have nonfunctional versions).
1123 AC_DEFUN([CF_LINK_FUNCS],
1124 [
1125 AC_CHECK_FUNCS( \
1126         remove \
1127         unlink )
1128
1129 if test "$ac_cv_prog_cc_cross" = yes ; then
1130         AC_CHECK_FUNCS( \
1131                 link \
1132                 symlink )
1133 else
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
1143 int 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         ])
1172 fi
1173 ])dnl
1174 dnl ---------------------------------------------------------------------------
1175 dnl Some 'make' programs support $(MAKEFLAGS), some $(MFLAGS), to pass 'make'
1176 dnl options to lower-levels.  It's very useful for "make -n" -- if we have it.
1177 dnl (GNU 'make' does both, something POSIX 'make', which happens to make the
1178 dnl $(MAKEFLAGS) variable incompatible because it adds the assignments :-)
1179 AC_DEFUN([CF_MAKEFLAGS],
1180 [
1181 AC_MSG_CHECKING([for makeflags variable])
1182 AC_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
1187 all :
1188         @ echo '.$cf_option'
1189 CF_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])
1207 AC_MSG_RESULT($cf_cv_makeflags)
1208 AC_SUBST(cf_cv_makeflags)
1209 ])dnl
1210 dnl ---------------------------------------------------------------------------
1211 dnl Option to allow user to override automatic configuration of manpage format.
1212 dnl There are several special cases.
1213 AC_DEFUN([CF_MANPAGE_FORMAT],
1214 [ AC_MSG_CHECKING(format of man-pages)
1215
1216 AC_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
1222 case ".$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
1234 changequote({{,}})dnl
1235     for cf_name in $cf_dir/*/date.[01]* $cf_dir/*/date
1236 changequote([,])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   ;;
1258 esac
1259
1260 AC_MSG_RESULT($cf_manpage_form)
1261 ])dnl
1262 dnl ---------------------------------------------------------------------------
1263 dnl The Debian people have their own naming convention for manpages.  This
1264 dnl option lets us override the name of the file containing renaming, or
1265 dnl disable it altogether.
1266 AC_DEFUN([CF_MANPAGE_RENAMES],
1267 [
1268 AC_MSG_CHECKING(for manpage renaming)
1269
1270 AC_ARG_WITH(manpage-renames,
1271         [  --with-manpage-renames  specify manpage-renaming],
1272         [cf_manpage_renames=$withval],
1273         [cf_manpage_renames=yes])
1274
1275 case ".$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   ;;
1286 esac
1287
1288 if 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
1300 fi
1301
1302 AC_MSG_RESULT($cf_manpage_renames)
1303 ])dnl
1304 dnl ---------------------------------------------------------------------------
1305 dnl Some people expect each tool to make all aliases for manpages in the
1306 dnl man-directory.  This accommodates the older, less-capable implementations
1307 dnl of 'man', and is optional.
1308 AC_DEFUN([CF_MANPAGE_SYMLINKS],
1309 [
1310 AC_MSG_CHECKING(for manpage symlinks)
1311
1312 AC_ARG_WITH(manpage-symlinks,
1313         [  --with-manpage-symlinks specify manpage-symlinks],
1314         [cf_manpage_symlinks=$withval],
1315         [cf_manpage_symlinks=yes])
1316
1317 AC_MSG_RESULT($cf_manpage_symlinks)
1318 ])dnl
1319 dnl ---------------------------------------------------------------------------
1320 dnl Try to determine if the man-pages on the system are compressed, and if
1321 dnl so, what format is used.  Use this information to construct a script that
1322 dnl will install man-pages.
1323 AC_DEFUN([CF_MAN_PAGES],
1324 [
1325 CF_HELP_MESSAGE(Options to Specify How Manpages are Installed:)
1326 CF_MANPAGE_FORMAT
1327 CF_MANPAGE_RENAMES
1328 CF_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
1347 test ! -d man && mkdir man
1348 cat >man/edit_man.sh <<CF_EOF
1349 changequote({{,}})dnl
1350 #! /bin/sh
1351 # this script is generated by the configure-script
1352 prefix="$cf_prefix"
1353 datadir="$datadir"
1354 MKDIRS="`cd $srcdir && pwd`/mkinstalldirs"
1355 INSTALL="$INSTALL"
1356 INSTALL_DATA="$INSTALL_DATA"
1357
1358 TMP=\${TMPDIR-/tmp}/man\$\$
1359 trap "rm -f \$TMP" 0 1 2 5 15
1360
1361 verb=\{{$}}1
1362 shift
1363
1364 mandir=\{{$}}1
1365 shift
1366
1367 srcdir=\{{$}}1
1368 shift
1369
1370 for i in \{{$}}* ; do
1371 case \$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\`
1382 CF_EOF
1383 if test "$cf_manpage_symlinks" = yes ; then
1384 cat >>man/edit_man.sh <<CF_EOF
1385         aliases=\`sed -f \$srcdir/manlinks.sed \$source | sort -u\`
1386 CF_EOF
1387 fi
1388 if test "$cf_manpage_renames" = no ; then
1389 cat >>man/edit_man.sh <<CF_EOF
1390         target=$cf_subdir\${section}/\$source
1391         sed -e "s,@DATADIR@,\$datadir," < \$i >\$TMP
1392 CF_EOF
1393 else
1394 cat >>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
1402 CF_EOF
1403 fi
1404 if test $cf_format = yes ; then
1405 cat >>man/edit_man.sh <<CF_EOF
1406         nroff -man \$TMP >\$TMP.out
1407         mv \$TMP.out \$TMP
1408 CF_EOF
1409 fi
1410 case "$cf_manpage_form" in #(vi
1411 *compress*) #(vi
1412 cat >>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"
1420 CF_EOF
1421   ;;
1422 *gzip*) #(vi
1423 cat >>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"
1431 CF_EOF
1432   ;;
1433 *BSDI*)
1434 cat >>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/'\`"
1437 CF_EOF
1438   ;;
1439 esac
1440 cat >>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         ;;
1480 esac
1481 done
1482 exit 0
1483 CF_EOF
1484 changequote([,])dnl
1485 chmod 755 man/edit_man.sh
1486
1487 ])dnl
1488 dnl ---------------------------------------------------------------------------
1489 dnl Checks for libraries.  At least one UNIX system, Apple Macintosh
1490 dnl Rhapsody 5.5, does not have -lm.  We cannot use the simpler
1491 dnl AC_CHECK_LIB(m,sin), because that fails for C++.
1492 AC_DEFUN([CF_MATH_LIB],
1493 [
1494 AC_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])])
1503 if test "$cf_cv_need_libm" = yes
1504 then
1505 ifelse($1,,[
1506         LIBS="$LIBS -lm"
1507 ],[$1=-lm])
1508 fi
1509 ])
1510 dnl ---------------------------------------------------------------------------
1511 dnl Compute the object-directory name from the given model name
1512 AC_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
1521 dnl ---------------------------------------------------------------------------
1522 dnl Check the argument to see that it looks like a pathname.  Rewrite it if it
1523 dnl begins with one of the prefix/exec_prefix variables, and then again if the
1524 dnl result begins with 'NONE'.  This is necessary to workaround autoconf's
1525 dnl delayed evaluation of those symbols.
1526 AC_DEFUN([CF_PATH_SYNTAX],[
1527 case ".[$]$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   ;;
1546 esac
1547 ])dnl
1548 dnl ---------------------------------------------------------------------------
1549 dnl Compute $PROG_EXT, used for non-Unix ports, such as OS/2 EMX.
1550 AC_DEFUN([CF_PROG_EXT],
1551 [
1552 AC_REQUIRE([CF_CHECK_CACHE])
1553 PROG_EXT=
1554 case $cf_cv_system_name in
1555 os2*)
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     ;;
1562 cygwin*)
1563     PROG_EXT=".exe"
1564     ;;
1565 esac
1566 AC_SUBST(PROG_EXT)
1567 ])dnl
1568 dnl ---------------------------------------------------------------------------
1569 dnl Force $INSTALL to be an absolute-path.  Otherwise, edit_man.sh and the
1570 dnl misc/tabset install won't work properly.  Usually this happens only when
1571 dnl using the fallback mkinstalldirs script
1572 AC_DEFUN([CF_PROG_INSTALL],
1573 [AC_PROG_INSTALL
1574 case $INSTALL in
1575 /*)
1576   ;;
1577 *)
1578 changequote({{,}})dnl
1579   cf_dir=`echo $INSTALL|sed -e 's%/[^/]*$%%'`
1580   test -z "$cf_dir" && cf_dir=.
1581 changequote([,])dnl
1582   INSTALL=`cd $cf_dir && pwd`/`echo $INSTALL | sed -e 's:^.*/::'`
1583   ;;
1584 esac
1585 ])dnl
1586 dnl ---------------------------------------------------------------------------
1587 dnl Attempt to determine if we've got one of the flavors of regular-expression
1588 dnl code that we can support.
1589 AC_DEFUN([CF_REGEX],
1590 [
1591 AC_MSG_CHECKING([for regular-expression headers])
1592 AC_CACHE_VAL(cf_cv_regex,[
1593 AC_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 ])
1611 AC_MSG_RESULT($cf_cv_regex)
1612 case $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) ;;
1616 esac
1617 ])dnl
1618 dnl ---------------------------------------------------------------------------
1619 dnl Attempt to determine the appropriate CC/LD options for creating a shared
1620 dnl library.
1621 dnl
1622 dnl Note: $(LOCAL_LDFLAGS) is used to link executables that will run within the
1623 dnl build-tree, i.e., by making use of the libraries that are compiled in ../lib
1624 dnl We avoid compiling-in a ../lib path for the shared library since that can
1625 dnl lead to unexpected results at runtime.
1626 dnl $(LOCAL_LDFLAGS2) has the same intention but assumes that the shared libraries
1627 dnl are compiled in ../../lib
1628 dnl
1629 dnl The variable 'cf_cv_do_symlinks' is used to control whether we configure
1630 dnl to install symbolic links to the rel/abi versions of shared libraries.
1631 dnl
1632 dnl The variable 'cf_cv_shlib_version' controls whether we use the rel or abi
1633 dnl version when making symbolic links.
1634 dnl
1635 dnl Some loaders leave 'so_locations' lying around.  It's nice to clean up.
1636 AC_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                 MK_SHARED_LIB='$(CC) -shared -Wl,-soname,`basename $[@] .$(REL_VERSION)`.$(ABI_VERSION),-stats,-lc -o $[@]'
1729                 ;;
1730         openbsd2*)
1731                 CC_SHARED_OPTS="$CC_SHARED_OPTS -DPIC"
1732                 MK_SHARED_LIB='$(LD) -Bshareable -soname,`basename $[@].$(ABI_VERSION)` -o $[@]'
1733                 ;;
1734         openbsd*|freebsd*)
1735                 CC_SHARED_OPTS="$CC_SHARED_OPTS -DPIC"
1736                 MK_SHARED_LIB='$(LD) -Bshareable -o $[@]'
1737                 test $cf_cv_shlib_version = auto && cf_cv_shlib_version=rel
1738                 ;;
1739         netbsd*)
1740                 CC_SHARED_OPTS="$CC_SHARED_OPTS -DPIC"
1741                 test $cf_cv_ld_rpath = yes && cf_ld_rpath_opt="-Wl,-rpath,"
1742                 if test $DFT_LWR_MODEL = "shared" && test $cf_cv_ld_rpath = yes ; then
1743                         LOCAL_LDFLAGS='-Wl,-rpath,../lib'
1744                         LOCAL_LDFLAGS2='-Wl,-rpath,../../lib'
1745                         EXTRA_LDFLAGS="-Wl,-rpath,\$(libdir) $EXTRA_LDFLAGS"
1746                         MK_SHARED_LIB='$(CC) -shared -Wl,-soname,`basename $[@] .$(REL_VERSION)`.$(ABI_VERSION) -o $[@]'
1747                         if test $cf_cv_shlib_version = auto; then
1748                         if test ! -f /usr/libexec/ld.elf_so; then
1749                                 cf_cv_shlib_version=rel
1750                         fi
1751                         fi
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 $[@] .$(REL_VERSION)`.$(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 $[@] .$(REL_VERSION)`.$(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                         test "$cf_cv_do_symlinks" = no && cf_cv_do_symlinks=yes
1827                         ;;
1828                 *)
1829                         AC_MSG_WARN(ignored --with-shlib-version)
1830                         ;;
1831                 esac
1832                 ;;
1833         esac
1834
1835         if test -n "$cf_ld_rpath_opt" ; then
1836                 AC_MSG_CHECKING(if we need a space after rpath option)
1837                 cf_save_LIBS="$LIBS"
1838                 LIBS="$LIBS ${cf_ld_rpath_opt}/usr/lib"
1839                 AC_TRY_LINK(, , cf_rpath_space=no, cf_rpath_space=yes)
1840                 LIBS="$cf_save_LIBS"
1841                 AC_MSG_RESULT($cf_rpath_space)
1842                 test $cf_rpath_space = yes && cf_ld_rpath_opt="$cf_ld_rpath_opt "
1843                 MK_SHARED_LIB="$MK_SHARED_LIB $cf_ld_rpath_opt\$(libdir)"
1844         fi
1845
1846         AC_SUBST(CC_SHARED_OPTS)
1847         AC_SUBST(LD_SHARED_OPTS)
1848         AC_SUBST(MK_SHARED_LIB)
1849         AC_SUBST(LINK_PROGS)
1850         AC_SUBST(LINK_TESTS)
1851         AC_SUBST(EXTRA_LDFLAGS)
1852         AC_SUBST(LOCAL_LDFLAGS)
1853         AC_SUBST(LOCAL_LDFLAGS2)
1854         AC_SUBST(INSTALL_LIB)
1855 ])dnl
1856 dnl ---------------------------------------------------------------------------
1857 dnl Check for definitions & structures needed for window size-changing
1858 dnl FIXME: check that this works with "snake" (HP-UX 10.x)
1859 AC_DEFUN([CF_SIZECHANGE],
1860 [
1861 AC_MSG_CHECKING([declaration of size-change])
1862 AC_CACHE_VAL(cf_cv_sizechange,[
1863     cf_cv_sizechange=unknown
1864     cf_save_CFLAGS="$CFLAGS"
1865
1866 for cf_opts in "" "NEED_PTEM_H"
1867 do
1868
1869     CFLAGS="$cf_save_CFLAGS"
1870     test -n "$cf_opts" && CFLAGS="$CFLAGS -D$cf_opts"
1871     AC_TRY_COMPILE([#include <sys/types.h>
1872 #if HAVE_TERMIOS_H
1873 #include <termios.h>
1874 #else
1875 #if HAVE_TERMIO_H
1876 #include <termio.h>
1877 #endif
1878 #endif
1879 #if NEED_PTEM_H
1880 /* This is a workaround for SCO:  they neglected to define struct winsize in
1881  * termios.h -- it's only in termio.h and ptem.h
1882  */
1883 #include        <sys/stream.h>
1884 #include        <sys/ptem.h>
1885 #endif
1886 #if !defined(sun) || !defined(HAVE_TERMIOS_H)
1887 #include <sys/ioctl.h>
1888 #endif
1889 ],[
1890 #ifdef TIOCGSIZE
1891         struct ttysize win;     /* FIXME: what system is this? */
1892         int y = win.ts_lines;
1893         int x = win.ts_cols;
1894 #else
1895 #ifdef TIOCGWINSZ
1896         struct winsize win;
1897         int y = win.ws_row;
1898         int x = win.ws_col;
1899 #else
1900         no TIOCGSIZE or TIOCGWINSZ
1901 #endif /* TIOCGWINSZ */
1902 #endif /* TIOCGSIZE */
1903         ],
1904         [cf_cv_sizechange=yes],
1905         [cf_cv_sizechange=no])
1906
1907         CFLAGS="$cf_save_CFLAGS"
1908         if test "$cf_cv_sizechange" = yes ; then
1909                 echo "size-change succeeded ($cf_opts)" >&AC_FD_CC
1910                 test -n "$cf_opts" && AC_DEFINE_UNQUOTED($cf_opts)
1911                 break
1912         fi
1913 done
1914         ])
1915 AC_MSG_RESULT($cf_cv_sizechange)
1916 test $cf_cv_sizechange != no && AC_DEFINE(HAVE_SIZECHANGE)
1917 ])dnl
1918 dnl ---------------------------------------------------------------------------
1919 dnl Check for datatype 'speed_t', which is normally declared via either
1920 dnl sys/types.h or termios.h
1921 AC_DEFUN([CF_SPEED_TYPE],
1922 [
1923 AC_MSG_CHECKING(for speed_t)
1924 OSPEED_INCLUDES=
1925 AC_TRY_COMPILE([#include <sys/types.h>],
1926         [speed_t some_variable = 0],
1927         [OSPEED_TYPE=speed_t],
1928         [OSPEED_TYPE=unsigned])
1929 AC_TRY_COMPILE([#include <termios.h>],
1930         [speed_t some_variable = 0],
1931         [OSPEED_TYPE=speed_t
1932          OSPEED_INCLUDES="#include <termios.h>"],[])
1933 AC_SUBST(OSPEED_TYPE)
1934 AC_SUBST(OSPEED_INCLUDES)
1935 if test "$OSPEED_TYPE" = "unsigned" ; then
1936         AC_MSG_RESULT(no)
1937         AC_DEFINE(speed_t,unsigned)
1938 else
1939         AC_MSG_RESULT(yes)
1940 fi
1941 ])dnl
1942 dnl ---------------------------------------------------------------------------
1943 dnl For each parameter, test if the source-directory exists, and if it contains
1944 dnl a 'modules' file.  If so, add to the list $cf_cv_src_modules which we'll
1945 dnl use in CF_LIB_RULES.
1946 dnl
1947 dnl This uses the configured value to make the lists SRC_SUBDIRS and
1948 dnl SUB_MAKEFILES which are used in the makefile-generation scheme.
1949 AC_DEFUN([CF_SRC_MODULES],
1950 [
1951 AC_MSG_CHECKING(for src modules)
1952
1953 # dependencies and linker-arguments for test-programs
1954 TEST_DEPS="${LIB_DIR}/${LIB_PREFIX}${LIB_NAME}${DFT_DEP_SUFFIX} $TEST_DEPS"
1955 TEST_ARGS="-l${LIB_NAME}${DFT_ARG_SUFFIX} $TEST_ARGS"
1956
1957 # dependencies and linker-arguments for utility-programs
1958 PROG_ARGS="$TEST_ARGS"
1959
1960 cf_cv_src_modules=
1961 for cf_dir in $1
1962 do
1963         if test -f $srcdir/$cf_dir/modules; then
1964
1965                 # We may/may not have tack in the distribution, though the
1966                 # makefile is.
1967                 if test $cf_dir = tack ; then
1968                         if test ! -f $srcdir/${cf_dir}/${cf_dir}.h; then
1969                                 continue
1970                         fi
1971                 fi
1972
1973                 if test -z "$cf_cv_src_modules"; then
1974                         cf_cv_src_modules=$cf_dir
1975                 else
1976                         cf_cv_src_modules="$cf_cv_src_modules $cf_dir"
1977                 fi
1978
1979                 # Make the ncurses_cfg.h file record the library interface files as
1980                 # well.  These are header files that are the same name as their
1981                 # directory.  Ncurses is the only library that does not follow
1982                 # that pattern.
1983                 if test $cf_dir = tack ; then
1984                         continue
1985                 elif test -f $srcdir/${cf_dir}/${cf_dir}.h; then
1986                         CF_UPPER(cf_have_include,$cf_dir)
1987                         AC_DEFINE_UNQUOTED(HAVE_${cf_have_include}_H)
1988                         AC_DEFINE_UNQUOTED(HAVE_LIB${cf_have_include})
1989                         TEST_DEPS="${LIB_DIR}/${LIB_PREFIX}${cf_dir}${DFT_DEP_SUFFIX} $TEST_DEPS"
1990                         TEST_ARGS="-l${cf_dir}${DFT_ARG_SUFFIX} $TEST_ARGS"
1991                 fi
1992         fi
1993 done
1994 AC_MSG_RESULT($cf_cv_src_modules)
1995 TEST_ARGS="-L${LIB_DIR} -L\$(libdir) $TEST_ARGS"
1996 AC_SUBST(TEST_DEPS)
1997 AC_SUBST(TEST_ARGS)
1998
1999 PROG_ARGS="-L${LIB_DIR} -L\$(libdir) $PROG_ARGS"
2000 AC_SUBST(PROG_ARGS)
2001
2002 SRC_SUBDIRS="man include"
2003 for cf_dir in $cf_cv_src_modules
2004 do
2005         SRC_SUBDIRS="$SRC_SUBDIRS $cf_dir"
2006 done
2007 SRC_SUBDIRS="$SRC_SUBDIRS misc test"
2008 test $cf_with_cxx_binding != no && SRC_SUBDIRS="$SRC_SUBDIRS c++"
2009
2010 ADA_SUBDIRS=
2011 if test "$cf_cv_prog_gnat_correct" = yes && test -f $srcdir/Ada95/Makefile.in; then
2012    SRC_SUBDIRS="$SRC_SUBDIRS Ada95"
2013    ADA_SUBDIRS="gen src samples"
2014 fi
2015
2016 SUB_MAKEFILES=
2017 for cf_dir in $SRC_SUBDIRS
2018 do
2019         SUB_MAKEFILES="$SUB_MAKEFILES $cf_dir/Makefile"
2020 done
2021
2022 if test -n "$ADA_SUBDIRS"; then
2023    for cf_dir in $ADA_SUBDIRS
2024    do
2025       SUB_MAKEFILES="$SUB_MAKEFILES Ada95/$cf_dir/Makefile"
2026    done
2027    AC_SUBST(ADA_SUBDIRS)
2028 fi
2029 ])dnl
2030 dnl ---------------------------------------------------------------------------
2031 dnl Check for -lstdc++, which is GNU's standard C++ library.
2032 AC_DEFUN([CF_STDCPP_LIBRARY],
2033 [
2034 if test -n "$GXX" ; then
2035 case $cf_cv_system_name in #(vi
2036 os2*) #(vi
2037         cf_stdcpp_libname=stdcpp
2038         ;;
2039 *)
2040         cf_stdcpp_libname=stdc++
2041         ;;
2042 esac
2043 AC_CACHE_CHECK(for library $cf_stdcpp_libname,cf_cv_libstdcpp,[
2044         cf_save="$LIBS"
2045         LIBS="$LIBS -l$cf_stdcpp_libname"
2046 AC_TRY_LINK([
2047 #include <strstream.h>],[
2048 char buf[80];
2049 strstreambuf foo(buf, sizeof(buf))
2050 ],
2051         [cf_cv_libstdcpp=yes],
2052         [cf_cv_libstdcpp=no])
2053         LIBS="$cf_save"
2054 ])
2055 test $cf_cv_libstdcpp = yes && CXXLIBS="$CXXLIBS -l$cf_stdcpp_libname"
2056 fi
2057 ])dnl
2058 dnl ---------------------------------------------------------------------------
2059 dnl     Remove "-g" option from the compiler options
2060 AC_DEFUN([CF_STRIP_G_OPT],
2061 [$1=`echo ${$1} | sed -e 's/-g //' -e 's/-g$//'`])dnl
2062 dnl ---------------------------------------------------------------------------
2063 dnl Check if we need _POSIX_SOURCE defined to use struct sigaction.  We'll only
2064 dnl do this if we've found the sigaction function.
2065 dnl
2066 dnl If needed, define SVR4_ACTION.
2067 AC_DEFUN([CF_STRUCT_SIGACTION],[
2068 if test $ac_cv_func_sigaction = yes; then
2069 AC_MSG_CHECKING(whether sigaction needs _POSIX_SOURCE)
2070 AC_TRY_COMPILE([
2071 #include <sys/types.h>
2072 #include <signal.h>],
2073         [struct sigaction act],
2074         [sigact_bad=no],
2075         [
2076 AC_TRY_COMPILE([
2077 #define _POSIX_SOURCE
2078 #include <sys/types.h>
2079 #include <signal.h>],
2080         [struct sigaction act],
2081         [sigact_bad=yes
2082          AC_DEFINE(SVR4_ACTION)],
2083          [sigact_bad=unknown])])
2084 AC_MSG_RESULT($sigact_bad)
2085 fi
2086 ])dnl
2087 dnl ---------------------------------------------------------------------------
2088 dnl Some machines require _POSIX_SOURCE to completely define struct termios.
2089 dnl If so, define SVR4_TERMIO
2090 AC_DEFUN([CF_STRUCT_TERMIOS],[
2091 if test $ac_cv_header_termios_h = yes ; then
2092         case "$CFLAGS" in
2093         *-D_POSIX_SOURCE*)
2094                 termios_bad=dunno ;;
2095         *)      termios_bad=maybe ;;
2096         esac
2097         if test $termios_bad = maybe ; then
2098         AC_MSG_CHECKING(whether termios.h needs _POSIX_SOURCE)
2099         AC_TRY_COMPILE([#include <termios.h>],
2100                 [struct termios foo; int x = foo.c_iflag],
2101                 termios_bad=no, [
2102                 AC_TRY_COMPILE([
2103 #define _POSIX_SOURCE
2104 #include <termios.h>],
2105                         [struct termios foo; int x = foo.c_iflag],
2106                         termios_bad=unknown,
2107                         termios_bad=yes AC_DEFINE(SVR4_TERMIO))
2108                         ])
2109         AC_MSG_RESULT($termios_bad)
2110         fi
2111 fi
2112 ])dnl
2113 dnl ---------------------------------------------------------------------------
2114 dnl     Shorthand macro for substituting things that the user may override
2115 dnl     with an environment variable.
2116 dnl
2117 dnl     $1 = long/descriptive name
2118 dnl     $2 = environment variable
2119 dnl     $3 = default value
2120 AC_DEFUN([CF_SUBST],
2121 [AC_CACHE_VAL(cf_cv_subst_$2,[
2122 AC_MSG_CHECKING(for $1 (symbol $2))
2123 test -z "[$]$2" && $2=$3
2124 AC_MSG_RESULT([$]$2)
2125 AC_SUBST($2)
2126 cf_cv_subst_$2=[$]$2])
2127 $2=${cf_cv_subst_$2}
2128 ])dnl
2129 dnl ---------------------------------------------------------------------------
2130 dnl Get the version-number for use in shared-library naming, etc.
2131 AC_DEFUN([CF_SUBST_NCURSES_VERSION],
2132 [
2133 changequote(,)dnl
2134 NCURSES_MAJOR="`egrep '^NCURSES_MAJOR[  ]*=' $srcdir/dist.mk | sed -e 's/^[^0-9]*//'`"
2135 NCURSES_MINOR="`egrep '^NCURSES_MINOR[  ]*=' $srcdir/dist.mk | sed -e 's/^[^0-9]*//'`"
2136 NCURSES_PATCH="`egrep '^NCURSES_PATCH[  ]*=' $srcdir/dist.mk | sed -e 's/^[^0-9]*//'`"
2137 changequote([,])dnl
2138 cf_cv_abi_version=${NCURSES_MAJOR}
2139 cf_cv_rel_version=${NCURSES_MAJOR}.${NCURSES_MINOR}
2140 dnl Show the computed version, for logging
2141 AC_MSG_RESULT(Configuring NCURSES $cf_cv_rel_version ABI $cf_cv_abi_version (`date`))
2142 dnl We need these values in the generated headers
2143 AC_SUBST(NCURSES_MAJOR)
2144 AC_SUBST(NCURSES_MINOR)
2145 AC_SUBST(NCURSES_PATCH)
2146 dnl We need these values in the generated makefiles
2147 AC_SUBST(cf_cv_rel_version)
2148 AC_SUBST(cf_cv_abi_version)
2149 AC_SUBST(cf_cv_cc_bool_type)
2150 AC_SUBST(cf_cv_builtin_bool)
2151 AC_SUBST(cf_cv_type_of_bool)dnl
2152 ])dnl
2153 dnl ---------------------------------------------------------------------------
2154 dnl Check if we can include <sys/time.h> with <sys/select.h>; this breaks on
2155 dnl older SCO configurations.
2156 AC_DEFUN([CF_SYS_TIME_SELECT],
2157 [
2158 AC_MSG_CHECKING(if sys/time.h works with sys/select.h)
2159 AC_CACHE_VAL(cf_cv_sys_time_select,[
2160 AC_TRY_COMPILE([
2161 #include <sys/types.h>
2162 #if HAVE_SYS_TIME_H
2163 #include <sys/time.h>
2164 #endif
2165 #if HAVE_SYS_SELECT_H
2166 #include <sys/select.h>
2167 #endif
2168 ],[],[cf_cv_sys_time_select=yes],
2169      [cf_cv_sys_time_select=no])
2170      ])
2171 AC_MSG_RESULT($cf_cv_sys_time_select)
2172 test $cf_cv_sys_time_select = yes && AC_DEFINE(HAVE_SYS_TIME_SELECT)
2173 ])dnl
2174 dnl ---------------------------------------------------------------------------
2175 dnl Determine the type we should use for chtype (and attr_t, which is treated
2176 dnl as the same thing).  We want around 32 bits, so on most machines want a
2177 dnl long, but on newer 64-bit machines, probably want an int.  If we're using
2178 dnl wide characters, we have to have a type compatible with that, as well.
2179 AC_DEFUN([CF_TYPEOF_CHTYPE],
2180 [
2181 AC_REQUIRE([CF_UNSIGNED_LITERALS])
2182 AC_MSG_CHECKING([for type of chtype])
2183 AC_CACHE_VAL(cf_cv_typeof_chtype,[
2184                 AC_TRY_RUN([
2185 #if USE_WIDEC_SUPPORT
2186 #include <stddef.h>     /* we want wchar_t */
2187 #define WANT_BITS 39
2188 #else
2189 #define WANT_BITS 31
2190 #endif
2191 #include <stdio.h>
2192 int main()
2193 {
2194         FILE *fp = fopen("cf_test.out", "w");
2195         if (fp != 0) {
2196                 char *result = "long";
2197 #if USE_WIDEC_SUPPORT
2198                 /*
2199                  * If wchar_t is smaller than a long, it must be an int or a
2200                  * short.  We prefer not to use a short anyway.
2201                  */
2202                 if (sizeof(unsigned long) > sizeof(wchar_t))
2203                         result = "int";
2204 #endif
2205                 if (sizeof(unsigned long) > sizeof(unsigned int)) {
2206                         int n;
2207                         unsigned int x;
2208                         for (n = 0; n < WANT_BITS; n++) {
2209                                 unsigned int y = (x >> n);
2210                                 if (y != 1 || x == 0) {
2211                                         x = 0;
2212                                         break;
2213                                 }
2214                         }
2215                         /*
2216                          * If x is nonzero, an int is big enough for the bits
2217                          * that we want.
2218                          */
2219                         result = (x != 0) ? "int" : "long";
2220                 }
2221                 fputs(result, fp);
2222                 fclose(fp);
2223         }
2224         exit(0);
2225 }
2226                 ],
2227                 [cf_cv_typeof_chtype=`cat cf_test.out`],
2228                 [cf_cv_typeof_chtype=long],
2229                 [cf_cv_typeof_chtype=long])
2230                 rm -f cf_test.out
2231         ])
2232 AC_MSG_RESULT($cf_cv_typeof_chtype)
2233
2234 AC_SUBST(cf_cv_typeof_chtype)
2235 AC_DEFINE_UNQUOTED(TYPEOF_CHTYPE,$cf_cv_typeof_chtype)
2236
2237 cf_cv_1UL="1"
2238 test "$cf_cv_unsigned_literals" = yes && cf_cv_1UL="${cf_cv_1UL}U"
2239 test "$cf_cv_typeof_chtype"    = long && cf_cv_1UL="${cf_cv_1UL}L"
2240 AC_SUBST(cf_cv_1UL)
2241
2242 ])dnl
2243 dnl ---------------------------------------------------------------------------
2244 dnl
2245 AC_DEFUN([CF_TYPE_SIGACTION],
2246 [
2247 AC_MSG_CHECKING([for type sigaction_t])
2248 AC_CACHE_VAL(cf_cv_type_sigaction,[
2249         AC_TRY_COMPILE([
2250 #include <signal.h>],
2251                 [sigaction_t x],
2252                 [cf_cv_type_sigaction=yes],
2253                 [cf_cv_type_sigaction=no])])
2254 AC_MSG_RESULT($cf_cv_type_sigaction)
2255 test $cf_cv_type_sigaction = yes && AC_DEFINE(HAVE_TYPE_SIGACTION)
2256 ])dnl
2257 dnl ---------------------------------------------------------------------------
2258 dnl Test if the compiler supports 'U' and 'L' suffixes.  Only old compilers
2259 dnl won't, but they're still there.
2260 AC_DEFUN([CF_UNSIGNED_LITERALS],
2261 [
2262 AC_MSG_CHECKING([if unsigned literals are legal])
2263 AC_CACHE_VAL(cf_cv_unsigned_literals,[
2264         AC_TRY_COMPILE([],[long x = 1L + 1UL + 1U + 1],
2265                 [cf_cv_unsigned_literals=yes],
2266                 [cf_cv_unsigned_literals=no])
2267         ])
2268 AC_MSG_RESULT($cf_cv_unsigned_literals)
2269 ])dnl
2270 dnl ---------------------------------------------------------------------------
2271 dnl Make an uppercase version of a variable
2272 dnl $1=uppercase($2)
2273 AC_DEFUN([CF_UPPER],
2274 [
2275 changequote(,)dnl
2276 $1=`echo $2 | tr '[a-z]' '[A-Z]'`
2277 changequote([,])dnl
2278 ])dnl
2279 dnl ---------------------------------------------------------------------------
2280 dnl Compute the shift-mask that we'll use for wide-character indices.  We use
2281 dnl all but the index portion of chtype for storing attributes.
2282 AC_DEFUN([CF_WIDEC_SHIFT],
2283 [
2284 AC_REQUIRE([CF_TYPEOF_CHTYPE])
2285 AC_MSG_CHECKING([for number of bits in chtype])
2286 AC_CACHE_VAL(cf_cv_shift_limit,[
2287         AC_TRY_RUN([
2288 #include <stdio.h>
2289 int main()
2290 {
2291         FILE *fp = fopen("cf_test.out", "w");
2292         if (fp != 0) {
2293                 int n;
2294                 unsigned TYPEOF_CHTYPE x = 1L;
2295                 for (n = 0; ; n++) {
2296                         unsigned long y = (x >> n);
2297                         if (y != 1 || x == 0)
2298                                 break;
2299                         x <<= 1;
2300                 }
2301                 fprintf(fp, "%d", n);
2302                 fclose(fp);
2303         }
2304         exit(0);
2305 }
2306                 ],
2307                 [cf_cv_shift_limit=`cat cf_test.out`],
2308                 [cf_cv_shift_limit=32],
2309                 [cf_cv_shift_limit=32])
2310                 rm -f cf_test.out
2311         ])
2312 AC_MSG_RESULT($cf_cv_shift_limit)
2313 AC_SUBST(cf_cv_shift_limit)
2314
2315 AC_MSG_CHECKING([for width of character-index])
2316 AC_CACHE_VAL(cf_cv_widec_shift,[
2317 if test ".$with_widec" = ".yes" ; then
2318         cf_attrs_width=39
2319         if ( expr $cf_cv_shift_limit \> $cf_attrs_width >/dev/null )
2320         then
2321                 cf_cv_widec_shift=`expr 16 + $cf_cv_shift_limit - $cf_attrs_width`
2322         else
2323                 cf_cv_widec_shift=16
2324         fi
2325 else
2326         cf_cv_widec_shift=8
2327 fi
2328 ])
2329 AC_MSG_RESULT($cf_cv_widec_shift)
2330 AC_SUBST(cf_cv_widec_shift)
2331 ])dnl
2332 dnl ---------------------------------------------------------------------------
2333 dnl Wrapper for AC_ARG_WITH to ensure that user supplies a pathname, not just
2334 dnl defaulting to yes/no.
2335 dnl
2336 dnl $1 = option name
2337 dnl $2 = help-text
2338 dnl $3 = environment variable to set
2339 dnl $4 = default value, shown in the help-message, must be a constant
2340 dnl $5 = default value, if it's an expression & cannot be in the help-message
2341 dnl
2342 AC_DEFUN([CF_WITH_PATH],
2343 [AC_ARG_WITH($1,[$2 ](default: ifelse($4,,empty,$4)),,
2344 ifelse($4,,[withval="${$3}"],[withval="${$3-ifelse($5,,$4,$5)}"]))dnl
2345 CF_PATH_SYNTAX(withval)
2346 eval $3="$withval"
2347 AC_SUBST($3)dnl
2348 ])dnl
2349 dnl ---------------------------------------------------------------------------
2350 dnl Process an option specifying a list of colon-separated paths.
2351 dnl
2352 dnl $1 = option name
2353 dnl $2 = help-text
2354 dnl $3 = environment variable to set
2355 dnl $4 = default value, shown in the help-message, must be a constant
2356 dnl $5 = default value, if it's an expression & cannot be in the help-message
2357 dnl
2358 AC_DEFUN([CF_WITH_PATHLIST],[
2359 AC_ARG_WITH($1,[$2 ](default: ifelse($4,,empty,$4)),,
2360 ifelse($4,,[withval="${$3}"],[withval="${$3-ifelse($5,,$4,$5)}"]))dnl
2361
2362 IFS="${IFS=     }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
2363 cf_dst_path=
2364 for cf_src_path in $withval
2365 do
2366   CF_PATH_SYNTAX(cf_src_path)
2367   test -n "$cf_dst_path" && cf_dst_path="${cf_dst_path}:"
2368   cf_dst_path="${cf_dst_path}${cf_src_path}"
2369 done
2370 IFS="$ac_save_ifs"
2371
2372 eval $3="$cf_dst_path"
2373 AC_SUBST($3)dnl
2374 ])dnl