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="replace.o"
12 AC_SUBST(LIBREPLACEOBJ)
14 LIBREPLACEOBJ="${LIBREPLACEOBJ} snprintf.o"
16 dnl stop the C89 attempt by autoconf - if autoconf detects -Ae it will enable it
17 dnl which conflicts with C99 on HPUX
24 AC_USE_SYSTEM_EXTENSIONS
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
35 AH_VERBATIM([_OSF_SOURCE],
36 [/* Enable OSF extensions on systems that have them. */
38 # define _OSF_SOURCE 1
41 LIBREPLACE_C99_STRUCT_INIT([],[])
45 dnl Add #include for broken IRIX header files
47 *irix6*) AC_ADD_INCLUDE(<standards.h>)
51 AC_CHECK_HEADERS([standards.h])
57 AC_CHECK_SIZEOF(off_t,cross)
58 AC_CHECK_SIZEOF(size_t,cross)
59 AC_CHECK_SIZEOF(ssize_t,cross)
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)
73 dnl these are needed for heimdal roken.h
74 AC_CHECK_TYPE(struct sockaddr, [], [], [
76 #include <sys/socket.h>])
77 AC_CHECK_TYPE(struct sockaddr_storage, [], [], [
79 #include <sys/socket.h>])
80 AC_CHECK_TYPE(struct addrinfo, [], [], [
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)
98 AC_CHECK_FUNCS(pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp)
100 AC_CHECK_HEADERS(stdbool.h stddef.h sys/select.h)
102 AC_CHECK_HEADERS(sys/epoll.h)
103 AC_CHECK_FUNCS(epoll_create)
106 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
109 #ifdef HAVE_STDBOOL_H
115 [AC_DEFINE(HAVE__Bool, 1, [Whether the _Bool type is available])],,
118 #ifdef HAVE_STDBOOL_H
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])
131 AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[
135 #include <sys/types.h>
136 #include <netinet/in.h>
137 #ifdef HAVE_ARPA_INET_H
138 #include <arpa/inet.h>
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); }
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])
149 dnl Provided by replace.c:
151 #include <sys/types.h>
156 #include <sys/socket.h>],
158 [AC_DEFINE(socklen_t, int,[Socket length type])])
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>])
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>
179 char tpl[20]="/tmp/test.XXXXXX";
180 int fd = mkstemp(tpl);
181 if (fd == -1) exit(1);
183 if (fstat(fd, &st) != 0) exit(1);
184 if ((st.st_mode & 0777) != 0600) exit(1);
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])
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)
199 AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[
201 #include <sys/types.h>
205 void foo(const char *format, ...) {
209 long long l = 1234567890;
212 va_start(ap, format);
213 len = vsnprintf(buf, 0, format, ap);
215 if (len != 5) exit(1);
217 va_start(ap, format);
218 len = vsnprintf(0, 0, format, ap);
220 if (len != 5) exit(2);
222 if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
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);
231 main() { foo("hello"); }
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])
239 LIBREPLACE_C99_STRUCT_INIT(c99_struct_initialization=yes,
240 c99_struct_initialization=no)
243 AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
244 AC_TRY_LINK([#include <stdarg.h>
245 va_list ap1,ap2;], [va_copy(ap1,ap2);],
246 samba_cv_HAVE_VA_COPY=yes,samba_cv_HAVE_VA_COPY=no)])
247 if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then
248 AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
251 if test x"$samba_cv_HAVE_VA_COPY" != x"yes"; then
252 AC_CACHE_CHECK([for __va_copy],samba_cv_HAVE___VA_COPY,[
253 AC_TRY_LINK([#include <stdarg.h>
254 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
255 samba_cv_HAVE___VA_COPY=yes,samba_cv_HAVE___VA_COPY=no)])
256 if test x"$samba_cv_HAVE___VA_COPY" = x"yes"; then
257 AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
261 dnl __FUNCTION__ macro
262 AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[
263 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
264 samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)])
265 if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
266 AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
269 AC_CACHE_CHECK([for __func__ macro],samba_cv_HAVE_func_MACRO,[
270 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
271 samba_cv_HAVE_func_MACRO=yes,samba_cv_HAVE_func_MACRO=no)])
272 if test x"$samba_cv_HAVE_func_MACRO" = x"yes"; then
273 AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
277 AC_CHECK_HEADERS([sys/param.h limits.h])
279 AC_CHECK_TYPE(comparison_fn_t,
280 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
282 AC_CHECK_FUNCS(strnlen setenv)
283 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
285 # this test disabled as we don't actually need __VA_ARGS__ yet
287 # #define eprintf(...) fprintf(stderr, __VA_ARGS__)
288 # eprintf("bla", "bar");
289 # ], [], [AC_MSG_ERROR([__VA_ARGS__ is required])])
291 # Check prerequisites
292 AC_CHECK_FUNCS([memset printf syslog], [],
293 [ AC_MSG_ERROR([Required function not found])])
295 AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [
297 #include <sys/types.h>
302 #include <signal.h>],[sig_atomic_t i = 0],
303 samba_cv_sig_atomic_t=yes,samba_cv_sig_atomic_t=no)])
304 if test x"$samba_cv_sig_atomic_t" = x"yes"; then
305 AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
309 AC_CACHE_CHECK([for O_DIRECT flag to open(2)],samba_cv_HAVE_OPEN_O_DIRECT,[
315 [int fd = open("/dev/null", O_DIRECT);],
316 samba_cv_HAVE_OPEN_O_DIRECT=yes,samba_cv_HAVE_OPEN_O_DIRECT=no)])
317 if test x"$samba_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
318 AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
322 AC_CACHE_CHECK([that the C compiler can precompile header files],samba_cv_precompiled_headers, [
323 dnl Check whether the compiler can generate precompiled headers
325 if ${CC-cc} conftest.h 2> /dev/null && test -f conftest.h.gch; then
326 precompiled_headers=yes
328 precompiled_headers=no
330 AC_SUBST(precompiled_headers)
333 dnl Check if the C compiler understands volatile (it should, being ANSI).
334 AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
335 AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
336 samba_cv_volatile=yes,samba_cv_volatile=no)])
337 if test x"$samba_cv_volatile" = x"yes"; then
338 AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
341 m4_include(system/config.m4)
344 m4_include(getpass.m4)
346 m4_include(timegm.m4)
347 m4_include(repdir.m4)
349 AC_CHECK_FUNCS([syslog memset setnetgrent getnetgrent endnetgrent memcpy],,
350 [AC_MSG_ERROR([Required function not found])])