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