Merge branch '2199_button_bar_mouse'
[midnight-commander.git] / m4.include / mc-with-screen.m4
blobde6eeaa46d1955caae4e2079fc559dfa9f45af4b
1 dnl
2 dnl Check if the system S-Lang library can be used.
3 dnl If not, and $1 is "strict", exit.
4 dnl
5 AC_DEFUN([MC_CHECK_SLANG_BY_PATH], [
7     param_slang_inc_path=[$1]
8     param_slang_lib_path=[$2]
10     if test x"$param_slang_inc_path" != x; then
11         ac_slang_inc_path="-I"$param_slang_inc_path
12     fi
14     if test x"$param_slang_lib_path" != x; then
15         ac_slang_lib_path="-L"$param_slang_lib_path
16     fi
18     saved_CFLAGS="$CFLAGS"
19     saved_CPPFLAGS="$CPPFLAGS"
20     saved_LDFLAGS="$LDFLAGS"
22     CFLAGS="$CFLAGS $ac_slang_inc_path $ac_slang_lib_path"
23     CPPFLAGS="$saved_CPPFLAGS $ac_slang_inc_path $ac_slang_lib_path"
25     dnl Check the header
26     AC_MSG_CHECKING([for slang.h])
27     AC_PREPROC_IFELSE(
28         [
29             AC_LANG_PROGRAM([#include <slang.h>],[return 0;])
30         ],
31         [
32             AC_MSG_RESULT(yes)
33             if test x"$ac_slang_inc_path" = x; then
34                 ac_slang_inc_path="-I/usr/include"
35             fi
36             if test x"$ac_slang_lib_path" = x; then
37                 ac_slang_lib_path="-L/usr/lib"
38             fi
39             found_slang=yes
40             AC_DEFINE(HAVE_SLANG_H, 1,[Define to use slang.h])
42         ],
43         [
44             AC_MSG_RESULT(no)
45             AC_MSG_CHECKING([for slang/slang.h])
46             AC_PREPROC_IFELSE(
47                 [
48                     AC_LANG_PROGRAM([#include <slang/slang.h>],[return 0;])
49                 ],
50                 [
51                     AC_MSG_RESULT(yes)
52                     if test x"$ac_slang_inc_path" = x; then
53                         ac_slang_inc_path="-I/usr/include"
54                     fi
55                     if test x"$ac_slang_lib_path" = x; then
56                         ac_slang_lib_path="-L/usr/lib"
57                     fi
58                     found_slang=yes
59                     AC_DEFINE(HAVE_SLANG_SLANG_H, 1,[Define to use slang.h])
60                     CFLAGS="-DHAVE_SLANG_SLANG_H $CFLAGS"
61                 ],
62                 [
63                     AC_MSG_RESULT(no)
64                     found_slang=no
65                     error_msg_slang="Slang header not found"
66                 ]
67             )
68         ],
69     )
70     dnl check if S-Lang have version 2.0 or newer
71     if test x"$found_slang" = x"yes"; then
72         AC_MSG_CHECKING([for S-Lang version 2.0 or newer])
73         AC_RUN_IFELSE([
74 #ifdef HAVE_SLANG_SLANG_H
75 #include <slang/slang.h>
76 #else
77 #include <slang.h>
78 #endif
79 int main (void)
81 #if SLANG_VERSION >= 20000
82     return 0;
83 #else
84     return 1;
85 #endif
88             [mc_slang_is_valid_version=yes],
89             [mc_slang_is_valid_version=no],
90             [
91             if test -f "$param_slang_inc_path/slang/slang.h" ; then
92                 hdr_file="$param_slang_inc_path/slang/slang.h"
93             else
94                 hdr_file="$param_slang_inc_path/slang.h"
95             fi
96             mc_slang_is_valid_version=`grep '^#define SLANG_VERSION[[:space:]]' "$hdr_file"| sed s'/^#define SLANG_VERSION[[:space:]]*//'`
97             if test "$mc_slang_is_valid_version" -ge "20000"; then
98                 mc_slang_is_valid_version=yes
99             else
100                 mc_slang_is_valid_version=no
101             fi
102             ]
103         )
104         if test x$mc_slang_is_valid_version = xno; then
105             found_slang=no
106             error_msg_slang="S-Lang library version 2.0 or newer not found"
107         fi
108         AC_MSG_RESULT($mc_slang_is_valid_version)
109     fi
111     dnl Check if termcap is needed.
112     dnl This check must be done before anything is linked against S-Lang.
113     if test x"$found_slang" = x"yes"; then
114         MC_SLANG_TERMCAP
115         if test x"$mc_cv_slang_termcap"  = x"yes"; then
116             saved_CPPFLAGS="-ltermcap $saved_CPPFLAGS "
117             saved_LDFLAGS="-ltermcap $saved_LDFLAGS"
118         fi
121         dnl Check the library
122         unset ac_cv_lib_slang_SLang_init_tty
123         AC_CHECK_LIB(
124             [slang],
125             [SLang_init_tty],
126             [:],
127             [
128                 found_slang=no
129                 error_msg_slang="S-lang library not found"
130             ]
131         )
132     fi
134     dnl Unless external S-Lang was requested, reject S-Lang with UTF-8 hacks
135     if test x"$found_slang" = x"yes"; then
136         unset ac_cv_lib_slang_SLsmg_write_nwchars
137         AC_CHECK_LIB(
138             [slang],
139             [SLsmg_write_nwchars],
140             [
141                 found_slang=no
142                 error_msg_slang="Rejecting S-Lang with UTF-8 support, it's not fully supported yet"
143             ],
144             [:]
145         )
146     fi
148     if test x"$found_slang" = x"yes"; then
149         screen_type=slang
150         screen_msg="S-Lang library (installed on the system)"
152         AC_DEFINE(HAVE_SLANG, 1,
153             [Define to use S-Lang library for screen management])
155         MCLIBS="$ac_slang_lib_path -lslang $MCLIBS"
156         CFLAGS="$ac_slang_inc_path $saved_CFLAGS"
157         dnl do not reset CPPFLAGS
158         dnl - if CPPFLAGS are resetted then cpp does not find the specified header
159         LDFLAGS="$saved_LDFLAGS"
160     else
161         CFLAGS="$saved_CFLAGS"
162         CPPFLAGS="$saved_CPPFLAGS"
163         LDFLAGS="$saved_LDFLAGS"
164     fi
168 dnl Use the slang library.
170 AC_DEFUN([MC_WITH_SLANG], [
171     with_screen=slang
172     found_slang=yes
173     error_msg_slang=""
175     AC_ARG_WITH([slang-includes],
176         AC_HELP_STRING([--with-slang-includes=@<:@DIR@:>@],
177             [set path to SLANG includes @<:@default=/usr/include@:>@; make sense only if --with-screen=slang]
178         ),
179         [ac_slang_inc_path="$withval"],
180         [ac_slang_inc_path=""]
181     )
183     AC_ARG_WITH([slang-libs],
184         AC_HELP_STRING([--with-slang-libs=@<:@DIR@:>@],
185             [set path to SLANG library @<:@default=/usr/lib@:>@; make sense only if --with-screen=slang]
186         ),
187         [ac_slang_lib_path="$withval"],
188         [ac_slang_lib_path=""]
189     )
190     if test x"$ac_slang_lib_path" != x -o x"$ac_slang_inc_path" != x; then
191         echo 'checking SLANG-headers in specified place ...'
192         MC_CHECK_SLANG_BY_PATH([$ac_slang_inc_path],[$ac_slang_lib_path])
193     else
194         found_slang=no
195         PKG_CHECK_MODULES(SLANG, [slang >= 2.0], [found_slang=yes], [:])
196         if test x"$found_slang" = "xyes"; then
197             MCLIBS="$SLANG_LIBS $MCLIBS"
198             CFLAGS="$SLANG_CFLAGS $CFLAGS"
199         fi
200     fi
202     if test x"$found_slang" = "xno"; then
203         found_slang=yes
204         ac_slang_inc_path="/usr/include"
205         ac_slang_lib_path="/usr/lib"
207         echo 'checking SLANG-headers in /usr ...'
208         MC_CHECK_SLANG_BY_PATH([$ac_slang_inc_path],[$ac_slang_lib_path])
209         if test x"$found_slang" = "xno"; then
210             found_slang=yes
211             ac_slang_inc_path="/usr/local/include"
212             ac_slang_lib_path="/usr/local/lib"
214             echo 'checking SLANG-headers in /usr/local ...'
215             MC_CHECK_SLANG_BY_PATH( $ac_slang_inc_path , $ac_slang_lib_path )
216             if test x"$found_slang" = "xno"; then
217                 AC_MSG_ERROR([$error_msg_slang])
218             fi
219         fi
220     fi
224 dnl check for ncurses in user supplied path
225 AC_DEFUN([MC_CHECK_NCURSES_BY_PATH], [
227     ac_ncurses_inc_path=[$1]
228     ac_ncurses_lib_path=[$2]
230     if test x"$ac_ncurses_inc_path" != x; then
231         ac_ncurses_inc_path="-I"$ac_ncurses_inc_path
232     fi
234     if test x"$ac_ncurses_lib_path" != x; then
235         ac_ncurses_lib_path="-L"$ac_ncurses_lib_path
236     fi
238     saved_CPPFLAGS="$CPPFLAGS"
239     CPPFLAGS="$CPPFLAGS $ac_ncurses_inc_path"
241     dnl Check for the headers
242     dnl Both headers should be in the same directory
243     dnl AIX term.h is unusable for mc
244     AC_MSG_CHECKING([for ncurses/ncurses.h and ncurses/term.h])
245     AC_PREPROC_IFELSE(
246         [
247             AC_LANG_PROGRAM([[#include <ncurses/ncurses.h>
248                               #include <ncurses/term.h>
249                             ]],[[return 0;]])
250         ],
251         [
252             AC_MSG_RESULT(yes)
253             if test x"$ac_ncurses_inc_path" = x; then
254                 ac_ncurses_inc_path="-I/usr/include"
255             fi
256             if test x"$ac_ncurses_lib_path" = x; then
257               ac_ncurses_lib_path="-L/usr/lib"
258             fi
259             found_ncurses=yes
260             AC_DEFINE(HAVE_NCURSES_NCURSES_H, 1,
261                       [Define to 1 if you have the <ncurses/ncurses.h> header file.])
262             AC_DEFINE(HAVE_NCURSES_TERM_H, 1,
263                       [Define to 1 if you have the <ncurses/term.h> header file.])
264         ],
265         [
266             AC_MSG_RESULT(no)
267             found_ncurses=no
268             error_msg_ncurses="ncurses header not found"
269         ],
270     )
272     if test x"$found_ncurses" = x"yes"; then
273         screen_type=ncurses
274         screen_msg="ncurses library (installed on the system)"
276         AC_DEFINE(HAVE_NCURSES, 1,
277                   [Define to use ncurses library for screen management])
279         MCLIBS="$MCLIBS $ac_ncurses_lib_path"
280     else
281         CPPFLAGS="$saved_CPPFLAGS"
282         AC_MSG_ERROR([$error_msg_ncurses])
283     fi
287 dnl Use the ncurses library.  It can only be requested explicitly,
288 dnl so just fail if anything goes wrong.
290 dnl If ncurses exports the ESCDELAY variable it should be set to 0
291 dnl or you'll have to press Esc three times to dismiss a dialog box.
293 AC_DEFUN([MC_WITH_NCURSES], [
294     dnl has_colors() is specific to ncurses, it's not in the old curses
295     save_LIBS="$LIBS"
296     ncursesw_found=
298     dnl get the user supplied include path
299     AC_ARG_WITH([ncurses-includes],
300         AC_HELP_STRING([--with-ncurses-includes=@<:@DIR@:>@],
301             [set path to ncurses includes @<:@default=/usr/include@:>@; make sense only if --with-screen=ncurses; for /usr/local/include/ncurses specify /usr/local/include]
302         ),
303         [ac_ncurses_inc_path="$withval"],
304         [ac_ncurses_inc_path=""]
305     )
307     dnl get the user supplied lib path
308     AC_ARG_WITH([ncurses-libs],
309         AC_HELP_STRING([--with-ncurses-libs=@<:@DIR@:>@],
310             [set path to ncurses library @<:@default=/usr/lib@:>@; make sense only if --with-screen=ncurses]
311         ),
312         [ac_ncurses_lib_path="$withval"],
313         [ac_ncurses_lib_path=""]
314     )
316     dnl we need at least the inc path, the lib may be in a std location
317     if test x"$ac_ncurses_inc_path" != x; then
318         dnl check the user supplied location
319         MC_CHECK_NCURSES_BY_PATH([$ac_ncurses_inc_path],[$ac_ncurses_lib_path])
321         LIBS=
322         AC_SEARCH_LIBS([has_colors], [ncurses], [MCLIBS="$MCLIBS $LIBS"], 
323                        [AC_MSG_ERROR([Cannot find ncurses library])])
325         screen_type=ncurses
326         screen_msg="ncurses library"
327         AC_DEFINE(USE_NCURSES, 1, 
328                   [Define to use ncurses for screen management])
329     else
330         LIBS=
331         AC_SEARCH_LIBS([addwstr], [ncursesw ncurses curses], [MCLIBS="$MCLIBS $LIBS";ncursesw_found=yes],
332                        [AC_MSG_WARN([Cannot find ncurses library, that support wide characters])])
334         if test x"$ncursesw_found" = "x"; then
335             LIBS=
336             AC_SEARCH_LIBS([has_colors], [ncurses curses], [MCLIBS="$MCLIBS $LIBS"], 
337                            [AC_MSG_ERROR([Cannot find ncurses library])])
338         fi
340         dnl Check the header
341         ncurses_h_found=
342         AC_CHECK_HEADERS([ncursesw/curses.h ncurses/curses.h ncurses.h curses.h], 
343                          [ncurses_h_found=yes; break])
345         if test x"$ncurses_h_found" = "x"; then
346             AC_MSG_ERROR([Cannot find ncurses header file])
347         fi
349         screen_type=ncurses
350         screen_msg="ncurses library"
351         AC_DEFINE(USE_NCURSES, 1, 
352                   [Define to use ncurses for screen management])
353     fi
355     dnl check for ESCDELAY
356     AC_CACHE_CHECK([for ESCDELAY variable],
357                    [mc_cv_ncurses_escdelay],
358                    [AC_TRY_LINK([], [
359                         extern int ESCDELAY;
360                         ESCDELAY = 0;
361                         ],
362                         [mc_cv_ncurses_escdelay=yes],
363                         [mc_cv_ncurses_escdelay=no])
364     ])
365     if test x"$mc_cv_ncurses_escdelay" = xyes; then
366         AC_DEFINE(HAVE_ESCDELAY, 1, 
367                   [Define if ncurses has ESCDELAY variable])
368     fi
370     dnl check for resizeterm
371     AC_CHECK_FUNCS(resizeterm)
372     LIBS="$save_LIBS"
376 dnl Use the ncursesw library.  It can only be requested explicitly,
377 dnl so just fail if anything goes wrong.
379 dnl If ncursesw exports the ESCDELAY variable it should be set to 0
380 dnl or you'll have to press Esc three times to dismiss a dialog box.
383 AC_DEFUN([MC_WITH_NCURSESW], [
384     dnl has_colors() is specific to ncurses, it's not in the old curses
385     save_LIBS="$LIBS"
386     LIBS=
387     AC_SEARCH_LIBS([has_colors], [ncursesw], [MCLIBS="$MCLIBS $LIBS"],
388                    [AC_MSG_ERROR([Cannot find ncursesw library])])
390     dnl Check the header
391     ncurses_h_found=
392     AC_CHECK_HEADERS([ncursesw/curses.h],
393                      [ncursesw_h_found=yes; break])
395     if test  x"$ncursesw_h_found" = "x"; then
396         AC_MSG_ERROR([Cannot find ncursesw header file])
397     fi
399     screen_type=ncursesw
400     screen_msg="ncursesw library"
401     AC_DEFINE(USE_NCURSESW, 1,
402               [Define to use ncursesw for screen management])
404     AC_CACHE_CHECK([for ESCDELAY variable],
405                    [mc_cv_ncursesw_escdelay],
406                    [AC_TRY_LINK([], [
407                         extern int ESCDELAY;
408                         ESCDELAY = 0;
409                         ],
410                         [mc_cv_ncursesw_escdelay=yes],
411                         [mc_cv_ncursesw_escdelay=no])
412     ])
413     if test x"$mc_cv_ncursesw_escdelay" = xyes; then
414         AC_DEFINE(HAVE_ESCDELAY, 1,
415                   [Define if ncursesw has ESCDELAY variable])
416     fi
418     AC_CHECK_FUNCS(resizeterm)
419     LIBS="$save_LIBS"