emacs-build (3468B)
1 #!/bin/bash 2 3 set -eux 4 5 src_dir=$(realpath "${EMACS_SRC:-.}") 6 build_dir=$(realpath "${EMACS_BUILD:-.}") 7 8 make=(make -j$(nproc --all)) 9 10 configure-cache () 11 { 12 local -r cachedir=${XDG_CACHE_HOME:-~/.cache}/emacs 13 test -d "${cachedir}" || mkdir -p "${cachedir}" 14 15 # Keep one cache per worktree, to prevent mixups between branches 16 # where configure requirements diverge. 17 local builddesc=${src_dir} 18 builddesc=${builddesc#~} 19 builddesc=${builddesc//\//,} 20 echo ${cachedir}/config${builddesc} 21 } 22 23 os-version () 24 { 25 # Use VERSION_ID. os-release(5) says it is optional, but it is 26 # present on Debian, Ubuntu & openSUSE Tumbleweed. 27 # 28 # Tumbleweed in particular sets it to the snapshot date, which 29 # covers the occasional backward-incompatible change (major-ish 30 # dependency bump, full distro rebuild). 31 grep ^VERSION_ID= /etc/os-release | 32 cut -d= -f2 | 33 tr -d \'\" 34 } 35 36 configure_cache=$(configure-cache) 37 configure_cacheversion=${configure_cache}.os-version 38 osversion_cached=$( 39 if test -f "${configure_cacheversion}" 40 then 41 cat "${configure_cacheversion}" 42 fi 43 ) 44 osversion_current=$(os-version) 45 46 configure_flags=( 47 --cache-file="${configure_cache}" 48 --prefix=${HOME}/apps/.emacs.$(date +%F) 49 --with-cairo 50 # Disable native compilation. trunk is my daily driver, and I 51 # update it regularly, so eln-cache grows a new subdir with every 52 # update. 53 # 54 # I have tried it out unwittingly because as distros start 55 # enabling it, libgccjit becomes part of Emacs build dependencies; 56 # hence package managers install libgccjit when I ask for these 57 # build dependencies, and 'configure' defaults to enabling native 58 # compilation if libgccjit is available. 59 # 60 # I am happy to report that on this workstation, native-comp seems 61 # to Just Workβ’: I remember seeing a grand total of one (1) 62 # compilation-warning popup over the couple of months I have been 63 # using it. So congrats to the devs for a smooth UX π 64 # 65 # Vibes-wise, I have not noticed performance improvements though. 66 # When Emacs feels "slow" to me, it is usually because the UI is 67 # completely unresponsive due to synchronous jobs: e.g. Gnus IMAP 68 # refresh, fontconfig matching, project-wide regexp search. 69 # 70 # So I bow out of native-comp, to avoid the eln-cache spill. 71 --with-native-compilation=no 72 --with-sqlite3 73 --with-xinput2 74 ${CONFIGURE_EXTRA_FLAGS:-} 75 ) 76 77 if test "${DEBUG:-}" 78 then 79 configure_flags+=( 80 --enable-checking=yes,glyphs 81 --enable-check-lisp-object-type 82 CFLAGS='-O0 -g3' 83 ) 84 fi 85 86 # Wipe cache if stale. 87 if test "${osversion_cached}" != "${osversion_current}" 88 then 89 rm -f "${configure_cache}" "${configure_cacheversion}" 90 fi 91 92 if ! test -f "${src_dir}"/Makefile 93 then 94 "${make[@]}" -C "${src_dir}" configure 95 fi 96 97 cd "${build_dir}" 98 99 # Used to check src/config.h:EMACS_CONFIG_OPTIONS to determine whether 100 # running 'configure' is necessary. Threw it all to the wind: 101 # date-based --prefix changes everyday; 'configure' got faster in 102 # recent years; I can always invoke 'make' directly myself if I want 103 # to cut to the chase. 104 "${src_dir}"/configure "${configure_flags[@]}" 105 "${make[@]}" "$@" 106 107 # Only record the cache stamp once the build proved successful: when 108 # hacking on 'configure' itself, we would not want to bless a bogus 109 # cache file. 110 echo "${osversion_current}" > "${configure_cacheversion}"