Use AC_LIBSOURCES and AC_LIBOBJ to indicate source and object files.
[gnulib.git] / m4 / dirfd.m4
1 #serial 10
2
3 dnl Find out how to get the file descriptor associated with an open DIR*.
4
5 # Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
6 # This file is free software; the Free Software Foundation
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
9
10 dnl From Jim Meyering
11
12 AC_DEFUN([gl_FUNC_DIRFD],
13 [
14   AC_LIBSOURCES([dirfd.c, dirfd.h])
15
16   dnl Work around a bug of AC_EGREP_CPP in autoconf-2.57.
17   AC_REQUIRE([AC_PROG_CPP])
18   AC_REQUIRE([AC_PROG_EGREP])
19
20   AC_HEADER_DIRENT
21   dirfd_headers='
22 #if HAVE_DIRENT_H
23 # include <dirent.h>
24 #else /* not HAVE_DIRENT_H */
25 # define dirent direct
26 # if HAVE_SYS_NDIR_H
27 #  include <sys/ndir.h>
28 # endif /* HAVE_SYS_NDIR_H */
29 # if HAVE_SYS_DIR_H
30 #  include <sys/dir.h>
31 # endif /* HAVE_SYS_DIR_H */
32 # if HAVE_NDIR_H
33 #  include <ndir.h>
34 # endif /* HAVE_NDIR_H */
35 #endif /* HAVE_DIRENT_H */
36 '
37   AC_CHECK_FUNCS(dirfd)
38   AC_CHECK_DECLS([dirfd], , , $dirfd_headers)
39
40   AC_CACHE_CHECK([whether dirfd is a macro],
41     gl_cv_func_dirfd_macro,
42     [AC_EGREP_CPP([dirent_header_defines_dirfd], [$dirfd_headers
43 #ifdef dirfd
44  dirent_header_defines_dirfd
45 #endif],
46        gl_cv_func_dirfd_macro=yes,
47        gl_cv_func_dirfd_macro=no)])
48
49   # Use the replacement only if we have no function, macro,
50   # or declaration with that name.
51   if test $ac_cv_func_dirfd,$ac_cv_have_decl_dirfd,$gl_cv_func_dirfd_macro \
52       = no,no,no; then
53     AC_REPLACE_FUNCS([dirfd])
54     AC_CACHE_CHECK(
55               [how to get the file descriptor associated with an open DIR*],
56                    gl_cv_sys_dir_fd_member_name,
57       [
58         dirfd_save_CFLAGS=$CFLAGS
59         for ac_expr in d_fd dd_fd; do
60
61           CFLAGS="$CFLAGS -DDIR_FD_MEMBER_NAME=$ac_expr"
62           AC_TRY_COMPILE(
63             [$dirfd_headers
64             ],
65             [DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;],
66             dir_fd_found=yes
67           )
68           CFLAGS=$dirfd_save_CFLAGS
69           test "$dir_fd_found" = yes && break
70         done
71         test "$dir_fd_found" = yes || ac_expr=no_such_member
72
73         gl_cv_sys_dir_fd_member_name=$ac_expr
74       ]
75     )
76     if test $gl_cv_sys_dir_fd_member_name != no_such_member; then
77       AC_DEFINE_UNQUOTED(DIR_FD_MEMBER_NAME,
78         $gl_cv_sys_dir_fd_member_name,
79         [the name of the file descriptor member of DIR])
80     fi
81     AH_VERBATIM(DIR_TO_FD,
82                 [#ifdef DIR_FD_MEMBER_NAME
83 # define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME)
84 #else
85 # define DIR_TO_FD(Dir_p) -1
86 #endif
87 ])
88   fi
89 ])