]> ncurses.scripts.mit.edu Git - ncurses.git/blob - aclocal.m4
ncurses 5.3
[ncurses.git] / 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.285 2002/09/21 23:59:01 tom Exp $
32 dnl Macros used in NCURSES auto-configuration script.
33 dnl
34 dnl See http://invisible-island.net/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 \
808                 Wundef $cf_warn_CONST
809         do
810                 CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
811                 if AC_TRY_EVAL(ac_compile); then
812                         test -n "$verbose" && AC_MSG_RESULT(... -$cf_opt)
813                         EXTRA_CFLAGS="$EXTRA_CFLAGS -$cf_opt"
814                         test "$cf_opt" = Wcast-qual && EXTRA_CFLAGS="$EXTRA_CFLAGS -DXTSTRINGDEFINES"
815                 fi
816         done
817         rm -f conftest*
818         CFLAGS="$cf_save_CFLAGS"
819 fi
820 AC_SUBST(EXTRA_CFLAGS)
821 ])dnl
822 dnl ---------------------------------------------------------------------------
823 dnl Verify that a test program compiles and runs with GNAT
824 dnl $cf_ada_make is set to the program that compiles/links
825 AC_DEFUN([CF_GNAT_TRY_RUN],
826 [
827 rm -f conftest*
828 cat >>conftest.ads <<CF_EOF
829 $1
830 CF_EOF
831 cat >>conftest.adb <<CF_EOF
832 $2
833 CF_EOF
834 if ( $cf_ada_make conftest 1>&AC_FD_CC 2>&1 ) ; then
835    if ( ./conftest 1>&AC_FD_CC 2>&1 ) ; then
836 ifelse($3,,      :,[      $3])
837 ifelse($4,,,[   else
838       $4])
839    fi
840 ifelse($4,,,[else
841    $4])
842 fi
843 rm -f conftest*
844 ])dnl
845 dnl ---------------------------------------------------------------------------
846 dnl Verify Version of GNAT.
847 AC_DEFUN([CF_GNAT_VERSION],
848 [
849 cf_cv_gnat_version=`$cf_ada_make -v 2>&1 | grep '[[0-9]].[[0-9]][[0-9]]*' |\
850   sed -e 's/[[^0-9 \.]]//g' | $AWK '{print $[1];}'`
851 case $cf_cv_gnat_version in
852   3.1[[1-9]]*|3.[[2-9]]*|[[4-9]].*)
853     cf_cv_prog_gnat_correct=yes
854     ;;
855   *) echo Unsupported GNAT version $cf_cv_gnat_version. Required is 3.11 or better. Disabling Ada95 binding.
856      cf_cv_prog_gnat_correct=no
857      ;;
858 esac
859 case $cf_cv_gnat_version in
860   3.1*|[[4-9]].*)
861       cf_compile_generics=generics
862       cf_generic_objects="\$(GENOBJS)"
863       ;;
864   *)  cf_compile_generics=
865       cf_generic_objects=
866       ;;
867 esac
868 ])
869 dnl ---------------------------------------------------------------------------
870 dnl Check if we must define _GNU_SOURCE to get a reasonable value for
871 dnl _XOPEN_SOURCE, upon which many POSIX definitions depend.  This is a defect
872 dnl (or misfeature) of glibc2, which breaks portability of many applications,
873 dnl since it is interwoven with GNU extensions.
874 dnl
875 dnl Well, yes we could work around it...
876 AC_DEFUN([CF_GNU_SOURCE],
877 [
878 AC_CACHE_CHECK(if we must define _GNU_SOURCE,cf_cv_gnu_source,[
879 AC_TRY_COMPILE([#include <sys/types.h>],[
880 #ifndef _XOPEN_SOURCE
881 make an error
882 #endif],
883         [cf_cv_gnu_source=no],
884         [cf_save="$CPPFLAGS"
885          CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
886          AC_TRY_COMPILE([#include <sys/types.h>],[
887 #ifdef _XOPEN_SOURCE
888 make an error
889 #endif],
890         [cf_cv_gnu_source=no],
891         [cf_cv_gnu_source=yes])
892         CPPFLAGS="$cf_save"
893         ])
894 ])
895 test "$cf_cv_gnu_source" = yes && CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
896 ])dnl
897 dnl ---------------------------------------------------------------------------
898 dnl If we're trying to use g++, test if libg++ is installed (a rather common
899 dnl problem :-).  If we have the compiler but no library, we'll be able to
900 dnl configure, but won't be able to build the c++ demo program.
901 AC_DEFUN([CF_GPP_LIBRARY],
902 [
903 cf_cxx_library=unknown
904 case $cf_cv_system_name in #(vi
905 os2*) #(vi
906         cf_gpp_libname=gpp
907         ;;
908 *)
909         cf_gpp_libname=g++
910         ;;
911 esac
912 if test "$ac_cv_prog_gxx" = yes; then
913         AC_MSG_CHECKING([for lib$cf_gpp_libname])
914         cf_save="$LIBS"
915         LIBS="$LIBS -l$cf_gpp_libname"
916         AC_TRY_LINK([
917 #include <$cf_gpp_libname/builtin.h>
918         ],
919         [two_arg_error_handler_t foo2 = lib_error_handler],
920         [cf_cxx_library=yes
921          CXXLIBS="$CXXLIBS -l$cf_gpp_libname"
922          if test "$cf_gpp_libname" = cpp ; then
923             AC_DEFINE(HAVE_GPP_BUILTIN_H)
924          else
925             AC_DEFINE(HAVE_GXX_BUILTIN_H)
926          fi],
927         [AC_TRY_LINK([
928 #include <builtin.h>
929         ],
930         [two_arg_error_handler_t foo2 = lib_error_handler],
931         [cf_cxx_library=yes
932          CXXLIBS="$CXXLIBS -l$cf_gpp_libname"
933          AC_DEFINE(HAVE_BUILTIN_H)],
934         [cf_cxx_library=no])])
935         LIBS="$cf_save"
936         AC_MSG_RESULT($cf_cxx_library)
937 fi
938 ])dnl
939 dnl ---------------------------------------------------------------------------
940 dnl Insert text into the help-message, for readability, from AC_ARG_WITH.
941 AC_DEFUN([CF_HELP_MESSAGE],
942 [AC_DIVERT_HELP([$1])dnl
943 ])dnl
944 dnl ---------------------------------------------------------------------------
945 dnl Construct the list of include-options according to whether we're building
946 dnl in the source directory or using '--srcdir=DIR' option.  If we're building
947 dnl with gcc, don't append the includedir if it happens to be /usr/include,
948 dnl since that usually breaks gcc's shadow-includes.
949 AC_DEFUN([CF_INCLUDE_DIRS],
950 [
951 CPPFLAGS="$CPPFLAGS -I. -I../include"
952 if test "$srcdir" != "."; then
953         CPPFLAGS="$CPPFLAGS -I\$(srcdir)/../include"
954 fi
955 if test "$GCC" != yes; then
956         CPPFLAGS="$CPPFLAGS -I\$(includedir)"
957 elif test "$includedir" != "/usr/include"; then
958         if test "$includedir" = '${prefix}/include' ; then
959                 if test $prefix != /usr ; then
960                         CPPFLAGS="$CPPFLAGS -I\$(includedir)"
961                 fi
962         else
963                 CPPFLAGS="$CPPFLAGS -I\$(includedir)"
964         fi
965 fi
966 AC_SUBST(CPPFLAGS)
967 ])dnl
968 dnl ---------------------------------------------------------------------------
969 dnl Check if we have either a function or macro for 'isascii()'.
970 AC_DEFUN([CF_ISASCII],
971 [
972 AC_MSG_CHECKING(for isascii)
973 AC_CACHE_VAL(cf_cv_have_isascii,[
974         AC_TRY_LINK([#include <ctype.h>],[int x = isascii(' ')],
975         [cf_cv_have_isascii=yes],
976         [cf_cv_have_isascii=no])
977 ])dnl
978 AC_MSG_RESULT($cf_cv_have_isascii)
979 test "$cf_cv_have_isascii" = yes && AC_DEFINE(HAVE_ISASCII)
980 ])dnl
981 dnl ---------------------------------------------------------------------------
982 dnl Check for libutf8
983 AC_DEFUN([CF_LIBUTF8],
984 [
985 AC_CACHE_CHECK(for putwc in libutf8,cf_cv_libutf8,[
986         cf_save_LIBS="$LIBS"
987         LIBS="-lutf8 $LIBS"
988 AC_TRY_LINK([
989 #include <libutf8.h>],[putwc(0,0);],
990         [cf_cv_libutf8=yes],
991         [cf_cv_libutf8=no])
992         LIBS="$cf_save_LIBS"
993 ])
994
995 if test "$cf_cv_libutf8" = yes ; then
996         AC_DEFINE(HAVE_LIBUTF8_H)
997         LIBS="-lutf8 $LIBS"
998 fi
999 ])dnl
1000 dnl ---------------------------------------------------------------------------
1001 dnl Compute the library-prefix for the given host system
1002 dnl $1 = variable to set
1003 AC_DEFUN([CF_LIB_PREFIX],
1004 [
1005         case $cf_cv_system_name in
1006         OS/2*)  LIB_PREFIX=''     ;;
1007         os2*)   LIB_PREFIX=''     ;;
1008         *)      LIB_PREFIX='lib'  ;;
1009         esac
1010 ifelse($1,,,[$1=$LIB_PREFIX])
1011         AC_SUBST(LIB_PREFIX)
1012 ])dnl
1013 dnl ---------------------------------------------------------------------------
1014 dnl Append definitions and rules for the given models to the subdirectory
1015 dnl Makefiles, and the recursion rule for the top-level Makefile.  If the
1016 dnl subdirectory is a library-source directory, modify the LIBRARIES list in
1017 dnl the corresponding makefile to list the models that we'll generate.
1018 dnl
1019 dnl For shared libraries, make a list of symbolic links to construct when
1020 dnl generating each library.  The convention used for Linux is the simplest
1021 dnl one:
1022 dnl     lib<name>.so    ->
1023 dnl     lib<name>.so.<major>    ->
1024 dnl     lib<name>.so.<maj>.<minor>
1025 AC_DEFUN([CF_LIB_RULES],
1026 [
1027 CF_LIB_PREFIX(cf_prefix)
1028 AC_REQUIRE([CF_SUBST_NCURSES_VERSION])
1029 for cf_dir in $SRC_SUBDIRS
1030 do
1031         if test -f $srcdir/$cf_dir/modules; then
1032
1033                 IMPORT_LIB=
1034                 SHARED_LIB=
1035                 LIBS_TO_MAKE=
1036                 for cf_item in $CF_LIST_MODELS
1037                 do
1038                         CF_LIB_SUFFIX($cf_item,cf_suffix)
1039                         if test $cf_item = shared ; then
1040                         if test "$cf_cv_do_symlinks" = yes ; then
1041                                 case "$cf_cv_shlib_version" in #(vi
1042                                 rel) #(vi
1043                                         case "$cf_cv_system_name" in #(vi
1044                                         darwin*) cf_suffix='.$(REL_VERSION)'"$cf_suffix" ;; #(vi
1045                                         *) cf_suffix="$cf_suffix"'.$(REL_VERSION)' ;;
1046                                         esac
1047                                         ;;
1048                                 abi)
1049                                         case "$cf_cv_system_name" in #(vi
1050                                         darwin*) cf_suffix='.$(ABI_VERSION)'"$cf_suffix" ;; #(vi
1051                                         *) cf_suffix="$cf_suffix"'.$(ABI_VERSION)' ;;
1052                                         esac
1053                                         ;;
1054                                 esac
1055                         fi
1056                         # cygwin needs import library, and has unique naming convention
1057                         if test $cf_cv_shlib_version = cygdll ; then
1058                                 SHARED_LIB="../lib/${cf_prefix}${cf_dir}\$(ABI_VERSION).dll"
1059                                 IMPORT_LIB="../lib/${cf_prefix}${cf_dir}.dll.a"
1060                                 LIBS_TO_MAKE="$LIBS_TO_MAKE \$(SHARED_LIB) \$(IMPORT_LIB)"
1061                                 continue
1062                         fi
1063                         fi
1064                         LIBS_TO_MAKE="$LIBS_TO_MAKE ../lib/${cf_prefix}${cf_dir}${cf_suffix}"
1065                 done
1066
1067                 if test $cf_dir = ncurses ; then
1068                         cf_subsets="$LIB_SUBSETS"
1069                         case "$LIB_SUBSETS" in #(vi
1070                         termlib+*) #(vi
1071                                 ;;
1072                         *) #(vi
1073                                 cf_item=`echo $LIBS_TO_MAKE |sed -e s/$LIB_NAME/$TINFO_NAME/g`
1074                                 LIBS_TO_MAKE="$cf_item $LIBS_TO_MAKE"
1075                                 ;;
1076                         esac
1077                 else
1078                         cf_subsets=`echo "$LIB_SUBSETS" | sed -e 's/^termlib //'`
1079                 fi
1080
1081                 sed -e "s%@LIBS_TO_MAKE@%$LIBS_TO_MAKE%" \
1082                     -e "s%@IMPORT_LIB@%$IMPORT_LIB%" \
1083                     -e "s%@SHARED_LIB@%$SHARED_LIB%" \
1084                         $cf_dir/Makefile >$cf_dir/Makefile.out
1085                 mv $cf_dir/Makefile.out $cf_dir/Makefile
1086
1087                 $AWK -f $srcdir/mk-0th.awk \
1088                         libname="${cf_dir}${LIB_SUFFIX}" subsets="$LIB_SUBSETS" \
1089                         $srcdir/$cf_dir/modules >>$cf_dir/Makefile
1090
1091                 for cf_subset in $cf_subsets
1092                 do
1093                         cf_subdirs=
1094                         for cf_item in $CF_LIST_MODELS
1095                         do
1096                         echo "Appending rules for ${cf_item} model (${cf_dir}: ${cf_subset})"
1097                         CF_UPPER(CF_ITEM,$cf_item)
1098                         CF_LIB_SUFFIX($cf_item,cf_suffix)
1099                         CF_OBJ_SUBDIR($cf_item,cf_subdir)
1100
1101                         # These dependencies really are for development, not
1102                         # builds, but they are useful in porting, too.
1103                         cf_depend="../include/ncurses_cfg.h"
1104                         if test "$srcdir" = "."; then
1105                                 cf_reldir="."
1106                         else
1107                                 cf_reldir="\$(srcdir)"
1108                         fi
1109
1110                         if test -f $srcdir/$cf_dir/$cf_dir.priv.h; then
1111                                 cf_depend="$cf_depend $cf_reldir/$cf_dir.priv.h"
1112                         elif test -f $srcdir/$cf_dir/curses.priv.h; then
1113                                 cf_depend="$cf_depend $cf_reldir/curses.priv.h"
1114                         fi
1115
1116                         $AWK -f $srcdir/mk-1st.awk \
1117                                 name=$cf_dir \
1118                                 traces=$LIB_TRACING \
1119                                 MODEL=$CF_ITEM \
1120                                 model=$cf_subdir \
1121                                 prefix=$cf_prefix \
1122                                 suffix=$cf_suffix \
1123                                 subset=$cf_subset \
1124                                 ShlibVer=$cf_cv_shlib_version \
1125                                 ShlibVerInfix=$cf_cv_shlib_version_infix \
1126                                 DoLinks=$cf_cv_do_symlinks \
1127                                 rmSoLocs=$cf_cv_rm_so_locs \
1128                                 ldconfig="$LDCONFIG" \
1129                                 overwrite=$WITH_OVERWRITE \
1130                                 depend="$cf_depend" \
1131                                 target="$target" \
1132                                 $srcdir/$cf_dir/modules >>$cf_dir/Makefile
1133                         for cf_subdir2 in $cf_subdirs lib
1134                         do
1135                                 test $cf_subdir = $cf_subdir2 && break
1136                         done
1137                         test "${cf_subset}.${cf_subdir2}" != "${cf_subset}.${cf_subdir}" && \
1138                         $AWK -f $srcdir/mk-2nd.awk \
1139                                 name=$cf_dir \
1140                                 traces=$LIB_TRACING \
1141                                 MODEL=$CF_ITEM \
1142                                 model=$cf_subdir \
1143                                 subset=$cf_subset \
1144                                 srcdir=$srcdir \
1145                                 echo=$WITH_ECHO \
1146                                 $srcdir/$cf_dir/modules >>$cf_dir/Makefile
1147                         cf_subdirs="$cf_subdirs $cf_subdir"
1148                         done
1149                 done
1150         fi
1151
1152         echo '  cd '$cf_dir' && $(MAKE) $(CF_MFLAGS) [$]@' >>Makefile
1153 done
1154
1155 for cf_dir in $SRC_SUBDIRS
1156 do
1157         if test -f $cf_dir/Makefile ; then
1158                 case "$cf_dir" in
1159                 Ada95) #(vi
1160                         echo 'libs \' >> Makefile
1161                         echo 'install.libs \' >> Makefile
1162                         echo 'uninstall.libs ::' >> Makefile
1163                         echo '  cd '$cf_dir' && $(MAKE) $(CF_MFLAGS) [$]@' >> Makefile
1164                         ;;
1165                 esac
1166         fi
1167
1168         if test -f $srcdir/$cf_dir/modules; then
1169                 echo >> Makefile
1170                 if test -f $srcdir/$cf_dir/headers; then
1171 cat >> Makefile <<CF_EOF
1172 install.includes \\
1173 uninstall.includes \\
1174 CF_EOF
1175                 fi
1176 if test "$cf_dir" != "c++" ; then
1177 echo 'lint \' >> Makefile
1178 fi
1179 cat >> Makefile <<CF_EOF
1180 libs \\
1181 lintlib \\
1182 install.libs \\
1183 uninstall.libs \\
1184 install.$cf_dir \\
1185 uninstall.$cf_dir ::
1186         cd $cf_dir && \$(MAKE) \$(CF_MFLAGS) \[$]@
1187 CF_EOF
1188         elif test -f $srcdir/$cf_dir/headers; then
1189 cat >> Makefile <<CF_EOF
1190
1191 libs \\
1192 install.libs \\
1193 uninstall.libs \\
1194 install.includes \\
1195 uninstall.includes ::
1196         cd $cf_dir && \$(MAKE) \$(CF_MFLAGS) \[$]@
1197 CF_EOF
1198 fi
1199 done
1200
1201 cat >> Makefile <<CF_EOF
1202
1203 install.data \\
1204 uninstall.data ::
1205 $MAKE_TERMINFO  cd misc && \$(MAKE) \$(CF_MFLAGS) \[$]@
1206
1207 install.man \\
1208 uninstall.man ::
1209         cd man && \$(MAKE) \$(CF_MFLAGS) \[$]@
1210
1211 distclean ::
1212         rm -f config.cache config.log config.status Makefile include/ncurses_cfg.h
1213         rm -f headers.sh headers.sed
1214         rm -rf \$(DIRS_TO_MAKE)
1215 CF_EOF
1216
1217 # Special case: tack's manpage lives in its own directory.
1218 if test -d tack ; then
1219 if test -f $srcdir/$tack.h; then
1220 cat >> Makefile <<CF_EOF
1221
1222 install.man \\
1223 uninstall.man ::
1224         cd tack && \$(MAKE) \$(CF_MFLAGS) \[$]@
1225 CF_EOF
1226 fi
1227 fi
1228
1229 dnl If we're installing into a subdirectory of /usr/include, etc., we should
1230 dnl prepend the subdirectory's name to the "#include" paths.  It won't hurt
1231 dnl anything, and will make it more standardized.  It's awkward to decide this
1232 dnl at configuration because of quoting, so we'll simply make all headers
1233 dnl installed via a script that can do the right thing.
1234
1235 rm -f headers.sed headers.sh
1236
1237 dnl ( generating this script makes the makefiles a little tidier :-)
1238 echo creating headers.sh
1239 cat >headers.sh <<CF_EOF
1240 #! /bin/sh
1241 # This shell script is generated by the 'configure' script.  It is invoked in a
1242 # subdirectory of the build tree.  It generates a sed-script in the parent
1243 # directory that is used to adjust includes for header files that reside in a
1244 # subdirectory of /usr/include, etc.
1245 PRG=""
1246 while test \[$]# != 3
1247 do
1248 PRG="\$PRG \[$]1"; shift
1249 done
1250 DST=\[$]1
1251 REF=\[$]2
1252 SRC=\[$]3
1253 TMPSRC=\${TMPDIR-/tmp}/\`basename \$SRC\`\$\$
1254 TMPSED=\${TMPDIR-/tmp}/headers.sed\$\$
1255 echo installing \$SRC in \$DST
1256 CF_EOF
1257 if test $WITH_CURSES_H = yes; then
1258         cat >>headers.sh <<CF_EOF
1259 case \$DST in
1260 /*/include/*)
1261         END=\`basename \$DST\`
1262         for i in \`cat \$REF/../*/headers |fgrep -v "#"\`
1263         do
1264                 NAME=\`basename \$i\`
1265                 echo "s/<\$NAME>/<\$END\/\$NAME>/" >> \$TMPSED
1266         done
1267         ;;
1268 *)
1269         echo "" >> \$TMPSED
1270         ;;
1271 esac
1272 CF_EOF
1273 else
1274         cat >>headers.sh <<CF_EOF
1275 case \$DST in
1276 /*/include/*)
1277         END=\`basename \$DST\`
1278         for i in \`cat \$REF/../*/headers |fgrep -v "#"\`
1279         do
1280                 NAME=\`basename \$i\`
1281                 if test "\$NAME" = "curses.h"
1282                 then
1283                         echo "s/<curses.h>/<ncurses.h>/" >> \$TMPSED
1284                         NAME=ncurses.h
1285                 fi
1286                 echo "s/<\$NAME>/<\$END\/\$NAME>/" >> \$TMPSED
1287         done
1288         ;;
1289 *)
1290         echo "s/<curses.h>/<ncurses.h>/" >> \$TMPSED
1291         ;;
1292 esac
1293 CF_EOF
1294 fi
1295 cat >>headers.sh <<CF_EOF
1296 rm -f \$TMPSRC
1297 sed -f \$TMPSED \$SRC > \$TMPSRC
1298 NAME=\`basename \$SRC\`
1299 CF_EOF
1300 if test $WITH_CURSES_H != yes; then
1301         cat >>headers.sh <<CF_EOF
1302 test "\$NAME" = "curses.h" && NAME=ncurses.h
1303 CF_EOF
1304 fi
1305 cat >>headers.sh <<CF_EOF
1306 # Just in case someone gzip'd manpages, remove the conflicting copy.
1307 test -f \$DST/\$NAME.gz && rm -f \$DST/\$NAME.gz
1308
1309 eval \$PRG \$TMPSRC \$DST/\$NAME
1310 rm -f \$TMPSRC \$TMPSED
1311 CF_EOF
1312
1313 chmod 0755 headers.sh
1314
1315 for cf_dir in $SRC_SUBDIRS
1316 do
1317         if test -f $srcdir/$cf_dir/headers; then
1318         cat >>$cf_dir/Makefile <<CF_EOF
1319 \$(DESTDIR)\$(includedir) :
1320         sh \$(srcdir)/../mkinstalldirs \[$]@
1321
1322 install \\
1323 install.libs \\
1324 install.includes :: \$(AUTO_SRC) \$(DESTDIR)\$(includedir) \\
1325 CF_EOF
1326                 j=""
1327                 for i in `cat $srcdir/$cf_dir/headers |fgrep -v "#"`
1328                 do
1329                         test -n "$j" && echo "          $j \\" >>$cf_dir/Makefile
1330                         j=$i
1331                 done
1332                 echo "          $j" >>$cf_dir/Makefile
1333                 for i in `cat $srcdir/$cf_dir/headers |fgrep -v "#"`
1334                 do
1335                         echo "  @ (cd \$(DESTDIR)\$(includedir) && rm -f `basename $i`) ; ../headers.sh \$(INSTALL_DATA) \$(DESTDIR)\$(includedir) \$(srcdir) $i" >>$cf_dir/Makefile
1336                         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
1337                 done
1338
1339         cat >>$cf_dir/Makefile <<CF_EOF
1340
1341 uninstall \\
1342 uninstall.libs \\
1343 uninstall.includes ::
1344 CF_EOF
1345                 for i in `cat $srcdir/$cf_dir/headers |fgrep -v "#"`
1346                 do
1347                         i=`basename $i`
1348                         echo "  -@ (cd \$(DESTDIR)\$(includedir) && rm -f $i)" >>$cf_dir/Makefile
1349                         test $i = curses.h && echo "    -@ (cd \$(DESTDIR)\$(includedir) && rm -f ncurses.h)" >>$cf_dir/Makefile
1350                 done
1351         fi
1352
1353         if test -f $srcdir/$cf_dir/modules; then
1354                 if test "$cf_dir" != "c++" ; then
1355                         cat >>$cf_dir/Makefile <<"CF_EOF"
1356 depend : $(AUTO_SRC)
1357         makedepend -- $(CPPFLAGS) -- $(C_SRC)
1358
1359 # DO NOT DELETE THIS LINE -- make depend depends on it.
1360 CF_EOF
1361                 fi
1362         fi
1363 done
1364
1365 ])dnl
1366 dnl ---------------------------------------------------------------------------
1367 dnl Compute the library file-suffix from the given model name
1368 dnl $1 = model name
1369 dnl $2 = variable to set
1370 dnl The variable $LIB_SUFFIX, if set, prepends the variable to set.
1371 AC_DEFUN([CF_LIB_SUFFIX],
1372 [
1373         AC_REQUIRE([CF_SUBST_NCURSES_VERSION])
1374         case $1 in
1375         libtool) $2='.la'  ;;
1376         normal)  $2='.a'   ;;
1377         debug)   $2='_g.a' ;;
1378         profile) $2='_p.a' ;;
1379         shared)
1380                 case $cf_cv_system_name in
1381                 cygwin*) $2='.dll' ;;
1382                 darwin*) $2='.dylib' ;;
1383                 hpux*)  $2='.sl'  ;;
1384                 *)      $2='.so'  ;;
1385                 esac
1386         esac
1387         test -n "$LIB_SUFFIX" && $2="${LIB_SUFFIX}[$]{$2}"
1388 ])dnl
1389 dnl ---------------------------------------------------------------------------
1390 dnl Compute the string to append to -library from the given model name
1391 dnl $1 = model name
1392 dnl $2 = variable to set
1393 dnl The variable $LIB_SUFFIX, if set, prepends the variable to set.
1394 AC_DEFUN([CF_LIB_TYPE],
1395 [
1396         case $1 in
1397         libtool) $2=''   ;;
1398         normal)  $2=''   ;;
1399         debug)   $2='_g' ;;
1400         profile) $2='_p' ;;
1401         shared)  $2=''   ;;
1402         esac
1403         test -n "$LIB_SUFFIX" && $2="${LIB_SUFFIX}[$]{$2}"
1404 ])dnl
1405 dnl ---------------------------------------------------------------------------
1406 dnl Some systems have a non-ANSI linker that doesn't pull in modules that have
1407 dnl only data (i.e., no functions), for example NeXT.  On those systems we'll
1408 dnl have to provide wrappers for global tables to ensure they're linked
1409 dnl properly.
1410 AC_DEFUN([CF_LINK_DATAONLY],
1411 [
1412 AC_MSG_CHECKING([if data-only library module links])
1413 AC_CACHE_VAL(cf_cv_link_dataonly,[
1414         rm -f conftest.a
1415         cat >conftest.$ac_ext <<EOF
1416 #line __oline__ "configure"
1417 int     testdata[[3]] = { 123, 456, 789 };
1418 EOF
1419         if AC_TRY_EVAL(ac_compile) ; then
1420                 mv conftest.o data.o && \
1421                 ( $AR $AR_OPTS conftest.a data.o ) 2>&5 1>/dev/null
1422         fi
1423         rm -f conftest.$ac_ext data.o
1424         cat >conftest.$ac_ext <<EOF
1425 #line __oline__ "configure"
1426 int     testfunc()
1427 {
1428 #if defined(NeXT)
1429         exit(1);        /* I'm told this linker is broken */
1430 #else
1431         extern int testdata[[3]];
1432         return testdata[[0]] == 123
1433            &&  testdata[[1]] == 456
1434            &&  testdata[[2]] == 789;
1435 #endif
1436 }
1437 EOF
1438         if AC_TRY_EVAL(ac_compile); then
1439                 mv conftest.o func.o && \
1440                 ( $AR $AR_OPTS conftest.a func.o ) 2>&5 1>/dev/null
1441         fi
1442         rm -f conftest.$ac_ext func.o
1443         ( eval $ac_cv_prog_RANLIB conftest.a ) 2>&5 >/dev/null
1444         cf_saveLIBS="$LIBS"
1445         LIBS="conftest.a $LIBS"
1446         AC_TRY_RUN([
1447         int main()
1448         {
1449                 extern int testfunc();
1450                 exit (!testfunc());
1451         }
1452         ],
1453         [cf_cv_link_dataonly=yes],
1454         [cf_cv_link_dataonly=no],
1455         [cf_cv_link_dataonly=unknown])
1456         LIBS="$cf_saveLIBS"
1457         ])
1458 AC_MSG_RESULT($cf_cv_link_dataonly)
1459
1460 if test "$cf_cv_link_dataonly" = no ; then
1461         AC_DEFINE(BROKEN_LINKER)
1462         BROKEN_LINKER=1
1463 fi
1464
1465 ])dnl
1466 dnl ---------------------------------------------------------------------------
1467 dnl Most Unix systems have both link and symlink, a few don't have symlink.
1468 dnl A few non-Unix systems implement symlink, but not link.
1469 dnl A few non-systems implement neither (or have nonfunctional versions).
1470 AC_DEFUN([CF_LINK_FUNCS],
1471 [
1472 AC_CHECK_FUNCS( \
1473         remove \
1474         unlink )
1475
1476 if test "$ac_cv_prog_cc_cross" = yes ; then
1477         AC_CHECK_FUNCS( \
1478                 link \
1479                 symlink )
1480 else
1481         AC_CACHE_CHECK(if link/symlink functions work,cf_cv_link_funcs,[
1482                 cf_cv_link_funcs=
1483                 for cf_func in link symlink ; do
1484                         AC_TRY_RUN([
1485 #include <sys/types.h>
1486 #include <sys/stat.h>
1487 #ifdef HAVE_UNISTD_H
1488 #include <unistd.h>
1489 #endif
1490 int main()
1491 {
1492         int fail = 0;
1493         char *src = "config.log";
1494         char *dst = "conftest.chk";
1495         struct stat src_sb;
1496         struct stat dst_sb;
1497
1498         stat(src, &src_sb);
1499         fail = ($cf_func("config.log", "conftest.chk") < 0)
1500             || (stat(dst, &dst_sb) < 0)
1501             || (dst_sb.st_mtime != src_sb.st_mtime);
1502 #ifdef HAVE_UNLINK
1503         unlink(dst);
1504 #else
1505         remove(dst);
1506 #endif
1507         exit (fail);
1508 }
1509                         ],[
1510                         cf_cv_link_funcs="$cf_cv_link_funcs $cf_func"
1511                         eval 'ac_cv_func_'$cf_func'=yes'],[
1512                         eval 'ac_cv_func_'$cf_func'=no'],[
1513                         eval 'ac_cv_func_'$cf_func'=error'])
1514                 done
1515                 test -z "$cf_cv_link_funcs" && cf_cv_link_funcs=no
1516         ])
1517         test "$ac_cv_func_link"    = yes && AC_DEFINE(HAVE_LINK)
1518         test "$ac_cv_func_symlink" = yes && AC_DEFINE(HAVE_SYMLINK)
1519 fi
1520 ])dnl
1521 dnl ---------------------------------------------------------------------------
1522 dnl Some 'make' programs support $(MAKEFLAGS), some $(MFLAGS), to pass 'make'
1523 dnl options to lower-levels.  It's very useful for "make -n" -- if we have it.
1524 dnl (GNU 'make' does both, something POSIX 'make', which happens to make the
1525 dnl $(MAKEFLAGS) variable incompatible because it adds the assignments :-)
1526 AC_DEFUN([CF_MAKEFLAGS],
1527 [
1528 AC_CACHE_CHECK(for makeflags variable, cf_cv_makeflags,[
1529         cf_cv_makeflags=''
1530         for cf_option in '-$(MAKEFLAGS)' '$(MFLAGS)'
1531         do
1532                 cat >cf_makeflags.tmp <<CF_EOF
1533 SHELL = /bin/sh
1534 all :
1535         @ echo '.$cf_option'
1536 CF_EOF
1537                 cf_result=`${MAKE-make} -k -f cf_makeflags.tmp 2>/dev/null`
1538                 case "$cf_result" in
1539                 .*k)
1540                         cf_result=`${MAKE-make} -k -f cf_makeflags.tmp CC=cc 2>/dev/null`
1541                         case "$cf_result" in
1542                         .*CC=*) cf_cv_makeflags=
1543                                 ;;
1544                         *)      cf_cv_makeflags=$cf_option
1545                                 ;;
1546                         esac
1547                         break
1548                         ;;
1549                 *)      echo no match "$cf_result"
1550                         ;;
1551                 esac
1552         done
1553         rm -f cf_makeflags.tmp
1554 ])
1555
1556 AC_SUBST(cf_cv_makeflags)
1557 ])dnl
1558 dnl ---------------------------------------------------------------------------
1559 dnl Generate tags/TAGS targets for makefiles.  Do not generate TAGS if we have
1560 dnl a monocase filesystem.
1561 AC_DEFUN([CF_MAKE_TAGS],[
1562 AC_REQUIRE([CF_MIXEDCASE_FILENAMES])
1563 AC_CHECK_PROG(MAKE_LOWER_TAGS, ctags, yes, no)
1564
1565 if test "$cf_cv_mixedcase" = yes ; then
1566         AC_CHECK_PROG(MAKE_UPPER_TAGS, etags, yes, no)
1567 else
1568         MAKE_UPPER_TAGS=no
1569 fi
1570
1571 if test "$MAKE_UPPER_TAGS" = yes ; then
1572         MAKE_UPPER_TAGS=
1573 else
1574         MAKE_UPPER_TAGS="#"
1575 fi
1576 AC_SUBST(MAKE_UPPER_TAGS)
1577
1578 if test "$MAKE_LOWER_TAGS" = yes ; then
1579         MAKE_LOWER_TAGS=
1580 else
1581         MAKE_LOWER_TAGS="#"
1582 fi
1583 AC_SUBST(MAKE_LOWER_TAGS)
1584 ])dnl
1585 dnl ---------------------------------------------------------------------------
1586 dnl Option to allow user to override automatic configuration of manpage format.
1587 dnl There are several special cases.
1588 AC_DEFUN([CF_MANPAGE_FORMAT],
1589 [
1590 AC_REQUIRE([CF_PATHSEP])
1591 AC_MSG_CHECKING(format of man-pages)
1592
1593 AC_ARG_WITH(manpage-format,
1594         [  --with-manpage-format   specify manpage-format: gzip/compress/BSDI/normal and
1595                           optionally formatted, e.g., gzip,formatted],
1596         [MANPAGE_FORMAT=$withval],
1597         [MANPAGE_FORMAT=unknown])
1598
1599 case ".$MANPAGE_FORMAT" in
1600 .gzip|.compress|.BSDI|.normal|.formatted) # (vi
1601   ;;
1602 .unknown|.) # (vi
1603   if test -z "$MANPATH" ; then
1604     MANPATH="/usr/man:/usr/share/man"
1605   fi
1606   # look for the 'date' man-page (it's most likely to be installed!)
1607   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATHSEP}"
1608   MANPAGE_FORMAT=unknown
1609   for cf_dir in $MANPATH; do
1610     test -z "$cf_dir" && cf_dir=/usr/man
1611     for cf_name in $cf_dir/*/date.[[01]]* $cf_dir/*/date
1612     do
1613        cf_test=`echo $cf_name | sed -e 's/*//'`
1614        if test "x$cf_test" = "x$cf_name" ; then
1615           case "$cf_name" in
1616           *.gz) MANPAGE_FORMAT=gzip;;
1617           *.Z)  MANPAGE_FORMAT=compress;;
1618           *.0)  MANPAGE_FORMAT=BSDI,formatted;;
1619           *)    MANPAGE_FORMAT=normal;;
1620           esac
1621           break
1622        fi
1623     done
1624     if test "$MANPAGE_FORMAT" != "unknown" ; then
1625        break
1626     fi
1627   done
1628   IFS="$ac_save_ifs"
1629   ;;
1630 .*) # (vi
1631   AC_MSG_WARN(Unexpected manpage-format)
1632   ;;
1633 esac
1634
1635 AC_MSG_RESULT($MANPAGE_FORMAT)
1636 ])dnl
1637 dnl ---------------------------------------------------------------------------
1638 dnl The Debian people have their own naming convention for manpages.  This
1639 dnl option lets us override the name of the file containing renaming, or
1640 dnl disable it altogether.
1641 AC_DEFUN([CF_MANPAGE_RENAMES],
1642 [
1643 AC_MSG_CHECKING(for manpage renaming)
1644
1645 AC_ARG_WITH(manpage-renames,
1646         [  --with-manpage-renames  specify manpage-renaming],
1647         [MANPAGE_RENAMES=$withval],
1648         [MANPAGE_RENAMES=yes])
1649
1650 case ".$MANPAGE_RENAMES" in #(vi
1651 .no) #(vi
1652   ;;
1653 .|.yes)
1654   # Debian 'man' program?
1655   if test -f /etc/debian_version ; then
1656     MANPAGE_RENAMES=`cd $srcdir && pwd`/man/man_db.renames
1657   else
1658     MANPAGE_RENAMES=no
1659   fi
1660   ;;
1661 esac
1662
1663 if test "$MANPAGE_RENAMES" != no ; then
1664   if test -f $srcdir/man/$MANPAGE_RENAMES ; then
1665     MANPAGE_RENAMES=`cd $srcdir/man && pwd`/$MANPAGE_RENAMES
1666   elif test ! -f $MANPAGE_RENAMES ; then
1667     AC_MSG_ERROR(not a filename: $MANPAGE_RENAMES)
1668   fi
1669
1670   test ! -d man && mkdir man
1671
1672   # Construct a sed-script to perform renaming within man-pages
1673   if test -n "$MANPAGE_RENAMES" ; then
1674     test ! -d man && mkdir man
1675     sh $srcdir/man/make_sed.sh $MANPAGE_RENAMES >man/edit_man.sed
1676   fi
1677 fi
1678
1679 AC_MSG_RESULT($MANPAGE_RENAMES)
1680 AC_SUBST(MANPAGE_RENAMES)
1681 ])dnl
1682 dnl ---------------------------------------------------------------------------
1683 dnl Some people expect each tool to make all aliases for manpages in the
1684 dnl man-directory.  This accommodates the older, less-capable implementations
1685 dnl of 'man', and is optional.
1686 AC_DEFUN([CF_MANPAGE_SYMLINKS],
1687 [
1688 AC_MSG_CHECKING(for manpage symlinks)
1689
1690 AC_ARG_WITH(manpage-symlinks,
1691         [  --with-manpage-symlinks specify manpage-symlinks],
1692         [MANPAGE_SYMLINKS=$withval],
1693         [MANPAGE_SYMLINKS=yes])
1694
1695 AC_MSG_RESULT($MANPAGE_SYMLINKS)
1696 ])dnl
1697 dnl ---------------------------------------------------------------------------
1698 dnl This option causes manpages to be run through tbl(1) to generate tables
1699 dnl correctly.
1700 AC_DEFUN([CF_MANPAGE_TBL],
1701 [
1702 AC_MSG_CHECKING(for manpage tbl)
1703
1704 AC_ARG_WITH(manpage-tbl,
1705         [  --with-manpage-tbl      specify manpage processing with tbl],
1706         [MANPAGE_TBL=$withval],
1707         [MANPAGE_TBL=no])
1708
1709 AC_MSG_RESULT($MANPAGE_TBL)
1710 ])dnl
1711 dnl ---------------------------------------------------------------------------
1712 dnl Try to determine if the man-pages on the system are compressed, and if
1713 dnl so, what format is used.  Use this information to construct a script that
1714 dnl will install man-pages.
1715 AC_DEFUN([CF_MAN_PAGES],
1716 [
1717 CF_HELP_MESSAGE(Options to Specify How Manpages are Installed:)
1718 CF_MANPAGE_FORMAT
1719 CF_MANPAGE_RENAMES
1720 CF_MANPAGE_SYMLINKS
1721 CF_MANPAGE_TBL
1722
1723   if test "$prefix" = "NONE" ; then
1724      cf_prefix="$ac_default_prefix"
1725   else
1726      cf_prefix="$prefix"
1727   fi
1728
1729   case "$MANPAGE_FORMAT" in # (vi
1730   *formatted*) # (vi
1731     cf_subdir='$mandir/cat'
1732     cf_format=yes
1733     ;;
1734   *)
1735     cf_subdir='$mandir/man'
1736     cf_format=no
1737     ;;
1738   esac
1739
1740 test ! -d man && mkdir man
1741 cat >man/edit_man.sh <<CF_EOF
1742 #! /bin/sh
1743 # this script is generated by the configure-script
1744 prefix="$cf_prefix"
1745 datadir="$datadir"
1746 NCURSES_OSPEED="$NCURSES_OSPEED"
1747 TERMINFO="$TERMINFO"
1748 MKDIRS="sh `cd $srcdir && pwd`/mkinstalldirs"
1749 INSTALL="$INSTALL"
1750 INSTALL_DATA="$INSTALL_DATA"
1751 transform="$program_transform_name"
1752
1753 TMP=\${TMPDIR-/tmp}/man\$\$
1754 trap "rm -f \$TMP" 0 1 2 5 15
1755
1756 verb=\[$]1
1757 shift
1758
1759 mandir=\[$]1
1760 shift
1761
1762 srcdir=\[$]1
1763 shift
1764
1765 for i in \[$]* ; do
1766 case \$i in #(vi
1767 *.orig|*.rej) ;; #(vi
1768 *.[[0-9]]*)
1769         section=\`expr "\$i" : '.*\\.\\([[0-9]]\\)[[xm]]*'\`;
1770         if test \$verb = installing ; then
1771         if test ! -d $cf_subdir\${section} ; then
1772                 \$MKDIRS $cf_subdir\$section
1773         fi
1774         fi
1775         aliases=
1776         source=\`basename \$i\`
1777         inalias=\$source
1778         test ! -f \$inalias && inalias="\$srcdir/\$inalias"
1779         if test ! -f \$inalias ; then
1780                 echo .. skipped \$source
1781                 continue
1782         fi
1783 CF_EOF
1784 if test "$MANPAGE_SYMLINKS" = yes ; then
1785 cat >>man/edit_man.sh <<CF_EOF
1786         aliases=\`sed -f \$srcdir/manlinks.sed \$inalias | sort -u\`
1787 CF_EOF
1788 fi
1789
1790 if test "$MANPAGE_RENAMES" = no ; then
1791 cat >>man/edit_man.sh <<CF_EOF
1792         # perform program transformations for section 1 man pages
1793         if test \$section = 1 ; then
1794                 target=$cf_subdir\${section}/\`echo \$source|sed "\${transform}"\`
1795         else
1796                 target=$cf_subdir\${section}/\$source
1797         fi
1798 CF_EOF
1799 else
1800 cat >>man/edit_man.sh <<CF_EOF
1801         target=\`grep "^\$source" $MANPAGE_RENAMES | $AWK '{print \[$]2}'\`
1802         if test -z "\$target" ; then
1803                 echo '? missing rename for '\$source
1804                 target="\$source"
1805         fi
1806         target="$cf_subdir\${section}/\${target}"
1807 CF_EOF
1808 fi
1809
1810         # replace variables in man page
1811         ifelse($1,,,[
1812         for cf_name in $1
1813         do
1814 cat >>man/edit_man.sh <<CF_EOF
1815         prog_$cf_name=\`echo $cf_name|sed "\${transform}"\`
1816 CF_EOF
1817         done
1818         ])
1819 cat >>man/edit_man.sh <<CF_EOF
1820         sed     -e "s,@DATADIR@,\$datadir," \\
1821                 -e "s,@TERMINFO@,\$TERMINFO," \\
1822                 -e "s,@NCURSES_OSPEED@,\$NCURSES_OSPEED," \\
1823 CF_EOF
1824         ifelse($1,,,[
1825         for cf_name in $1
1826         do
1827                 cf_NAME=`echo "$cf_name" | sed y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%`
1828 cat >>man/edit_man.sh <<CF_EOF
1829                 -e "s,@$cf_NAME@,\$prog_$cf_name," \\
1830 CF_EOF
1831         done
1832         ])
1833 if test -f $MANPAGE_RENAMES ; then
1834 cat >>man/edit_man.sh <<CF_EOF
1835                 < \$i | sed -f edit_man.sed >\$TMP
1836 CF_EOF
1837 else
1838 cat >>man/edit_man.sh <<CF_EOF
1839                 < \$i >\$TMP
1840 CF_EOF
1841 fi
1842 if test $MANPAGE_TBL = yes ; then
1843 cat >>man/edit_man.sh <<CF_EOF
1844         tbl \$TMP >\$TMP.out
1845         mv \$TMP.out \$TMP
1846 CF_EOF
1847 fi
1848 if test $with_curses_h != yes ; then
1849 cat >>man/edit_man.sh <<CF_EOF
1850         sed -e "/\#[    ]*include/s,curses.h,ncurses.h," < \$TMP >\$TMP.out
1851         mv \$TMP.out \$TMP
1852 CF_EOF
1853 fi
1854 if test $cf_format = yes ; then
1855 cat >>man/edit_man.sh <<CF_EOF
1856         nroff -man \$TMP >\$TMP.out
1857         mv \$TMP.out \$TMP
1858 CF_EOF
1859 fi
1860 case "$MANPAGE_FORMAT" in #(vi
1861 *compress*) #(vi
1862 cat >>man/edit_man.sh <<CF_EOF
1863         if test \$verb = installing ; then
1864         if ( compress -f \$TMP )
1865         then
1866                 mv \$TMP.Z \$TMP
1867         fi
1868         fi
1869         target="\$target.Z"
1870 CF_EOF
1871   ;;
1872 *gzip*) #(vi
1873 cat >>man/edit_man.sh <<CF_EOF
1874         if test \$verb = installing ; then
1875         if ( gzip -f \$TMP )
1876         then
1877                 mv \$TMP.gz \$TMP
1878         fi
1879         fi
1880         target="\$target.gz"
1881 CF_EOF
1882   ;;
1883 *BSDI*)
1884 cat >>man/edit_man.sh <<CF_EOF
1885         # BSDI installs only .0 suffixes in the cat directories
1886         target="\`echo \$target|sed -e 's/\.[[1-9]]\+.\?/.0/'\`"
1887 CF_EOF
1888   ;;
1889 esac
1890 cat >>man/edit_man.sh <<CF_EOF
1891         suffix=\`basename \$target | sed -e 's/^[[^.]]*//'\`
1892         if test \$verb = installing ; then
1893                 echo \$verb \$target
1894                 \$INSTALL_DATA \$TMP \$target
1895                 test -n "\$aliases" && (
1896                         cd $cf_subdir\${section} && (
1897                                 target=\`basename \$target\`
1898                                 for cf_alias in \$aliases
1899                                 do
1900                                         if test \$section = 1 ; then
1901                                                 cf_alias=\`echo \$cf_alias|sed "\${transform}"\`
1902                                         fi
1903
1904                                         if test -f \$cf_alias\${suffix} ; then
1905                                                 if ( cmp -s \$target \$cf_alias\${suffix} )
1906                                                 then
1907                                                         :
1908                                                 else
1909                                                         echo .. \$verb alias \$cf_alias\${suffix}
1910                                                         rm -f \$cf_alias\${suffix}
1911                                                         $LN_S \$target \$cf_alias\${suffix}
1912                                                 fi
1913                                         else
1914                                                 echo .. \$verb alias \$cf_alias\${suffix}
1915                                                 rm -f \$cf_alias\${suffix}
1916                                                 $LN_S \$target \$cf_alias\${suffix}
1917                                         fi
1918                                 done
1919                         )
1920                 )
1921         elif test \$verb = removing ; then
1922                 echo \$verb \$target
1923                 rm -f \$target
1924                 test -n "\$aliases" && (
1925                         cd $cf_subdir\${section} && (
1926                                 for cf_alias in \$aliases
1927                                 do
1928                                         if test \$section = 1 ; then
1929                                                 cf_alias=\`echo \$cf_alias|sed "\${transform}"\`
1930                                         fi
1931
1932                                         echo .. \$verb alias \$cf_alias\${suffix}
1933                                         rm -f \$cf_alias\${suffix}
1934                                 done
1935                         )
1936                 )
1937         else
1938 #               echo ".hy 0"
1939                 cat \$TMP
1940         fi
1941         ;;
1942 esac
1943 done
1944 exit 0
1945 CF_EOF
1946 chmod 755 man/edit_man.sh
1947
1948 ])dnl
1949 dnl ---------------------------------------------------------------------------
1950 dnl Checks for libraries.  At least one UNIX system, Apple Macintosh
1951 dnl Rhapsody 5.5, does not have -lm.  We cannot use the simpler
1952 dnl AC_CHECK_LIB(m,sin), because that fails for C++.
1953 AC_DEFUN([CF_MATH_LIB],
1954 [
1955 AC_CACHE_CHECK(if -lm needed for math functions,
1956         cf_cv_need_libm,[
1957         AC_TRY_LINK([
1958         #include <stdio.h>
1959         #include <math.h>
1960         ],
1961         [double x = rand(); printf("result = %g\n", ]ifelse($2,,sin(x),$2)[)],
1962         [cf_cv_need_libm=no],
1963         [cf_cv_need_libm=yes])])
1964 if test "$cf_cv_need_libm" = yes
1965 then
1966 ifelse($1,,[
1967         LIBS="$LIBS -lm"
1968 ],[$1=-lm])
1969 fi
1970 ])
1971 dnl ---------------------------------------------------------------------------
1972 dnl Check if mbstate_t is declared, and if so, which header file.
1973 AC_DEFUN([CF_MBSTATE_T],
1974 [
1975 # This is needed on Tru64 5.0 to declare mbstate_t
1976 AC_CACHE_CHECK(if we must include wchar.h to declare mbstate_t,cf_cv_mbstate_t,[
1977 AC_TRY_COMPILE([
1978 #include <stdlib.h>
1979 #ifdef HAVE_LIBUTF8_H
1980 #include <libutf8.h>
1981 #endif],
1982         [mbstate_t state],
1983         [cf_cv_mbstate_t=no],
1984         [AC_TRY_COMPILE([
1985 #include <stdlib.h>
1986 #include <wchar.h>
1987 #ifdef HAVE_LIBUTF8_H
1988 #include <libutf8.h>
1989 #endif],
1990         [mbstate_t value],
1991         [cf_cv_mbstate_t=yes],
1992         [cf_cv_mbstate_t=unknown])])])
1993
1994 if test "$cf_cv_mbstate_t" = yes ; then
1995         AC_DEFINE(NEED_WCHAR_H)
1996 fi
1997
1998 if test "$cf_cv_mbstate_t" != unknown ; then
1999         AC_DEFINE(HAVE_MBSTATE_T)
2000 fi
2001 ])dnl
2002 dnl ---------------------------------------------------------------------------
2003 dnl Check if the file-system supports mixed-case filenames.  If we're able to
2004 dnl create a lowercase name and see it as uppercase, it doesn't support that.
2005 AC_DEFUN([CF_MIXEDCASE_FILENAMES],
2006 [
2007 AC_CACHE_CHECK(if filesystem supports mixed-case filenames,cf_cv_mixedcase,[
2008         rm -f conftest CONFTEST
2009         echo test >conftest
2010         if test -f CONFTEST ; then
2011                 cf_cv_mixedcase=no
2012         else
2013                 cf_cv_mixedcase=yes
2014         fi
2015         rm -f conftest CONFTEST
2016 ])
2017 test "$cf_cv_mixedcase" = yes && AC_DEFINE(MIXEDCASE_FILENAMES)
2018 ])dnl
2019 dnl ---------------------------------------------------------------------------
2020 dnl Check for a working mkstemp.  This creates two files, checks that they are
2021 dnl successfully created and distinct (AmigaOS apparently fails on the last).
2022 AC_DEFUN([CF_MKSTEMP],[
2023 AC_CACHE_CHECK(for working mkstemp, cf_cv_func_mkstemp,[
2024 rm -f conftest*
2025 AC_TRY_RUN([
2026 #include <sys/types.h>
2027 #include <stdlib.h>
2028 #include <stdio.h>
2029 #include <string.h>
2030 #include <sys/stat.h>
2031 int main()
2032 {
2033         char *tmpl = "conftestXXXXXX";
2034         char name[2][80];
2035         int n;
2036         int result = 0;
2037         int fd;
2038         struct stat sb;
2039
2040         umask(077);
2041         for (n = 0; n < 2; ++n) {
2042                 strcpy(name[n], tmpl);
2043                 if ((fd = mkstemp(name[n])) >= 0) {
2044                         if (!strcmp(name[n], tmpl)
2045                          || stat(name[n], &sb) != 0
2046                          || (sb.st_mode & S_IFMT) != S_IFREG
2047                          || (sb.st_mode & 077) != 0) {
2048                                 result = 1;
2049                         }
2050                         close(fd);
2051                 }
2052         }
2053         if (result == 0
2054          && !strcmp(name[0], name[1]))
2055                 result = 1;
2056         exit(result);
2057 }
2058 ],[cf_cv_func_mkstemp=yes
2059 ],[cf_cv_func_mkstemp=no
2060 ],[AC_CHECK_FUNC(mkstemp)
2061 ])
2062 ])
2063 if test "$cf_cv_func_mkstemp" = yes ; then
2064         AC_DEFINE(HAVE_MKSTEMP)
2065 fi
2066 ])dnl
2067 dnl ---------------------------------------------------------------------------
2068 dnl Compute the object-directory name from the given model name
2069 AC_DEFUN([CF_OBJ_SUBDIR],
2070 [
2071         case $1 in
2072         libtool) $2='obj_lo'  ;;
2073         normal)  $2='objects' ;;
2074         debug)   $2='obj_g' ;;
2075         profile) $2='obj_p' ;;
2076         shared)
2077                 case $cf_cv_system_name in #(vi
2078                 cygwin) #(vi
2079                         $2='objects' ;;
2080                 *)
2081                         $2='obj_s' ;;
2082                 esac
2083         esac
2084 ])dnl
2085 dnl ---------------------------------------------------------------------------
2086 dnl Provide a value for the $PATH and similar separator
2087 AC_DEFUN([CF_PATHSEP],
2088 [
2089         case $cf_cv_system_name in
2090         os2*)   PATHSEP=';'  ;;
2091         *)      PATHSEP=':'  ;;
2092         esac
2093 ifelse($1,,,[$1=$PATHSEP])
2094         AC_SUBST(PATHSEP)
2095 ])dnl
2096 dnl ---------------------------------------------------------------------------
2097 dnl Check the argument to see that it looks like a pathname.  Rewrite it if it
2098 dnl begins with one of the prefix/exec_prefix variables, and then again if the
2099 dnl result begins with 'NONE'.  This is necessary to work around autoconf's
2100 dnl delayed evaluation of those symbols.
2101 AC_DEFUN([CF_PATH_SYNTAX],[
2102 case ".[$]$1" in #(vi
2103 .\[$]\(*\)*|.\'*\'*) #(vi
2104   ;;
2105 ..|./*|.\\*) #(vi
2106   ;;
2107 .[[a-zA-Z]]:[[\\/]]*) #(vi OS/2 EMX
2108   ;;
2109 .\[$]{*prefix}*) #(vi
2110   eval $1="[$]$1"
2111   case ".[$]$1" in #(vi
2112   .NONE/*)
2113     $1=`echo [$]$1 | sed -e s%NONE%$ac_default_prefix%`
2114     ;;
2115   esac
2116   ;; #(vi
2117 .NONE/*)
2118   $1=`echo [$]$1 | sed -e s%NONE%$ac_default_prefix%`
2119   ;;
2120 *)
2121   ifelse($2,,[AC_ERROR([expected a pathname, not \"[$]$1\"])],$2)
2122   ;;
2123 esac
2124 ])dnl
2125 dnl ---------------------------------------------------------------------------
2126 dnl Compute $PROG_EXT, used for non-Unix ports, such as OS/2 EMX.
2127 AC_DEFUN([CF_PROG_EXT],
2128 [
2129 AC_REQUIRE([CF_CHECK_CACHE])
2130 PROG_EXT=
2131 case $cf_cv_system_name in
2132 os2*)
2133     # We make sure -Zexe is not used -- it would interfere with @PROG_EXT@
2134     CFLAGS="$CFLAGS -Zmt"
2135     CPPFLAGS="$CPPFLAGS -D__ST_MT_ERRNO__"
2136     CXXFLAGS="$CXXFLAGS -Zmt"
2137     LDFLAGS=`echo "$LDFLAGS -Zmt -Zcrtdll" | sed "s/-Zexe//g"`
2138     PROG_EXT=".exe"
2139     ;;
2140 cygwin*)
2141     PROG_EXT=".exe"
2142     ;;
2143 esac
2144 AC_SUBST(PROG_EXT)
2145 test -n "$PROG_EXT" && AC_DEFINE_UNQUOTED(PROG_EXT,"$PROG_EXT")
2146 ])dnl
2147 dnl ---------------------------------------------------------------------------
2148 dnl Force $INSTALL to be an absolute-path.  Otherwise, edit_man.sh and the
2149 dnl misc/tabset install won't work properly.  Usually this happens only when
2150 dnl using the fallback mkinstalldirs script
2151 AC_DEFUN([CF_PROG_INSTALL],
2152 [AC_PROG_INSTALL
2153 case $INSTALL in
2154 /*)
2155   ;;
2156 *)
2157   CF_DIRNAME(cf_dir,$INSTALL)
2158   test -z "$cf_dir" && cf_dir=.
2159   INSTALL=`cd $cf_dir && pwd`/`echo $INSTALL | sed -e 's:^.*/::'`
2160   ;;
2161 esac
2162 ])dnl
2163 dnl ---------------------------------------------------------------------------
2164 dnl Attempt to determine if we've got one of the flavors of regular-expression
2165 dnl code that we can support.
2166 AC_DEFUN([CF_REGEX],
2167 [
2168 AC_MSG_CHECKING([for regular-expression headers])
2169 AC_CACHE_VAL(cf_cv_regex,[
2170 AC_TRY_LINK([#include <sys/types.h>
2171 #include <regex.h>],[
2172         regex_t *p;
2173         int x = regcomp(p, "", 0);
2174         int y = regexec(p, "", 0, 0, 0);
2175         regfree(p);
2176         ],[cf_cv_regex="regex.h"],[
2177         AC_TRY_LINK([#include <regexp.h>],[
2178                 char *p = compile("", "", "", 0);
2179                 int x = step("", "");
2180         ],[cf_cv_regex="regexp.h"],[
2181                 cf_save_LIBS="$LIBS"
2182                 LIBS="-lgen $LIBS"
2183                 AC_TRY_LINK([#include <regexpr.h>],[
2184                         char *p = compile("", "", "");
2185                         int x = step("", "");
2186                 ],[cf_cv_regex="regexpr.h"],[LIBS="$cf_save_LIBS"])])])
2187 ])
2188 AC_MSG_RESULT($cf_cv_regex)
2189 case $cf_cv_regex in
2190         regex.h)   AC_DEFINE(HAVE_REGEX_H_FUNCS) ;;
2191         regexp.h)  AC_DEFINE(HAVE_REGEXP_H_FUNCS) ;;
2192         regexpr.h) AC_DEFINE(HAVE_REGEXPR_H_FUNCS) ;;
2193 esac
2194 ])dnl
2195 dnl ---------------------------------------------------------------------------
2196 dnl Attempt to determine the appropriate CC/LD options for creating a shared
2197 dnl library.
2198 dnl
2199 dnl Note: $(LOCAL_LDFLAGS) is used to link executables that will run within the
2200 dnl build-tree, i.e., by making use of the libraries that are compiled in ../lib
2201 dnl We avoid compiling-in a ../lib path for the shared library since that can
2202 dnl lead to unexpected results at runtime.
2203 dnl $(LOCAL_LDFLAGS2) has the same intention but assumes that the shared libraries
2204 dnl are compiled in ../../lib
2205 dnl
2206 dnl The variable 'cf_cv_do_symlinks' is used to control whether we configure
2207 dnl to install symbolic links to the rel/abi versions of shared libraries.
2208 dnl
2209 dnl The variable 'cf_cv_shlib_version' controls whether we use the rel or abi
2210 dnl version when making symbolic links.
2211 dnl
2212 dnl The variable 'cf_cv_shlib_version_infix' controls whether shared library
2213 dnl version numbers are infix (ex: libncurses.<ver>.dylib) or postfix
2214 dnl (ex: libncurses.so.<ver>).
2215 dnl
2216 dnl Some loaders leave 'so_locations' lying around.  It's nice to clean up.
2217 AC_DEFUN([CF_SHARED_OPTS],
2218 [
2219         AC_REQUIRE([CF_SUBST_NCURSES_VERSION])
2220         LOCAL_LDFLAGS=
2221         LOCAL_LDFLAGS2=
2222         LD_SHARED_OPTS=
2223         INSTALL_LIB="-m 644"
2224
2225         cf_cv_do_symlinks=no
2226
2227         AC_MSG_CHECKING(if release/abi version should be used for shared libs)
2228         AC_ARG_WITH(shlib-version,
2229         [  --with-shlib-version=X  Specify rel or abi version for shared libs],
2230         [test -z "$withval" && withval=auto
2231         case $withval in #(vi
2232         yes) #(vi
2233                 cf_cv_shlib_version=auto
2234                 ;;
2235         rel|abi|auto|no) #(vi
2236                 cf_cv_shlib_version=$withval
2237                 ;;
2238         *)
2239                 AC_ERROR([option value must be one of: rel, abi, auto or no])
2240                 ;;
2241         esac
2242         ],[cf_cv_shlib_version=auto])
2243         AC_MSG_RESULT($cf_cv_shlib_version)
2244
2245         cf_cv_rm_so_locs=no
2246
2247         # Some less-capable ports of gcc support only -fpic
2248         CC_SHARED_OPTS=
2249         if test "$GCC" = yes
2250         then
2251                 AC_MSG_CHECKING(which $CC option to use)
2252                 cf_save_CFLAGS="$CFLAGS"
2253                 for CC_SHARED_OPTS in -fPIC -fpic ''
2254                 do
2255                         CFLAGS="$cf_save_CFLAGS $CC_SHARED_OPTS"
2256                         AC_TRY_COMPILE([#include <stdio.h>],[int x = 1],[break],[])
2257                 done
2258                 AC_MSG_RESULT($CC_SHARED_OPTS)
2259                 CFLAGS="$cf_save_CFLAGS"
2260         fi
2261
2262         cf_cv_shlib_version_infix=no
2263
2264         case $cf_cv_system_name in
2265         beos*)
2266                 MK_SHARED_LIB='$(CC) -o $[@] -Xlinker -soname=`basename $[@]` -nostart -e 0'
2267                 ;;
2268         cygwin*)
2269                 CC_SHARED_OPTS=
2270                 MK_SHARED_LIB='$(CC) -shared -Wl,--out-implib=$(IMPORT_LIB) -Wl,--export-all-symbols -o $(SHARED_LIB)'
2271                 cf_cv_shlib_version=cygdll
2272                 cf_cv_shlib_version_infix=cygdll
2273                 ;;
2274         darwin*)
2275                 EXTRA_CFLAGS="-no-cpp-precomp"
2276                 CC_SHARED_OPTS="-dynamic"
2277                 MK_SHARED_LIB='$(CC) -dynamiclib -install_name $(DESTDIR)$(libdir)/`basename $[@]` -compatibility_version $(ABI_VERSION) -current_version $(ABI_VERSION) -o $[@]'
2278                 test "$cf_cv_shlib_version" = auto && cf_cv_shlib_version=abi
2279                 cf_cv_shlib_version_infix=yes
2280                 ;;
2281         hpux*)
2282                 # (tested with gcc 2.7.2 -- I don't have c89)
2283                 if test "$GCC" = yes; then
2284                         LD_SHARED_OPTS='-Xlinker +b -Xlinker $(libdir)'
2285                 else
2286                         CC_SHARED_OPTS='+Z'
2287                         LD_SHARED_OPTS='-Wl,+b,$(libdir)'
2288                 fi
2289                 MK_SHARED_LIB='$(LD) +b $(libdir) -b -o $[@]'
2290                 # HP-UX shared libraries must be executable, and should be
2291                 # readonly to exploit a quirk in the memory manager.
2292                 INSTALL_LIB="-m 555"
2293                 ;;
2294         irix*)
2295                 if test "$cf_cv_ld_rpath" = yes ; then
2296                         cf_ld_rpath_opt="-Wl,-rpath,"
2297                         EXTRA_LDFLAGS="-Wl,-rpath,\$(libdir) $EXTRA_LDFLAGS"
2298                 fi
2299                 # tested with IRIX 5.2 and 'cc'.
2300                 if test "$GCC" != yes; then
2301                         CC_SHARED_OPTS='-KPIC'
2302                 fi
2303                 MK_SHARED_LIB='$(LD) -shared -rdata_shared -soname `basename $[@]` -o $[@]'
2304                 cf_cv_rm_so_locs=yes
2305                 ;;
2306         linux*|gnu*)
2307                 if test "$DFT_LWR_MODEL" = "shared" ; then
2308                         LOCAL_LDFLAGS="-Wl,-rpath,`pwd`/lib"
2309                         LOCAL_LDFLAGS2="$LOCAL_LDFLAGS"
2310                 fi
2311                 if test "$cf_cv_ld_rpath" = yes ; then
2312                         cf_ld_rpath_opt="-Wl,-rpath,"
2313                         EXTRA_LDFLAGS="$LOCAL_LDFLAGS $EXTRA_LDFLAGS"
2314                 fi
2315                 test "$cf_cv_shlib_version" = auto && cf_cv_shlib_version=rel
2316                 MK_SHARED_LIB='$(CC) -shared -Wl,-soname,`basename $[@] .$(REL_VERSION)`.$(ABI_VERSION),-stats,-lc -o $[@]'
2317                 ;;
2318         openbsd2*)
2319                 CC_SHARED_OPTS="$CC_SHARED_OPTS -DPIC"
2320                 MK_SHARED_LIB='$(LD) -Bshareable -soname,`basename $[@].$(ABI_VERSION)` -o $[@]'
2321                 ;;
2322         openbsd*|freebsd*)
2323                 CC_SHARED_OPTS="$CC_SHARED_OPTS -DPIC"
2324                 MK_SHARED_LIB='$(LD) -Bshareable -o $[@]'
2325                 test "$cf_cv_shlib_version" = auto && cf_cv_shlib_version=rel
2326                 ;;
2327         netbsd*)
2328                 CC_SHARED_OPTS="$CC_SHARED_OPTS -DPIC"
2329                 test "$cf_cv_ld_rpath" = yes && cf_ld_rpath_opt="-Wl,-rpath,"
2330                 if test "$DFT_LWR_MODEL" = "shared" && test "$cf_cv_ld_rpath" = yes ; then
2331                         LOCAL_LDFLAGS="-Wl,-rpath,`pwd`/lib"
2332                         LOCAL_LDFLAGS2="$LOCAL_LDFLAGS"
2333                         EXTRA_LDFLAGS="-Wl,-rpath,\$(libdir) $EXTRA_LDFLAGS"
2334                         MK_SHARED_LIB='$(CC) -shared -Wl,-soname,`basename $[@] .$(REL_VERSION)`.$(ABI_VERSION) -o $[@]'
2335                         if test "$cf_cv_shlib_version" = auto; then
2336                         if test ! -f /usr/libexec/ld.elf_so; then
2337                                 cf_cv_shlib_version=rel
2338                         fi
2339                         fi
2340                 else
2341                         MK_SHARED_LIB='$(LD) -Bshareable -o $[@]'
2342                 fi
2343                 ;;
2344         osf*|mls+*)
2345                 # tested with OSF/1 V3.2 and 'cc'
2346                 # tested with OSF/1 V3.2 and gcc 2.6.3 (but the c++ demo didn't
2347                 # link with shared libs).
2348                 MK_SHARED_LIB='$(LD) -set_version $(REL_VERSION):$(ABI_VERSION) -expect_unresolved "*" -shared -soname `basename $[@]`'
2349                 case $host_os in
2350                 osf4*)
2351                         MK_SHARED_LIB="${MK_SHARED_LIB} -msym"
2352                         ;;
2353                 esac
2354                 MK_SHARED_LIB="${MK_SHARED_LIB}"' -o $[@]'
2355                 if test "$DFT_LWR_MODEL" = "shared" ; then
2356                         LOCAL_LDFLAGS="-Wl,-rpath,`pwd`/lib"
2357                         LOCAL_LDFLAGS2="$LOCAL_LDFLAGS"
2358                 fi
2359                 if test "$cf_cv_ld_rpath" = yes ; then
2360                         cf_ld_rpath_opt="-rpath"
2361                         # EXTRA_LDFLAGS="$LOCAL_LDFLAGS $EXTRA_LDFLAGS"
2362                 fi
2363                 cf_cv_rm_so_locs=yes
2364                 ;;
2365         sco3.2v5*)  # (also uw2* and UW7) hops 13-Apr-98
2366                 # tested with osr5.0.5
2367                 if test "$ac_cv_prog_gcc" != yes; then
2368                         CC_SHARED_OPTS='-belf -KPIC'
2369                 fi
2370                 MK_SHARED_LIB='$(LD) -dy -G -h `basename $[@] .$(REL_VERSION)`.$(ABI_VERSION) -o [$]@'
2371                 if test "$cf_cv_ld_rpath" = yes ; then
2372                         # only way is to set LD_RUN_PATH but no switch for it
2373                         RUN_PATH=$libdir
2374                 fi
2375                 test "$cf_cv_shlib_version" = auto && cf_cv_shlib_version=rel
2376                 LINK_PROGS='LD_RUN_PATH=$(libdir)'
2377                 LINK_TESTS='Pwd=`pwd`;LD_RUN_PATH=`dirname $${Pwd}`/lib'
2378                 ;;
2379         sunos4*)
2380                 # tested with SunOS 4.1.1 and gcc 2.7.0
2381                 if test "$ac_cv_prog_gcc" != yes; then
2382                         CC_SHARED_OPTS='-KPIC'
2383                 fi
2384                 MK_SHARED_LIB='$(LD) -assert pure-text -o $[@]'
2385                 test "$cf_cv_shlib_version" = auto && cf_cv_shlib_version=rel
2386                 ;;
2387         solaris2*)
2388                 # tested with SunOS 5.5.1 (solaris 2.5.1) and gcc 2.7.2
2389                 if test "$ac_cv_prog_gcc" != yes; then
2390                         CC_SHARED_OPTS='-KPIC'
2391                 fi
2392                 MK_SHARED_LIB='$(LD) -dy -G -h `basename $[@] .$(REL_VERSION)`.$(ABI_VERSION) -o $[@]'
2393                 if test "$DFT_LWR_MODEL" = "shared" ; then
2394                         LOCAL_LDFLAGS="-R `pwd`/lib:\$(libdir)"
2395                         LOCAL_LDFLAGS2="$LOCAL_LDFLAGS"
2396                 fi
2397                 if test "$cf_cv_ld_rpath" = yes ; then
2398                         cf_ld_rpath_opt="-R"
2399                         EXTRA_LDFLAGS="$LOCAL_LDFLAGS $EXTRA_LDFLAGS"
2400                 fi
2401                 test "$cf_cv_shlib_version" = auto && cf_cv_shlib_version=rel
2402                 ;;
2403         sysv5uw7*|unix_sv*)
2404                 # tested with UnixWare 7.1.0 (gcc 2.95.2 and cc)
2405                 if test "$ac_cv_prog_gcc" != yes; then
2406                         CC_SHARED_OPTS='-KPIC'
2407                 fi
2408                 MK_SHARED_LIB='$(LD) -d y -G -o [$]@'
2409                 ;;
2410         *)
2411                 CC_SHARED_OPTS='unknown'
2412                 MK_SHARED_LIB='echo unknown'
2413                 ;;
2414         esac
2415
2416         # This works if the last tokens in $MK_SHARED_LIB are the -o target.
2417         case "$cf_cv_shlib_version" in #(vi
2418         rel|abi)
2419                 case "$MK_SHARED_LIB" in #(vi
2420                 *'-o $[@]')
2421                         test "$cf_cv_do_symlinks" = no && cf_cv_do_symlinks=yes
2422                         ;;
2423                 *)
2424                         AC_MSG_WARN(ignored --with-shlib-version)
2425                         ;;
2426                 esac
2427                 ;;
2428         esac
2429
2430         if test -n "$cf_ld_rpath_opt" ; then
2431                 AC_MSG_CHECKING(if we need a space after rpath option)
2432                 cf_save_LIBS="$LIBS"
2433                 LIBS="$LIBS ${cf_ld_rpath_opt}$libdir"
2434                 AC_TRY_LINK(, , cf_rpath_space=no, cf_rpath_space=yes)
2435                 LIBS="$cf_save_LIBS"
2436                 AC_MSG_RESULT($cf_rpath_space)
2437                 test "$cf_rpath_space" = yes && cf_ld_rpath_opt="$cf_ld_rpath_opt "
2438                 MK_SHARED_LIB="$MK_SHARED_LIB $cf_ld_rpath_opt\$(libdir)"
2439         fi
2440
2441         AC_SUBST(CC_SHARED_OPTS)
2442         AC_SUBST(LD_SHARED_OPTS)
2443         AC_SUBST(MK_SHARED_LIB)
2444         AC_SUBST(LINK_PROGS)
2445         AC_SUBST(LINK_TESTS)
2446         AC_SUBST(EXTRA_LDFLAGS)
2447         AC_SUBST(LOCAL_LDFLAGS)
2448         AC_SUBST(LOCAL_LDFLAGS2)
2449         AC_SUBST(INSTALL_LIB)
2450 ])dnl
2451 dnl ---------------------------------------------------------------------------
2452 dnl Check for definitions & structures needed for window size-changing
2453 dnl FIXME: check that this works with "snake" (HP-UX 10.x)
2454 AC_DEFUN([CF_SIZECHANGE],
2455 [
2456 AC_REQUIRE([CF_STRUCT_TERMIOS])
2457 AC_CACHE_CHECK(declaration of size-change, cf_cv_sizechange,[
2458     cf_cv_sizechange=unknown
2459     cf_save_CPPFLAGS="$CPPFLAGS"
2460
2461 for cf_opts in "" "NEED_PTEM_H"
2462 do
2463
2464     CPPFLAGS="$cf_save_CPPFLAGS"
2465     test -n "$cf_opts" && CPPFLAGS="$CPPFLAGS -D$cf_opts"
2466     AC_TRY_COMPILE([#include <sys/types.h>
2467 #ifdef HAVE_TERMIOS_H
2468 #include <termios.h>
2469 #else
2470 #ifdef HAVE_TERMIO_H
2471 #include <termio.h>
2472 #endif
2473 #endif
2474 #ifdef NEED_PTEM_H
2475 /* This is a workaround for SCO:  they neglected to define struct winsize in
2476  * termios.h -- it's only in termio.h and ptem.h
2477  */
2478 #include        <sys/stream.h>
2479 #include        <sys/ptem.h>
2480 #endif
2481 #if !defined(sun) || !defined(HAVE_TERMIOS_H)
2482 #include <sys/ioctl.h>
2483 #endif
2484 ],[
2485 #ifdef TIOCGSIZE
2486         struct ttysize win;     /* FIXME: what system is this? */
2487         int y = win.ts_lines;
2488         int x = win.ts_cols;
2489 #else
2490 #ifdef TIOCGWINSZ
2491         struct winsize win;
2492         int y = win.ws_row;
2493         int x = win.ws_col;
2494 #else
2495         no TIOCGSIZE or TIOCGWINSZ
2496 #endif /* TIOCGWINSZ */
2497 #endif /* TIOCGSIZE */
2498         ],
2499         [cf_cv_sizechange=yes],
2500         [cf_cv_sizechange=no])
2501
2502         CPPFLAGS="$cf_save_CPPFLAGS"
2503         if test "$cf_cv_sizechange" = yes ; then
2504                 echo "size-change succeeded ($cf_opts)" >&AC_FD_CC
2505                 test -n "$cf_opts" && cf_cv_sizechange="$cf_opts"
2506                 break
2507         fi
2508 done
2509 ])
2510 if test "$cf_cv_sizechange" != no ; then
2511         AC_DEFINE(HAVE_SIZECHANGE)
2512         case $cf_cv_sizechange in #(vi
2513         NEED*)
2514                 AC_DEFINE_UNQUOTED($cf_cv_sizechange )
2515                 ;;
2516         esac
2517 fi
2518 ])dnl
2519 dnl ---------------------------------------------------------------------------
2520 dnl For each parameter, test if the source-directory exists, and if it contains
2521 dnl a 'modules' file.  If so, add to the list $cf_cv_src_modules which we'll
2522 dnl use in CF_LIB_RULES.
2523 dnl
2524 dnl This uses the configured value to make the lists SRC_SUBDIRS and
2525 dnl SUB_MAKEFILES which are used in the makefile-generation scheme.
2526 AC_DEFUN([CF_SRC_MODULES],
2527 [
2528 AC_MSG_CHECKING(for src modules)
2529
2530 # dependencies and linker-arguments for test-programs
2531 TEST_DEPS="${LIB_DIR}/${LIB_PREFIX}${LIB_NAME}${DFT_DEP_SUFFIX} $TEST_DEPS"
2532 if test "$DFT_LWR_MODEL" = "libtool"; then
2533         TEST_ARGS="${TEST_DEPS}"
2534 else
2535         TEST_ARGS="-l${LIB_NAME}${DFT_ARG_SUFFIX} $TEST_ARGS"
2536 fi
2537
2538 # dependencies and linker-arguments for utility-programs
2539 PROG_ARGS="$TEST_ARGS"
2540
2541 cf_cv_src_modules=
2542 for cf_dir in $1
2543 do
2544         if test -f $srcdir/$cf_dir/modules; then
2545
2546                 # We may/may not have tack in the distribution, though the
2547                 # makefile is.
2548                 if test $cf_dir = tack ; then
2549                         if test ! -f $srcdir/${cf_dir}/${cf_dir}.h; then
2550                                 continue
2551                         fi
2552                 fi
2553
2554                 if test -z "$cf_cv_src_modules"; then
2555                         cf_cv_src_modules=$cf_dir
2556                 else
2557                         cf_cv_src_modules="$cf_cv_src_modules $cf_dir"
2558                 fi
2559
2560                 # Make the ncurses_cfg.h file record the library interface files as
2561                 # well.  These are header files that are the same name as their
2562                 # directory.  Ncurses is the only library that does not follow
2563                 # that pattern.
2564                 if test $cf_dir = tack ; then
2565                         continue
2566                 elif test -f $srcdir/${cf_dir}/${cf_dir}.h; then
2567                         CF_UPPER(cf_have_include,$cf_dir)
2568                         AC_DEFINE_UNQUOTED(HAVE_${cf_have_include}_H)
2569                         AC_DEFINE_UNQUOTED(HAVE_LIB${cf_have_include})
2570                         TEST_DEPS="${LIB_DIR}/${LIB_PREFIX}${cf_dir}${DFT_DEP_SUFFIX} $TEST_DEPS"
2571                         if test "$DFT_LWR_MODEL" = "libtool"; then
2572                                 TEST_ARGS="${TEST_DEPS}"
2573                         else
2574                                 TEST_ARGS="-l${cf_dir}${DFT_ARG_SUFFIX} $TEST_ARGS"
2575                         fi
2576                 fi
2577         fi
2578 done
2579 AC_MSG_RESULT($cf_cv_src_modules)
2580 TEST_ARGS="-L${LIB_DIR} $TEST_ARGS"
2581 AC_SUBST(TEST_DEPS)
2582 AC_SUBST(TEST_ARGS)
2583
2584 PROG_ARGS="-L${LIB_DIR} $PROG_ARGS"
2585 AC_SUBST(PROG_ARGS)
2586
2587 SRC_SUBDIRS="man include"
2588 for cf_dir in $cf_cv_src_modules
2589 do
2590         SRC_SUBDIRS="$SRC_SUBDIRS $cf_dir"
2591 done
2592 SRC_SUBDIRS="$SRC_SUBDIRS test"
2593 test -z "$MAKE_TERMINFO" && SRC_SUBDIRS="$SRC_SUBDIRS misc"
2594 test "$cf_with_cxx_binding" != no && SRC_SUBDIRS="$SRC_SUBDIRS c++"
2595
2596 ADA_SUBDIRS=
2597 if test "$cf_cv_prog_gnat_correct" = yes && test -f $srcdir/Ada95/Makefile.in; then
2598    SRC_SUBDIRS="$SRC_SUBDIRS Ada95"
2599    ADA_SUBDIRS="gen src samples"
2600 fi
2601
2602 SUB_MAKEFILES=
2603 for cf_dir in $SRC_SUBDIRS
2604 do
2605         SUB_MAKEFILES="$SUB_MAKEFILES $cf_dir/Makefile"
2606 done
2607
2608 if test -n "$ADA_SUBDIRS"; then
2609    for cf_dir in $ADA_SUBDIRS
2610    do
2611       SUB_MAKEFILES="$SUB_MAKEFILES Ada95/$cf_dir/Makefile"
2612    done
2613    AC_SUBST(ADA_SUBDIRS)
2614 fi
2615 ])dnl
2616 dnl ---------------------------------------------------------------------------
2617 dnl Check for -lstdc++, which is GNU's standard C++ library.
2618 AC_DEFUN([CF_STDCPP_LIBRARY],
2619 [
2620 if test -n "$GXX" ; then
2621 case $cf_cv_system_name in #(vi
2622 os2*) #(vi
2623         cf_stdcpp_libname=stdcpp
2624         ;;
2625 *)
2626         cf_stdcpp_libname=stdc++
2627         ;;
2628 esac
2629 AC_CACHE_CHECK(for library $cf_stdcpp_libname,cf_cv_libstdcpp,[
2630         cf_save="$LIBS"
2631         LIBS="$LIBS -l$cf_stdcpp_libname"
2632 AC_TRY_LINK([
2633 #include <strstream.h>],[
2634 char buf[80];
2635 strstreambuf foo(buf, sizeof(buf))
2636 ],
2637         [cf_cv_libstdcpp=yes],
2638         [cf_cv_libstdcpp=no])
2639         LIBS="$cf_save"
2640 ])
2641 test "$cf_cv_libstdcpp" = yes && CXXLIBS="$CXXLIBS -l$cf_stdcpp_libname"
2642 fi
2643 ])dnl
2644 dnl ---------------------------------------------------------------------------
2645 dnl     Remove "-g" option from the compiler options
2646 AC_DEFUN([CF_STRIP_G_OPT],
2647 [$1=`echo ${$1} | sed -e 's/-g //' -e 's/-g$//'`])dnl
2648 dnl ---------------------------------------------------------------------------
2649 dnl Check if we need _POSIX_SOURCE defined to use struct sigaction.  We'll only
2650 dnl do this if we've found the sigaction function.
2651 dnl
2652 dnl If needed, define SVR4_ACTION.
2653 AC_DEFUN([CF_STRUCT_SIGACTION],[
2654 if test "$ac_cv_func_sigaction" = yes; then
2655 AC_MSG_CHECKING(whether sigaction needs _POSIX_SOURCE)
2656 AC_TRY_COMPILE([
2657 #include <sys/types.h>
2658 #include <signal.h>],
2659         [struct sigaction act],
2660         [sigact_bad=no],
2661         [
2662 AC_TRY_COMPILE([
2663 #define _POSIX_SOURCE
2664 #include <sys/types.h>
2665 #include <signal.h>],
2666         [struct sigaction act],
2667         [sigact_bad=yes
2668          AC_DEFINE(SVR4_ACTION)],
2669          [sigact_bad=unknown])])
2670 AC_MSG_RESULT($sigact_bad)
2671 fi
2672 ])dnl
2673 dnl ---------------------------------------------------------------------------
2674 dnl Some machines require _POSIX_SOURCE to completely define struct termios.
2675 dnl If so, define SVR4_TERMIO
2676 AC_DEFUN([CF_STRUCT_TERMIOS],[
2677 AC_CHECK_HEADERS( \
2678 termio.h \
2679 termios.h \
2680 unistd.h \
2681 )
2682 if test "$ISC" = yes ; then
2683         AC_CHECK_HEADERS( sys/termio.h )
2684 fi
2685 if test "$ac_cv_header_termios_h" = yes ; then
2686         case "$CFLAGS $CPPFLAGS" in
2687         *-D_POSIX_SOURCE*)
2688                 termios_bad=dunno ;;
2689         *)      termios_bad=maybe ;;
2690         esac
2691         if test "$termios_bad" = maybe ; then
2692         AC_MSG_CHECKING(whether termios.h needs _POSIX_SOURCE)
2693         AC_TRY_COMPILE([#include <termios.h>],
2694                 [struct termios foo; int x = foo.c_iflag],
2695                 termios_bad=no, [
2696                 AC_TRY_COMPILE([
2697 #define _POSIX_SOURCE
2698 #include <termios.h>],
2699                         [struct termios foo; int x = foo.c_iflag],
2700                         termios_bad=unknown,
2701                         termios_bad=yes AC_DEFINE(SVR4_TERMIO))
2702                         ])
2703         AC_MSG_RESULT($termios_bad)
2704         fi
2705 fi
2706 ])dnl
2707 dnl ---------------------------------------------------------------------------
2708 dnl     Shorthand macro for substituting things that the user may override
2709 dnl     with an environment variable.
2710 dnl
2711 dnl     $1 = long/descriptive name
2712 dnl     $2 = environment variable
2713 dnl     $3 = default value
2714 AC_DEFUN([CF_SUBST],
2715 [AC_CACHE_VAL(cf_cv_subst_$2,[
2716 AC_MSG_CHECKING(for $1 (symbol $2))
2717 test -z "[$]$2" && $2=$3
2718 AC_MSG_RESULT([$]$2)
2719 AC_SUBST($2)
2720 cf_cv_subst_$2=[$]$2])
2721 $2=${cf_cv_subst_$2}
2722 ])dnl
2723 dnl ---------------------------------------------------------------------------
2724 dnl Get the version-number for use in shared-library naming, etc.
2725 AC_DEFUN([CF_SUBST_NCURSES_VERSION],
2726 [
2727 NCURSES_MAJOR="`egrep '^NCURSES_MAJOR[[         ]]*=' $srcdir/dist.mk | sed -e 's/^[[^0-9]]*//'`"
2728 NCURSES_MINOR="`egrep '^NCURSES_MINOR[[         ]]*=' $srcdir/dist.mk | sed -e 's/^[[^0-9]]*//'`"
2729 NCURSES_PATCH="`egrep '^NCURSES_PATCH[[         ]]*=' $srcdir/dist.mk | sed -e 's/^[[^0-9]]*//'`"
2730 cf_cv_abi_version=${NCURSES_MAJOR}
2731 cf_cv_rel_version=${NCURSES_MAJOR}.${NCURSES_MINOR}
2732 dnl Show the computed version, for logging
2733 cf_cv_timestamp=`date`
2734 AC_MSG_RESULT(Configuring NCURSES $cf_cv_rel_version ABI $cf_cv_abi_version ($cf_cv_timestamp))
2735 dnl We need these values in the generated headers
2736 AC_SUBST(NCURSES_MAJOR)
2737 AC_SUBST(NCURSES_MINOR)
2738 AC_SUBST(NCURSES_PATCH)
2739 dnl We need these values in the generated makefiles
2740 AC_SUBST(cf_cv_rel_version)
2741 AC_SUBST(cf_cv_abi_version)
2742 AC_SUBST(cf_cv_cc_bool_type)
2743 AC_SUBST(cf_cv_builtin_bool)
2744 AC_SUBST(cf_cv_header_stdbool_h)
2745 AC_SUBST(cf_cv_type_of_bool)dnl
2746 ])dnl
2747 dnl ---------------------------------------------------------------------------
2748 dnl Check if we can include <sys/time.h> with <sys/select.h>; this breaks on
2749 dnl older SCO configurations.
2750 AC_DEFUN([CF_SYS_TIME_SELECT],
2751 [
2752 AC_MSG_CHECKING(if sys/time.h works with sys/select.h)
2753 AC_CACHE_VAL(cf_cv_sys_time_select,[
2754 AC_TRY_COMPILE([
2755 #include <sys/types.h>
2756 #ifdef HAVE_SYS_TIME_H
2757 #include <sys/time.h>
2758 #endif
2759 #ifdef HAVE_SYS_SELECT_H
2760 #include <sys/select.h>
2761 #endif
2762 ],[],[cf_cv_sys_time_select=yes],
2763      [cf_cv_sys_time_select=no])
2764      ])
2765 AC_MSG_RESULT($cf_cv_sys_time_select)
2766 test "$cf_cv_sys_time_select" = yes && AC_DEFINE(HAVE_SYS_TIME_SELECT)
2767 ])dnl
2768 dnl ---------------------------------------------------------------------------
2769 dnl Determine the type we should use for chtype (and attr_t, which is treated
2770 dnl as the same thing).  We want around 32 bits, so on most machines want a
2771 dnl long, but on newer 64-bit machines, probably want an int.  If we're using
2772 dnl wide characters, we have to have a type compatible with that, as well.
2773 AC_DEFUN([CF_TYPEOF_CHTYPE],
2774 [
2775 AC_REQUIRE([CF_UNSIGNED_LITERALS])
2776 AC_MSG_CHECKING([for type of chtype])
2777 AC_CACHE_VAL(cf_cv_typeof_chtype,[
2778                 AC_TRY_RUN([
2779 #ifdef USE_WIDEC_SUPPORT
2780 #include <stddef.h>     /* we want wchar_t */
2781 #define WANT_BITS 39
2782 #else
2783 #define WANT_BITS 31
2784 #endif
2785 #include <stdio.h>
2786 int main()
2787 {
2788         FILE *fp = fopen("cf_test.out", "w");
2789         if (fp != 0) {
2790                 char *result = "long";
2791 #ifdef USE_WIDEC_SUPPORT
2792                 /*
2793                  * If wchar_t is smaller than a long, it must be an int or a
2794                  * short.  We prefer not to use a short anyway.
2795                  */
2796                 if (sizeof(unsigned long) > sizeof(wchar_t))
2797                         result = "int";
2798 #endif
2799                 if (sizeof(unsigned long) > sizeof(unsigned int)) {
2800                         int n;
2801                         unsigned int x;
2802                         for (n = 0; n < WANT_BITS; n++) {
2803                                 unsigned int y = (x >> n);
2804                                 if (y != 1 || x == 0) {
2805                                         x = 0;
2806                                         break;
2807                                 }
2808                         }
2809                         /*
2810                          * If x is nonzero, an int is big enough for the bits
2811                          * that we want.
2812                          */
2813                         result = (x != 0) ? "int" : "long";
2814                 }
2815                 fputs(result, fp);
2816                 fclose(fp);
2817         }
2818         exit(0);
2819 }
2820                 ],
2821                 [cf_cv_typeof_chtype=`cat cf_test.out`],
2822                 [cf_cv_typeof_chtype=long],
2823                 [cf_cv_typeof_chtype=long])
2824                 rm -f cf_test.out
2825         ])
2826 AC_MSG_RESULT($cf_cv_typeof_chtype)
2827
2828 AC_SUBST(cf_cv_typeof_chtype)
2829 AC_DEFINE_UNQUOTED(TYPEOF_CHTYPE,$cf_cv_typeof_chtype)
2830
2831 cf_cv_1UL="1"
2832 test "$cf_cv_unsigned_literals" = yes && cf_cv_1UL="${cf_cv_1UL}U"
2833 test "$cf_cv_typeof_chtype"    = long && cf_cv_1UL="${cf_cv_1UL}L"
2834 AC_SUBST(cf_cv_1UL)
2835
2836 ])dnl
2837 dnl ---------------------------------------------------------------------------
2838 dnl
2839 AC_DEFUN([CF_TYPE_SIGACTION],
2840 [
2841 AC_MSG_CHECKING([for type sigaction_t])
2842 AC_CACHE_VAL(cf_cv_type_sigaction,[
2843         AC_TRY_COMPILE([
2844 #include <signal.h>],
2845                 [sigaction_t x],
2846                 [cf_cv_type_sigaction=yes],
2847                 [cf_cv_type_sigaction=no])])
2848 AC_MSG_RESULT($cf_cv_type_sigaction)
2849 test "$cf_cv_type_sigaction" = yes && AC_DEFINE(HAVE_TYPE_SIGACTION)
2850 ])dnl
2851 dnl ---------------------------------------------------------------------------
2852 dnl Test if the compiler supports 'U' and 'L' suffixes.  Only old compilers
2853 dnl won't, but they're still there.
2854 AC_DEFUN([CF_UNSIGNED_LITERALS],
2855 [
2856 AC_MSG_CHECKING([if unsigned literals are legal])
2857 AC_CACHE_VAL(cf_cv_unsigned_literals,[
2858         AC_TRY_COMPILE([],[long x = 1L + 1UL + 1U + 1],
2859                 [cf_cv_unsigned_literals=yes],
2860                 [cf_cv_unsigned_literals=no])
2861         ])
2862 AC_MSG_RESULT($cf_cv_unsigned_literals)
2863 ])dnl
2864 dnl ---------------------------------------------------------------------------
2865 dnl Make an uppercase version of a variable
2866 dnl $1=uppercase($2)
2867 AC_DEFUN([CF_UPPER],
2868 [
2869 $1=`echo "$2" | sed y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%`
2870 ])dnl
2871 dnl ---------------------------------------------------------------------------
2872 dnl Use AC_VERBOSE w/o the warnings
2873 AC_DEFUN([CF_VERBOSE],
2874 [test -n "$verbose" && echo "   $1" 1>&AC_FD_MSG
2875 ])dnl
2876 dnl ---------------------------------------------------------------------------
2877 dnl Wrapper for AC_ARG_WITH to ensure that user supplies a pathname, not just
2878 dnl defaulting to yes/no.
2879 dnl
2880 dnl $1 = option name
2881 dnl $2 = help-text
2882 dnl $3 = environment variable to set
2883 dnl $4 = default value, shown in the help-message, must be a constant
2884 dnl $5 = default value, if it's an expression & cannot be in the help-message
2885 dnl
2886 AC_DEFUN([CF_WITH_PATH],
2887 [AC_ARG_WITH($1,[$2 ](default: ifelse($4,,empty,$4)),,
2888 ifelse($4,,[withval="${$3}"],[withval="${$3-ifelse($5,,$4,$5)}"]))dnl
2889 CF_PATH_SYNTAX(withval)
2890 eval $3="$withval"
2891 AC_SUBST($3)dnl
2892 ])dnl
2893 dnl ---------------------------------------------------------------------------
2894 dnl Process an option specifying a list of colon-separated paths.
2895 dnl
2896 dnl $1 = option name
2897 dnl $2 = help-text
2898 dnl $3 = environment variable to set
2899 dnl $4 = default value, shown in the help-message, must be a constant
2900 dnl $5 = default value, if it's an expression & cannot be in the help-message
2901 dnl $6 = flag to tell if we want to define or substitute
2902 dnl
2903 AC_DEFUN([CF_WITH_PATHLIST],[
2904 AC_REQUIRE([CF_PATHSEP])
2905 AC_ARG_WITH($1,[$2 ](default: ifelse($4,,empty,$4)),,
2906 ifelse($4,,[withval=${$3}],[withval=${$3-ifelse($5,,$4,$5)}]))dnl
2907
2908 IFS="${IFS=     }"; ac_save_ifs="$IFS"; IFS="${PATHSEP}"
2909 cf_dst_path=
2910 for cf_src_path in $withval
2911 do
2912   CF_PATH_SYNTAX(cf_src_path)
2913   test -n "$cf_dst_path" && cf_dst_path="${cf_dst_path}:"
2914   cf_dst_path="${cf_dst_path}${cf_src_path}"
2915 done
2916 IFS="$ac_save_ifs"
2917
2918 ifelse($6,define,[
2919 # Strip single quotes from the value, e.g., when it was supplied as a literal
2920 # for $4 or $5.
2921 case $cf_dst_path in #(vi
2922 \'*)
2923   cf_dst_path=`echo $cf_dst_path |sed -e s/\'// -e s/\'\$//`
2924   ;;
2925 esac
2926 cf_dst_path=`echo "$cf_dst_path" | sed -e 's/\\\\/\\\\\\\\/g'`
2927 ])
2928
2929 eval '$3="$cf_dst_path"'
2930 AC_SUBST($3)dnl
2931
2932 ])dnl