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