From 61697e092a1c9bd43d6cc92046550af7f53bce3f Mon Sep 17 00:00:00 2001 From: Chip Davis Date: Tue, 21 Aug 2018 18:08:04 +0200 Subject: [PATCH] build: Detect soname of libvulkan at configure time. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- configure.ac | 6 ++--- libs/vkd3d/device.c | 4 ++-- m4/check-soname.m4 | 54 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 m4/check-soname.m4 diff --git a/configure.ac b/configure.ac index b5123b8d..90557ee4 100644 --- a/configure.ac +++ b/configure.ac @@ -77,9 +77,9 @@ AC_CHECK_LIB([pthread], [pthread_create], [AC_MSG_ERROR([libpthread not found.])]) AC_SUBST([VULKAN_LIBS]) -AC_CHECK_LIB([vulkan], [vkGetInstanceProcAddr], - [VULKAN_LIBS="-lvulkan"], - [AC_MSG_ERROR([libvulkan not found.])]) +VKD3D_CHECK_SONAME([vulkan], [vkGetInstanceProcAddr], + [VULKAN_LIBS="-lvulkan"], + [AC_MSG_ERROR([libvulkan not found.])]) AS_IF([test "x$with_spirv_tools" = "xyes"], [PKG_CHECK_MODULES([SPIRV_TOOLS], [SPIRV-Tools-shared], diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 8280fd5d..c11f474a 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -283,9 +283,9 @@ static HRESULT vkd3d_init_vk_global_procs(struct vkd3d_instance *instance, if (!vkGetInstanceProcAddr) { - if (!(instance->libvulkan = dlopen("libvulkan.so.1", RTLD_NOW))) + if (!(instance->libvulkan = dlopen(SONAME_LIBVULKAN, RTLD_NOW))) { - ERR("Failed to load libvulkan.\n"); + ERR("Failed to load libvulkan: %s.\n", dlerror()); return E_FAIL; } diff --git a/m4/check-soname.m4 b/m4/check-soname.m4 new file mode 100644 index 00000000..f1953413 --- /dev/null +++ b/m4/check-soname.m4 @@ -0,0 +1,54 @@ +dnl +dnl Copyright 2002 Alexandre Julliard +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License, or (at your option) any later version. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library; if not, write to the Free Software +dnl Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA +dnl +dnl As a special exception to the GNU Lesser General Public License, +dnl if you distribute this file as part of a program that contains a +dnl configuration script generated by Autoconf, you may include it +dnl under the same distribution terms that you use for the rest of +dnl that program. + +dnl VKD3D_PATH_SONAME_TOOLS +AC_DEFUN([VKD3D_PATH_SONAME_TOOLS], +[AC_PATH_PROG(LDD,ldd,true,/sbin:/usr/sbin:$PATH) +AC_CHECK_TOOL(OTOOL,otool,otool) +AC_CHECK_TOOL(READELF,[readelf],true)]) + +dnl VKD3D_CHECK_SONAME(library, function, [action-if-found, [action-if-not-found, [other_libraries, [pattern]]]]) +AC_DEFUN([VKD3D_CHECK_SONAME], +[AC_REQUIRE([VKD3D_PATH_SONAME_TOOLS])dnl +AS_VAR_PUSHDEF([ac_Lib],[ac_cv_lib_soname_$1])dnl +m4_pushdef([ac_lib_pattern],m4_default([$6],[lib$1]))dnl +AC_MSG_CHECKING([for -l$1]) +AC_CACHE_VAL(ac_Lib, +[ac_check_soname_save_LIBS=$LIBS + LIBS="-l$1 $5 $LIBS" + AC_LINK_IFELSE([AC_LANG_CALL([], [$2])], + [AS_CASE(["$host_os"], + [darwin*|macosx*], [AS_VAR_SET(ac_Lib,[`$OTOOL -L conftest$ac_exeext | grep "]ac_lib_pattern[\\.[[0-9A-Za-z.]]*dylib" | sed -e "s/^.*\/\(]ac_lib_pattern[\.[[0-9A-Za-z.]]*dylib\).*$/\1/"';2,$d'`])], + [AS_VAR_SET(ac_Lib,[`$READELF -d conftest$ac_exeext | grep "NEEDED.*]ac_lib_pattern[" | sed -e "s/^.*\\m4_dquote(\\(]ac_lib_pattern[[[^ ]]*\\)\\).*$/\1/"';2,$d'`]) + AS_VAR_IF([ac_Lib],[], + [AS_VAR_SET(ac_Lib,[`$LDD conftest$ac_exeext | grep "]ac_lib_pattern[" | sed -e "s/^.*\(]ac_lib_pattern[[[^ ]]*\).*$/\1/"';2,$d'`])])])]) + LIBS=$ac_check_soname_save_LIBS])dnl +AS_VAR_IF([ac_Lib],[], + [AC_MSG_RESULT([not found]) + $4], + [AC_MSG_RESULT(AS_VAR_GET(ac_Lib)) + AC_DEFINE_UNQUOTED(AS_TR_CPP(SONAME_LIB$1),["]AS_VAR_GET(ac_Lib)["], + [Define to the soname of the lib$1 library.]) + $3])dnl +m4_popdef([ac_lib_pattern])dnl +AS_VAR_POPDEF([ac_Lib])])