2
dnl This file was created by Joachim Ansorg <jansorg@gmx.de>
3
dnl It provides macord for the autoconf package to find the Sword library on your system.
5
dnl ----------------------------------------------------------------------
6
dnl Check wheter to use static linking
7
dnl first parameter is the required version
8
dnl second is whether to use static sword library
9
dnl ----------------------------------------------------------------------
10
AC_DEFUN(SW_CHECK_SWORD,
12
dnl AC_MSG_CHECKING([for a Sword installation])
14
dnl The option for the configure script
15
AC_ARG_WITH(sword-dir,
16
[ --with-sword-dir=DIR Patch where Sword is being installed (default=/usr) ],
22
AC_ARG_ENABLE(static-sword,
23
[ --enable-static-sword Link to the static Sword library],
24
ac_static_sword="YES",
25
[ ac_static_sword="$2" ]
28
dnl try to find Sword library files
29
AC_MSG_CHECKING([for Sword library files])
30
AC_REQUIRE([AC_FIND_ZLIB])
31
ac_sword_library_dirs="$ac_sword_dir/lib /usr/lib /usr/lib/sword /usr/local/lib /usr/local/lib/sword /usr/local/sword/lib"
33
if test "$ac_static_sword" = "YES"; then
34
SEARCH_LIBS="libsword.a";
36
SEARCH_LIBS="libsword.a libsword.so";
40
AC_CACHE_VAL(ac_cv_sword_libdir, AC_FIND_FILE($SEARCH_LIBS, $ac_sword_library_dirs, ac_cv_sword_libdir))
42
if test "$ac_cv_sword_libdir" = "NO"; then
43
AC_MSG_ERROR(SWORD library not found. Try to use configure with --with-sword-dir=/your/SWORD/path!);
46
if test "$ac_static_sword" = "YES"; then
47
LIB_SWORD="$ac_cv_sword_libdir/libsword.a";
49
LIB_SWORD="-L$ac_cv_sword_libdir -lsword";
52
#AC_SUBST(SWORD_LIBRARY_PATH)
54
all_libraries="$all_libraries -L$ac_cv_sword_libdir"
56
if test "$ac_static_sword" = "YES"; then
57
MESSAGE="static library $ac_cv_sword_libdir/libsword.a";
59
MESSAGE="$ac_cv_sword_libdir";
61
AC_MSG_RESULT([$MESSAGE])
65
dnl -- try to find Swords include files --
66
AC_MSG_CHECKING([for Sword include files])
67
ac_sword_include_dirs="$ac_sword_dir/include/sword $ac_sword_dir/include /usr/include/sword /usr/include /usr/local/include/sword /usr/local/include /usr/local/sword/include /usr/local/sword/include/sword"
69
AC_CACHE_VAL(ac_cv_sword_incdir, AC_FIND_FILE(swmgr.h, $ac_sword_include_dirs, ac_cv_sword_incdir))
71
if test "$ac_cv_sword_incdir" = "NO"; then
72
AC_MSG_ERROR([The Sword include file files were not found.
73
Please try to use configure with --with-sword-dir=/your/SWORD/path !
77
SWORD_INCLUDES="-I$ac_cv_sword_incdir"
78
AC_SUBST(SWORD_INCLUDES)
79
all_includes="$all_includes -I$ac_cv_sword_incdir"
81
AC_MSG_RESULT([$ac_cv_sword_incdir])
85
dnl -- check if Sword matches the minimum version --
86
AC_MSG_CHECKING([if you have Sword $1 or later])
88
AC_CACHE_VAL(ac_cv_installed_sword_version,
92
ac_LD_LIBRARY_PATH_safe=$LD_LIBRARY_PATH
93
ac_LIBRARY_PATH="$LIBRARY_PATH"
94
ac_cxxflags_safe="$CXXFLAGS"
95
ac_ldflags_safe="$LDFLAGS"
98
CXXFLAGS="$CXXFLAGS -I$"
99
LDFLAGS="$LDFLAGS -L$ac_cv_sword_libdir"
100
LIBS="$LIB_SWORD -lz"
101
LD_LIBRARY_PATH="$ac_cv_sword_libdir"
102
export LD_LIBRARY_PATH
106
cat > conftest.$ac_ext <<EOF
107
#include <iostream.h>
108
#include <swversion.h>
111
using sword::SWVersion;
113
int main(int argc, char* argv[]) {
115
cout << SWVersion::currentVersion << endl;
119
if (SWVersion(&argv[[1]]) < SWVersion::currentVersion || SWVersion(&argv[[1]]) == SWVersion::currentVersion)
127
return 1; //version not recent enough
134
ac_link='${CXX-g++} -o conftest $CXXFLAGS $all_includes $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
135
if AC_TRY_EVAL(ac_link) && test -s conftest; then
136
if test -x conftest; then
137
eval ac_cv_installed_sword_version=`./conftest 2>&5`
138
echo "configure: ac_cv_installed_sword_version=$ac_cv_installed_sword_version" >&AC_FD_CC
139
eval sword_test_returncode=`./conftest $1 2>&5`;
140
echo "configure: sword_test_returncode=$sword_test_returncode" >&AC_FD_CC
143
echo "configure: failed program was:" >&AC_FD_CC
144
cat conftest.$ac_ext >&AC_FD_CC
148
CXXFLAGS="$ac_cxxflags_safe"
149
LDFLAGS="$ac_ldflags_safe"
152
LD_LIBRARY_PATH="$ac_LD_LIBRARY_PATH_safe"
153
export LD_LIBRARY_PATH
154
LIBRARY_PATH="$ac_LIBRARY_PATH"
160
if test "x$sword_test_returncode" = "x1"; then
161
echo "configure: changing right_version" >&AC_FD_CC
162
right_version="wrong version";
165
AC_MSG_RESULT([$ac_cv_installed_sword_version])
166
echo "configure: right_version=$right_version" >&AC_FD_CC
167
if test "x$right_version" != "xok"; then
168
AC_MSG_ERROR([Your Sword installation is not recent enough! $sword_test_returncode Please
169
upgrade to version $1!]);