dotfiles

🎜 Clone'em, tweak'em, stick'em in your $HOME 🎝
git clone https://git.kevinlegouguec.net/dotfiles
Log | Files | Refs | README

commit 9700b7bc4f2c198ef73276dddb77b37077214a1d
parent a61d1e2f14229f02df5422635adcf053e2688b73
Author: KΓ©vin Le Gouguec <kevin.legouguec@gmail.com>
Date:   Fri,  8 May 2026 13:21:04 +0200

Fuss over Emacs build scripts

Mostly out of annoyance from seeing the os-release sourcing, then "one
thing led to another".  The main change is (a) always using the
configure cache (b) hopefully being more precise in assessing its
freshness.

While in there, remove config_h (unused since c53b1a4), add some
commentary, copyedit code & prose.

Diffstat:
M.local/bin/emacs-build | 97++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
M.local/bin/emacs-install | 17++++++++++++-----
2 files changed, 69 insertions(+), 45 deletions(-)

diff --git a/.local/bin/emacs-build b/.local/bin/emacs-build @@ -4,10 +4,47 @@ set -eux src_dir=$(realpath "${EMACS_SRC:-.}") build_dir=$(realpath "${EMACS_BUILD:-.}") -config_h=${build_dir}/src/config.h -make="make -j$(nproc --all)" +make=(make -j$(nproc --all)) + +configure-cache () +{ + local -r cachedir=${XDG_CACHE_HOME:-~/.cache}/emacs + test -d "${cachedir}" || mkdir -p "${cachedir}" + + # Keep one cache per worktree, to prevent mixups between branches + # where configure requirements diverge. + local builddesc=${src_dir} + builddesc=${builddesc#~} + builddesc=${builddesc//\//,} + echo ${cachedir}/config${builddesc} +} + +os-version () +{ + # Use VERSION_ID. os-release(5) says it is optional, but it is + # present on Debian, Ubuntu & openSUSE Tumbleweed. + # + # Tumbleweed in particular sets it to the snapshot date, which + # covers the occasional backward-incompatible change (major-ish + # dependency bump, full distro rebuild). + grep ^VERSION_ID= /etc/os-release | + cut -d= -f2 | + tr -d \'\" +} + +configure_cache=$(configure-cache) +configure_cacheversion=${configure_cache}.os-version +osversion_cached=$( + if test -f "${configure_cacheversion}" + then + cat "${configure_cacheversion}" + fi +) +osversion_current=$(os-version) + configure_flags=( + --cache-file="${configure_cache}" --prefix=${HOME}/apps/.emacs.$(date +%F) --with-cairo # Disable native compilation. trunk is my daily driver, and I @@ -37,37 +74,6 @@ configure_flags=( ${CONFIGURE_EXTRA_FLAGS:-} ) -is-rolling-distro () -{ - ( - . /etc/os-release - case "${ID}" - in - opensuse-tumbleweed) return 0;; - esac - return 1 - ) -} - -cache-file () -{ - local -r cachedir=${XDG_CACHE_HOME:-~/.cache}/emacs - test -d "${cachedir}" || mkdir -p "${cachedir}" - - local builddesc=${PWD} - builddesc=${builddesc#~} - builddesc=${builddesc//\//,} - echo ${cachedir}/config${builddesc} -} - -if ! is-rolling-distro -then - configure_flags=( - --cache-file="$(cache-file)" - "${configure_flags[@]}" - ) -fi - if test "${DEBUG:-}" then configure_flags+=( @@ -77,17 +83,28 @@ then ) fi +# Wipe cache if stale. +if test "${osversion_cached}" != "${osversion_current}" +then + rm -f "${configure_cache}" "${configure_cacheversion}" +fi + if ! test -f "${src_dir}"/Makefile then - ${make} -C "${src_dir}" configure + "${make[@]}" -C "${src_dir}" configure fi cd "${build_dir}" -# Had logic to check src/config.h:EMACS_CONFIG_OPTIONS to determine -# whether running 'configure' is redundant. Threw it all to the wind: -# date-based --prefix changes everyday; build times are not as long as -# they used to be; I can always invoke 'make' if I want fast iteration -# over build errors. +# Used to check src/config.h:EMACS_CONFIG_OPTIONS to determine whether +# running 'configure' is necessary. Threw it all to the wind: +# date-based --prefix changes everyday; 'configure' got faster in +# recent years; I can always invoke 'make' directly myself if I want +# to cut to the chase. "${src_dir}"/configure "${configure_flags[@]}" -${make} "$@" +"${make[@]}" "$@" + +# Only record the cache stamp once the build proved successful: when +# hacking on 'configure' itself, we would not want to bless a bogus +# cache file. +echo "${osversion_current}" > "${configure_cacheversion}" diff --git a/.local/bin/emacs-install b/.local/bin/emacs-install @@ -3,15 +3,22 @@ set -eux build_dir=${EMACS_BUILD:-.} +apps_dir=~/apps cd "${build_dir}" make install -# Retrieve installation directory. Many ways to do this; parsing -# 'config.status --config' might be TRT in principle; for simplicity, -# just: -prefix_dir=$(sed -n s/'^prefix *= *'//p Makefile) -apps_dir=~/apps +# For peace of mind, to make rollbacks trivial, I usually add a date +# to --prefix, and use a symlink to pick a known-good installation. +# +# So if this build is configured to install under ~/apps, assume we +# are following this practice & update the symlink. + +prefix_dir=$( + # Many ways to do this. Parsing 'config.status --config' might be + # TRT in principle? For simplicity, just: + sed -n s/'^prefix *= *'//p Makefile +) case ${prefix_dir} in