325.1. openttd-15.3
Transport Tycoon Deluxe engine — build rail, road, air and sea networks
| Version | 15.3, release 2 |
| Shelf | games-strategy — Strategy, simulation and space-trading games, and their data |
| Phase | 44_apps (Applications), 201 of 422 in build order |
| Licence | GPL-2.0-only |
| Homepage | https://www.openttd.org/ |
| Build time | 27.8 SBU |
| Installed size | 22.7 MiB in 92 files |
| Recipe | ports/core/games-strategy/openttd/kpkgbuild |
About
OpenTTD is an open-source engine for Transport Tycoon Deluxe: the player builds rail, road, air and sea networks and runs a transport company over a century of play, alone, against AI companies or with others over the network. The engine needs base sets of graphics, sounds and music to start; the free ones are the openttd-opengfx, openttd-opensfx and openttd-openmsx ports in depends, so the game runs without the original game’s files.
Sources
openttd-15.3.tar.xz(8.1 MiB)
sha2565ea21eea7d59c78a42071924ac18c6bc0116088f2e96b14cfee9369175973be7
upstream: https://cdn.openttd.org/openttd-releases/15.3/openttd-15.3-source.tar.xz
archive copy: sources-2/games-strategy--openttd-15.3.tar.xz
Dependencies
Depends on: cmake, ninja, pkgconf, sdl2-compat, mesa, libglvnd, freetype2, fontconfig, harfbuzz, icu, fluidsynth, opusfile, libpng, zlib, xz, lzo, curl, openttd-opengfx, openttd-opensfx, openttd-openmsx.
Required by: no port names it.
Patches
build.sh applies these; kpkg applies nothing by itself.
fix-segfault.patch— From upstream pull request 15962. Insrc/gfx_layout_icu.cpp, keeps theicu::UnicodeStringhanded to the ICU line-break iterator in a named variable instead of a temporary. The iterator keeps a reference to the text, and a temporary is destroyed at the end of the statement, before the iterator reads it, so laying out a line that needs breaking could crash.musl-getrandom.patch— Insrc/core/random_func.cpp, takesgetrandom()from<sys/random.h>on any Linux, rather than only when__GLIBC__says glibc 2.25 or later. musl defines no__GLIBC__, so unpatched the game falls back to its own non-cryptographic random generator and warns that no strong one is available.no-survey.patch— Insrc/network/network_survey.h, makesIsSurveyPossible()returnfalse. That removes the opt-in usage survey, its settings button and the question about it the first time the main menu opens, so the program never offers to send a survey report.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/44_apps/phase.env && kpkg install openttd'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/games-strategy/openttd.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/games-strategy/openttd
echo '5ea21eea7d59c78a42071924ac18c6bc0116088f2e96b14cfee9369175973be7 openttd-15.3.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/openttd
SRC=$SRC_ROOT/openttd-15.3
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf openttd-15.3.tar.xz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
patch -p1 -i "$PORT_SRC/fix-segfault.patch"
patch -p1 -i "$PORT_SRC/no-survey.patch"
patch -p1 -i "$PORT_SRC/musl-getrandom.patch"
cmake -S . -B build -G Ninja \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_INSTALL_BINDIR=bin \
-DCMAKE_INSTALL_DATADIR=share/games \
-DOPTION_INSTALL_FHS=ON \
-DOPTION_DEDICATED=OFF \
-DOPTION_USE_ASSERTS=OFF \
-DCMAKE_DISABLE_FIND_PACKAGE_Allegro=ON \
-DCMAKE_DISABLE_FIND_PACKAGE_unofficial-breakpad=ON \
-DCMAKE_DISABLE_FIND_PACKAGE_Grfcodec=ON \
-DCMAKE_DISABLE_FIND_PACKAGE_Doxygen=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_SDL2=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_Freetype=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_Fontconfig=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_Harfbuzz=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_ICU=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_Fluidsynth=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_OpusFile=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_PNG=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_ZLIB=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_LibLZMA=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_LZO=ON \
-DCURL_NO_CURL_CMAKE=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_CURL=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_OpenGL=ON \
-DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS -Wl,-z,stack-size=1048576"
cmake --build build
DESTDIR=$PKG cmake --install build
find "$PKG/usr/share/games/openttd/lang" -name '*.lng' ! -name 'english*.lng' -delete
cat > "$PKG/usr/share/applications/openttd.desktop" <<'DESKTOP'
[Desktop Entry]
Type=Application
Name=OpenTTD
GenericName=Transport Simulation
Comment=Build rail, road, air and sea transport networks
Exec=openttd
Icon=openttd
Terminal=false
StartupWMClass=openttd
Categories=Game;Simulation;
Keywords=game;simulation;transport;tycoon;deluxe;economics;train;ship;bus;truck;aircraft;cargo;
DESKTOP
chmod 644 "$PKG/usr/share/applications/openttd.desktop"
The switches, and why each is set:
-DCMAKE_INSTALL_BINDIR=bin— installopenttdinto/usr/bin. Upstream sets its own default,games, which would put it in/usr/games.-DCMAKE_INSTALL_DATADIR=share/games— with-DOPTION_INSTALL_FHS=ON: the FHS layout, with the data in/usr/share/games/openttd, where the base-set ports install.share/gamesis upstream’s own default and FHS is its default on Linux; both are named.-DOPTION_DEDICATED=OFF— build the game with its interface, not a dedicated server only. Upstream’s default, named.-DOPTION_USE_ASSERTS=OFF— no assertions, as upstream recommends for a stable release. Its default, named.-DCMAKE_DISABLE_FIND_PACKAGE_Allegro=ON— with the same switch forunofficial-breakpad,GrfcodecandDoxygen: never look for these four. Allegro is an alternative video and sound backend; Breakpad is a crash reporter; grfcodec and nforenum would rebuild the engine’s ownopenttd.grfandorig_extra.grffrom their sources instead of using the prebuilt ones in the release; and Doxygen adds a target for the source documentation. None of the first three is a port, and the switches keep the build from changing when one appears in the build root.-DCMAKE_REQUIRE_FIND_PACKAGE_SDL2=ON— and the same switch forFreetype,Fontconfig,Harfbuzz,ICU,Fluidsynth,OpusFile,PNG,ZLIB,LibLZMA,LZO,CURLandOpenGL: make each of those lookups required. Upstream looks for every one of them as optional and builds without the feature when it is missing: the SDL2 video driver, scalable fonts and their lookup, text shaping and line breaking for complex scripts, MIDI music through fluidsynth, Opus sound files, PNG screenshots and heightmaps, the zlib, LZMA and LZO save-game formats, HTTP for downloads from the online content service, and OpenGL drawing.-DCURL_NO_CURL_CMAKE=ON— keep CMake’s FindCURL from first looking for aCURLConfig.cmake, which the tree’s curl does not install; with the lookup required, that search would itself fail the configure (see A graphical application).-DCMAKE_EXE_LINKER_FLAGS— the tree’sLDFLAGSplus-Wl,-z,stack-size=1048576. musl gives a new thread 128 KiB of stack unless the executable asks for more, and OpenTTD runs its game loop, with the pathfinders and the AI and game scripts, on a thread of its own (ottd:game), which needs more than that; the linker flag records a 1 MiB request in the program.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/openttd, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf openttd-15.3-2.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/openttd, and runs the triggers its paths call for.
Contents
Installed programs: openttd.
Installed directories: /usr/share/doc/openttd, /usr/share/games/openttd/ai, /usr/share/games/openttd/game, /usr/share/games/openttd/lang, /usr/share/games/openttd/scripts, /usr/share/licenses/openttd.
Short descriptions
openttd |
open source clone of the Microprose game "Transport Tycoon Deluxe" |
Notes
build.sh deletes every language file under /usr/share/games/openttd/lang except the English ones. OpenTTD’s .lng files are its translations, which kpkg’s language prune does not recognise. The in-game list then offers English alone, and a configuration that names another language falls back to English.
Upstream’s desktop entry carries no window class, so build.sh writes its own over it with StartupWMClass=openttd, the window’s Wayland app id, which is the program’s name.