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