1 AC_DEFUN_ONCE(AC_LIBREPLACE_LOCATION_CHECKS,
3 echo "LIBREPLACE_LOCATION_CHECKS: START"
5 dnl find the libreplace sources. This is meant to work both for
6 dnl libreplace standalone builds, and builds of packages using libreplace
8 libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace"
9 for d in $libreplacepaths; do
10 if test -f "$d/replace.c"; then
12 AC_SUBST(libreplacedir)
16 if test x"$libreplacedir" = "x"; then
17 AC_MSG_ERROR([cannot find libreplace in $libreplacepaths])
19 LIBREPLACEOBJ="replace.o"
20 AC_SUBST(LIBREPLACEOBJ)
26 echo "LIBREPLACE_LOCATION_CHECKS: END"
27 ]) dnl end AC_LIBREPLACE_LOCATION_CHECKS
30 AC_DEFUN_ONCE(AC_LIBREPLACE_BROKEN_CHECKS,
32 echo "LIBREPLACE_BROKEN_CHECKS: START"
34 dnl find the libreplace sources. This is meant to work both for
35 dnl libreplace standalone builds, and builds of packages using libreplace
37 for d in "$srcdir" "$srcdir/lib/replace" "$srcdir/libreplace" "$srcdir/../libreplace" "$srcdir/../replace"; do
38 if test -f "$d/replace.c"; then
40 AC_SUBST(libreplacedir)
44 LIBREPLACEOBJ="replace.o"
45 AC_SUBST(LIBREPLACEOBJ)
47 LIBREPLACEOBJ="${LIBREPLACEOBJ} snprintf.o"
56 AC_CHECK_TYPE(ino_t,unsigned)
57 AC_CHECK_TYPE(loff_t,off_t)
58 AC_CHECK_TYPE(offset_t,loff_t)
62 AC_CHECK_FUNCS(pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp)
64 AC_CHECK_HEADERS(stdbool.h stdint.h sys/select.h)
65 AC_CHECK_HEADERS(setjmp.h)
67 LIBREPLACE_PROVIDE_HEADER([stdint.h])
68 LIBREPLACE_PROVIDE_HEADER([stdbool.h])
71 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
80 [AC_DEFINE(HAVE__Bool, 1, [Whether the _Bool type is available])],,
88 AC_CACHE_CHECK([for working mmap],libreplace_cv_HAVE_MMAP,[
89 AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"],
90 libreplace_cv_HAVE_MMAP=yes,libreplace_cv_HAVE_MMAP=no,libreplace_cv_HAVE_MMAP=cross)])
91 if test x"$libreplace_cv_HAVE_MMAP" = x"yes"; then
92 AC_DEFINE(HAVE_MMAP,1,[Whether mmap works])
96 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
97 AC_CHECK_HEADERS(sys/time.h time.h)
98 AC_CHECK_HEADERS(stdarg.h vararg.h)
99 AC_CHECK_HEADERS(sys/socket.h netinet/in.h netdb.h arpa/inet.h)
100 AC_CHECK_HEADERS(netinet/ip.h netinet/tcp.h netinet/in_systm.h netinet/in_ip.h)
101 AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
102 AC_CHECK_HEADERS(sys/mount.h mntent.h)
103 AC_CHECK_HEADERS(stropts.h)
105 dnl we need to check that net/if.h really can be used, to cope with hpux
106 dnl where including it always fails
107 AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
108 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
110 #if HAVE_SYS_SOCKET_H
111 # include <sys/socket.h>
114 int main(void) {return 0;}])],
115 [libreplace_cv_USABLE_NET_IF_H=yes],
116 [libreplace_cv_USABLE_NET_IF_H=no]
119 if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
120 AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
123 AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
127 #include <sys/types.h>
128 #include <netinet/in.h>
129 #ifdef HAVE_ARPA_INET_H
130 #include <arpa/inet.h>
132 main() { struct in_addr ip; ip.s_addr = 0x12345678;
133 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
134 strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
136 libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
137 if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
138 AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
141 AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])
142 AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])
143 AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
144 AC_HAVE_TYPE([struct sockaddr], [#include <sys/socket.h>])
145 AC_HAVE_TYPE([struct sockaddr_storage], [
146 #include <sys/socket.h>
147 #include <sys/types.h>
148 #include <netinet/in.h>
150 AC_HAVE_TYPE([struct sockaddr_in6], [
151 #include <sys/socket.h>
152 #include <sys/types.h>
153 #include <netinet/in.h>
156 if test x"$ac_cv_type_struct_sockaddr_storage" = x"yes"; then
157 AC_CHECK_MEMBER(struct sockaddr_storage.ss_family,
158 AC_DEFINE(HAVE_SS_FAMILY, 1, [Defined if struct sockaddr_storage has ss_family field]),,
160 #include <sys/socket.h>
161 #include <sys/types.h>
162 #include <netinet/in.h>
165 if test x"$ac_cv_member_struct_sockaddr_storage_ss_family" != x"yes"; then
166 AC_CHECK_MEMBER(struct sockaddr_storage.__ss_family,
167 AC_DEFINE(HAVE___SS_FAMILY, 1, [Defined if struct sockaddr_storage has __ss_family field]),,
169 #include <sys/socket.h>
170 #include <sys/types.h>
171 #include <netinet/in.h>
176 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
177 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
178 AC_CHECK_FUNCS(waitpid strlcpy strlcat initgroups memmove strdup)
179 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp socketpair)
180 AC_CHECK_FUNCS(isatty)
181 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
182 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
183 AC_HAVE_DECL(errno, [#include <errno.h>])
185 AC_CACHE_CHECK([for secure mkstemp],libreplace_cv_HAVE_SECURE_MKSTEMP,[
186 AC_TRY_RUN([#include <stdlib.h>
187 #include <sys/types.h>
188 #include <sys/stat.h>
192 char tpl[20]="/tmp/test.XXXXXX";
193 int fd = mkstemp(tpl);
194 if (fd == -1) exit(1);
196 if (fstat(fd, &st) != 0) exit(1);
197 if ((st.st_mode & 0777) != 0600) exit(1);
200 libreplace_cv_HAVE_SECURE_MKSTEMP=yes,
201 libreplace_cv_HAVE_SECURE_MKSTEMP=no,
202 libreplace_cv_HAVE_SECURE_MKSTEMP=cross)])
203 if test x"$libreplace_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
204 AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
207 dnl Provided by snprintf.c:
208 AC_CHECK_HEADERS(stdio.h strings.h)
209 AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
210 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
212 AC_CACHE_CHECK([for C99 vsnprintf],libreplace_cv_HAVE_C99_VSNPRINTF,[
214 #include <sys/types.h>
218 void foo(const char *format, ...) {
222 long long l = 1234567890;
225 va_start(ap, format);
226 len = vsnprintf(buf, 0, format, ap);
228 if (len != 5) exit(1);
230 va_start(ap, format);
231 len = vsnprintf(0, 0, format, ap);
233 if (len != 5) exit(2);
235 if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
237 if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
238 if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
239 if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
240 if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
244 main() { foo("hello"); }
246 libreplace_cv_HAVE_C99_VSNPRINTF=yes,libreplace_cv_HAVE_C99_VSNPRINTF=no,libreplace_cv_HAVE_C99_VSNPRINTF=cross)])
247 if test x"$libreplace_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
248 AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
253 AC_CACHE_CHECK([for va_copy],libreplace_cv_HAVE_VA_COPY,[
254 AC_TRY_LINK([#include <stdarg.h>
255 va_list ap1,ap2;], [va_copy(ap1,ap2);],
256 libreplace_cv_HAVE_VA_COPY=yes,libreplace_cv_HAVE_VA_COPY=no)])
257 if test x"$libreplace_cv_HAVE_VA_COPY" = x"yes"; then
258 AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
261 if test x"$libreplace_cv_HAVE_VA_COPY" != x"yes"; then
262 AC_CACHE_CHECK([for __va_copy],libreplace_cv_HAVE___VA_COPY,[
263 AC_TRY_LINK([#include <stdarg.h>
264 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
265 libreplace_cv_HAVE___VA_COPY=yes,libreplace_cv_HAVE___VA_COPY=no)])
266 if test x"$libreplace_cv_HAVE___VA_COPY" = x"yes"; then
267 AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
271 dnl __FUNCTION__ macro
272 AC_CACHE_CHECK([for __FUNCTION__ macro],libreplace_cv_HAVE_FUNCTION_MACRO,[
273 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
274 libreplace_cv_HAVE_FUNCTION_MACRO=yes,libreplace_cv_HAVE_FUNCTION_MACRO=no)])
275 if test x"$libreplace_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
276 AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
279 AC_CACHE_CHECK([for __func__ macro],libreplace_cv_HAVE_func_MACRO,[
280 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
281 libreplace_cv_HAVE_func_MACRO=yes,libreplace_cv_HAVE_func_MACRO=no)])
282 if test x"$libreplace_cv_HAVE_func_MACRO" = x"yes"; then
283 AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
287 AC_CHECK_HEADERS([sys/param.h limits.h])
289 AC_CHECK_TYPE(comparison_fn_t,
290 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
292 AC_HAVE_DECL(setenv, [#include <stdlib.h>])
293 AC_CHECK_FUNCS(setenv unsetenv)
295 AC_CHECK_FUNCS(strnlen)
296 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
298 # this test disabled as we don't actually need __VA_ARGS__ yet
300 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
301 eprintf("bla", "bar");
302 ], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available]))
305 AC_CACHE_CHECK([for sig_atomic_t type],libreplace_cv_sig_atomic_t, [
307 #include <sys/types.h>
312 #include <signal.h>],[sig_atomic_t i = 0],
313 libreplace_cv_sig_atomic_t=yes,libreplace_cv_sig_atomic_t=no)])
314 if test x"$libreplace_cv_sig_atomic_t" = x"yes"; then
315 AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
319 AC_CACHE_CHECK([for O_DIRECT flag to open(2)],libreplace_cv_HAVE_OPEN_O_DIRECT,[
325 [int fd = open("/dev/null", O_DIRECT);],
326 libreplace_cv_HAVE_OPEN_O_DIRECT=yes,libreplace_cv_HAVE_OPEN_O_DIRECT=no)])
327 if test x"$libreplace_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
328 AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
332 dnl Check if the C compiler understands volatile (it should, being ANSI).
333 AC_CACHE_CHECK([that the C compiler understands volatile],libreplace_cv_volatile, [
334 AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
335 libreplace_cv_volatile=yes,libreplace_cv_volatile=no)])
336 if test x"$libreplace_cv_volatile" = x"yes"; then
337 AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
340 m4_include(system/config.m4)
343 m4_include(getpass.m4)
344 m4_include(strptime.m4)
346 m4_include(timegm.m4)
347 m4_include(socket.m4)
348 m4_include(inet_ntop.m4)
349 m4_include(inet_pton.m4)
350 m4_include(inet_aton.m4)
351 m4_include(getaddrinfo.m4)
352 m4_include(repdir.m4)
353 m4_include(getifaddrs.m4)
355 AC_CHECK_FUNCS([syslog printf memset memcpy],,[AC_MSG_ERROR([Required function not found])])
357 echo "LIBREPLACE_BROKEN_CHECKS: END"
358 ]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
360 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START,
362 #LIBREPLACE_ALL_CHECKS: START"
364 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END,
366 #LIBREPLACE_ALL_CHECKS: END"
368 m4_define(AC_LIBREPLACE_ALL_CHECKS,
370 AC__LIBREPLACE_ALL_CHECKS_START
371 AC_LIBREPLACE_LOCATION_CHECKS
372 AC_LIBREPLACE_CC_CHECKS
373 AC_LIBREPLACE_BROKEN_CHECKS
374 AC__LIBREPLACE_ALL_CHECKS_END
375 CFLAGS="$CFLAGS -I$libreplacedir"
378 m4_include(libreplace_cc.m4)
379 m4_include(libreplace_ld.m4)
380 m4_include(libreplace_macros.m4)
381 m4_include(autoconf-2.60.m4)