Bibletime – a bible study tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. ## -*- autoconf -*-
  2. dnl This file was created by Joachim Ansorg <joachim@ansorgs.de>
  3. dnl It provides macord for the autoconf package to find the Sword library on your system.
  4. dnl ----------------------------------------------------------------------
  5. dnl Check wheter to use static linking
  6. dnl first parameter is the required version
  7. dnl second is whether to use static sword library
  8. dnl ----------------------------------------------------------------------
  9. AC_DEFUN(AC_CHECK_SWORD,
  10. [
  11. dnl AC_MSG_CHECKING([for a Sword installation])
  12. dnl The option for the configure script
  13. AC_ARG_WITH(sword-dir,
  14. [ --with-sword-dir=DIR Path where Sword is being installed (default=/usr) ],
  15. [
  16. ac_sword_dir=$withval
  17. ],ac_sword_dir=/usr
  18. )
  19. AC_ARG_ENABLE(static-sword,
  20. [ --enable-static-sword Link to the static Sword library],
  21. ac_static_sword="YES",
  22. [ ac_static_sword="$2" ]
  23. )
  24. dnl try to find Sword library files
  25. AC_MSG_CHECKING([for Sword library files])
  26. AC_REQUIRE([AC_FIND_ZLIB])
  27. sword_multiarch="`gcc -print-multiarch 2>/dev/null`"
  28. ac_sword_library_dirs="$ac_sword_dir/lib/$sword_multiarch $ac_sword_dir/lib64 $ac_sword_dir/lib $exec_prefix/lib/$sword_multiarch $exec_prefix/lib $prefix/lib/$sword_multiarch $prefix/lib64 $prefix/lib /usr/lib/$sword_multiarch /usr/lib /usr/lib64 /usr/lib/sword /usr/local/lib/$sword_multiarch /usr/local/lib /usr/local/lib/sword /usr/local/sword/lib"
  29. if test "x$ac_static_sword" = "xYES"; then
  30. SEARCH_LIBS="libsword.a";
  31. else
  32. SEARCH_LIBS="libsword.so libsword.so.3 libsword.so.4 libsword.a";
  33. fi
  34. AC_CACHE_VAL(ac_cv_sword_libdir, AC_FIND_FILE($SEARCH_LIBS, $ac_sword_library_dirs, ac_cv_sword_libdir))
  35. if test "x$ac_cv_sword_libdir" = "xNO"; then
  36. AC_MSG_ERROR(SWORD library not found. Try to use configure with --with-sword-dir=/your/SWORD/path!);
  37. fi
  38. if test "x$ac_static_sword" = "xYES"; then
  39. LIB_SWORD="$ac_cv_sword_libdir/libsword.a";
  40. else
  41. LIB_SWORD="-lsword";
  42. fi
  43. AC_SUBST(SWORD_LIBRARY_PATH)
  44. AC_SUBST(LIB_SWORD)
  45. all_libraries="$all_libraries -L$ac_cv_sword_libdir"
  46. if test "x$ac_static_sword" = "xYES"; then
  47. MESSAGE="static library $ac_cv_sword_libdir/libsword.a";
  48. else
  49. MESSAGE="$ac_cv_sword_libdir";
  50. fi
  51. AC_MSG_RESULT([$MESSAGE])
  52. dnl -- try to find Swords include files --
  53. AC_MSG_CHECKING([for Sword include files])
  54. ac_sword_include_dirs="$ac_sword_dir/include/sword $ac_sword_dir/include $exec_prefix/include $prefix/include /usr/include/sword /usr/include /usr/local/include/sword /usr/local/include /usr/local/sword/include /usr/local/sword/include/sword"
  55. AC_CACHE_VAL(ac_cv_sword_incdir, AC_FIND_FILE(swmgr.h, $ac_sword_include_dirs, ac_cv_sword_incdir))
  56. if test "x$ac_cv_sword_incdir" = "xNO"; then
  57. AC_MSG_ERROR([The Sword include file files were not found.
  58. Please try to use configure with --with-sword-dir=/your/SWORD/path !
  59. ])
  60. fi
  61. SWORD_INCLUDES="-I$ac_cv_sword_incdir"
  62. AC_SUBST(SWORD_INCLUDES)
  63. all_includes="$all_includes -I$ac_cv_sword_incdir"
  64. AC_MSG_RESULT([$ac_cv_sword_incdir])
  65. dnl -- Sword version tests --
  66. dnl First test for installed Sword version
  67. dnl Then check if it's recent enough
  68. AC_MSG_CHECKING([for installed Sword version])
  69. AC_CACHE_VAL(ac_cv_installed_sword_version,
  70. [
  71. AC_LANG_SAVE
  72. AC_LANG_CPLUSPLUS
  73. ac_LD_LIBRARY_PATH_safe=$LD_LIBRARY_PATH
  74. ac_LIBRARY_PATH="$LIBRARY_PATH"
  75. ac_cxxflags_safe="$CXXFLAGS"
  76. ac_ldflags_safe="$LDFLAGS"
  77. ac_libs_safe="$LIBS"
  78. CXXFLAGS="$CXXFLAGS -I$"
  79. LDFLAGS="$LDFLAGS -L$ac_cv_sword_libdir"
  80. LIBS="$LIB_SWORD -lz -ltqt"
  81. LD_LIBRARY_PATH="$ac_cv_sword_libdir"
  82. export LD_LIBRARY_PATH
  83. LIBRARY_PATH=
  84. export LIBRARY_PATH
  85. cat > conftest.$ac_ext <<EOF
  86. #include <iostream>
  87. #include <swversion.h>
  88. #ifdef SWORD_NAMESPACE_START
  89. using namespace sword;
  90. #endif
  91. int main(int argc, char** argv) {
  92. std::cout << SWVersion::currentVersion << std::endl;
  93. return 0;
  94. }
  95. EOF
  96. ac_link='$LIBTOOL_SHELL --silent --mode=link --tag=LD ${CXX-g++} -o conftest $CXXFLAGS $all_includes $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
  97. if AC_TRY_EVAL(ac_link) && test -s conftest; then
  98. if test -x conftest; then
  99. eval ac_cv_installed_sword_version=`./conftest 2>&5`
  100. fi
  101. else
  102. echo "configure: failed program was:" >&AC_FD_CC
  103. AC_MSG_ERROR([Failed to compile the test program to check the Sword version! Please have a look at config.log! Report this to the BibleTime developers!]);
  104. cat conftest.$ac_ext >&AC_FD_CC
  105. fi
  106. rm -f conftest*
  107. CXXFLAGS="$ac_cxxflags_safe"
  108. LDFLAGS="$ac_ldflags_safe"
  109. LIBS="$ac_libs_safe"
  110. LD_LIBRARY_PATH="$ac_LD_LIBRARY_PATH_safe"
  111. export LD_LIBRARY_PATH
  112. LIBRARY_PATH="$ac_LIBRARY_PATH"
  113. export LIBRARY_PATH
  114. AC_LANG_RESTORE
  115. ])
  116. AC_MSG_RESULT([$ac_cv_installed_sword_version])
  117. dnl *** Now check if the installed version is recent enough
  118. AC_MSG_CHECKING([whether your Sword installation is recent enough])
  119. AC_CACHE_VAL(ac_cv_sword_recent_version,
  120. [
  121. AC_LANG_SAVE
  122. AC_LANG_CPLUSPLUS
  123. ac_LD_LIBRARY_PATH_safe=$LD_LIBRARY_PATH
  124. ac_LIBRARY_PATH="$LIBRARY_PATH"
  125. ac_cxxflags_safe="$CXXFLAGS"
  126. ac_ldflags_safe="$LDFLAGS"
  127. ac_libs_safe="$LIBS"
  128. CXXFLAGS="$CXXFLAGS -I$"
  129. LDFLAGS="$LDFLAGS -L$ac_cv_sword_libdir"
  130. LIBS="$LIB_SWORD -lz -ltqt"
  131. LD_LIBRARY_PATH="$ac_cv_sword_libdir"
  132. export LD_LIBRARY_PATH
  133. LIBRARY_PATH=
  134. export LIBRARY_PATH
  135. cat > conftest.$ac_ext <<EOF
  136. #include <iostream>
  137. #include <swversion.h>
  138. #ifdef SWORD_NAMESPACE_START
  139. using namespace sword;
  140. #endif
  141. int main(int argc, char** argv) {
  142. if (argc == 2) { //compare required with installed Sword version
  143. const char* requiredVersion( argv[[1]] );
  144. if ( (SWVersion( requiredVersion ) < SWVersion::currentVersion) || (SWVersion( requiredVersion ) == SWVersion::currentVersion) ) {
  145. std::cout << "ok";
  146. return -1;
  147. }
  148. else {
  149. std::cout << "not-ok";
  150. return -2; //version not recent enough
  151. }
  152. }
  153. return 0;
  154. }
  155. EOF
  156. ac_link='$LIBTOOL_SHELL --silent --mode=link --tag=LD ${CXX-g++} -o conftest $CXXFLAGS $all_includes $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
  157. if AC_TRY_EVAL(ac_link) && test -s conftest; then
  158. if test -x conftest; then
  159. eval ac_cv_sword_recent_version=`./conftest $1 2>&5`
  160. fi
  161. else
  162. echo "configure: failed program was:" >&AC_FD_CC
  163. AC_MSG_ERROR([Failed to compile the test program to check the Sword version! Please have a look at config.log! Report this to the BibleTime developers!]);
  164. cat conftest.$ac_ext >&AC_FD_CC
  165. fi;
  166. rm -f conftest*
  167. CXXFLAGS="$ac_cxxflags_safe"
  168. LDFLAGS="$ac_ldflags_safe"
  169. LIBS="$ac_libs_safe"
  170. LD_LIBRARY_PATH="$ac_LD_LIBRARY_PATH_safe"
  171. export LD_LIBRARY_PATH
  172. LIBRARY_PATH="$ac_LIBRARY_PATH"
  173. export LIBRARY_PATH
  174. AC_LANG_RESTORE
  175. ])
  176. if test "x$ac_cv_sword_recent_version" = "xok"; then
  177. AC_MSG_RESULT([yes]);
  178. elif test "x$ac_cv_sword_recent_version" = "xnot-ok"; then
  179. AC_MSG_RESULT([no]);
  180. AC_MSG_ERROR([Your Sword installation is not recent enought! Please upgrade to version $1! Get the Sword library at www.crosswire.org.]);
  181. else
  182. AC_MSG_ERROR([Invalid return code of the internal Sword version test program. Please submit a bugreport!]);
  183. fi;
  184. ])