magic/scripts/magic_run_common.sh.in

61 lines
3.1 KiB
Bash
Raw Normal View History

build: add run_magic*.sh launchers to run magic from the build tree Four configure-generated launch scripts let you run magic straight from the build directory without `make install`: * run_magic.sh -- GUI magic (Cairo/X11) * run_magicnull.sh -- batch / no-GUI (-dnull) * run_magic_gdb.sh -- magic under gdb * run_magic_valgrind.sh -- magic under valgrind magic resolves its runtime files through a single $CAD_ROOT root ($CAD_ROOT/magic/{sys,tcl}), but in the build tree they are scattered across build/ (generated tech, .magicrc, magic.tcl, tclmagic, execs) and source/ (colormaps, dstyles, glyphs, fonts, tcl scripts). On first run each launcher self-stages ${builddir}/CAD_DIR as a symlink tree in that layout (no copies, always current) via the shared scripts/magic_run_common.sh, exports CAD_ROOT=${builddir}/CAD_DIR, and execs the right binary. This pairs with the preceding commit that made the C launchers honor CAD_ROOT. magic_stage() is idempotent and re-runs on every launch. Most staged entries are files, but the bitmaps entry links a *directory*, so it uses `ln -sfn` (--no-dereference; also accepted by BSD ln): a plain `ln -sf` would, on a second run, dereference the existing symlink-to-directory and drop the new link *inside* the target -- a magic/bitmaps/bitmaps self-loop in the source tree that trips up find/tar/cp -r. Verified: ./run_magicnull.sh self-stages (30 sys + 24 tcl symlinks) and runs -- `tech load scmos` reports 13 planes -- straight from the build dir. gitignore covers the generated scripts and the CAD_DIR tree. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-24 00:06:28 +02:00
# Shared setup for the run_magic* launchers -- sourced, not run directly.
#
# Generated by configure from scripts/magic_run_common.sh.in. It stages a
# CAD_ROOT directory of *symlinks* into the build (generated) and source trees --
# the same layout `make install` copies, but instantly and always reflecting the
# latest build -- and exports the environment magic needs to start straight from
# the build tree without `make install`.
#
# See magic's runtime file discovery: MAGIC_SYS_PATH = ". $CAD_ROOT/magic/sys
# $CAD_ROOT/magic/sys/current" (utils/paths.h) for tech/glyphs/fonts/styles, the
# system .magicrc at $CAD_ROOT/magic/sys/.magicrc, and (since tcltk/tcldir.h)
# magic.tcl / tclmagic / auto_path at $CAD_ROOT/magic/tcl.
MAGIC_BUILDDIR="@abs_top_builddir@"
MAGIC_SRCDIR="@abs_top_srcdir@"
SHDLIB_EXT="@SHDLIB_EXT@"
CAD_ROOT="${MAGIC_BUILDDIR}/CAD_DIR"
export CAD_ROOT
MAGIC_SYS="${CAD_ROOT}/magic/sys"
MAGIC_TCL="${CAD_ROOT}/magic/tcl"
# (Re)build the symlink layout. Idempotent; `ln -sf` relinks so a rebuilt target
# is always current. Missing globs (a partial build) are tolerated.
magic_stage() {
local b="$MAGIC_BUILDDIR" s="$MAGIC_SRCDIR"
mkdir -p "$MAGIC_SYS" "$MAGIC_TCL"
# --- sys/ : generated tech (build) + display files/glyphs/fonts (source) ---
ln -sf "$b"/scmos/*.tech "$MAGIC_SYS"/ 2>/dev/null || :
ln -sf "$s"/scmos/*.cmap "$s"/scmos/*dstyle "$MAGIC_SYS"/ 2>/dev/null || :
ln -sf "$s"/windows/*.glyphs "$s"/windows/vfont.* "$MAGIC_SYS"/ 2>/dev/null || :
ln -sf "$s"/graphics/*.glyphs "$s"/graphics/*.pt3 "$MAGIC_SYS"/ 2>/dev/null || :
ln -sf "$b"/magic/proto.magicrc "$MAGIC_SYS"/.magicrc 2>/dev/null || :
ln -sf "$b"/magic/proto.initrc "$MAGIC_SYS"/.initrc 2>/dev/null || :
if [ -f "$b"/magic/magicps.pro ]; then
ln -sf "$b"/magic/magicps.pro "$MAGIC_SYS"/ 2>/dev/null || :
else
ln -sf "$s"/magic/magicps.pro "$MAGIC_SYS"/ 2>/dev/null || :
fi
# --- tcl/ : source scripts + generated magic.tcl + .so + execs + bitmaps ---
ln -sf "$s"/tcltk/*.tcl "$MAGIC_TCL"/ 2>/dev/null || :
ln -sf "$b"/tcltk/magic.tcl "$MAGIC_TCL"/ 2>/dev/null || :
ln -sf "$b"/magic/tclmagic${SHDLIB_EXT} "$MAGIC_TCL"/ 2>/dev/null || :
ln -sf "$b"/tcltk/magicexec "$b"/tcltk/magicdnull "$MAGIC_TCL"/ 2>/dev/null || :
# bitmaps is a *directory*: use -n so a re-stage replaces the existing
# symlink instead of dereferencing it and dropping a self-link *inside* the
# source tree (magic/bitmaps/bitmaps -> .../magic/bitmaps).
ln -sfn "$s"/magic/bitmaps "$MAGIC_TCL"/bitmaps 2>/dev/null || :
}
# Fail early with a clear message if the build has not produced the binaries yet.
magic_require_built() {
if [ ! -x "$MAGIC_BUILDDIR/tcltk/magicexec" ] && \
[ ! -x "$MAGIC_BUILDDIR/tcltk/magicdnull" ]; then
echo "error: magic is not built yet -- run 'make' in ${MAGIC_BUILDDIR} first." >&2
exit 1
fi
}