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