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