r18445: splitout the dlfcn related tests
[jelmer/samba4-debian.git] / source / lib / replace / libreplace.m4
1 dnl find the libreplace sources. This is meant to work both for 
2 dnl libreplace standalone builds, and builds of packages using libreplace
3 libreplacedir=""
4 for d in "$srcdir" "$srcdir/lib/replace" "$srcdir/libreplace" "$srcdir/../libreplace" "$srcdir/../replace"; do
5         if test -f "$d/replace.c"; then
6                 libreplacedir="$d"              
7                 AC_SUBST(libreplacedir)
8                 break;
9         fi
10 done
11 LIBREPLACEOBJ="replace.o"
12 AC_SUBST(LIBREPLACEOBJ)
13
14 LIBREPLACEOBJ="${LIBREPLACEOBJ} snprintf.o timegm.o"
15
16 dnl stop the C89 attempt by autoconf - if autoconf detects -Ae it will enable it
17 dnl which conflicts with C99 on HPUX
18 ac_cv_prog_cc_Ae=no
19
20 savedCFLAGS=$CFLAGS
21 AC_PROG_CC
22 CFLAGS=$savedCFLAGS
23 AC_ISC_POSIX
24 AC_USE_SYSTEM_EXTENSIONS
25 AC_PROG_CC_C99
26 AC_C_INLINE
27 AC_PROG_INSTALL
28
29 AH_VERBATIM([_XOPEN_SOURCE_EXTENDED],
30 [/* Enable XOPEN extensions on systems that have them.  */
31 #ifndef _XOPEN_SOURCE_EXTENDED
32 # define _XOPEN_SOURCE_EXTENDED 1
33 #endif])
34
35 AH_VERBATIM([_OSF_SOURCE],
36 [/* Enable OSF extensions on systems that have them.  */
37 #ifndef _OSF_SOURCE
38 # define _OSF_SOURCE 1
39 #endif])
40
41 LIBREPLACE_C99_STRUCT_INIT([],[])
42
43 AC_SYS_LARGEFILE
44
45 dnl Add #include for broken IRIX header files
46 case "$host_os" in
47         *irix6*) AC_ADD_INCLUDE(<standards.h>)
48                 ;;
49 esac
50
51 AC_CHECK_HEADERS([standards.h])
52
53 AC_C_BIGENDIAN
54 AC_HEADER_STDC
55
56
57 AC_CHECK_SIZEOF(off_t,cross)
58 AC_CHECK_SIZEOF(size_t,cross)
59 AC_CHECK_SIZEOF(ssize_t,cross)
60
61 AC_CHECK_HEADERS([stdint.h inttypes.h])
62 AC_CHECK_TYPE(uint_t, unsigned int)
63 AC_CHECK_TYPE(uint8_t, unsigned char)
64 AC_CHECK_TYPE(int8_t, char)
65 AC_CHECK_TYPE(int16_t, short)
66 AC_CHECK_TYPE(uint16_t, unsigned short)
67 AC_CHECK_TYPE(int32_t, long)
68 AC_CHECK_TYPE(intptr_t, unsigned long long)
69 AC_CHECK_TYPE(uint32_t, unsigned long)
70 AC_CHECK_TYPE(ssize_t, int)
71 AC_CHECK_TYPE(ptrdiff_t, unsigned long long)
72
73 dnl these are needed for heimdal roken.h
74 AC_CHECK_TYPE(struct sockaddr, [], [], [
75 AC_INCLUDES_DEFAULT
76 #include <sys/socket.h>])
77 AC_CHECK_TYPE(struct sockaddr_storage, [], [], [
78 AC_INCLUDES_DEFAULT
79 #include <sys/socket.h>])
80 AC_CHECK_TYPE(struct addrinfo, [], [], [
81 AC_INCLUDES_DEFAULT
82 #include <netdb.h>])
83
84 AC_TYPE_SIGNAL
85 AC_TYPE_UID_T
86 AC_TYPE_MODE_T
87 AC_TYPE_OFF_T
88 AC_TYPE_SIZE_T
89 AC_TYPE_PID_T
90 AC_STRUCT_ST_RDEV
91 AC_CHECK_TYPE(ino_t,unsigned)
92 AC_CHECK_TYPE(loff_t,off_t)
93 AC_CHECK_TYPE(offset_t,loff_t)
94 AC_CHECK_TYPES(long long)
95
96 AC_FUNC_MEMCMP
97
98 AC_CHECK_FUNCS(pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp)
99
100 AC_CHECK_HEADERS(stdbool.h stddef.h sys/select.h)
101
102 AC_CHECK_HEADERS(sys/epoll.h)
103 AC_CHECK_FUNCS(epoll_create)
104
105 AC_CHECK_TYPE(bool, 
106 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
107 [
108 AC_INCLUDES_DEFAULT
109 #ifdef HAVE_STDBOOL_H
110 #include <stdbool.h>
111 #endif]
112 )
113
114 AC_CHECK_TYPE(_Bool, 
115 [AC_DEFINE(HAVE__Bool, 1, [Whether the _Bool type is available])],,
116 [
117 AC_INCLUDES_DEFAULT
118 #ifdef HAVE_STDBOOL_H
119 #include <stdbool.h>
120 #endif]
121 )
122
123 AC_CACHE_CHECK([for working mmap],samba_cv_HAVE_MMAP,[
124 AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"],
125            samba_cv_HAVE_MMAP=yes,samba_cv_HAVE_MMAP=no,samba_cv_HAVE_MMAP=cross)])
126 if test x"$samba_cv_HAVE_MMAP" = x"yes"; then
127     AC_DEFINE(HAVE_MMAP,1,[Whether mmap works])
128 fi
129
130
131 AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[
132 AC_TRY_RUN([
133 #include <stdio.h>
134 #include <unistd.h>
135 #include <sys/types.h>
136 #include <netinet/in.h>
137 #ifdef HAVE_ARPA_INET_H
138 #include <arpa/inet.h>
139 #endif
140 main() { struct in_addr ip; ip.s_addr = 0x12345678;
141 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
142     strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); } 
143 exit(1);}],
144            samba_cv_REPLACE_INET_NTOA=yes,samba_cv_REPLACE_INET_NTOA=no,samba_cv_REPLACE_INET_NTOA=cross)])
145 if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then
146     AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
147 fi
148
149 dnl Provided by replace.c:
150 AC_TRY_COMPILE([
151 #include <sys/types.h>
152 #if STDC_HEADERS
153 #include <stdlib.h>
154 #include <stddef.h>
155 #endif
156 #include <sys/socket.h>], 
157 [socklen_t foo;],,
158 [AC_DEFINE(socklen_t, int,[Socket length type])])
159
160 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
161 AC_CHECK_HEADERS(sys/time.h time.h)
162 AC_CHECK_HEADERS(sys/socket.h netinet/in.h)
163 AC_CHECK_HEADERS(stdarg.h vararg.h)
164 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
165 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
166 AC_CHECK_FUNCS(waitpid strlcpy strlcat innetgr initgroups memmove strdup)
167 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp)
168 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
169 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
170 AC_HAVE_DECL(errno, [#include <errno.h>])
171
172 AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[
173 AC_TRY_RUN([#include <stdlib.h>
174 #include <sys/types.h>
175 #include <sys/stat.h>
176 #include <unistd.h>
177 main() { 
178   struct stat st;
179   char tpl[20]="/tmp/test.XXXXXX"; 
180   int fd = mkstemp(tpl); 
181   if (fd == -1) exit(1);
182   unlink(tpl);
183   if (fstat(fd, &st) != 0) exit(1);
184   if ((st.st_mode & 0777) != 0600) exit(1);
185   exit(0);
186 }],
187 samba_cv_HAVE_SECURE_MKSTEMP=yes,
188 samba_cv_HAVE_SECURE_MKSTEMP=no,
189 samba_cv_HAVE_SECURE_MKSTEMP=cross)])
190 if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
191     AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
192 fi
193
194 dnl Provided by snprintf.c:
195 AC_CHECK_HEADERS(stdio.h strings.h)
196 AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
197 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
198
199 AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[
200 AC_TRY_RUN([
201 #include <sys/types.h>
202 #include <stdio.h>
203 #include <stdarg.h>
204 #include <stdlib.h>
205 void foo(const char *format, ...) { 
206        va_list ap;
207        int len;
208        char buf[20];
209        long long l = 1234567890;
210        l *= 100;
211
212        va_start(ap, format);
213        len = vsnprintf(buf, 0, format, ap);
214        va_end(ap);
215        if (len != 5) exit(1);
216
217        va_start(ap, format);
218        len = vsnprintf(0, 0, format, ap);
219        va_end(ap);
220        if (len != 5) exit(2);
221
222        if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
223
224        if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
225        if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
226        if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
227        if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
228
229        exit(0);
230 }
231 main() { foo("hello"); }
232 ],
233 samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)])
234 if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
235     AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
236 fi
237
238
239 AC_CHECK_FUNCS([syslog memset setnetgrent getnetgrent endnetgrent memcpy],,
240                            [AC_MSG_ERROR([Required function not found])])
241
242 m4_include(dlfcn.m4)
243 m4_include(getpass.m4)
244 m4_include(system/config.m4)
245
246 LIBREPLACE_C99_STRUCT_INIT(c99_struct_initialization=yes,
247                         c99_struct_initialization=no)
248
249 dnl VA_COPY
250 AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
251 AC_TRY_LINK([#include <stdarg.h>
252 va_list ap1,ap2;], [va_copy(ap1,ap2);],
253 samba_cv_HAVE_VA_COPY=yes,samba_cv_HAVE_VA_COPY=no)])
254 if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then
255     AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
256 fi
257
258 if test x"$samba_cv_HAVE_VA_COPY" != x"yes"; then
259 AC_CACHE_CHECK([for __va_copy],samba_cv_HAVE___VA_COPY,[
260 AC_TRY_LINK([#include <stdarg.h>
261 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
262 samba_cv_HAVE___VA_COPY=yes,samba_cv_HAVE___VA_COPY=no)])
263 if test x"$samba_cv_HAVE___VA_COPY" = x"yes"; then
264     AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
265 fi
266 fi
267
268 dnl __FUNCTION__ macro
269 AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[
270 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
271 samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)])
272 if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
273     AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
274 else
275     dnl __func__ macro
276     AC_CACHE_CHECK([for __func__ macro],samba_cv_HAVE_func_MACRO,[
277     AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
278     samba_cv_HAVE_func_MACRO=yes,samba_cv_HAVE_func_MACRO=no)])
279     if test x"$samba_cv_HAVE_func_MACRO" = x"yes"; then
280        AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
281     fi
282 fi
283
284 AC_CHECK_HEADERS([sys/param.h limits.h])
285
286 AC_CHECK_TYPE(comparison_fn_t, 
287 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
288
289 AC_CHECK_FUNCS(timegm strnlen setenv)
290 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
291
292 # this test disabled as we don't actually need __VA_ARGS__ yet
293 # AC_TRY_CPP([
294 # #define eprintf(...) fprintf(stderr, __VA_ARGS__)
295 # eprintf("bla", "bar");
296 # ], [], [AC_MSG_ERROR([__VA_ARGS__ is required])])
297
298 # Check prerequisites
299 AC_CHECK_FUNCS([memset printf syslog], [], 
300                            [ AC_MSG_ERROR([Required function not found])])
301
302 AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [
303     AC_TRY_COMPILE([
304 #include <sys/types.h>
305 #if STDC_HEADERS
306 #include <stdlib.h>
307 #include <stddef.h>
308 #endif
309 #include <signal.h>],[sig_atomic_t i = 0],
310         samba_cv_sig_atomic_t=yes,samba_cv_sig_atomic_t=no)])
311 if test x"$samba_cv_sig_atomic_t" = x"yes"; then
312    AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
313 fi
314
315
316 AC_CACHE_CHECK([for O_DIRECT flag to open(2)],samba_cv_HAVE_OPEN_O_DIRECT,[
317 AC_TRY_COMPILE([
318 #include <unistd.h>
319 #ifdef HAVE_FCNTL_H
320 #include <fcntl.h>
321 #endif],
322 [int fd = open("/dev/null", O_DIRECT);],
323 samba_cv_HAVE_OPEN_O_DIRECT=yes,samba_cv_HAVE_OPEN_O_DIRECT=no)])
324 if test x"$samba_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
325     AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
326 fi 
327
328
329 AC_CACHE_CHECK([that the C compiler can precompile header files],samba_cv_precompiled_headers, [
330         dnl Check whether the compiler can generate precompiled headers
331         touch conftest.h
332         if ${CC-cc} conftest.h 2> /dev/null && test -f conftest.h.gch; then
333                 precompiled_headers=yes
334         else
335                 precompiled_headers=no
336         fi])
337 AC_SUBST(precompiled_headers)
338
339
340 dnl Check if the C compiler understands volatile (it should, being ANSI).
341 AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
342         AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
343                 samba_cv_volatile=yes,samba_cv_volatile=no)])
344 if test x"$samba_cv_volatile" = x"yes"; then
345         AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
346 fi