1 AC_DEFUN_ONCE(AC_LIBREPLACE_LOCATION_CHECKS,
3 echo "LIBREPLACE_LOCATION_CHECKS: START"
5 dnl find the libreplace sources. This is meant to work both for
6 dnl libreplace standalone builds, and builds of packages using libreplace
8 libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace"
9 for d in $libreplacepaths; do
10 if test -f "$d/replace.c"; then
12 AC_SUBST(libreplacedir)
16 if test x"$libreplacedir" = "x"; then
17 AC_MSG_ERROR([cannot find libreplace in $libreplacepaths])
19 LIBREPLACEOBJ="$libreplacedir/replace.o"
20 AC_SUBST(LIBREPLACEOBJ)
26 echo "LIBREPLACE_LOCATION_CHECKS: END"
27 ]) dnl end AC_LIBREPLACE_LOCATION_CHECKS
30 AC_DEFUN_ONCE(AC_LIBREPLACE_BROKEN_CHECKS,
32 echo "LIBREPLACE_BROKEN_CHECKS: START"
34 dnl find the libreplace sources. This is meant to work both for
35 dnl libreplace standalone builds, and builds of packages using libreplace
37 libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace"
38 for d in $libreplacepaths; do
39 if test -f "$d/replace.c"; then
41 AC_SUBST(libreplacedir)
45 if test x"$libreplacedir" = "x"; then
46 AC_MSG_ERROR([cannot find libreplace in $libreplacepaths])
49 LIBREPLACEOBJ="$libreplacedir/replace.o"
50 AC_SUBST(LIBREPLACEOBJ)
52 LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/snprintf.o $libreplacedir/xattr.o"
60 AC_CHECK_TYPE(ino_t,unsigned)
61 AC_CHECK_TYPE(loff_t,off_t)
62 AC_CHECK_TYPE(offset_t,loff_t)
63 AC_CHECK_TYPE(blksize_t,long)
64 AC_CHECK_TYPE(blkcnt_t,long)
68 AC_CHECK_FUNCS([pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp utime utimes])
70 AC_CHECK_HEADERS(stdbool.h stdint.h sys/select.h)
71 AC_CHECK_HEADERS(setjmp.h utime.h sys/wait.h)
73 LIBREPLACE_PROVIDE_HEADER([stdint.h])
74 LIBREPLACE_PROVIDE_HEADER([stdbool.h])
76 AC_DEFINE(HAVE_LIBREPLACE, 1, [We have libreplace])
79 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
88 [AC_DEFINE(HAVE__Bool, 1, [Whether the _Bool type is available])],,
96 AC_CHECK_HEADERS(linux/types.h)
98 AC_CACHE_CHECK([for working mmap],libreplace_cv_HAVE_MMAP,[
99 AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"],
100 libreplace_cv_HAVE_MMAP=yes,libreplace_cv_HAVE_MMAP=no,libreplace_cv_HAVE_MMAP=cross)])
101 if test x"$libreplace_cv_HAVE_MMAP" = x"yes"; then
102 AC_DEFINE(HAVE_MMAP,1,[Whether mmap works])
105 AC_CACHE_CHECK([for working mremap],libreplace_cv_HAVE_MREMAP,[
106 AC_TRY_RUN([#include "$libreplacedir/test/shared_mremap.c"],
107 libreplace_cv_HAVE_MREMAP=yes,libreplace_cv_HAVE_MREMAP=no,libreplace_cv_HAVE_MREMAP=cross)])
108 if test x"$libreplace_cv_HAVE_MREMAP" = x"yes"; then
109 AC_DEFINE(HAVE_MREMAP,1,[Whether mremap works])
112 AC_CACHE_CHECK([for incoherent mmap],libreplace_cv_HAVE_INCOHERENT_MMAP,[
113 AC_TRY_RUN([#include "$libreplacedir/test/incoherent_mmap.c"],
114 libreplace_cv_HAVE_INCOHERENT_MMAP=yes,libreplace_cv_HAVE_INCOHERENT_MMAP=no,libreplace_cv_HAVE_INCOHERENT_MMAP=cross)])
115 if test x"$libreplace_cv_HAVE_INCOHERENT_MMAP" = x"yes"; then
116 AC_DEFINE(HAVE_INCOHERENT_MMAP,1,[Whether mmap is incoherent against write])
120 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
121 AC_CHECK_HEADERS(sys/time.h time.h)
122 AC_CHECK_HEADERS(stdarg.h vararg.h)
123 AC_CHECK_HEADERS(sys/mount.h mntent.h)
124 AC_CHECK_HEADERS(stropts.h)
125 AC_CHECK_HEADERS(unix.h)
126 AC_CHECK_HEADERS(malloc.h)
127 AC_CHECK_HEADERS(syscall.h)
128 AC_CHECK_HEADERS(sys/syscall.h)
129 AC_CHECK_HEADERS(sys/ucontext.h)
131 AC_CHECK_FUNCS(syscall setuid seteuid setreuid setresuid setgid setegid setregid setresgid setgroups)
132 AC_CHECK_FUNCS(chroot bzero strerror strerror_r memalign posix_memalign getpagesize)
133 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
134 AC_CHECK_FUNCS(waitpid wait4 strlcpy strlcat initgroups memmove strdup)
135 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp dup2 dprintf vdprintf)
136 AC_CHECK_FUNCS(isatty chown lchown link readlink symlink realpath)
137 AC_CHECK_FUNCS(fdatasync,,[
138 # if we didn't find it, look in librt (Solaris hides it there...)
139 AC_CHECK_LIB(rt, fdatasync,
140 [libreplace_cv_HAVE_FDATASYNC_IN_LIBRT=yes
141 AC_DEFINE(HAVE_FDATASYNC, 1, Define to 1 if there is support for fdatasync)])
143 AC_HAVE_DECL(fdatasync, [#include <unistd.h>])
144 AC_CHECK_FUNCS(clock_gettime,libreplace_cv_have_clock_gettime=yes,[
145 AC_CHECK_LIB(rt, clock_gettime,
146 [libreplace_cv_HAVE_CLOCK_GETTIME_IN_LIBRT=yes
147 libreplace_cv_have_clock_gettime=yes
148 AC_DEFINE(HAVE_CLOCK_GETTIME, 1, Define to 1 if there is support for clock_gettime)])
151 AC_CHECK_HEADERS(sys/attributes.h attr/xattr.h sys/xattr.h sys/extattr.h sys/uio.h)
152 AC_CHECK_HEADERS(sys/ea.h sys/proplist.h)
154 LIBREPLACE_FILESYS_LIBS=""
156 ############################################
157 # Check for EA implementations
159 *freebsd4* | *dragonfly* )
160 AC_DEFINE(BROKEN_EXTATTR, 1, [Does extattr API work])
163 AC_SEARCH_LIBS(getxattr, [attr])
164 AC_CHECK_FUNCS(attr_get attr_getf attr_list attr_listf attropen attr_remove)
165 AC_CHECK_FUNCS(attr_removef attr_set attr_setf extattr_delete_fd extattr_delete_file)
166 AC_CHECK_FUNCS(extattr_get_fd extattr_get_file extattr_list_fd extattr_list_file)
167 AC_CHECK_FUNCS(extattr_set_fd extattr_set_file fgetea fgetxattr flistea flistxattr)
168 AC_CHECK_FUNCS(fremoveea fremovexattr fsetea fsetxattr getea getxattr listea)
169 AC_CHECK_FUNCS(listxattr removeea removexattr setea setxattr)
171 AC_CHECK_LIB_EXT(attr, LIBREPLACE_FILESYS_LIBS, flistea)
172 AC_CHECK_LIB_EXT(attr, LIBREPLACE_FILESYS_LIBS, flistxattr)
173 AC_CHECK_LIB_EXT(attr, LIBREPLACE_FILESYS_LIBS, attr_listf)
174 AC_CHECK_LIB_EXT(attr, LIBREPLACE_FILESYS_LIBS, extattr_list_fd)
180 ########################################################
181 # Do xattr functions take additional options like on Darwin?
182 if test x"$ac_cv_func_getxattr" = x"yes" ; then
183 AC_CACHE_CHECK([whether xattr interface takes additional options], smb_attr_cv_xattr_add_opt, [
185 LIBS="$LIBS $LIBREPLACE_FILESYS_LIBS"
187 #include <sys/types.h>
188 #if HAVE_ATTR_XATTR_H
189 #include <attr/xattr.h>
190 #elif HAVE_SYS_XATTR_H
191 #include <sys/xattr.h>
194 getxattr(0, 0, 0, 0, 0, 0);
196 [smb_attr_cv_xattr_add_opt=yes],
197 [smb_attr_cv_xattr_add_opt=no;LIBS=$old_LIBS])
199 if test x"$smb_attr_cv_xattr_add_opt" = x"yes"; then
200 AC_DEFINE(XATTR_ADDITIONAL_OPTIONS, 1, [xattr functions have additional options])
204 AC_CHECK_FUNCS(get_current_dir_name)
205 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
206 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
207 AC_HAVE_DECL(errno, [#include <errno.h>])
209 AC_CACHE_CHECK([for secure mkstemp],libreplace_cv_HAVE_SECURE_MKSTEMP,[
210 AC_TRY_RUN([#include <stdlib.h>
211 #include <sys/types.h>
212 #include <sys/stat.h>
216 char tpl[20]="/tmp/test.XXXXXX";
217 char tpl2[20]="/tmp/test.XXXXXX";
218 int fd = mkstemp(tpl);
219 int fd2 = mkstemp(tpl2);
226 if (fd2 == -1) exit(1);
229 if (fstat(fd, &st) != 0) exit(1);
230 if ((st.st_mode & 0777) != 0600) exit(1);
231 if (strcmp(tpl, "/tmp/test.XXXXXX") == 0) {
234 if (strcmp(tpl, tpl2) == 0) {
239 libreplace_cv_HAVE_SECURE_MKSTEMP=yes,
240 libreplace_cv_HAVE_SECURE_MKSTEMP=no,
241 libreplace_cv_HAVE_SECURE_MKSTEMP=cross)])
242 if test x"$libreplace_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
243 AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
246 dnl Provided by snprintf.c:
247 AC_CHECK_HEADERS(stdio.h strings.h)
248 AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
249 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
251 AC_CACHE_CHECK([for C99 vsnprintf],libreplace_cv_HAVE_C99_VSNPRINTF,[
253 #include <sys/types.h>
257 void foo(const char *format, ...) {
261 long long l = 1234567890;
264 va_start(ap, format);
265 len = vsnprintf(buf, 0, format, ap);
267 if (len != 5) exit(1);
269 va_start(ap, format);
270 len = vsnprintf(0, 0, format, ap);
272 if (len != 5) exit(2);
274 if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
276 if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
277 if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
278 if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
279 if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
283 main() { foo("hello"); }
285 libreplace_cv_HAVE_C99_VSNPRINTF=yes,libreplace_cv_HAVE_C99_VSNPRINTF=no,libreplace_cv_HAVE_C99_VSNPRINTF=cross)])
286 if test x"$libreplace_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
287 AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
292 AC_CACHE_CHECK([for va_copy],libreplace_cv_HAVE_VA_COPY,[
293 AC_TRY_LINK([#include <stdarg.h>
294 va_list ap1,ap2;], [va_copy(ap1,ap2);],
295 libreplace_cv_HAVE_VA_COPY=yes,libreplace_cv_HAVE_VA_COPY=no)])
296 if test x"$libreplace_cv_HAVE_VA_COPY" = x"yes"; then
297 AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
300 if test x"$libreplace_cv_HAVE_VA_COPY" != x"yes"; then
301 AC_CACHE_CHECK([for __va_copy],libreplace_cv_HAVE___VA_COPY,[
302 AC_TRY_LINK([#include <stdarg.h>
303 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
304 libreplace_cv_HAVE___VA_COPY=yes,libreplace_cv_HAVE___VA_COPY=no)])
305 if test x"$libreplace_cv_HAVE___VA_COPY" = x"yes"; then
306 AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
310 dnl __FUNCTION__ macro
311 AC_CACHE_CHECK([for __FUNCTION__ macro],libreplace_cv_HAVE_FUNCTION_MACRO,[
312 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
313 libreplace_cv_HAVE_FUNCTION_MACRO=yes,libreplace_cv_HAVE_FUNCTION_MACRO=no)])
314 if test x"$libreplace_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
315 AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
318 AC_CACHE_CHECK([for __func__ macro],libreplace_cv_HAVE_func_MACRO,[
319 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
320 libreplace_cv_HAVE_func_MACRO=yes,libreplace_cv_HAVE_func_MACRO=no)])
321 if test x"$libreplace_cv_HAVE_func_MACRO" = x"yes"; then
322 AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
326 AC_CHECK_HEADERS([sys/param.h limits.h])
328 AC_CHECK_TYPE(comparison_fn_t,
329 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
331 AC_HAVE_DECL(setenv, [#include <stdlib.h>])
332 AC_CHECK_FUNCS(setenv unsetenv)
333 AC_HAVE_DECL(environ, [#include <unistd.h>])
335 AC_CHECK_FUNCS(strnlen)
336 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
338 AC_CHECK_FUNCS(memmem)
340 # this test disabled as we don't actually need __VA_ARGS__ yet
342 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
343 eprintf("bla", "bar");
344 ], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available]))
347 AC_CACHE_CHECK([for sig_atomic_t type],libreplace_cv_sig_atomic_t, [
349 #include <sys/types.h>
354 #include <signal.h>],[sig_atomic_t i = 0],
355 libreplace_cv_sig_atomic_t=yes,libreplace_cv_sig_atomic_t=no)])
356 if test x"$libreplace_cv_sig_atomic_t" = x"yes"; then
357 AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
361 dnl Check if the C compiler understands volatile (it should, being ANSI).
362 AC_CACHE_CHECK([that the C compiler understands volatile],libreplace_cv_volatile, [
363 AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
364 libreplace_cv_volatile=yes,libreplace_cv_volatile=no)])
365 if test x"$libreplace_cv_volatile" = x"yes"; then
366 AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
369 m4_include(system/config.m4)
371 AC_CACHE_CHECK([for O_DIRECT flag to open(2)],libreplace_cv_HAVE_OPEN_O_DIRECT,[
377 [int fd = open("/dev/null", O_DIRECT);],
378 libreplace_cv_HAVE_OPEN_O_DIRECT=yes,libreplace_cv_HAVE_OPEN_O_DIRECT=no)])
379 if test x"$libreplace_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
380 AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
384 m4_include(strptime.m4)
386 m4_include(timegm.m4)
387 m4_include(repdir.m4)
390 if test x$libreplace_cv_have_clock_gettime = xyes ; then
391 SMB_CHECK_CLOCK_ID(CLOCK_MONOTONIC)
392 SMB_CHECK_CLOCK_ID(CLOCK_PROCESS_CPUTIME_ID)
393 SMB_CHECK_CLOCK_ID(CLOCK_REALTIME)
396 AC_CACHE_CHECK([for struct timespec type],libreplace_cv_struct_timespec, [
398 #include <sys/types.h>
403 #if TIME_WITH_SYS_TIME
404 # include <sys/time.h>
408 # include <sys/time.h>
413 ],[struct timespec ts;],
414 libreplace_cv_struct_timespec=yes,libreplace_cv_struct_timespec=no)])
415 if test x"$libreplace_cv_struct_timespec" = x"yes"; then
416 AC_DEFINE(HAVE_STRUCT_TIMESPEC,1,[Whether we have struct timespec])
419 AC_CACHE_CHECK([for ucontext_t type],libreplace_cv_ucontext_t, [
422 #if HAVE_SYS_UCONTEXT_H
423 #include <sys/ucontext.h>
425 ],[ucontext_t uc; sigaddset(&uc.uc_sigmask, SIGUSR1);],
426 libreplace_cv_ucontext_t=yes,libreplace_cv_ucontext_t=no)])
427 if test x"$libreplace_cv_ucontext_t" = x"yes"; then
428 AC_DEFINE(HAVE_UCONTEXT_T,1,[Whether we have ucontext_t])
431 AC_CHECK_FUNCS([printf memset memcpy],,[AC_MSG_ERROR([Required function not found])])
433 echo "LIBREPLACE_BROKEN_CHECKS: END"
434 ]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
436 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START,
438 #LIBREPLACE_ALL_CHECKS: START"
440 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END,
442 #LIBREPLACE_ALL_CHECKS: END"
444 m4_define(AC_LIBREPLACE_ALL_CHECKS,
446 AC__LIBREPLACE_ALL_CHECKS_START
447 AC_LIBREPLACE_LOCATION_CHECKS
448 AC_LIBREPLACE_CC_CHECKS
449 AC_LIBREPLACE_BROKEN_CHECKS
450 AC__LIBREPLACE_ALL_CHECKS_END
451 CFLAGS="$CFLAGS -I$libreplacedir"
454 m4_include(libreplace_cc.m4)
455 m4_include(libreplace_ld.m4)
456 m4_include(libreplace_network.m4)
457 m4_include(libreplace_macros.m4)
460 dnl SMB_CHECK_CLOCK_ID(clockid)
461 dnl Test whether the specified clock_gettime clock ID is available. If it
462 dnl is, we define HAVE_clockid
463 AC_DEFUN([SMB_CHECK_CLOCK_ID],
465 AC_MSG_CHECKING(for $1)
467 #if TIME_WITH_SYS_TIME
468 # include <sys/time.h>
472 # include <sys/time.h>
483 AC_DEFINE(HAVE_$1, 1,
484 [Whether the clock_gettime clock ID $1 is available])
490 m4_ifndef([AC_USE_SYSTEM_EXTENSIONS],[m4_include(autoconf-2.60.m4)])