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