Meson: localstatedir defaults to /usr/var

Created on 17 Apr 2017  Â·  11Comments  Â·  Source: mesonbuild/meson

This is discussed somewhat in #68, which correctly identifies this is the default in the GNU Coding Standards, but that this directory doesn't exist...

FHS-conforming systems appear to have a /usr/share/config.site (as documented here), to override the autoconf defaults to FHS-conforming values, if the prefix is /usr. e.g if prefix=/usr then default sysconfdir=/etc, sharedstatedir=/var and localstatedir=/var.

Then again, the current default might be right on Hurd. :smile:

(If the default is an absolute path, there's probably also a documentation issue here that the correct way to use this option in a meson.build is join_paths(get_option('prefix'), get_option('localstatedir'))) so the correct path is used if localstatedir is an absolute path or relative to prefix.)

documentation supporRFC

Most helpful comment

I think we can special-case only two directories: /usr and /usr/local since those are very commonly-used and we know what the default values should be in those cases. Anything outside of that is an edge-case that the user must handle themselves.

All 11 comments

1) The option is relative to prefix because not everyone installs into /usr by default. For instance, people install inside their home-directory for testing. Perhaps we could set the value to /var when prefix is /usr, but that seems like a surprising thing to do.

2) When specifying install_dir:, you should always use get_option('localstatedir') since the directory is relative to prefix if the value is a relative directory.

The option is relative to prefix because not everyone installs into /usr by default. For instance, people install inside their home-directory for testing. Perhaps we could set the value to /var when prefix is /usr, but that seems like a surprising thing to do.

This is what I was expecting since it's what autotools does, for me. Maybe I'm just lucky to have a config.site which does that. It's also more useful than using /usr/var, which then causes my built program to fail because that directory doesn't exist.

When specifying install_dir:, you should always use get_option('localstatedir') since the directory is relative to prefix if the value is a relative directory.

Installing files into localstatedir is possibly not done very often, I was more thinking of constructing a path in localstatedir to bake into the built program via a define etc.

/usr/var is just plain wrong. Putting variable state there goes against the purpose of /usr, as it is used on modern linux distros. Quoting https://www.freedesktop.org/software/systemd/man/file-hierarchy.html#/usr:

Usually read-only, [...]. Possibly shared between multiple hosts. This directory should not be modified by the administrator, [...]

FHS is outdated here.

Perhaps we could set the value to /var when prefix is /usr

This seems like the right thing to do. prefix=/usr → localstatedir=/var, prefix=/usr/local, localstatedir=/var/local.

Prefix is the top-level; if we want to add something like config.site so distros can change the defaults when prefix is not set, then that might work. But having the default be outside prefix and/or ignoring --prefix because of it is IMO broken. If I configure things with --prefix=$HOME/.local, that's where things should be installed.

Sure, for anything which is under /home, putting everything under --prefix is the right thing. But not if the prefix starts with /usr.

I think we can special-case only two directories: /usr and /usr/local since those are very commonly-used and we know what the default values should be in those cases. Anything outside of that is an edge-case that the user must handle themselves.

Should we do it for /usr/local? That means it could overwrite system versions of /etc and /var without being explicit.

Nothing on the system will ever write to /var/local. That exists specifically for programs installed into /usr/local.

TingPing means it would be bad to ever write to /var if prefix is /usr/local. When prefix is /usr/local the user assumes nothing is going to overwrite system packages. It would be really unexpected for meson to install files outside the prefix without warning, unless the prefix is /usr. I think you should only special-case /usr.

If it was special cased to /var/local as mentioned that would be acceptable but that just adds more exceptions to understand.

So there's actually a comment in coredata.py about this:

   # sysconfdir, localstatedir and sharedstatedir are a bit special. These defaults to ${prefix}/etc,
   # ${prefix}/var and ${prefix}/com but nobody uses that. Instead they always set it
   # manually to /etc, /var and /var/lib. This default values is thus pointless and not really used
   # but we set it to this for consistency with other systems.
   #
   # Projects installing to sysconfdir, localstatedir or sharedstatedir probably want
   # to set the following in project():
   #
   # default_options : ['sysconfdir=/etc', 'localstatedir=/var', 'sharedstatedir=/var/lib']

So I guess this _could_ be fixed by surfacing that into the documentation.

PR #2511 avoids the need to include some boilerplate in every project's meson.build by making the defaults for those options depend upon the prefix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xyproto picture xyproto  Â·  4Comments

sarum9in picture sarum9in  Â·  3Comments

Ericson2314 picture Ericson2314  Â·  4Comments

nirbheek picture nirbheek  Â·  5Comments

ignatenkobrain picture ignatenkobrain  Â·  4Comments