s3: piddir creation fix part 2.
[ira/wip.git] / lib / replace / libreplace.m4
1 AC_DEFUN_ONCE(AC_LIBREPLACE_LOCATION_CHECKS,
2 [
3 echo "LIBREPLACE_LOCATION_CHECKS: START"
4
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])
18 fi
19 LIBREPLACEOBJ="$libreplacedir/replace.o"
20 AC_SUBST(LIBREPLACEOBJ)
21
22 AC_CANONICAL_BUILD
23 AC_CANONICAL_HOST
24 AC_CANONICAL_TARGET
25
26 echo "LIBREPLACE_LOCATION_CHECKS: END"
27 ]) dnl end AC_LIBREPLACE_LOCATION_CHECKS
28
29
30 AC_DEFUN_ONCE(AC_LIBREPLACE_BROKEN_CHECKS,
31 [
32 echo "LIBREPLACE_BROKEN_CHECKS: START"
33
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])
47 fi
48
49 LIBREPLACEOBJ="$libreplacedir/replace.o"
50 AC_SUBST(LIBREPLACEOBJ)
51
52 LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/snprintf.o"
53
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
64 AC_FUNC_MEMCMP
65
66 AC_CHECK_FUNCS([pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp utime utimes])
67
68 AC_CHECK_HEADERS(stdbool.h stdint.h sys/select.h)
69 AC_CHECK_HEADERS(setjmp.h utime.h)
70
71 LIBREPLACE_PROVIDE_HEADER([stdint.h])
72 LIBREPLACE_PROVIDE_HEADER([stdbool.h])
73
74 AC_DEFINE(HAVE_LIBREPLACE, 1, [We have libreplace])
75
76 AC_CHECK_TYPE(bool, 
77 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
78 [
79 AC_INCLUDES_DEFAULT
80 #ifdef HAVE_STDBOOL_H
81 #include <stdbool.h>
82 #endif]
83 )
84
85 AC_CHECK_TYPE(_Bool, 
86 [AC_DEFINE(HAVE__Bool, 1, [Whether the _Bool type is available])],,
87 [
88 AC_INCLUDES_DEFAULT
89 #ifdef HAVE_STDBOOL_H
90 #include <stdbool.h>
91 #endif]
92 )
93
94 AC_CHECK_HEADERS(linux/types.h)
95
96 AC_CACHE_CHECK([for working mmap],libreplace_cv_HAVE_MMAP,[
97 AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"],
98            libreplace_cv_HAVE_MMAP=yes,libreplace_cv_HAVE_MMAP=no,libreplace_cv_HAVE_MMAP=cross)])
99 if test x"$libreplace_cv_HAVE_MMAP" = x"yes"; then
100     AC_DEFINE(HAVE_MMAP,1,[Whether mmap works])
101 fi
102
103 AC_CACHE_CHECK([for working mremap],libreplace_cv_HAVE_MREMAP,[
104 AC_TRY_RUN([#include "$libreplacedir/test/shared_mremap.c"],
105            libreplace_cv_HAVE_MREMAP=yes,libreplace_cv_HAVE_MREMAP=no,libreplace_cv_HAVE_MREMAP=cross)])
106 if test x"$libreplace_cv_HAVE_MREMAP" = x"yes"; then
107     AC_DEFINE(HAVE_MREMAP,1,[Whether mremap works])
108 fi
109
110
111 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
112 AC_CHECK_HEADERS(sys/time.h time.h)
113 AC_CHECK_HEADERS(stdarg.h vararg.h)
114 AC_CHECK_HEADERS(sys/mount.h mntent.h)
115 AC_CHECK_HEADERS(stropts.h)
116 AC_CHECK_HEADERS(unix.h)
117
118 AC_CHECK_FUNCS(seteuid setreuid setresuid setegid setregid setresgid)
119 AC_CHECK_FUNCS(chroot bzero strerror strerror_r)
120 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
121 AC_CHECK_FUNCS(waitpid wait4 strlcpy strlcat initgroups memmove strdup)
122 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp dup2 dprintf vdprintf)
123 AC_CHECK_FUNCS(isatty chown lchown link readlink symlink realpath)
124 AC_CHECK_FUNCS(fdatasync,,[
125         # if we didn't find it, look in librt (Solaris hides it there...)
126         AC_CHECK_LIB(rt, fdatasync,
127                 [libreplace_cv_HAVE_FDATASYNC_IN_LIBRT=yes
128                 AC_DEFINE(HAVE_FDATASYNC, 1, Define to 1 if there is support for fdatasync)])
129 ])
130 AC_HAVE_DECL(fdatasync, [#include <unistd.h>])
131 AC_CHECK_FUNCS(clock_gettime,libreplace_cv_have_clock_gettime=yes,[
132         AC_CHECK_LIB(rt, clock_gettime,
133                 [libreplace_cv_HAVE_CLOCK_GETTIME_IN_LIBRT=yes
134                 libreplace_cv_have_clock_gettime=yes
135                 AC_DEFINE(HAVE_CLOCK_GETTIME, 1, Define to 1 if there is support for clock_gettime)])
136 ])
137 AC_CHECK_FUNCS(get_current_dir_name)
138 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
139 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
140 AC_HAVE_DECL(errno, [#include <errno.h>])
141
142 AC_CACHE_CHECK([for secure mkstemp],libreplace_cv_HAVE_SECURE_MKSTEMP,[
143 AC_TRY_RUN([#include <stdlib.h>
144 #include <sys/types.h>
145 #include <sys/stat.h>
146 #include <unistd.h>
147 main() { 
148   struct stat st;
149   char tpl[20]="/tmp/test.XXXXXX"; 
150   int fd = mkstemp(tpl); 
151   if (fd == -1) exit(1);
152   unlink(tpl);
153   if (fstat(fd, &st) != 0) exit(1);
154   if ((st.st_mode & 0777) != 0600) exit(1);
155   exit(0);
156 }],
157 libreplace_cv_HAVE_SECURE_MKSTEMP=yes,
158 libreplace_cv_HAVE_SECURE_MKSTEMP=no,
159 libreplace_cv_HAVE_SECURE_MKSTEMP=cross)])
160 if test x"$libreplace_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
161     AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
162 fi
163
164 dnl Provided by snprintf.c:
165 AC_CHECK_HEADERS(stdio.h strings.h)
166 AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
167 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
168
169 AC_CACHE_CHECK([for C99 vsnprintf],libreplace_cv_HAVE_C99_VSNPRINTF,[
170 AC_TRY_RUN([
171 #include <sys/types.h>
172 #include <stdio.h>
173 #include <stdarg.h>
174 #include <stdlib.h>
175 void foo(const char *format, ...) { 
176        va_list ap;
177        int len;
178        char buf[20];
179        long long l = 1234567890;
180        l *= 100;
181
182        va_start(ap, format);
183        len = vsnprintf(buf, 0, format, ap);
184        va_end(ap);
185        if (len != 5) exit(1);
186
187        va_start(ap, format);
188        len = vsnprintf(0, 0, format, ap);
189        va_end(ap);
190        if (len != 5) exit(2);
191
192        if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
193
194        if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
195        if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
196        if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
197        if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
198
199        exit(0);
200 }
201 main() { foo("hello"); }
202 ],
203 libreplace_cv_HAVE_C99_VSNPRINTF=yes,libreplace_cv_HAVE_C99_VSNPRINTF=no,libreplace_cv_HAVE_C99_VSNPRINTF=cross)])
204 if test x"$libreplace_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
205     AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
206 fi
207
208
209 dnl VA_COPY
210 AC_CACHE_CHECK([for va_copy],libreplace_cv_HAVE_VA_COPY,[
211 AC_TRY_LINK([#include <stdarg.h>
212 va_list ap1,ap2;], [va_copy(ap1,ap2);],
213 libreplace_cv_HAVE_VA_COPY=yes,libreplace_cv_HAVE_VA_COPY=no)])
214 if test x"$libreplace_cv_HAVE_VA_COPY" = x"yes"; then
215     AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
216 fi
217
218 if test x"$libreplace_cv_HAVE_VA_COPY" != x"yes"; then
219 AC_CACHE_CHECK([for __va_copy],libreplace_cv_HAVE___VA_COPY,[
220 AC_TRY_LINK([#include <stdarg.h>
221 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
222 libreplace_cv_HAVE___VA_COPY=yes,libreplace_cv_HAVE___VA_COPY=no)])
223 if test x"$libreplace_cv_HAVE___VA_COPY" = x"yes"; then
224     AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
225 fi
226 fi
227
228 dnl __FUNCTION__ macro
229 AC_CACHE_CHECK([for __FUNCTION__ macro],libreplace_cv_HAVE_FUNCTION_MACRO,[
230 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
231 libreplace_cv_HAVE_FUNCTION_MACRO=yes,libreplace_cv_HAVE_FUNCTION_MACRO=no)])
232 if test x"$libreplace_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
233     AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
234 else
235     dnl __func__ macro
236     AC_CACHE_CHECK([for __func__ macro],libreplace_cv_HAVE_func_MACRO,[
237     AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
238     libreplace_cv_HAVE_func_MACRO=yes,libreplace_cv_HAVE_func_MACRO=no)])
239     if test x"$libreplace_cv_HAVE_func_MACRO" = x"yes"; then
240        AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
241     fi
242 fi
243
244 AC_CHECK_HEADERS([sys/param.h limits.h])
245
246 AC_CHECK_TYPE(comparison_fn_t, 
247 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
248
249 AC_HAVE_DECL(setenv, [#include <stdlib.h>])
250 AC_CHECK_FUNCS(setenv unsetenv)
251 AC_HAVE_DECL(environ, [#include <unistd.h>])
252
253 AC_CHECK_FUNCS(strnlen)
254 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
255
256 AC_CHECK_FUNCS(memmem)
257
258 # this test disabled as we don't actually need __VA_ARGS__ yet
259 AC_TRY_CPP([
260 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
261 eprintf("bla", "bar");
262 ], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available]))
263
264
265 AC_CACHE_CHECK([for sig_atomic_t type],libreplace_cv_sig_atomic_t, [
266     AC_TRY_COMPILE([
267 #include <sys/types.h>
268 #if STDC_HEADERS
269 #include <stdlib.h>
270 #include <stddef.h>
271 #endif
272 #include <signal.h>],[sig_atomic_t i = 0],
273         libreplace_cv_sig_atomic_t=yes,libreplace_cv_sig_atomic_t=no)])
274 if test x"$libreplace_cv_sig_atomic_t" = x"yes"; then
275    AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
276 fi
277
278
279 AC_CACHE_CHECK([for O_DIRECT flag to open(2)],libreplace_cv_HAVE_OPEN_O_DIRECT,[
280 AC_TRY_COMPILE([
281 #include <unistd.h>
282 #ifdef HAVE_FCNTL_H
283 #include <fcntl.h>
284 #endif],
285 [int fd = open("/dev/null", O_DIRECT);],
286 libreplace_cv_HAVE_OPEN_O_DIRECT=yes,libreplace_cv_HAVE_OPEN_O_DIRECT=no)])
287 if test x"$libreplace_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
288     AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
289 fi
290
291
292 dnl Check if the C compiler understands volatile (it should, being ANSI).
293 AC_CACHE_CHECK([that the C compiler understands volatile],libreplace_cv_volatile, [
294         AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
295                 libreplace_cv_volatile=yes,libreplace_cv_volatile=no)])
296 if test x"$libreplace_cv_volatile" = x"yes"; then
297         AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
298 fi
299
300 m4_include(system/config.m4)
301
302 m4_include(dlfcn.m4)
303 m4_include(getpass.m4)
304 m4_include(strptime.m4)
305 m4_include(win32.m4)
306 m4_include(timegm.m4)
307 m4_include(repdir.m4)
308 m4_include(crypt.m4)
309
310 if test x$libreplace_cv_have_clock_gettime = xyes ; then
311         SMB_CHECK_CLOCK_ID(CLOCK_MONOTONIC)
312         SMB_CHECK_CLOCK_ID(CLOCK_PROCESS_CPUTIME_ID)
313         SMB_CHECK_CLOCK_ID(CLOCK_REALTIME)
314 fi
315
316 AC_CACHE_CHECK([for struct timespec type],libreplace_cv_struct_timespec, [
317     AC_TRY_COMPILE([
318 #include <sys/types.h>
319 #if STDC_HEADERS
320 #include <stdlib.h>
321 #include <stddef.h>
322 #endif
323 #if TIME_WITH_SYS_TIME
324 # include <sys/time.h>
325 # include <time.h>
326 #else
327 # if HAVE_SYS_TIME_H
328 #  include <sys/time.h>
329 # else
330 #  include <time.h>
331 # endif
332 #endif
333 ],[struct timespec ts;],
334         libreplace_cv_struct_timespec=yes,libreplace_cv_struct_timespec=no)])
335 if test x"$libreplace_cv_struct_timespec" = x"yes"; then
336    AC_DEFINE(HAVE_STRUCT_TIMESPEC,1,[Whether we have struct timespec])
337 fi
338
339 AC_CHECK_FUNCS([printf memset memcpy],,[AC_MSG_ERROR([Required function not found])])
340
341 echo "LIBREPLACE_BROKEN_CHECKS: END"
342 ]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
343
344 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START,
345 [
346 #LIBREPLACE_ALL_CHECKS: START"
347 ])
348 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END,
349 [
350 #LIBREPLACE_ALL_CHECKS: END"
351 ])
352 m4_define(AC_LIBREPLACE_ALL_CHECKS,
353 [
354 AC__LIBREPLACE_ALL_CHECKS_START
355 AC_LIBREPLACE_LOCATION_CHECKS
356 AC_LIBREPLACE_CC_CHECKS
357 AC_LIBREPLACE_BROKEN_CHECKS
358 AC__LIBREPLACE_ALL_CHECKS_END
359 CFLAGS="$CFLAGS -I$libreplacedir"
360 ])
361
362 m4_include(libreplace_cc.m4)
363 m4_include(libreplace_ld.m4)
364 m4_include(libreplace_network.m4)
365 m4_include(libreplace_macros.m4)
366
367
368 dnl SMB_CHECK_CLOCK_ID(clockid)
369 dnl Test whether the specified clock_gettime clock ID is available. If it
370 dnl is, we define HAVE_clockid
371 AC_DEFUN([SMB_CHECK_CLOCK_ID],
372 [
373     AC_MSG_CHECKING(for $1)
374     AC_TRY_LINK([
375 #if TIME_WITH_SYS_TIME
376 # include <sys/time.h>
377 # include <time.h>
378 #else
379 # if HAVE_SYS_TIME_H
380 #  include <sys/time.h>
381 # else
382 #  include <time.h>
383 # endif
384 #endif
385     ],
386     [
387 clockid_t clk = $1;
388     ],
389     [
390         AC_MSG_RESULT(yes)
391         AC_DEFINE(HAVE_$1, 1,
392             [Whether the clock_gettime clock ID $1 is available])
393     ],
394     [
395         AC_MSG_RESULT(no)
396     ])
397 ])
398 m4_ifndef([AC_USE_SYSTEM_EXTENSIONS],[m4_include(autoconf-2.60.m4)])