Original patch as attached on the bugreport
[midnight-commander.git] / acinclude.m4
blobf4c0e3bc5f6111df4a40ec563a49cfb66e0d9aaf
1 dnl MC_UNDELFS_CHECKS
2 dnl    Check for ext2fs undel support.
3 dnl    Set shell variable ext2fs_undel to "yes" if we have it,
4 dnl    "no" otherwise.  May define USE_EXT2FSLIB for cpp.
5 dnl    Will set EXT2FS_UNDEL_LIBS to required libraries.
7 AC_DEFUN([MC_UNDELFS_CHECKS], [
8   ext2fs_undel=no
9   EXT2FS_UNDEL_LIBS=
10   AC_CHECK_HEADERS([ext2fs/ext2_fs.h linux/ext2_fs.h], [ext2_fs_h=yes; break])
11   if test x$ext2_fs_h = xyes; then
12     AC_CHECK_HEADERS([ext2fs/ext2fs.h], [ext2fs_ext2fs_h=yes], ,
13                      [
14 #include <stdio.h>
15 #ifdef HAVE_EXT2FS_EXT2_FS_H
16 #include <ext2fs/ext2_fs.h>
17 #else
18 #undef umode_t
19 #include <linux/ext2_fs.h>
20 #endif
21                      ])
22     if test x$ext2fs_ext2fs_h = xyes; then
23       AC_DEFINE(USE_EXT2FSLIB, 1,
24                 [Define to enable undelete support on ext2])
25       ext2fs_undel=yes
26       EXT2FS_UNDEL_LIBS="-lext2fs -lcom_err"
27       AC_CHECK_TYPE(ext2_ino_t, ,
28                     [AC_DEFINE(ext2_ino_t, ino_t,
29                                [Define to ino_t if undefined.])],
30                     [
31 #include <errno.h>
32 #include <stdio.h>
33 #include <fcntl.h>
34 #include <stdlib.h>
35 #ifdef HAVE_EXT2FS_EXT2_FS_H
36 #include <ext2fs/ext2_fs.h>
37 #else
38 #undef umode_t
39 #include <linux/ext2_fs.h>
40 #endif
41 #include <ext2fs/ext2fs.h>
42                     ])
43     fi
44   fi
49 dnl MC_EXTFS_CHECKS
50 dnl    Check for tools used in extfs scripts.
51 AC_DEFUN([MC_EXTFS_CHECKS], [
52     AC_PATH_PROG([ZIP], [zip], [/usr/bin/zip])
53     AC_PATH_PROG([UNZIP], [unzip], [/usr/bin/unzip])
54     AC_CACHE_CHECK([for zipinfo code in unzip], [mc_cv_have_zipinfo],
55         [mc_cv_have_zipinfo=no
56         if $UNZIP -Z </dev/null >/dev/null 2>&1; then
57             mc_cv_have_zipinfo=yes
58         fi])
59     if test "x$mc_cv_have_zipinfo" = xyes; then
60         HAVE_ZIPINFO=1
61     else
62         HAVE_ZIPINFO=0
63     fi
64     AC_SUBST([HAVE_ZIPINFO])
65     AC_PATH_PROG([PERL], [perl], [/usr/bin/perl])
70 dnl MC_MCSERVER_CHECKS
71 dnl    Check how mcserver should check passwords.
72 dnl    Possible methods are PAM, pwdauth and crypt.
73 dnl    The later works with both /etc/shadow and /etc/passwd.
74 dnl    If PAM is found, other methods are not checked.
76 AC_DEFUN([MC_MCSERVER_CHECKS], [
78     dnl Check if PAM can be used for mcserv
79     AC_CHECK_LIB(dl, dlopen, [LIB_DL="-ldl"])
80     AC_CHECK_LIB(pam, pam_start, [
81         AC_DEFINE(HAVE_PAM, 1,
82                   [Define if PAM (Pluggable Authentication Modules) is available])
83         MCSERVLIBS="-lpam $LIB_DL"
84         mcserv_pam=yes], [], [$LIB_DL])
86     dnl Check for crypt() - needed for both /etc/shadow and /etc/passwd.
87     if test -z "$mcserv_pam"; then
89         dnl Check for pwdauth() - used on SunOS.
90         AC_CHECK_FUNCS([pwdauth])
92         dnl Check for crypt()
93         AC_CHECK_HEADERS([crypt.h], [crypt_header=yes])
94         if test -n "$crypt_header"; then
95             save_LIBS="$LIBS"
96             LIBS=
97             AC_SEARCH_LIBS(crypt, [crypt crypt_i], [mcserv_auth=crypt])
98             MCSERVLIBS="$LIBS"
99             LIBS="$save_LIBS"
100             if test -n "$mcserv_auth"; then
101                 AC_DEFINE(HAVE_CRYPT, 1,
102                           [Define to use crypt function in mcserv])
104                 dnl Check for shadow passwords
105                 AC_CHECK_HEADERS([shadow.h shadow/shadow.h],
106                                  [shadow_header=yes; break])
107                 if test -n "$shadow_header"; then
108                     save_LIBS="$LIBS"
109                     LIBS="$MCSERVLIBS"
110                     AC_SEARCH_LIBS(getspnam, [shadow], [mcserv_auth=shadow])
111                     MCSERVLIBS="$LIBS"
112                     LIBS="$save_LIBS"
113                     if test -n "$mcserv_auth"; then
114                         AC_DEFINE(HAVE_SHADOW, 1,
115                                   [Define to use shadow passwords for mcserv])
116                     fi
117                 fi
118             fi
119         fi
120     fi
122     AC_SUBST(MCSERVLIBS)
127 dnl MC_VFS_CHECKS
128 dnl   Check for various functions needed by libvfs.
129 dnl   This has various effects:
130 dnl     Sets MC_VFS_LIBS to libraries required
131 dnl     Sets vfs_flags to "pretty" list of vfs implementations we include.
132 dnl     Sets shell variable use_vfs to yes (default, --with-vfs) or
133 dnl        "no" (--without-vfs).
135 dnl Private define
136 AC_DEFUN([MC_WITH_VFS],[
137   MC_EXTFS_CHECKS
139   vfs_flags="cpiofs, extfs, tarfs"
140   use_net_code=false
142   AC_ARG_ENABLE([netcode],
143                 [  --enable-netcode         Support for networking [[yes]]])
145   if test "x$enable_netcode" != xno; then
146     dnl FIXME: network checks should probably be in their own macro.
147     AC_SEARCH_LIBS(socket, [xnet bsd socket inet], [have_socket=yes])
148     if test x$have_socket = xyes; then
149       AC_SEARCH_LIBS(gethostbyname, [bsd socket inet netinet])
150       AC_CHECK_MEMBERS([struct linger.l_linger], , , [
151 #include <sys/types.h>
152 #include <sys/socket.h>
153                        ])
154       AC_CHECK_FUNCS(pmap_set, , [
155          AC_CHECK_LIB(rpc, pmap_set, [
156            LIBS="-lrpc $LIBS"
157           AC_DEFINE(HAVE_PMAP_SET)
158           ])])
159       AC_CHECK_FUNCS(pmap_getport pmap_getmaps rresvport)
160       dnl add for source routing support setsockopt
161       AC_CHECK_HEADERS(rpc/pmap_clnt.h, , , [
162 #include <sys/types.h>
163 #include <sys/socket.h>
164 #include <netinet/in.h>
165 #include <rpc/rpc.h>
166 #include <rpc/pmap_prot.h>
167                                             ])
168       dnl
169       dnl mcfs support
170       dnl
171       AC_ARG_WITH(mcfs,
172         [  --with-mcfs              Support mc-specific networking file system [[no]]],
173         [if test "x$withval" != "xno"; then
174             AC_DEFINE(WITH_MCFS, 1, [Define to enable mc-specific networking file system])
175             vfs_flags="$vfs_flags, mcfs"
176             use_mcfs=yes
177             MC_MCSERVER_CHECKS
178         fi]
179       )
180       vfs_flags="$vfs_flags, ftpfs, fish"
181       use_net_code=true
182     fi
183   fi
185   dnl
186   dnl Samba support
187   dnl
188   use_smbfs=
189   AC_ARG_WITH(samba,
190           [  --with-samba             Support smb virtual file system [[no]]],
191           [if test "x$withval" != "xno"; then
192                   AC_DEFINE(WITH_SMBFS, 1, [Define to enable VFS over SMB])
193                   vfs_flags="$vfs_flags, smbfs"
194                   use_smbfs=yes
195           fi
196   ])
198   if test -n "$use_smbfs"; then
199   #################################################
200   # set Samba configuration directory location
201   configdir="/etc"
202   AC_ARG_WITH(configdir,
203   [  --with-configdir=DIR     Where the Samba configuration files are [[/etc]]],
204   [ case "$withval" in
205     yes|no)
206     #
207     # Just in case anybody does it
208     #
209         AC_MSG_WARN([--with-configdir called without argument - will use default])
210     ;;
211     * )
212         configdir="$withval"
213     ;;
214   esac]
215   )
216   AC_SUBST(configdir)
218   AC_ARG_WITH(codepagedir,
219     [  --with-codepagedir=DIR   Where the Samba codepage files are],
220     [ case "$withval" in
221       yes|no)
222       #
223       # Just in case anybody does it
224       #
225         AC_MSG_WARN([--with-codepagedir called without argument - will use default])
226       ;;
227     esac]
228   )
229   fi
231   dnl
232   dnl Ext2fs undelete support
233   dnl
234   AC_ARG_WITH(ext2undel,
235     [  --with-ext2undel         Compile with ext2 undelete code [[yes if found]]],
236     [if test x$withval != xno; then
237       if test x$withval != xyes; then
238         LDFLAGS="$LDFLAGS -L$withval/lib"
239         CPPFLAGS="$CPPFLAGS -I$withval/include"
240       fi
241       AC_EXT2_UNDEL
242     fi],[
243     dnl Default: detect
244     AC_CHECK_LIB(ext2fs, ext2fs_close, [AC_EXT2_UNDEL], , [-lcom_err])
245   ])
247   AC_DEFINE(USE_VFS, 1, [Define to enable VFS support])
248   if $use_net_code; then
249      AC_DEFINE(USE_NETCODE, 1, [Define to use networked VFS])
250   fi
255 AC_DEFUN([MC_VFS_CHECKS],[
256         use_vfs=yes
257         AC_ARG_WITH(vfs,
258                 [  --with-vfs               Compile with the VFS code [[yes]]],
259                 use_vfs=$withval
260         )
261         case $use_vfs in
262                 yes)    MC_WITH_VFS;;
263                 no)     use_vfs=no;;
264                 *)      use_vfs=no;;
265                         dnl Should we issue a warning?
266         esac
272 dnl Filesystem information detection
274 dnl To get information about the disk, mount points, etc.
277 AC_DEFUN([AC_GET_FS_INFO], [
278     AC_CHECK_HEADERS([fcntl.h utime.h])
280     gl_LIST_MOUNTED_FILE_SYSTEMS([
281         AC_DEFINE(HAVE_INFOMOUNT_LIST, 1,
282             [Define if the list of mounted filesystems can be determined])],
283         [AC_MSG_WARN([could not determine how to read list of mounted fs])])
285     gl_FSUSAGE
286     gl_FSTYPENAME
291 dnl Try using termcap database and link with libtermcap if possible.
293 AC_DEFUN([MC_USE_TERMCAP], [
294         screen_msg="$screen_msg with termcap database"
295         AC_MSG_NOTICE([using S-Lang screen library with termcap])
296         AC_DEFINE(USE_TERMCAP, 1, [Define to use termcap database])
297         AC_CHECK_LIB(termcap, tgoto, [MCLIBS="$MCLIBS -ltermcap"], , [$LIBS])
302 dnl Check if private functions are available for linking
304 AC_DEFUN([MC_SLANG_PRIVATE], [
305     AC_CACHE_CHECK([if S-Lang exports private functions],
306                    [mc_cv_slang_private], [
307         ac_save_LIBS="$LIBS"
308         LIBS="$LIBS -lslang"
309         AC_TRY_LINK([
310                      #ifdef HAVE_SLANG_SLANG_H
311                      #include <slang/slang.h>
312                      #else
313                      #include <slang.h>
314                      #endif
315                      #if SLANG_VERSION >= 10000
316                      extern unsigned int SLsys_getkey (void);
317                      #else
318                      extern unsigned int _SLsys_getkey (void);
319                      #endif
320                     ], [
321                      #if SLANG_VERSION >= 10000
322                      _SLsys_getkey ();
323                      #else
324                      SLsys_getkey ();
325                      #endif
326                     ],
327                     [mc_cv_slang_private=yes],
328                     [mc_cv_slang_private=no])
329         LIBS="$ac_save_LIBS"
330     ])
332     if test x$mc_cv_slang_private = xyes; then
333         AC_DEFINE(HAVE_SLANG_PRIVATE, 1,
334                   [Define if private S-Lang functions are available])
335     fi
340 dnl Check if the installed S-Lang library uses termcap
342 AC_DEFUN([MC_SLANG_TERMCAP], [
343     AC_CACHE_CHECK([if S-Lang uses termcap], [mc_cv_slang_termcap], [
344         ac_save_LIBS="$LIBS"
345         LIBS="$LIBS -lslang"
346         AC_TRY_LINK([
347                      #ifdef HAVE_SLANG_SLANG_H
348                      #include <slang/slang.h>
349                      #else
350                      #include <slang.h>
351                      #endif
352                     ],
353                     [SLtt_get_terminfo(); SLtt_tgetflag("");],
354                     [mc_cv_slang_termcap=no],
355                     [mc_cv_slang_termcap=yes])
356         LIBS="$ac_save_LIBS"
357     ])
359     if test x$mc_cv_slang_termcap = xyes; then
360         MC_USE_TERMCAP
361     fi
365 dnl Common code for MC_WITH_SLANG and MC_WITH_MCSLANG
367 AC_DEFUN([_MC_WITH_XSLANG], [
368     screen_type=slang
369     AC_DEFINE(HAVE_SLANG, 1,
370               [Define to use S-Lang library for screen management])
375 dnl Check if the system S-Lang library can be used.
376 dnl If not, and $1 is "strict", exit, otherwise fall back to mcslang.
378 AC_DEFUN([MC_WITH_SLANG], [
379     with_screen=slang
381     dnl Check the header
382     slang_h_found=
383     AC_CHECK_HEADERS([slang.h slang/slang.h],
384                      [slang_h_found=yes; break])
385     if test -z "$slang_h_found"; then
386         with_screen=mcslang
387     fi
389     dnl Check if termcap is needed.
390     dnl This check must be done before anything is linked against S-Lang.
391     if test x$with_screen = xslang; then
392         MC_SLANG_TERMCAP
393     fi
395     dnl Check the library
396     if test x$with_screen = xslang; then
397         AC_CHECK_LIB([slang], [SLang_init_tty], [MCLIBS="$MCLIBS -lslang"],
398                      [with_screen=mcslang], ["$MCLIBS"])
399     fi
401     dnl Unless external S-Lang was requested, reject S-Lang with UTF-8 hacks
402     if test x$with_screen = xslang; then
403         :
404         m4_if([$1], strict, ,
405               [AC_CHECK_LIB([slang], [SLsmg_write_nwchars],
406                             [AC_MSG_WARN([Rejecting S-Lang with UTF-8 support, \
407 it's not fully supported yet])
408               with_screen=mcslang])])
409     fi
411     if test x$with_screen = xslang; then
412         AC_DEFINE(HAVE_SYSTEM_SLANG, 1,
413                   [Define to use S-Lang library installed on the system])
414         MC_SLANG_PRIVATE
415         screen_type=slang
416         screen_msg="S-Lang library (installed on the system)"
417     else
418         m4_if([$1], strict,
419             [if test $with_screen != slang; then
420                 AC_MSG_ERROR([S-Lang library not found])
421             fi],
422             [MC_WITH_MCSLANG]
423         )
424     fi
426     _MC_WITH_XSLANG
431 dnl Use the included S-Lang library.
433 AC_DEFUN([MC_WITH_MCSLANG], [
434     screen_type=mcslang
435     screen_msg="Included S-Lang library (mcslang)"
437     dnl Type checks from S-Lang sources
438     AC_CHECK_SIZEOF(short, 2)
439     AC_CHECK_SIZEOF(int, 4)
440     AC_CHECK_SIZEOF(long, 4)
441     AC_CHECK_SIZEOF(float, 4)
442     AC_CHECK_SIZEOF(double, 8)
443     AC_TYPE_OFF_T
444     AC_CHECK_SIZEOF(off_t)
445     AC_CHECK_TYPES(long long)
446     AC_CHECK_SIZEOF(long long)
447     AC_CHECK_FUNCS(atexit on_exit)
449     # Search for terminfo database.
450     use_terminfo=
451     if test x"$with_termcap" != xyes; then
452         if test x"$with_termcap" = xno; then
453             use_terminfo=yes
454         fi
455         if test -n "$TERMINFO" && test -r "$TERMINFO/v/vt100"; then
456             use_terminfo=yes
457         fi
458         for dir in "/usr/share/terminfo" "/usr/lib/terminfo" \
459                    "/usr/share/lib/terminfo" "/etc/terminfo" \
460                    "/usr/local/lib/terminfo" "$HOME/.terminfo"; do
461             if test -r "$dir/v/vt100"; then
462                 use_terminfo=yes
463             fi
464         done
465     fi
467     # If there is no terminfo, use termcap
468     if test -z "$use_terminfo"; then
469         MC_USE_TERMCAP
470     fi
472     _MC_WITH_XSLANG
477 dnl Use the ncurses library.  It can only be requested explicitly,
478 dnl so just fail if anything goes wrong.
480 dnl If ncurses exports the ESCDELAY variable it should be set to 0
481 dnl or you'll have to press Esc three times to dismiss a dialog box.
483 AC_DEFUN([MC_WITH_NCURSES], [
484     dnl has_colors() is specific to ncurses, it's not in the old curses
485     save_LIBS="$LIBS"
486     LIBS=
487     AC_SEARCH_LIBS([has_colors], [ncurses curses], [MCLIBS="$MCLIBS $LIBS"],
488                    [AC_MSG_ERROR([Cannot find ncurses library])])
490     dnl Check the header
491     ncurses_h_found=
492     AC_CHECK_HEADERS([ncurses/curses.h ncurses.h curses.h],
493                      [ncurses_h_found=yes; break])
495     if test -z "$ncurses_h_found"; then
496         AC_MSG_ERROR([Cannot find ncurses header file])
497     fi
499     screen_type=ncurses
500     screen_msg="ncurses library"
501     AC_DEFINE(USE_NCURSES, 1,
502               [Define to use ncurses for screen management])
504     AC_CACHE_CHECK([for ESCDELAY variable],
505                    [mc_cv_ncurses_escdelay],
506                    [AC_TRY_LINK([], [
507                         extern int ESCDELAY;
508                         ESCDELAY = 0;
509                         ],
510                         [mc_cv_ncurses_escdelay=yes],
511                         [mc_cv_ncurses_escdelay=no])
512     ])
513     if test "$mc_cv_ncurses_escdelay" = yes; then
514         AC_DEFINE(HAVE_ESCDELAY, 1,
515                   [Define if ncurses has ESCDELAY variable])
516     fi
518     AC_CHECK_FUNCS(resizeterm)
519     LIBS="$save_LIBS"
524 dnl Check for ext2fs recovery code
526 AC_DEFUN([AC_EXT2_UNDEL], [
527   MC_UNDELFS_CHECKS
528   if test "$ext2fs_undel" = yes; then
529      AC_MSG_NOTICE([using ext2fs file recovery code])
530      vfs_flags="${vfs_flags}, undelfs"
531      use_undelfs=yes
532      MCLIBS="$MCLIBS $EXT2FS_UNDEL_LIBS"
533   else
534      AC_MSG_NOTICE([not using ext2fs file recovery code])
535   fi
539 dnl Check whether the g_module_* family of functions works
540 dnl on this system.  We need to know that at the compile time to
541 dnl decide whether to link with X11.
543 AC_DEFUN([AC_G_MODULE_SUPPORTED], [
544     AC_CACHE_CHECK([if gmodule functionality is supported], mc_cv_g_module_supported, [
545         ac_save_CFLAGS="$CFLAGS"
546         ac_save_LIBS="$LIBS"
547         CFLAGS="$CFLAGS $GMODULE_CFLAGS"
548         LIBS="$GMODULE_LIBS $LIBS"
549         AC_TRY_RUN([
550 #include <gmodule.h>
552 int main ()
554     int ret = (g_module_supported () == TRUE) ? 0 : 1;
555     return ret;
557         ],
558             [mc_cv_g_module_supported=yes],
559             [mc_cv_g_module_supported=no],
560             [mc_cv_g_module_supported=no]
561         )
562         CFLAGS="$ac_save_CFLAGS"
563         LIBS="$ac_save_LIBS"
564     ])
566 if test "$mc_cv_g_module_supported" = yes; then
567     AC_DEFINE(HAVE_GMODULE, 1,
568               [Define if gmodule functionality is supported])