s3: Remove some unused code
[Samba/gebeck_regimport.git] / lib / replace / libreplace.m4
blob7335c98a5979ea9c5919144a98cc8cc28456b4de
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
7 libreplacedir=""
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
11                 libreplacedir="$d"              
12                 AC_SUBST(libreplacedir)
13                 break;
14         fi
15 done
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)
22 AC_CANONICAL_BUILD
23 AC_CANONICAL_HOST
24 AC_CANONICAL_TARGET
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
36 libreplacedir=""
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
40                 libreplacedir="$d"              
41                 AC_SUBST(libreplacedir)
42                 break;
43         fi
44 done
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"
54 AC_TYPE_UID_T
55 AC_TYPE_MODE_T
56 AC_TYPE_OFF_T
57 AC_TYPE_SIZE_T
58 AC_TYPE_PID_T
59 AC_STRUCT_ST_RDEV
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)
66 AC_FUNC_MEMCMP
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)
73 LIBREPLACE_PROVIDE_HEADER([stdint.h])
74 LIBREPLACE_PROVIDE_HEADER([stdbool.h])
76 AC_DEFINE(HAVE_LIBREPLACE, 1, [We have libreplace])
78 AC_CHECK_TYPE(bool, 
79 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
81 AC_INCLUDES_DEFAULT
82 #ifdef HAVE_STDBOOL_H
83 #include <stdbool.h>
84 #endif]
87 AC_CHECK_TYPE(_Bool, 
88 [AC_DEFINE(HAVE__Bool, 1, [Whether the _Bool type is available])],,
90 AC_INCLUDES_DEFAULT
91 #ifdef HAVE_STDBOOL_H
92 #include <stdbool.h>
93 #endif]
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)
128 AC_CHECK_FUNCS(seteuid setreuid setresuid setegid setregid setresgid)
129 AC_CHECK_FUNCS(chroot bzero strerror strerror_r memalign posix_memalign getpagesize)
130 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
131 AC_CHECK_FUNCS(waitpid wait4 strlcpy strlcat initgroups memmove strdup)
132 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp dup2 dprintf vdprintf)
133 AC_CHECK_FUNCS(isatty chown lchown link readlink symlink realpath)
134 AC_CHECK_FUNCS(fdatasync,,[
135         # if we didn't find it, look in librt (Solaris hides it there...)
136         AC_CHECK_LIB(rt, fdatasync,
137                 [libreplace_cv_HAVE_FDATASYNC_IN_LIBRT=yes
138                 AC_DEFINE(HAVE_FDATASYNC, 1, Define to 1 if there is support for fdatasync)])
140 AC_HAVE_DECL(fdatasync, [#include <unistd.h>])
141 AC_CHECK_FUNCS(clock_gettime,libreplace_cv_have_clock_gettime=yes,[
142         AC_CHECK_LIB(rt, clock_gettime,
143                 [libreplace_cv_HAVE_CLOCK_GETTIME_IN_LIBRT=yes
144                 libreplace_cv_have_clock_gettime=yes
145                 AC_DEFINE(HAVE_CLOCK_GETTIME, 1, Define to 1 if there is support for clock_gettime)])
147 AC_CHECK_FUNCS(get_current_dir_name)
148 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
149 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
150 AC_HAVE_DECL(errno, [#include <errno.h>])
152 AC_CACHE_CHECK([for secure mkstemp],libreplace_cv_HAVE_SECURE_MKSTEMP,[
153 AC_TRY_RUN([#include <stdlib.h>
154 #include <sys/types.h>
155 #include <sys/stat.h>
156 #include <unistd.h>
157 main() { 
158   struct stat st;
159   char tpl[20]="/tmp/test.XXXXXX"; 
160   int fd = mkstemp(tpl); 
161   if (fd == -1) exit(1);
162   unlink(tpl);
163   if (fstat(fd, &st) != 0) exit(1);
164   if ((st.st_mode & 0777) != 0600) exit(1);
165   exit(0);
167 libreplace_cv_HAVE_SECURE_MKSTEMP=yes,
168 libreplace_cv_HAVE_SECURE_MKSTEMP=no,
169 libreplace_cv_HAVE_SECURE_MKSTEMP=cross)])
170 if test x"$libreplace_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
171     AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
174 dnl Provided by snprintf.c:
175 AC_CHECK_HEADERS(stdio.h strings.h)
176 AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
177 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
179 AC_CACHE_CHECK([for C99 vsnprintf],libreplace_cv_HAVE_C99_VSNPRINTF,[
180 AC_TRY_RUN([
181 #include <sys/types.h>
182 #include <stdio.h>
183 #include <stdarg.h>
184 #include <stdlib.h>
185 void foo(const char *format, ...) { 
186        va_list ap;
187        int len;
188        char buf[20];
189        long long l = 1234567890;
190        l *= 100;
192        va_start(ap, format);
193        len = vsnprintf(buf, 0, format, ap);
194        va_end(ap);
195        if (len != 5) exit(1);
197        va_start(ap, format);
198        len = vsnprintf(0, 0, format, ap);
199        va_end(ap);
200        if (len != 5) exit(2);
202        if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
204        if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
205        if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
206        if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
207        if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
209        exit(0);
211 main() { foo("hello"); }
213 libreplace_cv_HAVE_C99_VSNPRINTF=yes,libreplace_cv_HAVE_C99_VSNPRINTF=no,libreplace_cv_HAVE_C99_VSNPRINTF=cross)])
214 if test x"$libreplace_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
215     AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
219 dnl VA_COPY
220 AC_CACHE_CHECK([for va_copy],libreplace_cv_HAVE_VA_COPY,[
221 AC_TRY_LINK([#include <stdarg.h>
222 va_list ap1,ap2;], [va_copy(ap1,ap2);],
223 libreplace_cv_HAVE_VA_COPY=yes,libreplace_cv_HAVE_VA_COPY=no)])
224 if test x"$libreplace_cv_HAVE_VA_COPY" = x"yes"; then
225     AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
228 if test x"$libreplace_cv_HAVE_VA_COPY" != x"yes"; then
229 AC_CACHE_CHECK([for __va_copy],libreplace_cv_HAVE___VA_COPY,[
230 AC_TRY_LINK([#include <stdarg.h>
231 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
232 libreplace_cv_HAVE___VA_COPY=yes,libreplace_cv_HAVE___VA_COPY=no)])
233 if test x"$libreplace_cv_HAVE___VA_COPY" = x"yes"; then
234     AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
238 dnl __FUNCTION__ macro
239 AC_CACHE_CHECK([for __FUNCTION__ macro],libreplace_cv_HAVE_FUNCTION_MACRO,[
240 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
241 libreplace_cv_HAVE_FUNCTION_MACRO=yes,libreplace_cv_HAVE_FUNCTION_MACRO=no)])
242 if test x"$libreplace_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
243     AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
244 else
245     dnl __func__ macro
246     AC_CACHE_CHECK([for __func__ macro],libreplace_cv_HAVE_func_MACRO,[
247     AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
248     libreplace_cv_HAVE_func_MACRO=yes,libreplace_cv_HAVE_func_MACRO=no)])
249     if test x"$libreplace_cv_HAVE_func_MACRO" = x"yes"; then
250        AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
251     fi
254 AC_CHECK_HEADERS([sys/param.h limits.h])
256 AC_CHECK_TYPE(comparison_fn_t, 
257 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
259 AC_HAVE_DECL(setenv, [#include <stdlib.h>])
260 AC_CHECK_FUNCS(setenv unsetenv)
261 AC_HAVE_DECL(environ, [#include <unistd.h>])
263 AC_CHECK_FUNCS(strnlen)
264 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
266 AC_CHECK_FUNCS(memmem)
268 # this test disabled as we don't actually need __VA_ARGS__ yet
269 AC_TRY_CPP([
270 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
271 eprintf("bla", "bar");
272 ], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available]))
275 AC_CACHE_CHECK([for sig_atomic_t type],libreplace_cv_sig_atomic_t, [
276     AC_TRY_COMPILE([
277 #include <sys/types.h>
278 #if STDC_HEADERS
279 #include <stdlib.h>
280 #include <stddef.h>
281 #endif
282 #include <signal.h>],[sig_atomic_t i = 0],
283         libreplace_cv_sig_atomic_t=yes,libreplace_cv_sig_atomic_t=no)])
284 if test x"$libreplace_cv_sig_atomic_t" = x"yes"; then
285    AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
289 AC_CACHE_CHECK([for O_DIRECT flag to open(2)],libreplace_cv_HAVE_OPEN_O_DIRECT,[
290 AC_TRY_COMPILE([
291 #include <unistd.h>
292 #ifdef HAVE_FCNTL_H
293 #include <fcntl.h>
294 #endif],
295 [int fd = open("/dev/null", O_DIRECT);],
296 libreplace_cv_HAVE_OPEN_O_DIRECT=yes,libreplace_cv_HAVE_OPEN_O_DIRECT=no)])
297 if test x"$libreplace_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
298     AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
302 dnl Check if the C compiler understands volatile (it should, being ANSI).
303 AC_CACHE_CHECK([that the C compiler understands volatile],libreplace_cv_volatile, [
304         AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
305                 libreplace_cv_volatile=yes,libreplace_cv_volatile=no)])
306 if test x"$libreplace_cv_volatile" = x"yes"; then
307         AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
310 m4_include(system/config.m4)
312 m4_include(dlfcn.m4)
313 m4_include(getpass.m4)
314 m4_include(strptime.m4)
315 m4_include(win32.m4)
316 m4_include(timegm.m4)
317 m4_include(repdir.m4)
318 m4_include(crypt.m4)
320 if test x$libreplace_cv_have_clock_gettime = xyes ; then
321         SMB_CHECK_CLOCK_ID(CLOCK_MONOTONIC)
322         SMB_CHECK_CLOCK_ID(CLOCK_PROCESS_CPUTIME_ID)
323         SMB_CHECK_CLOCK_ID(CLOCK_REALTIME)
326 AC_CACHE_CHECK([for struct timespec type],libreplace_cv_struct_timespec, [
327     AC_TRY_COMPILE([
328 #include <sys/types.h>
329 #if STDC_HEADERS
330 #include <stdlib.h>
331 #include <stddef.h>
332 #endif
333 #if TIME_WITH_SYS_TIME
334 # include <sys/time.h>
335 # include <time.h>
336 #else
337 # if HAVE_SYS_TIME_H
338 #  include <sys/time.h>
339 # else
340 #  include <time.h>
341 # endif
342 #endif
343 ],[struct timespec ts;],
344         libreplace_cv_struct_timespec=yes,libreplace_cv_struct_timespec=no)])
345 if test x"$libreplace_cv_struct_timespec" = x"yes"; then
346    AC_DEFINE(HAVE_STRUCT_TIMESPEC,1,[Whether we have struct timespec])
349 AC_CHECK_FUNCS([printf memset memcpy],,[AC_MSG_ERROR([Required function not found])])
351 echo "LIBREPLACE_BROKEN_CHECKS: END"
352 ]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
354 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START,
356 #LIBREPLACE_ALL_CHECKS: START"
358 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END,
360 #LIBREPLACE_ALL_CHECKS: END"
362 m4_define(AC_LIBREPLACE_ALL_CHECKS,
364 AC__LIBREPLACE_ALL_CHECKS_START
365 AC_LIBREPLACE_LOCATION_CHECKS
366 AC_LIBREPLACE_CC_CHECKS
367 AC_LIBREPLACE_BROKEN_CHECKS
368 AC__LIBREPLACE_ALL_CHECKS_END
369 CFLAGS="$CFLAGS -I$libreplacedir"
372 m4_include(libreplace_cc.m4)
373 m4_include(libreplace_ld.m4)
374 m4_include(libreplace_network.m4)
375 m4_include(libreplace_macros.m4)
378 dnl SMB_CHECK_CLOCK_ID(clockid)
379 dnl Test whether the specified clock_gettime clock ID is available. If it
380 dnl is, we define HAVE_clockid
381 AC_DEFUN([SMB_CHECK_CLOCK_ID],
383     AC_MSG_CHECKING(for $1)
384     AC_TRY_LINK([
385 #if TIME_WITH_SYS_TIME
386 # include <sys/time.h>
387 # include <time.h>
388 #else
389 # if HAVE_SYS_TIME_H
390 #  include <sys/time.h>
391 # else
392 #  include <time.h>
393 # endif
394 #endif
395     ],
396     [
397 clockid_t clk = $1;
398     ],
399     [
400         AC_MSG_RESULT(yes)
401         AC_DEFINE(HAVE_$1, 1,
402             [Whether the clock_gettime clock ID $1 is available])
403     ],
404     [
405         AC_MSG_RESULT(no)
406     ])
408 m4_ifndef([AC_USE_SYSTEM_EXTENSIONS],[m4_include(autoconf-2.60.m4)])