In general, autotooled packages are supposed to allow './configure --prefix=$HOME/subdir' as a way to then get 'make install' to run as non-root. In fact, 'make distcheck' tests that this scenario works; alas, we fail due to: /usr/bin/install -c -m 644 ../../../bash/nbdkit '/usr/share/bash-completion/completions' /usr/bin/install: cannot remove '/usr/share/bash-completion/completions/nbdkit': Permission denied The culprit? We use pkg-config to ask bash-completion where it would install user completion scripts. bash-completion.pc states: prefix=/usr completionsdir=${prefix}/share/bash-completion/completions but pkg-config --variable defaults to flattening the ${prefix} in our use of the PKG_CHECK_VAR() macro, which in turn means that './configure --prefix=$HOME/subdir' still uses an absolute path pointing to a root-owned directory (rather than one relative to our desired ${prefix}) in our definition of bashcompsdir. The solution? Tell pkg-config to NOT flatten the prefix variable. Signed-off-by: Eric Blake <eblake@redhat.com> --- I'm posting this one for review, particularly since it means someone running 'make install' with a non-root --prefix will now be stuck with bash completion libraries that won't be loaded by default (the user will have to probably edit their ~/.bashrc to load things), but that still seems better than the alternative of failing to install because the installation wants to override root-owned files in spite of the non-root --prefix. 'make distcheck' still doesn't pass for me; the next failure is due to attempts to overwrite root-owned ocaml files. Similar symptoms as what this patch addressed for bashcompsdir, but there we aren't using pkg-config --variable. Instaed, our definition of ocamllibdir (based on ${OCAMLLIB} in m4/ocaml.m4) is coming from 'ocamlc -where', and I have no idea how to coerce that to print a relative pathname, or even if it is common to have ocaml libraries installed in a non-root home directory but which can still be picked up by ocaml at runtime. configure.ac | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 33ed4d5..8c97ffb 100644 --- a/configure.ac +++ b/configure.ac @@ -337,7 +337,15 @@ PKG_CHECK_MODULES([BASH_COMPLETION], [bash-completion >= 2.0], [ bash_completion=yes AC_MSG_CHECKING([for bash-completions directory]) m4_ifdef([PKG_CHECK_VAR],[ - PKG_CHECK_VAR(bashcompdir, [bash-completion], [completionsdir]) + dnl PKG_CHECK_VAR(bashcompdir, [bash-completion], [completionsdir]) + dnl Unfortunately, PKG_CHECK_VAR flattens references to ${prefix}, + dnl which in turn means './configure --prefix=...' to a location + dnl writable by non-root still fails when it comes to installing + dnl the bash completions. + dnl So here, we just run the same command as the macro would, but + dnl with an override for prefix to keep 'make distcheck' happy. + bashcompdir=`$PKG_CONFIG --define-variable=prefix='${prefix}' \ + --variable=completionsdir bash-completion 2>/dev/null` ]) AS_IF([test -z "$bashcompdir"], [ bashcompdir="${sysconfdir}/bash_completion.d" -- 2.17.2