Files
makronix/tools/mcde-debian.sh
T

377 lines
17 KiB
Bash
Executable File

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# mcde-debian.sh -- MCDE as a Debian package, with its own Motif in it
#
# usage: tools/mcde-debian.sh [build|install|clean]
# (make debian, make debian-install)
#
# Konrad asked for this (2026-11-22): "i want mcde to support 'make debian' and
# it'll fully create and download all required build dependencies ... and make
# debian-install would make the deb and all and then even install", and then
# "inkluding our own motif stuff xyz".
#
# It does not use debian/ of the imported CDE tree: that one calls
# admin/IntegTools/dbTools/installCDE with sudo inside the build, and the fork
# does not have that helper any more. This builds the desktop the way
# tools/mcde-host.sh builds it (/usr/mdt, configuration /etc/mdt), installs it
# into a stage with DESTDIR, and packs what is in the stage:
#
# build the build dependencies (BUILD_DEPS) are installed with apt-get(8)
# through sudo(8); the working tree of ext/src/mcde (without pkgsrc/)
# is copied to build/mcde-debian, autogen.sh and configure run when
# configure.ac or a Makefile.am changed, then make, make install
# DESTDIR=build/mcde-debian-stage, and the stage becomes
# build/mcde-debian/mcde_<version>_<arch>.deb. The package carries
# Motif's libXm, libMrm and libUil with the uil compiler and the
# headers -- built from this tree (motif/, --with-private-motif), not
# the system's libxm4: on Makronix Motif is ours too (x11/motif).
# install build, then apt-get install ./<the deb>: apt resolves the
# dependencies; dpkg -i would leave them to the caller.
# clean remove build/mcde-debian*.
#
# The prefix is /usr/mdt with /etc/mdt -- the paths tools/mcde-host.sh uses, so
# a package installation and a `make mcde-host MCDE_DIRS=install` end up in the
# same place and a session finds its icons and data types in either. The
# programs carry RUNPATH=/usr/mdt/lib (libtool -rpath), so the system's Motif is
# never picked up beside ours and no /etc/ld.so.conf.d file is needed.
#
# Nothing here goes into a Makronix set or into pkgsrc
# (ext/src/mcde/pkgsrc). This is the Linux side of the build host.
#
# The last line of the output is "mcde-debian exit=N".
set -u
TOP=$(cd "$(dirname "$0")/.." && pwd)
# This tool writes below build/: only inside the build lock, like the others.
if [ -z "${BUILD_LOCK_HELD:-}" ] || [ ! -d "$BUILD_LOCK_HELD" ]; then
echo "${0##*/}: run this through make or tools/build-lock.sh" >&2
exit 1
fi
SRC=$TOP/ext/src/mcde
B=$TOP/build/mcde-debian
STAGE=$TOP/build/mcde-debian-stage
META=$SRC/debian-mcde
PREFIX=/usr/mdt
SYSCONF=/etc/mdt
PKG=mcde
JOBS=${JOBS:-16}
finish() { echo "mcde-debian exit=$1"; exit "$1"; }
case ${1:-build} in
build|install|clean) ;;
*) echo "usage: ${0##*/} [build|install|clean]" >&2; finish 2 ;;
esac
if [ "$1" = clean ]; then
rm -rf "$B" "$STAGE"
finish 0
fi
# apt-get(8) through sudo(8), -n: never ask for a password, so a run that
# cannot get root stops instead of waiting for input that never comes.
apt() {
if [ "$(id -u)" = 0 ]; then
apt-get "$@"
elif sudo -n true 2>/dev/null; then
sudo -n apt-get "$@"
else
echo "${0##*/}: need root for apt-get $* (no passwordless sudo)" >&2
return 1
fi
}
# What the build of MCDE and of its own Motif reads, as Debian names it. Each
# one is a package configure would stop on (AC_MSG_ERROR in configure.ac) or a
# program MISSING_PROGS reports, or a header a library is built against:
# autoconf automake libtool pkg-config -- autogen.sh, --with-private-motif
# bison flex -- motif's parser and lexer (YACC, AM_PROG_LEX)
# m4 cpp gzip perl -- configure, tradcpp, the catalogues
# ksh93u+m -- programs/Xsession runs /usr/bin/ksh (KSH)
# mksh -- the fallback AC_PATH_PROG(KSH, mksh) finds
# rpcsvc-proto -- rpcgen; libc-dev-bin -- gencat
# opensp -- onsgmls, the help books
# x11-xserver-utils -- xrdb, sessreg (dtlogin reads and registers)
# xfonts-utils -- bdftopcf, mkfontdir (the fonts of the session)
# xbitmaps xfonts-* -- the bitmaps and fonts dtlogin and dtwm name
# lib*-dev -- X11, Xft, Xinerama, Xrandr, Xfixes, Xpm, Xmu, Xt,
# Xext, Xrender, Xau, ICE, SM, Xss, ICE, jpeg, png,
# lmdb, ssl (libcrypto), opus, tls (libretls is
# libtls-dev on Debian), tcl (tcl8.6-dev has tcl.h),
# pam, utempter, tirpc, cups (dtprintinfo links it)
BUILD_DEPS="autoconf automake libtool pkg-config bison flex m4 cpp gzip perl
ksh93u+m mksh rpcsvc-proto libc-dev-bin opensp
x11-xserver-utils xfonts-utils xbitmaps xfonts-base xfonts-100dpi
xfonts-75dpi libx11-dev libxext-dev libxrender-dev libxau-dev
libxpm-dev libxt-dev libxmu-dev libxinerama-dev libxrandr-dev
libxfixes-dev libxft-dev libxss-dev libice-dev libsm-dev
libjpeg-dev libpng-dev libfontconfig1-dev libfreetype-dev
liblmdb-dev libssl-dev libopus-dev libtls-dev tcl8.6-dev
libpam0g-dev libutempter-dev libtirpc-dev libcups2-dev"
# The programs and data dpkg-shlibdeps(1) cannot see, because nothing links
# them: the ksh the session scripts run, tcl for dtinfo, the X tools dtlogin
# calls, and the fonts and bitmaps its configuration names.
RUNTIME_DEPS="ksh93u+m tcl x11-xserver-utils xfonts-base xfonts-100dpi
xfonts-75dpi xbitmaps"
MISSING=
for p in $BUILD_DEPS; do
dpkg -s "$p" >/dev/null 2>&1 || MISSING="$MISSING $p"
done
if [ -n "$MISSING" ]; then
echo "${0##*/}: installing build dependencies:$MISSING"
apt install -y $MISSING || finish 1
else
echo "${0##*/}: build dependencies are there"
fi
# --- the source tree, as tools/mcde-host.sh copies it ------------------------
# Without the artefacts of a build: an in-tree run (someone typed make in
# ext/src/mcde) leaves object files, .libs/ and -- the one that stops an
# install -- .la files that name their own libdir. Copied along, make keeps
# them for up to date and the install stops at "cannot install
# 'libMcdeSound.la' to a directory not ending in /usr/local/lib" (measured
# 2026-11-22). The build tree below build/ keeps its own; these excludes only
# keep the source tree's out of it.
#
# The endings are not enough. A generated file usually has no telling name:
# Xsession is made from Xsession.src by tradcpp, Xconfig from Xconfig.src, the
# catalogue and the dtlogin resources the same way, and they are not .o or
# .la. Measured 2026-11-22: an in-tree build from a run with another prefix
# left Xsession with DT_BINPATH=/usr/local/bin in it; copied along it was newer
# than Xsession.src, so make kept it, the package shipped it, and the session
# of the installed desktop came up as a bare xterm -- greeter and login fine,
# no dtwm and no front panel.
#
# The rule is the tree's own convention: a file that has a .src next to it is
# generated, never source. That covers Xsession, Xconfig, Xstartup, Xsetup,
# Xreset, Xfailsafe, the dtlogin resources, the catalogues and every other
# cpp-derived file of the desktop -- all of them without an ending that says
# so. A file without a .src is copied as it is; one that is left behind
# instead would only be regenerated if it looked older than its source, and an
# obsolete copy does not.
mkdir -p "$B" || finish 1
GEN=$B/.mcde-debian-generated
(cd "$SRC" && find . -path ./pkgsrc -prune -o -type f -name '*.src' -print) |
sed -e 's,\.src$,,;s,^\./,/,' > "$GEN"
rsync -a --exclude=/pkgsrc --exclude=/pkgsrc-* --exclude-from="$GEN" \
--exclude='*.o' --exclude='*.lo' --exclude='*.la' --exclude='*.so' \
--exclude='*.so.*' --exclude='*.a' --exclude=.libs/ --exclude=.deps/ \
--exclude=/libtool --exclude=config.status --exclude=config.log \
--exclude=config.cache --exclude='stamp-h*' \
"$SRC/" "$B/" || finish 1
# The CDE paths in the source, the step the pkgsrc recipe does before its
# configure (pre-configure) and tools/mcde-host.sh copies: CDE has /usr/dt,
# /etc/dt and /usr/bin/X11 written into its scripts and its programs, and a
# tree that keeps them builds a desktop that looks for dtsession in
# /usr/local/bin. Measured 2026-11-22 on the installed package: dtlogin
# started Xsession, Xsession read DT_BINPATH=/usr/local/bin, found no
# dtsession and fell back to xterm -- the greeter and the login were fine, the
# desktop was a bare terminal.
#
# /etc/dt -> the package's own configuration directory; /usr/mdt is the
# prefix configure uses, so a file that already says /usr/dt (none does) would
# only be rewritten once. A Makefile.am that changed gets .mcde-debian-regen,
# the same marker mcde-host.sh uses: autogen.sh has to run afterwards.
(cd "$B" && grep -rlI -e /usr/dt -e /etc/dt -e /usr/bin/X11 . \
--exclude-dir=pkgsrc --exclude-dir=pkgsrc-motif \
--exclude=configure --exclude=Makefile.in --exclude=aclocal.m4 \
--exclude-dir=.git) > "$B/.mcde-debian-subst" || finish 1
: > "$B/.mcde-debian-regen"
while IFS= read -r f; do
f=${f#./}
out=$B/$f.subst
cp -p "$B/$f" "$out" || finish 1
sed -e "s:/usr/bin/X11:/usr/bin:g" -e "s:/usr/dt:$PREFIX:g" \
-e "s:/etc/dt:$SYSCONF:g" "$B/$f" > "$out" || finish 1
if cmp -s "$out" "$B/$f"; then
rm -f "$out"
else
mv "$out" "$B/$f" || finish 1
case $f in
*Makefile.am) : > "$B/.mcde-debian-regen" ;;
esac
fi
done < "$B/.mcde-debian-subst"
# motif/'s Makefile.in, configure and aclocal.m4 were generated by automake
# 1.15 and autoconf of 2017, and their Makefiles name those programs
# (`missing aclocal-1.15'). This host has automake 1.19: a Makefile.am newer
# than its Makefile.in (motif's is, 2026-11-13) makes make call the missing
# automake-1.15 and stop with "Error 127" (measured 2026-11-22). The
# generated files get the current time, so nothing in motif/ is regenerated --
# its sources are from 2017 and are not touched. Before configure runs, so
# the Makefiles it writes are newer and config.status stays quiet.
#
# Only motif/: the rest of the tree is ours and its Makefile.in files are made
# by autogen.sh from the Makefile.am, which is where a change belongs. Given
# the same treatment, a changed Makefile.am (dtphoto's, 2026-11-22) would never
# reach its Makefile and the program would link without the library it now
# calls (mcde_sys_print_file, undefined reference).
find "$B/motif" \( -name Makefile.in -o -name configure -o -name aclocal.m4 \) \
-exec touch {} + || finish 1
# debian/ of this fork: the metadata, copied so a build never edits the tree
# it builds from.
mkdir -p "$B/debian" || finish 1
for f in control.in postinst mcde.desktop; do
[ -f "$META/$f" ] || { echo "${0##*/}: no $META/$f" >&2; finish 1; }
cp "$META/$f" "$B/debian/$f" || finish 1
done
cd "$B" || finish 1
if [ ! -f config.status ] ||
[ -n "$(find . -name configure.ac -newer config.status -o \
-name Makefile.am -newer config.status | head -1)" ]; then
./autogen.sh || finish 1
# --with-private-motif is the default and is given for the record: the
# package carries its own libXm/libMrm/libUil, as Konrad asked.
# --disable-printing: libcups of a build host has no destinations, and
# the test HOME of tools/mcde-tests.sh has no printer (mcde-linux.sh).
./configure --prefix="$PREFIX" --sysconfdir=/etc --localstatedir=/var \
--with-config-dir="$SYSCONF" --with-logfiles-dir=/var/mdt \
--with-pamdir=/etc/pam.d --with-calendar-dir=/var/spool/calendar \
--with-private-motif --enable-xft --enable-png --enable-jpeg \
--disable-printing || finish 1
fi
nice -n 19 make -j"$JOBS" || finish $?
# The substitution above has to have reached the tree that gets installed.
# Without it Xsession says /usr/local/bin and the desktop is a bare xterm;
# that costs a flash and a login to notice, so it is checked here. Only the
# desktop's own path variables: /usr/local/bin inside a PATH list is a normal
# entry and not a sign that CDE_INSTALLATION_TOP was missed.
if [ -f "$B/programs/dtlogin/config/Xsession" ]; then
bad=$(sed -n 's/^[[:space:]]*\(DT_BINPATH\|DT_INSTALL\|DT_INSTALL_CONFIG\|DT_CONFIG\)=\(.*\)$/\1=\2/p' \
"$B/programs/dtlogin/config/Xsession" | grep '/usr/local')
if [ -n "$bad" ]; then
echo "${0##*/}: programs/dtlogin/config/Xsession still points at" >&2
echo " /usr/local -- the CDE paths were not substituted, the desktop" >&2
echo " would start without dtwm and without the front panel:" >&2
printf ' %s\n' $bad >&2
finish 1
fi
fi
# --- the installation -------------------------------------------------------
rm -rf "$STAGE" || finish 1
make install DESTDIR="$STAGE" >"$B/.install.log" 2>&1 ||
{ tail -20 "$B/.install.log" >&2; finish 1; }
[ -x "$STAGE$PREFIX/bin/dtwm" ] ||
{ echo "${0##*/}: install left no $PREFIX/bin/dtwm" >&2; finish 1; }
# A package carries no libtool archives (nothing reads them once the libraries
# are in place) and no test binaries.
find "$STAGE" -name '*.la' -delete
find "$STAGE" -type f -name 'test_*' -path '*/bin/*' -delete
# strip: only the debug and symbol sections, so objdump's RUNPATH, NEEDED and
# the loader's view stay exactly as the build made them.
find "$STAGE" -type f | while IFS= read -r f; do
case $f in
*/lib/*.so|*/lib/*.so.*) strip --strip-unneeded "$f" 2>/dev/null ;;
*/bin/*|*/libexec/*)
case $(head -c 4 "$f" 2>/dev/null | od -An -c | tr -d ' \n') in
*177E*L*F) strip --strip-unneeded "$f" 2>/dev/null ;;
esac ;;
esac
done
# An empty /var/spool/calendar is not a file of a package, and a state
# directory belongs to the system's package manager only if it is used.
rm -rf "$STAGE/var" || finish 1
# --- the metadata -----------------------------------------------------------
# Version: AC_INIT is the base; a tree with local edits says so, because the
# package is then not the commit it claims to be.
BASE=$(sed -n 's/^ *\[\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)\],$/\1/p' \
"$SRC/configure.ac" | head -1)
[ -n "$BASE" ] || BASE=0.0.0
GIT=$(git -C "$TOP" rev-parse --short HEAD 2>/dev/null || echo unknown)
DIRTY=
git -C "$TOP" status --porcelain -- ext/src/mcde 2>/dev/null | grep -q . &&
DIRTY=+git$GIT
VERSION=$BASE$DIRTY
ARCH=$(dpkg --print-architecture)
INSIZE=$(du -sk "$STAGE" | cut -f1)
# The dependencies the ELF files ask for. Our own libraries (libXm, libMrm,
# libUil, libDt*, libMcde*) are in this very package, so they are not
# dependencies: a shlibs.local line per library of the package says so, and
# without it dpkg-shlibdeps looks for a Debian package that owns
# /usr/mdt/lib/libXm.so.4 and finds the system's libxm4 instead.
: > "$B/.shlibs.local"
find "$STAGE$PREFIX/lib" -maxdepth 1 -name '*.so.*' | while IFS= read -r so; do
n=$(basename "$so")
lib=${n%%.so.*}
# dpkg-shlibdeps matches on the SONAME version (libXm.so.4 -> 4), not on
# the file version (libXm.so.4.0.4): a shlibs line with 4.0.4 is ignored
# and the system's libxm4 gets the dependency instead.
ver=${n#*.so.}
ver=${ver%%.*}
case $lib in
*) echo "$lib $ver $PKG" >> "$B/.shlibs.local" ;;
esac
done
# a library with a symlink and its versioned file gives two lines
sort -u -o "$B/.shlibs.local" "$B/.shlibs.local"
# -L is the file dpkg-shlibdeps READS for overrides (-T is where it writes
# the substvars it produced, which is what the log below is for).
dpkg-shlibdeps -O -L"$B/.shlibs.local" -x"$PKG" --ignore-missing-info \
-l"$STAGE$PREFIX/lib" \
$(find "$STAGE$PREFIX/bin" "$STAGE$PREFIX/libexec" -type f 2>/dev/null |
while IFS= read -r f; do
case $(head -c 4 "$f" 2>/dev/null | od -An -c | tr -d ' \n') in
*177E*L*F) echo "-e$f" ;;
esac
done) > "$B/.shlibdeps.log" 2>&1
SHLIBS=$(sed -n 's/^shlibs:Depends=//p' "$B/.shlibdeps.log")
if [ -z "$SHLIBS" ] || grep -q 'no dependency information' "$B/.shlibdeps.log"
then
echo "${0##*/}: dpkg-shlibdeps found no dependencies:" >&2
tail -5 "$B/.shlibdeps.log" >&2
finish 1
fi
DEPENDS=$(printf '%s, %s' "$SHLIBS" \
"$(echo $RUNTIME_DEPS | tr ' ' ',')" | sed -e 's/, */, /g' -e 's/^, //')
mkdir -p "$STAGE/DEBIAN" || finish 1
sed -e "s|@VERSION@|$VERSION|g" -e "s|@ARCH@|$ARCH|g" \
-e "s|@DEPENDS@|$DEPENDS|g" -e "s|@PREFIX@|$PREFIX|g" \
-e "s|@PACKAGE@|$PKG|g" -e "s|@DATE@|$(date -R)|g" \
-e "s|@INSIZE@|$INSIZE|g" \
"$B/debian/control.in" > "$STAGE/DEBIAN/control" || finish 1
install -m 755 "$B/debian/postinst" "$STAGE/DEBIAN/postinst" || finish 1
# The session entry: without it the display manager lists the desktop of the
# host and not MCDE. Type=XSession, so the file goes to /usr/share/xsessions
# and not to a package-private share/.
install -D -m 644 "$B/debian/mcde.desktop" \
"$STAGE/usr/share/xsessions/mcde.desktop" || finish 1
# every file under /etc is configuration: a local edit survives an upgrade
find "$STAGE/etc" -type f 2>/dev/null | sed "s,^$STAGE,," \
> "$STAGE/DEBIAN/conffiles"
OUT=$B/${PKG}_${VERSION}_${ARCH}.deb
# The version carries the commit, so every build leaves a new file here and an
# older one stays beside it. `dpkg -i build/mcde-debian/*.deb' then installs
# both and the older one wins (measured 2026-11-22): one package, one file.
rm -f "$B/${PKG}_"*"_${ARCH}.deb"
dpkg-deb --root-owner-group --build "$STAGE" "$OUT" >"$B/.dpkg-deb.log" 2>&1 ||
{ tail -20 "$B/.dpkg-deb.log" >&2; finish 1; }
echo "${0##*/}: $OUT ($(du -h "$OUT" | cut -f1), $INSIZE KiB installed)"
dpkg-deb -f "$OUT" Package Version Depends | sed 's/^/ /'
if [ "${1:-build}" = install ]; then
# The package just built, by name: a glob could take an older one too.
apt install -y "$OUT" || finish 1
dpkg-query -W -f=' ${Package} ${Version} ${Status}\n' "$PKG" || finish 1
fi
finish 0