Free FS info before closing panel.
[kaloumi3.git] / m4.include / mc-with-screen.m4
blobf22f68a599603ab2ae2047595753ca41b1af1ae2
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     ac_slang_inc_path=[$1]
8     ac_slang_lib_path=[$2]
10     if test x"$ac_slang_inc_path" != x; then
11         ac_slang_inc_path="-I"$ac_slang_inc_path
12     fi
14     if test x"$ac_slang_lib_path" != x; then
15         ac_slang_lib_path="-L"$ac_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                 ],
61                 [
62                     AC_MSG_RESULT(no)
63                     found_slang=no
64                     error_msg_slang="Slang header not found"
65                 ]
66             )
67         ],
68     )
70     dnl Check if termcap is needed.
71     dnl This check must be done before anything is linked against S-Lang.
72     if test x"$found_slang" = x"yes"; then
73         CFLAGS="$saved_CFLAGS $ac_slang_inc_path $ac_slang_lib_path"
74         LDFLAGS="$saved_LDFLAGS $ac_slang_lib_path"
75         CPPFLAGS="$saved_CPPFLAGS $ac_slang_inc_path $ac_slang_lib_path"
77         MC_SLANG_TERMCAP
78         if test x"$mc_cv_slang_termcap"  = x"yes"; then
79             ac_slang_lib_path="$ac_slang_lib_path -ltermcap"
80             CFLAGS="$saved_CFLAGS $ac_slang_inc_path $ac_slang_lib_path"
81             CPPFLAGS="$saved_CPPFLAGS $ac_slang_inc_path $ac_slang_lib_path"
82             LDFLAGS="$saved_LDFLAGS $ac_slang_lib_path"
83         fi
84     fi
85     dnl Check the library
86     if test x"$found_slang" = x"yes"; then
87         unset ac_cv_lib_slang_SLang_init_tty
88         AC_CHECK_LIB(
89             [slang],
90             [SLang_init_tty],
91             [:],
92             [
93                 found_slang=no
94                 error_msg_slang="S-lang library not found"
95             ]
96         )
97     fi
98     dnl check if S-Lang have version 2.0 or newer
99     if test x"$found_slang" = x"yes"; then
100         AC_MSG_CHECKING([for S-Lang version 2.0 or newer])
101         AC_TRY_RUN([
102 #ifdef HAVE_SLANG_SLANG_H
103 #include <slang/slang.h>
104 #else
105 #include <slang.h>
106 #endif
107 int main (void)
109 #if SLANG_VERSION >= 20000
110     return 0;
111 #else
112     return 1;
113 #endif
116             [mc_slang_is_valid_version=yes],
117             [mc_slang_is_valid_version=no],
118             [mc_slang_is_valid_version=no]
119         )
120         if test x$mc_slang_is_valid_version = xno; then
121             found_slang=no
122             error_msg_slang="S-Lang library version 2.0 or newer not found"
123         fi
124         AC_MSG_RESULT($mc_slang_is_valid_version)
125     fi
127     dnl Unless external S-Lang was requested, reject S-Lang with UTF-8 hacks
128     if test x"$found_slang" = x"yes"; then
129         unset ac_cv_lib_slang_SLsmg_write_nwchars
130         AC_CHECK_LIB(
131             [slang],
132             [SLsmg_write_nwchars],
133             [
134                 found_slang=no
135                 error_msg_slang="Rejecting S-Lang with UTF-8 support, it's not fully supported yet"
136             ],
137             [:]
138         )
139     fi
141     if test x"$found_slang" = x"yes"; then
142         screen_type=slang
143         screen_msg="S-Lang library (installed on the system)"
145         AC_DEFINE(HAVE_SLANG, 1,
146             [Define to use S-Lang library for screen management])
148         MCLIBS="$MCLIBS $ac_slang_lib_path -lslang"
149         CFLAGS="$saved_CFLAGS"
150         dnl do not reset CPPFLAGS
151         dnl - if CPPFLAGS are resetted then cpp does not find the specified header
152         LDFLAGS="$saved_LDFLAGS"
153     else
154         CFLAGS="$saved_CFLAGS"
155         CPPFLAGS="$saved_CPPFLAGS"
156         LDFLAGS="$saved_LDFLAGS"
157     fi
161 dnl Use the slang library.
163 AC_DEFUN([MC_WITH_SLANG], [
164     with_screen=slang
165     found_slang=yes
166     error_msg_slang=""
168     AC_ARG_WITH([slang-includes],
169         AC_HELP_STRING([--with-slang-includes=@<:@DIR@:>@],
170             [set path to SLANG includes @<:@default=/usr/include@:>@; make sense only if --with-screen=slang]
171         ),
172         [ac_slang_inc_path="$withval"],
173         [ac_slang_inc_path=""]
174     )
176     AC_ARG_WITH([slang-libs],
177         AC_HELP_STRING([--with-slang-libs=@<:@DIR@:>@],
178             [set path to SLANG library @<:@default=/usr/lib@:>@; make sense only if --with-screen=slang]
179         ),
180         [ac_slang_lib_path="$withval"],
181         [ac_slang_lib_path=""]
182     )
183     echo 'checking SLANG-headers in default place ...'
184     MC_CHECK_SLANG_BY_PATH([$ac_slang_inc_path],[$ac_slang_lib_path])
185     if test x"$found_slang" = "xno"; then
186         ac_slang_inc_path="/usr/include"
187         ac_slang_lib_path="/usr/lib"
189         echo 'checking SLANG-headers in /usr ...'
190         MC_CHECK_SLANG_BY_PATH([$ac_slang_inc_path],[$ac_slang_lib_path])
191         if test x"$found_slang" = "xno"; then
192             ac_slang_inc_path="/usr/local/include"
193             ac_slang_lib_path="/usr/local/lib"
195             echo 'checking SLANG-headers in /usr/local ...'
196             MC_CHECK_SLANG_BY_PATH( $ac_slang_inc_path , $ac_slang_lib_path )
197             if test x"$found_slang" = "xno"; then
198                 AC_MSG_ERROR([$error_msg_slang])
199             fi
200         fi
201     fi
205 dnl check for ncurses in user supplied path
206 AC_DEFUN([MC_CHECK_NCURSES_BY_PATH], [
208     ac_ncurses_inc_path=[$1]
209     ac_ncurses_lib_path=[$2]
211     if test x"$ac_ncurses_inc_path" != x; then
212         ac_ncurses_inc_path="-I"$ac_ncurses_inc_path
213     fi
215     if test x"$ac_ncurses_lib_path" != x; then
216         ac_ncurses_lib_path="-L"$ac_ncurses_lib_path
217     fi
219     saved_CPPFLAGS="$CPPFLAGS"
220     CPPFLAGS="$CPPFLAGS $ac_ncurses_inc_path"
222     dnl Check for the headers
223     dnl Both headers should be in the same directory
224     dnl AIX term.h is unusable for mc
225     AC_MSG_CHECKING([for ncurses/ncurses.h and ncurses/term.h])
226     AC_PREPROC_IFELSE(
227         [
228             AC_LANG_PROGRAM([[#include <ncurses/ncurses.h>
229                               #include <ncurses/term.h>
230                             ]],[[return 0;]])
231         ],
232         [
233             AC_MSG_RESULT(yes)
234             if test x"$ac_ncurses_inc_path" = x; then
235                 ac_ncurses_inc_path="-I/usr/include"
236             fi
237             if test x"$ac_ncurses_lib_path" = x; then
238               ac_ncurses_lib_path="-L/usr/lib"
239             fi
240             found_ncurses=yes
241             AC_DEFINE(HAVE_NCURSES_NCURSES_H, 1,
242                       [Define to 1 if you have the <ncurses/ncurses.h> header file.])
243             AC_DEFINE(HAVE_NCURSES_TERM_H, 1,
244                       [Define to 1 if you have the <ncurses/term.h> header file.])
245         ],
246         [
247             AC_MSG_RESULT(no)
248             found_ncurses=no
249             error_msg_ncurses="ncurses header not found"
250         ],
251     )
253     if test x"$found_ncurses" = x"yes"; then
254         screen_type=ncurses
255         screen_msg="ncurses library (installed on the system)"
257         AC_DEFINE(HAVE_NCURSES, 1,
258                   [Define to use ncurses library for screen management])
260         MCLIBS="$MCLIBS $ac_ncurses_lib_path"
261     else
262         CPPFLAGS="$saved_CPPFLAGS"
263         AC_MSG_ERROR([$error_msg_ncurses])
264     fi
268 dnl Use the ncurses library.  It can only be requested explicitly,
269 dnl so just fail if anything goes wrong.
271 dnl If ncurses exports the ESCDELAY variable it should be set to 0
272 dnl or you'll have to press Esc three times to dismiss a dialog box.
274 AC_DEFUN([MC_WITH_NCURSES], [
275     dnl has_colors() is specific to ncurses, it's not in the old curses
276     save_LIBS="$LIBS"
277     ncursesw_found=
279     dnl get the user supplied include path
280     AC_ARG_WITH([ncurses-includes],
281         AC_HELP_STRING([--with-ncurses-includes=@<:@DIR@:>@],
282             [set path to ncurses includes @<:@default=/usr/include@:>@; make sense only if --with-screen=ncurses; for /usr/local/include/ncurses specify /usr/local/include]
283         ),
284         [ac_ncurses_inc_path="$withval"],
285         [ac_ncurses_inc_path=""]
286     )
288     dnl get the user supplied lib path
289     AC_ARG_WITH([ncurses-libs],
290         AC_HELP_STRING([--with-ncurses-libs=@<:@DIR@:>@],
291             [set path to ncurses library @<:@default=/usr/lib@:>@; make sense only if --with-screen=ncurses]
292         ),
293         [ac_ncurses_lib_path="$withval"],
294         [ac_ncurses_lib_path=""]
295     )
297     dnl we need at least the inc path, the lib may be in a std location
298     if test x"$ac_ncurses_inc_path" != x; then
299         dnl check the user supplied location
300         MC_CHECK_NCURSES_BY_PATH([$ac_ncurses_inc_path],[$ac_ncurses_lib_path])
302         LIBS=
303         AC_SEARCH_LIBS([has_colors], [ncurses], [MCLIBS="$MCLIBS $LIBS"], 
304                        [AC_MSG_ERROR([Cannot find ncurses library])])
306         screen_type=ncurses
307         screen_msg="ncurses library"
308         AC_DEFINE(USE_NCURSES, 1, 
309                   [Define to use ncurses for screen management])
310     else
311         LIBS=
312         AC_SEARCH_LIBS([addwstr], [ncursesw ncurses curses], [MCLIBS="$MCLIBS $LIBS";ncursesw_found=yes],
313                        [AC_MSG_WARN([Cannot find ncurses library, that support wide characters])])
315         if test x"$ncursesw_found" = "x"; then
316             LIBS=
317             AC_SEARCH_LIBS([has_colors], [ncurses curses], [MCLIBS="$MCLIBS $LIBS"], 
318                            [AC_MSG_ERROR([Cannot find ncurses library])])
319         fi
321         dnl Check the header
322         ncurses_h_found=
323         AC_CHECK_HEADERS([ncursesw/curses.h ncurses/curses.h ncurses.h curses.h], 
324                          [ncurses_h_found=yes; break])
326         if test x"$ncurses_h_found" = "x"; then
327             AC_MSG_ERROR([Cannot find ncurses header file])
328         fi
330         screen_type=ncurses
331         screen_msg="ncurses library"
332         AC_DEFINE(USE_NCURSES, 1, 
333                   [Define to use ncurses for screen management])
334     fi
336     dnl check for ESCDELAY
337     AC_CACHE_CHECK([for ESCDELAY variable],
338                    [mc_cv_ncurses_escdelay],
339                    [AC_TRY_LINK([], [
340                         extern int ESCDELAY;
341                         ESCDELAY = 0;
342                         ],
343                         [mc_cv_ncurses_escdelay=yes],
344                         [mc_cv_ncurses_escdelay=no])
345     ])
346     if test x"$mc_cv_ncurses_escdelay" = xyes; then
347         AC_DEFINE(HAVE_ESCDELAY, 1, 
348                   [Define if ncurses has ESCDELAY variable])
349     fi
351     dnl check for resizeterm
352     AC_CHECK_FUNCS(resizeterm)
353     LIBS="$save_LIBS"
357 dnl Use the ncursesw library.  It can only be requested explicitly,
358 dnl so just fail if anything goes wrong.
360 dnl If ncursesw exports the ESCDELAY variable it should be set to 0
361 dnl or you'll have to press Esc three times to dismiss a dialog box.
364 AC_DEFUN([MC_WITH_NCURSESW], [
365     dnl has_colors() is specific to ncurses, it's not in the old curses
366     save_LIBS="$LIBS"
367     LIBS=
368     AC_SEARCH_LIBS([has_colors], [ncursesw], [MCLIBS="$MCLIBS $LIBS"],
369                    [AC_MSG_ERROR([Cannot find ncursesw library])])
371     dnl Check the header
372     ncurses_h_found=
373     AC_CHECK_HEADERS([ncursesw/curses.h],
374                      [ncursesw_h_found=yes; break])
376     if test  x"$ncursesw_h_found" = "x"; then
377         AC_MSG_ERROR([Cannot find ncursesw header file])
378     fi
380     screen_type=ncursesw
381     screen_msg="ncursesw library"
382     AC_DEFINE(USE_NCURSESW, 1,
383               [Define to use ncursesw for screen management])
385     AC_CACHE_CHECK([for ESCDELAY variable],
386                    [mc_cv_ncursesw_escdelay],
387                    [AC_TRY_LINK([], [
388                         extern int ESCDELAY;
389                         ESCDELAY = 0;
390                         ],
391                         [mc_cv_ncursesw_escdelay=yes],
392                         [mc_cv_ncursesw_escdelay=no])
393     ])
394     if test x"$mc_cv_ncursesw_escdelay" = xyes; then
395         AC_DEFINE(HAVE_ESCDELAY, 1,
396                   [Define if ncursesw has ESCDELAY variable])
397     fi
399     AC_CHECK_FUNCS(resizeterm)
400     LIBS="$save_LIBS"