Miscellaneous Wesnoth loading tricks on Linux

People using development versions or SVN trunk might find it excessively cumbersome to install Wesnoth’s binaries and data files whenever a new version is released (or commit made, for trunk). Since long ago (probably 1.3.x) Wesnoth supports overriding the data directory by providing its path as the last command line argument and, since 1.9.0, it’s also possible to use to use the --data-dir switch to avoid ambiguity with other switches taking path arguments.

Since version 1.5.4 (more specifically, r28934), Wesnoth will also try to locate a usable data directory by itself, by trying to locate data/_main.cfg in the parent dir of the executable file, which is resolved in Linux by making use of the /proc/self/exe symbolic link.

Until today, it had not occurred to me that this makes it possible to link to the Wesnoth binary from any directory, not just one containing the aforementioned WML file. The /proc/self/exe link points towards the final target if the process image is a symbolic link, so you can have a layout like this work as desired provided ~/bin is in PATH:

shadowm@reicore:~$ ls -l bin/wesnoth*
lrwxrwxrwx 1 shadowm shadowm 33 Dec 10 21:09 bin/wesnoth ->; /home/shadowm/src/wesnoth/wesnoth
lrwxrwxrwx 1 shadowm shadowm 37 Dec 10 21:10 bin/wesnoth-1.8 -> /home/shadowm/src/wesnoth-1.8/wesnoth
lrwxrwxrwx 1 shadowm shadowm 40 Dec 10 21:10 bin/wesnoth-1.9.12 -> /home/shadowm/src/wesnoth-1.9.12/wesnoth

The Wesnoth 1.8 binary in this case is compiled with the scons prefsdir option set to .wesnoth-1.8 so conflicts with the development versions can’t occur — those use the custom .wesnoth-1.9 dir instead. Nowadays things seem to be a little more complicated in that regard, as seemingly the game will opt for an XDG layout if there’s no compiled-in preferences dir path on non-Mac, non-Windows builds. According to the EditingWesnoth article on the wiki, 1.8 builds default to .wesnoth1.8. Why the default doesn’t include a hyphen is beyond me.

With things set up like this, I can start Wesnoth from any directory without having to provide my own command line arguments. Of course, you could say this is a rather archaic approach as it’s also possible to create desktop/panel shortcuts instead, depending on the desktop environment. Since I spend more time looking at a terminal emulator with my hands on the keyboard than staring at the wallpaper and desktop icons with the mouse in hand, my own approach turns out to be more efficient for my purposes.

Finally, there’s an even less known feature introduced in r31261 (before 1.5.7) that also makes it possible to omit the --editor or -e switch to start the map editor if the game executable file contains “editor” in its name. This was added as a replacement for the old wesnoth_editor binary that provided the map editor before it was replaced with the built-in version (“editor2”) as part of GSoC 2008.