(copy_dir_dir): get rid of extra string duplication.
[midnight-commander.git] / m4.include / mc-with-screen-ncurses.m4
blob14be9ed73ee4027fc2ba3ac493cc46e016120569
1 dnl check for ncurses in user supplied path
2 AC_DEFUN([MC_CHECK_NCURSES_BY_PATH], [
4     ac_ncurses_inc_path=[$1]
5     ac_ncurses_lib_path=[$2]
7     if test x"$ac_ncurses_inc_path" != x; then
8         ac_ncurses_inc_path="-I"$ac_ncurses_inc_path
9     fi
11     if test x"$ac_ncurses_lib_path" != x; then
12         ac_ncurses_lib_path="-L"$ac_ncurses_lib_path
13     fi
15     saved_CPPFLAGS="$CPPFLAGS"
16     CPPFLAGS="$CPPFLAGS $ac_ncurses_inc_path"
18     dnl Check for the headers
19     dnl Both headers should be in the same directory
20     dnl AIX term.h is unusable for mc
21     AC_MSG_CHECKING([for ncurses/ncurses.h and ncurses/term.h])
22     AC_PREPROC_IFELSE(
23         [
24             AC_LANG_PROGRAM([[#include <ncurses/ncurses.h>
25                               #include <ncurses/term.h>
26                             ]],[[return 0;]])
27         ],
28         [
29             AC_MSG_RESULT(yes)
30             if test x"$ac_ncurses_inc_path" = x; then
31                 ac_ncurses_inc_path="-I/usr/include"
32             fi
33             if test x"$ac_ncurses_lib_path" = x; then
34               ac_ncurses_lib_path="-L/usr/lib"
35             fi
36             found_ncurses=yes
37             AC_DEFINE(HAVE_NCURSES_NCURSES_H, 1,
38                       [Define to 1 if you have the <ncurses/ncurses.h> header file.])
39             AC_DEFINE(HAVE_NCURSES_TERM_H, 1,
40                       [Define to 1 if you have the <ncurses/term.h> header file.])
41         ],
42         [
43             AC_MSG_RESULT(no)
44             found_ncurses=no
45             error_msg_ncurses="ncurses header not found"
46         ],
47     )
49     if test x"$found_ncurses" = x"yes"; then
50         screen_type=ncurses
51         screen_msg="Ncurses library"
53         AC_DEFINE(HAVE_NCURSES, 1,
54                   [Define to use ncurses library for screen management])
56         MCLIBS="$MCLIBS $ac_ncurses_lib_path"
57     else
58         CPPFLAGS="$saved_CPPFLAGS"
59         AC_MSG_ERROR([$error_msg_ncurses])
60     fi
63 dnl
64 dnl Use the ncurses library.  It can only be requested explicitly,
65 dnl so just fail if anything goes wrong.
66 dnl
67 dnl If ncurses exports the ESCDELAY variable it should be set to 0
68 dnl or you'll have to press Esc three times to dismiss a dialog box.
69 dnl
70 AC_DEFUN([MC_WITH_NCURSES], [
71     dnl has_colors() is specific to ncurses, it's not in the old curses
72     save_LIBS="$LIBS"
73     ncursesw_found=
75     dnl get the user supplied include path
76     AC_ARG_WITH([ncurses-includes],
77         AS_HELP_STRING([--with-ncurses-includes=@<:@DIR@:>@],
78             [set path to ncurses includes @<:@default=/usr/include@:>@; make sense only if --with-screen=ncurses; for /usr/local/include/ncurses specify /usr/local/include]
79         ),
80         [ac_ncurses_inc_path="$withval"],
81         [ac_ncurses_inc_path=""]
82     )
84     dnl get the user supplied lib path
85     AC_ARG_WITH([ncurses-libs],
86         AS_HELP_STRING([--with-ncurses-libs=@<:@DIR@:>@],
87             [set path to ncurses library @<:@default=/usr/lib@:>@; make sense only if --with-screen=ncurses]
88         ),
89         [ac_ncurses_lib_path="$withval"],
90         [ac_ncurses_lib_path=""]
91     )
93     dnl we need at least the inc path, the lib may be in a std location
94     if test x"$ac_ncurses_inc_path" != x; then
95         dnl check the user supplied location
96         MC_CHECK_NCURSES_BY_PATH([$ac_ncurses_inc_path],[$ac_ncurses_lib_path])
98         LIBS=
99         AC_SEARCH_LIBS([has_colors], [ncurses], [MCLIBS="$MCLIBS $LIBS"], 
100                        [AC_MSG_ERROR([Cannot find ncurses library])])
102         screen_type=ncurses
103         screen_msg="Ncurses library"
104         AC_DEFINE(USE_NCURSES, 1, 
105                   [Define to use ncurses for screen management])
106     else
107         LIBS=
108         AC_SEARCH_LIBS([addwstr], [ncursesw ncurses curses], [MCLIBS="$MCLIBS $LIBS";ncursesw_found=yes],
109                        [AC_MSG_WARN([Cannot find ncurses library, that support wide characters])])
111         if test x"$ncursesw_found" = "x"; then
112             LIBS=
113             AC_SEARCH_LIBS([has_colors], [ncurses curses], [MCLIBS="$MCLIBS $LIBS"], 
114                            [AC_MSG_ERROR([Cannot find ncurses library])])
115         fi
117         dnl Check the header
118         ncurses_h_found=
119         AC_CHECK_HEADERS([ncursesw/curses.h ncurses/curses.h ncurses.h curses.h], 
120                          [ncurses_h_found=yes; break])
122         if test x"$ncurses_h_found" = "x"; then
123             AC_MSG_ERROR([Cannot find ncurses header file])
124         fi
126         screen_type=ncurses
127         screen_msg="Ncurses library"
128         AC_DEFINE(USE_NCURSES, 1, 
129                   [Define to use ncurses for screen management])
130     fi
132     dnl check for ESCDELAY
133     AC_CACHE_CHECK([for ESCDELAY variable],
134                    [mc_cv_ncurses_escdelay],
135                    [AC_TRY_LINK([], [
136                         extern int ESCDELAY;
137                         ESCDELAY = 0;
138                         ],
139                         [mc_cv_ncurses_escdelay=yes],
140                         [mc_cv_ncurses_escdelay=no])
141     ])
142     if test x"$mc_cv_ncurses_escdelay" = xyes; then
143         AC_DEFINE(HAVE_ESCDELAY, 1, 
144                   [Define if ncurses has ESCDELAY variable])
145     fi
147     dnl check for resizeterm
148     AC_CHECK_FUNCS(resizeterm)
149     LIBS="$save_LIBS"
153 dnl Use the ncursesw library.  It can only be requested explicitly,
154 dnl so just fail if anything goes wrong.
156 dnl If ncursesw exports the ESCDELAY variable it should be set to 0
157 dnl or you'll have to press Esc three times to dismiss a dialog box.
160 AC_DEFUN([MC_WITH_NCURSESW], [
161     dnl has_colors() is specific to ncurses, it's not in the old curses
162     save_LIBS="$LIBS"
163     LIBS=
164     AC_SEARCH_LIBS([has_colors], [ncursesw], [MCLIBS="$MCLIBS $LIBS"],
165                    [AC_MSG_ERROR([Cannot find ncursesw library])])
167     dnl Check the header
168     ncurses_h_found=
169     AC_CHECK_HEADERS([ncursesw/curses.h],
170                      [ncursesw_h_found=yes; break])
172     if test  x"$ncursesw_h_found" = "x"; then
173         AC_MSG_ERROR([Cannot find ncursesw header file])
174     fi
176     screen_type=ncursesw
177     screen_msg="Ncursesw library"
178     AC_DEFINE(USE_NCURSESW, 1,
179               [Define to use ncursesw for screen management])
181     AC_CACHE_CHECK([for ESCDELAY variable],
182                    [mc_cv_ncursesw_escdelay],
183                    [AC_TRY_LINK([], [
184                         extern int ESCDELAY;
185                         ESCDELAY = 0;
186                         ],
187                         [mc_cv_ncursesw_escdelay=yes],
188                         [mc_cv_ncursesw_escdelay=no])
189     ])
190     if test x"$mc_cv_ncursesw_escdelay" = xyes; then
191         AC_DEFINE(HAVE_ESCDELAY, 1,
192                   [Define if ncursesw has ESCDELAY variable])
193     fi
195     AC_CHECK_FUNCS(resizeterm)
196     LIBS="$save_LIBS"