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 $srcdir/../lib/replace $srcdir/../../../lib/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 libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace"
38 for d in $libreplacepaths; do
39 if test -f "$d/replace.c"; then
41 AC_SUBST(libreplacedir)
45 if test x"$libreplacedir" = "x"; then
46 AC_MSG_ERROR([cannot find libreplace in $libreplacepaths])
49 LIBREPLACEOBJ="replace.o"
50 AC_SUBST(LIBREPLACEOBJ)
52 LIBREPLACEOBJ="${LIBREPLACEOBJ} snprintf.o"
61 AC_CHECK_TYPE(ino_t,unsigned)
62 AC_CHECK_TYPE(loff_t,off_t)
63 AC_CHECK_TYPE(offset_t,loff_t)
67 AC_CHECK_FUNCS([pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp utime utimes])
69 AC_CHECK_HEADERS(stdbool.h stdint.h sys/select.h)
70 AC_CHECK_HEADERS(setjmp.h utime.h)
72 LIBREPLACE_PROVIDE_HEADER([stdint.h])
73 LIBREPLACE_PROVIDE_HEADER([stdbool.h])
76 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
85 [AC_DEFINE(HAVE__Bool, 1, [Whether the _Bool type is available])],,
93 AC_CACHE_CHECK([for working mmap],libreplace_cv_HAVE_MMAP,[
94 AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"],
95 libreplace_cv_HAVE_MMAP=yes,libreplace_cv_HAVE_MMAP=no,libreplace_cv_HAVE_MMAP=cross)])
96 if test x"$libreplace_cv_HAVE_MMAP" = x"yes"; then
97 AC_DEFINE(HAVE_MMAP,1,[Whether mmap works])
101 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
102 AC_CHECK_HEADERS(sys/time.h time.h)
103 AC_CHECK_HEADERS(stdarg.h vararg.h)
104 AC_CHECK_HEADERS(sys/mount.h mntent.h)
105 AC_CHECK_HEADERS(stropts.h)
107 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
108 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
109 AC_CHECK_FUNCS(waitpid wait4 strlcpy strlcat initgroups memmove strdup)
110 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp dup2)
111 AC_CHECK_FUNCS(isatty chown lchown link readlink symlink realpath)
112 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
113 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
114 AC_HAVE_DECL(errno, [#include <errno.h>])
116 AC_CACHE_CHECK([for secure mkstemp],libreplace_cv_HAVE_SECURE_MKSTEMP,[
117 AC_TRY_RUN([#include <stdlib.h>
118 #include <sys/types.h>
119 #include <sys/stat.h>
123 char tpl[20]="/tmp/test.XXXXXX";
124 int fd = mkstemp(tpl);
125 if (fd == -1) exit(1);
127 if (fstat(fd, &st) != 0) exit(1);
128 if ((st.st_mode & 0777) != 0600) exit(1);
131 libreplace_cv_HAVE_SECURE_MKSTEMP=yes,
132 libreplace_cv_HAVE_SECURE_MKSTEMP=no,
133 libreplace_cv_HAVE_SECURE_MKSTEMP=cross)])
134 if test x"$libreplace_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
135 AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
138 dnl Provided by snprintf.c:
139 AC_CHECK_HEADERS(stdio.h strings.h)
140 AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
141 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
143 AC_CACHE_CHECK([for C99 vsnprintf],libreplace_cv_HAVE_C99_VSNPRINTF,[
145 #include <sys/types.h>
149 void foo(const char *format, ...) {
153 long long l = 1234567890;
156 va_start(ap, format);
157 len = vsnprintf(buf, 0, format, ap);
159 if (len != 5) exit(1);
161 va_start(ap, format);
162 len = vsnprintf(0, 0, format, ap);
164 if (len != 5) exit(2);
166 if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
168 if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
169 if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
170 if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
171 if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
175 main() { foo("hello"); }
177 libreplace_cv_HAVE_C99_VSNPRINTF=yes,libreplace_cv_HAVE_C99_VSNPRINTF=no,libreplace_cv_HAVE_C99_VSNPRINTF=cross)])
178 if test x"$libreplace_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
179 AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
184 AC_CACHE_CHECK([for va_copy],libreplace_cv_HAVE_VA_COPY,[
185 AC_TRY_LINK([#include <stdarg.h>
186 va_list ap1,ap2;], [va_copy(ap1,ap2);],
187 libreplace_cv_HAVE_VA_COPY=yes,libreplace_cv_HAVE_VA_COPY=no)])
188 if test x"$libreplace_cv_HAVE_VA_COPY" = x"yes"; then
189 AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
192 if test x"$libreplace_cv_HAVE_VA_COPY" != x"yes"; then
193 AC_CACHE_CHECK([for __va_copy],libreplace_cv_HAVE___VA_COPY,[
194 AC_TRY_LINK([#include <stdarg.h>
195 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
196 libreplace_cv_HAVE___VA_COPY=yes,libreplace_cv_HAVE___VA_COPY=no)])
197 if test x"$libreplace_cv_HAVE___VA_COPY" = x"yes"; then
198 AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
202 dnl __FUNCTION__ macro
203 AC_CACHE_CHECK([for __FUNCTION__ macro],libreplace_cv_HAVE_FUNCTION_MACRO,[
204 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
205 libreplace_cv_HAVE_FUNCTION_MACRO=yes,libreplace_cv_HAVE_FUNCTION_MACRO=no)])
206 if test x"$libreplace_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
207 AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
210 AC_CACHE_CHECK([for __func__ macro],libreplace_cv_HAVE_func_MACRO,[
211 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
212 libreplace_cv_HAVE_func_MACRO=yes,libreplace_cv_HAVE_func_MACRO=no)])
213 if test x"$libreplace_cv_HAVE_func_MACRO" = x"yes"; then
214 AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
218 AC_CHECK_HEADERS([sys/param.h limits.h])
220 AC_CHECK_TYPE(comparison_fn_t,
221 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
223 AC_HAVE_DECL(setenv, [#include <stdlib.h>])
224 AC_CHECK_FUNCS(setenv unsetenv)
225 AC_HAVE_DECL(environ, [#include <unistd.h>])
227 AC_CHECK_FUNCS(strnlen)
228 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
230 # this test disabled as we don't actually need __VA_ARGS__ yet
232 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
233 eprintf("bla", "bar");
234 ], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available]))
237 AC_CACHE_CHECK([for sig_atomic_t type],libreplace_cv_sig_atomic_t, [
239 #include <sys/types.h>
244 #include <signal.h>],[sig_atomic_t i = 0],
245 libreplace_cv_sig_atomic_t=yes,libreplace_cv_sig_atomic_t=no)])
246 if test x"$libreplace_cv_sig_atomic_t" = x"yes"; then
247 AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
251 AC_CACHE_CHECK([for O_DIRECT flag to open(2)],libreplace_cv_HAVE_OPEN_O_DIRECT,[
257 [int fd = open("/dev/null", O_DIRECT);],
258 libreplace_cv_HAVE_OPEN_O_DIRECT=yes,libreplace_cv_HAVE_OPEN_O_DIRECT=no)])
259 if test x"$libreplace_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
260 AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
264 dnl Check if the C compiler understands volatile (it should, being ANSI).
265 AC_CACHE_CHECK([that the C compiler understands volatile],libreplace_cv_volatile, [
266 AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
267 libreplace_cv_volatile=yes,libreplace_cv_volatile=no)])
268 if test x"$libreplace_cv_volatile" = x"yes"; then
269 AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
272 m4_include(system/config.m4)
275 m4_include(getpass.m4)
276 m4_include(strptime.m4)
278 m4_include(timegm.m4)
279 m4_include(repdir.m4)
282 AC_CHECK_FUNCS([printf memset memcpy],,[AC_MSG_ERROR([Required function not found])])
284 echo "LIBREPLACE_BROKEN_CHECKS: END"
285 ]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
287 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START,
289 #LIBREPLACE_ALL_CHECKS: START"
291 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END,
293 #LIBREPLACE_ALL_CHECKS: END"
295 m4_define(AC_LIBREPLACE_ALL_CHECKS,
297 AC__LIBREPLACE_ALL_CHECKS_START
298 AC_LIBREPLACE_LOCATION_CHECKS
299 AC_LIBREPLACE_CC_CHECKS
300 AC_LIBREPLACE_BROKEN_CHECKS
301 AC__LIBREPLACE_ALL_CHECKS_END
302 CFLAGS="$CFLAGS -I$libreplacedir"
305 m4_include(libreplace_cc.m4)
306 m4_include(libreplace_ld.m4)
307 m4_include(libreplace_network.m4)
308 m4_include(libreplace_macros.m4)
310 m4_ifndef([AC_USE_SYSTEM_EXTENSIONS],[m4_include(autoconf-2.60.m4)])