I understand the advantages, but it doesn't seem to be as well supported. As you said, the default PATH often doesn't contain a user-specific directory. I made some lame attempts many years ago to see if I would work for my own software but the binaries were not found by default and the .desktop files were not picked up.
Many programs doesn't really need to be "installed" which I guess is why you can put them on a thumb-drive as you said. Instead of running
make
followed by
make install
you only run
make
and start running the program from where the executable is located (unless you create your own shortcuts manually). If the program has data files that are required to run then the program would need to search for the necessarily data files relative to the location of the executable file for this to work.
Makefiles often have variables (e.g. PREFIX) to configure where to install the files. This allows the user to do a "local install" pretty easily, assuming the PATH etc. has been set up for it to work correctly.
make install PREFIX=/home/user |
I don't know if it's worth trying to read the XDG variables in the makefile. I think most build scripts just defaults to /usr/local (even when using ./configure by GNU Autotools).
XDG_DATA_DIRS can contain many paths so it's not even clear which one to choose for installation. I think these variables are mostly intended for the program itself and not for the build scripts because that is up to who is building to decide. When I said I would "
follow the XDG Base Directory Specification no matter what SDL says" I mainly meant that I would not use SDL as the source of truth but instead do something that is compatible with the XDG specification even if that means the user needs to explicitly set the path when installing.
Forgive me if I make things more complicated than they really are, but to me it's not clear from the XDG specification how XDG_DATA_HOME should be handled exactly.
In the past I have treated XDG_DATA_HOME the same as the XDG_DATA_DIRS, with highest priority, and simply used it to look for static data files that the program used. It's a game so we're talking things like fonts and graphics.
XDG Base Directory Specification wrote: |
---|
$XDG_DATA_DIRS defines the preference-ordered set of base directories to search for data files in addition to the $XDG_DATA_HOME base directory. |
XDG Base Directory Specification wrote: |
---|
The order of base directories denotes their importance; the first directory listed is the most important. When the same information is defined in multiple places the information defined relative to the more important base directory takes precedent. The base directory defined by $XDG_DATA_HOME is considered more important than any of the base directories defined by $XDG_DATA_DIRS. |
I used XDG_CONFIG_HOME for all files that the program created (settings, replays and highscores) but I'm thinking now that maybe it would have been more correct to only use XDG_CONFIG_HOME for the settings and instead used XDG_DATA_HOME for the other program-generated files?
XDG Base Directory Specification wrote: |
---|
There is a single base directory relative to which user-specific configuration files should be written. This directory is defined by the environment variable $XDG_CONFIG_HOME. |
XDG Base Directory Specification wrote: |
---|
There is a single base directory relative to which user-specific data files should be written. This directory is defined by the environment variable $XDG_DATA_HOME. |
But does this mean that XDG_DATA_HOME should be used both for searching for static data files (that normally doesn't change after installation) AND for writing various data files that are created by the program (high scores, saved games, etc.)? My concern here is that it would require the uninstall target of the makefile to be much more complicated (normally I just remove all files in the game's install data dir but I don't necessarily want it to remove saved games and such). It would also make it more cumbersome for the user to make backups of only the relevant data.
I know the degree to which this specification is followed varies quite a lot. Some projects keep doing how they always have done because they don't want to break backwards compatibility. But I have a suspicion that many projects simply treat XDG_DATA_HOME and XDG_DATA_DIRS differently (i.e. write files to XDG_DATA_HOME and read static data files from XDG_DATA_DIRS) but I would have to do more research to know if this is true.