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