summaryrefslogtreecommitdiff
path: root/.local/bin/emacs-build
blob: c63338fc36b83beb7a30b7a1dc9d2b9eefbc1964 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash

set -eux

src_dir=$(realpath "${EMACS_SRC:-.}")
build_dir=$(realpath "${EMACS_BUILD:-.}")
config_h=${build_dir}/src/config.h

make="make -j$(nproc --all)"
configure_flags=(
    --prefix=${HOME}/apps/.emacs.$(date +%F)
    --with-cairo
    # Disable native compilation.  trunk is my daily driver, and I
    # update it regularly, so eln-cache grows a new subdir with every
    # update.
    #
    # I have tried it out unwittingly because as distros start
    # enabling it, libgccjit becomes part of Emacs build dependencies;
    # hence package managers install libgccjit when I ask for these
    # build dependencies, and 'configure' defaults to enabling native
    # compilation if libgccjit is available.
    #
    # I am happy to report that on this workstation, native-comp seems
    # to Just Workβ„’: I remember seeing a grand total of one (1)
    # compilation-warning popup over the couple of months I have been
    # using it.  So congrats to the devs for a smooth UX πŸ‘
    #
    # Vibes-wise, I have not noticed performance improvements though.
    # When Emacs feels "slow" to me, it is usually because the UI is
    # completely unresponsive due to synchronous jobs: e.g. Gnus IMAP
    # refresh, fontconfig matching, project-wide regexp search.
    #
    # So I bow out of native-comp, to avoid the eln-cache spill.
    --with-native-compilation=no
    --with-sqlite3
    --with-xinput2
    ${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+=(
        --enable-checking=yes,glyphs
        --enable-check-lisp-object-type
        CFLAGS='-O0 -g3'
    )
fi

if ! test -f "${src_dir}"/Makefile
then
    ${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.
"${src_dir}"/configure "${configure_flags[@]}"
${make} "$@"