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/mount.h mntent.h)
100 AC_CHECK_HEADERS(stropts.h)
102 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
103 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
104 AC_CHECK_FUNCS(waitpid strlcpy strlcat initgroups memmove strdup)
105 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp)
106 AC_CHECK_FUNCS(isatty)
107 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
108 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
109 AC_HAVE_DECL(errno, [#include <errno.h>])
111 AC_CACHE_CHECK([for secure mkstemp],libreplace_cv_HAVE_SECURE_MKSTEMP,[
112 AC_TRY_RUN([#include <stdlib.h>
113 #include <sys/types.h>
114 #include <sys/stat.h>
118 char tpl[20]="/tmp/test.XXXXXX";
119 int fd = mkstemp(tpl);
120 if (fd == -1) exit(1);
122 if (fstat(fd, &st) != 0) exit(1);
123 if ((st.st_mode & 0777) != 0600) exit(1);
126 libreplace_cv_HAVE_SECURE_MKSTEMP=yes,
127 libreplace_cv_HAVE_SECURE_MKSTEMP=no,
128 libreplace_cv_HAVE_SECURE_MKSTEMP=cross)])
129 if test x"$libreplace_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
130 AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
133 dnl Provided by snprintf.c:
134 AC_CHECK_HEADERS(stdio.h strings.h)
135 AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
136 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
138 AC_CACHE_CHECK([for C99 vsnprintf],libreplace_cv_HAVE_C99_VSNPRINTF,[
140 #include <sys/types.h>
144 void foo(const char *format, ...) {
148 long long l = 1234567890;
151 va_start(ap, format);
152 len = vsnprintf(buf, 0, format, ap);
154 if (len != 5) exit(1);
156 va_start(ap, format);
157 len = vsnprintf(0, 0, format, ap);
159 if (len != 5) exit(2);
161 if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
163 if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
164 if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
165 if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
166 if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
170 main() { foo("hello"); }
172 libreplace_cv_HAVE_C99_VSNPRINTF=yes,libreplace_cv_HAVE_C99_VSNPRINTF=no,libreplace_cv_HAVE_C99_VSNPRINTF=cross)])
173 if test x"$libreplace_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
174 AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
179 AC_CACHE_CHECK([for va_copy],libreplace_cv_HAVE_VA_COPY,[
180 AC_TRY_LINK([#include <stdarg.h>
181 va_list ap1,ap2;], [va_copy(ap1,ap2);],
182 libreplace_cv_HAVE_VA_COPY=yes,libreplace_cv_HAVE_VA_COPY=no)])
183 if test x"$libreplace_cv_HAVE_VA_COPY" = x"yes"; then
184 AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
187 if test x"$libreplace_cv_HAVE_VA_COPY" != x"yes"; then
188 AC_CACHE_CHECK([for __va_copy],libreplace_cv_HAVE___VA_COPY,[
189 AC_TRY_LINK([#include <stdarg.h>
190 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
191 libreplace_cv_HAVE___VA_COPY=yes,libreplace_cv_HAVE___VA_COPY=no)])
192 if test x"$libreplace_cv_HAVE___VA_COPY" = x"yes"; then
193 AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
197 dnl __FUNCTION__ macro
198 AC_CACHE_CHECK([for __FUNCTION__ macro],libreplace_cv_HAVE_FUNCTION_MACRO,[
199 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
200 libreplace_cv_HAVE_FUNCTION_MACRO=yes,libreplace_cv_HAVE_FUNCTION_MACRO=no)])
201 if test x"$libreplace_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
202 AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
205 AC_CACHE_CHECK([for __func__ macro],libreplace_cv_HAVE_func_MACRO,[
206 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
207 libreplace_cv_HAVE_func_MACRO=yes,libreplace_cv_HAVE_func_MACRO=no)])
208 if test x"$libreplace_cv_HAVE_func_MACRO" = x"yes"; then
209 AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
213 AC_CHECK_HEADERS([sys/param.h limits.h])
215 AC_CHECK_TYPE(comparison_fn_t,
216 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
218 AC_HAVE_DECL(setenv, [#include <stdlib.h>])
219 AC_CHECK_FUNCS(setenv unsetenv)
221 AC_CHECK_FUNCS(strnlen)
222 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
224 # this test disabled as we don't actually need __VA_ARGS__ yet
226 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
227 eprintf("bla", "bar");
228 ], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available]))
231 AC_CACHE_CHECK([for sig_atomic_t type],libreplace_cv_sig_atomic_t, [
233 #include <sys/types.h>
238 #include <signal.h>],[sig_atomic_t i = 0],
239 libreplace_cv_sig_atomic_t=yes,libreplace_cv_sig_atomic_t=no)])
240 if test x"$libreplace_cv_sig_atomic_t" = x"yes"; then
241 AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
245 AC_CACHE_CHECK([for O_DIRECT flag to open(2)],libreplace_cv_HAVE_OPEN_O_DIRECT,[
251 [int fd = open("/dev/null", O_DIRECT);],
252 libreplace_cv_HAVE_OPEN_O_DIRECT=yes,libreplace_cv_HAVE_OPEN_O_DIRECT=no)])
253 if test x"$libreplace_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
254 AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
258 dnl Check if the C compiler understands volatile (it should, being ANSI).
259 AC_CACHE_CHECK([that the C compiler understands volatile],libreplace_cv_volatile, [
260 AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
261 libreplace_cv_volatile=yes,libreplace_cv_volatile=no)])
262 if test x"$libreplace_cv_volatile" = x"yes"; then
263 AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
266 m4_include(system/config.m4)
269 m4_include(getpass.m4)
270 m4_include(strptime.m4)
272 m4_include(timegm.m4)
273 m4_include(repdir.m4)
275 AC_CHECK_FUNCS([syslog printf memset memcpy],,[AC_MSG_ERROR([Required function not found])])
277 echo "LIBREPLACE_BROKEN_CHECKS: END"
278 ]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
280 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START,
282 #LIBREPLACE_ALL_CHECKS: START"
284 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END,
286 #LIBREPLACE_ALL_CHECKS: END"
288 m4_define(AC_LIBREPLACE_ALL_CHECKS,
290 AC__LIBREPLACE_ALL_CHECKS_START
291 AC_LIBREPLACE_LOCATION_CHECKS
292 AC_LIBREPLACE_CC_CHECKS
293 AC_LIBREPLACE_BROKEN_CHECKS
294 AC__LIBREPLACE_ALL_CHECKS_END
295 CFLAGS="$CFLAGS -I$libreplacedir"
298 m4_include(libreplace_cc.m4)
299 m4_include(libreplace_ld.m4)
300 m4_include(libreplace_network.m4)
301 m4_include(libreplace_macros.m4)
302 m4_include(autoconf-2.60.m4)