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.
 
 
 
 
 
 

228 lines
6.5 KiB

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