r18067: some tweaks for irix and hpux
[bbaumbach/samba-autobuild/.git] / source / lib / replace / config.m4
1 AC_CHECK_HEADERS([stdint.h inttypes.h])
2 AC_CHECK_TYPE(uint_t, unsigned int)
3 AC_CHECK_TYPE(uint8_t, unsigned char)
4 AC_CHECK_TYPE(int8_t, char)
5 AC_CHECK_TYPE(int16_t, short)
6 AC_CHECK_TYPE(uint16_t, unsigned short)
7 AC_CHECK_TYPE(int32_t, long)
8 AC_CHECK_TYPE(intptr_t, unsigned long long)
9 AC_CHECK_TYPE(uint32_t, unsigned long)
10 AC_CHECK_TYPE(ssize_t, int)
11
12 AC_CHECK_HEADERS(stdbool.h)
13
14 AC_CHECK_TYPE(bool, 
15 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
16 [
17 AC_INCLUDES_DEFAULT
18 #ifdef HAVE_STDBOOL_H
19 #include <stdbool.h>
20 #endif]
21 )
22
23
24 AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[
25 AC_TRY_RUN([
26 #include <stdio.h>
27 #include <sys/types.h>
28 #include <netinet/in.h>
29 #ifdef HAVE_ARPA_INET_H
30 #include <arpa/inet.h>
31 #endif
32 main() { struct in_addr ip; ip.s_addr = 0x12345678;
33 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
34     strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); } 
35 exit(1);}],
36            samba_cv_REPLACE_INET_NTOA=yes,samba_cv_REPLACE_INET_NTOA=no,samba_cv_REPLACE_INET_NTOA=cross)])
37 if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then
38     AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
39 fi
40
41 dnl Provided by replace.c:
42 AC_TRY_COMPILE([
43 #include <sys/types.h>
44 #if STDC_HEADERS
45 #include <stdlib.h>
46 #include <stddef.h>
47 #endif
48 #include <sys/socket.h>], 
49 [socklen_t foo;],,
50 [AC_DEFINE(socklen_t, int,[Socket length type])])
51
52 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
53 AC_CHECK_HEADERS(sys/time.h time.h)
54 AC_CHECK_HEADERS(sys/socket.h netinet/in.h)
55 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
56 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
57 AC_CHECK_FUNCS(waitpid strlcpy strlcat innetgr initgroups memmove strdup)
58 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp)
59 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
60 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
61 AC_HAVE_DECL(errno, [#include <errno.h>])
62
63 AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[
64 AC_TRY_RUN([#include <stdlib.h>
65 #include <sys/types.h>
66 #include <sys/stat.h>
67 #include <unistd.h>
68 main() { 
69   struct stat st;
70   char tpl[20]="/tmp/test.XXXXXX"; 
71   int fd = mkstemp(tpl); 
72   if (fd == -1) exit(1);
73   unlink(tpl);
74   if (fstat(fd, &st) != 0) exit(1);
75   if ((st.st_mode & 0777) != 0600) exit(1);
76   exit(0);
77 }],
78 samba_cv_HAVE_SECURE_MKSTEMP=yes,
79 samba_cv_HAVE_SECURE_MKSTEMP=no,
80 samba_cv_HAVE_SECURE_MKSTEMP=cross)])
81 if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
82     AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
83 fi
84
85 dnl Provided by snprintf.c:
86 AC_HAVE_DECL(asprintf, [#include <stdio.h>])
87 AC_HAVE_DECL(vasprintf, [#include <stdio.h>])
88 AC_HAVE_DECL(vsnprintf, [#include <stdio.h>])
89 AC_HAVE_DECL(snprintf, [#include <stdio.h>])
90 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
91 AC_CHECK_HEADERS(strings.h)
92
93 AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[
94 AC_TRY_RUN([
95 #include <sys/types.h>
96 #include <stdio.h>
97 #include <stdarg.h>
98 #include <stdlib.h>
99 void foo(const char *format, ...) { 
100        va_list ap;
101        int len;
102        char buf[20];
103        long long l = 1234567890;
104        l *= 100;
105
106        va_start(ap, format);
107        len = vsnprintf(buf, 0, format, ap);
108        va_end(ap);
109        if (len != 5) exit(1);
110
111        va_start(ap, format);
112        len = vsnprintf(0, 0, format, ap);
113        va_end(ap);
114        if (len != 5) exit(2);
115
116        if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
117
118        if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
119        if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
120        if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
121        if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
122
123        exit(0);
124 }
125 main() { foo("hello"); }
126 ],
127 samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)])
128 if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
129     AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
130 fi
131
132 dnl Provided by dlfcn.c:
133 AC_SEARCH_LIBS_EXT(dlopen, [dl], DL_LIBS)
134 SMB_EXT_LIB(DL,[${DL_LIBS}],[${DL_CFLAGS}],[${DL_CPPFLAGS}],[${DL_LDFLAGS}])
135 SAVE_LIBS="$LIBS"
136 LIBS="$LIBS $DL_LIBS"
137 AC_CHECK_HEADERS(dlfcn.h)
138 AC_CHECK_FUNCS(dlopen dlsym dlerror dlclose)
139 LIBS="$SAVE_LIBS"
140
141 AC_CHECK_FUNCS([syslog memset setnetgrent getnetgrent endnetgrent memcpy],,
142                            [AC_MSG_ERROR([Required function not found])])
143
144 sinclude(lib/replace/getpass.m4)
145 sinclude(getpass.m4)
146 sinclude(lib/replace/cc_features.m4)
147 sinclude(cc_features.m4)
148
149 LIBREPLACE_C99_STRUCT_INIT(c99_struct_initialization=yes,
150                         c99_struct_initialization=no)
151
152 dnl VA_COPY
153 AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
154 AC_TRY_LINK([#include <stdarg.h>
155 va_list ap1,ap2;], [va_copy(ap1,ap2);],
156 samba_cv_HAVE_VA_COPY=yes,samba_cv_HAVE_VA_COPY=no)])
157 if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then
158     AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
159 fi
160
161 if test x"$samba_cv_HAVE_VA_COPY" != x"yes"; then
162 AC_CACHE_CHECK([for __va_copy],samba_cv_HAVE___VA_COPY,[
163 AC_TRY_LINK([#include <stdarg.h>
164 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
165 samba_cv_HAVE___VA_COPY=yes,samba_cv_HAVE___VA_COPY=no)])
166 if test x"$samba_cv_HAVE___VA_COPY" = x"yes"; then
167     AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
168 fi
169 fi
170
171 dnl __FUNCTION__ macro
172 AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[
173 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
174 samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)])
175 if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
176     AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
177 else
178     dnl __func__ macro
179     AC_CACHE_CHECK([for __func__ macro],samba_cv_HAVE_func_MACRO,[
180     AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
181     samba_cv_HAVE_func_MACRO=yes,samba_cv_HAVE_func_MACRO=no)])
182     if test x"$samba_cv_HAVE_func_MACRO" = x"yes"; then
183        AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
184     fi
185 fi
186
187 AC_CHECK_HEADERS([sys/param.h limits.h])
188
189 AC_CHECK_TYPE(comparison_fn_t, 
190 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
191
192 AC_CHECK_FUNCS(timegm strnlen setenv)
193 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
194
195 # this test disabled as we don't actually need __VA_ARGS__ yet
196 # AC_TRY_CPP([
197 # #define eprintf(...) fprintf(stderr, __VA_ARGS__)
198 # eprintf("bla", "bar");
199 # ], [], [AC_MSG_ERROR([__VA_ARGS__ is required])])
200
201 # Check prerequisites
202 AC_CHECK_FUNCS([memset printf syslog], [], 
203                            [ AC_MSG_ERROR([Required function not found])])
204
205 AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [
206     AC_TRY_COMPILE([
207 #include <sys/types.h>
208 #if STDC_HEADERS
209 #include <stdlib.h>
210 #include <stddef.h>
211 #endif
212 #include <signal.h>],[sig_atomic_t i = 0],
213         samba_cv_sig_atomic_t=yes,samba_cv_sig_atomic_t=no)])
214 if test x"$samba_cv_sig_atomic_t" = x"yes"; then
215    AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
216 fi