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
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
#
|
2026-07-24 00:49:49 +02:00
|
|
|
# run_magic_valgrind.sh -- run magic under valgrind, straight from the build tree.
|
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
|
|
|
# Generated by configure from scripts/run_magic_valgrind.sh.in.
|
|
|
|
|
#
|
2026-07-24 00:49:49 +02:00
|
|
|
# PURPOSE
|
|
|
|
|
# Memory-check the just-built magic without `make install`. Stages
|
|
|
|
|
# ${builddir}/CAD_DIR (symlinks) on first run, exports CAD_ROOT, then runs
|
|
|
|
|
# valgrind on the self-contained "magicexec".
|
|
|
|
|
#
|
|
|
|
|
# USAGE
|
2026-07-24 01:06:27 +02:00
|
|
|
# ./run_magic_valgrind.sh [valgrind-opts...] [-- [magic-args...]]
|
|
|
|
|
#
|
|
|
|
|
# A "--" separates valgrind's own options from magic's:
|
|
|
|
|
# ./run_magic_valgrind.sh # default memcheck options
|
|
|
|
|
# ./run_magic_valgrind.sh foo.mag # no "--" => all args go to magic
|
|
|
|
|
# ./run_magic_valgrind.sh -v -- foo.mag # valgrind -v, magic gets foo.mag
|
|
|
|
|
# ./run_magic_valgrind.sh --tool=callgrind -- # a different valgrind tool
|
|
|
|
|
# With no "--", every argument is passed to magic (the common case).
|
|
|
|
|
#
|
|
|
|
|
# This checks the GUI binary; Tk/X allocations make the output noisy, so for
|
|
|
|
|
# real leak hunting run the batch device: ./run_magic_valgrind.sh -- -dnull
|
2026-07-24 00:49:49 +02:00
|
|
|
#
|
|
|
|
|
# ENVIRONMENT OVERRIDES (all optional; each wins over the baked default)
|
2026-07-24 01:06:27 +02:00
|
|
|
# VALGRIND valgrind binary to use (default: valgrind on PATH)
|
|
|
|
|
# VALGRIND_OPTS default valgrind options (default: --leak-check=full
|
|
|
|
|
# --error-exitcode=0). Set empty to clear them; command-line
|
|
|
|
|
# options before "--" are added after these.
|
2026-07-24 00:49:49 +02:00
|
|
|
# CAD_ROOT reuse an alternate runtime tree instead of staging $builddir/CAD_DIR
|
|
|
|
|
# MAGIC_WISH wish for the Tk console (default: the configure-matched wish)
|
|
|
|
|
# WISH TCLSH wish/tclsh matching this build's Tcl/Tk (--with-tk / --with-tcl)
|
|
|
|
|
# MAGIC_BUILDDIR MAGIC_SRCDIR build/source tops (default: baked-in absolutes)
|
|
|
|
|
# Inherited values are sanity-checked; problems print as stderr warnings.
|
|
|
|
|
# See magic_run_common.sh for the authoritative list and defaults.
|
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
|
|
|
set -eu
|
|
|
|
|
here="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
|
. "$here/magic_run_common.sh"
|
|
|
|
|
|
2026-07-24 01:06:27 +02:00
|
|
|
VALGRIND="${VALGRIND:-valgrind}"
|
|
|
|
|
command -v "$VALGRIND" >/dev/null 2>&1 || magic_warn "valgrind '$VALGRIND' not found on PATH"
|
|
|
|
|
VALGRIND_OPTS="${VALGRIND_OPTS---leak-check=full --error-exitcode=0}"
|
|
|
|
|
|
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
|
|
|
magic_require_built
|
|
|
|
|
magic_stage
|
2026-07-24 01:06:27 +02:00
|
|
|
magic_split_args "$@"
|
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
|
|
|
|
2026-07-24 01:06:27 +02:00
|
|
|
# valgrind <opts> magicexec -- <magic-args>
|
|
|
|
|
exec "$VALGRIND" $VALGRIND_OPTS \
|
|
|
|
|
${MAGIC_TOOL_OPTS[@]+"${MAGIC_TOOL_OPTS[@]}"} \
|
|
|
|
|
"$MAGIC_TCL/magicexec" -- \
|
|
|
|
|
${MAGIC_ARGS[@]+"${MAGIC_ARGS[@]}"}
|