Use AC_LIBSOURCES and AC_LIBOBJ to indicate source and object files.
[gnulib.git] / m4 / getcwd.m4
1 # getcwd.m4 - check for working getcwd that is compatible with glibc
2
3 # Copyright (C) 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
4 # This file is free software; the Free Software Foundation
5 # gives unlimited permission to copy and/or distribute it,
6 # with or without modifications, as long as this notice is preserved.
7
8 # Written by Paul Eggert.
9
10 AC_DEFUN([gl_FUNC_GETCWD_NULL],
11   [
12    AC_LIBSOURCES([getcwd.c, getcwd.h])
13
14    AC_CHECK_HEADERS_ONCE(unistd.h)
15    AC_CACHE_CHECK([whether getcwd (NULL, 0) allocates memory for result],
16      [gl_cv_func_getcwd_null],
17      [AC_TRY_RUN(
18         [
19 #        include <stdlib.h>
20 #        ifdef HAVE_UNISTD_H
21 #         include <unistd.h>
22 #        endif
23 #        ifndef getcwd
24          char *getcwd ();
25 #        endif
26          int
27          main ()
28          {
29            if (chdir ("/") != 0)
30              exit (1);
31            else
32              {
33                char *f = getcwd (NULL, 0);
34                exit (! (f && f[0] == '/' && !f[1]));
35              }
36          }],
37         [gl_cv_func_getcwd_null=yes],
38         [gl_cv_func_getcwd_null=no],
39         [gl_cv_func_getcwd_null=no])])
40 ])
41
42 AC_DEFUN([gl_FUNC_GETCWD],
43 [
44   AC_REQUIRE([gl_FUNC_GETCWD_NULL])
45
46   case $gl_cv_func_getcwd_null in
47   yes) gl_FUNC_GETCWD_PATH_MAX;;
48   esac
49
50   case $gl_cv_func_getcwd_null,$gl_cv_func_getcwd_path_max in
51   yes,yes) ;;
52   *)
53     AC_LIBOBJ([getcwd])
54     AC_DEFINE([__GETCWD_PREFIX], [[rpl_]],
55       [Define to rpl_ if the getcwd replacement function should be used.])
56     gl_PREREQ_GETCWD;;
57   esac
58 ])
59
60 # Prerequisites of lib/getcwd.c.
61 AC_DEFUN([gl_PREREQ_GETCWD],
62 [
63   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
64   AC_REQUIRE([AC_HEADER_DIRENT])
65   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_DIRENT_D_INO])
66   AC_CHECK_HEADERS_ONCE(fcntl.h)
67   :
68 ])