147.6. bsd-games-2.17
Three of the BSD games — Colossal Cave, tetris and worm
| Version | 2.17, release 2 |
| Shelf | games-board — Board, card, puzzle, chess and classic small games, whatever toolkit or desktop project they come from |
| Phase | 41_system (System), 571 of 1047 in build order |
| Licence | BSD-3-Clause |
| Homepage | https://www.polyomino.org.uk/computer/software/bsd-games/ |
| Build time | 0.2 SBU |
| Installed size | 213.7 KiB in 11 files |
| Recipe | ports/core/games-board/bsd-games/kpkgbuild |
About
bsd-games is the Linux packaging of the classic BSD games. KDOS builds three of the collection: adventure, the original Colossal Cave Adventure; tetris-bsd; and worm. All three are terminal programs, and the recipe writes a desktop entry for each.
The package’s configure is not autoconf. It is a hand-written interactive script that asks its questions on a terminal and writes the answers to config.params; when a config.params already exists it reads it first, and bsd_games_cfg_non_interactive=y makes it take every answer from there without asking. build.sh therefore writes the whole of config.params and then runs ./configure with no arguments.
Why it is in KDOS
The comment above it in script/phases/41_system/packages.d/games-board.txt:
Three of the BSD games — Colossal Cave, tetris and worm. Not hangman: it calls err(1) when it cannot open /usr/share/dict/words, and no wordlist exists anywhere on this image.
Sources
bsd-games-2.17.tar.gz(2.4 MiB)
sha256066f924aef6c1c5ea946f588e36f303021f5dfc093944738f025d8edbc6fff60
upstream: https://ibiblio.org/pub/Linux/games/bsd-games-2.17.tar.gz
archive copy: sources-2/games-board--bsd-games-2.17.tar.gz
Dependencies
Required by: no port names it.
Patches
build.sh applies these; kpkg applies nothing by itself.
adventure-linkdata-bounds.patch— Inadventure/init.c, upstream’s loop inlinkdata()runsfor (i = 1; i <= LOCSIZ; i++)overltext,travelandcond, which are arrays ofLOCSIZelements, so its last pass readsltextandtravelone element past their end and can writecondone past its end. The patch stops the loop ati < LOCSIZ.
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/41_system/phase.env && kpkg install bsd-games'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/games-board/bsd-games.
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-board/bsd-games
echo '066f924aef6c1c5ea946f588e36f303021f5dfc093944738f025d8edbc6fff60 bsd-games-2.17.tar.gz' | 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/bsd-games
SRC=$SRC_ROOT/bsd-games-2.17
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf bsd-games-2.17.tar.gz -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/adventure-linkdata-bounds.patch"
cat > config.params <<PARAMS
bsd_games_cfg_non_interactive=y
bsd_games_cfg_install_prefix="$PKG"
bsd_games_cfg_no_build_dirs=
bsd_games_cfg_build_dirs="adventure tetris worm"
bsd_games_cfg_gamesdir=/usr/games
bsd_games_cfg_man6dir=/usr/share/man/man6
bsd_games_cfg_sharedir=/usr/share/games
bsd_games_cfg_varlibdir=/var/games
bsd_games_cfg_do_chown=n
bsd_games_cfg_binary_perms=0755
bsd_games_cfg_score_game_perms=0755
bsd_games_cfg_manpage_perms=0644
bsd_games_cfg_constdata_perms=0644
bsd_games_cfg_vardata_perms=0666
bsd_games_cfg_vardata_perms_priv=0660
bsd_games_cfg_use_dot_so=.so
bsd_games_cfg_gzip_manpages=n
bsd_games_cfg_cc="$CC"
bsd_games_cfg_optimize_flags=
bsd_games_cfg_warning_flags=
bsd_games_cfg_other_cflags="$CFLAGS"
bsd_games_cfg_other_ldflags="$LDFLAGS"
bsd_games_cfg_ncurses_lib=-lncurses
bsd_games_cfg_ncurses_includes=
bsd_games_cfg_base_libs=
bsd_games_cfg_pager=/usr/bin/less
bsd_games_cfg_hangman_wordsfile=/usr/share/dict/words
bsd_games_cfg_tetris_scorefile=/var/games/tetris-bsd.scores
PARAMS
./configure
make
make install
install -d "$PKG/usr/share/applications"
cat > "$PKG/usr/share/applications/bsd-adventure.desktop" <<'ENTRY'
[Desktop Entry]
Type=Application
Name=Colossal Cave Adventure
GenericName=Text Adventure
Comment=Explore Colossal Cave and carry the treasure out
Exec=/usr/games/adventure
Icon=input-gaming
Terminal=true
Categories=Game;AdventureGame;
Keywords=adventure;text;cave;interactive;fiction;colossal;
ENTRY
cat > "$PKG/usr/share/applications/bsd-tetris.desktop" <<'ENTRY'
[Desktop Entry]
Type=Application
Name=Tetris
GenericName=Falling Blocks Game
Comment=Stack the falling shapes and clear the rows
Exec=/usr/games/tetris-bsd
Icon=input-gaming
Terminal=true
Categories=Game;BlocksGame;
Keywords=tetris;blocks;falling;puzzle;arcade;
ENTRY
cat > "$PKG/usr/share/applications/bsd-worm.desktop" <<'ENTRY'
[Desktop Entry]
Type=Application
Name=Worm
GenericName=Snake Game
Comment=Grow the worm without running into anything
Exec=/usr/games/worm
Icon=input-gaming
Terminal=true
Categories=Game;ArcadeGame;
Keywords=worm;snake;arcade;grow;
ENTRY
chmod 644 "$PKG"/usr/share/applications/bsd-*.desktop
The switches, and why each is set:
bsd_games_cfg_build_dirs— The games to build:adventure tetris worm, and none of the others in the collection.hangmanis left out because it opens/usr/share/dict/wordsat start and exits througherr(1)when it cannot, and no port installs a word list.bsd_games_cfg_other_cflags,bsd_games_cfg_other_ldflags— Carry the tree’sCFLAGSandLDFLAGSinto the build.MakeconfigassignsCFLAGS := $(OPTIMIZE) $(WARNING) @other_cflags@andLDFLAGS := @other_ldflags@with:=, discarding whatever the environment exported, so the tree’s flags (the prefix maps and build ID that keep a package the same bytes on every build among them) reach the compiler only through these two answers.bsd_games_cfg_optimize_flagsandbsd_games_cfg_warning_flagsare left empty, so thatconfigure’s own defaults (-g -O2and a list of-Wwarnings) are not added before them.bsd_games_cfg_install_prefix— Install under$PKG, the package’s staging root, instead of the running system.bsd_games_cfg_do_chown—n: do not change the owner or group of what is installed. The install runs into$PKG, and the games are not installed setgid.bsd_games_cfg_vardata_perms—0666for the files under/var/games, which is the tetris score file. tetris opens it read-write at the end of every game and exits througherr(1)when it cannot, so a score file the player cannot write ends the program the first time a game is over. Upstream’sSECURITYfile gives two ways for a game to update a system-wide score file: a setgid binary, or a world-writable file. The binaries here are installed0755with no setgid bit, so the score file is the one that is writable, and it is the only writable file in the package.bsd_games_cfg_tetris_scorefile— Keep the score file at/var/games/tetris-bsd.scores.bsd_games_cfg_ncurses_lib— Link the games against-lncurses, the ncurses port’s library.bsd_games_cfg_gzip_manpages—n: install the manual pages uncompressed.
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/bsd-games, 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 bsd-games-2.17-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/bsd-games, and runs the triggers its paths call for.
Contents
Installed directories: /usr/games, /usr/share/licenses/bsd-games, /var/games.
Notes
libbsd is in depends although nothing links it. Every source file includes bsd-games’ own include/sys/cdefs.h, which is a wrapper that does #include_next <sys/cdefs.h>, so a system header of that name has to exist. musl installs none; on KDOS it is the copy the libbsd port installs into /usr/include/sys.