fe0c76f4f5d190bc30ecf20a0a44554656e45d66
[citadel.git] / libcitadel / configure.in
1 dnl   configuration script for libcitadel
2 dnl   Process this file with autoconf to produce a configure script.
3 dnl
4
5 dnl Ensure that libcitadel is configured with autoconf 2.52 or newer
6 AC_PREREQ(2.52)
7
8 AC_INIT(libcitadel, 902, http://uncensored.citadel.org)
9
10 AC_CONFIG_SRCDIR(Makefile.in)
11 AC_CONFIG_AUX_DIR(conftools)
12 AC_CONFIG_SRCDIR(tests/Makefile.in)
13
14 dnl
15 dnl Set LIBREVISION to the ever-ascending libcitadel version number.
16 dnl
17 dnl If the API has changed, increment LIBCURRENT.
18 dnl
19 dnl Set LIBAGE to 0.
20 dnl
21
22 LIBCURRENT=4
23 LIBREVISION=902
24 LIBAGE=0
25
26 sinclude(conftools/libtool.m4)
27 sinclude(conftools/ac_c_bigendian_cross.m4)
28
29 AC_PROG_LIBTOOL
30
31 AC_SUBST(LIBCURRENT)
32 AC_SUBST(LIBREVISION)
33 AC_SUBST(LIBAGE)
34
35 dnl Checks for programs.
36 AC_PROG_CC
37 AC_PROG_INSTALL
38
39 if test "$GCC" = yes ; then
40     dnl
41     dnl Be careful about adding the -fexceptions option; some versions of
42     dnl GCC don't support it and it causes extra warnings that are only
43     dnl distracting; avoid.
44     dnl
45     OLDCFLAGS="$CFLAGS -Wall -Wmissing-prototypes -Wstrict-prototypes"
46     CFLAGS="$OLDCFLAGS -fexceptions"
47     AC_MSG_CHECKING(whether $CC accepts -fexceptions)
48     AC_TRY_LINK( , ,
49                    AC_MSG_RESULT(yes),
50                    AC_MSG_RESULT(no); CFLAGS="$OLDCFLAGS")
51     CXXFLAGS=`echo "$CFLAGS" | sed 's/ -Wmissing-prototypes -Wstrict-prototypes//'`
52 fi
53
54 dnl Checks for header files.
55 AC_HEADER_STDC
56
57 AC_CHECK_HEADER(sys/mman.h, [CFLAGS="$CFLAGS -D HAVE_MMAP"])
58 AC_ARG_WITH(with_zlib,    [  --with-zlib             use zlib compression if present])
59 dnl Checks for the zlib compression library.
60 if test "x$with_zlib" != xno ; then
61         AC_CHECK_HEADERS(zlib.h,
62                 [AC_CHECK_LIB(z, zlibVersion,
63                         [ok_zlib=yes],,
64         )])
65 fi
66
67 if test "x$ok_zlib" = xyes ; then
68         LIBS="-lz $LIBS"
69         AC_DEFINE(HAVE_ZLIB,[],[whether we have zlib])
70 fi
71
72 AC_CHECK_HEADER(CUnit/CUnit.h, [AC_DEFINE(ENABLE_TESTS, [], [whether we should compile the test-suite])])
73
74 AC_CHECK_HEADER(sys/sendfile.h, [AC_DEFINE(LINUX_SENDFILE, [], [whether we have the linux sendfile api])])
75 dnl TODO: we might need to check for the actual syntax....  
76
77
78 AC_MSG_CHECKING([whether your system knows about splice()]) 
79 AC_TRY_COMPILE([
80 #define _GNU_SOURCE
81 #include <unistd.h>
82 #include <fcntl.h>
83 ],
84 [
85         ssize_t sent, pipesize;
86         int fd, SplicePipe[2];
87         pipesize = splice(fd, NULL, 
88                           SplicePipe[1], NULL, 
89                           1, 
90                           SPLICE_F_MORE | SPLICE_F_MOVE|SPLICE_F_NONBLOCK);
91 ],
92                 [
93                   ok_splice=yes
94                   AC_DEFINE(LINUX_SPLICE, [], [whether we have the linux splice api])
95                   AC_MSG_RESULT([yes])
96                 ],
97                 [ 
98                   ok_splice=no
99                   AC_MSG_RESULT([no])
100                 ]
101 )
102
103 AC_MSG_CHECKING([whether your system likes memcpy + HKEY]) 
104 AC_TRY_COMPILE([
105 #define _GNU_SOURCE
106 #include <ctype.h>
107 #include <errno.h>
108 #include <string.h>
109 #include <unistd.h>
110 #include <string.h>
111 #include <stdio.h>
112 #include <sys/select.h>
113 #include <fcntl.h>
114 #include <sys/types.h>
115
116 #include "lib/libcitadel.h"
117 ],
118 [
119         char foo[22];
120         memcpy(foo, HKEY("foo"));
121         
122 ],
123                 [
124
125                   AC_MSG_RESULT([yes])
126                 ],
127                 [ 
128                   AC_DEFINE(UNDEF_MEMCPY, [], [whether we need to undefine memcpy])
129                   AC_MSG_RESULT([no])
130                 ]
131 )
132
133
134 AC_CHECK_HEADERS(iconv.h)
135
136
137 dnl Here is the check for a libc integrated iconv
138 AC_ARG_ENABLE(iconv,
139         [  --disable-iconv         do not use iconv charset conversion],
140         ok_iconv=no, ok_iconv=yes)
141
142 AC_MSG_CHECKING(Checking to see if your system supports iconv)
143 AC_TRY_RUN([
144         #include <iconv.h>
145         main() {
146                 iconv_t ic = (iconv_t)(-1) ;
147                 ic = iconv_open("UTF-8", "us-ascii");
148                 iconv_close(ic);
149                 exit(0);
150         }
151  ],
152                 [
153                   ok_iconv=yes
154                   AC_MSG_RESULT([yes])
155                 ],
156                 [ 
157                   ok_iconv=no
158                   AC_MSG_RESULT([no])
159                 ]
160 )
161
162 dnl Check for iconv in external libiconv
163 if test "$ok_iconv" = no; then
164         AC_MSG_CHECKING(Checking for an external libiconv)
165         OLD_LDFLAGS="$LDFLAGS"
166         LDFLAGS="$LDFLAGS -liconv"
167         AC_TRY_RUN([
168                         #include <iconv.h>
169                         main() {
170                                 iconv_t ic = (iconv_t)(-1) ;
171                                 ic = iconv_open("UTF-8", "us-ascii");
172                                 iconv_close(ic);
173                         }
174                 ],
175                         [
176                           ok_iconv=yes
177                           AC_MSG_RESULT([yes])
178                         ],
179                         [ 
180                           ok_iconv=no
181                           LDFLAGS="$OLD_LDFLAGS"
182                           AC_MSG_RESULT([no])
183                         ]
184                 )
185 fi      
186 if test "$ok_iconv" != "no"; then
187         AC_MSG_RESULT(libcitadel will be built with character set conversion.)
188         AC_DEFINE(HAVE_ICONV,[],[whether we have iconv for charset conversion])
189 else
190         AC_MSG_RESULT(libcitadel will be built without character set conversion.)
191 fi
192
193 dnl disable backtrace if we don't want it.
194 AC_ARG_WITH(backtrace, 
195                     [  --with-backtrace          enable backtrace dumps in the syslog],
196                         [ if test "x$withval" != "xno" ; then
197                              CFLAGS="$CFLAGS  -rdynamic "
198                              LDFLAGS="$LDFLAGS  -rdynamic "
199                              AC_CHECK_FUNCS(backtrace)
200                           fi
201                         ]
202 )
203
204
205 AC_ARG_WITH(with_zlib,    [  --with-zlib             use zlib compression if present])
206 dnl Checks for the zlib compression library.
207 if test "x$with_zlib" != xno ; then
208         AC_CHECK_HEADERS(zlib.h,
209                 [AC_CHECK_LIB(z, zlibVersion,
210                         [ok_zlib=yes],,
211         )])
212 fi
213
214 if test "x$ok_zlib" = xyes ; then
215         LIBS="-lz $LIBS"
216         AC_DEFINE(HAVE_ZLIB,[],[whether we have zlib])
217 fi
218
219
220 dnl Checks for typedefs, structures, and compiler characteristics.
221
222 AC_SUBST(LIBS)
223 AC_C_CONST
224 AC_TYPE_SIZE_T
225 AC_CHECK_FUNCS(memmove bcopy)
226
227 AC_CONFIG_FILES(Makefile libcitadel.pc tests/Makefile)
228 AC_CONFIG_HEADER(sysdep.h)
229 AC_OUTPUT
230
231 abs_srcdir="`cd $srcdir && pwd`"
232 abs_builddir="`pwd`"
233 if test "$abs_srcdir" != "$abs_builddir"; then
234   make mkdir-init
235 fi
236 echo 'zlib compression:                ' $ok_zlib
237 echo 'Character set conversion support:' $ok_iconv