]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/aclocal.m4
47928a057bf1751ba11232d18655f9d0e8a1d683
[ncurses.git] / test / aclocal.m4
1 dnl $Id: aclocal.m4,v 1.6 2003/10/19 00:09:23 tom Exp $
2 dnl ---------------------------------------------------------------------------
3 dnl ---------------------------------------------------------------------------
4 dnl CF_ADD_INCDIR version: 4 updated: 2002/12/21 14:25:52
5 dnl -------------
6 dnl Add an include-directory to $CPPFLAGS.  Don't add /usr/include, since it's
7 dnl redundant.  We don't normally need to add -I/usr/local/include for gcc,
8 dnl but old versions (and some misinstalled ones) need that.  To make things
9 dnl worse, gcc 3.x gives error messages if -I/usr/local/include is added to
10 dnl the include-path).
11 AC_DEFUN([CF_ADD_INCDIR],
12 [
13 for cf_add_incdir in $1
14 do
15         while true
16         do
17                 case $cf_add_incdir in
18                 /usr/include) # (vi
19                         ;;
20                 /usr/local/include) # (vi
21                         if test "$GCC" = yes
22                         then
23                                 cf_save_CPPFLAGS="$CPPFLAGS"
24                                 CPPFLAGS="$CPPFLAGS -I$cf_add_incdir"
25                                 AC_TRY_COMPILE([#include <stdio.h>],
26                                                 [printf("Hello")],
27                                                 [],
28                                                 [CPPFLAGS="$cf_save_CPPFLAGS"])
29                         fi
30                         ;;
31                 *) # (vi
32                         CPPFLAGS="$CPPFLAGS -I$cf_add_incdir"
33                         ;;
34                 esac
35                 cf_top_incdir=`echo $cf_add_incdir | sed -e 's%/include/.*$%/include%'`
36                 test "$cf_top_incdir" = "$cf_add_incdir" && break
37                 cf_add_incdir="$cf_top_incdir"
38         done
39 done
40 ])dnl
41 dnl ---------------------------------------------------------------------------
42 dnl CF_CHECK_CACHE version: 7 updated: 2001/12/19 00:50:10
43 dnl --------------
44 dnl Check if we're accidentally using a cache from a different machine.
45 dnl Derive the system name, as a check for reusing the autoconf cache.
46 dnl
47 dnl If we've packaged config.guess and config.sub, run that (since it does a
48 dnl better job than uname).  Normally we'll use AC_CANONICAL_HOST, but allow
49 dnl an extra parameter that we may override, e.g., for AC_CANONICAL_SYSTEM
50 dnl which is useful in cross-compiles.
51 AC_DEFUN([CF_CHECK_CACHE],
52 [
53 if test -f $srcdir/config.guess ; then
54         ifelse([$1],,[AC_CANONICAL_HOST],[$1])
55         system_name="$host_os"
56 else
57         system_name="`(uname -s -r) 2>/dev/null`"
58         if test -z "$system_name" ; then
59                 system_name="`(hostname) 2>/dev/null`"
60         fi
61 fi
62 test -n "$system_name" && AC_DEFINE_UNQUOTED(SYSTEM_NAME,"$system_name")
63 AC_CACHE_VAL(cf_cv_system_name,[cf_cv_system_name="$system_name"])
64
65 test -z "$system_name" && system_name="$cf_cv_system_name"
66 test -n "$cf_cv_system_name" && AC_MSG_RESULT(Configuring for $cf_cv_system_name)
67
68 if test ".$system_name" != ".$cf_cv_system_name" ; then
69         AC_MSG_RESULT(Cached system name ($system_name) does not agree with actual ($cf_cv_system_name))
70         AC_ERROR("Please remove config.cache and try again.")
71 fi
72 ])dnl
73 dnl ---------------------------------------------------------------------------
74 dnl CF_CURSES_ACS_MAP version: 3 updated: 2003/05/17 22:19:02
75 dnl -----------------
76 dnl Check for likely values of acs_map[]:
77 AC_DEFUN([CF_CURSES_ACS_MAP],
78 [
79 AC_CACHE_CHECK(for alternate character set array, cf_cv_curses_acs_map,[
80 cf_cv_curses_acs_map=unknown
81 for name in acs_map _acs_map __acs_map _nc_acs_map
82 do
83 AC_TRY_LINK([
84 #include <${cf_cv_ncurses_header-curses.h}>
85 ],[
86 $name['k'] = ACS_PLUS
87 ],[cf_cv_curses_acs_map=$name; break])
88 done
89 ])
90
91 test "$cf_cv_curses_acs_map" != unknown && AC_DEFINE_UNQUOTED(CURSES_ACS_ARRAY,$cf_cv_curses_acs_map)
92 ])
93 dnl ---------------------------------------------------------------------------
94 dnl CF_CURSES_CHECK_TYPE version: 2 updated: 2003/03/01 23:40:33
95 dnl --------------------
96 dnl Check if curses.h defines the given type
97 AC_DEFUN([CF_CURSES_CHECK_TYPE],
98 [
99 AC_MSG_CHECKING(for type $1 in ${cf_cv_ncurses_header-curses.h})
100 AC_TRY_COMPILE([
101 #ifndef _XOPEN_SOURCE_EXTENDED
102 #define _XOPEN_SOURCE_EXTENDED
103 #endif
104 #include <${cf_cv_ncurses_header-curses.h}>],[
105 $1 foo
106 ],cf_result=yes,cf_result=no)
107 AC_MSG_RESULT($cf_result)
108 if test $cf_result = yes ; then
109         CF_UPPER(cf_result,have_type_$1)
110         AC_DEFINE_UNQUOTED($cf_result)
111 else
112         AC_DEFINE_UNQUOTED($1,$2)
113 fi
114 ])dnl
115 dnl ---------------------------------------------------------------------------
116 dnl CF_CURSES_CPPFLAGS version: 7 updated: 2003/06/06 00:48:41
117 dnl ------------------
118 dnl Look for the curses headers.
119 AC_DEFUN([CF_CURSES_CPPFLAGS],[
120
121 AC_CACHE_CHECK(for extra include directories,cf_cv_curses_incdir,[
122 cf_cv_curses_incdir=no
123 case $host_os in #(vi
124 hpux10.*|hpux11.*) #(vi
125         test -d /usr/include/curses_colr && \
126         cf_cv_curses_incdir="-I/usr/include/curses_colr"
127         ;;
128 sunos3*|sunos4*)
129         test -d /usr/5lib && \
130         test -d /usr/5include && \
131         cf_cv_curses_incdir="-I/usr/5include"
132         ;;
133 esac
134 ])
135 test "$cf_cv_curses_incdir" != no && CPPFLAGS="$cf_cv_curses_incdir $CPPFLAGS"
136
137 AC_CACHE_CHECK(if we have identified curses headers,cf_cv_ncurses_header,[
138 cf_cv_ncurses_header=none
139 for cf_header in \
140         curses.h \
141         ncurses.h \
142         ncurses/curses.h \
143         ncurses/ncurses.h
144 do
145 AC_TRY_COMPILE([#include <${cf_header}>],
146         [initscr(); tgoto("?", 0,0)],
147         [cf_cv_ncurses_header=$cf_header; break],[])
148 done
149 ])
150
151 if test "$cf_cv_ncurses_header" = none ; then
152         AC_MSG_ERROR(No curses header-files found)
153 fi
154
155 # cheat, to get the right #define's for HAVE_NCURSES_H, etc.
156 AC_CHECK_HEADERS($cf_cv_ncurses_header)
157
158 ])dnl
159 dnl ---------------------------------------------------------------------------
160 dnl CF_CURSES_LIBS version: 22 updated: 2002/10/27 18:21:42
161 dnl --------------
162 dnl Look for the curses libraries.  Older curses implementations may require
163 dnl termcap/termlib to be linked as well.  Call CF_CURSES_CPPFLAGS first.
164 AC_DEFUN([CF_CURSES_LIBS],[
165
166 AC_MSG_CHECKING(if we have identified curses libraries)
167 AC_TRY_LINK([#include <${cf_cv_ncurses_header-curses.h}>],
168         [initscr(); tgoto("?", 0,0)],
169         cf_result=yes,
170         cf_result=no)
171 AC_MSG_RESULT($cf_result)
172
173 if test "$cf_result" = no ; then
174 case $host_os in #(vi
175 freebsd*) #(vi
176         AC_CHECK_LIB(mytinfo,tgoto,[LIBS="-lmytinfo $LIBS"])
177         ;;
178 hpux10.*|hpux11.*) #(vi
179         AC_CHECK_LIB(cur_colr,initscr,[
180                 LIBS="-lcur_colr $LIBS"
181                 ac_cv_func_initscr=yes
182                 ],[
183         AC_CHECK_LIB(Hcurses,initscr,[
184                 # HP's header uses __HP_CURSES, but user claims _HP_CURSES.
185                 LIBS="-lHcurses $LIBS"
186                 CPPFLAGS="-D__HP_CURSES -D_HP_CURSES $CPPFLAGS"
187                 ac_cv_func_initscr=yes
188                 ])])
189         ;;
190 linux*) # Suse Linux does not follow /usr/lib convention
191         LIBS="$LIBS -L/lib"
192         ;;
193 sunos3*|sunos4*)
194         test -d /usr/5lib && \
195         LIBS="$LIBS -L/usr/5lib -lcurses -ltermcap"
196         ac_cv_func_initscr=yes
197         ;;
198 esac
199
200 if test ".$ac_cv_func_initscr" != .yes ; then
201         cf_save_LIBS="$LIBS"
202         cf_term_lib=""
203         cf_curs_lib=""
204
205         if test ".${cf_cv_ncurses_version-no}" != .no
206         then
207                 cf_check_list="ncurses curses cursesX"
208         else
209                 cf_check_list="cursesX curses ncurses"
210         fi
211
212         # Check for library containing tgoto.  Do this before curses library
213         # because it may be needed to link the test-case for initscr.
214         AC_CHECK_FUNC(tgoto,[cf_term_lib=predefined],[
215                 for cf_term_lib in $cf_check_list termcap termlib unknown
216                 do
217                         AC_CHECK_LIB($cf_term_lib,tgoto,[break])
218                 done
219         ])
220
221         # Check for library containing initscr
222         test "$cf_term_lib" != predefined && test "$cf_term_lib" != unknown && LIBS="-l$cf_term_lib $cf_save_LIBS"
223         for cf_curs_lib in $cf_check_list xcurses jcurses unknown
224         do
225                 AC_CHECK_LIB($cf_curs_lib,initscr,[break])
226         done
227         test $cf_curs_lib = unknown && AC_ERROR(no curses library found)
228
229         LIBS="-l$cf_curs_lib $cf_save_LIBS"
230         if test "$cf_term_lib" = unknown ; then
231                 AC_MSG_CHECKING(if we can link with $cf_curs_lib library)
232                 AC_TRY_LINK([#include <${cf_cv_ncurses_header-curses.h}>],
233                         [initscr()],
234                         [cf_result=yes],
235                         [cf_result=no])
236                 AC_MSG_RESULT($cf_result)
237                 test $cf_result = no && AC_ERROR(Cannot link curses library)
238         elif test "$cf_curs_lib" = "$cf_term_lib" ; then
239                 :
240         elif test "$cf_term_lib" != predefined ; then
241                 AC_MSG_CHECKING(if we need both $cf_curs_lib and $cf_term_lib libraries)
242                 AC_TRY_LINK([#include <${cf_cv_ncurses_header-curses.h}>],
243                         [initscr(); tgoto((char *)0, 0, 0);],
244                         [cf_result=no],
245                         [
246                         LIBS="-l$cf_curs_lib -l$cf_term_lib $cf_save_LIBS"
247                         AC_TRY_LINK([#include <${cf_cv_ncurses_header-curses.h}>],
248                                 [initscr()],
249                                 [cf_result=yes],
250                                 [cf_result=error])
251                         ])
252                 AC_MSG_RESULT($cf_result)
253         fi
254 fi
255 fi
256
257 ])dnl
258 dnl ---------------------------------------------------------------------------
259 dnl CF_CURSES_WACS_MAP version: 3 updated: 2003/05/17 22:19:02
260 dnl ------------------
261 dnl Check for likely values of wacs_map[]:
262 AC_DEFUN([CF_CURSES_WACS_MAP],
263 [
264 AC_CACHE_CHECK(for wide alternate character set array, cf_cv_curses_wacs_map,[
265         cf_cv_curses_wacs_map=unknown
266         for name in wacs_map _wacs_map __wacs_map _nc_wacs
267         do
268         AC_TRY_LINK([
269 #ifndef _XOPEN_SOURCE_EXTENDED
270 #define _XOPEN_SOURCE_EXTENDED
271 #endif
272 #include <${cf_cv_ncurses_header-curses.h}>],
273         [$name['k'] = *WACS_PLUS],
274         [cf_cv_curses_wacs_map=$name
275          break])
276         done])
277 ])
278 dnl ---------------------------------------------------------------------------
279 dnl CF_DIRNAME version: 4 updated: 2002/12/21 19:25:52
280 dnl ----------
281 dnl "dirname" is not portable, so we fake it with a shell script.
282 AC_DEFUN([CF_DIRNAME],[$1=`echo $2 | sed -e 's%/[[^/]]*$%%'`])dnl
283 dnl ---------------------------------------------------------------------------
284 dnl CF_FIND_LIBRARY version: 7 updated: 2000/04/13 21:38:04
285 dnl ---------------
286 dnl Look for a non-standard library, given parameters for AC_TRY_LINK.  We
287 dnl prefer a standard location, and use -L options only if we do not find the
288 dnl library in the standard library location(s).
289 dnl     $1 = library name
290 dnl     $2 = library class, usually the same as library name
291 dnl     $3 = includes
292 dnl     $4 = code fragment to compile/link
293 dnl     $5 = corresponding function-name
294 dnl     $6 = flag, nonnull if failure causes an error-exit
295 dnl
296 dnl Sets the variable "$cf_libdir" as a side-effect, so we can see if we had
297 dnl to use a -L option.
298 AC_DEFUN([CF_FIND_LIBRARY],
299 [
300         eval 'cf_cv_have_lib_'$1'=no'
301         cf_libdir=""
302         AC_CHECK_FUNC($5,
303                 eval 'cf_cv_have_lib_'$1'=yes',[
304                 cf_save_LIBS="$LIBS"
305                 AC_MSG_CHECKING(for $5 in -l$1)
306                 LIBS="-l$1 $LIBS"
307                 AC_TRY_LINK([$3],[$4],
308                         [AC_MSG_RESULT(yes)
309                          eval 'cf_cv_have_lib_'$1'=yes'
310                         ],
311                         [AC_MSG_RESULT(no)
312                         CF_LIBRARY_PATH(cf_search,$2)
313                         for cf_libdir in $cf_search
314                         do
315                                 AC_MSG_CHECKING(for -l$1 in $cf_libdir)
316                                 LIBS="-L$cf_libdir -l$1 $cf_save_LIBS"
317                                 AC_TRY_LINK([$3],[$4],
318                                         [AC_MSG_RESULT(yes)
319                                          eval 'cf_cv_have_lib_'$1'=yes'
320                                          break],
321                                         [AC_MSG_RESULT(no)
322                                          LIBS="$cf_save_LIBS"])
323                         done
324                         ])
325                 ])
326 eval 'cf_found_library=[$]cf_cv_have_lib_'$1
327 ifelse($6,,[
328 if test $cf_found_library = no ; then
329         AC_ERROR(Cannot link $1 library)
330 fi
331 ])
332 ])dnl
333 dnl ---------------------------------------------------------------------------
334 dnl CF_FUNC_CURSES_VERSION version: 3 updated: 2003/05/17 22:19:02
335 dnl ----------------------
336 dnl Solaris has a data item 'curses_version', which confuses AC_CHECK_FUNCS.
337 dnl It's a character string "SVR4", not documented.
338 AC_DEFUN([CF_FUNC_CURSES_VERSION],
339 [
340 AC_CACHE_CHECK(for function curses_version, cf_cv_func_curses_version,[
341 AC_TRY_RUN([
342 #include <${cf_cv_ncurses_header-curses.h}>
343 int main()
344 {
345         char temp[1024];
346         sprintf(temp, "%s\n", curses_version());
347         exit(0);
348 }]
349 ,[cf_cv_func_curses_version=yes]
350 ,[cf_cv_func_curses_version=no]
351 ,[cf_cv_func_curses_version=unknown])
352 rm -f core])
353 test "$cf_cv_func_curses_version" = yes && AC_DEFINE(HAVE_CURSES_VERSION)
354 ])
355 dnl ---------------------------------------------------------------------------
356 dnl CF_GNU_SOURCE version: 3 updated: 2000/10/29 23:30:53
357 dnl -------------
358 dnl Check if we must define _GNU_SOURCE to get a reasonable value for
359 dnl _XOPEN_SOURCE, upon which many POSIX definitions depend.  This is a defect
360 dnl (or misfeature) of glibc2, which breaks portability of many applications,
361 dnl since it is interwoven with GNU extensions.
362 dnl
363 dnl Well, yes we could work around it...
364 AC_DEFUN([CF_GNU_SOURCE],
365 [
366 AC_CACHE_CHECK(if we must define _GNU_SOURCE,cf_cv_gnu_source,[
367 AC_TRY_COMPILE([#include <sys/types.h>],[
368 #ifndef _XOPEN_SOURCE
369 make an error
370 #endif],
371         [cf_cv_gnu_source=no],
372         [cf_save="$CPPFLAGS"
373          CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
374          AC_TRY_COMPILE([#include <sys/types.h>],[
375 #ifdef _XOPEN_SOURCE
376 make an error
377 #endif],
378         [cf_cv_gnu_source=no],
379         [cf_cv_gnu_source=yes])
380         CPPFLAGS="$cf_save"
381         ])
382 ])
383 test "$cf_cv_gnu_source" = yes && CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
384 ])dnl
385 dnl ---------------------------------------------------------------------------
386 dnl CF_HEADER_PATH version: 8 updated: 2002/11/10 14:46:59
387 dnl --------------
388 dnl Construct a search-list for a nonstandard header-file
389 AC_DEFUN([CF_HEADER_PATH],
390 [CF_SUBDIR_PATH($1,$2,include)
391 test "$includedir" != NONE && \
392 test "$includedir" != "/usr/include" && \
393 test -d "$includedir" && {
394         test -d $includedir &&    $1="[$]$1 $includedir"
395         test -d $includedir/$2 && $1="[$]$1 $includedir/$2"
396 }
397
398 test "$oldincludedir" != NONE && \
399 test "$oldincludedir" != "/usr/include" && \
400 test -d "$oldincludedir" && {
401         test -d $oldincludedir    && $1="[$]$1 $oldincludedir"
402         test -d $oldincludedir/$2 && $1="[$]$1 $oldincludedir/$2"
403 }
404
405 ])dnl
406 dnl ---------------------------------------------------------------------------
407 dnl CF_INHERIT_SCRIPT version: 2 updated: 2003/03/01 23:50:42
408 dnl -----------------
409 dnl If we do not have a given script, look for it in the parent directory.
410 AC_DEFUN([CF_INHERIT_SCRIPT],
411 [
412 test -f $1 || ( test -f ../$1 && cp ../$1 ./ )
413 ])dnl
414 dnl ---------------------------------------------------------------------------
415 dnl CF_LIBRARY_PATH version: 7 updated: 2002/11/10 14:46:59
416 dnl ---------------
417 dnl Construct a search-list for a nonstandard library-file
418 AC_DEFUN([CF_LIBRARY_PATH],
419 [CF_SUBDIR_PATH($1,$2,lib)])dnl
420 dnl ---------------------------------------------------------------------------
421 dnl CF_NCURSES_CC_CHECK version: 3 updated: 2003/01/12 18:59:28
422 dnl -------------------
423 dnl Check if we can compile with ncurses' header file
424 dnl $1 is the cache variable to set
425 dnl $2 is the header-file to include
426 dnl $3 is the root name (ncurses or ncursesw)
427 AC_DEFUN([CF_NCURSES_CC_CHECK],[
428         AC_TRY_COMPILE([
429 ]ifelse($3,ncursesw,[
430 #define _XOPEN_SOURCE_EXTENDED
431 #undef  HAVE_LIBUTF8_H  /* in case we used CF_UTF8_LIB */
432 #define HAVE_LIBUTF8_H  /* to force ncurses' header file to use cchar_t */
433 ])[
434 #include <$2>],[
435 #ifdef NCURSES_VERSION
436 ]ifelse($3,ncursesw,[
437 #ifndef WACS_BSSB
438         make an error
439 #endif
440 ])[
441 printf("%s\n", NCURSES_VERSION);
442 #else
443 #ifdef __NCURSES_H
444 printf("old\n");
445 #else
446         make an error
447 #endif
448 #endif
449         ]
450         ,[$1=$cf_header]
451         ,[$1=no])
452 ])dnl
453 dnl ---------------------------------------------------------------------------
454 dnl CF_NCURSES_CPPFLAGS version: 16 updated: 2002/12/29 18:30:46
455 dnl -------------------
456 dnl Look for the SVr4 curses clone 'ncurses' in the standard places, adjusting
457 dnl the CPPFLAGS variable so we can include its header.
458 dnl
459 dnl The header files may be installed as either curses.h, or ncurses.h (would
460 dnl be obsolete, except that some packagers prefer this name to distinguish it
461 dnl from a "native" curses implementation).  If not installed for overwrite,
462 dnl the curses.h file would be in an ncurses subdirectory (e.g.,
463 dnl /usr/include/ncurses), but someone may have installed overwriting the
464 dnl vendor's curses.  Only very old versions (pre-1.9.2d, the first autoconf'd
465 dnl version) of ncurses don't define either __NCURSES_H or NCURSES_VERSION in
466 dnl the header.
467 dnl
468 dnl If the installer has set $CFLAGS or $CPPFLAGS so that the ncurses header
469 dnl is already in the include-path, don't even bother with this, since we cannot
470 dnl easily determine which file it is.  In this case, it has to be <curses.h>.
471 dnl
472 dnl The optional parameter gives the root name of the library, in case it is
473 dnl not installed as the default curses library.  That is how the
474 dnl wide-character version of ncurses is installed.
475 AC_DEFUN([CF_NCURSES_CPPFLAGS],
476 [AC_REQUIRE([CF_WITH_CURSES_DIR])
477
478 cf_ncuhdr_root=ifelse($1,,ncurses,$1)
479
480 test -n "$cf_cv_curses_dir" && \
481 test "$cf_cv_curses_dir" != "no" && \
482 CPPFLAGS="-I$cf_cv_curses_dir/include -I$cf_cv_curses_dir/include/$cf_ncuhdr_root $CPPFLAGS"
483
484 AC_CACHE_CHECK(for $cf_ncuhdr_root header in include-path, cf_cv_ncurses_h,[
485         cf_header_list="$cf_ncuhdr_root/curses.h $cf_ncuhdr_root/ncurses.h"
486         ( test "$cf_ncuhdr_root" = ncurses || test "$cf_ncuhdr_root" = ncursesw ) && cf_header_list="$cf_header_list curses.h ncurses.h"
487         for cf_header in $cf_header_list
488         do
489                 CF_NCURSES_CC_CHECK(cf_cv_ncurses_h,$cf_header,$1)
490                 test "$cf_cv_ncurses_h" != no && break
491         done
492 ])
493
494 if test "$cf_cv_ncurses_h" != no ; then
495         cf_cv_ncurses_header=$cf_cv_ncurses_h
496 else
497 AC_CACHE_CHECK(for $cf_ncuhdr_root include-path, cf_cv_ncurses_h2,[
498         test -n "$verbose" && echo
499         CF_HEADER_PATH(cf_search,$cf_ncuhdr_root)
500         test -n "$verbose" && echo search path $cf_search
501         cf_save2_CPPFLAGS="$CPPFLAGS"
502         for cf_incdir in $cf_search
503         do
504                 CF_ADD_INCDIR($cf_incdir)
505                 for cf_header in \
506                         ncurses.h \
507                         curses.h
508                 do
509                         CF_NCURSES_CC_CHECK(cf_cv_ncurses_h2,$cf_header,$1)
510                         if test "$cf_cv_ncurses_h2" != no ; then
511                                 cf_cv_ncurses_h2=$cf_incdir/$cf_header
512                                 test -n "$verbose" && echo $ac_n "      ... found $ac_c" 1>&AC_FD_MSG
513                                 break
514                         fi
515                         test -n "$verbose" && echo "    ... tested $cf_incdir/$cf_header" 1>&AC_FD_MSG
516                 done
517                 CPPFLAGS="$cf_save2_CPPFLAGS"
518                 test "$cf_cv_ncurses_h2" != no && break
519         done
520         test "$cf_cv_ncurses_h2" = no && AC_ERROR(not found)
521         ])
522
523         CF_DIRNAME(cf_1st_incdir,$cf_cv_ncurses_h2)
524         cf_cv_ncurses_header=`basename $cf_cv_ncurses_h2`
525         if test `basename $cf_1st_incdir` = $cf_ncuhdr_root ; then
526                 cf_cv_ncurses_header=$cf_ncuhdr_root/$cf_cv_ncurses_header
527         fi
528         CF_ADD_INCDIR($cf_1st_incdir)
529
530 fi
531
532 AC_DEFINE(NCURSES)
533
534 case $cf_cv_ncurses_header in # (vi
535 *ncurses.h)
536         AC_DEFINE(HAVE_NCURSES_H)
537         ;;
538 esac
539
540 case $cf_cv_ncurses_header in # (vi
541 ncurses/curses.h|ncurses/ncurses.h)
542         AC_DEFINE(HAVE_NCURSES_NCURSES_H)
543         ;;
544 ncursesw/curses.h|ncursesw/ncurses.h)
545         AC_DEFINE(HAVE_NCURSESW_NCURSES_H)
546         ;;
547 esac
548
549 CF_NCURSES_VERSION
550 ])dnl
551 dnl ---------------------------------------------------------------------------
552 dnl CF_NCURSES_LIBS version: 11 updated: 2002/12/22 14:22:25
553 dnl ---------------
554 dnl Look for the ncurses library.  This is a little complicated on Linux,
555 dnl because it may be linked with the gpm (general purpose mouse) library.
556 dnl Some distributions have gpm linked with (bsd) curses, which makes it
557 dnl unusable with ncurses.  However, we don't want to link with gpm unless
558 dnl ncurses has a dependency, since gpm is normally set up as a shared library,
559 dnl and the linker will record a dependency.
560 dnl
561 dnl The optional parameter gives the root name of the library, in case it is
562 dnl not installed as the default curses library.  That is how the
563 dnl wide-character version of ncurses is installed.
564 AC_DEFUN([CF_NCURSES_LIBS],
565 [AC_REQUIRE([CF_NCURSES_CPPFLAGS])
566
567 cf_nculib_root=ifelse($1,,ncurses,$1)
568         # This works, except for the special case where we find gpm, but
569         # ncurses is in a nonstandard location via $LIBS, and we really want
570         # to link gpm.
571 cf_ncurses_LIBS=""
572 cf_ncurses_SAVE="$LIBS"
573 AC_CHECK_LIB(gpm,Gpm_Open,
574         [AC_CHECK_LIB(gpm,initscr,
575                 [LIBS="$cf_ncurses_SAVE"],
576                 [cf_ncurses_LIBS="-lgpm"])])
577
578 case $host_os in #(vi
579 freebsd*)
580         # This is only necessary if you are linking against an obsolete
581         # version of ncurses (but it should do no harm, since it's static).
582         AC_CHECK_LIB(mytinfo,tgoto,[cf_ncurses_LIBS="-lmytinfo $cf_ncurses_LIBS"])
583         ;;
584 esac
585
586 LIBS="$cf_ncurses_LIBS $LIBS"
587
588 if ( test -n "$cf_cv_curses_dir" && test "$cf_cv_curses_dir" != "no" )
589 then
590         LIBS="-L$cf_cv_curses_dir/lib -l$cf_nculib_root $LIBS"
591 else
592         CF_FIND_LIBRARY($cf_nculib_root,$cf_nculib_root,
593                 [#include <${cf_cv_ncurses_header-curses.h}>],
594                 [initscr()],
595                 initscr)
596 fi
597
598 if test -n "$cf_ncurses_LIBS" ; then
599         AC_MSG_CHECKING(if we can link $cf_nculib_root without $cf_ncurses_LIBS)
600         cf_ncurses_SAVE="$LIBS"
601         for p in $cf_ncurses_LIBS ; do
602                 q=`echo $LIBS | sed -e "s%$p %%" -e "s%$p$%%"`
603                 if test "$q" != "$LIBS" ; then
604                         LIBS="$q"
605                 fi
606         done
607         AC_TRY_LINK([#include <${cf_cv_ncurses_header-curses.h}>],
608                 [initscr(); mousemask(0,0); tgoto((char *)0, 0, 0);],
609                 [AC_MSG_RESULT(yes)],
610                 [AC_MSG_RESULT(no)
611                  LIBS="$cf_ncurses_SAVE"])
612 fi
613
614 CF_UPPER(cf_nculib_ROOT,HAVE_LIB$cf_nculib_root)
615 AC_DEFINE_UNQUOTED($cf_nculib_ROOT)
616 ])dnl
617 dnl ---------------------------------------------------------------------------
618 dnl CF_NCURSES_VERSION version: 10 updated: 2002/10/27 18:21:42
619 dnl ------------------
620 dnl Check for the version of ncurses, to aid in reporting bugs, etc.
621 dnl Call CF_CURSES_CPPFLAGS first, or CF_NCURSES_CPPFLAGS.  We don't use
622 dnl AC_REQUIRE since that does not work with the shell's if/then/else/fi.
623 AC_DEFUN([CF_NCURSES_VERSION],
624 [
625 AC_CACHE_CHECK(for ncurses version, cf_cv_ncurses_version,[
626         cf_cv_ncurses_version=no
627         cf_tempfile=out$$
628         rm -f $cf_tempfile
629         AC_TRY_RUN([
630 #include <${cf_cv_ncurses_header-curses.h}>
631 #include <stdio.h>
632 int main()
633 {
634         FILE *fp = fopen("$cf_tempfile", "w");
635 #ifdef NCURSES_VERSION
636 # ifdef NCURSES_VERSION_PATCH
637         fprintf(fp, "%s.%d\n", NCURSES_VERSION, NCURSES_VERSION_PATCH);
638 # else
639         fprintf(fp, "%s\n", NCURSES_VERSION);
640 # endif
641 #else
642 # ifdef __NCURSES_H
643         fprintf(fp, "old\n");
644 # else
645         make an error
646 # endif
647 #endif
648         exit(0);
649 }],[
650         cf_cv_ncurses_version=`cat $cf_tempfile`],,[
651
652         # This will not work if the preprocessor splits the line after the
653         # Autoconf token.  The 'unproto' program does that.
654         cat > conftest.$ac_ext <<EOF
655 #include <${cf_cv_ncurses_header-curses.h}>
656 #undef Autoconf
657 #ifdef NCURSES_VERSION
658 Autoconf NCURSES_VERSION
659 #else
660 #ifdef __NCURSES_H
661 Autoconf "old"
662 #endif
663 ;
664 #endif
665 EOF
666         cf_try="$ac_cpp conftest.$ac_ext 2>&AC_FD_CC | grep '^Autoconf ' >conftest.out"
667         AC_TRY_EVAL(cf_try)
668         if test -f conftest.out ; then
669                 cf_out=`cat conftest.out | sed -e 's%^Autoconf %%' -e 's%^[[^"]]*"%%' -e 's%".*%%'`
670                 test -n "$cf_out" && cf_cv_ncurses_version="$cf_out"
671                 rm -f conftest.out
672         fi
673 ])
674         rm -f $cf_tempfile
675 ])
676 test "$cf_cv_ncurses_version" = no || AC_DEFINE(NCURSES)
677 ])dnl
678 dnl ---------------------------------------------------------------------------
679 dnl CF_PATH_SYNTAX version: 9 updated: 2002/09/17 23:03:38
680 dnl --------------
681 dnl Check the argument to see that it looks like a pathname.  Rewrite it if it
682 dnl begins with one of the prefix/exec_prefix variables, and then again if the
683 dnl result begins with 'NONE'.  This is necessary to work around autoconf's
684 dnl delayed evaluation of those symbols.
685 AC_DEFUN([CF_PATH_SYNTAX],[
686 case ".[$]$1" in #(vi
687 .\[$]\(*\)*|.\'*\'*) #(vi
688   ;;
689 ..|./*|.\\*) #(vi
690   ;;
691 .[[a-zA-Z]]:[[\\/]]*) #(vi OS/2 EMX
692   ;;
693 .\[$]{*prefix}*) #(vi
694   eval $1="[$]$1"
695   case ".[$]$1" in #(vi
696   .NONE/*)
697     $1=`echo [$]$1 | sed -e s%NONE%$ac_default_prefix%`
698     ;;
699   esac
700   ;; #(vi
701 .NONE/*)
702   $1=`echo [$]$1 | sed -e s%NONE%$ac_default_prefix%`
703   ;;
704 *)
705   ifelse($2,,[AC_ERROR([expected a pathname, not \"[$]$1\"])],$2)
706   ;;
707 esac
708 ])dnl
709 dnl ---------------------------------------------------------------------------
710 dnl CF_PREDEFINE version: 1 updated: 2003/07/26 17:53:56
711 dnl ------------
712 dnl Add definitions to CPPFLAGS to ensure they're predefined for all compiles.
713 dnl
714 dnl $1 = symbol to test
715 dnl $2 = value (if any) to use for a predefinition
716 AC_DEFUN([CF_PREDEFINE],
717 [
718 AC_MSG_CHECKING(if we must define $1)
719 AC_TRY_COMPILE([#include <sys/types.h>
720 ],[
721 #ifndef $1
722 make an error
723 #endif],[cf_result=no],[cf_result=yes])
724 AC_MSG_RESULT($cf_result)
725
726 if test "$cf_result" = yes ; then
727         CPPFLAGS="$CPPFLAGS ifelse($2,,-D$1,[-D$1=$2])"
728 elif test "x$2" != "x" ; then
729         AC_MSG_CHECKING(checking for compatible value versus $2)
730         AC_TRY_COMPILE([#include <sys/types.h>
731 ],[
732 #if $1-$2 < 0
733 make an error
734 #endif],[cf_result=yes],[cf_result=no])
735         AC_MSG_RESULT($cf_result)
736         if test "$cf_result" = no ; then
737                 # perhaps we can override it - try...
738                 CPPFLAGS="$CPPFLAGS -D$1=$2"
739         fi
740 fi
741 ])dnl
742 dnl ---------------------------------------------------------------------------
743 dnl CF_SUBDIR_PATH version: 3 updated: 2002/12/29 18:30:46
744 dnl --------------
745 dnl Construct a search-list for a nonstandard header/lib-file
746 dnl     $1 = the variable to return as result
747 dnl     $2 = the package name
748 dnl     $3 = the subdirectory, e.g., bin, include or lib
749 AC_DEFUN([CF_SUBDIR_PATH],
750 [$1=""
751
752 test -d [$]HOME && {
753         test -n "$verbose" && echo "    ... testing $3-directories under [$]HOME"
754         test -d [$]HOME/$3 &&          $1="[$]$1 [$]HOME/$3"
755         test -d [$]HOME/$3/$2 &&       $1="[$]$1 [$]HOME/$3/$2"
756         test -d [$]HOME/$3/$2/$3 &&    $1="[$]$1 [$]HOME/$3/$2/$3"
757 }
758
759 # For other stuff under the home directory, it should be sufficient to put
760 # a symbolic link for $HOME/$2 to the actual package location:
761 test -d [$]HOME/$2 && {
762         test -n "$verbose" && echo "    ... testing $3-directories under [$]HOME/$2"
763         test -d [$]HOME/$2/$3 &&       $1="[$]$1 [$]HOME/$2/$3"
764         test -d [$]HOME/$2/$3/$2 &&    $1="[$]$1 [$]HOME/$2/$3/$2"
765 }
766
767 test "$prefix" != /usr/local && \
768 test -d /usr/local && {
769         test -n "$verbose" && echo "    ... testing $3-directories under /usr/local"
770         test -d /usr/local/$3 &&       $1="[$]$1 /usr/local/$3"
771         test -d /usr/local/$3/$2 &&    $1="[$]$1 /usr/local/$3/$2"
772         test -d /usr/local/$3/$2/$3 && $1="[$]$1 /usr/local/$3/$2/$3"
773         test -d /usr/local/$2/$3 &&    $1="[$]$1 /usr/local/$2/$3"
774         test -d /usr/local/$2/$3/$2 && $1="[$]$1 /usr/local/$2/$3/$2"
775 }
776
777 test "$prefix" != NONE && \
778 test -d $prefix && {
779         test -n "$verbose" && echo "    ... testing $3-directories under $prefix"
780         test -d $prefix/$3 &&          $1="[$]$1 $prefix/$3"
781         test -d $prefix/$3/$2 &&       $1="[$]$1 $prefix/$3/$2"
782         test -d $prefix/$3/$2/$3 &&    $1="[$]$1 $prefix/$3/$2/$3"
783         test -d $prefix/$2/$3 &&       $1="[$]$1 $prefix/$2/$3"
784         test -d $prefix/$2/$3/$2 &&    $1="[$]$1 $prefix/$2/$3/$2"
785 }
786
787 test "$prefix" != /opt && \
788 test -d /opt && {
789         test -n "$verbose" && echo "    ... testing $3-directories under /opt"
790         test -d /opt/$3 &&             $1="[$]$1 /opt/$3"
791         test -d /opt/$3/$2 &&          $1="[$]$1 /opt/$3/$2"
792         test -d /opt/$3/$2/$3 &&       $1="[$]$1 /opt/$3/$2/$3"
793         test -d /opt/$2/$3 &&          $1="[$]$1 /opt/$2/$3"
794         test -d /opt/$2/$3/$2 &&       $1="[$]$1 /opt/$2/$3/$2"
795 }
796
797 test "$prefix" != /usr && \
798 test -d /usr && {
799         test -n "$verbose" && echo "    ... testing $3-directories under /usr"
800         test -d /usr/$3 &&             $1="[$]$1 /usr/$3"
801         test -d /usr/$3/$2 &&          $1="[$]$1 /usr/$3/$2"
802         test -d /usr/$3/$2/$3 &&       $1="[$]$1 /usr/$3/$2/$3"
803         test -d /usr/$2/$3 &&          $1="[$]$1 /usr/$2/$3"
804 }
805 ])dnl
806 dnl ---------------------------------------------------------------------------
807 dnl CF_SYS_TIME_SELECT version: 4 updated: 2000/10/04 09:18:40
808 dnl ------------------
809 dnl Check if we can include <sys/time.h> with <sys/select.h>; this breaks on
810 dnl older SCO configurations.
811 AC_DEFUN([CF_SYS_TIME_SELECT],
812 [
813 AC_MSG_CHECKING(if sys/time.h works with sys/select.h)
814 AC_CACHE_VAL(cf_cv_sys_time_select,[
815 AC_TRY_COMPILE([
816 #include <sys/types.h>
817 #ifdef HAVE_SYS_TIME_H
818 #include <sys/time.h>
819 #endif
820 #ifdef HAVE_SYS_SELECT_H
821 #include <sys/select.h>
822 #endif
823 ],[],[cf_cv_sys_time_select=yes],
824      [cf_cv_sys_time_select=no])
825      ])
826 AC_MSG_RESULT($cf_cv_sys_time_select)
827 test "$cf_cv_sys_time_select" = yes && AC_DEFINE(HAVE_SYS_TIME_SELECT)
828 ])dnl
829 dnl ---------------------------------------------------------------------------
830 dnl CF_UPPER version: 5 updated: 2001/01/29 23:40:59
831 dnl --------
832 dnl Make an uppercase version of a variable
833 dnl $1=uppercase($2)
834 AC_DEFUN([CF_UPPER],
835 [
836 $1=`echo "$2" | sed y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%`
837 ])dnl
838 dnl ---------------------------------------------------------------------------
839 dnl CF_UTF8_LIB version: 4 updated: 2003/03/01 18:36:42
840 dnl -----------
841 dnl Check for multibyte support, and if not found, utf8 compatibility library
842 AC_DEFUN([CF_UTF8_LIB],
843 [
844 AC_CACHE_CHECK(for multibyte character support,cf_cv_utf8_lib,[
845         cf_save_LIBS="$LIBS"
846         AC_TRY_LINK([
847 #include <stdlib.h>],[putwc(0,0);],
848         [cf_cv_utf8_lib=yes],
849         [LIBS="-lutf8 $LIBS"
850          AC_TRY_LINK([
851 #include <libutf8.h>],[putwc(0,0);],
852                 [cf_cv_utf8_lib=add-on],
853                 [cf_cv_utf8_lib=no])
854         LIBS="$cf_save_LIBS"
855 ])])
856
857 # HAVE_LIBUTF8_H is used by ncurses if curses.h is shared between
858 # ncurses/ncursesw:
859 if test "$cf_cv_utf8_lib" = "add-on" ; then
860         AC_DEFINE(HAVE_LIBUTF8_H)
861         LIBS="-lutf8 $LIBS"
862 fi
863 ])dnl
864 dnl ---------------------------------------------------------------------------
865 dnl CF_WITH_CURSES_DIR version: 2 updated: 2002/11/10 14:46:59
866 dnl ------------------
867 dnl Wrapper for AC_ARG_WITH to specify directory under which to look for curses
868 dnl libraries.
869 AC_DEFUN([CF_WITH_CURSES_DIR],[
870 AC_ARG_WITH(curses-dir,
871         [  --with-curses-dir=DIR   directory in which (n)curses is installed],
872         [CF_PATH_SYNTAX(withval)
873          cf_cv_curses_dir=$withval],
874         [cf_cv_curses_dir=no])
875 ])dnl