From 03a61295af97983a2313df9717653a466c99ef03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Thu, 9 Oct 2014 03:17:02 +0200 Subject: [PATCH] Fix FTBFS on missing magic_getpath --- CMakeLists.txt | 20 ++++++++++++++++++++ config.h.cmake | 6 ++++++ tdeio/tdeio/CMakeLists.txt | 2 +- tdeio/tdeio/configure.in.in | 22 ++++++++++++++++++++++ tdeio/tdeio/kmimemagic.cpp | 5 +++++ 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11d3c4bfe..e02891634 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -525,6 +525,26 @@ if( NOT HAVE_LIBDL ) endif( NOT HAVE_LIBDL ) +##### check for magic ########################### + +set( MAGIC_LIBRARIES magic ) +check_library_exists( ${MAGIC_LIBRARIES} magic_load "" HAVE_LIBMAGIC ) +if( HAVE_LIBMAGIC ) + check_library_exists( ${MAGIC_LIBRARIES} magic_getpath "" HAVE_LIBMAGIC_GETPATH ) + if( NOT HAVE_LIBMAGIC_GETPATH ) + execute_process( + COMMAND file --version + OUTPUT_VARIABLE LIBMAGIC_VERSION + ERROR_VARIABLE LIBMAGIC_VERSION + ) + string(REGEX REPLACE ".*magic file from ([^ \n]*).*" "\\1" LIBMAGIC_PATH ${LIBMAGIC_VERSION} ) + message( STATUS "libmagick default path ${LIBMAGIC_PATH}" ) + endif( NOT HAVE_LIBMAGIC_GETPATH ) +else( HAVE_LIBMAGIC ) + tde_message_fatal( "libmagic is required, but not found on your system" ) +endif( HAVE_LIBMAGIC ) + + ##### check for utempter ######################## if( WITH_UTEMPTER ) diff --git a/config.h.cmake b/config.h.cmake index b1e4eb30a..145fa2c14 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -914,6 +914,12 @@ /* Defined if compiling with TDEIconLoader debugging */ #cmakedefine TDEICONLOADER_DEBUG 1 +/* Defined if libmagic contain magic_getpath function */ +#cmakedefine HAVE_LIBMAGIC_GETPATH 1 + +/* Define default path for libmagick files */ +#cmakedefine LIBMAGIC_PATH "@LIBMAGIC_PATH@" + /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ #if defined AC_APPLE_UNIVERSAL_BUILD diff --git a/tdeio/tdeio/CMakeLists.txt b/tdeio/tdeio/CMakeLists.txt index 2b90c0107..77d16f2c7 100644 --- a/tdeio/tdeio/CMakeLists.txt +++ b/tdeio/tdeio/CMakeLists.txt @@ -117,7 +117,7 @@ set( ${target}_SRCS tde_add_library( ${target} STATIC_PIC AUTOMOC SOURCES ${${target}_SRCS} - LINK magic ${GAMIN_LIBRARIES} + LINK ${MAGIC_LIBRARIES} ${GAMIN_LIBRARIES} ) diff --git a/tdeio/tdeio/configure.in.in b/tdeio/tdeio/configure.in.in index 8683dfec1..70d381bac 100644 --- a/tdeio/tdeio/configure.in.in +++ b/tdeio/tdeio/configure.in.in @@ -165,3 +165,25 @@ if test "x$kde_enable_inotify" = "xyes"; then AC_MSG_RESULT(no) fi fi + +dnl ------------------------------------------------------------------------ +dnl Try to find if libmagic is installed and contains magic_getpath +dnl ------------------------------------------------------------------------ +dnl +AC_MSG_CHECKING([for libmagic]) +KDE_CHECK_LIB(magic, magic_load, kde_have_libmagic=yes, kde_have_libmagic=no) +if test $kde_have_libmagic = yes; then + AC_MSG_RESULT(yes) + AC_MSG_CHECKING([for libmagic - magic_getpath]) + KDE_CHECK_LIB(magic, magic_getpath, kde_have_libmagic_getpath=yes, kde_have_libmagic_getpath=no) + if test $kde_have_libmagic_getpath = yes; then + AC_DEFINE_UNQUOTED(HAVE_LIBMAGIC_GETPATH, 1, [Defined if libmagic contain magic_getpath function]) + AC_MSG_RESULT(yes) + else + libmagic_path=`file --version 2>&1 | sed -n "s/^magic file from //p"` + AC_DEFINE_UNQUOTED(LIBMAGIC_PATH, $libmagic_path, [Define default path for libmagic files]) + AC_MSG_RESULT(no) + fi +else + AC_MSG_RESULT(no) +fi diff --git a/tdeio/tdeio/kmimemagic.cpp b/tdeio/tdeio/kmimemagic.cpp index 41c69dd3a..97496de98 100644 --- a/tdeio/tdeio/kmimemagic.cpp +++ b/tdeio/tdeio/kmimemagic.cpp @@ -20,6 +20,7 @@ Boston, MA 02110-1301, USA. */ +#include "config.h" #include "kmimemagic.h" #include #include @@ -164,7 +165,11 @@ struct config_rec { int KMimeMagic::apprentice( const TQString& magicfile ) { TQString maindatabase = magicfile; if (maindatabase == "") { +#ifdef HAVE_LIBMAGIC_GETPATH maindatabase = magic_getpath(0, FILE_LOAD); +#else + maindatabase = TQString(LIBMAGIC_PATH); +#endif if (maindatabase == "") { kdWarning() << k_funcinfo << "Unable to locate system mime magic database; mime type detection will not function correctly!" << endl; }