Eina: Fix cases where dlopen is wrongly checked because of autoconf cache values
authorcaro <caro@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 3 Apr 2012 16:28:40 +0000 (16:28 +0000)
committercaro <caro@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 3 Apr 2012 16:28:40 +0000 (16:28 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@69909 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

configure.ac
eina.pc.in
m4/common/efl_dlfcn.m4 [new file with mode: 0644]
src/lib/Makefile.am

index f1c86a3..9987541 100644 (file)
@@ -529,30 +529,8 @@ if test "x${ac_cv_func_malloc_usable_size}" = "xyes" && test "x${want_debug_mall
 fi
 
 # dlopen and dladdr
-dlopen_libs=""
-case "$host_os" in
-   mingw*)
-# managed by evil
-      AC_DEFINE([HAVE_DLADDR])
-      AC_DEFINE([HAVE_DLOPEN])
-      dlopen_libs="-ldl"
-      ;;
-   *)
-      AC_CHECK_FUNCS([dlopen], [res="yes"], [res="no"])
-      if test "x${res}" = "xyes" ; then
-         AC_CHECK_FUNCS([dladdr], [AC_DEFINE([HAVE_DLADDR])])
-         AC_DEFINE([HAVE_DLOPEN])
-      else
-         AC_CHECK_LIB([dl], [dlopen], [res="yes"], [res="no"])
-         if test "x${res}" = "xyes" ; then
-            AC_CHECK_LIB([dl], [dladdr], [AC_DEFINE([HAVE_DLADDR])])
-            AC_DEFINE(HAVE_DLOPEN)
-            dlopen_libs="-ldl"
-         fi
-      fi
-      ;;
-esac
-AC_SUBST([dlopen_libs])
+EFL_CHECK_DLOPEN
+EFL_CHECK_DLADDR
 
 have_log="yes"
 EFL_CHECK_FNMATCH([have_log="yes"], [have_log="no"])
index b1f7b9a..e7a5cc0 100644 (file)
@@ -8,5 +8,5 @@ Description: A Library that implements fast data types and miscellaneous tools
 @pkgconfig_requires_private@: @requirement_eina@
 Version: @VERSION@
 Libs: -L${libdir} -leina @EFL_PTHREAD_LIBS@
-Libs.private: @EFL_FNMATCH_LIBS@ @EFL_SHM_OPEN_LIBS@ @EFL_PTHREAD_LIBS@ @iconv_libs@ @EINA_LIBS@ -lm
+Libs.private: @EFL_FNMATCH_LIBS@ @EFL_SHM_OPEN_LIBS@ @EFL_PTHREAD_LIBS@ @iconv_libs@ @EFL_DLOPEN_LIBS@ @EFL_DLADDR_LIBS@ @EINA_LIBS@ -lm
 Cflags: -I${includedir}/eina-@VMAJ@ -I${includedir}/eina-@VMAJ@/eina
diff --git a/m4/common/efl_dlfcn.m4 b/m4/common/efl_dlfcn.m4
new file mode 100644 (file)
index 0000000..53ca839
--- /dev/null
@@ -0,0 +1,136 @@
+dnl Copyright (C) 2012 Vincent Torri <vtorri at univ-evry dot fr>
+dnl That code is public domain and can be freely used or copied.
+
+dnl Macro that check if dlopen and dladdr functions are available or not.
+
+dnl Usage: EFL_CHECK_DLOPEN([, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
+dnl Call AC_SUBST(EFL_DLOPEN_LIBS)
+dnl Define HAVE_DLOPEN to 1if dlopen is available
+
+AC_DEFUN([EFL_CHECK_DLOPEN],
+[
+case "$host_os" in
+   mingw*)
+      _efl_have_dlopen="yes"
+      EFL_DLOPEN_LIBS="-ldl"
+      ;;
+   *)
+   _efl_have_dlopen="no"
+
+dnl Check is dlopen is in libc
+
+   AC_MSG_CHECKING([for dlopen in libc])
+   AC_LINK_IFELSE(
+      [AC_LANG_PROGRAM(
+          [[
+#include <dlfcn.h>
+          ]],
+          [[
+void *h = dlopen(0, 0);
+          ]])],
+      [_efl_have_dlopen="yes"],
+      [_efl_have_dlopen="no"])
+
+   AC_MSG_RESULT([${_efl_have_dlopen}])
+
+   if test "x${_efl_have_dlopen}" = "xno" ; then
+      AC_MSG_CHECKING([for dlopen in libdl])
+
+      LIBS_save="${LIBS}"
+      LIBS="${LIBS} -ldl"
+      AC_LINK_IFELSE(
+         [AC_LANG_PROGRAM(
+             [[
+#include <dlfcn.h>
+             ]],
+             [[
+void *h = dlopen(0, 0);
+             ]])],
+         [
+          EFL_DLOPEN_LIBS="-ldl"
+          _efl_have_dlopen="yes"
+         ],
+         [_efl_have_dlopen="no"])
+
+      LIBS="${LIBS_save}"
+
+      AC_MSG_RESULT([${_efl_have_dlopen}])
+   fi
+   ;;
+esac
+
+AC_SUBST([EFL_DLOPEN_LIBS])
+
+if test "x${_efl_have_dlopen}" = "xyes" ; then
+   AC_DEFINE([HAVE_DLOPEN], [1], [Define to 1 if you have the `dlopen' function.])
+fi
+
+AS_IF([test "x${_efl_have_dlopen}" = "xyes"], [$1], [$2])
+])
+
+dnl Usage: EFL_CHECK_DLADDR([, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
+dnl Call AC_SUBST(EFL_DLADDR_LIBS)
+dnl Define HAVE_DLADDR to 1if dladdr is available
+
+AC_DEFUN([EFL_CHECK_DLADDR],
+[
+case "$host_os" in
+   mingw*)
+      _efl_have_dladdr="yes"
+      EFL_DLADDR_LIBS="-ldl"
+      ;;
+   *)
+   _efl_have_dladdr="no"
+
+dnl Check is dladdr is in libc
+
+   AC_MSG_CHECKING([for dladdr in libc])
+   AC_LINK_IFELSE(
+      [AC_LANG_PROGRAM(
+          [[
+#define _GNU_SOURCE
+#include <dlfcn.h>
+          ]],
+          [[
+int res = dladdr(0, 0);
+          ]])],
+      [_efl_have_dladdr="yes"],
+      [_efl_have_dladdr="no"])
+
+   AC_MSG_RESULT([${_efl_have_dladdr}])
+
+   if test "x${_efl_have_dladdr}" = "xno" ; then
+      AC_MSG_CHECKING([for dladdr in libdl])
+
+      LIBS_save="${LIBS}"
+      LIBS="${LIBS} -ldl"
+      AC_LINK_IFELSE(
+         [AC_LANG_PROGRAM(
+             [[
+#define _GNU_SOURCE
+#include <dlfcn.h>
+             ]],
+             [[
+int res = dladdr(0, 0);
+             ]])],
+         [
+          EFL_DLADDR_LIBS="-ldl"
+          _efl_have_dladdr="yes"
+         ],
+         [_efl_have_dladdr="no"])
+
+      LIBS="${LIBS_save}"
+
+      AC_MSG_RESULT([${_efl_have_dladdr}])
+   fi
+   ;;
+esac
+
+AC_SUBST([EFL_DLADDR_LIBS])
+
+if test "x${_efl_have_dladdr}" = "xyes" ; then
+   AC_DEFINE([HAVE_DLADDR], [1], [Define to 1 if you have the `dladdr' function.])
+fi
+
+AS_IF([test "x${_efl_have_dladdr}" = "xyes"], [$1], [$2])
+])
index fc1ac7f..5f633a4 100644 (file)
@@ -170,7 +170,7 @@ else
 libeina_la_SOURCES = $(base_sources)
 endif
 
-libeina_la_LIBADD = @iconv_libs@ @EFL_SHM_OPEN_LIBS@ @EINA_LIBS@ @dlopen_libs@ -lm
+libeina_la_LIBADD = @iconv_libs@ @EFL_SHM_OPEN_LIBS@ @EINA_LIBS@ @EFL_DLOPEN_LIBS@ @EFL_DLADDR_LIBS@ -lm
 libeina_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @release_info@ @EFL_PTHREAD_LIBS@
 libeina_la_CFLAGS = @EINA_CFLAGS@ @EFL_PTHREAD_CFLAGS@