26b4c3636d7f9500e1b14e3d9f506ecd67b61cc2
[jerry/samba.git] / source / 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 stdint.h sys/select.h)
65 AC_CHECK_HEADERS(setjmp.h)
66
67 LIBREPLACE_PROVIDE_HEADER([stdint.h])
68 LIBREPLACE_PROVIDE_HEADER([stdbool.h])
69
70 AC_CHECK_TYPE(bool, 
71 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
72 [
73 AC_INCLUDES_DEFAULT
74 #ifdef HAVE_STDBOOL_H
75 #include <stdbool.h>
76 #endif]
77 )
78
79 AC_CHECK_TYPE(_Bool, 
80 [AC_DEFINE(HAVE__Bool, 1, [Whether the _Bool type is available])],,
81 [
82 AC_INCLUDES_DEFAULT
83 #ifdef HAVE_STDBOOL_H
84 #include <stdbool.h>
85 #endif]
86 )
87
88 AC_CACHE_CHECK([for working mmap],samba_cv_HAVE_MMAP,[
89 AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"],
90            samba_cv_HAVE_MMAP=yes,samba_cv_HAVE_MMAP=no,samba_cv_HAVE_MMAP=cross)])
91 if test x"$samba_cv_HAVE_MMAP" = x"yes"; then
92     AC_DEFINE(HAVE_MMAP,1,[Whether mmap works])
93 fi
94
95
96 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
97 AC_CHECK_HEADERS(sys/time.h time.h)
98 AC_CHECK_HEADERS(stdarg.h vararg.h)
99 AC_CHECK_HEADERS(sys/socket.h netinet/in.h netdb.h arpa/inet.h)
100 AC_CHECK_HEADERS(netinet/ip.h netinet/tcp.h netinet/in_systm.h netinet/in_ip.h)
101 AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
102 AC_CHECK_HEADERS(sys/mount.h mntent.h)
103
104 dnl we need to check that net/if.h really can be used, to cope with hpux
105 dnl where including it always fails
106 AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
107         AC_COMPILE_IFELSE([AC_LANG_SOURCE([
108                 AC_INCLUDES_DEFAULT
109                 #if HAVE_SYS_SOCKET_H
110                 # include <sys/socket.h>
111                 #endif
112                 #include <net/if.h>
113                 int main(void) {return 0;}])],
114                 [libreplace_cv_USABLE_NET_IF_H=yes],
115                 [libreplace_cv_USABLE_NET_IF_H=no]
116         )
117 ])
118 if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
119         AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
120 fi
121
122 AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[
123 AC_TRY_RUN([
124 #include <stdio.h>
125 #include <unistd.h>
126 #include <sys/types.h>
127 #include <netinet/in.h>
128 #ifdef HAVE_ARPA_INET_H
129 #include <arpa/inet.h>
130 #endif
131 main() { struct in_addr ip; ip.s_addr = 0x12345678;
132 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
133     strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); } 
134 exit(1);}],
135            samba_cv_REPLACE_INET_NTOA=yes,samba_cv_REPLACE_INET_NTOA=no,samba_cv_REPLACE_INET_NTOA=cross)])
136 if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then
137     AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
138 fi
139
140 AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])
141 AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])
142 AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
143 AC_HAVE_TYPE([struct sockaddr], [#include <sys/socket.h>])
144 AC_HAVE_TYPE([struct sockaddr_storage], [
145 #include <sys/socket.h>
146 #include <sys/types.h>
147 #include <netinet/in.h>
148 ])
149 AC_HAVE_TYPE([struct sockaddr_in6], [
150 #include <sys/socket.h>
151 #include <sys/types.h>
152 #include <netinet/in.h>
153 ])
154
155 dnl test for getaddrinfo/getnameinfo
156 AC_CACHE_CHECK([for getaddrinfo],samba_cv_HAVE_GETADDRINFO,[
157 AC_TRY_COMPILE([
158 #include <sys/types.h>
159 #if STDC_HEADERS
160 #include <stdlib.h>
161 #include <stddef.h>
162 #endif
163 #include <sys/socket.h>
164 #include <netdb.h>],
165 [
166 struct sockaddr sa;
167 struct addrinfo *ai = NULL;
168 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
169 if (ret != 0) {
170         const char *es = gai_strerror(ret);
171 }
172 freeaddrinfo(ai);
173 ret = getnameinfo(&sa, sizeof(sa),
174                 NULL, 0,
175                 NULL, 0, 0);
176
177 ],
178 samba_cv_HAVE_GETADDRINFO=yes,samba_cv_HAVE_GETADDRINFO=no)])
179 if test x"$samba_cv_HAVE_GETADDRINFO" = x"yes"; then
180     AC_DEFINE(HAVE_GETADDRINFO,1,[Whether the system has getaddrinfo and getnameinfo])
181     AC_DEFINE(HAVE_FREEADDRINFO,1,[Whether the system has freeaddrinfo])
182     AC_DEFINE(HAVE_GAI_STRERROR,1,[Whether the system has gai_strerror])
183 fi
184
185 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
186 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
187 AC_CHECK_FUNCS(waitpid strlcpy strlcat initgroups memmove strdup)
188 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp socketpair)
189 AC_CHECK_FUNCS(isatty)
190 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
191 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
192 AC_HAVE_DECL(errno, [#include <errno.h>])
193
194 AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[
195 AC_TRY_RUN([#include <stdlib.h>
196 #include <sys/types.h>
197 #include <sys/stat.h>
198 #include <unistd.h>
199 main() { 
200   struct stat st;
201   char tpl[20]="/tmp/test.XXXXXX"; 
202   int fd = mkstemp(tpl); 
203   if (fd == -1) exit(1);
204   unlink(tpl);
205   if (fstat(fd, &st) != 0) exit(1);
206   if ((st.st_mode & 0777) != 0600) exit(1);
207   exit(0);
208 }],
209 samba_cv_HAVE_SECURE_MKSTEMP=yes,
210 samba_cv_HAVE_SECURE_MKSTEMP=no,
211 samba_cv_HAVE_SECURE_MKSTEMP=cross)])
212 if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
213     AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
214 fi
215
216 dnl Provided by snprintf.c:
217 AC_CHECK_HEADERS(stdio.h strings.h)
218 AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
219 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
220
221 AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[
222 AC_TRY_RUN([
223 #include <sys/types.h>
224 #include <stdio.h>
225 #include <stdarg.h>
226 #include <stdlib.h>
227 void foo(const char *format, ...) { 
228        va_list ap;
229        int len;
230        char buf[20];
231        long long l = 1234567890;
232        l *= 100;
233
234        va_start(ap, format);
235        len = vsnprintf(buf, 0, format, ap);
236        va_end(ap);
237        if (len != 5) exit(1);
238
239        va_start(ap, format);
240        len = vsnprintf(0, 0, format, ap);
241        va_end(ap);
242        if (len != 5) exit(2);
243
244        if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
245
246        if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
247        if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
248        if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
249        if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
250
251        exit(0);
252 }
253 main() { foo("hello"); }
254 ],
255 samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)])
256 if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
257     AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
258 fi
259
260
261 dnl VA_COPY
262 AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
263 AC_TRY_LINK([#include <stdarg.h>
264 va_list ap1,ap2;], [va_copy(ap1,ap2);],
265 samba_cv_HAVE_VA_COPY=yes,samba_cv_HAVE_VA_COPY=no)])
266 if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then
267     AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
268 fi
269
270 if test x"$samba_cv_HAVE_VA_COPY" != x"yes"; then
271 AC_CACHE_CHECK([for __va_copy],samba_cv_HAVE___VA_COPY,[
272 AC_TRY_LINK([#include <stdarg.h>
273 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
274 samba_cv_HAVE___VA_COPY=yes,samba_cv_HAVE___VA_COPY=no)])
275 if test x"$samba_cv_HAVE___VA_COPY" = x"yes"; then
276     AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
277 fi
278 fi
279
280 dnl __FUNCTION__ macro
281 AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[
282 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
283 samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)])
284 if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
285     AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
286 else
287     dnl __func__ macro
288     AC_CACHE_CHECK([for __func__ macro],samba_cv_HAVE_func_MACRO,[
289     AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
290     samba_cv_HAVE_func_MACRO=yes,samba_cv_HAVE_func_MACRO=no)])
291     if test x"$samba_cv_HAVE_func_MACRO" = x"yes"; then
292        AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
293     fi
294 fi
295
296 AC_CHECK_HEADERS([sys/param.h limits.h])
297
298 AC_CHECK_TYPE(comparison_fn_t, 
299 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
300
301 AC_HAVE_DECL(setenv, [#include <stdlib.h>])
302 AC_CHECK_FUNCS(setenv unsetenv)
303
304 AC_CHECK_FUNCS(strnlen)
305 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
306
307 # this test disabled as we don't actually need __VA_ARGS__ yet
308 AC_TRY_CPP([
309 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
310 eprintf("bla", "bar");
311 ], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available]))
312
313 # Check prerequisites
314 AC_CHECK_FUNCS([memset printf syslog], [], 
315                            [ AC_MSG_ERROR([Required function not found])])
316
317 AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [
318     AC_TRY_COMPILE([
319 #include <sys/types.h>
320 #if STDC_HEADERS
321 #include <stdlib.h>
322 #include <stddef.h>
323 #endif
324 #include <signal.h>],[sig_atomic_t i = 0],
325         samba_cv_sig_atomic_t=yes,samba_cv_sig_atomic_t=no)])
326 if test x"$samba_cv_sig_atomic_t" = x"yes"; then
327    AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
328 fi
329
330
331 AC_CACHE_CHECK([for O_DIRECT flag to open(2)],samba_cv_HAVE_OPEN_O_DIRECT,[
332 AC_TRY_COMPILE([
333 #include <unistd.h>
334 #ifdef HAVE_FCNTL_H
335 #include <fcntl.h>
336 #endif],
337 [int fd = open("/dev/null", O_DIRECT);],
338 samba_cv_HAVE_OPEN_O_DIRECT=yes,samba_cv_HAVE_OPEN_O_DIRECT=no)])
339 if test x"$samba_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
340     AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
341 fi
342
343
344 dnl Check if the C compiler understands volatile (it should, being ANSI).
345 AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
346         AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
347                 samba_cv_volatile=yes,samba_cv_volatile=no)])
348 if test x"$samba_cv_volatile" = x"yes"; then
349         AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
350 fi
351
352 m4_include(system/config.m4)
353
354 m4_include(dlfcn.m4)
355 m4_include(getpass.m4)
356 m4_include(strptime.m4)
357 m4_include(win32.m4)
358 m4_include(timegm.m4)
359 m4_include(inet_ntop.m4)
360 m4_include(inet_pton.m4)
361 m4_include(repdir.m4)
362
363 AC_CHECK_FUNCS([syslog memset memcpy],,[AC_MSG_ERROR([Required function not found])])
364
365 echo "LIBREPLACE_BROKEN_CHECKS: END"
366 ]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
367
368 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START,
369 [
370 #LIBREPLACE_ALL_CHECKS: START"
371 ])
372 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END,
373 [
374 #LIBREPLACE_ALL_CHECKS: END"
375 ])
376 m4_define(AC_LIBREPLACE_ALL_CHECKS,
377 [
378 AC__LIBREPLACE_ALL_CHECKS_START
379 AC_LIBREPLACE_LOCATION_CHECKS
380 AC_LIBREPLACE_CC_CHECKS
381 AC_LIBREPLACE_BROKEN_CHECKS
382 AC__LIBREPLACE_ALL_CHECKS_END
383 CFLAGS="$CFLAGS -I$libreplacedir"
384 ])
385
386 m4_include(libreplace_cc.m4)
387 m4_include(libreplace_macros.m4)
388 m4_include(autoconf-2.60.m4)