Ticket #30: Support for x clipboard (fixup)
[midnight-commander.git] / m4.include / mc-with-screen-slang.m4
blob28dddb7159c54cac9b4d47210391e55dadc47332
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_CFLAGS="$CFLAGS"
38     saved_CPPFLAGS="$CPPFLAGS"
39     saved_LDFLAGS="$LDFLAGS"
41     CFLAGS="$CFLAGS $ac_slang_inc_path $ac_slang_lib_path"
42     CPPFLAGS="$saved_CPPFLAGS $ac_slang_inc_path $ac_slang_lib_path"
44     AC_MSG_CHECKING([for slang.h])
45     AC_PREPROC_IFELSE(
46         [
47             AC_LANG_PROGRAM([#include <slang.h>],[return 0;])
48         ],
49         [
50             AC_MSG_RESULT(yes)
51             if test x"$ac_slang_inc_path" = x; then
52                 ac_slang_inc_path="-I/usr/include"
53             fi
54             if test x"$ac_slang_lib_path" = x; then
55                 ac_slang_lib_path="-L/usr/lib"
56             fi
57             found_slang=yes
58             AC_DEFINE(HAVE_SLANG_H, 1,[Define to use slang.h])
60         ],
61         [
62             AC_MSG_RESULT(no)
64             MC_CHECK_SLANG_HEADER
65             if test x"$found_slang" = xno; then
66                 error_msg_slang="Slang header not found"
67             else
68                 if test x"$ac_slang_inc_path" = x; then
69                     ac_slang_inc_path="-I/usr/include"
70                 fi
71                 if test x"$ac_slang_lib_path" = x; then
72                     ac_slang_lib_path="-L/usr/lib"
73                 fi
74                 CFLAGS="-DHAVE_SLANG_SLANG_H $CFLAGS"
75             fi
76         ],
77     )
78     dnl check if S-Lang have version 2.0 or newer
79     if test x"$found_slang" = x"yes"; then
80         AC_MSG_CHECKING([for S-Lang version 2.0 or newer])
81         AC_RUN_IFELSE([
82 #ifdef HAVE_SLANG_SLANG_H
83 #include <slang/slang.h>
84 #else
85 #include <slang.h>
86 #endif
87 int main (void)
89 #if SLANG_VERSION >= 20000
90     return 0;
91 #else
92     return 1;
93 #endif
96             [mc_slang_is_valid_version=yes],
97             [mc_slang_is_valid_version=no],
98             [
99             if test -f "$param_slang_inc_path/slang/slang.h" ; then
100                 hdr_file="$param_slang_inc_path/slang/slang.h"
101             else
102                 hdr_file="$param_slang_inc_path/slang.h"
103             fi
104             mc_slang_is_valid_version=`grep '^#define SLANG_VERSION[[:space:]]' "$hdr_file"| sed s'/^#define SLANG_VERSION[[:space:]]*//'`
105             if test "$mc_slang_is_valid_version" -ge "20000"; then
106                 mc_slang_is_valid_version=yes
107             else
108                 mc_slang_is_valid_version=no
109             fi
110             ]
111         )
112         if test x$mc_slang_is_valid_version = xno; then
113             found_slang=no
114             error_msg_slang="S-Lang library version 2.0 or newer not found"
115         fi
116         AC_MSG_RESULT($mc_slang_is_valid_version)
117     fi
118     dnl Check if termcap is needed.
119     dnl This check must be done before anything is linked against S-Lang.
120     if test x"$found_slang" = x"yes"; then
121         MC_SLANG_TERMCAP
122         if test x"$mc_cv_slang_termcap"  = x"yes"; then
123             saved_CPPFLAGS="-ltermcap $saved_CPPFLAGS "
124             saved_LDFLAGS="-ltermcap $saved_LDFLAGS"
125         fi
128         dnl Check the library
129         unset ac_cv_lib_slang_SLang_init_tty
130         AC_CHECK_LIB(
131             [slang],
132             [SLang_init_tty],
133             [:],
134             [
135                 found_slang=no
136                 error_msg_slang="S-lang library not found"
137             ]
138         )
139     fi
141     dnl Unless external S-Lang was requested, reject S-Lang with UTF-8 hacks
142     if test x"$found_slang" = x"yes"; then
143         unset ac_cv_lib_slang_SLsmg_write_nwchars
144         AC_CHECK_LIB(
145             [slang],
146             [SLsmg_write_nwchars],
147             [
148                 found_slang=no
149                 error_msg_slang="Rejecting S-Lang with UTF-8 support, it's not fully supported yet"
150             ],
151             [:]
152         )
153     fi
155     if test x"$found_slang" = x"yes"; then
156         screen_type=slang
157         screen_msg="S-Lang library (installed on the system)"
159         MCLIBS="$ac_slang_lib_path -lslang $MCLIBS"
160         CFLAGS="$ac_slang_inc_path $saved_CFLAGS"
161         dnl do not reset CPPFLAGS
162         dnl - if CPPFLAGS are resetted then cpp does not find the specified header
163         LDFLAGS="$saved_LDFLAGS"
164     else
165         CFLAGS="$saved_CFLAGS"
166         CPPFLAGS="$saved_CPPFLAGS"
167         LDFLAGS="$saved_LDFLAGS"
168     fi
172 dnl Use the slang library.
174 AC_DEFUN([MC_WITH_SLANG], [
175     with_screen=slang
176     found_slang=yes
177     error_msg_slang=""
179     AC_ARG_WITH([slang-includes],
180         AC_HELP_STRING([--with-slang-includes=@<:@DIR@:>@],
181             [set path to SLANG includes @<:@default=/usr/include@:>@; make sense only if --with-screen=slang]
182         ),
183         [ac_slang_inc_path="$withval"],
184         [ac_slang_inc_path=""]
185     )
187     AC_ARG_WITH([slang-libs],
188         AC_HELP_STRING([--with-slang-libs=@<:@DIR@:>@],
189             [set path to SLANG library @<:@default=/usr/lib@:>@; make sense only if --with-screen=slang]
190         ),
191         [ac_slang_lib_path="$withval"],
192         [ac_slang_lib_path=""]
193     )
194     if test x"$ac_slang_lib_path" != x -o x"$ac_slang_inc_path" != x; then
195         echo 'checking SLANG-headers in specified place ...'
196         MC_CHECK_SLANG_BY_PATH([$ac_slang_inc_path],[$ac_slang_lib_path])
197     else
198         found_slang=no
199         PKG_CHECK_MODULES(SLANG, [slang >= 2.0], [found_slang=yes], [:])
200         if test x"$found_slang" = "xyes"; then
201             MCLIBS="$pkg_cv_SLANG_LIBS $MCLIBS"
202             CFLAGS="$pkg_cv_SLANG_CFLAGS $CFLAGS"
203         fi
204     fi
206     if test x"$found_slang" = "xno"; then
207         found_slang=yes
208         ac_slang_inc_path="/usr/include"
209         ac_slang_lib_path="/usr/lib"
211         echo 'checking SLANG-headers in /usr ...'
212         MC_CHECK_SLANG_BY_PATH([$ac_slang_inc_path],[$ac_slang_lib_path])
213         if test x"$found_slang" = "xno"; then
214             found_slang=yes
215             ac_slang_inc_path="/usr/local/include"
216             ac_slang_lib_path="/usr/local/lib"
218             echo 'checking SLANG-headers in /usr/local ...'
219             MC_CHECK_SLANG_BY_PATH( $ac_slang_inc_path , $ac_slang_lib_path )
220             if test x"$found_slang" = "xno"; then
221                 AC_MSG_ERROR([$error_msg_slang])
222             fi
223         fi
224     fi
226     AC_DEFINE(HAVE_SLANG, 1,
227         [Define to use S-Lang library for screen management])
229     MC_CHECK_SLANG_HEADER