make install: Run ldconfig or install a DT_RUNPATH in binary as appropriate.

Various users were confused as to why they couldn't run notmuch
immediately after "make install", (with linker errors saying that
libnotmuch.so could not be found). The errors came from two different
causes:

1. The user had installed to a system library directory, but had not
   yet run ldconfig.

2. The user had installed to some non-system directory, and had not
   set the LD_LIBRARY_PATH variable.

With this change we fix both problems (on Linux) without the user
having to do anything additional. We first use ldconfig to find the
system library directories. If the user is installing to one of these,
then we run ldconfig as part of "make install".

For case (2) we use the -rpath and --enable-new-dtags linker options
to install a DT_RUNPATH entry in the binary. This entry tells the
dynamic linker where to find libnotmuch. Without the
--enable-new-dtags option only a DT_RPATH option would be installed,
(which has the drawback of not allowing any override with the
LD_LIBRARY_PATH variable).

Distributions (such as Debian and Fedora) don't want to see binaries
packaged with a DT_RPATH or DT_RUNPATH entry. This should be avoided
automatically as long as the packages install to standard locations,
(such as /usr/lib).
This commit is contained in:
Carl Worth 2010-06-04 16:52:56 -07:00
parent b3076ed269
commit d64d0cc8d9
3 changed files with 31 additions and 0 deletions

View file

@ -37,6 +37,11 @@ ifneq ($(LINKER_RESOLVES_LIBRARY_DEPENDENCIES),1)
FINAL_NOTMUCH_LDFLAGS += $(CONFIGURE_LDFLAGS)
FINAL_NOTMUCH_LINKER = CXX
endif
ifeq ($(PLATFORM),LINUX)
ifeq ($(LIBDIR_IN_LDCONFIG),0)
FINAL_NOTMUCH_LDFLAGS += -Wl,--enable-new-dtags -Wl,-rpath,$(libdir)
endif
endif
FINAL_LIBNOTMUCH_LDFLAGS = $(LDFLAGS) $(CONFIGURE_LDFLAGS)
.PHONY: all

22
configure vendored
View file

@ -167,6 +167,12 @@ for option; do
fi
done
# We set this value early, (rather than just while printing the
# Makefile.config file later like most values), because we need to
# actually investigate this value compared to the ldconfig_paths value
# below.
libdir_expanded=${LIBDIR:-${PREFIX}/lib}
cat <<EOF
Welcome to Notmuch, a system for indexing, searching and tagging your email.
@ -266,6 +272,8 @@ else
have_emacs=0
fi
libdir_in_ldconfig=0
printf "Checking which platform we are on... "
if [ `uname` = "Darwin" ] ; then
printf "Mac OS X.\n"
@ -279,6 +287,13 @@ elif [ `uname` = "Linux" ] ; then
printf "Linux\n"
platform=LINUX
linker_resolves_library_dependencies=1
ldconfig_paths=$(/sbin/ldconfig -N -X -v 2>/dev/null | sed -n -e 's,^\(/.*\):\( (.*)\)\?$,\1,p')
for path in $ldconfig_paths; do
echo "Checking $path compared to $libdir_expanded"
if [ "$path" = "$libdir_expanded" ]; then
libdir_in_ldconfig=1
fi
done
else
printf "Unknown.\n"
cat <<EOF
@ -419,11 +434,18 @@ WARN_CXXFLAGS=-Wall -Wextra -Wwrite-strings -Wswitch-enum
WARN_CFLAGS=\$(WARN_CXXFLAGS) -Wmissing-declarations
# The prefix to which notmuch should be installed
# Note: If you change this value here, be sure to ensure that the
# LIBDIR_IN_LDCONFIG value below is still set correctly.
prefix = ${PREFIX}
# The directory to which libraries should be installed
# Note: If you change this value here, be sure to ensure that the
# LIBDIR_IN_LDCONFIG value below is still set correctly.
libdir = ${LIBDIR:=\$(prefix)/lib}
# Whether libdir is in a path configured into ldconfig
LIBDIR_IN_LDCONFIG = ${libdir_in_ldconfig}
# The directory to which header files should be installed
includedir = ${INCLUDEDIR:=\$(prefix)/include}

View file

@ -35,6 +35,9 @@ LINKER_NAME = libnotmuch.$(LIBRARY_SUFFIX)
SONAME = $(LINKER_NAME).$(LIBNOTMUCH_VERSION_MAJOR)
LIBNAME = $(SONAME).$(LIBNOTMUCH_VERSION_MINOR).$(LIBNOTMUCH_VERSION_RELEASE)
LIBRARY_LINK_FLAG = -shared -Wl,-soname=$(SONAME)
ifeq ($(LIBDIR_IN_LDCONFIG),1)
LIBRARY_INSTALL_POST_COMMAND=ldconfig
endif
endif
dir := lib
@ -80,6 +83,7 @@ install-$(dir):
ln -sf $(LIBNAME) $(DESTDIR)$(libdir)/$(LINKER_NAME)
mkdir -p $(DESTDIR)$(includedir)
install -m0644 $(dir)/notmuch.h $(DESTDIR)$(includedir)/
$(LIBRARY_INSTALL_POST_COMMAND)
SRCS := $(SRCS) $(libnotmuch_c_srcs) $(libnotmuch_cxx_srcs)
CLEAN := $(CLEAN) $(libnotmuch_modules) $(dir)/$(SONAME) $(dir)/$(LINKER_NAME) $(dir)$(LIBNAME) libnotmuch.a