(copy_dir_dir): get rid of extra string duplication.
[midnight-commander.git] / m4.include / mc-with-screen-slang.m4
blob8e83e6a9c29bc7b0e52248655ca3fd1aaf781d11
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="S-Lang 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([AC_LANG_SOURCE([
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
95 ])],
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
127         dnl Check the library
128         unset ac_cv_lib_slang_SLang_init_tty
129         AC_CHECK_LIB(
130             [slang],
131             [SLang_init_tty],
132             [:],
133             [
134                 found_slang=no
135                 error_msg_slang="S-Lang library not found"
136             ]
137         )
138     fi
140     if test x"$found_slang" = x"yes"; then
141         screen_type=slang
142         screen_msg="S-Lang library"
144         MCLIBS="$ac_slang_lib_path -lslang $MCLIBS"
145         CFLAGS="$ac_slang_inc_path $saved_CFLAGS"
146         dnl do not reset CPPFLAGS
147         dnl - if CPPFLAGS are reset then cpp does not find the specified header
148         LDFLAGS="$saved_LDFLAGS"
149     else
150         CFLAGS="$saved_CFLAGS"
151         CPPFLAGS="$saved_CPPFLAGS"
152         LDFLAGS="$saved_LDFLAGS"
153     fi
157 dnl Use the slang library.
159 AC_DEFUN([MC_WITH_SLANG], [
160     with_screen=slang
161     found_slang=yes
162     error_msg_slang=""
164     AC_ARG_WITH([slang-includes],
165         AS_HELP_STRING([--with-slang-includes=@<:@DIR@:>@],
166             [set path to S-Lang includes @<:@default=/usr/include@:>@; make sense only if --with-screen=slang]
167         ),
168         [ac_slang_inc_path="$withval"],
169         [ac_slang_inc_path=""]
170     )
172     AC_ARG_WITH([slang-libs],
173         AS_HELP_STRING([--with-slang-libs=@<:@DIR@:>@],
174             [set path to S-Lang library @<:@default=/usr/lib@:>@; make sense only if --with-screen=slang]
175         ),
176         [ac_slang_lib_path="$withval"],
177         [ac_slang_lib_path=""]
178     )
179     if test x"$ac_slang_lib_path" != x -o x"$ac_slang_inc_path" != x; then
180         echo 'checking S-Lang headers in specified place ...'
181         MC_CHECK_SLANG_BY_PATH([$ac_slang_inc_path],[$ac_slang_lib_path])
182     else
183         found_slang=no
184         PKG_CHECK_MODULES(SLANG, [slang >= 2.0], [found_slang=yes], [:])
185         if test x"$found_slang" = "xyes"; then
186             MCLIBS="$pkg_cv_SLANG_LIBS $MCLIBS"
187             CFLAGS="$pkg_cv_SLANG_CFLAGS $CFLAGS"
188         fi
189     fi
191     if test x"$found_slang" = "xno"; then
192         found_slang=yes
193         ac_slang_inc_path="/usr/include"
194         ac_slang_lib_path="/usr/lib"
196         echo 'checking S-Lang headers in /usr ...'
197         MC_CHECK_SLANG_BY_PATH([$ac_slang_inc_path],[$ac_slang_lib_path])
198         if test x"$found_slang" = "xno"; then
199             found_slang=yes
200             ac_slang_inc_path="/usr/local/include"
201             ac_slang_lib_path="/usr/local/lib"
203             echo 'checking S-Lang headers in /usr/local ...'
204             MC_CHECK_SLANG_BY_PATH( $ac_slang_inc_path , $ac_slang_lib_path )
205             if test x"$found_slang" = "xno"; then
206                 AC_MSG_ERROR([$error_msg_slang])
207             fi
208         fi
209     fi
211     AC_DEFINE(HAVE_SLANG, 1, [Define to use S-Lang library for screen management])
213     MC_CHECK_SLANG_HEADER