gavinhoward / bc

An implementation of the POSIX bc calculator with GNU extensions and dc, moved away from GitHub. Finished, but well-maintained.
https://git.gavinhoward.com/gavin/bc
Other
145 stars 29 forks source link

--prefix=... is partially ignored? #53

Closed drawkula closed 2 years ago

drawkula commented 2 years ago

Testing on Debian11...

After configuring with --prefix=/tmp/bctmpdir and a successful build, make install fails:

/tmp/bc $ make install
./scripts/locale_install.sh /usr/share/locale/%L/%N bc 
mkdir: cannot create directory ‘//usr/share/locale/de_DE.utf8’: Permission denied
mkdir: cannot create directory ‘//usr/share/locale/de_DE.UTF-8’: Permission denied
ln: failed to create symbolic link '//usr/share/locale/de_DE.utf8/bc': No such file or directory
mkdir: cannot create directory ‘//usr/share/locale/en_GB.utf8’: Permission denied
ln: failed to create symbolic link '//usr/share/locale/en_GB.utf8/bc': No such file or directory
mkdir: cannot create directory ‘//usr/share/locale/en_US.utf8’: Permission denied
ln: failed to create symbolic link '//usr/share/locale/en_US.utf8/bc': No such file or directory
./scripts/safe-install.sh -Dm644 manuals/bc.1 /tmp/bctmpdir/share/man/man1/bc.1
./scripts/safe-install.sh -Dm644 manuals/dc.1 /tmp/bctmpdir/share/man/man1/dc.1
./scripts/exec-install.sh /tmp/bctmpdir/bin "" "/tmp/bc/bin"

Some paths aren't adapted to fit the --prefix=... setting, some others fit the desired prefix setting.

gavinhoward commented 2 years ago

Thank you for this report. I will look into it. Thankfully, you caught me before I made a release, which is coming soon. This will be fixed in that release, even if I have to delay it.

gavinhoward commented 2 years ago

I noticed that you are installing bc in a temp directory. Is this a holding directory for a package, which will then install bc in its true place? Or is it something eke?

I ask because locales are special (meaning, they are bad). They must be installed in one, and only one place. That place is $NLSPATH, which is actually a format string (the funny looking path after ./scripts/locale_install.sh in your pasted output), but it usually points to /usr/share/locale with separate directories for every locale and then separate files in those directories for each program.

If locales are not installed properly in $NLSPATH, they will not work. This means that locales have to ignore --prefix. It's stupid, but that's POSIX for you. (This behavior is mandated by the POSIX standard.)

So if you are trying to install bc in /tmp/bctmpdir, unfortunately, you still have to install the locale files in $NLSPATH, anyway.

If you're installing in /tmp/bctmpdir to later be installed in its proper place by a package manager, then you can use the $DESTDIR environment variable when running configure.sh. If you do this, then locales will be installed at $DESTDIR/$NLSPATH, while other files will be installed at $DESTDIR/$PREFIX/<whatever>, where $PREFIX was passed in with --prefix=$PREFIX. Once that is done, and the package is made, then when users install the package, the locales will be put into the correct $NLSPATH.

If, however, you absolutely must override the behavior of installing the locales in $NLSPATH, you can set your own $NLSPATH when running configure.sh. The %L in the format specifier will be replaced by the locale name, and the %N will be replaced by the name of the program. You probably want both of those format specifiers in there.

But I do NOT recommend this because those installed locales will not work unless your $NLSPATH is set to that same format during in normal usage, which it appears it is not based on the format string in your output above.

I hope that explains why things are the way they are. If that is the reason you are having problems, I am willing to help you figure out what would be best for you to do.

However, if you still believe there is a bug in the install behavior, I'll do my best to find it.

Please let me know; I would like to help in any way I can.

drawkula commented 2 years ago

I just repeated the build in /tmp for catching the log.

Originally I wanted to have bc/dc in an own "bonsai subtree" in /opt/gavinhoward-bc for not interfering with the default dc/bc of Debian and I typically manage /opt via an own account not being root (and not my standard user account). Had I tried this as root I easily could have overlooked the files falling out of that subtree. I think that may surprise other users in some other contexts too or will just drop the NLS files somewhere they do not even notice.

Maybe dropping them into the desired prefix too and issuing a warning is an idea?

Well, so far nobody complained (or noticed it?). Maybe I'm just the one with strange ideas...

In my case, if the NLS files are dropped into that subtree with the consequence that only english works, it would be good enough. And alternatively I can just deactivate NLS.

This issue just should be about the surprise that some paths don't respect --prefix=... and maybe about minimising surprises.

And it definitely is not urgent.

gavinhoward commented 2 years ago

I agree that the surprise is bad.

The problem with putting them into the desired prefix is that they just won't work, and then I'll get bug reports about it because I know several distros that depend on the current behavior.

I think there are two things I can do. First, I can ensure that locales are not installed if NLS is disabled. I did that. (It already did it right, thankfully.) Second, I can add warnings. I added 7 in https://github.com/gavinhoward/bc/commit/b78e8e4cfb03b1135f03426b2a4aaf848b6c4d5d.

Actually, there's a third thing I can do: I can have configure.sh output a warning to the user when the prefix does not match with $NLSPATH. That has been done in https://github.com/gavinhoward/bc/commit/6dccfebe21c62d1c043387590d23a91b8499f68c.

What else would you like me to do or think that I should do?

drawkula commented 2 years ago

Thanks! The warnings at configure-time really should help everyone.

May I add a tiny "last" (for in this issue) wish? Can the warning be reformatted to fit an 80 columns terminal? Reformatted to be slightly below 80 CpL it will not even take more lines.

gavinhoward commented 2 years ago

I meant to have 80 columns or less from the beginning. Whoops.

Is https://github.com/gavinhoward/bc/commit/7cdddb8cc53fc1c08fe52fcf7fedbf7c84800c7c at 80 columns or less?

drawkula commented 2 years ago

Without changing the indentation 77 chars are the maximal sub-80 width that fits.

*****************************************************************************

WARNING: Locales will *NOT* be installed in $PREFIX (/opt/gavinhoward-bc).

         This is because they *MUST* be installed at a fixed location to even
         work, and that fixed location is $NLSPATH ().

         This location is *outside* of $PREFIX. If you do not wish to install
         locales outside of $PREFIX, you must disable NLS with the -N or the
         --disable-nls options.

         The author apologizes for the inconvenience, but the need to install
         the locales at a fixed location is mandated by POSIX. It is not
         possible for the author to change.

*****************************************************************************
gavinhoward commented 2 years ago

Whoops. How does https://github.com/gavinhoward/bc/commit/6035d39a68e6078f578823fe407892930fe0d955 look?

drawkula commented 2 years ago

Looks good:

20220723-092628

Would it make sense not to show it when configure is run with --disable-nls?

gavinhoward commented 2 years ago

Whoops.

You are absolutely right, of course. Does https://github.com/gavinhoward/bc/commit/8d8935e44bba15e96e8db83536ba54cd1deab398 fix the issue for you?

drawkula commented 2 years ago

Perfect! Thanks!

gavinhoward commented 2 years ago

You're welcome.

Since it appears this issue has been resolved, I'm going to close it, but if you disagree, feel free to reopen it.