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