1# ===========================================================================
2#   https://www.gnu.org/software/autoconf-archive/ax_with_curses_extra.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_WITH_CURSES_PANEL
8#   AX_WITH_CURSES_MENU
9#   AX_WITH_CURSES_FORM
10#
11# DESCRIPTION
12#
13#   These macros try to find additional libraries that often come with
14#   SysV-compatible Curses.  In particular, the Panel, Menu and Form
15#   libraries are searched, along with their header files.  These macros
16#   depend on AX_WITH_CURSES.
17#
18#   The following preprocessor symbols may be defined by these macros:
19#
20#     By AX_WITH_CURSES_PANEL:
21#
22#     HAVE_PANEL              - if the Panel library is present
23#     HAVE_PANEL_H            - if <panel.h> is present and should be used
24#     HAVE_NCURSES_PANEL_H    - if <ncurses/panel.h> should be used
25#     HAVE_NCURSESW_PANEL_H   - if <ncursesw/panel.h> should be used
26#
27#     By AX_WITH_CURSES_MENU:
28#
29#     HAVE_MENU               - if the Menu library is present
30#     HAVE_MENU_H             - if <menu.h> is present and should be used
31#     HAVE_NCURSES_MENU_H     - if <ncurses/menu.h> should be used
32#     HAVE_NCURSESW_MENU_H    - if <ncursesw/menu.h> should be used
33#
34#     By AX_WITH_CURSES_FORM:
35#
36#     HAVE_FORM               - if the Form library is present
37#     HAVE_FORM_H             - if <form.h> is present and should be used
38#     HAVE_NCURSES_FORM_H     - if <ncurses/form.h> should be used
39#     HAVE_NCURSESW_FORM_H    - if <ncursesw/form.h> should be used
40#
41#   The following output variables may be defined by these macros; these are
42#   precious and may be overridden on the ./configure command line:
43#
44#     PANEL_LIBS   - library to add to xxx_LDADD before CURSES_LIBS
45#     MENU_LIBS    - library to add to xxx_LDADD before CURSES_LIBS
46#     FORM_LIBS    - library to add to xxx_LDADD before CURSES_LIBS
47#
48#   In previous versions of this macro, the flags PANEL_LIB, MENU_LIB and
49#   FORM_LIB were defined. These have been renamed, in keeping with the
50#   variable scheme of PKG_CHECK_MODULES, which should eventually supersede
51#   the use of AX_WITH_CURSES and AX_WITH_CURSES_* macros. These libraries
52#   are NOT added to LIBS by default.  You need to add them to the
53#   appropriate xxx_LDADD line in your Makefile.am in front of the
54#   equivalent CURSES_LIBS incantation.  For example:
55#
56#     prog_LDADD = @PANEL_LIBS@ @CURSES_LIBS@
57#
58#   If one of the xxx_LIBS variables is set on the configure command line
59#   (such as by running "./configure PANEL_LIBS=-lmypanel"), then the header
60#   file searched must NOT contain a subpath.  In this case, in other words,
61#   only <panel.h> would be searched for.  The user may use the CPPFLAGS
62#   precious variable to override the standard #include search path.
63#
64#   The following shell variables may be defined by these macros:
65#
66#     ax_cv_panel   - set to "yes" if Panels library is present
67#     ax_cv_menu    - set to "yes" if Menu library is present
68#     ax_cv_form    - set to "yes" if Form library is present
69#
70#   These variables can be used in your configure.ac to determine whether a
71#   library you require is actually present.  For example:
72#
73#     AX_WITH_CURSES
74#     if test "x$ax_cv_curses" != xyes; then
75#         AC_MSG_ERROR([requires a SysV or X/Open-compatible Curses library])
76#     fi
77#     AX_WITH_CURSES_PANEL
78#     if test "x$ax_cv_panel" != xyes; then
79#         AC_MSG_ERROR([requires the Curses Panel library])
80#     fi
81#
82#   To use the HAVE_xxx_H preprocessor symbols, insert the following into
83#   your system.h (or equivalent) header file:
84#
85#     For AX_WITH_CURSES_PANEL:
86#
87#     #if defined HAVE_NCURSESW_PANEL_H
88#     #  include <ncursesw/panel.h>
89#     #elif defined HAVE_NCURSES_PANEL_H
90#     #  include <ncurses/panel.h>
91#     #elif defined HAVE_PANEL_H
92#     #  include <panel.h>
93#     #else
94#     #  error "SysV-compatible Curses Panel header file required"
95#     #endif
96#
97#     For AX_WITH_CURSES_MENU:
98#
99#     #if defined HAVE_NCURSESW_MENU_H
100#     #  include <ncursesw/menu.h>
101#     #elif defined HAVE_NCURSES_MENU_H
102#     #  include <ncurses/menu.h>
103#     #elif defined HAVE_MENU_H
104#     #  include <menu.h>
105#     #else
106#     #  error "SysV-compatible Curses Menu header file required"
107#     #endif
108#
109#     For AX_WITH_CURSES_FORM:
110#
111#     #if defined HAVE_NCURSESW_FORM_H
112#     #  include <ncursesw/form.h>
113#     #elif defined HAVE_NCURSES_FORM_H
114#     #  include <ncurses/form.h>
115#     #elif defined HAVE_FORM_H
116#     #  include <form.h>
117#     #else
118#     #  error "SysV-compatible Curses Form header file required"
119#     #endif
120#
121# LICENSE
122#
123#   Copyright (c) 2011 John Zaitseff <J.Zaitseff@zap.org.au>
124#
125#   This program is free software: you can redistribute it and/or modify it
126#   under the terms of the GNU General Public License as published by the
127#   Free Software Foundation, either version 3 of the License, or (at your
128#   option) any later version.
129#
130#   This program is distributed in the hope that it will be useful, but
131#   WITHOUT ANY WARRANTY; without even the implied warranty of
132#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
133#   Public License for more details.
134#
135#   You should have received a copy of the GNU General Public License along
136#   with this program. If not, see <https://www.gnu.org/licenses/>.
137#
138#   As a special exception, the respective Autoconf Macro's copyright owner
139#   gives unlimited permission to copy, distribute and modify the configure
140#   scripts that are the output of Autoconf when processing the Macro. You
141#   need not follow the terms of the GNU General Public License when using
142#   or distributing such scripts, even though portions of the text of the
143#   Macro appear in them. The GNU General Public License (GPL) does govern
144#   all other use of the material that constitutes the Autoconf Macro.
145#
146#   This special exception to the GPL applies to versions of the Autoconf
147#   Macro released by the Autoconf Archive. When you make and distribute a
148#   modified version of the Autoconf Macro, you may extend this special
149#   exception to the GPL to apply to your modified version as well.
150
151#serial 5
152
153AC_DEFUN([_AX_WITH_CURSES_CHECKEXTRA], [
154    dnl Parameter 1 is the variable name component, using uppercase letters only
155    dnl Parameter 2 is the printable library name
156    dnl Parameter 3 is the C code to try compiling and linking
157    dnl Parameter 4 is the header filename
158    dnl Parameter 5 is the library command line
159
160    AS_VAR_PUSHDEF([_AX_WITH_CURSES_CHECKEXTRA_have_var],        [HAVE_$1])dnl
161    AS_VAR_PUSHDEF([_AX_WITH_CURSES_CHECKEXTRA_cv_var],          [ax_cv_[]m4_tolower($1)])dnl
162    AS_VAR_PUSHDEF([_AX_WITH_CURSES_CHECKEXTRA_header_var],      [ax_cv_header_$4])dnl
163    AS_VAR_PUSHDEF([_AX_WITH_CURSES_CHECKEXTRA_have_header_var], [HAVE_[]m4_toupper($4)])dnl
164
165    ax_saved_LIBS=$LIBS
166    ax_saved_CPPFLAGS=$CPPFLAGS
167
168    AC_CACHE_CHECK([for Curses $2 library with $4], [_AX_WITH_CURSES_CHECKEXTRA_header_var], [
169        LIBS="$ax_saved_LIBS $5 $CURSES_LIBS"
170        CPPFLAGS="$ax_saved_CPPFLAGS $CURSES_CFLAGS"
171        AC_LINK_IFELSE([AC_LANG_PROGRAM([[
172                @%:@include <$4>
173            ]], [$3])],
174            [_AX_WITH_CURSES_CHECKEXTRA_header_var=yes],
175            [_AX_WITH_CURSES_CHECKEXTRA_header_var=no])
176    ])
177    AS_IF([test "x$[]_AX_WITH_CURSES_CHECKEXTRA_header_var" = xyes], [
178        _AX_WITH_CURSES_CHECKEXTRA_cv_var=yes
179        AS_LITERAL_IF([$5], [$1_LIBS="$5"])
180        AC_DEFINE([_AX_WITH_CURSES_CHECKEXTRA_have_var],        [1], [Define to 1 if the Curses $2 library is present])
181        AC_DEFINE([_AX_WITH_CURSES_CHECKEXTRA_have_header_var], [1], [Define to 1 if <$4> is present])
182    ], [
183        AS_IF([test "x$[]_AX_WITH_CURSES_CHECKEXTRA_cv_var" = xyes], [],
184            [_AX_WITH_CURSES_CHECKEXTRA_cv_var=no])
185    ])
186
187    LIBS=$ax_saved_LIBS
188    CPPFLAGS=$ax_saved_CPPFLAGS
189    unset ax_saved_LIBS
190    unset ax_saved_CPPFLAGS
191
192    AS_VAR_POPDEF([_AX_WITH_CURSES_CHECKEXTRA_have_header_var])dnl
193    AS_VAR_POPDEF([_AX_WITH_CURSES_CHECKEXTRA_header_var])dnl
194    AS_VAR_POPDEF([_AX_WITH_CURSES_CHECKEXTRA_cv_var])dnl
195    AS_VAR_POPDEF([_AX_WITH_CURSES_CHECKEXTRA_have_var])dnl
196])dnl
197
198AC_DEFUN([_AX_WITH_CURSES_EXTRA], [
199    dnl Parameter 1 is the variable name component, using uppercase letters only
200    dnl Parameter 2 is the printable library name
201    dnl Parameter 3 is the C code to try compiling and linking
202    dnl Parameter 4 is the header filename component
203    dnl Parameter 5 is the NCursesW library command line
204    dnl Parameter 6 is the NCurses library command line
205    dnl Parameter 7 is the plain Curses library command line
206
207    AC_REQUIRE([AX_WITH_CURSES])
208    AC_ARG_VAR([$1_LIBS], [linker library for Curses $2, e.g. $7])
209
210    AS_IF([test "x$[]$1_LIBS" != x], [
211        _AX_WITH_CURSES_CHECKEXTRA([$1], [$2], [$3], [$4], [$[]$1_LIBS])
212    ], [
213        AS_IF([test "x$ax_cv_curses_which" = xncursesw], [
214            _AX_WITH_CURSES_CHECKEXTRA([$1], [$2], [$3], [ncursesw/$4], [$5])
215        ], [test "x$ax_cv_curses_which" = xncurses], [
216            _AX_WITH_CURSES_CHECKEXTRA([$1], [$2], [$3], [$4], [$6])
217            AS_IF([test x$[]ax_cv_[]m4_tolower($1) != "xyes"], [
218                _AX_WITH_CURSES_CHECKEXTRA([$1], [$2], [$3], [ncurses/$4], [$6])
219            ])
220        ], [test "x$ax_cv_curses_which" = xplaincurses], [
221            _AX_WITH_CURSES_CHECKEXTRA([$1], [$2], [$3], [$4], [$7])
222        ])
223    ])
224])dnl
225
226AC_DEFUN([AX_WITH_CURSES_PANEL], [
227    _AX_WITH_CURSES_EXTRA([PANEL], [Panel], [[
228            WINDOW *win = newwin(0, 0, 0, 0);
229            PANEL *pan = new_panel(win);
230        ]], [panel.h], [-lpanelw], [-lpanel], [-lpanel])
231])dnl
232
233AC_DEFUN([AX_WITH_CURSES_MENU], [
234    _AX_WITH_CURSES_EXTRA([MENU], [Menu], [[
235            ITEM **mi;
236            MENU *m = new_menu(mi);
237        ]], [menu.h], [-lmenuw], [-lmenu], [-lmenu])
238])dnl
239
240AC_DEFUN([AX_WITH_CURSES_FORM], [
241    _AX_WITH_CURSES_EXTRA([FORM], [Form], [[
242            FIELD **ff;
243            FORM *f = new_form(ff);
244        ]], [form.h], [-lformw], [-lform], [-lform])
245])dnl
246