From 6ae9bb615f7a28b3742b18e4e79bb3d1711e3bd3 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Wed, 15 Feb 2017 16:02:32 +0100 Subject: [PATCH 1/2] build: Optionally create relocatable dbus-1.pc file Relocatable pkgconfig files are necessary when using packages installed to a location that does not match the location for which they were compiled. However, using ${pcfiledir} is problematic for system installations in standard locations, because it interferes with pkg-config's ability to filter out -I, -L options that are redundant with compiler defaults (which is important if you are trying to use a newer version of a library than the system copy). So make relocation optional, and switch it off by default when using Autotools (as distribution vendors do in practice) and compiling for a Unix platform. For simplicity, we're also not relocatable if libdir (autotools) or CMAKE_INSTALL_LIBDIR (cmake) is something more complicated (e.g. Debian multiarch); we don't want to have to compute how many ../ to add. [smcv: don't be relocatable by default on Unix + Autotools] Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99721 --- cmake/CMakeLists.txt | 32 +++++++++++++++++++++++++------- configure.ac | 19 +++++++++++++++++++ dbus-1.pc.in | 2 +- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 5eb9ed3a..b484e96e 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -84,6 +84,17 @@ set(SYSCONFDIR_FROM_PKGDATADIR ${CMAKE_INSTALL_FULL_SYSCONFDIR}) set(DATADIR_FROM_PKGSYSCONFDIR ${CMAKE_INSTALL_FULL_DATADIR}) endif() +# For simplicity, we're not relocatable if CMAKE_INSTALL_LIBDIR +# is something more complicated (e.g. Debian multiarch); +# we don't want to have to compute how many ../ to add +if(CMAKE_INSTALL_LIBDIR STREQUAL "lib" OR CMAKE_INSTALL_LIBDIR STREQUAL "lib64") + # we know we can use ../ to get to the prefix + set(DBUS_RELOCATABLE 1) +else() + # sorry, it's too hard to make this particular build relocatable + set(DBUS_RELOCATABLE 0) +endif() + # used in the C code set(DBUS_LIBEXECDIR ${CMAKE_INSTALL_FULL_LIBEXECDIR}) set(DBUS_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}) @@ -638,13 +649,20 @@ if(UNIX) foreach(LIB ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS}) set(LIBDBUS_LIBS "${LIBDBUS_LIBS} -l${LIB}") endforeach() - set(bindir ${EXPANDED_BINDIR}) - set(libdir ${EXPANDED_LIBDIR}) - set(includedir ${EXPANDED_INCLUDEDIR}) - set(sysconfdir ${EXPANDED_SYSCONFDIR}) - set(datadir ${EXPANDED_DATADIR}) - set(datarootdir ${EXPANDED_DATADIR}) - set(dbus_daemondir ${DBUS_DAEMONDIR}) + if(DBUS_RELOCATABLE) + set(pkgconfig_prefix "\${pcfiledir}/../../") + else() + message("Unusual CMAKE_INSTALL_PREFIX: the generated package will not be relocatable.") + set(pkgconfig_prefix "${CMAKE_INSTALL_PREFIX}") + endif() + set(exec_prefix "\${prefix}") + set(bindir "\${prefix}/${CMAKE_INSTALL_BINDIR}") + set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") + set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") + set(sysconfdir "\${prefix}/${CMAKE_INSTALL_SYSCONFDIR}") + set(datadir "\${prefix}/${CMAKE_INSTALL_DATADIR}") + set(datarootdir "\${prefix}/${CMAKE_INSTALL_DATADIR}") + set(dbus_daemondir "\${prefix}/${CMAKE_INSTALL_BINDIR}") configure_file(../dbus-1.pc.in ${CMAKE_BINARY_DIR}/dbus-1.pc @ONLY) install(FILES ${CMAKE_BINARY_DIR}/dbus-1.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endif() diff --git a/configure.ac b/configure.ac index 00c271cb..c3a8c85e 100644 --- a/configure.ac +++ b/configure.ac @@ -1530,6 +1530,25 @@ AS_AC_EXPAND(EXPANDED_LIBDIR, "$libdir") AS_AC_EXPAND(EXPANDED_LIBEXECDIR, "$libexecdir") AS_AC_EXPAND(EXPANDED_DATADIR, "$datadir") +AC_ARG_ENABLE([relocation], + [AS_HELP_STRING([--enable-relocation], + [make pkg-config metadata relocatable [default: only on Windows]])], + [], [enable_relocation="$dbus_win"]) + +AS_IF([test "x$enable_relocation" = xyes], + [ + AS_IF([test "x$EXPANDED_LIBDIR" = "x$EXPANDED_PREFIX/lib" || + test "x$EXPANDED_LIBDIR" = "x$EXPANDED_PREFIX/lib64"], + [], + [AC_MSG_ERROR([Your libdir is too complicated to be relocatable, use \${prefix}/lib instead])]) + + pkgconfig_prefix='${pcfiledir}/../..' + ], + [ + pkgconfig_prefix='${prefix}' + ]) +AC_SUBST([pkgconfig_prefix]) + #### Check our operating system operating_system=unknown if test -f /etc/redhat-release || test -f $EXPANDED_SYSCONFDIR/redhat-release ; then diff --git a/dbus-1.pc.in b/dbus-1.pc.in index f93d1563..26fc9709 100644 --- a/dbus-1.pc.in +++ b/dbus-1.pc.in @@ -1,4 +1,4 @@ -prefix=@prefix@ +prefix=@pkgconfig_prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ libdir=@libdir@ -- 2.11.0