Merge branch '2947_quoting_in_user_menu'
[midnight-commander.git] / m4.include / mc-with-screen-slang.m4
blob6ae263fff669d61542338e61718e3f3907bf5d9d
2 dnl Check the header
3 AC_DEFUN([mc_CHECK_SLANG_HEADER], [
4     AC_MSG_CHECKING([for slang/slang.h])
5     AC_PREPROC_IFELSE(
6         [
7             AC_LANG_PROGRAM([#include <slang/slang.h>], [return 0;])
8         ],
9         [
10             AC_MSG_RESULT(yes)
11             AC_DEFINE(HAVE_SLANG_SLANG_H, 1, [Define to use slang.h])
12             found_slang=yes
13         ],
14         [
15             AC_MSG_RESULT(no)
16         ]
17     )
20 dnl
21 dnl Check if the system S-Lang library can be used.
22 dnl If not, and $1 is "strict", exit.
23 dnl
24 AC_DEFUN([mc_CHECK_SLANG_BY_PATH], [
26     param_slang_inc_path=[$1]
27     param_slang_lib_path=[$2]
29     if test x"$param_slang_inc_path" != x; then
30         ac_slang_inc_path="-I"$param_slang_inc_path
31     fi
33     if test x"$param_slang_lib_path" != x; then
34         ac_slang_lib_path="-L"$param_slang_lib_path
35     fi
37     saved_CPPFLAGS="$CPPFLAGS"
38     saved_LDFLAGS="$LDFLAGS"
40     CPPFLAGS="$saved_CPPFLAGS $ac_slang_inc_path"
41     LDFLAGS="$saved_LDFLAGS $ac_slang_lib_path"
43     AC_MSG_CHECKING([for slang.h])
44     AC_PREPROC_IFELSE(
45         [
46             AC_LANG_PROGRAM([#include <slang.h>], [return 0;])
47         ],
48         [
49             AC_MSG_RESULT(yes)
50             if test x"$ac_slang_inc_path" = x; then
51                 ac_slang_inc_path="-I/usr/include"
52             fi
53             if test x"$ac_slang_lib_path" = x; then
54                 ac_slang_lib_path="-L/usr/lib"
55             fi
56             found_slang=yes
57             AC_DEFINE(HAVE_SLANG_H, 1, [Define to use slang.h])
59         ],
60         [
61             AC_MSG_RESULT(no)
63             mc_CHECK_SLANG_HEADER
64             if test x"$found_slang" = xno; then
65                 error_msg_slang="S-Lang header not found"
66             else
67                 if test x"$ac_slang_inc_path" = x; then
68                     ac_slang_inc_path="-I/usr/include"
69                 fi
70                 if test x"$ac_slang_lib_path" = x; then
71                     ac_slang_lib_path="-L/usr/lib"
72                 fi
73                 CPPFLAGS="-DHAVE_SLANG_SLANG_H $CPPFLAGS"
74             fi
75         ],
76     )
77     dnl check if S-Lang have version 2.0 or newer
78     if test x"$found_slang" = x"yes"; then
79         AC_MSG_CHECKING([for S-Lang version 2.0 or newer])
80         AC_RUN_IFELSE([AC_LANG_SOURCE([
81 #ifdef HAVE_SLANG_SLANG_H
82 #include <slang/slang.h>
83 #else
84 #include <slang.h>
85 #endif
86 int main (void)
88 #if SLANG_VERSION >= 20000
89     return 0;
90 #else
91     return 1;
92 #endif
94 ])],
95             [mc_slang_is_valid_version=yes],
96             [mc_slang_is_valid_version=no],
97             [
98             if test -f "$param_slang_inc_path/slang/slang.h" ; then
99                 hdr_file="$param_slang_inc_path/slang/slang.h"
100             else
101                 hdr_file="$param_slang_inc_path/slang.h"
102             fi
103             mc_slang_is_valid_version=`grep '^#define SLANG_VERSION[[:space:]]' "$hdr_file"| sed s'/^#define SLANG_VERSION[[:space:]]*//'`
104             if test "$mc_slang_is_valid_version" -ge "20000"; then
105                 mc_slang_is_valid_version=yes
106             else
107                 mc_slang_is_valid_version=no
108             fi
109             ]
110         )
111         if test x$mc_slang_is_valid_version = xno; then
112             found_slang=no
113             error_msg_slang="S-Lang library version 2.0 or newer not found"
114         fi
115         AC_MSG_RESULT($mc_slang_is_valid_version)
116     fi
117     dnl Check if termcap is needed.
118     dnl This check must be done before anything is linked against S-Lang.
119     if test x"$found_slang" = x"yes"; then
120         mc_SLANG_TERMCAP
121         if test x"$mc_cv_slang_termcap"  = x"yes"; then
122             saved_CPPFLAGS="$saved_CPPFLAGS "
123             saved_LDFLAGS="-ltermcap $saved_LDFLAGS"
124         fi
126         dnl Check the library
127         unset ac_cv_lib_slang_SLang_init_tty
128         AC_CHECK_LIB(
129             [slang],
130             [SLang_init_tty],
131             [:],
132             [
133                 found_slang=no
134                 error_msg_slang="S-Lang library not found"
135             ]
136         )
137     fi
139     if test x"$found_slang" = x"yes"; then
140         screen_type=slang
141         screen_msg="S-Lang library"
143         MCLIBS="$ac_slang_lib_path -lslang $MCLIBS"
144         dnl do not reset CPPFLAGS
145         dnl if CPPFLAGS are reset then cpp does not find the specified header
146         CPPFLAGS="$ac_slang_inc_path $saved_CPPFLAGS"
147         LDFLAGS="$saved_LDFLAGS"
148     else
149         CPPFLAGS="$saved_CPPFLAGS"
150         LDFLAGS="$saved_LDFLAGS"
151     fi
155 dnl Use the slang library.
157 AC_DEFUN([mc_WITH_SLANG], [
158     with_screen=slang
159     found_slang=yes
160     error_msg_slang=""
162     AC_ARG_WITH([slang-includes],
163         AS_HELP_STRING([--with-slang-includes=@<:@DIR@:>@],
164             [set path to S-Lang includes @<:@default=/usr/include@:>@; make sense only if --with-screen=slang]
165         ),
166         [ac_slang_inc_path="$withval"],
167         [ac_slang_inc_path=""]
168     )
170     AC_ARG_WITH([slang-libs],
171         AS_HELP_STRING([--with-slang-libs=@<:@DIR@:>@],
172             [set path to S-Lang library @<:@default=/usr/lib@:>@; make sense only if --with-screen=slang]
173         ),
174         [ac_slang_lib_path="$withval"],
175         [ac_slang_lib_path=""]
176     )
177     if test x"$ac_slang_lib_path" != x -o x"$ac_slang_inc_path" != x; then
178         echo 'checking S-Lang headers in specified place ...'
179         mc_CHECK_SLANG_BY_PATH([$ac_slang_inc_path],[$ac_slang_lib_path])
180     else
181         found_slang=no
182         PKG_CHECK_MODULES(SLANG, [slang >= 2.0], [found_slang=yes], [:])
183         if test x"$found_slang" = "xyes"; then
184             MCLIBS="$pkg_cv_SLANG_LIBS $MCLIBS"
185             CPPFLAGS="$pkg_cv_SLANG_CFLAGS $CPPFLAGS"
186         fi
187     fi
189     if test x"$found_slang" = "xno"; then
190         found_slang=yes
191         ac_slang_inc_path="/usr/include"
192         ac_slang_lib_path="/usr/lib"
194         echo 'checking S-Lang headers in /usr ...'
195         mc_CHECK_SLANG_BY_PATH([$ac_slang_inc_path],[$ac_slang_lib_path])
196         if test x"$found_slang" = "xno"; then
197             found_slang=yes
198             ac_slang_inc_path="/usr/local/include"
199             ac_slang_lib_path="/usr/local/lib"
201             echo 'checking S-Lang headers in /usr/local ...'
202             mc_CHECK_SLANG_BY_PATH( $ac_slang_inc_path , $ac_slang_lib_path )
203             if test x"$found_slang" = "xno"; then
204                 AC_MSG_ERROR([$error_msg_slang])
205             fi
206         fi
207     fi
209     AC_DEFINE(HAVE_SLANG, 1, [Define to use S-Lang library for screen management])
211     mc_CHECK_SLANG_HEADER