d996cd2944f01e83432a1f87e4aa4fa57e49e783
[idzebra-moved-to-github.git] / configure.ac
1 dnl This file is part of the Zebra server.
2 dnl   Copyright (C) 1994-2009 Index Data
3 dnl
4 AC_PREREQ(2.60)
5 AC_INIT([idzebra],[2.0.38],[zebra-help@indexdata.dk])
6 AC_CONFIG_SRCDIR(configure.ac)
7 AC_CONFIG_AUX_DIR(config)
8 AM_INIT_AUTOMAKE([1.9])
9 PACKAGE_SUFFIX="-2.0"
10 AC_SUBST(PACKAGE_SUFFIX)
11 dnl http://www.gnu.org/software/libtool/manual.html#Versioning
12 ZEBRALIBS_VERSION_INFO=0:1:0
13 AC_SUBST(ZEBRALIBS_VERSION_INFO)
14 main_zebralib=index/libidzebra${PACKAGE_SUFFIX}.la
15 AC_SUBST(main_zebralib)
16 dnl ------ Substitutions
17 AC_SUBST(TCL_INCLUDE)
18 AC_SUBST(TCL_LIB)
19 AC_SUBST(READLINE_LIBS)
20 AC_SUBST(ZEBRA_CFLAGS)
21 dnl
22 dnl ------ Checking programs
23 AC_PROG_CC
24 AC_PROG_CPP
25 AM_PROG_LIBTOOL
26 AC_DEFINE_UNQUOTED(HOST_TRIPLET,"${host}")
27 dnl
28 dnl ------ headers
29 AC_CHECK_HEADERS([sys/resource.h sys/time.h sys/wait.h sys/utsname.h unistd.h])
30 dnl ------ crypt
31 AC_CHECK_LIB([crypt],[crypt])
32 if test "$ac_cv_lib_crypt_crypt" = "yes"; then
33     AC_CHECK_HEADERS(crypt.h)
34 fi
35 dnl
36 dnl ------ YAZ
37 YAZ_INIT([server icu],[3.0.17])
38 if test "$YAZVERSION" = "NONE"; then
39     AC_MSG_ERROR([YAZ development libraries required])
40 fi
41 YAZ_DOC
42 dnl ------ Look for Tcl
43 dnl See if user has specified location of tclConfig.sh; otherwise
44 dnl see if tclConfig.sh exists in same prefix lcoation as tclsh; otherwise
45 dnl disable Tcl.
46 TCL_LIB=""
47 TCL_INCLUDE=""
48 tclconfig=NONE
49 AC_ARG_WITH(tclconfig, [  --with-tclconfig=DIR    tclConfig.sh in DIR], [tclconfig=$withval])
50 if test "x$tclconfig" = xNONE; then
51     saveprefix=${prefix}
52     AC_PREFIX_PROGRAM(tclsh)
53     tclconfig=${prefix}/lib
54     prefix=${saveprefix}
55     if test ! -r ${tclconfig}/tclConfig.sh; then
56         # Not found, try search for Tcl on Debian systems.
57         for d in /usr/lib/tcl*; do
58             if test -f $d/tclConfig.sh; then
59                 tclconfig=$d
60             fi
61         done
62     fi
63 fi
64 AC_MSG_CHECKING(for Tcl)
65 if test -r ${tclconfig}/tclConfig.sh; then
66     . ${tclconfig}/tclConfig.sh
67     if test -r ${tclconfig}/../generic/tcl.h; then
68         TCL_INCLUDE=-I${tclconfig}/../generic
69         TCL_LIB="$TCL_BUILD_LIB_SPEC $TCL_LIBS"
70     elif test -d ${TCL_PREFIX}/include/tcl${TCL_VERSION}; then
71         TCL_INCLUDE=-I${TCL_PREFIX}/include/tcl${TCL_VERSION}
72         TCL_LIB="$TCL_LIB_SPEC $TCL_LIBS"
73     else
74         TCL_INCLUDE=-I${TCL_PREFIX}/include
75         TCL_LIB="$TCL_LIB_SPEC $TCL_LIBS"
76     fi
77     TCL_LIB=`echo $TCL_LIB|sed 's%-L/usr/lib%%g'`
78     SHLIB_CFLAGS=$TCL_SHLIB_CFLAGS
79     SHLIB_LD=$TCL_SHLIB_LD
80     SHLIB_SUFFIX=$TCL_SHLIB_SUFFIX
81     SHLIB_VERSION=$TCL_SHLIB_VERSION
82     AC_MSG_RESULT($TCL_VERSION)
83
84     old_CPPFLAGS=$CPPFLAGS
85     CPPFLAGS="${TCL_INCLUDE} $CPPFLAGS"
86     AC_CHECK_HEADERS(tcl.h)
87     CPPFLAGS=${old_CPPFLAGS}
88
89     # The Mac OSX -framework causes problems with Libtool
90     # and dependancy libs.. so apply Tcl libs everywhere bug #461
91     case $host in
92         *-*-darwin*)
93             LIBS="$LIBS $TCL_LIB";
94             ;;
95     esac
96     
97 else
98     AC_MSG_RESULT(Not found)
99     AC_DEFINE(HAVE_TCL_H,0)
100 fi
101 dnl
102 dnl ------ various functions
103 AC_CHECK_FUNCS(mkstemp atoll)
104 dnl
105 dnl ------ GNU Readline
106 READLINE_SHARED_LIBADD=""
107 AC_CHECK_LIB(ncurses, tgetent, [READLINE_SHARED_LIBADD="-lncurses"],
108     AC_CHECK_LIB(termcap, tgetent, [READLINE_SHARED_LIBADD="-ltermcap"])
109 )
110 READLINE_LIBS=""
111 AC_CHECK_LIB(readline, readline, [READLINE_LIBS="$READLINE_LIBS -lreadline $READLINE_SHARED_LIBADD"],,$READLINE_SHARED_LIBADD)
112 AC_CHECK_LIB(history, add_history, [READLINE_LIBS="$READLINE_LIBS -lhistory"])
113 if test "$ac_cv_lib_readline_readline" = "yes"; then
114     AC_CHECK_HEADERS(readline/readline.h readline/history.h)
115     xLIBS=$LIBS
116     LIBS="$LIBS $READLINE_LIBS"
117     AC_TRY_LINK([
118         #include <stdio.h>
119         #include <readline/readline.h>
120         ],[
121             rl_attempted_completion_over = 0;
122             ],AC_DEFINE(HAVE_READLINE_COMPLETION_OVER))
123     AC_TRY_LINK([
124         #include <stdio.h>
125         #include <readline/readline.h>
126             ],[
127             rl_completion_matches (0, 0);
128             ],AC_DEFINE(HAVE_READLINE_RL_COMPLETION_MATCHES))
129     LIBS=$xLIBS
130 fi
131 dnl
132 dnl ------ iconv
133 AC_ARG_WITH(iconv, [  --with-iconv[=DIR]        iconv library in DIR])
134 if test "$with_iconv" != "no"; then
135     AC_MSG_CHECKING(for iconv)
136     oldLIBS="$LIBS"
137     oldCPPFLAGS="${CPPFLAGS}"
138     if test "$with_iconv" != "yes" -a "$with_iconv" != ""; then
139         LIBS="$LIBS -L${with_iconv}/lib"
140         CPPFLAGS="${CPPFLAGS} -I${with_iconv}/include"
141     fi
142     AC_TRY_LINK([
143                 #include <iconv.h>
144             ],[
145             iconv_t t = iconv_open("", "");
146             ],[
147             AC_DEFINE(HAVE_ICONV_H)
148             AC_MSG_RESULT(yes)
149             ],[
150             LIBS="$LIBS -liconv"
151             AC_TRY_LINK([
152                         #include <iconv.h>
153                     ],[
154                     iconv_t t = iconv_open("", "");
155                     ],[
156                     AC_DEFINE(HAVE_ICONV_H)
157                     AC_MSG_RESULT(yes)
158                     ],[
159                     LIBS="$oldLIBS"
160                     CPPFLAGS="$oldCPPFLAGS"
161                     AC_MSG_RESULT(no)
162                     ])
163             ])
164 fi
165 dnl
166 dnl ------- BZIP2
167 AC_CHECK_LIB(bz2,bzCompressInit)
168 if test "$ac_cv_lib_bz2_bzCompressInit" = "yes"; then
169     AC_CHECK_HEADERS(bzlib.h)
170 else
171     AC_CHECK_LIB(bz2,BZ2_bzCompressInit)
172     if test "$ac_cv_lib_bz2_BZ2_bzCompressInit" = "yes"; then
173         AC_CHECK_HEADERS(bzlib.h)
174     fi
175 fi
176 dnl
177 dnl ------- zlib
178 AC_CHECK_LIB([z],[compress2])
179 if test "$ac_cv_lib_z_compress2" = "yes"; then
180     AC_CHECK_HEADERS([zlib.h])
181 fi
182 dnl ------ -lm
183 AC_CHECK_LIB(m,sqrt)
184 dnl ------ -ldl
185 AC_CHECK_LIB(dl,dlopen)
186 dnl
187 dnl ------ EXPAT
188 expat=yes
189 AC_SUBST(EXPAT_LIBS)
190 AC_ARG_WITH(expat,   [  --with-expat[=DIR]        EXPAT library in DIR],[expat=$withval])
191 if test "$expat" != "no"; then
192     xLIBS="$LIBS";
193     xCFLAGS="$CFLAGS";
194     if test "$expat" != "yes"; then
195         EXPAT_CFLAGS="-I$expat/include"
196         EXPAT_LIBS="-L$expat/lib"
197         CFLAGS="$EXPAT_CFLAGS $CFLAGS"
198         LIBS="$EXPAT_LIBS $LIBS"
199     fi
200     AC_CHECK_LIB(expat,XML_ParserCreate,[EXPAT_LIBS="$EXPAT_LIBS -lexpat"])
201     if test "$ac_cv_lib_expat_XML_ParserCreate" = "yes"; then
202                 AC_CHECK_HEADERS(expat.h)
203     fi
204     LIBS="$xLIBS"
205     CFLAGS="$xCFLAGS"
206 fi
207 dnl
208 dnl ------- 64 bit files
209 AC_SYS_LARGEFILE
210 AC_CHECK_TYPES([long long])
211 if test "${ac_cv_type_long_long}" = "yes"; then
212     ZINT_VALUE=1
213 else
214     ZINT_VALUE=0
215 fi 
216 ZEBRA_CFLAGS="-DZEBRA_ZINT=${ZINT_VALUE}"
217 AC_DEFINE_UNQUOTED(ZEBRA_ZINT,${ZINT_VALUE})
218 dnl ------ Modules
219 AC_SUBST(SHARED_MODULE_LA)
220 SHARED_MODULE_LA=""
221 AC_SUBST(STATIC_MODULE_OBJ)
222 STATIC_MODULE_OBJ=""
223 AC_SUBST(STATIC_MODULE_LADD)
224 STATIC_MODULE_LADD=""
225 AC_DEFUN([ZEBRA_MODULE],[
226         AC_ARG_ENABLE(mod-$1,[$3],[myen=$enableval],[myen=$2])
227         AC_MSG_CHECKING([for module $1])
228         if test "$myen" = "yes"; then
229            myen="shared" 
230         fi
231         if test "$enable_shared" != "yes"; then
232             if test "$myen" = "shared"; then
233                 myen="static"
234             fi
235         fi
236         m=`echo $1|tr .- __`
237         if test "$myen" = "no" -o "$myen" = "disabled"; then
238             AC_MSG_RESULT([disabled])
239         elif test "$2" = "disabled"; then
240             AC_MSG_RESULT([disabled])
241             AC_MSG_ERROR([Cannot enable mod-$1 because of missing libs (XML, etc)])
242         elif test "$myen" = "shared"; then
243             AC_MSG_RESULT([shared])
244             SHARED_MODULE_LA="${SHARED_MODULE_LA} mod-$1.la"
245         elif test "$myen" = "static"; then
246             AC_MSG_RESULT([static])
247             STATIC_MODULE_OBJ="${STATIC_MODULE_OBJ} \$(mod_${m}_la_OBJECTS)"
248             STATIC_MODULE_LADD="${STATIC_MODULE_LADD} \$(mod_${m}_la_LADD)"
249             modcpp=`echo $1|tr abcdefghijklmnopqrstuvwxyz- ABCDEFGHIJKLMNOPQRSTUVWXYZ_`
250             AC_DEFINE_UNQUOTED([IDZEBRA_STATIC_$modcpp])
251         else
252             AC_MSG_RESULT([$myen])
253             AC_MSG_ERROR([invalid --enable-mod-$1 value. Use on,off,static or shared])
254         fi
255         ])
256
257 AC_DEFINE(IDZEBRA_STATIC_GRS_SGML)
258 ZEBRA_MODULE(text,shared,    [  --enable-mod-text       Text filter])
259 ZEBRA_MODULE(grs-regx,shared,[  --enable-mod-grs-regx   REGX/TCL filter])
260 ZEBRA_MODULE(grs-marc,shared,[  --enable-mod-grs-marc   MARC filter])
261 if test "$ac_cv_header_expat_h" = "yes"; then
262     def="shared"
263 else
264     def="disabled"
265 fi
266 ZEBRA_MODULE(grs-xml,[$def], [  --enable-mod-grs-xml    XML filter (Expat based)])
267 oldCPPFLAGS="$CPPFLAGS"
268 CPPFLAGS="$CPPFLAGS $YAZINC"
269 AC_PREPROC_IFELSE(
270    [AC_LANG_PROGRAM([[
271 #if YAZ_HAVE_XML2
272 #include <libxml/xmlversion.h>
273 #include <libxml/parser.h>
274 #include <libxml/tree.h>
275 #include <libxml/xmlIO.h>
276 #include <libxslt/transform.h>
277 #include <libxslt/xsltutils.h>
278 #else
279 #error Libxml2 not available
280 #endif
281 ]],[[
282 #if LIBXML_VERSION < 20615
283 #error Libxml2 version < 2.6.15. xmlreader not reliable/present
284 #endif
285 ]])],
286    [def="shared"],
287    [def="disabled"])
288 CPPFLAGS=$oldCPPFLAGS
289 ZEBRA_MODULE(dom,[$def],   [  --enable-mod-dom        XML/XSLT filter (Requires libxslt)])
290 ZEBRA_MODULE(alvis,[$def], [  --enable-mod-alvis      ALVIS filter (Requires libxslt)])
291 ZEBRA_MODULE(safari,shared,[  --enable-mod-safari     Safari filter (DBC)])
292
293 dnl ------ ANSI C Header files
294 AC_STDC_HEADERS
295 if test "$ac_cv_header_stdc" = "no"; then
296     AC_MSG_WARN([Your system does not seem to support ANSI C])
297 fi
298 AC_SUBST(IDZEBRA_SRC_ROOT)
299 AC_SUBST(IDZEBRA_BUILD_ROOT)
300 IDZEBRA_SRC_ROOT=`cd ${srcdir}; pwd`
301 IDZEBRA_BUILD_ROOT=`pwd`
302 dnl
303 dnl ------ versioning
304 dnl
305 WIN_FILEVERSION=`echo $PACKAGE_VERSION | $AWK 'BEGIN { FS = "."; } { m = $4; printf("%d,%d,%d,%d", $1, $2, $3 == "" ? "0" : $3, $4 == "" ? "1" : $4);}'`
306 AC_SUBST([WIN_FILEVERSION])
307 VERSION_HEX=`echo $PACKAGE_VERSION | $AWK 'BEGIN { FS = "."; } { printf("%x", ($1 * 256 + $2) * 256 + $3);}'`
308 AC_SUBST([VERSION_HEX])
309 if test -d ${srcdir}/.git; then
310     VERSION_SHA1=`git show --pretty=format:%H|head -1`
311 else
312     VERSION_SHA1=`head -1 ${srcdir}/ChangeLog|awk '{print $2}'`
313 fi
314 AC_SUBST([VERSION_SHA1])
315 dnl
316 dnl ------ Create Makefiles
317 dnl
318 AC_OUTPUT([
319   Makefile
320   util/Makefile
321   bfile/Makefile
322   dfa/Makefile
323   dict/Makefile
324   isamb/Makefile
325   isams/Makefile
326   isamc/Makefile
327   rset/Makefile
328   data1/Makefile
329   index/Makefile
330   include/Makefile include/idzebra/Makefile
331   tab/Makefile
332   doc/Makefile
333   doc/local.ent
334   doc/common/Makefile
335   doc/common/print.dsl
336   test/Makefile test/gils/Makefile test/usmarc/Makefile test/api/Makefile
337   test/xslt/Makefile
338   test/xpath/Makefile
339   test/rusmarc/Makefile test/cddb/Makefile test/malxml/Makefile 
340   test/mbox/Makefile
341   test/config/Makefile
342   test/xelm/Makefile
343   test/dmoz/Makefile test/zsh/Makefile
344   test/marcxml/Makefile test/charmap/Makefile test/codec/Makefile
345   test/espec/Makefile
346   test/filters/Makefile
347   examples/Makefile 
348   examples/gils/Makefile 
349   examples/marc21/Makefile 
350   examples/marcxml/Makefile 
351   examples/oai-pmh/Makefile
352   examples/zthes/Makefile
353   idzebra.spec
354   idzebra-config-2.0
355   Doxyfile
356   win/version.nsi
357   include/idzebra/version.h
358 ],[sed s%echo_source=yes%echo_source=no%g < idzebra-config-2.0 > util/idzebra-config-2.0 && chmod +x idzebra-config-2.0 util/idzebra-config-2.0])
359
360 echo \
361 "------------------------------------------------------------------------
362
363   ZEBRA Package:              ${PACKAGE}
364   ZEBRA Version:              ${VERSION}
365   Source code location:       ${srcdir}
366   C Preprocessor:             ${CPP}
367   C Preprocessor flags:       ${CPPFLAGS}
368   C Compiler:                 ${CC}
369   C Compiler flags:           ${CFLAGS}
370   Linker flags:               ${LDFLAGS}
371   Linked libs:                ${LIBS}
372   Host System Type:           ${host}
373   Install path:               ${prefix}
374   Automake:                   ${AUTOMAKE}
375   Archiver:                   ${AR}
376   Ranlib:                     ${RANLIB}
377   YAZ Version:                ${YAZVERSION}
378   YAZ Include:                ${YAZINC}
379   YAZ La Lib:                 ${YAZLALIB}
380   YAZ Lib:                    ${YAZLIB}
381   Bugreport:                  ${PACKAGE_BUGREPORT}
382
383 ------------------------------------------------------------------------"
384 dnl Local Variables:
385 dnl mode:shell-script
386 dnl sh-indentation:2
387 dnl sh-basic-offset: 4
388 dnl End: