1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_with_curses.html
3 # ===========================================================================
11 # This macro checks whether a SysV or X/Open-compatible Curses library is
12 # present, along with the associated header file. The NcursesW
13 # (wide-character) library is searched for first, followed by Ncurses,
14 # then the system-default plain Curses. The first library found is the
17 # The following options are understood: --with-ncursesw, --with-ncurses,
18 # --without-ncursesw, --without-ncurses. The "--with" options force the
19 # macro to use that particular library, terminating with an error if not
20 # found. The "--without" options simply skip the check for that library.
21 # The effect on the search pattern is:
23 # (no options) - NcursesW, Ncurses, Curses
24 # --with-ncurses --with-ncursesw - NcursesW only [*]
25 # --without-ncurses --with-ncursesw - NcursesW only [*]
26 # --with-ncursesw - NcursesW only [*]
27 # --with-ncurses --without-ncursesw - Ncurses only [*]
28 # --with-ncurses - NcursesW, Ncurses [**]
29 # --without-ncurses --without-ncursesw - Curses only
30 # --without-ncursesw - Ncurses, Curses
31 # --without-ncurses - NcursesW, Curses
33 # [*] If the library is not found, abort the configure script.
35 # [**] If the second library (Ncurses) is not found, abort configure.
37 # The following preprocessor symbols may be defined by this macro if the
38 # appropriate conditions are met:
40 # HAVE_CURSES - if any SysV or X/Open Curses library found
41 # HAVE_CURSES_ENHANCED - if library supports X/Open Enhanced functions
42 # HAVE_CURSES_COLOR - if library supports color (enhanced functions)
43 # HAVE_CURSES_OBSOLETE - if library supports certain obsolete features
44 # HAVE_NCURSESW - if NcursesW (wide char) library is to be used
45 # HAVE_NCURSES - if the Ncurses library is to be used
47 # HAVE_CURSES_H - if <curses.h> is present and should be used
48 # HAVE_NCURSESW_H - if <ncursesw.h> should be used
49 # HAVE_NCURSES_H - if <ncurses.h> should be used
50 # HAVE_NCURSESW_CURSES_H - if <ncursesw/curses.h> should be used
51 # HAVE_NCURSES_CURSES_H - if <ncurses/curses.h> should be used
53 # (These preprocessor symbols are discussed later in this document.)
55 # The following output variable is defined by this macro; it is precious
56 # and may be overridden on the ./configure command line:
58 # CURSES_LIB - library to add to xxx_LDADD
60 # The library listed in CURSES_LIB is NOT added to LIBS by default. You
61 # need to add CURSES_LIB to the appropriate xxx_LDADD line in your
62 # Makefile.am. For example:
64 # prog_LDADD = @CURSES_LIB@
66 # If CURSES_LIB is set on the configure command line (such as by running
67 # "./configure CURSES_LIB=-lmycurses"), then the only header searched for
68 # is <curses.h>. The user may use the CPPFLAGS precious variable to
69 # override the standard #include search path. If the user needs to
70 # specify an alternative path for a library (such as for a non-standard
71 # NcurseW), the user should use the LDFLAGS variable.
73 # The following shell variables may be defined by this macro:
75 # ax_cv_curses - set to "yes" if any Curses library found
76 # ax_cv_curses_enhanced - set to "yes" if Enhanced functions present
77 # ax_cv_curses_color - set to "yes" if color functions present
78 # ax_cv_curses_obsolete - set to "yes" if obsolete features present
80 # ax_cv_ncursesw - set to "yes" if NcursesW library found
81 # ax_cv_ncurses - set to "yes" if Ncurses library found
82 # ax_cv_plaincurses - set to "yes" if plain Curses library found
83 # ax_cv_curses_which - set to "ncursesw", "ncurses", "plaincurses" or "no"
85 # These variables can be used in your configure.ac to determine the level
86 # of support you need from the Curses library. For example, if you must
87 # have either Ncurses or NcursesW, you could include:
90 # if test "x$ax_cv_ncursesw" != xyes && test "x$ax_cv_ncurses" != xyes; then
91 # AC_MSG_ERROR([requires either NcursesW or Ncurses library])
94 # If any Curses library will do (but one must be present and must support
95 # color), you could use:
98 # if test "x$ax_cv_curses" != xyes || test "x$ax_cv_curses_color" != xyes; then
99 # AC_MSG_ERROR([requires an X/Open-compatible Curses library with color])
102 # Certain preprocessor symbols and shell variables defined by this macro
103 # can be used to determine various features of the Curses library. In
104 # particular, HAVE_CURSES and ax_cv_curses are defined if the Curses
105 # library found conforms to the traditional SysV and/or X/Open Base Curses
106 # definition. Any working Curses library conforms to this level.
108 # HAVE_CURSES_ENHANCED and ax_cv_curses_enhanced are defined if the
109 # library supports the X/Open Enhanced Curses definition. In particular,
110 # the wide-character types attr_t, cchar_t and wint_t, the functions
111 # wattr_set() and wget_wch() and the macros WA_NORMAL and _XOPEN_CURSES
112 # are checked. The Ncurses library does NOT conform to this definition,
113 # although NcursesW does.
115 # HAVE_CURSES_COLOR and ax_cv_curses_color are defined if the library
116 # supports color functions and macros such as COLOR_PAIR, A_COLOR,
117 # COLOR_WHITE, COLOR_RED and init_pair(). These are NOT part of the
118 # X/Open Base Curses definition, but are part of the Enhanced set of
119 # functions. The Ncurses library DOES support these functions, as does
122 # HAVE_CURSES_OBSOLETE and ax_cv_curses_obsolete are defined if the
123 # library supports certain features present in SysV and BSD Curses but not
124 # defined in the X/Open definition. In particular, the functions
125 # getattrs(), getcurx() and getmaxx() are checked.
127 # To use the HAVE_xxx_H preprocessor symbols, insert the following into
128 # your system.h (or equivalent) header file:
130 # #if defined HAVE_NCURSESW_CURSES_H
131 # # include <ncursesw/curses.h>
132 # #elif defined HAVE_NCURSESW_H
133 # # include <ncursesw.h>
134 # #elif defined HAVE_NCURSES_CURSES_H
135 # # include <ncurses/curses.h>
136 # #elif defined HAVE_NCURSES_H
137 # # include <ncurses.h>
138 # #elif defined HAVE_CURSES_H
139 # # include <curses.h>
141 # # error "SysV or X/Open-compatible Curses header file required"
144 # For previous users of this macro: you should not need to change anything
145 # in your configure.ac or Makefile.am, as the previous (serial 10)
146 # semantics are still valid. However, you should update your system.h (or
147 # equivalent) header file to the fragment shown above. You are encouraged
148 # also to make use of the extended functionality provided by this version
149 # of AX_WITH_CURSES, as well as in the additional macros
150 # AX_WITH_CURSES_PANEL, AX_WITH_CURSES_MENU and AX_WITH_CURSES_FORM.
154 # Copyright (c) 2009 Mark Pulford <mark@kyne.com.au>
155 # Copyright (c) 2009 Damian Pietras <daper@daper.net>
156 # Copyright (c) 2012 Reuben Thomas <rrt@sc3d.org>
157 # Copyright (c) 2011 John Zaitseff <J.Zaitseff@zap.org.au>
159 # This program is free software: you can redistribute it and/or modify it
160 # under the terms of the GNU General Public License as published by the
161 # Free Software Foundation, either version 3 of the License, or (at your
162 # option) any later version.
164 # This program is distributed in the hope that it will be useful, but
165 # WITHOUT ANY WARRANTY; without even the implied warranty of
166 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
167 # Public License for more details.
169 # You should have received a copy of the GNU General Public License along
170 # with this program. If not, see <http://www.gnu.org/licenses/>.
172 # As a special exception, the respective Autoconf Macro's copyright owner
173 # gives unlimited permission to copy, distribute and modify the configure
174 # scripts that are the output of Autoconf when processing the Macro. You
175 # need not follow the terms of the GNU General Public License when using
176 # or distributing such scripts, even though portions of the text of the
177 # Macro appear in them. The GNU General Public License (GPL) does govern
178 # all other use of the material that constitutes the Autoconf Macro.
180 # This special exception to the GPL applies to versions of the Autoconf
181 # Macro released by the Autoconf Archive. When you make and distribute a
182 # modified version of the Autoconf Macro, you may extend this special
183 # exception to the GPL to apply to your modified version as well.
187 AU_ALIAS([MP_WITH_CURSES], [AX_WITH_CURSES])
188 AC_DEFUN([AX_WITH_CURSES], [
189 AC_ARG_VAR([CURSES_LIB], [linker library for Curses, e.g. -lcurses])
190 AC_ARG_WITH([ncurses], [AS_HELP_STRING([--with-ncurses],
191 [force the use of Ncurses or NcursesW])],
192 [], [with_ncurses=check])
193 AC_ARG_WITH([ncursesw], [AS_HELP_STRING([--without-ncursesw],
194 [do not use NcursesW (wide character support)])],
195 [], [with_ncursesw=check])
198 AS_IF([test "x$with_ncurses" = xyes || test "x$with_ncursesw" = xyes],
199 [ax_with_plaincurses=no], [ax_with_plaincurses=check])
201 ax_cv_curses_which=no
205 AS_IF([test "x$CURSES_LIB" = x && test "x$with_ncursesw" != xno], [
206 LIBS="$ax_saved_LIBS -lncursesw"
208 AC_CACHE_CHECK([for NcursesW wide-character library], [ax_cv_ncursesw], [
209 AC_LINK_IFELSE([AC_LANG_CALL([], [initscr])],
210 [ax_cv_ncursesw=yes], [ax_cv_ncursesw=no])
212 AS_IF([test "x$ax_cv_ncursesw" = xno && test "x$with_ncursesw" = xyes], [
213 AC_MSG_ERROR([--with-ncursesw specified but could not find NcursesW library])
216 AS_IF([test "x$ax_cv_ncursesw" = xyes], [
218 ax_cv_curses_which=ncursesw
219 CURSES_LIB="-lncursesw"
220 AC_DEFINE([HAVE_NCURSESW], [1], [Define to 1 if the NcursesW library is present])
221 AC_DEFINE([HAVE_CURSES], [1], [Define to 1 if a SysV or X/Open compatible Curses library is present])
223 AC_CACHE_CHECK([for working ncursesw/curses.h], [ax_cv_header_ncursesw_curses_h], [
224 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
225 @%:@define _XOPEN_SOURCE_EXTENDED 1
226 @%:@include <ncursesw/curses.h>
230 chtype c = COLOR_PAIR(1) & A_COLOR;
231 attr_t d = WA_NORMAL;
234 int g = getattrs(stdscr);
235 int h = getcurx(stdscr) + getmaxx(stdscr);
237 init_pair(1, COLOR_WHITE, COLOR_RED);
238 wattr_set(stdscr, d, 0, NULL);
239 wget_wch(stdscr, &f);
241 [ax_cv_header_ncursesw_curses_h=yes],
242 [ax_cv_header_ncursesw_curses_h=no])
244 AS_IF([test "x$ax_cv_header_ncursesw_curses_h" = xyes], [
245 ax_cv_curses_enhanced=yes
246 ax_cv_curses_color=yes
247 ax_cv_curses_obsolete=yes
248 AC_DEFINE([HAVE_CURSES_ENHANCED], [1], [Define to 1 if library supports X/Open Enhanced functions])
249 AC_DEFINE([HAVE_CURSES_COLOR], [1], [Define to 1 if library supports color (enhanced functions)])
250 AC_DEFINE([HAVE_CURSES_OBSOLETE], [1], [Define to 1 if library supports certain obsolete features])
251 AC_DEFINE([HAVE_NCURSESW_CURSES_H], [1], [Define to 1 if <ncursesw/curses.h> is present])
254 AC_CACHE_CHECK([for working ncursesw.h], [ax_cv_header_ncursesw_h], [
255 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
256 @%:@define _XOPEN_SOURCE_EXTENDED 1
257 @%:@include <ncursesw.h>
261 chtype c = COLOR_PAIR(1) & A_COLOR;
262 attr_t d = WA_NORMAL;
265 int g = getattrs(stdscr);
266 int h = getcurx(stdscr) + getmaxx(stdscr);
268 init_pair(1, COLOR_WHITE, COLOR_RED);
269 wattr_set(stdscr, d, 0, NULL);
270 wget_wch(stdscr, &f);
272 [ax_cv_header_ncursesw_h=yes],
273 [ax_cv_header_ncursesw_h=no])
275 AS_IF([test "x$ax_cv_header_ncursesw_h" = xyes], [
276 ax_cv_curses_enhanced=yes
277 ax_cv_curses_color=yes
278 ax_cv_curses_obsolete=yes
279 AC_DEFINE([HAVE_CURSES_ENHANCED], [1], [Define to 1 if library supports X/Open Enhanced functions])
280 AC_DEFINE([HAVE_CURSES_COLOR], [1], [Define to 1 if library supports color (enhanced functions)])
281 AC_DEFINE([HAVE_CURSES_OBSOLETE], [1], [Define to 1 if library supports certain obsolete features])
282 AC_DEFINE([HAVE_NCURSESW_H], [1], [Define to 1 if <ncursesw.h> is present])
285 AC_CACHE_CHECK([for working ncurses.h], [ax_cv_header_ncurses_h_with_ncursesw], [
286 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
287 @%:@define _XOPEN_SOURCE_EXTENDED 1
288 @%:@include <ncurses.h>
292 chtype c = COLOR_PAIR(1) & A_COLOR;
293 attr_t d = WA_NORMAL;
296 int g = getattrs(stdscr);
297 int h = getcurx(stdscr) + getmaxx(stdscr);
299 init_pair(1, COLOR_WHITE, COLOR_RED);
300 wattr_set(stdscr, d, 0, NULL);
301 wget_wch(stdscr, &f);
303 [ax_cv_header_ncurses_h_with_ncursesw=yes],
304 [ax_cv_header_ncurses_h_with_ncursesw=no])
306 AS_IF([test "x$ax_cv_header_ncurses_h_with_ncursesw" = xyes], [
307 ax_cv_curses_enhanced=yes
308 ax_cv_curses_color=yes
309 ax_cv_curses_obsolete=yes
310 AC_DEFINE([HAVE_CURSES_ENHANCED], [1], [Define to 1 if library supports X/Open Enhanced functions])
311 AC_DEFINE([HAVE_CURSES_COLOR], [1], [Define to 1 if library supports color (enhanced functions)])
312 AC_DEFINE([HAVE_CURSES_OBSOLETE], [1], [Define to 1 if library supports certain obsolete features])
313 AC_DEFINE([HAVE_NCURSES_H], [1], [Define to 1 if <ncurses.h> is present])
316 AS_IF([test "x$ax_cv_header_ncursesw_curses_h" = xno && test "x$ax_cv_header_ncursesw_h" = xno && test "x$ax_cv_header_ncurses_h_with_ncursesw" = xno], [
317 AC_MSG_WARN([could not find a working ncursesw/curses.h, ncursesw.h or ncurses.h])
324 AS_IF([test "x$CURSES_LIB" = x && test "x$with_ncurses" != xno && test "x$ax_cv_curses_which" = xno], [
325 LIBS="$ax_saved_LIBS -lncurses"
327 AC_CACHE_CHECK([for Ncurses library], [ax_cv_ncurses], [
328 AC_LINK_IFELSE([AC_LANG_CALL([], [initscr])],
329 [ax_cv_ncurses=yes], [ax_cv_ncurses=no])
331 AS_IF([test "x$ax_cv_ncurses" = xno && test "x$with_ncurses" = xyes], [
332 AC_MSG_ERROR([--with-ncurses specified but could not find Ncurses library])
335 AS_IF([test "x$ax_cv_ncurses" = xyes], [
337 ax_cv_curses_which=ncurses
338 CURSES_LIB="-lncurses"
339 AC_DEFINE([HAVE_NCURSES], [1], [Define to 1 if the Ncurses library is present])
340 AC_DEFINE([HAVE_CURSES], [1], [Define to 1 if a SysV or X/Open compatible Curses library is present])
342 AC_CACHE_CHECK([for working ncurses/curses.h], [ax_cv_header_ncurses_curses_h], [
343 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
344 @%:@include <ncurses/curses.h>
348 chtype c = COLOR_PAIR(1) & A_COLOR;
349 int g = getattrs(stdscr);
350 int h = getcurx(stdscr) + getmaxx(stdscr);
352 init_pair(1, COLOR_WHITE, COLOR_RED);
354 [ax_cv_header_ncurses_curses_h=yes],
355 [ax_cv_header_ncurses_curses_h=no])
357 AS_IF([test "x$ax_cv_header_ncurses_curses_h" = xyes], [
358 ax_cv_curses_color=yes
359 ax_cv_curses_obsolete=yes
360 AC_DEFINE([HAVE_CURSES_COLOR], [1], [Define to 1 if library supports color (enhanced functions)])
361 AC_DEFINE([HAVE_CURSES_OBSOLETE], [1], [Define to 1 if library supports certain obsolete features])
362 AC_DEFINE([HAVE_NCURSES_CURSES_H], [1], [Define to 1 if <ncurses/curses.h> is present])
365 AC_CACHE_CHECK([for working ncurses.h], [ax_cv_header_ncurses_h], [
366 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
367 @%:@include <ncurses.h>
371 chtype c = COLOR_PAIR(1) & A_COLOR;
372 int g = getattrs(stdscr);
373 int h = getcurx(stdscr) + getmaxx(stdscr);
375 init_pair(1, COLOR_WHITE, COLOR_RED);
377 [ax_cv_header_ncurses_h=yes],
378 [ax_cv_header_ncurses_h=no])
380 AS_IF([test "x$ax_cv_header_ncurses_h" = xyes], [
381 ax_cv_curses_color=yes
382 ax_cv_curses_obsolete=yes
383 AC_DEFINE([HAVE_CURSES_COLOR], [1], [Define to 1 if library supports color (enhanced functions)])
384 AC_DEFINE([HAVE_CURSES_OBSOLETE], [1], [Define to 1 if library supports certain obsolete features])
385 AC_DEFINE([HAVE_NCURSES_H], [1], [Define to 1 if <ncurses.h> is present])
388 AS_IF([test "x$ax_cv_header_ncurses_curses_h" = xno && test "x$ax_cv_header_ncurses_h" = xno], [
389 AC_MSG_WARN([could not find a working ncurses/curses.h or ncurses.h])
394 # Test for plain Curses (or if CURSES_LIB was set by user)
396 AS_IF([test "x$with_plaincurses" != xno && test "x$ax_cv_curses_which" = xno], [
397 AS_IF([test "x$CURSES_LIB" != x], [
398 LIBS="$ax_saved_LIBS $CURSES_LIB"
400 LIBS="$ax_saved_LIBS -lcurses"
403 AC_CACHE_CHECK([for Curses library], [ax_cv_plaincurses], [
404 AC_LINK_IFELSE([AC_LANG_CALL([], [initscr])],
405 [ax_cv_plaincurses=yes], [ax_cv_plaincurses=no])
408 AS_IF([test "x$ax_cv_plaincurses" = xyes], [
410 ax_cv_curses_which=plaincurses
411 AS_IF([test "x$CURSES_LIB" = x], [
412 CURSES_LIB="-lcurses"
414 AC_DEFINE([HAVE_CURSES], [1], [Define to 1 if a SysV or X/Open compatible Curses library is present])
416 # Check for base conformance (and header file)
418 AC_CACHE_CHECK([for working curses.h], [ax_cv_header_curses_h], [
419 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
420 @%:@include <curses.h>
426 [ax_cv_header_curses_h=yes],
427 [ax_cv_header_curses_h=no])
429 AS_IF([test "x$ax_cv_header_curses_h" = xyes], [
430 AC_DEFINE([HAVE_CURSES_H], [1], [Define to 1 if <curses.h> is present])
432 # Check for X/Open Enhanced conformance
434 AC_CACHE_CHECK([for X/Open Enhanced Curses conformance], [ax_cv_plaincurses_enhanced], [
435 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
436 @%:@define _XOPEN_SOURCE_EXTENDED 1
437 @%:@include <curses.h>
438 @%:@ifndef _XOPEN_CURSES
439 @%:@error "this Curses library is not enhanced"
440 "this Curses library is not enhanced"
445 chtype c = COLOR_PAIR(1) & A_COLOR;
446 attr_t d = WA_NORMAL;
450 init_pair(1, COLOR_WHITE, COLOR_RED);
451 wattr_set(stdscr, d, 0, NULL);
452 wget_wch(stdscr, &f);
454 [ax_cv_plaincurses_enhanced=yes],
455 [ax_cv_plaincurses_enhanced=no])
457 AS_IF([test "x$ax_cv_plaincurses_enhanced" = xyes], [
458 ax_cv_curses_enhanced=yes
459 ax_cv_curses_color=yes
460 AC_DEFINE([HAVE_CURSES_ENHANCED], [1], [Define to 1 if library supports X/Open Enhanced functions])
461 AC_DEFINE([HAVE_CURSES_COLOR], [1], [Define to 1 if library supports color (enhanced functions)])
464 # Check for color functions
466 AC_CACHE_CHECK([for Curses color functions], [ax_cv_plaincurses_color], [
467 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
468 @%:@define _XOPEN_SOURCE_EXTENDED 1
469 @%:@include <curses.h>
473 chtype c = COLOR_PAIR(1) & A_COLOR;
475 init_pair(1, COLOR_WHITE, COLOR_RED);
477 [ax_cv_plaincurses_color=yes],
478 [ax_cv_plaincurses_color=no])
480 AS_IF([test "x$ax_cv_plaincurses_color" = xyes], [
481 ax_cv_curses_color=yes
482 AC_DEFINE([HAVE_CURSES_COLOR], [1], [Define to 1 if library supports color (enhanced functions)])
485 # Check for obsolete functions
487 AC_CACHE_CHECK([for obsolete Curses functions], [ax_cv_plaincurses_obsolete], [
488 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
489 @%:@include <curses.h>
493 int g = getattrs(stdscr);
494 int h = getcurx(stdscr) + getmaxx(stdscr);
497 [ax_cv_plaincurses_obsolete=yes],
498 [ax_cv_plaincurses_obsolete=no])
500 AS_IF([test "x$ax_cv_plaincurses_obsolete" = xyes], [
501 ax_cv_curses_obsolete=yes
502 AC_DEFINE([HAVE_CURSES_OBSOLETE], [1], [Define to 1 if library supports certain obsolete features])
506 AS_IF([test "x$ax_cv_header_curses_h" = xno], [
507 AC_MSG_WARN([could not find a working curses.h])
512 AS_IF([test "x$ax_cv_curses" != xyes], [ax_cv_curses=no])
513 AS_IF([test "x$ax_cv_curses_enhanced" != xyes], [ax_cv_curses_enhanced=no])
514 AS_IF([test "x$ax_cv_curses_color" != xyes], [ax_cv_curses_color=no])
515 AS_IF([test "x$ax_cv_curses_obsolete" != xyes], [ax_cv_curses_obsolete=no])