r18283: libreplace.m4 needs to be early in configure.ac in other packages too
[ab/samba.git/.git] / source4 / lib / replace / libreplace.m4
1 dnl find the libreplace sources. This is meant to work both for 
2 dnl libreplace standalone builds, and builds of packages using libreplace
3 libreplacedir=""
4 for d in "$srcdir" "$srcdir/lib/replace" "$srcdir/libreplace" "$srcdir/../libreplace" "$srcdir/../replace"; do
5         if test -f "$d/replace.c"; then
6                 libreplacedir="$d"              
7                 AC_SUBST(libreplacedir)
8                 break;
9         fi
10 done
11 LIBREPLACEOBJ="dlfcn.o getpass.o replace.o snprintf.o timegm.o"
12 AC_SUBST(LIBREPLACEOBJ)
13
14 dnl needed before AC_TRY_COMPILE
15 AC_ISC_POSIX
16 AC_USE_SYSTEM_EXTENSIONS
17 AC_C_INLINE
18 AC_PROG_CC
19 AC_PROG_INSTALL
20
21 LIBREPLACE_C99_STRUCT_INIT([],[])
22
23 AC_SYS_LARGEFILE
24
25 dnl Add #include for broken IRIX header files
26 case "$host_os" in
27         *irix6*) AC_ADD_INCLUDE(<standards.h>)
28                 ;;
29 esac
30
31 AC_C_BIGENDIAN
32 AC_HEADER_STDC
33
34
35 AC_CHECK_SIZEOF(off_t,cross)
36 AC_CHECK_SIZEOF(size_t,cross)
37 AC_CHECK_SIZEOF(ssize_t,cross)
38 AC_FUNC_MMAP
39
40 AC_CHECK_HEADERS([stdint.h inttypes.h])
41 AC_CHECK_TYPE(uint_t, unsigned int)
42 AC_CHECK_TYPE(uint8_t, unsigned char)
43 AC_CHECK_TYPE(int8_t, char)
44 AC_CHECK_TYPE(int16_t, short)
45 AC_CHECK_TYPE(uint16_t, unsigned short)
46 AC_CHECK_TYPE(int32_t, long)
47 AC_CHECK_TYPE(intptr_t, unsigned long long)
48 AC_CHECK_TYPE(uint32_t, unsigned long)
49 AC_CHECK_TYPE(ssize_t, int)
50
51 AC_TYPE_SIGNAL
52 AC_TYPE_UID_T
53 AC_TYPE_MODE_T
54 AC_TYPE_OFF_T
55 AC_TYPE_SIZE_T
56 AC_TYPE_PID_T
57 AC_STRUCT_ST_RDEV
58 AC_CHECK_TYPE(ino_t,unsigned)
59 AC_CHECK_TYPE(loff_t,off_t)
60 AC_CHECK_TYPE(offset_t,loff_t)
61 AC_CHECK_TYPES(long long)
62
63 AC_FUNC_MEMCMP
64
65 AC_CHECK_FUNCS(pipe strftime srandom random srand rand usleep setbuffer)
66
67 AC_CHECK_HEADERS(stdbool.h stddef.h)
68
69 AC_CHECK_TYPE(bool, 
70 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
71 [
72 AC_INCLUDES_DEFAULT
73 #ifdef HAVE_STDBOOL_H
74 #include <stdbool.h>
75 #endif]
76 )
77
78
79 AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[
80 AC_TRY_RUN([
81 #include <stdio.h>
82 #include <sys/types.h>
83 #include <netinet/in.h>
84 #ifdef HAVE_ARPA_INET_H
85 #include <arpa/inet.h>
86 #endif
87 main() { struct in_addr ip; ip.s_addr = 0x12345678;
88 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
89     strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); } 
90 exit(1);}],
91            samba_cv_REPLACE_INET_NTOA=yes,samba_cv_REPLACE_INET_NTOA=no,samba_cv_REPLACE_INET_NTOA=cross)])
92 if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then
93     AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
94 fi
95
96 dnl Provided by replace.c:
97 AC_TRY_COMPILE([
98 #include <sys/types.h>
99 #if STDC_HEADERS
100 #include <stdlib.h>
101 #include <stddef.h>
102 #endif
103 #include <sys/socket.h>], 
104 [socklen_t foo;],,
105 [AC_DEFINE(socklen_t, int,[Socket length type])])
106
107 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
108 AC_CHECK_HEADERS(sys/time.h time.h)
109 AC_CHECK_HEADERS(sys/socket.h netinet/in.h)
110 AC_CHECK_HEADERS(stdarg.h vararg.h)
111 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
112 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
113 AC_CHECK_FUNCS(waitpid strlcpy strlcat innetgr initgroups memmove strdup)
114 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp)
115 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
116 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
117 AC_HAVE_DECL(errno, [#include <errno.h>])
118
119 AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[
120 AC_TRY_RUN([#include <stdlib.h>
121 #include <sys/types.h>
122 #include <sys/stat.h>
123 #include <unistd.h>
124 main() { 
125   struct stat st;
126   char tpl[20]="/tmp/test.XXXXXX"; 
127   int fd = mkstemp(tpl); 
128   if (fd == -1) exit(1);
129   unlink(tpl);
130   if (fstat(fd, &st) != 0) exit(1);
131   if ((st.st_mode & 0777) != 0600) exit(1);
132   exit(0);
133 }],
134 samba_cv_HAVE_SECURE_MKSTEMP=yes,
135 samba_cv_HAVE_SECURE_MKSTEMP=no,
136 samba_cv_HAVE_SECURE_MKSTEMP=cross)])
137 if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
138     AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
139 fi
140
141 dnl Provided by snprintf.c:
142 AC_CHECK_HEADERS(stdio.h strings.h)
143 AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
144 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
145
146 AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[
147 AC_TRY_RUN([
148 #include <sys/types.h>
149 #include <stdio.h>
150 #include <stdarg.h>
151 #include <stdlib.h>
152 void foo(const char *format, ...) { 
153        va_list ap;
154        int len;
155        char buf[20];
156        long long l = 1234567890;
157        l *= 100;
158
159        va_start(ap, format);
160        len = vsnprintf(buf, 0, format, ap);
161        va_end(ap);
162        if (len != 5) exit(1);
163
164        va_start(ap, format);
165        len = vsnprintf(0, 0, format, ap);
166        va_end(ap);
167        if (len != 5) exit(2);
168
169        if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
170
171        if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
172        if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
173        if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
174        if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
175
176        exit(0);
177 }
178 main() { foo("hello"); }
179 ],
180 samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)])
181 if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
182     AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
183 fi
184
185 dnl dummies provided by dlfcn.c if not available
186 save_LIBS="$LIBS"
187 LIBS=""
188 AC_SEARCH_LIBS(dlopen, dl)
189 AC_CHECK_HEADERS(dlfcn.h)
190 AC_CHECK_FUNCS(dlopen dlsym dlerror dlclose)
191 LIBDL="$LIBS"
192 AC_SUBST(LIBDL)
193 LIBS="$save_LIBS"
194
195 AC_CHECK_FUNCS([syslog memset setnetgrent getnetgrent endnetgrent memcpy],,
196                            [AC_MSG_ERROR([Required function not found])])
197
198 m4_include(getpass.m4)
199 m4_include(system/config.m4)
200
201 LIBREPLACE_C99_STRUCT_INIT(c99_struct_initialization=yes,
202                         c99_struct_initialization=no)
203
204 dnl VA_COPY
205 AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
206 AC_TRY_LINK([#include <stdarg.h>
207 va_list ap1,ap2;], [va_copy(ap1,ap2);],
208 samba_cv_HAVE_VA_COPY=yes,samba_cv_HAVE_VA_COPY=no)])
209 if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then
210     AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
211 fi
212
213 if test x"$samba_cv_HAVE_VA_COPY" != x"yes"; then
214 AC_CACHE_CHECK([for __va_copy],samba_cv_HAVE___VA_COPY,[
215 AC_TRY_LINK([#include <stdarg.h>
216 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
217 samba_cv_HAVE___VA_COPY=yes,samba_cv_HAVE___VA_COPY=no)])
218 if test x"$samba_cv_HAVE___VA_COPY" = x"yes"; then
219     AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
220 fi
221 fi
222
223 dnl __FUNCTION__ macro
224 AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[
225 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
226 samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)])
227 if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
228     AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
229 else
230     dnl __func__ macro
231     AC_CACHE_CHECK([for __func__ macro],samba_cv_HAVE_func_MACRO,[
232     AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
233     samba_cv_HAVE_func_MACRO=yes,samba_cv_HAVE_func_MACRO=no)])
234     if test x"$samba_cv_HAVE_func_MACRO" = x"yes"; then
235        AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
236     fi
237 fi
238
239 AC_CHECK_HEADERS([sys/param.h limits.h])
240
241 AC_CHECK_TYPE(comparison_fn_t, 
242 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
243
244 AC_CHECK_FUNCS(timegm strnlen setenv)
245 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
246
247 # this test disabled as we don't actually need __VA_ARGS__ yet
248 # AC_TRY_CPP([
249 # #define eprintf(...) fprintf(stderr, __VA_ARGS__)
250 # eprintf("bla", "bar");
251 # ], [], [AC_MSG_ERROR([__VA_ARGS__ is required])])
252
253 # Check prerequisites
254 AC_CHECK_FUNCS([memset printf syslog], [], 
255                            [ AC_MSG_ERROR([Required function not found])])
256
257 AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [
258     AC_TRY_COMPILE([
259 #include <sys/types.h>
260 #if STDC_HEADERS
261 #include <stdlib.h>
262 #include <stddef.h>
263 #endif
264 #include <signal.h>],[sig_atomic_t i = 0],
265         samba_cv_sig_atomic_t=yes,samba_cv_sig_atomic_t=no)])
266 if test x"$samba_cv_sig_atomic_t" = x"yes"; then
267    AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
268 fi
269
270
271 AC_CACHE_CHECK([for O_DIRECT flag to open(2)],samba_cv_HAVE_OPEN_O_DIRECT,[
272 AC_TRY_COMPILE([
273 #include <unistd.h>
274 #ifdef HAVE_FCNTL_H
275 #include <fcntl.h>
276 #endif],
277 [int fd = open("/dev/null", O_DIRECT);],
278 samba_cv_HAVE_OPEN_O_DIRECT=yes,samba_cv_HAVE_OPEN_O_DIRECT=no)])
279 if test x"$samba_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
280     AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
281 fi 
282
283
284 AC_CACHE_CHECK([that the C compiler can precompile header files],samba_cv_precompiled_headers, [
285         dnl Check whether the compiler can generate precompiled headers
286         touch conftest.h
287         if ${CC-cc} conftest.h 2> /dev/null && test -f conftest.h.gch; then
288                 precompiled_headers=yes
289         else
290                 precompiled_headers=no
291         fi])
292 AC_SUBST(precompiled_headers)
293
294
295 dnl Check if the C compiler understands volatile (it should, being ANSI).
296 AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
297         AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
298                 samba_cv_volatile=yes,samba_cv_volatile=no)])
299 if test x"$samba_cv_volatile" = x"yes"; then
300         AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
301 fi