r20816: merge from samba3:
[amitay/samba.git] / source4 / 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"
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="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 for d in "$srcdir" "$srcdir/lib/replace" "$srcdir/libreplace" "$srcdir/../libreplace" "$srcdir/../replace"; do
38         if test -f "$d/replace.c"; then
39                 libreplacedir="$d"              
40                 AC_SUBST(libreplacedir)
41                 break;
42         fi
43 done
44 LIBREPLACEOBJ="replace.o"
45 AC_SUBST(LIBREPLACEOBJ)
46
47 LIBREPLACEOBJ="${LIBREPLACEOBJ} snprintf.o"
48
49 AC_TYPE_SIGNAL
50 AC_TYPE_UID_T
51 AC_TYPE_MODE_T
52 AC_TYPE_OFF_T
53 AC_TYPE_SIZE_T
54 AC_TYPE_PID_T
55 AC_STRUCT_ST_RDEV
56 AC_CHECK_TYPE(ino_t,unsigned)
57 AC_CHECK_TYPE(loff_t,off_t)
58 AC_CHECK_TYPE(offset_t,loff_t)
59
60 AC_FUNC_MEMCMP
61
62 AC_CHECK_FUNCS(pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp)
63
64 AC_CHECK_HEADERS(stdbool.h sys/select.h)
65 AC_CHECK_HEADERS(setjmp.h)
66
67 AC_CHECK_TYPE(bool, 
68 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
69 [
70 AC_INCLUDES_DEFAULT
71 #ifdef HAVE_STDBOOL_H
72 #include <stdbool.h>
73 #endif]
74 )
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_CACHE_CHECK([for working mmap],samba_cv_HAVE_MMAP,[
86 AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"],
87            samba_cv_HAVE_MMAP=yes,samba_cv_HAVE_MMAP=no,samba_cv_HAVE_MMAP=cross)])
88 if test x"$samba_cv_HAVE_MMAP" = x"yes"; then
89     AC_DEFINE(HAVE_MMAP,1,[Whether mmap works])
90 fi
91
92
93 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
94 AC_CHECK_HEADERS(sys/time.h time.h)
95 AC_CHECK_HEADERS(stdarg.h vararg.h)
96 AC_CHECK_HEADERS(sys/socket.h netinet/in.h netdb.h arpa/inet.h)
97 AC_CHECK_HEADERS(netinet/ip.h netinet/tcp.h netinet/in_systm.h netinet/in_ip.h)
98 AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
99
100
101 dnl we need to check that net/if.h really can be used, to cope with hpux
102 dnl where including it always fails
103 AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
104         AC_COMPILE_IFELSE([AC_LANG_SOURCE([
105                 AC_INCLUDES_DEFAULT
106                 #if HAVE_SYS_SOCKET_H
107                 # include <sys/socket.h>
108                 #endif
109                 #include <net/if.h>
110                 int main(void) {return 0;}])],
111                 [libreplace_cv_USABLE_NET_IF_H=yes],
112                 [libreplace_cv_USABLE_NET_IF_H=no]
113         )
114 ])
115 if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
116         AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
117 fi
118
119 AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[
120 AC_TRY_RUN([
121 #include <stdio.h>
122 #include <unistd.h>
123 #include <sys/types.h>
124 #include <netinet/in.h>
125 #ifdef HAVE_ARPA_INET_H
126 #include <arpa/inet.h>
127 #endif
128 main() { struct in_addr ip; ip.s_addr = 0x12345678;
129 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
130     strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); } 
131 exit(1);}],
132            samba_cv_REPLACE_INET_NTOA=yes,samba_cv_REPLACE_INET_NTOA=no,samba_cv_REPLACE_INET_NTOA=cross)])
133 if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then
134     AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
135 fi
136
137 dnl Provided by replace.c:
138 AC_TRY_COMPILE([
139 #include <sys/types.h>
140 #if STDC_HEADERS
141 #include <stdlib.h>
142 #include <stddef.h>
143 #endif
144 #include <sys/socket.h>], 
145 [socklen_t foo;],,
146 [AC_DEFINE(socklen_t, int,[Socket length type])])
147
148 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
149 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
150 AC_CHECK_FUNCS(waitpid strlcpy strlcat innetgr initgroups memmove strdup)
151 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp socketpair)
152 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
153 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
154 AC_HAVE_DECL(errno, [#include <errno.h>])
155
156 AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[
157 AC_TRY_RUN([#include <stdlib.h>
158 #include <sys/types.h>
159 #include <sys/stat.h>
160 #include <unistd.h>
161 main() { 
162   struct stat st;
163   char tpl[20]="/tmp/test.XXXXXX"; 
164   int fd = mkstemp(tpl); 
165   if (fd == -1) exit(1);
166   unlink(tpl);
167   if (fstat(fd, &st) != 0) exit(1);
168   if ((st.st_mode & 0777) != 0600) exit(1);
169   exit(0);
170 }],
171 samba_cv_HAVE_SECURE_MKSTEMP=yes,
172 samba_cv_HAVE_SECURE_MKSTEMP=no,
173 samba_cv_HAVE_SECURE_MKSTEMP=cross)])
174 if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
175     AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
176 fi
177
178 dnl Provided by snprintf.c:
179 AC_CHECK_HEADERS(stdio.h strings.h)
180 AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
181 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
182
183 AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[
184 AC_TRY_RUN([
185 #include <sys/types.h>
186 #include <stdio.h>
187 #include <stdarg.h>
188 #include <stdlib.h>
189 void foo(const char *format, ...) { 
190        va_list ap;
191        int len;
192        char buf[20];
193        long long l = 1234567890;
194        l *= 100;
195
196        va_start(ap, format);
197        len = vsnprintf(buf, 0, format, ap);
198        va_end(ap);
199        if (len != 5) exit(1);
200
201        va_start(ap, format);
202        len = vsnprintf(0, 0, format, ap);
203        va_end(ap);
204        if (len != 5) exit(2);
205
206        if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
207
208        if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
209        if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
210        if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
211        if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
212
213        exit(0);
214 }
215 main() { foo("hello"); }
216 ],
217 samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)])
218 if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
219     AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
220 fi
221
222
223 dnl VA_COPY
224 AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
225 AC_TRY_LINK([#include <stdarg.h>
226 va_list ap1,ap2;], [va_copy(ap1,ap2);],
227 samba_cv_HAVE_VA_COPY=yes,samba_cv_HAVE_VA_COPY=no)])
228 if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then
229     AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
230 fi
231
232 if test x"$samba_cv_HAVE_VA_COPY" != x"yes"; then
233 AC_CACHE_CHECK([for __va_copy],samba_cv_HAVE___VA_COPY,[
234 AC_TRY_LINK([#include <stdarg.h>
235 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
236 samba_cv_HAVE___VA_COPY=yes,samba_cv_HAVE___VA_COPY=no)])
237 if test x"$samba_cv_HAVE___VA_COPY" = x"yes"; then
238     AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
239 fi
240 fi
241
242 dnl __FUNCTION__ macro
243 AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[
244 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
245 samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)])
246 if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
247     AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
248 else
249     dnl __func__ macro
250     AC_CACHE_CHECK([for __func__ macro],samba_cv_HAVE_func_MACRO,[
251     AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
252     samba_cv_HAVE_func_MACRO=yes,samba_cv_HAVE_func_MACRO=no)])
253     if test x"$samba_cv_HAVE_func_MACRO" = x"yes"; then
254        AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
255     fi
256 fi
257
258 AC_CHECK_HEADERS([sys/param.h limits.h])
259
260 AC_CHECK_TYPE(comparison_fn_t, 
261 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
262
263 AC_CHECK_FUNCS(strnlen setenv)
264 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
265
266 # this test disabled as we don't actually need __VA_ARGS__ yet
267 AC_TRY_CPP([
268 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
269 eprintf("bla", "bar");
270 ], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available]))
271
272 # Check prerequisites
273 AC_CHECK_FUNCS([memset printf syslog], [], 
274                            [ AC_MSG_ERROR([Required function not found])])
275
276 AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [
277     AC_TRY_COMPILE([
278 #include <sys/types.h>
279 #if STDC_HEADERS
280 #include <stdlib.h>
281 #include <stddef.h>
282 #endif
283 #include <signal.h>],[sig_atomic_t i = 0],
284         samba_cv_sig_atomic_t=yes,samba_cv_sig_atomic_t=no)])
285 if test x"$samba_cv_sig_atomic_t" = x"yes"; then
286    AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
287 fi
288
289
290 AC_CACHE_CHECK([for O_DIRECT flag to open(2)],samba_cv_HAVE_OPEN_O_DIRECT,[
291 AC_TRY_COMPILE([
292 #include <unistd.h>
293 #ifdef HAVE_FCNTL_H
294 #include <fcntl.h>
295 #endif],
296 [int fd = open("/dev/null", O_DIRECT);],
297 samba_cv_HAVE_OPEN_O_DIRECT=yes,samba_cv_HAVE_OPEN_O_DIRECT=no)])
298 if test x"$samba_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
299     AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
300 fi 
301
302
303 AC_CACHE_CHECK([that the C compiler can precompile header files],samba_cv_precompiled_headers, [
304         dnl Check whether the compiler can generate precompiled headers
305         touch conftest.h
306         if ${CC-cc} conftest.h 2> /dev/null && test -f conftest.h.gch; then
307                 precompiled_headers=yes
308         else
309                 precompiled_headers=no
310         fi])
311 AC_SUBST(precompiled_headers)
312
313
314 dnl Check if the C compiler understands volatile (it should, being ANSI).
315 AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
316         AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
317                 samba_cv_volatile=yes,samba_cv_volatile=no)])
318 if test x"$samba_cv_volatile" = x"yes"; then
319         AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
320 fi
321
322 m4_include(system/config.m4)
323
324 m4_include(dlfcn.m4)
325 m4_include(getpass.m4)
326 m4_include(win32.m4)
327 m4_include(timegm.m4)
328 m4_include(repdir.m4)
329
330 AC_CHECK_FUNCS([syslog memset setnetgrent getnetgrent endnetgrent memcpy],,
331                            [AC_MSG_ERROR([Required function not found])])
332
333 echo "LIBREPLACE_BROKEN_CHECKS: END"
334 ]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
335
336 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START,
337 [
338 #LIBREPLACE_ALL_CHECKS: START"
339 ])
340 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END,
341 [
342 #LIBREPLACE_ALL_CHECKS: END"
343 ])
344 m4_define(AC_LIBREPLACE_ALL_CHECKS,
345 [
346 AC__LIBREPLACE_ALL_CHECKS_START
347 AC_LIBREPLACE_LOCATION_CHECKS
348 AC_LIBREPLACE_CC_CHECKS
349 AC_LIBREPLACE_BROKEN_CHECKS
350 AC__LIBREPLACE_ALL_CHECKS_END
351 ])
352
353 m4_include(libreplace_cc.m4)
354 m4_include(libreplace_macros.m4)
355 m4_include(autoconf-2.60.m4)