Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Makefile): Make bash completion honor PREFIX #155

Merged

Conversation

tokuchan
Copy link
Contributor

The current version of the build system uses pkgconfig to discover the location of the bash completion scripts. Typically, this script outputs a directory under the /usr prefix. Unfortunately, if the user chooses to override the build prefix with PREFIX, the BASHCOMPLETION variable is not also updated.

In this commit, I propose to correct this issue by simply looking for the /usr prefix and substituting it with the contents of PREFIX. I've tested this approach using my stow-based "package" collection, where I build commands with custom prefixes, and do not grant root or sudo privileges when doing so. It appears to function normally for me.

The current version of the build system uses `pkgconfig` to discover the
location of the bash completion scripts. Typically, this script outputs
a directory under the `/usr` prefix. Unfortunately, if the user chooses
to override the build prefix with PREFIX, the BASHCOMPLETION variable is
not also updated.

In this commit, I propose to correct this issue by simply looking for
the `/usr` prefix and substituting it with the contents of `PREFIX`.
I've tested this approach using my `stow`-based "package" collection,
where I build commands with custom prefixes, and do not grant root or
sudo privileges when doing so. It appears to function normally for me.
@nelhage
Copy link
Owner

nelhage commented Jan 15, 2025

Hm.

This would result in a default make install (with PREFIX=/usr/local) installing the completions into /usr/local/share/bash-completion/completions/ instead of /usr/share/bash-completion/completions/, right (assuming a vanilla system bash install)? That's a behavior change, although it's not immediately clear to me that it's correct.

In particular, we really need to make sure that we agree with bash about where we're putting files, in order for it to find them, and so "making up" paths isn't necessarily okay.

That said, reading the bash_completion documentation, I notice this:

In bash-completion >= 2.12, we search the data directory of bash-completion under the installation prefix where the target command is installed. When one can assume that the version of the target bash-completion is 2.12 or higher, the completion script can actually be installed to $PREFIX/share/bash-completion/completions/ under the same installation prefix as the target program installed under $PREFIX/bin/ or $PREFIX/sbin/.

v2.12 is new this year so that's not necessarily a safe assumption, but at least that's the direction things are moving, and also seems much more sensible behavior.

(I also see that FreeBSD already patches us to use that behavior)

I'll amend this to just use $PREFIX/share/bash-completion/completions/ unconditionally; if that fixes your problems, as well, that feels simpler and cleaner and the Approved New Way.

Per [the bash_completion documentation](https://github.com/scop/bash-completion/blob/main/README.md), this is the preferred style as of new versions. It's also generally much simpler and more consistent with other options, so let's see if we can just switch over.
@tokuchan
Copy link
Contributor Author

That should work just fine for me. Thanks!

Comment on lines +53 to +54
install -d -m 755 $(DESTDIR)$(BASHCOMPDIR) ; \
install -m 644 reptyr.bash $(DESTDIR)$(BASHCOMPDIR)/reptyr
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does $(DESTDIR) come from? I know that autoconf works with PREFIX and DESTDIR, but I didn't see an autoconf setup in your build system, just the Makefile. What happens if someone sets the DESTDIR to e.g. foobar? Does line 54 expand to install -m 644 reptyr.bash foobar/usr/local/share/bash-completions/reptyr? That seems a little odd to me.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make allows referencing undefined variables, and they'll just expand to an empty string. I just cargo-culted the existing pattern we have, which seems to match the convention recommended by GNU Make.

@nelhage nelhage merged commit e294304 into nelhage:master Jan 15, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants