Make relocatable in the filesystem
It would be nice if the application could run from paths other the one defined at compile time. This would allow one to put Twinkle into Mac-style .app bundles, ROX-style .AppDir directories, and .AppImage files.
Currently we get

when we try to run Twinkle from a location other than the one that was defined at compile time:
make DESTDIR=appdir install ; find appdir/
(...)
appdir/usr/local/bin/twinkle
(...)
appdir/usr/local/share/twinkle
(...)
./appdir/usr/local/bin/twinkle
This is because an absolute path to DATADIR https://github.com/LubosD/twinkle/search?q=DATADIR gets compiled in.
It would be nicer if instead of compiling in DATADIR this would be figured out at runtime
- Based on
QStringList QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);(using theXDG_DATA_DIRSenvironment variable) - As a fallback, using
QString QCoreApplication::applicationDirPath()and constructing a path to../share/twinkle/from there
In the meantime, super crude workaround (only used duing my own development):
FreeBSD% sudo ln -s $(readlink -f appdir/usr/local/share/twinkle) /usr/local/share
FreeBSD% ./appdir/usr/local/bin/twinkle
make DESTDIR=appdir install ; find appdir/
You need to use CMAKE_INSTALL_PREFIX instead:
cmake .. -DCMAKE_INSTALL_PREFIX=appdir [...]
make install
Setting DESTDIR after the build will merely install the already-built files elsewhere, which is not what you want here. (It is useful for other purposes, just not for this one.)
- Based on
QStringList QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);(using theXDG_DATA_DIRSenvironment variable)
The Twinkle core is also used to build a non-GUI client, so it cannot depend on Qt, but I guess we could always check XDG_DATA_DIRS ourselves. But given how we still don't observe XDG_CONFIG_HOME yet, I wouldn't hold my breath over this one. :smirk:
@fbiere, what I want to achieve is that it still works after renaming or moving appdir.
I can find some crude ways involving binary patching, but a clean solution would be so much nicer. Not super urgent though.
Workaround:
sed -i'' -e 's|/usr/local|././/local|g' appdir/usr/local/bin/twinkle
echo > ./appdir/Twinkle <<\EOF
#!/bin/sh
HERE="$(dirname "$(readlink -f "${0}")")"
cd "${HERE}/usr" # https://github.com/LubosD/twinkle/issues/311
exec local/bin/twinkle "$@"
EOF
chmod +x ./appdir/Twinkle
./appdir/Twinkle
While working on something completely unrelated, I just coincidentally discovered that the GUI client has a --share option that appears to do exactly what you want.
Thanks, will try it out.
coincidentally discovered
Since we both didn't immediately discover it, this makes me wonder why it isn't the default...
Since we both didn't immediately discover it, this makes me wonder why it isn't the default...
Because it needs an actual value, such as --share appdir/usr/local/share/twinkle in your case.
I see. I can make that work for my use case, even though it's a bit less elegant than "automagic" would be. Thanks! Issue can be closed unless the project wants to keep it open.