summaryrefslogtreecommitdiff
path: root/.local/bin/emacs-build
blob: c96c134ecf0a057c712d96544d2e0a50a65c24f7 (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
#!/bin/bash

set -eux

src=${EMACS_SRC:-~/src/emacs/master}
build=${EMACS_BUILD:-.}
config_h=${build}/src/config.h

make="make -j$(nproc --all)"
configure_flags=(
    --with-cairo
    --with-sqlite3
    --with-xinput2
)

is-rolling-distro ()
{
    (
        . /etc/os-release
        case "${ID}"
        in
            opensuse-tumbleweed) return 0;;
        esac
        return 1
    )
}

if ! is-rolling-distro
then
    cachedir=${XDG_CACHE_HOME:-~/.cache}/emacs
    test -d "${cachedir}" || mkdir -p "${cachedir}"

    builddesc=${PWD}
    builddesc=${builddesc#~}
    builddesc=${builddesc//\//,}
    cachefile=${cachedir}/config${builddesc}

    configure_flags=(--cache-file="${cachefile}" "${configure_flags[@]}")
fi

if ! test -f "${src}"/Makefile
then
        ${make} -C "${src}" configure
fi

check-config ()
{
    if ! test -f "${config_h}"
    then
        return 1
    fi

    local pattern="#define EMACS_CONFIG_OPTIONS \"${configure_flags[@]}\""
    grep "${pattern}" "${config_h}"
}

cd "${build}"

if ! check-config
then
    "${src}"/configure "${configure_flags[@]}"
fi

${make} "$@"