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