1 dnl find the libreplace sources. This is meant to work both for
2 dnl libreplace standalone builds, and builds of packages using libreplace
4 for d in "$srcdir" "$srcdir/lib/replace" "$srcdir/libreplace" "$srcdir/../libreplace" "$srcdir/../replace"; do
5 if test -f "$d/replace.c"; then
7 AC_SUBST(libreplacedir)
11 LIBREPLACEOBJ="dlfcn.o getpass.o replace.o snprintf.o timegm.o"
12 AC_SUBST(LIBREPLACEOBJ)
14 dnl needed before AC_TRY_COMPILE
16 AC_USE_SYSTEM_EXTENSIONS
21 LIBREPLACE_C99_STRUCT_INIT([],[])
25 dnl Add #include for broken IRIX header files
27 *irix6*) AC_ADD_INCLUDE(<standards.h>)
35 AC_CHECK_SIZEOF(off_t,cross)
36 AC_CHECK_SIZEOF(size_t,cross)
37 AC_CHECK_SIZEOF(ssize_t,cross)
40 AC_CHECK_HEADERS([stdint.h inttypes.h])
41 AC_CHECK_TYPE(uint_t, unsigned int)
42 AC_CHECK_TYPE(uint8_t, unsigned char)
43 AC_CHECK_TYPE(int8_t, char)
44 AC_CHECK_TYPE(int16_t, short)
45 AC_CHECK_TYPE(uint16_t, unsigned short)
46 AC_CHECK_TYPE(int32_t, long)
47 AC_CHECK_TYPE(intptr_t, unsigned long long)
48 AC_CHECK_TYPE(uint32_t, unsigned long)
49 AC_CHECK_TYPE(ssize_t, int)
58 AC_CHECK_TYPE(ino_t,unsigned)
59 AC_CHECK_TYPE(loff_t,off_t)
60 AC_CHECK_TYPE(offset_t,loff_t)
61 AC_CHECK_TYPES(long long)
65 AC_CHECK_FUNCS(pipe strftime srandom random srand rand usleep setbuffer)
67 AC_CHECK_HEADERS(stdbool.h stddef.h)
70 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
79 AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[
82 #include <sys/types.h>
83 #include <netinet/in.h>
84 #ifdef HAVE_ARPA_INET_H
85 #include <arpa/inet.h>
87 main() { struct in_addr ip; ip.s_addr = 0x12345678;
88 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
89 strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
91 samba_cv_REPLACE_INET_NTOA=yes,samba_cv_REPLACE_INET_NTOA=no,samba_cv_REPLACE_INET_NTOA=cross)])
92 if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then
93 AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
96 dnl Provided by replace.c:
98 #include <sys/types.h>
103 #include <sys/socket.h>],
105 [AC_DEFINE(socklen_t, int,[Socket length type])])
107 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
108 AC_CHECK_HEADERS(sys/time.h time.h)
109 AC_CHECK_HEADERS(sys/socket.h netinet/in.h)
110 AC_CHECK_HEADERS(stdarg.h vararg.h)
111 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
112 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
113 AC_CHECK_FUNCS(waitpid strlcpy strlcat innetgr initgroups memmove strdup)
114 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp)
115 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
116 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
117 AC_HAVE_DECL(errno, [#include <errno.h>])
119 AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[
120 AC_TRY_RUN([#include <stdlib.h>
121 #include <sys/types.h>
122 #include <sys/stat.h>
126 char tpl[20]="/tmp/test.XXXXXX";
127 int fd = mkstemp(tpl);
128 if (fd == -1) exit(1);
130 if (fstat(fd, &st) != 0) exit(1);
131 if ((st.st_mode & 0777) != 0600) exit(1);
134 samba_cv_HAVE_SECURE_MKSTEMP=yes,
135 samba_cv_HAVE_SECURE_MKSTEMP=no,
136 samba_cv_HAVE_SECURE_MKSTEMP=cross)])
137 if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
138 AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
141 dnl Provided by snprintf.c:
142 AC_CHECK_HEADERS(stdio.h strings.h)
143 AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
144 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
146 AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[
148 #include <sys/types.h>
152 void foo(const char *format, ...) {
156 long long l = 1234567890;
159 va_start(ap, format);
160 len = vsnprintf(buf, 0, format, ap);
162 if (len != 5) exit(1);
164 va_start(ap, format);
165 len = vsnprintf(0, 0, format, ap);
167 if (len != 5) exit(2);
169 if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
171 if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
172 if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
173 if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
174 if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
178 main() { foo("hello"); }
180 samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)])
181 if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
182 AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
185 dnl dummies provided by dlfcn.c if not available
188 AC_SEARCH_LIBS(dlopen, dl)
189 AC_CHECK_HEADERS(dlfcn.h)
190 AC_CHECK_FUNCS(dlopen dlsym dlerror dlclose)
195 AC_CHECK_FUNCS([syslog memset setnetgrent getnetgrent endnetgrent memcpy],,
196 [AC_MSG_ERROR([Required function not found])])
198 m4_include(getpass.m4)
199 m4_include(system/config.m4)
201 LIBREPLACE_C99_STRUCT_INIT(c99_struct_initialization=yes,
202 c99_struct_initialization=no)
205 AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
206 AC_TRY_LINK([#include <stdarg.h>
207 va_list ap1,ap2;], [va_copy(ap1,ap2);],
208 samba_cv_HAVE_VA_COPY=yes,samba_cv_HAVE_VA_COPY=no)])
209 if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then
210 AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
213 if test x"$samba_cv_HAVE_VA_COPY" != x"yes"; then
214 AC_CACHE_CHECK([for __va_copy],samba_cv_HAVE___VA_COPY,[
215 AC_TRY_LINK([#include <stdarg.h>
216 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
217 samba_cv_HAVE___VA_COPY=yes,samba_cv_HAVE___VA_COPY=no)])
218 if test x"$samba_cv_HAVE___VA_COPY" = x"yes"; then
219 AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
223 dnl __FUNCTION__ macro
224 AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[
225 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
226 samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)])
227 if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
228 AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
231 AC_CACHE_CHECK([for __func__ macro],samba_cv_HAVE_func_MACRO,[
232 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
233 samba_cv_HAVE_func_MACRO=yes,samba_cv_HAVE_func_MACRO=no)])
234 if test x"$samba_cv_HAVE_func_MACRO" = x"yes"; then
235 AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
239 AC_CHECK_HEADERS([sys/param.h limits.h])
241 AC_CHECK_TYPE(comparison_fn_t,
242 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
244 AC_CHECK_FUNCS(timegm strnlen setenv)
245 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
247 # this test disabled as we don't actually need __VA_ARGS__ yet
249 # #define eprintf(...) fprintf(stderr, __VA_ARGS__)
250 # eprintf("bla", "bar");
251 # ], [], [AC_MSG_ERROR([__VA_ARGS__ is required])])
253 # Check prerequisites
254 AC_CHECK_FUNCS([memset printf syslog], [],
255 [ AC_MSG_ERROR([Required function not found])])
257 AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [
259 #include <sys/types.h>
264 #include <signal.h>],[sig_atomic_t i = 0],
265 samba_cv_sig_atomic_t=yes,samba_cv_sig_atomic_t=no)])
266 if test x"$samba_cv_sig_atomic_t" = x"yes"; then
267 AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
271 AC_CACHE_CHECK([for O_DIRECT flag to open(2)],samba_cv_HAVE_OPEN_O_DIRECT,[
277 [int fd = open("/dev/null", O_DIRECT);],
278 samba_cv_HAVE_OPEN_O_DIRECT=yes,samba_cv_HAVE_OPEN_O_DIRECT=no)])
279 if test x"$samba_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
280 AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
284 AC_CACHE_CHECK([that the C compiler can precompile header files],samba_cv_precompiled_headers, [
285 dnl Check whether the compiler can generate precompiled headers
287 if ${CC-cc} conftest.h 2> /dev/null && test -f conftest.h.gch; then
288 precompiled_headers=yes
290 precompiled_headers=no
292 AC_SUBST(precompiled_headers)
295 dnl Check if the C compiler understands volatile (it should, being ANSI).
296 AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
297 AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
298 samba_cv_volatile=yes,samba_cv_volatile=no)])
299 if test x"$samba_cv_volatile" = x"yes"; then
300 AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])