source: trunk/server/lib/replace/libreplace.m4@ 1000

Last change on this file since 1000 was 862, checked in by Silvan Scherrer, 11 years ago

Samba Server: update trunk to 3.6.23

File size: 12.0 KB
Line 
1AC_DEFUN_ONCE(AC_LIBREPLACE_LOCATION_CHECKS,
2[
3echo "LIBREPLACE_LOCATION_CHECKS: START"
4
5dnl find the libreplace sources. This is meant to work both for
6dnl libreplace standalone builds, and builds of packages using libreplace
7libreplacedir=""
8libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace"
9for d in $libreplacepaths; do
10 if test -f "$d/replace.c"; then
11 libreplacedir="$d"
12 AC_SUBST(libreplacedir)
13 break;
14 fi
15done
16if test x"$libreplacedir" = "x"; then
17 AC_MSG_ERROR([cannot find libreplace in $libreplacepaths])
18fi
19LIBREPLACEOBJ="$libreplacedir/replace.o"
20AC_SUBST(LIBREPLACEOBJ)
21
22AC_CANONICAL_BUILD
23AC_CANONICAL_HOST
24AC_CANONICAL_TARGET
25
26echo "LIBREPLACE_LOCATION_CHECKS: END"
27]) dnl end AC_LIBREPLACE_LOCATION_CHECKS
28
29
30AC_DEFUN_ONCE(AC_LIBREPLACE_BROKEN_CHECKS,
31[
32echo "LIBREPLACE_BROKEN_CHECKS: START"
33
34dnl find the libreplace sources. This is meant to work both for
35dnl libreplace standalone builds, and builds of packages using libreplace
36libreplacedir=""
37libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace"
38for d in $libreplacepaths; do
39 if test -f "$d/replace.c"; then
40 libreplacedir="$d"
41 AC_SUBST(libreplacedir)
42 break;
43 fi
44done
45if test x"$libreplacedir" = "x"; then
46 AC_MSG_ERROR([cannot find libreplace in $libreplacepaths])
47fi
48
49LIBREPLACEOBJ="$libreplacedir/replace.o"
50AC_SUBST(LIBREPLACEOBJ)
51
52LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/snprintf.o"
53
54AC_TYPE_UID_T
55AC_TYPE_MODE_T
56AC_TYPE_OFF_T
57AC_TYPE_SIZE_T
58AC_TYPE_PID_T
59AC_STRUCT_ST_RDEV
60AC_CHECK_TYPE(ino_t,unsigned)
61AC_CHECK_TYPE(loff_t,off_t)
62AC_CHECK_TYPE(offset_t,loff_t)
63
64AC_FUNC_MEMCMP
65
66AC_CHECK_FUNCS([pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp utime utimes])
67
68AC_CHECK_HEADERS(stdbool.h stdint.h sys/select.h)
69AC_CHECK_HEADERS(setjmp.h utime.h sys/wait.h)
70
71LIBREPLACE_PROVIDE_HEADER([stdint.h])
72LIBREPLACE_PROVIDE_HEADER([stdbool.h])
73
74AC_CHECK_TYPE(bool,
75[AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
76[
77AC_INCLUDES_DEFAULT
78#ifdef HAVE_STDBOOL_H
79#include <stdbool.h>
80#endif]
81)
82
83AC_CHECK_TYPE(_Bool,
84[AC_DEFINE(HAVE__Bool, 1, [Whether the _Bool type is available])],,
85[
86AC_INCLUDES_DEFAULT
87#ifdef HAVE_STDBOOL_H
88#include <stdbool.h>
89#endif]
90)
91
92AC_CHECK_HEADERS(linux/types.h)
93
94AC_CACHE_CHECK([for working mmap],libreplace_cv_HAVE_MMAP,[
95AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"],
96 libreplace_cv_HAVE_MMAP=yes,libreplace_cv_HAVE_MMAP=no,libreplace_cv_HAVE_MMAP=cross)])
97if test x"$libreplace_cv_HAVE_MMAP" = x"yes"; then
98 AC_DEFINE(HAVE_MMAP,1,[Whether mmap works])
99fi
100
101
102AC_CHECK_HEADERS(sys/syslog.h syslog.h)
103AC_CHECK_HEADERS(sys/time.h time.h)
104AC_CHECK_HEADERS(stdarg.h vararg.h)
105AC_CHECK_HEADERS(sys/mount.h mntent.h)
106AC_CHECK_HEADERS(stropts.h)
107AC_CHECK_HEADERS(unix.h)
108AC_CHECK_HEADERS(sys/ucontext.h)
109
110AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror strerror_r)
111AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
112AC_CHECK_FUNCS(waitpid wait4 strlcpy strlcat initgroups memmove strdup)
113AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp dup2 dprintf vdprintf)
114AC_CHECK_FUNCS(isatty chown lchown link readlink symlink realpath)
115AC_CHECK_FUNCS(fdatasync,,[
116 # if we didn't find it, look in librt (Solaris hides it there...)
117 AC_CHECK_LIB(rt, fdatasync,
118 [libreplace_cv_HAVE_FDATASYNC_IN_LIBRT=yes
119 AC_DEFINE(HAVE_FDATASYNC, 1, Define to 1 if there is support for fdatasync)])
120])
121AC_HAVE_DECL(fdatasync, [#include <unistd.h>])
122AC_CHECK_FUNCS(clock_gettime,libreplace_cv_have_clock_gettime=yes,[
123 AC_CHECK_LIB(rt, clock_gettime,
124 [libreplace_cv_HAVE_CLOCK_GETTIME_IN_LIBRT=yes
125 libreplace_cv_have_clock_gettime=yes
126 AC_DEFINE(HAVE_CLOCK_GETTIME, 1, Define to 1 if there is support for clock_gettime)])
127])
128AC_CHECK_FUNCS(get_current_dir_name)
129AC_HAVE_DECL(setresuid, [#include <unistd.h>])
130AC_HAVE_DECL(setresgid, [#include <unistd.h>])
131AC_HAVE_DECL(errno, [#include <errno.h>])
132
133AC_CACHE_CHECK([for secure mkstemp],libreplace_cv_HAVE_SECURE_MKSTEMP,[
134AC_TRY_RUN([#include <stdlib.h>
135#include <sys/types.h>
136#include <sys/stat.h>
137#include <unistd.h>
138main() {
139 struct stat st;
140 char tpl[20]="/tmp/test.XXXXXX";
141 int fd = mkstemp(tpl);
142 if (fd == -1) exit(1);
143 unlink(tpl);
144 if (fstat(fd, &st) != 0) exit(1);
145 if ((st.st_mode & 0777) != 0600) exit(1);
146 exit(0);
147}],
148libreplace_cv_HAVE_SECURE_MKSTEMP=yes,
149libreplace_cv_HAVE_SECURE_MKSTEMP=no,
150libreplace_cv_HAVE_SECURE_MKSTEMP=cross)])
151if test x"$libreplace_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
152 AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
153fi
154
155dnl Provided by snprintf.c:
156AC_CHECK_HEADERS(stdio.h strings.h)
157AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
158AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
159
160AC_CACHE_CHECK([for C99 vsnprintf],libreplace_cv_HAVE_C99_VSNPRINTF,[
161AC_TRY_RUN([
162#include <sys/types.h>
163#include <stdio.h>
164#include <stdarg.h>
165#include <stdlib.h>
166void foo(const char *format, ...) {
167 va_list ap;
168 int len;
169 char buf[20];
170 long long l = 1234567890;
171 l *= 100;
172
173 va_start(ap, format);
174 len = vsnprintf(buf, 0, format, ap);
175 va_end(ap);
176 if (len != 5) exit(1);
177
178 va_start(ap, format);
179 len = vsnprintf(0, 0, format, ap);
180 va_end(ap);
181 if (len != 5) exit(2);
182
183 if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
184
185 if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
186 if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
187 if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
188 if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
189
190 exit(0);
191}
192main() { foo("hello"); }
193],
194libreplace_cv_HAVE_C99_VSNPRINTF=yes,libreplace_cv_HAVE_C99_VSNPRINTF=no,libreplace_cv_HAVE_C99_VSNPRINTF=cross)])
195if test x"$libreplace_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
196 AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
197fi
198
199
200dnl VA_COPY
201AC_CACHE_CHECK([for va_copy],libreplace_cv_HAVE_VA_COPY,[
202AC_TRY_LINK([#include <stdarg.h>
203va_list ap1,ap2;], [va_copy(ap1,ap2);],
204libreplace_cv_HAVE_VA_COPY=yes,libreplace_cv_HAVE_VA_COPY=no)])
205if test x"$libreplace_cv_HAVE_VA_COPY" = x"yes"; then
206 AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
207fi
208
209if test x"$libreplace_cv_HAVE_VA_COPY" != x"yes"; then
210AC_CACHE_CHECK([for __va_copy],libreplace_cv_HAVE___VA_COPY,[
211AC_TRY_LINK([#include <stdarg.h>
212va_list ap1,ap2;], [__va_copy(ap1,ap2);],
213libreplace_cv_HAVE___VA_COPY=yes,libreplace_cv_HAVE___VA_COPY=no)])
214if test x"$libreplace_cv_HAVE___VA_COPY" = x"yes"; then
215 AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
216fi
217fi
218
219dnl __FUNCTION__ macro
220AC_CACHE_CHECK([for __FUNCTION__ macro],libreplace_cv_HAVE_FUNCTION_MACRO,[
221AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
222libreplace_cv_HAVE_FUNCTION_MACRO=yes,libreplace_cv_HAVE_FUNCTION_MACRO=no)])
223if test x"$libreplace_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
224 AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
225else
226 dnl __func__ macro
227 AC_CACHE_CHECK([for __func__ macro],libreplace_cv_HAVE_func_MACRO,[
228 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
229 libreplace_cv_HAVE_func_MACRO=yes,libreplace_cv_HAVE_func_MACRO=no)])
230 if test x"$libreplace_cv_HAVE_func_MACRO" = x"yes"; then
231 AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
232 fi
233fi
234
235AC_CHECK_HEADERS([sys/param.h limits.h])
236
237AC_CHECK_TYPE(comparison_fn_t,
238[AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
239
240AC_HAVE_DECL(setenv, [#include <stdlib.h>])
241AC_CHECK_FUNCS(setenv unsetenv)
242AC_HAVE_DECL(environ, [#include <unistd.h>])
243
244AC_CHECK_FUNCS(strnlen)
245AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
246
247AC_CHECK_FUNCS(memmem)
248
249# this test disabled as we don't actually need __VA_ARGS__ yet
250AC_TRY_CPP([
251#define eprintf(...) fprintf(stderr, __VA_ARGS__)
252eprintf("bla", "bar");
253], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available]))
254
255
256AC_CACHE_CHECK([for sig_atomic_t type],libreplace_cv_sig_atomic_t, [
257 AC_TRY_COMPILE([
258#include <sys/types.h>
259#if STDC_HEADERS
260#include <stdlib.h>
261#include <stddef.h>
262#endif
263#include <signal.h>],[sig_atomic_t i = 0],
264 libreplace_cv_sig_atomic_t=yes,libreplace_cv_sig_atomic_t=no)])
265if test x"$libreplace_cv_sig_atomic_t" = x"yes"; then
266 AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
267fi
268
269
270dnl Check if the C compiler understands volatile (it should, being ANSI).
271AC_CACHE_CHECK([that the C compiler understands volatile],libreplace_cv_volatile, [
272 AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
273 libreplace_cv_volatile=yes,libreplace_cv_volatile=no)])
274if test x"$libreplace_cv_volatile" = x"yes"; then
275 AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
276fi
277
278m4_include(system/config.m4)
279
280AC_CACHE_CHECK([for O_DIRECT flag to open(2)],libreplace_cv_HAVE_OPEN_O_DIRECT,[
281AC_TRY_COMPILE([
282#include <unistd.h>
283#ifdef HAVE_FCNTL_H
284#include <fcntl.h>
285#endif],
286[int fd = open("/dev/null", O_DIRECT);],
287libreplace_cv_HAVE_OPEN_O_DIRECT=yes,libreplace_cv_HAVE_OPEN_O_DIRECT=no)])
288if test x"$libreplace_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
289 AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
290fi
291
292m4_include(dlfcn.m4)
293m4_include(getpass.m4)
294m4_include(strptime.m4)
295m4_include(win32.m4)
296m4_include(timegm.m4)
297m4_include(repdir.m4)
298m4_include(crypt.m4)
299
300if test x$libreplace_cv_have_clock_gettime = xyes ; then
301 SMB_CHECK_CLOCK_ID(CLOCK_MONOTONIC)
302 SMB_CHECK_CLOCK_ID(CLOCK_PROCESS_CPUTIME_ID)
303 SMB_CHECK_CLOCK_ID(CLOCK_REALTIME)
304fi
305
306AC_CACHE_CHECK([for struct timespec type],libreplace_cv_struct_timespec, [
307 AC_TRY_COMPILE([
308#include <sys/types.h>
309#if STDC_HEADERS
310#include <stdlib.h>
311#include <stddef.h>
312#endif
313#if TIME_WITH_SYS_TIME
314# include <sys/time.h>
315# include <time.h>
316#else
317# if HAVE_SYS_TIME_H
318# include <sys/time.h>
319# else
320# include <time.h>
321# endif
322#endif
323],[struct timespec ts;],
324 libreplace_cv_struct_timespec=yes,libreplace_cv_struct_timespec=no)])
325if test x"$libreplace_cv_struct_timespec" = x"yes"; then
326 AC_DEFINE(HAVE_STRUCT_TIMESPEC,1,[Whether we have struct timespec])
327fi
328
329AC_CACHE_CHECK([for ucontext_t type],libreplace_cv_ucontext_t, [
330 AC_TRY_COMPILE([
331#include <signal.h>
332#if HAVE_SYS_UCONTEXT_H
333#include <sys/ucontext.h>
334# endif
335],[ucontext_t uc; sigaddset(&uc.uc_sigmask, SIGUSR1);],
336 libreplace_cv_ucontext_t=yes,libreplace_cv_ucontext_t=no)])
337if test x"$libreplace_cv_ucontext_t" = x"yes"; then
338 AC_DEFINE(HAVE_UCONTEXT_T,1,[Whether we have ucontext_t])
339fi
340
341AC_CHECK_FUNCS([printf memset memcpy],,[AC_MSG_ERROR([Required function not found])])
342
343echo "LIBREPLACE_BROKEN_CHECKS: END"
344]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
345
346AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START,
347[
348#LIBREPLACE_ALL_CHECKS: START"
349])
350AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END,
351[
352#LIBREPLACE_ALL_CHECKS: END"
353])
354m4_define(AC_LIBREPLACE_ALL_CHECKS,
355[
356AC__LIBREPLACE_ALL_CHECKS_START
357AC_LIBREPLACE_LOCATION_CHECKS
358AC_LIBREPLACE_CC_CHECKS
359AC_LIBREPLACE_BROKEN_CHECKS
360AC__LIBREPLACE_ALL_CHECKS_END
361CFLAGS="$CFLAGS -I$libreplacedir"
362])
363
364m4_include(libreplace_cc.m4)
365m4_include(libreplace_ld.m4)
366m4_include(libreplace_network.m4)
367m4_include(libreplace_macros.m4)
368
369
370dnl SMB_CHECK_CLOCK_ID(clockid)
371dnl Test whether the specified clock_gettime clock ID is available. If it
372dnl is, we define HAVE_clockid
373AC_DEFUN([SMB_CHECK_CLOCK_ID],
374[
375 AC_MSG_CHECKING(for $1)
376 AC_TRY_LINK([
377#if TIME_WITH_SYS_TIME
378# include <sys/time.h>
379# include <time.h>
380#else
381# if HAVE_SYS_TIME_H
382# include <sys/time.h>
383# else
384# include <time.h>
385# endif
386#endif
387 ],
388 [
389clockid_t clk = $1;
390 ],
391 [
392 AC_MSG_RESULT(yes)
393 AC_DEFINE(HAVE_$1, 1,
394 [Whether the clock_gettime clock ID $1 is available])
395 ],
396 [
397 AC_MSG_RESULT(no)
398 ])
399])
400m4_ifndef([AC_USE_SYSTEM_EXTENSIONS],[m4_include(autoconf-2.60.m4)])
Note: See TracBrowser for help on using the repository browser.