]> ncurses.scripts.mit.edu Git - ncurses.git/blob - aclocal.m4
ncurses 4.2
[ncurses.git] / aclocal.m4
1 dnl***************************************************************************
2 dnl Copyright (c) 1998 Free Software Foundation, Inc.                        *
3 dnl                                                                          *
4 dnl Permission is hereby granted, free of charge, to any person obtaining a  *
5 dnl copy of this software and associated documentation files (the            *
6 dnl "Software"), to deal in the Software without restriction, including      *
7 dnl without limitation the rights to use, copy, modify, merge, publish,      *
8 dnl distribute, distribute with modifications, sublicense, and/or sell       *
9 dnl copies of the Software, and to permit persons to whom the Software is    *
10 dnl furnished to do so, subject to the following conditions:                 *
11 dnl                                                                          *
12 dnl The above copyright notice and this permission notice shall be included  *
13 dnl in all copies or substantial portions of the Software.                   *
14 dnl                                                                          *
15 dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16 dnl OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17 dnl MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18 dnl IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19 dnl DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20 dnl OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21 dnl THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22 dnl                                                                          *
23 dnl Except as contained in this notice, the name(s) of the above copyright   *
24 dnl holders shall not be used in advertising or otherwise to promote the     *
25 dnl sale, use or other dealings in this Software without prior written       *
26 dnl authorization.                                                           *
27 dnl***************************************************************************
28 dnl
29 dnl Author: Thomas E. Dickey <dickey@clark.net> 1996,1997,1998
30 dnl
31 dnl $Id: aclocal.m4,v 1.121 1998/02/11 12:13:40 tom Exp $
32 dnl Macros used in NCURSES auto-configuration script.
33 dnl
34 dnl ---------------------------------------------------------------------------
35 dnl ---------------------------------------------------------------------------
36 dnl Construct the list of include-options for the C programs in the Ada95
37 dnl binding.
38 AC_DEFUN([CF_ADA_INCLUDE_DIRS],
39 [
40 ACPPFLAGS="$ACPPFLAGS -I. -I../../include"
41 if test "$srcdir" != "."; then
42         ACPPFLAGS="$ACPPFLAGS -I\$(srcdir)/../../include"
43 fi
44 if test -z "$GCC"; then
45         ACPPFLAGS="$ACPPFLAGS -I\$(includedir)"
46 elif test "$includedir" != "/usr/include"; then
47         if test "$includedir" = '${prefix}/include' ; then
48                 if test $prefix != /usr ; then
49                         ACPPFLAGS="$ACPPFLAGS -I\$(includedir)"
50                 fi
51         else
52                 ACPPFLAGS="$ACPPFLAGS -I\$(includedir)"
53         fi
54 fi
55 AC_SUBST(ACPPFLAGS)
56 ])dnl
57 dnl ---------------------------------------------------------------------------
58 dnl Test if 'bool' is a builtin type in the configured C++ compiler.  Some
59 dnl older compilers (e.g., gcc 2.5.8) don't support 'bool' directly; gcc
60 dnl 2.6.3 does, in anticipation of the ANSI C++ standard.
61 dnl
62 dnl Treat the configuration-variable specially here, since we're directly
63 dnl substituting its value (i.e., 1/0).
64 AC_DEFUN([CF_BOOL_DECL],
65 [
66 AC_MSG_CHECKING([for builtin c++ bool type])
67 AC_CACHE_VAL(cf_cv_builtin_bool,[
68         AC_TRY_COMPILE([],[bool x = false],
69                 [cf_cv_builtin_bool=1],
70                 [cf_cv_builtin_bool=0])
71         ])
72 if test $cf_cv_builtin_bool = 1
73 then    AC_MSG_RESULT(yes)
74 else    AC_MSG_RESULT(no)
75 fi
76 ])dnl
77 dnl ---------------------------------------------------------------------------
78 dnl Test for the size of 'bool' in the configured C++ compiler (e.g., a type).
79 dnl Don't bother looking for bool.h, since it's been deprecated.
80 AC_DEFUN([CF_BOOL_SIZE],
81 [
82 AC_MSG_CHECKING([for size of c++ bool])
83 AC_CACHE_VAL(cf_cv_type_of_bool,[
84         rm -f cf_test.out
85         AC_TRY_RUN([
86 #include <stdlib.h>
87 #include <stdio.h>
88 #if HAVE_BUILTIN_H
89 #include <builtin.h>
90 #endif
91 main()
92 {
93         FILE *fp = fopen("cf_test.out", "w");
94         if (fp != 0) {
95                 bool x = true;
96                 if ((-x) >= 0)
97                         fputs("unsigned ", fp);
98                 if (sizeof(x) == sizeof(int))       fputs("int",  fp);
99                 else if (sizeof(x) == sizeof(char)) fputs("char", fp);
100                 else if (sizeof(x) == sizeof(short))fputs("short",fp);
101                 else if (sizeof(x) == sizeof(long)) fputs("long", fp);
102                 fclose(fp);
103         }
104         exit(0);
105 }
106                 ],
107                 [cf_cv_type_of_bool=`cat cf_test.out`],
108                 [cf_cv_type_of_bool=unknown],
109                 [cf_cv_type_of_bool=unknown])
110         ])
111         rm -f cf_test.out
112 AC_MSG_RESULT($cf_cv_type_of_bool)
113 if test "$cf_cv_type_of_bool" = unknown ; then
114         AC_MSG_WARN(Assuming unsigned for type of bool)
115         cf_cv_type_of_bool=unsigned
116 fi
117 ])dnl
118 dnl ---------------------------------------------------------------------------
119 dnl Determine the default configuration into which we'll install ncurses.  This
120 dnl can be overridden by the user's command-line options.  There's two items to
121 dnl look for:
122 dnl     1. the prefix (e.g., /usr)
123 dnl     2. the header files (e.g., /usr/include/ncurses)
124 dnl We'll look for a previous installation of ncurses and use the same defaults.
125 dnl
126 dnl We don't use AC_PREFIX_DEFAULT, because it gets evaluated too soon, and
127 dnl we don't use AC_PREFIX_PROGRAM, because we cannot distinguish ncurses's
128 dnl programs from a vendor's.
129 AC_DEFUN([CF_CFG_DEFAULTS],
130 [
131 AC_MSG_CHECKING(for prefix)
132 if test "x$prefix" = "xNONE" ; then
133         case "$cf_cv_system_name" in
134                 # non-vendor systems don't have a conflict
135         openbsd*|netbsd*|freebsd*|linux*)
136                 prefix=/usr
137                 ;;
138         *)      prefix=$ac_default_prefix
139                 ;;
140         esac
141 fi
142 AC_MSG_RESULT($prefix)
143
144 if test "x$prefix" = "xNONE" ; then
145 AC_MSG_CHECKING(for default include-directory)
146 test -n "$verbose" && echo 1>&AC_FD_MSG
147 for cf_symbol in \
148         $includedir \
149         $includedir/ncurses \
150         $prefix/include \
151         $prefix/include/ncurses \
152         /usr/local/include \
153         /usr/local/include/ncurses \
154         /usr/include \
155         /usr/include/ncurses
156 do
157         cf_dir=`eval echo $cf_symbol`
158         if test -f $cf_dir/curses.h ; then
159         if ( fgrep NCURSES_VERSION $cf_dir/curses.h 2>&1 >/dev/null ) ; then
160                 includedir="$cf_symbol"
161                 test -n "$verbose"  && echo $ac_n "     found " 1>&AC_FD_MSG
162                 break
163         fi
164         fi
165         test -n "$verbose"  && echo "   tested $cf_dir" 1>&AC_FD_MSG
166 done
167 AC_MSG_RESULT($includedir)
168 fi
169 ])dnl
170 dnl ---------------------------------------------------------------------------
171 dnl Check for data that is usually declared in <stdio.h> or <errno.h>
172 dnl $1 = the name to check
173 AC_DEFUN([CF_CHECK_ERRNO],
174 [
175 AC_MSG_CHECKING([declaration of $1])
176 AC_CACHE_VAL(cf_cv_dcl_$1,[
177     AC_TRY_COMPILE([
178 #include <stdio.h>
179 #include <sys/types.h>
180 #include <errno.h> ],
181     [long x = (long) $1],
182     [eval 'cf_cv_dcl_'$1'=yes'],
183     [eval 'cf_cv_dcl_'$1'=no]')])
184 eval 'cf_result=$cf_cv_dcl_'$1
185 AC_MSG_RESULT($cf_result)
186
187 # It's possible (for near-UNIX clones) that the data doesn't exist
188 AC_CACHE_VAL(cf_cv_have_$1,[
189 if test $cf_result = no ; then
190     eval 'cf_result=DECL_'$1
191     CF_UPPER(cf_result,$cf_result)
192     AC_DEFINE_UNQUOTED($cf_result)
193     AC_MSG_CHECKING([existence of $1])
194         AC_TRY_LINK([
195 #undef $1
196 extern long $1;
197 ],
198             [$1 = 2],
199             [eval 'cf_cv_have_'$1'=yes'],
200             [eval 'cf_cv_have_'$1'=no'])
201         eval 'cf_result=$cf_cv_have_'$1
202         AC_MSG_RESULT($cf_result)
203 else
204     eval 'cf_cv_have_'$1'=yes'
205 fi
206 ])
207 eval 'cf_result=HAVE_'$1
208 CF_UPPER(cf_result,$cf_result)
209 eval 'test $cf_cv_have_'$1' = yes && AC_DEFINE_UNQUOTED($cf_result)'
210 ])dnl
211 dnl ---------------------------------------------------------------------------
212 dnl Check if the terminal-capability database functions are available.  If not,
213 dnl ncurses has a much-reduced version.
214 AC_DEFUN([CF_CGETENT],[
215 AC_MSG_CHECKING(for terminal-capability database functions)
216 AC_CACHE_VAL(cf_cv_cgetent,[
217 AC_TRY_LINK([
218 #include <stdlib.h>],[
219         char temp[128];
220         char *buf = temp;
221         char *db_array = temp;
222         cgetent(&buf, /* int *, */ &db_array, "vt100");
223         cgetcap(buf, "tc", '=');
224         cgetmatch(buf, "tc");
225         ],
226         [cf_cv_cgetent=yes],
227         [cf_cv_cgetent=no])
228 ])
229 AC_MSG_RESULT($cf_cv_cgetent)
230 test $cf_cv_cgetent = yes && AC_DEFINE(HAVE_BSD_CGETENT)
231 ])dnl
232 dnl ---------------------------------------------------------------------------
233 dnl Check if we're accidentally using a cache from a different machine.
234 dnl Derive the system name, as a check for reusing the autoconf cache.
235 dnl
236 dnl If we've packaged config.guess and config.sub, run that (since it does a
237 dnl better job than uname). 
238 AC_DEFUN([CF_CHECK_CACHE],
239 [
240 if test -f $srcdir/config.guess ; then
241         AC_CANONICAL_HOST
242         system_name="$host_os"
243 else
244         system_name="`(uname -s -r) 2>/dev/null`"
245         if test -z "$system_name" ; then
246                 system_name="`(hostname) 2>/dev/null`"
247         fi
248 fi
249 test -n "$system_name" && AC_DEFINE_UNQUOTED(SYSTEM_NAME,"$system_name")
250 AC_CACHE_VAL(cf_cv_system_name,[cf_cv_system_name="$system_name"])
251
252 test -z "$system_name" && system_name="$cf_cv_system_name"
253 test -n "$cf_cv_system_name" && AC_MSG_RESULT("Configuring for $cf_cv_system_name")
254
255 if test ".$system_name" != ".$cf_cv_system_name" ; then
256         AC_MSG_RESULT(Cached system name ($system_name) does not agree with actual ($cf_cv_system_name))
257         AC_ERROR("Please remove config.cache and try again.")
258 fi
259 ])dnl
260 dnl ---------------------------------------------------------------------------
261 dnl If we're trying to use g++, test if libg++ is installed (a rather common
262 dnl problem :-).  If we have the compiler but no library, we'll be able to
263 dnl configure, but won't be able to build the c++ demo program.
264 AC_DEFUN([CF_CXX_LIBRARY],
265 [
266 cf_cxx_library=unknown
267 if test $ac_cv_prog_gxx = yes; then
268         AC_MSG_CHECKING([for libg++])
269         cf_save="$LIBS"
270         LIBS="$LIBS -lg++ -lm"
271         AC_TRY_LINK([
272 #include <builtin.h>
273         ],
274         [float foo=abs(1.0)],
275         [cf_cxx_library=yes
276          CXXLIBS="$CXXLIBS -lg++ -lm"],
277         [cf_cxx_library=no])
278         LIBS="$cf_save"
279         AC_MSG_RESULT($cf_cxx_library)
280 fi
281 ])dnl
282 dnl ---------------------------------------------------------------------------
283 AC_DEFUN([CF_DIRS_TO_MAKE],
284 [
285 DIRS_TO_MAKE="lib"
286 for cf_item in $cf_list_models
287 do
288         CF_OBJ_SUBDIR($cf_item,cf_subdir)
289         DIRS_TO_MAKE="$DIRS_TO_MAKE $cf_subdir"
290 done
291 for cf_dir in $DIRS_TO_MAKE
292 do
293         test ! -d $cf_dir && mkdir $cf_dir
294 done
295 AC_SUBST(DIRS_TO_MAKE)
296 ])dnl
297 dnl ---------------------------------------------------------------------------
298 dnl Check if 'errno' is declared in <errno.h>
299 AC_DEFUN([CF_ERRNO],
300 [
301 CF_CHECK_ERRNO(errno)
302 ])dnl
303 dnl ---------------------------------------------------------------------------
304 dnl Test for availability of useful gcc __attribute__ directives to quiet
305 dnl compiler warnings.  Though useful, not all are supported -- and contrary
306 dnl to documentation, unrecognized directives cause older compilers to barf.
307 AC_DEFUN([CF_GCC_ATTRIBUTES],
308 [
309 if test -n "$GCC"
310 then
311 cat > conftest.i <<EOF
312 #ifndef GCC_PRINTF
313 #define GCC_PRINTF 0
314 #endif
315 #ifndef GCC_SCANF
316 #define GCC_SCANF 0
317 #endif
318 #ifndef GCC_NORETURN
319 #define GCC_NORETURN /* nothing */
320 #endif
321 #ifndef GCC_UNUSED
322 #define GCC_UNUSED /* nothing */
323 #endif
324 EOF
325 if test -n "$GCC"
326 then
327         AC_CHECKING([for gcc __attribute__ directives])
328         changequote(,)dnl
329 cat > conftest.$ac_ext <<EOF
330 #line __oline__ "configure"
331 #include "confdefs.h"
332 #include "conftest.h"
333 #include "conftest.i"
334 #if     GCC_PRINTF
335 #define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
336 #else
337 #define GCC_PRINTFLIKE(fmt,var) /*nothing*/
338 #endif
339 #if     GCC_SCANF
340 #define GCC_SCANFLIKE(fmt,var)  __attribute__((format(scanf,fmt,var)))
341 #else
342 #define GCC_SCANFLIKE(fmt,var)  /*nothing*/
343 #endif
344 extern void wow(char *,...) GCC_SCANFLIKE(1,2);
345 extern void oops(char *,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN;
346 extern void foo(void) GCC_NORETURN;
347 int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) { return 0; }
348 EOF
349         changequote([,])dnl
350         for cf_attribute in scanf printf unused noreturn
351         do
352                 CF_UPPER(CF_ATTRIBUTE,$cf_attribute)
353                 cf_directive="__attribute__(($cf_attribute))"
354                 echo "checking for gcc $cf_directive" 1>&AC_FD_CC
355                 case $cf_attribute in
356                 scanf|printf)
357                 cat >conftest.h <<EOF
358 #define GCC_$CF_ATTRIBUTE 1
359 EOF
360                         ;;
361                 *)
362                 cat >conftest.h <<EOF
363 #define GCC_$CF_ATTRIBUTE $cf_directive
364 EOF
365                         ;;
366                 esac
367                 if AC_TRY_EVAL(ac_compile); then
368                         test -n "$verbose" && AC_MSG_RESULT(... $cf_attribute)
369                         cat conftest.h >>confdefs.h
370 #               else
371 #                       sed -e 's/__attr.*/\/*nothing*\//' conftest.h >>confdefs.h
372                 fi
373         done
374 else
375         fgrep define conftest.i >>confdefs.h
376 fi
377 rm -rf conftest*
378 fi
379 ])dnl
380 dnl ---------------------------------------------------------------------------
381 dnl Check if the compiler supports useful warning options.  There's a few that
382 dnl we don't use, simply because they're too noisy:
383 dnl
384 dnl     -Wconversion (useful in older versions of gcc, but not in gcc 2.7.x)
385 dnl     -Wredundant-decls (system headers make this too noisy)
386 dnl     -Wtraditional (combines too many unrelated messages, only a few useful)
387 dnl     -Wwrite-strings (too noisy, but should review occasionally)
388 dnl     -pedantic
389 dnl
390 AC_DEFUN([CF_GCC_WARNINGS],
391 [
392 if test -n "$GCC"
393 then
394         changequote(,)dnl
395         cat > conftest.$ac_ext <<EOF
396 #line __oline__ "configure"
397 int main(int argc, char *argv[]) { return argv[argc-1] == 0; }
398 EOF
399         changequote([,])dnl
400         AC_CHECKING([for gcc warning options])
401         cf_save_CFLAGS="$CFLAGS"
402         EXTRA_CFLAGS="-W -Wall"
403         cf_warn_CONST=""
404         test "$with_ext_const" = yes && cf_warn_CONST="Wwrite-strings"
405         for cf_opt in \
406                 Wbad-function-cast \
407                 Wcast-align \
408                 Wcast-qual \
409                 Winline \
410                 Wmissing-declarations \
411                 Wmissing-prototypes \
412                 Wnested-externs \
413                 Wpointer-arith \
414                 Wshadow \
415                 Wstrict-prototypes $cf_warn_CONST
416         do
417                 CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
418                 if AC_TRY_EVAL(ac_compile); then
419                         test -n "$verbose" && AC_MSG_RESULT(... -$cf_opt)
420                         EXTRA_CFLAGS="$EXTRA_CFLAGS -$cf_opt"
421                         test "$cf_opt" = Wcast-qual && EXTRA_CFLAGS="$EXTRA_CFLAGS -DXTSTRINGDEFINES"
422                 fi
423         done
424         rm -f conftest*
425         CFLAGS="$cf_save_CFLAGS"
426 fi
427 AC_SUBST(EXTRA_CFLAGS)
428 ])dnl
429 dnl ---------------------------------------------------------------------------
430 dnl Verify Version of GNAT.
431 AC_DEFUN([CF_GNAT_VERSION],
432 [
433 changequote(<<, >>)dnl
434 cf_cv_gnat_version=`$cf_ada_make -v 2>&1 | grep '[0-9].[0-9][0-9]*' |\
435   sed -e 's/[^0-9 \.]//g' | $AWK '{print $<<1>>;}'`
436 case $cf_cv_gnat_version in
437   3.[1-9]*|[4-9].*)
438     ac_cv_prog_gnat_correct=yes
439     ;;
440   *) echo Unsupported GNAT version $cf_cv_gnat_version. Required is 3.10 or better. Disabling Ada95 binding.
441      ac_cv_prog_gnat_correct=no
442      ;;
443 esac
444 case $cf_cv_gnat_version in
445   3.1*|[4-9].*)
446       cf_compile_generics=generics
447       ;;
448   *)  cf_compile_generics=
449       ;;
450 esac
451 changequote([, ])dnl
452 ])
453 dnl ---------------------------------------------------------------------------
454 dnl Insert text into the help-message, for readability, from AC_ARG_WITH.
455 AC_DEFUN([CF_HELP_MESSAGE],
456 [AC_DIVERT_HELP([$1])dnl
457 ])dnl
458 dnl ---------------------------------------------------------------------------
459 dnl Construct the list of include-options according to whether we're building
460 dnl in the source directory or using '--srcdir=DIR' option.  If we're building
461 dnl with gcc, don't append the includedir if it happens to be /usr/include,
462 dnl since that usually breaks gcc's shadow-includes.
463 AC_DEFUN([CF_INCLUDE_DIRS],
464 [
465 CPPFLAGS="$CPPFLAGS -I. -I../include"
466 if test "$srcdir" != "."; then
467         CPPFLAGS="$CPPFLAGS -I\$(srcdir)/../include"
468 fi
469 if test -z "$GCC"; then
470         CPPFLAGS="$CPPFLAGS -I\$(includedir)"
471 elif test "$includedir" != "/usr/include"; then
472         if test "$includedir" = '${prefix}/include' ; then
473                 if test $prefix != /usr ; then
474                         CPPFLAGS="$CPPFLAGS -I\$(includedir)"
475                 fi
476         else
477                 CPPFLAGS="$CPPFLAGS -I\$(includedir)"
478         fi
479 fi
480 AC_SUBST(CPPFLAGS)
481 ])dnl
482 dnl ---------------------------------------------------------------------------
483 dnl Check if we have either a function or macro for 'isascii()'.
484 AC_DEFUN([CF_ISASCII],
485 [
486 AC_MSG_CHECKING(for isascii)
487 AC_CACHE_VAL(cf_cv_have_isascii,[
488         AC_TRY_LINK([#include <ctype.h>],[int x = isascii(' ')],
489         [cf_cv_have_isascii=yes],
490         [cf_cv_have_isascii=no])
491 ])dnl
492 AC_MSG_RESULT($cf_cv_have_isascii)
493 test $cf_cv_have_isascii = yes && AC_DEFINE(HAVE_ISASCII)
494 ])dnl
495 dnl ---------------------------------------------------------------------------
496 dnl Append definitions and rules for the given models to the subdirectory
497 dnl Makefiles, and the recursion rule for the top-level Makefile.  If the
498 dnl subdirectory is a library-source directory, modify the LIBRARIES list in
499 dnl the corresponding makefile to list the models that we'll generate.
500 dnl
501 dnl For shared libraries, make a list of symbolic links to construct when
502 dnl generating each library.  The convention used for Linux is the simplest
503 dnl one:
504 dnl     lib<name>.so    ->
505 dnl     lib<name>.so.<major>    ->
506 dnl     lib<name>.so.<maj>.<minor>
507 AC_DEFUN([CF_LIB_RULES],
508 [
509 CF_LIB_PREFIX(cf_prefix)
510 AC_REQUIRE([CF_SUBST_NCURSES_VERSION])
511 for cf_dir in $SRC_SUBDIRS
512 do
513         if test -f $srcdir/$cf_dir/modules; then
514
515                 cf_libs_to_make=
516                 for cf_item in $CF_LIST_MODELS
517                 do
518                         CF_LIB_SUFFIX($cf_item,cf_suffix)
519                         cf_libs_to_make="$cf_libs_to_make ../lib/${cf_prefix}${cf_dir}${cf_suffix}"
520                 done
521
522                 if test $cf_dir = ncurses ; then
523                         case "$LIB_SUBSETS" in
524                         termlib+*) #(vi
525                                 ;;
526                         *) #(vi
527                                 cf_item=`echo $cf_libs_to_make |sed -e s/$LIB_NAME/$TINFO_NAME/g`
528                                 cf_libs_to_make="$cf_libs_to_make $cf_item"
529                                 ;;
530                         esac
531                 fi
532
533                 sed -e "s@\@LIBS_TO_MAKE\@@$cf_libs_to_make@" \
534                         $cf_dir/Makefile >$cf_dir/Makefile.out
535                 mv $cf_dir/Makefile.out $cf_dir/Makefile
536
537                 $AWK -f $srcdir/mk-0th.awk \
538                         name=$cf_dir \
539                         $srcdir/$cf_dir/modules >>$cf_dir/Makefile
540
541                 for cf_item in $CF_LIST_MODELS
542                 do
543                         echo 'Appending rules for '$cf_item' model ('$cf_dir')'
544                         CF_UPPER(CF_ITEM,$cf_item)
545                         CF_LIB_SUFFIX($cf_item,cf_suffix)
546                         CF_OBJ_SUBDIR($cf_item,cf_subdir)
547
548                         # These dependencies really are for development, not
549                         # builds, but they are useful in porting, too.
550                         cf_depend="../include/ncurses_cfg.h"
551                         if test "$srcdir" = "."; then
552                                 cf_reldir="."
553                         else
554                                 cf_reldir="\$(srcdir)"
555                         fi
556
557                         if test -f $srcdir/$cf_dir/$cf_dir.priv.h; then
558                                 cf_depend="$cf_depend $cf_reldir/$cf_dir.priv.h"
559                         elif test -f $srcdir/$cf_dir/curses.priv.h; then
560                                 cf_depend="$cf_depend $cf_reldir/curses.priv.h"
561                         fi
562
563                         for cf_subset in $LIB_SUBSETS
564                         do
565                         $AWK -f $srcdir/mk-1st.awk \
566                                 name=$cf_dir \
567                                 MODEL=$CF_ITEM \
568                                 model=$cf_subdir \
569                                 prefix=$cf_prefix \
570                                 suffix=$cf_suffix \
571                                 subset=$cf_subset \
572                                 DoLinks=$cf_cv_do_symlinks \
573                                 rmSoLocs=$cf_cv_rm_so_locs \
574                                 ldconfig="$LDCONFIG" \
575                                 overwrite=$WITH_OVERWRITE \
576                                 depend="$cf_depend" \
577                                 target="$target" \
578                                 $srcdir/$cf_dir/modules >>$cf_dir/Makefile
579                         test $cf_dir = ncurses && WITH_OVERWRITE=no
580                         $AWK -f $srcdir/mk-2nd.awk \
581                                 name=$cf_dir \
582                                 MODEL=$CF_ITEM \
583                                 model=$cf_subdir \
584                                 subset=$cf_subset \
585                                 srcdir=$srcdir \
586                                 echo=$WITH_ECHO \
587                                 $srcdir/$cf_dir/modules >>$cf_dir/Makefile
588                         done
589                 done
590         fi
591
592         echo '  cd '$cf_dir' && $(MAKE) $(CF_MFLAGS) [$]@' >>Makefile
593 done
594
595 for cf_dir in $SRC_SUBDIRS
596 do
597         if test -f $cf_dir/Makefile ; then
598                 case "$cf_dir" in
599                 Ada95) #(vi
600                         echo 'install.libs \' >> Makefile
601                         echo 'uninstall.libs ::' >> Makefile
602                         echo '  cd '$cf_dir' && $(MAKE) $(CF_MFLAGS) [$]@' >> Makefile
603                         ;;
604                 esac
605         fi
606
607         if test -f $srcdir/$cf_dir/modules; then
608                 echo >> Makefile
609                 if test -f $srcdir/$cf_dir/headers; then
610 cat >> Makefile <<CF_EOF
611 install.includes \\
612 uninstall.includes \\
613 CF_EOF
614                 fi
615 if test "$cf_dir" != "c++" ; then
616 echo 'lint \' >> Makefile
617 fi
618 cat >> Makefile <<CF_EOF
619 lintlib \\
620 install.libs \\
621 uninstall.libs \\
622 install.$cf_dir \\
623 uninstall.$cf_dir ::
624         cd $cf_dir && \$(MAKE) \$(CF_MFLAGS) \[$]@
625 CF_EOF
626         elif test -f $srcdir/$cf_dir/headers; then
627 cat >> Makefile <<CF_EOF
628
629 install.libs \\
630 uninstall.libs \\
631 install.includes \\
632 uninstall.includes ::
633         cd $cf_dir && \$(MAKE) \$(CF_MFLAGS) \[$]@
634 CF_EOF
635 fi
636 done
637
638 cat >> Makefile <<CF_EOF
639
640 install.data ::
641         cd misc && \$(MAKE) \$(CF_MFLAGS) \[$]@
642
643 install.man ::
644         cd man && \$(MAKE) \$(CF_MFLAGS) \[$]@
645
646 distclean ::
647         rm -f config.cache config.log config.status Makefile include/ncurses_cfg.h
648         rm -f headers.sh headers.sed
649         rm -rf \$(DIRS_TO_MAKE)
650 CF_EOF
651
652 dnl If we're installing into a subdirectory of /usr/include, etc., we should
653 dnl prepend the subdirectory's name to the "#include" paths.  It won't hurt
654 dnl anything, and will make it more standardized.  It's awkward to decide this
655 dnl at configuration because of quoting, so we'll simply make all headers
656 dnl installed via a script that can do the right thing.
657
658 rm -f headers.sed headers.sh
659
660 dnl ( generating this script makes the makefiles a little tidier :-)
661 echo creating headers.sh
662 cat >headers.sh <<CF_EOF
663 #! /bin/sh
664 # This shell script is generated by the 'configure' script.  It is invoked in a
665 # subdirectory of the build tree.  It generates a sed-script in the parent
666 # directory that is used to adjust includes for header files that reside in a
667 # subdirectory of /usr/include, etc.
668 PRG=""
669 while test \[$]# != 3
670 do
671 PRG="\$PRG \[$]1"; shift
672 done
673 DST=\[$]1
674 REF=\[$]2
675 SRC=\[$]3
676 echo installing \$SRC in \$DST
677 case \$DST in
678 /*/include/*)
679         TMP=\${TMPDIR-/tmp}/\`basename \$SRC\`
680         if test ! -f ../headers.sed ; then
681                 END=\`basename \$DST\`
682                 for i in \`cat \$REF/../*/headers |fgrep -v "#"\`
683                 do
684                         NAME=\`basename \$i\`
685                         echo "s/<\$NAME>/<\$END\/\$NAME>/" >> ../headers.sed
686                 done
687         fi
688         rm -f \$TMP
689         sed -f ../headers.sed \$SRC > \$TMP
690         eval \$PRG \$TMP \$DST
691         rm -f \$TMP
692         ;;
693 *)
694         eval \$PRG \$SRC \$DST
695         ;;
696 esac
697 CF_EOF
698
699 chmod 0755 headers.sh
700
701 for cf_dir in $SRC_SUBDIRS
702 do
703         if test -f $srcdir/$cf_dir/headers; then
704         cat >>$cf_dir/Makefile <<CF_EOF
705 \$(INSTALL_PREFIX)\$(includedir) :
706         \$(srcdir)/../mkinstalldirs \[$]@
707
708 install \\
709 install.libs \\
710 install.includes :: \$(INSTALL_PREFIX)\$(includedir) \\
711 CF_EOF
712                 j=""
713                 for i in `cat $srcdir/$cf_dir/headers |fgrep -v "#"`
714                 do
715                         test -n "$j" && echo "          $j \\" >>$cf_dir/Makefile
716                         j=$i
717                 done
718                 echo "          $j" >>$cf_dir/Makefile
719                 for i in `cat $srcdir/$cf_dir/headers |fgrep -v "#"`
720                 do
721                         echo "  @ (cd \$(INSTALL_PREFIX)\$(includedir) && rm -f `basename $i`) ; ../headers.sh \$(INSTALL_DATA) \$(INSTALL_PREFIX)\$(includedir) \$(srcdir) $i" >>$cf_dir/Makefile
722                         test $i = curses.h && echo "    @ (cd \$(INSTALL_PREFIX)\$(includedir) && rm -f ncurses.h && \$(LN_S) curses.h ncurses.h)" >>$cf_dir/Makefile
723                 done
724
725         cat >>$cf_dir/Makefile <<CF_EOF
726
727 uninstall \\
728 uninstall.libs \\
729 uninstall.includes ::
730 CF_EOF
731                 for i in `cat $srcdir/$cf_dir/headers |fgrep -v "#"`
732                 do
733                         i=`basename $i`
734                         echo "  -@ (cd \$(INSTALL_PREFIX)\$(includedir) && rm -f $i)" >>$cf_dir/Makefile
735                         test $i = curses.h && echo "    -@ (cd \$(INSTALL_PREFIX)\$(includedir) && rm -f ncurses.h)" >>$cf_dir/Makefile
736                 done
737         fi
738 done
739
740 ])dnl
741 dnl ---------------------------------------------------------------------------
742 dnl Compute the library-prefix for the given host system
743 dnl $1 = variable to set
744 AC_DEFUN([CF_LIB_PREFIX],
745 [
746         case $cf_cv_system_name in
747         os2)    $1=''     ;;
748         *)      $1='lib'  ;;
749         esac
750 ])dnl
751 dnl ---------------------------------------------------------------------------
752 dnl Compute the library-suffix from the given model name
753 dnl $1 = model name
754 dnl $2 = variable to set
755 AC_DEFUN([CF_LIB_SUFFIX],
756 [
757         AC_REQUIRE([CF_SUBST_NCURSES_VERSION])
758         case $1 in
759         normal)  $2='.a'   ;;
760         debug)   $2='_g.a' ;;
761         profile) $2='_p.a' ;;
762         shared)
763                 case $cf_cv_system_name in
764                 openbsd*|netbsd*|freebsd*)
765                         $2='.so.$(REL_VERSION)' ;;
766                 hpux*)  $2='.sl'  ;;
767                 *)      $2='.so'  ;;
768                 esac
769         esac
770 ])dnl
771 dnl ---------------------------------------------------------------------------
772 dnl Compute the string to append to -library from the given model name
773 AC_DEFUN([CF_LIB_TYPE],
774 [
775         case $1 in
776         normal)  $2=''   ;;
777         debug)   $2='_g' ;;
778         profile) $2='_p' ;;
779         shared)  $2=''   ;;
780         esac
781 ])dnl
782 dnl ---------------------------------------------------------------------------
783 dnl Some systems have a non-ANSI linker that doesn't pull in modules that have
784 dnl only data (i.e., no functions), for example NeXT.  On those systems we'll
785 dnl have to provide wrappers for global tables to ensure they're linked
786 dnl properly.
787 AC_DEFUN([CF_LINK_DATAONLY],
788 [
789 AC_MSG_CHECKING([if data-only library module links])
790 AC_CACHE_VAL(cf_cv_link_dataonly,[
791         rm -f conftest.a
792         changequote(,)dnl
793         cat >conftest.$ac_ext <<EOF
794 #line __oline__ "configure"
795 int     testdata[3] = { 123, 456, 789 };
796 EOF
797         changequote([,])dnl
798         if AC_TRY_EVAL(ac_compile) ; then
799                 mv conftest.o data.o && \
800                 ( $AR $AR_OPTS conftest.a data.o ) 2>&5 1>/dev/null
801         fi
802         rm -f conftest.$ac_ext data.o
803         changequote(,)dnl
804         cat >conftest.$ac_ext <<EOF
805 #line __oline__ "configure"
806 int     testfunc()
807 {
808 #if defined(NeXT)
809         exit(1);        /* I'm told this linker is broken */
810 #else
811         extern int testdata[3];
812         return testdata[0] == 123
813            &&  testdata[1] == 456
814            &&  testdata[2] == 789;
815 #endif
816 }
817 EOF
818         changequote([,])dnl
819         if AC_TRY_EVAL(ac_compile); then
820                 mv conftest.o func.o && \
821                 ( $AR $AR_OPTS conftest.a func.o ) 2>&5 1>/dev/null
822         fi
823         rm -f conftest.$ac_ext func.o
824         ( eval $ac_cv_prog_RANLIB conftest.a ) 2>&5 >/dev/null
825         cf_saveLIBS="$LIBS"
826         LIBS="conftest.a $LIBS"
827         AC_TRY_RUN([
828         int main()
829         {
830                 extern int testfunc();
831                 exit (!testfunc());
832         }
833         ],
834         [cf_cv_link_dataonly=yes],
835         [cf_cv_link_dataonly=no],
836         [cf_cv_link_dataonly=unknown])
837         LIBS="$cf_saveLIBS"
838         ])
839 AC_MSG_RESULT($cf_cv_link_dataonly)
840 test $cf_cv_link_dataonly = no && AC_DEFINE(BROKEN_LINKER)
841 ])dnl
842 dnl ---------------------------------------------------------------------------
843 dnl Some 'make' programs support $(MAKEFLAGS), some $(MFLAGS), to pass 'make'
844 dnl options to lower-levels.  It's very useful for "make -n" -- if we have it.
845 dnl (GNU 'make' does both :-)
846 AC_DEFUN([CF_MAKEFLAGS],
847 [
848 AC_MSG_CHECKING([for makeflags variable])
849 AC_CACHE_VAL(cf_cv_makeflags,[
850         cf_cv_makeflags=''
851         for cf_option in '$(MFLAGS)' '-$(MAKEFLAGS)'
852         do
853                 cat >cf_makeflags.tmp <<CF_EOF
854 all :
855         echo '.$cf_option'
856 CF_EOF
857                 set cf_result=`${MAKE-make} -f cf_makeflags.tmp 2>/dev/null`
858                 if test "$cf_result" != "."
859                 then
860                         cf_cv_makeflags=$cf_option
861                         break
862                 fi
863         done
864         rm -f cf_makeflags.tmp])
865 AC_MSG_RESULT($cf_cv_makeflags)
866 AC_SUBST(cf_cv_makeflags)
867 ])dnl
868 dnl ---------------------------------------------------------------------------
869 dnl Try to determine if the man-pages on the system are compressed, and if
870 dnl so, what format is used.  Use this information to construct a script that
871 dnl will install man-pages.
872 AC_DEFUN([CF_MAN_PAGES],
873 [AC_MSG_CHECKING(format of man-pages)
874   if test -z "$MANPATH" ; then
875     MANPATH="/usr/man:/usr/share/man"
876   fi
877   # look for the 'date' man-page (it's most likely to be installed!)
878   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
879   cf_form=unknown
880   for cf_dir in $MANPATH; do
881     test -z "$cf_dir" && cf_dir=/usr/man
882     cf_rename=""
883     cf_format=no
884 changequote({{,}})dnl
885     for cf_name in $cf_dir/*/date.[01]* $cf_dir/*/date
886 changequote([,])dnl
887     do
888        cf_test=`echo $cf_name | sed -e 's/*//'`
889        if test "x$cf_test" = "x$cf_name" ; then
890           case "$cf_name" in
891           *.gz) cf_form=gzip;     cf_name=`basename $cf_name .gz`;;
892           *.Z)  cf_form=compress; cf_name=`basename $cf_name .Z`;;
893           *.0)  cf_form=BSDI; cf_format=yes;;
894           *)    cf_form=cat;;
895           esac
896           break
897        fi
898     done
899     if test "$cf_form" != "unknown" ; then
900        break
901     fi
902   done
903   IFS="$ac_save_ifs"
904   if test "$prefix" = "NONE" ; then
905      cf_prefix="$ac_default_prefix"
906   else
907      cf_prefix="$prefix"
908   fi
909
910   # Debian 'man' program?
911   test -f /etc/debian_version && \
912   cf_rename=`cd $srcdir && pwd`/man/man_db.renames
913
914   test ! -d man && mkdir man
915
916   # Construct a sed-script to perform renaming within man-pages
917   if test -n "$cf_rename" ; then
918     $srcdir/man/make_sed.sh $cf_rename >man/edit_man.sed
919   fi
920   if test $cf_format = yes ; then
921     cf_subdir='$mandir/cat'
922   else
923     cf_subdir='$mandir/man'
924   fi
925
926 cat >man/edit_man.sh <<CF_EOF
927 changequote({{,}})dnl
928 #! /bin/sh
929 # this script is generated by the configure-script
930 prefix="$cf_prefix"
931 datadir="$datadir"
932 MKDIRS="`cd $srcdir && pwd`/mkinstalldirs"
933 INSTALL="$INSTALL"
934 INSTALL_DATA="$INSTALL_DATA"
935 TMP=\${TMPDIR-/tmp}/man\$\$
936 trap "rm -f \$TMP" 0 1 2 5 15
937
938 verb=\{{$}}1
939 shift
940
941 mandir=\{{$}}1
942 shift
943
944 for i in \{{$}}*
945 do
946 case \$i in
947 *.[0-9]*)
948         section=\`expr "\$i" : '.*\\.\\([0-9]\\)[xm]*'\`;
949         if test \$verb = installing ; then
950         if test ! -d $cf_subdir\${section} ; then
951                 \$MKDIRS $cf_subdir\$section
952         fi
953         fi
954         source=\`basename \$i\`
955 CF_EOF
956 if test -z "$cf_rename" ; then
957 cat >>man/edit_man.sh <<CF_EOF
958         target=$cf_subdir\${section}/\$source
959         sed -e "s,@DATADIR@,\$datadir," < \$i >\$TMP
960 CF_EOF
961 else
962 cat >>man/edit_man.sh <<CF_EOF
963         target=\`grep "^\$source" $cf_rename | $AWK '{print \{{$}}2}'\`
964         if test -z "\$target" ; then
965                 echo '? missing rename for '\$source
966                 target="\$source"
967         fi
968         target="$cf_subdir\$section/\$target"
969         test \$verb = installing && sed -e "s,@DATADIR@,\$datadir," < \$i | sed -f edit_man.sed >\$TMP
970 CF_EOF
971 fi
972 if test \$verb = installing ; then
973 if test $cf_format = yes ; then
974 cat >>man/edit_man.sh <<CF_EOF
975         nroff -man \$TMP >\$TMP.out
976         mv \$TMP.out \$TMP
977 CF_EOF
978 fi
979 fi
980 case "$cf_form" in
981 compress)
982 cat >>man/edit_man.sh <<CF_EOF
983         if test \$verb = installing ; then
984         if ( compress -f \$TMP )
985         then
986                 mv \$TMP.Z \$TMP
987         fi
988         fi
989         target="\$target.Z"
990 CF_EOF
991   ;;
992 gzip)
993 cat >>man/edit_man.sh <<CF_EOF
994         if test \$verb = installing ; then
995         if ( gzip -f \$TMP )
996         then
997                 mv \$TMP.gz \$TMP
998         fi
999         fi
1000         target="\$target.gz"
1001 CF_EOF
1002   ;;
1003 BSDI)
1004 cat >>man/edit_man.sh <<CF_EOF
1005         # BSDI installs only .0 suffixes in the cat directories
1006         target="\`echo \$target|sed -e 's/\.[1-9]\+.\?/.0/'\`"
1007 CF_EOF
1008   ;;
1009 esac
1010 cat >>man/edit_man.sh <<CF_EOF
1011         echo \$verb \$target
1012         if test \$verb = installing ; then
1013                 \$INSTALL_DATA \$TMP \$target
1014         else
1015                 rm -f \$target
1016         fi
1017         ;;
1018 esac
1019 done 
1020 CF_EOF
1021 changequote([,])dnl
1022 chmod 755 man/edit_man.sh
1023 AC_MSG_RESULT($cf_form)
1024 ])dnl
1025 dnl ---------------------------------------------------------------------------
1026 dnl Compute the object-directory name from the given model name
1027 AC_DEFUN([CF_OBJ_SUBDIR],
1028 [
1029         case $1 in
1030         normal)  $2='objects' ;;
1031         debug)   $2='obj_g' ;;
1032         profile) $2='obj_p' ;;
1033         shared)  $2='obj_s' ;;
1034         esac
1035 ])dnl
1036 dnl ---------------------------------------------------------------------------
1037 dnl Within AC_OUTPUT, check if the given file differs from the target, and
1038 dnl update it if so.  Otherwise, remove the generated file.
1039 dnl
1040 dnl Parameters:
1041 dnl $1 = input, which configure has done substitutions upon
1042 dnl $2 = target file
1043 dnl
1044 AC_DEFUN([CF_OUTPUT_IF_CHANGED],[
1045 if ( cmp -s $1 $2 2>/dev/null )
1046 then
1047         echo "$2 is unchanged"
1048         rm -f $1
1049 else
1050         echo "creating $2"
1051         rm -f $2
1052         mv $1 $2
1053 fi
1054 ])dnl
1055 dnl ---------------------------------------------------------------------------
1056 dnl Force $INSTALL to be an absolute-path.  Otherwise, edit_man.sh and the
1057 dnl misc/tabset install won't work properly.  Usually this happens only when
1058 dnl using the fallback mkinstalldirs script
1059 AC_DEFUN([CF_PROG_INSTALL],
1060 [AC_PROG_INSTALL
1061 case $INSTALL in
1062 /*)
1063   ;;
1064 *)
1065 changequote({{,}})dnl
1066   cf_dir=`echo $INSTALL|sed -e 's%/[^/]*$%%'`
1067   test -z "$cf_dir" && cf_dir=.
1068 changequote([,])dnl
1069   INSTALL=`cd $cf_dir && pwd`/`echo $INSTALL | sed -e 's:^.*/::'`
1070   ;;
1071 esac
1072 ])dnl
1073 dnl ---------------------------------------------------------------------------
1074 dnl Attempt to determine if we've got one of the flavors of regular-expression
1075 dnl code that we can support.
1076 AC_DEFUN([CF_REGEX],
1077 [
1078 AC_MSG_CHECKING([for regular-expression headers])
1079 AC_CACHE_VAL(cf_cv_regex,[
1080 AC_TRY_LINK([#include <sys/types.h>
1081 #include <regex.h>],[
1082         regex_t *p;
1083         int x = regcomp(p, "", 0);
1084         int y = regexec(p, "", 0, 0, 0);
1085         regfree(p);
1086         ],[cf_cv_regex="regex.h"],[
1087         AC_TRY_LINK([#include <regexp.h>],[
1088                 char *p = compile("", "", "", 0);
1089                 int x = step("", "");
1090         ],[cf_cv_regex="regexp.h"],[
1091                 cf_save_LIBS="$LIBS"
1092                 LIBS="-lgen $LIBS"
1093                 AC_TRY_LINK([#include <regexpr.h>],[
1094                         char *p = compile("", "", "");
1095                         int x = step("", "");
1096                 ],[cf_cv_regex="regexpr.h"],[LIBS="$cf_save_LIBS"])])])
1097 ])
1098 AC_MSG_RESULT($cf_cv_regex)
1099 case $cf_cv_regex in
1100         regex.h)   AC_DEFINE(HAVE_REGEX_H_FUNCS) ;;
1101         regexp.h)  AC_DEFINE(HAVE_REGEXP_H_FUNCS) ;;
1102         regexpr.h) AC_DEFINE(HAVE_REGEXPR_H_FUNCS) ;;
1103 esac
1104 ])dnl
1105 dnl ---------------------------------------------------------------------------
1106 dnl This bypasses the normal autoconf process because we're generating an
1107 dnl arbitrary number of NEED_xxxx definitions with the CF_HAVE_FUNCS macro. 
1108 dnl Rather than populate an aclocal.h file with all of those definitions, we do
1109 dnl it here.
1110 dnl
1111 dnl Parameters:
1112 dnl $1 = input, which configure has done substitutions upon (will delete)
1113 dnl $2 = target file
1114 dnl $3 = preamble, if any (a 'here' document)
1115 dnl $4 = trailer, if any (a 'here' document)
1116 dnl
1117 AC_DEFUN([CF_SED_CONFIG_H],[
1118 cf_config_h=conf$$
1119 rm -f $cf_config_h
1120 ## PREAMBLE
1121 ifelse($3,,[
1122 echo '/* generated by configure-script */' >$cf_config_h
1123 ],[cat >$cf_config_h <<CF_EOF
1124 $3[]dnl
1125 CF_EOF])
1126 ## DEFINITIONS
1127 if test -n "$ac_cv_path_TD_CONFIG" ; then
1128         $ac_cv_path_TD_CONFIG $1 |egrep -v '^#' >$cf_config_h
1129         $ac_cv_path_TD_CONFIG $1 |egrep '^#' | sort >>$cf_config_h
1130 else
1131 grep -v '^ -D' $1 >>$cf_config_h
1132 changequote(,)dnl
1133 sed     -e '/^ -D/!d' \
1134         -e '/^# /d' \
1135         -e 's/ -D/\
1136 #define /g' \
1137         -e 's/\(#define [A-Za-z_][A-Za-z0-9_]*\)=/\1    /g' \
1138         -e 's@\\@@g' \
1139         $1 | sort >>$cf_config_h
1140 changequote([,])dnl
1141 fi
1142 ## TRAILER
1143 ifelse($4,,,
1144 [cat >>$cf_config_h <<CF_EOF
1145 $4[]dnl
1146 CF_EOF])
1147 CF_OUTPUT_IF_CHANGED($cf_config_h,$2)
1148 rm -f $1 $cf_config_h
1149 ])dnl
1150 dnl ---------------------------------------------------------------------------
1151 dnl Attempt to determine the appropriate CC/LD options for creating a shared
1152 dnl library.
1153 dnl
1154 dnl Note: $(LOCAL_LDFLAGS) is used to link executables that will run within the 
1155 dnl build-tree, i.e., by making use of the libraries that are compiled in ../lib
1156 dnl We avoid compiling-in a ../lib path for the shared library since that can
1157 dnl lead to unexpected results at runtime.
1158 dnl $(LOCAL_LDFLAGS2) has the same intention but assumes that the shared libraries
1159 dnl are compiled in ../../lib
1160 dnl
1161 dnl The variable 'cf_cv_do_symlinks' is used to control whether we configure
1162 dnl to install symbolic links to the rel/abi versions of shared libraries.
1163 dnl
1164 dnl Some loaders leave 'so_locations' lying around.  It's nice to clean up.
1165 AC_DEFUN([CF_SHARED_OPTS],
1166 [
1167         AC_REQUIRE([CF_SUBST_NCURSES_VERSION])
1168         LOCAL_LDFLAGS=
1169         LOCAL_LDFLAGS2=
1170         LD_SHARED_OPTS=
1171         INSTALL_LIB="-m 644"
1172
1173         cf_cv_do_symlinks=no
1174         cf_cv_rm_so_locs=no
1175
1176         case $cf_cv_system_name in
1177         hpux*)
1178                 # (tested with gcc 2.7.2 -- I don't have c89)
1179                 if test "${CC}" = "gcc"; then
1180                         CC_SHARED_OPTS='-fPIC'
1181                         LD_SHARED_OPTS='-Xlinker +b -Xlinker $(libdir)'
1182                 else
1183                         CC_SHARED_OPTS='+Z'
1184                         LD_SHARED_OPTS='+b $(libdir)'
1185                 fi
1186                 MK_SHARED_LIB='$(LD) -b -o $[@]'
1187                 # HP-UX shared libraries must be executable, and should be
1188                 # readonly to exploit a quirk in the memory manager.
1189                 INSTALL_LIB="-m 555"
1190                 ;;
1191         irix*)
1192                 # tested with IRIX 5.2 and 'cc'.
1193                 if test "${CC}" = "gcc"; then
1194                         CC_SHARED_OPTS='-fPIC'
1195                 else
1196                         CC_SHARED_OPTS='-KPIC'
1197                 fi
1198                 MK_SHARED_LIB='$(LD) -shared -rdata_shared -soname `basename $[@]` -o $[@]'
1199                 cf_cv_rm_so_locs=yes
1200                 ;;
1201         linux*)
1202                 # tested with Linux 2.0.29 and gcc 2.7.2 (ELF)
1203                 CC_SHARED_OPTS='-fPIC'
1204                 MK_SHARED_LIB='gcc -o $[@].$(REL_VERSION) -L../lib -L\$(libdir) -shared -Wl,-soname,`basename $[@].$(ABI_VERSION)`,-stats,$(SHLIB_LIST)-lc'
1205                 test $cf_cv_ld_rpath = yes && cf_ld_rpath_opt="-Wl,-rpath,"
1206                 if test $DFT_LWR_MODEL = "shared" ; then
1207                         LOCAL_LDFLAGS='-Wl,-rpath,../lib'
1208                         LOCAL_LDFLAGS2='-Wl,-rpath,../../lib'
1209                 fi
1210                 cf_cv_do_symlinks=yes
1211                 ;;
1212         openbsd*|netbsd*|freebsd*)
1213                 CC_SHARED_OPTS='-fpic -DPIC'
1214                 MK_SHARED_LIB='$(LD) -Bshareable -o $[@]'
1215                 ;;
1216         osf*|mls+*)
1217                 # tested with OSF/1 V3.2 and 'cc'
1218                 # tested with OSF/1 V3.2 and gcc 2.6.3 (but the c++ demo didn't
1219                 # link with shared libs).
1220                 CC_SHARED_OPTS=''
1221                 MK_SHARED_LIB='$(LD) -o $[@].$(REL_VERSION) -set_version $(ABI_VERSION):$(REL_VERSION) -expect_unresolved "*" -shared -soname `basename $[@].$(ABI_VERSION)`'
1222                 test $cf_cv_ld_rpath = yes && cf_ld_rpath_opt="-rpath"
1223                 case $host_os in
1224                 osf4*)
1225                         MK_SHARED_LIB="${MK_SHARED_LIB} -msym"
1226                         ;;
1227                 esac
1228                 if test $DFT_LWR_MODEL = "shared" ; then
1229                         LOCAL_LDFLAGS='-Wl,-rpath,../lib'
1230                         LOCAL_LDFLAGS2='-Wl,-rpath,../../lib'
1231                 fi
1232                 cf_cv_do_symlinks=yes
1233                 cf_cv_rm_so_locs=yes
1234                 ;;
1235         sunos4*)
1236                 # tested with SunOS 4.1.1 and gcc 2.7.0
1237                 if test $ac_cv_prog_gcc = yes; then
1238                         CC_SHARED_OPTS='-fpic'
1239                 else
1240                         CC_SHARED_OPTS='-KPIC'
1241                 fi
1242                 MK_SHARED_LIB='$(LD) -assert pure-text -o $[@].$(REL_VERSION)'
1243                 cf_cv_do_symlinks=yes
1244                 ;;
1245         solaris2*)
1246                 # tested with SunOS 5.5.1 (solaris 2.5.1) and gcc 2.7.2
1247                 if test $ac_cv_prog_gcc = yes; then
1248                         CC_SHARED_OPTS='-fpic'
1249                 else
1250                         CC_SHARED_OPTS='-KPIC'
1251                 fi
1252                 MK_SHARED_LIB='$(LD) -dy -G -h `basename $[@].$(ABI_VERSION)` -o $[@].$(REL_VERSION)'
1253                 if test $cf_cv_ld_rpath = yes ; then
1254                         cf_ld_rpath_opt="-R"
1255                         EXTRA_LDFLAGS="-R ../lib:\$(libdir) $EXTRA_LDFLAGS"
1256                 fi
1257                 cf_cv_do_symlinks=yes
1258                 ;;
1259         unix_sv*)
1260                 # tested with UnixWare 1.1.2
1261                 CC_SHARED_OPTS='-KPIC'
1262                 MK_SHARED_LIB='$(LD) -d y -G -o $[@]'
1263                 ;;
1264         *)
1265                 CC_SHARED_OPTS='unknown'
1266                 MK_SHARED_LIB='echo unknown'
1267                 ;;
1268         esac
1269
1270         if test -n "$cf_ld_rpath_opt" ; then
1271                 AC_MSG_CHECKING(if we need a space after rpath option)
1272                 cf_save_LIBS="$LIBS"
1273                 LIBS="$LIBS ${cf_ld_rpath_opt}/usr/lib"
1274                 AC_TRY_LINK(, , cf_rpath_space=no, cf_rpath_space=yes)
1275                 LIBS="$cf_save_LIBS"
1276                 AC_MSG_RESULT($cf_rpath_space)
1277                 test $cf_rpath_space = yes && cf_ld_rpath_opt="$cf_ld_rpath_opt "
1278                 MK_SHARED_LIB="$MK_SHARED_LIB $cf_ld_rpath_opt\$(libdir)"
1279         fi
1280
1281         AC_SUBST(CC_SHARED_OPTS)
1282         AC_SUBST(LD_SHARED_OPTS)
1283         AC_SUBST(MK_SHARED_LIB)
1284         AC_SUBST(EXTRA_LDFLAGS)
1285         AC_SUBST(LOCAL_LDFLAGS)
1286         AC_SUBST(LOCAL_LDFLAGS2)
1287         AC_SUBST(INSTALL_LIB)
1288 ])dnl
1289 dnl ---------------------------------------------------------------------------
1290 dnl Check for definitions & structures needed for window size-changing
1291 dnl FIXME: check that this works with "snake" (HP-UX 10.x)
1292 AC_DEFUN([CF_SIZECHANGE],
1293 [
1294 AC_MSG_CHECKING([declaration of size-change])
1295 AC_CACHE_VAL(cf_cv_sizechange,[
1296     cf_cv_sizechange=unknown
1297     cf_save_CFLAGS="$CFLAGS"
1298
1299 for cf_opts in "" "NEED_PTEM_H"
1300 do
1301
1302     CFLAGS="$cf_save_CFLAGS"
1303     test -n "$cf_opts" && CFLAGS="$CFLAGS -D$cf_opts"
1304     AC_TRY_COMPILE([#include <sys/types.h>
1305 #if HAVE_TERMIOS_H
1306 #include <termios.h>
1307 #else
1308 #if HAVE_TERMIO_H
1309 #include <termio.h>
1310 #endif
1311 #endif
1312 #if NEED_PTEM_H
1313 /* This is a workaround for SCO:  they neglected to define struct winsize in
1314  * termios.h -- it's only in termio.h and ptem.h
1315  */
1316 #include        <sys/stream.h>
1317 #include        <sys/ptem.h>
1318 #endif
1319 #if !defined(sun) || !defined(HAVE_TERMIOS_H)
1320 #include <sys/ioctl.h>
1321 #endif
1322 ],[
1323 #ifdef TIOCGSIZE
1324         struct ttysize win;     /* FIXME: what system is this? */
1325         int y = win.ts_lines;
1326         int x = win.ts_cols;
1327 #else
1328 #ifdef TIOCGWINSZ
1329         struct winsize win;
1330         int y = win.ws_row;
1331         int x = win.ws_col;
1332 #else
1333         no TIOCGSIZE or TIOCGWINSZ
1334 #endif /* TIOCGWINSZ */
1335 #endif /* TIOCGSIZE */
1336         ],
1337         [cf_cv_sizechange=yes],
1338         [cf_cv_sizechange=no])
1339
1340         CFLAGS="$cf_save_CFLAGS"
1341         if test "$cf_cv_sizechange" = yes ; then
1342                 echo "size-change succeeded ($cf_opts)" >&AC_FD_CC
1343                 test -n "$cf_opts" && AC_DEFINE_UNQUOTED($cf_opts)
1344                 break
1345         fi
1346 done
1347         ])
1348 AC_MSG_RESULT($cf_cv_sizechange)
1349 test $cf_cv_sizechange != no && AC_DEFINE(HAVE_SIZECHANGE)
1350 ])dnl
1351 dnl ---------------------------------------------------------------------------
1352 dnl Check for datatype 'speed_t', which is normally declared via either
1353 dnl sys/types.h or termios.h
1354 AC_DEFUN([CF_SPEED_TYPE],
1355 [
1356 AC_MSG_CHECKING([for speed_t])
1357 AC_CACHE_VAL(cf_cv_type_speed_t,[
1358         AC_TRY_COMPILE([
1359 #include <sys/types.h>
1360 #if HAVE_TERMIOS_H
1361 #include <termios.h>
1362 #endif],
1363         [speed_t x = 0],
1364         [cf_cv_type_speed_t=yes],
1365         [cf_cv_type_speed_t=no])
1366         ])
1367 AC_MSG_RESULT($cf_cv_type_speed_t)
1368 test $cf_cv_type_speed_t != yes && AC_DEFINE(speed_t,unsigned)
1369 ])dnl
1370 dnl ---------------------------------------------------------------------------
1371 dnl For each parameter, test if the source-directory exists, and if it contains
1372 dnl a 'modules' file.  If so, add to the list $cf_cv_src_modules which we'll
1373 dnl use in CF_LIB_RULES.
1374 dnl
1375 dnl This uses the configured value to make the lists SRC_SUBDIRS and
1376 dnl SUB_MAKEFILES which are used in the makefile-generation scheme.
1377 AC_DEFUN([CF_SRC_MODULES],
1378 [
1379 AC_MSG_CHECKING(for src modules)
1380
1381 # dependencies and linker-arguments for test-programs
1382 TEST_DEPS="${LIB_PREFIX}${LIB_NAME}${DFT_DEP_SUFFIX} $TEST_DEPS"
1383 TEST_ARGS="-l${LIB_NAME}${DFT_ARG_SUFFIX} $TEST_ARGS"
1384
1385 # dependencies and linker-arguments for utility-programs
1386 PROG_ARGS="$TEST_ARGS"
1387
1388 cf_cv_src_modules=
1389 for cf_dir in $1
1390 do
1391         if test -f $srcdir/$cf_dir/modules; then
1392
1393                 # We may/may not have tack in the distribution, though the
1394                 # makefile is.
1395                 if test $cf_dir = tack ; then
1396                         if test ! -f $srcdir/${cf_dir}/${cf_dir}.h; then
1397                                 continue
1398                         fi
1399                 fi
1400
1401                 if test -z "$cf_cv_src_modules"; then
1402                         cf_cv_src_modules=$cf_dir
1403                 else
1404                         cf_cv_src_modules="$cf_cv_src_modules $cf_dir"
1405                 fi
1406
1407                 # Make the ncurses_cfg.h file record the library interface files as
1408                 # well.  These are header files that are the same name as their
1409                 # directory.  Ncurses is the only library that does not follow
1410                 # that pattern.
1411                 if test $cf_dir = tack ; then
1412                         continue
1413                 elif test -f $srcdir/${cf_dir}/${cf_dir}.h; then
1414                         CF_UPPER(cf_have_include,$cf_dir)
1415                         AC_DEFINE_UNQUOTED(HAVE_${cf_have_include}_H)
1416                         AC_DEFINE_UNQUOTED(HAVE_LIB${cf_have_include})
1417                         TEST_DEPS="${LIB_PREFIX}${cf_dir}${DFT_DEP_SUFFIX} $TEST_DEPS"
1418                         TEST_ARGS="-l${cf_dir}${DFT_ARG_SUFFIX} $TEST_ARGS"
1419                 fi
1420         fi
1421 done
1422 AC_MSG_RESULT($cf_cv_src_modules)
1423 TEST_ARGS="-L${LIB_DIR} -L\$(libdir) $TEST_ARGS"
1424 AC_SUBST(TEST_DEPS)
1425 AC_SUBST(TEST_ARGS)
1426
1427 PROG_ARGS="-L${LIB_DIR} -L\$(libdir) $PROG_ARGS"
1428 AC_SUBST(PROG_ARGS)
1429
1430 SRC_SUBDIRS="man include"
1431 for cf_dir in $cf_cv_src_modules
1432 do
1433         SRC_SUBDIRS="$SRC_SUBDIRS $cf_dir"
1434 done
1435 SRC_SUBDIRS="$SRC_SUBDIRS misc test"
1436 test $cf_cxx_library != no && SRC_SUBDIRS="$SRC_SUBDIRS c++"
1437
1438 ADA_SUBDIRS=
1439 if test "$ac_cv_prog_gnat_correct" = yes && test -d $srcdir/Ada95; then
1440    SRC_SUBDIRS="$SRC_SUBDIRS Ada95"
1441    ADA_SUBDIRS="gen ada_include samples"
1442 fi
1443
1444 SUB_MAKEFILES=
1445 for cf_dir in $SRC_SUBDIRS
1446 do
1447         SUB_MAKEFILES="$SUB_MAKEFILES $cf_dir/Makefile"
1448 done
1449
1450 if test -n "$ADA_SUBDIRS"; then
1451    for cf_dir in $ADA_SUBDIRS
1452    do   
1453       SUB_MAKEFILES="$SUB_MAKEFILES Ada95/$cf_dir/Makefile"
1454    done
1455    AC_SUBST(ADA_SUBDIRS)
1456 fi
1457 ])dnl
1458 dnl ---------------------------------------------------------------------------
1459 dnl     Remove "-g" option from the compiler options
1460 AC_DEFUN([CF_STRIP_G_OPT],
1461 [$1=`echo ${$1} | sed -e 's/-g //' -e 's/-g$//'`])dnl
1462 dnl ---------------------------------------------------------------------------
1463 dnl Check if we need _POSIX_SOURCE defined to use struct sigaction.  We'll only
1464 dnl do this if we've found the sigaction function.
1465 dnl
1466 dnl If needed, define SVR4_ACTION.
1467 AC_DEFUN([CF_STRUCT_SIGACTION],[
1468 if test $ac_cv_func_sigaction = yes; then
1469 AC_MSG_CHECKING(whether sigaction needs _POSIX_SOURCE)
1470 AC_TRY_COMPILE([
1471 #include <sys/types.h>
1472 #include <signal.h>],
1473         [struct sigaction act],
1474         [sigact_bad=no],
1475         [
1476 AC_TRY_COMPILE([
1477 #define _POSIX_SOURCE
1478 #include <sys/types.h>
1479 #include <signal.h>],
1480         [struct sigaction act],
1481         [sigact_bad=yes
1482          AC_DEFINE(SVR4_ACTION)],
1483          [sigact_bad=unknown])])
1484 AC_MSG_RESULT($sigact_bad)
1485 fi
1486 ])dnl
1487 dnl ---------------------------------------------------------------------------
1488 dnl Some machines require _POSIX_SOURCE to completely define struct termios.
1489 dnl If so, define SVR4_TERMIO
1490 AC_DEFUN([CF_STRUCT_TERMIOS],[
1491 if test $ac_cv_header_termios_h = yes ; then
1492         case "$CFLAGS" in
1493         *-D_POSIX_SOURCE*)
1494                 termios_bad=dunno ;;
1495         *)      termios_bad=maybe ;;
1496         esac
1497         if test $termios_bad = maybe ; then
1498         AC_MSG_CHECKING(whether termios.h needs _POSIX_SOURCE)
1499         AC_TRY_COMPILE([#include <termios.h>],
1500                 [struct termios foo; int x = foo.c_iflag],
1501                 termios_bad=no, [
1502                 AC_TRY_COMPILE([
1503 #define _POSIX_SOURCE
1504 #include <termios.h>],
1505                         [struct termios foo; int x = foo.c_iflag],
1506                         termios_bad=unknown,
1507                         termios_bad=yes AC_DEFINE(SVR4_TERMIO))
1508                         ])
1509         AC_MSG_RESULT($termios_bad)
1510         fi
1511 fi
1512 ])dnl
1513 dnl ---------------------------------------------------------------------------
1514 dnl     Shorthand macro for substituting things that the user may override
1515 dnl     with an environment variable.
1516 dnl
1517 dnl     $1 = long/descriptive name
1518 dnl     $2 = environment variable
1519 dnl     $3 = default value
1520 AC_DEFUN([CF_SUBST],
1521 [AC_CACHE_VAL(cf_cv_subst_$2,[
1522 AC_MSG_CHECKING(for $1 (symbol $2))
1523 test -z "[$]$2" && $2=$3
1524 AC_MSG_RESULT([$]$2)
1525 AC_SUBST($2)
1526 cf_cv_subst_$2=[$]$2])
1527 $2=${cf_cv_subst_$2}
1528 ])dnl
1529 dnl ---------------------------------------------------------------------------
1530 dnl Get the version-number for use in shared-library naming, etc.
1531 AC_DEFUN([CF_SUBST_NCURSES_VERSION],
1532 [
1533 changequote(,)dnl
1534 NCURSES_MAJOR="`egrep '^NCURSES_MAJOR[  ]*=' $srcdir/dist.mk | sed -e 's/^[^0-9]*//'`"
1535 NCURSES_MINOR="`egrep '^NCURSES_MINOR[  ]*=' $srcdir/dist.mk | sed -e 's/^[^0-9]*//'`"
1536 NCURSES_PATCH="`egrep '^NCURSES_PATCH[  ]*=' $srcdir/dist.mk | sed -e 's/^[^0-9]*//'`"
1537 changequote([,])dnl
1538 cf_cv_abi_version=${NCURSES_MAJOR}
1539 cf_cv_rel_version=${NCURSES_MAJOR}.${NCURSES_MINOR}
1540 dnl Show the computed version, for logging
1541 AC_MSG_RESULT(Configuring NCURSES $cf_cv_rel_version ABI $cf_cv_abi_version (`date`))
1542 dnl We need these values in the generated headers
1543 AC_SUBST(NCURSES_MAJOR)
1544 AC_SUBST(NCURSES_MINOR)
1545 AC_SUBST(NCURSES_PATCH)
1546 dnl We need these values in the generated makefiles
1547 AC_SUBST(cf_cv_rel_version)
1548 AC_SUBST(cf_cv_abi_version)
1549 AC_SUBST(cf_cv_builtin_bool)
1550 AC_SUBST(cf_cv_type_of_bool)
1551 ])dnl
1552 dnl ---------------------------------------------------------------------------
1553 dnl Check if we can include <sys/time.h> with <sys/select.h>; this breaks on
1554 dnl older SCO configurations.
1555 AC_DEFUN([CF_SYS_TIME_SELECT],
1556 [
1557 AC_MSG_CHECKING(if sys/time.h works with sys/select.h)
1558 AC_CACHE_VAL(cf_cv_sys_time_select,[
1559 AC_TRY_COMPILE([
1560 #include <sys/types.h>
1561 #if HAVE_SYS_TIME_H
1562 #include <sys/time.h>
1563 #endif
1564 #if HAVE_SYS_SELECT_H
1565 #include <sys/select.h>
1566 #endif
1567 ],[],[cf_cv_sys_time_select=yes],
1568      [cf_cv_sys_time_select=no])
1569      ])
1570 AC_MSG_RESULT($cf_cv_sys_time_select)
1571 test $cf_cv_sys_time_select = yes && AC_DEFINE(HAVE_SYS_TIME_SELECT)
1572 ])dnl
1573 dnl ---------------------------------------------------------------------------
1574 dnl Determine the type we should use for chtype (and attr_t, which is treated
1575 dnl as the same thing).  We want around 32 bits, so on most machines want a
1576 dnl long, but on newer 64-bit machines, probably want an int.  If we're using
1577 dnl wide characters, we have to have a type compatible with that, as well.
1578 AC_DEFUN([CF_TYPEOF_CHTYPE],
1579 [
1580 AC_REQUIRE([CF_UNSIGNED_LITERALS])
1581 AC_MSG_CHECKING([for type of chtype])
1582 AC_CACHE_VAL(cf_cv_typeof_chtype,[
1583                 AC_TRY_RUN([
1584 #if USE_WIDEC_SUPPORT
1585 #include <stddef.h>     /* we want wchar_t */
1586 #define WANT_BITS 39
1587 #else
1588 #define WANT_BITS 31
1589 #endif
1590 #include <stdio.h>
1591 int main()
1592 {
1593         FILE *fp = fopen("cf_test.out", "w");
1594         if (fp != 0) {
1595                 char *result = "long";
1596 #if USE_WIDEC_SUPPORT
1597                 /*
1598                  * If wchar_t is smaller than a long, it must be an int or a
1599                  * short.  We prefer not to use a short anyway.
1600                  */
1601                 if (sizeof(unsigned long) > sizeof(wchar_t))
1602                         result = "int";
1603 #endif
1604                 if (sizeof(unsigned long) > sizeof(unsigned int)) {
1605                         int n;
1606                         unsigned int x;
1607                         for (n = 0; n < WANT_BITS; n++) {
1608                                 unsigned int y = (x >> n);
1609                                 if (y != 1 || x == 0) {
1610                                         x = 0;
1611                                         break;
1612                                 }
1613                         }
1614                         /*
1615                          * If x is nonzero, an int is big enough for the bits
1616                          * that we want.
1617                          */
1618                         result = (x != 0) ? "int" : "long";
1619                 }
1620                 fputs(result, fp);
1621                 fclose(fp);
1622         }
1623         exit(0);
1624 }
1625                 ],
1626                 [cf_cv_typeof_chtype=`cat cf_test.out`],
1627                 [cf_cv_typeof_chtype=long],
1628                 [cf_cv_typeof_chtype=long])
1629                 rm -f cf_test.out
1630         ])
1631 AC_MSG_RESULT($cf_cv_typeof_chtype)
1632
1633 AC_SUBST(cf_cv_typeof_chtype)
1634 AC_DEFINE_UNQUOTED(TYPEOF_CHTYPE,$cf_cv_typeof_chtype)
1635
1636 cf_cv_1UL="1"
1637 test "$cf_cv_unsigned_literals" = yes && cf_cv_1UL="${cf_cv_1UL}U"
1638 test "$cf_cv_typeof_chtype"    = long && cf_cv_1UL="${cf_cv_1UL}L"
1639 AC_SUBST(cf_cv_1UL)
1640
1641 ])dnl
1642 dnl ---------------------------------------------------------------------------
1643 dnl
1644 AC_DEFUN([CF_TYPE_SIGACTION],
1645 [
1646 AC_MSG_CHECKING([for type sigaction_t])
1647 AC_CACHE_VAL(cf_cv_type_sigaction,[
1648         AC_TRY_COMPILE([
1649 #include <signal.h>],
1650                 [sigaction_t x],
1651                 [cf_cv_type_sigaction=yes],
1652                 [cf_cv_type_sigaction=no])])
1653 AC_MSG_RESULT($cf_cv_type_sigaction)
1654 test $cf_cv_type_sigaction = yes && AC_DEFINE(HAVE_TYPE_SIGACTION)
1655 ])dnl
1656 dnl ---------------------------------------------------------------------------
1657 dnl Test if the compiler supports 'U' and 'L' suffixes.  Only old compilers
1658 dnl won't, but they're still there.
1659 AC_DEFUN([CF_UNSIGNED_LITERALS],
1660 [
1661 AC_MSG_CHECKING([if unsigned literals are legal])
1662 AC_CACHE_VAL(cf_cv_unsigned_literals,[
1663         AC_TRY_COMPILE([],[long x = 1L + 1UL + 1U + 1],
1664                 [cf_cv_unsigned_literals=yes],
1665                 [cf_cv_unsigned_literals=no])
1666         ])
1667 AC_MSG_RESULT($cf_cv_unsigned_literals)
1668 ])dnl
1669 dnl ---------------------------------------------------------------------------
1670 dnl Make an uppercase version of a variable
1671 dnl $1=uppercase($2)
1672 AC_DEFUN([CF_UPPER],
1673 [
1674 changequote(,)dnl
1675 $1=`echo $2 | tr '[a-z]' '[A-Z]'`
1676 changequote([,])dnl
1677 ])dnl
1678 dnl ---------------------------------------------------------------------------
1679 dnl Compute the shift-mask that we'll use for wide-character indices.  We use
1680 dnl all but the index portion of chtype for storing attributes.
1681 AC_DEFUN([CF_WIDEC_SHIFT],
1682 [
1683 AC_REQUIRE([CF_TYPEOF_CHTYPE])
1684 AC_MSG_CHECKING([for number of bits in chtype])
1685 AC_CACHE_VAL(cf_cv_shift_limit,[
1686         AC_TRY_RUN([
1687 #include <stdio.h>
1688 int main()
1689 {
1690         FILE *fp = fopen("cf_test.out", "w");
1691         if (fp != 0) {
1692                 int n;
1693                 unsigned TYPEOF_CHTYPE x = 1L;
1694                 for (n = 0; ; n++) {
1695                         unsigned long y = (x >> n);
1696                         if (y != 1 || x == 0)
1697                                 break;
1698                         x <<= 1;
1699                 }
1700                 fprintf(fp, "%d", n);
1701                 fclose(fp);
1702         }
1703         exit(0);
1704 }
1705                 ],
1706                 [cf_cv_shift_limit=`cat cf_test.out`],
1707                 [cf_cv_shift_limit=32],
1708                 [cf_cv_shift_limit=32])
1709                 rm -f cf_test.out
1710         ])
1711 AC_MSG_RESULT($cf_cv_shift_limit)
1712 AC_SUBST(cf_cv_shift_limit)
1713
1714 AC_MSG_CHECKING([for width of character-index])
1715 AC_CACHE_VAL(cf_cv_widec_shift,[
1716 if test ".$with_widec" = ".yes" ; then
1717         cf_attrs_width=39
1718         if ( expr $cf_cv_shift_limit \> $cf_attrs_width >/dev/null )
1719         then
1720                 cf_cv_widec_shift=`expr 16 + $cf_cv_shift_limit - $cf_attrs_width`
1721         else
1722                 cf_cv_widec_shift=16
1723         fi
1724 else
1725         cf_cv_widec_shift=8
1726 fi
1727 ])
1728 AC_MSG_RESULT($cf_cv_widec_shift)
1729 AC_SUBST(cf_cv_widec_shift)
1730 ])dnl
1731 dnl ---------------------------------------------------------------------------
1732 dnl Wrapper for AC_ARG_WITH to ensure that user supplies a pathname, not just
1733 dnl defaulting to yes/no.
1734 dnl
1735 dnl $1 = option name
1736 dnl $2 = help-text
1737 dnl $3 = environment variable to set
1738 dnl $4 = default value, shown in the help-message, must be a constant
1739 dnl $5 = default value, if it's an expression & cannot be in the help-message
1740 dnl
1741 AC_DEFUN([CF_WITH_PATH],
1742 [AC_ARG_WITH($1,[$2 ](default: ifelse($4,,empty,$4)),,
1743 ifelse($4,,[withval="${$3}"],[withval="${$3-ifelse($5,,$4,$5)}"]))dnl
1744 case ".$withval" in #(vi
1745 ./*) #(vi
1746   ;;
1747 .\[$]{*prefix}*) #(vi
1748   eval withval="$withval"
1749   case ".$withval" in #(vi
1750   .NONE/*)
1751     withval=`echo $withval | sed -e s@NONE@$ac_default_prefix@`
1752     ;;
1753   esac
1754   ;; #(vi
1755 .NONE/*)
1756   withval=`echo $withval | sed -e s@NONE@$ac_default_prefix@`
1757   ;;
1758 *)
1759   AC_ERROR(expected a pathname for $1)
1760   ;;
1761 esac
1762 eval $3="$withval"
1763 AC_SUBST($3)dnl
1764 ])dnl