-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.sh
executable file
·235 lines (192 loc) · 5.7 KB
/
bootstrap.sh
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
NOTICES=()
TOPDIR=$PWD
function qpopd() {
popd > /dev/null
}
function qpushd() {
pushd "$1" > /dev/null
}
function qwhich() {
which "$1" > /dev/null 2>&1
}
function uname_grep() {
uname | grep "$1" > /dev/null 2>&1
}
function notify() {
local text="$1"
NOTICES+=("$1")
}
function compile_check() {
if ! qwhich "$1"; then
notify "Warning: Could not find \"$1\" in your path, skipped compilation"
BUILD=
fi
}
function update_submodule () {
local subdir="$1"
qpushd "$subdir"
git submodule init
git submodule update --depth 1
qpopd
}
function byte_compile() {
local module="$1"
local subdir="$2"
emacs --script byte-compile-local.el "$module" "$subdir" 2>&1 | \
grep -v '^Loading '
}
if uname_grep 'MINGW' || uname_grep 'MSYS_NT'; then
OS=Windows
BIN_TPL=tpl/bin/windows
elif uname_grep 'Darwin'; then
OS=macOS
BIN_TPL=tpl/bin/mac
else
OS=Linux
if grep "^Ubuntu" < /etc/issue > /dev/null 2>&1; then
OS_VARIANT=Ubuntu
BIN_TPL=tpl/bin/ubuntu
else
BIN_TPL=tpl/bin/linux
fi
fi
BUILD=y
compile_check which
compile_check make
compile_check node
compile_check npm
if [[ $OS == Windows ]]; then
compile_check ninja
if ! uname_grep 'MINGW64_NT'; then
# Symptom of building in Git Bash is that Emacs will crash when trying to use magit
notify "Warning: Cannot compile binaries unless you are in an MSYS2 MinGW 64-bit terminal, skipped compilation"
BUILD=
fi
fi
REQUIRED_EMACS_VERSION=29.4
# Set this environment variable to rebuild git-for-windows manpages; otherwise use pre-built ones
: ${BUILD_GIT_MANPAGES:=}
if [[ $OS == Windows ]]; then
if ! qwhich emacs-${REQUIRED_EMACS_VERSION}; then
PATH="/c/Program Files/Emacs/emacs-${REQUIRED_EMACS_VERSION}/bin":"$PATH"
if ! qwhich emacs-${REQUIRED_EMACS_VERSION}; then
echo >&2 "Error: Could not find \"emacs-${REQUIRED_EMACS_VERSION}\" in your path"
exit 1
fi
fi
elif [[ $OS == macOS ]]; then
if ! test -e /Applications/Emacs.app; then
echo >&2 "Error: Emacs does not seem to be installed in Applications"
exit 1
fi
if ! test -e /opt/homebrew/opt/emacs-plus@29/Emacs.app/Contents/MacOS/Emacs; then
echo >&2 "Error: Could not find Emacs Homebrew installation"
exit 1
fi
elif [[ $OS_VARIANT == Ubuntu ]]; then
if ! test -x /usr/local/bin/emacs; then
echo >&2 "Error: /usr/local/bin/emacs does not exist"
exit 1
fi
elif ! qwhich emacs; then
echo >&2 "Error: Could not find \"emacs\" in your path"
exit 1
fi
# Create bin directory
rm -fr bin
mkdir bin
cp tpl/bin/shared/* bin
cp "$BIN_TPL"/* bin
DESTDIR=$PWD
PATH="$PWD"/bin:"$PATH"
# Make sure we're using the recommended version of Emacs
EMACS_VERSION=$(emacs --batch -q --no-site-file --eval "(message \"%s\" emacs-version)" 2>&1)
if [[ z$EMACS_VERSION != z${REQUIRED_EMACS_VERSION}* ]]; then
echo >&2 "Error: Your version of Emacs is \"$EMACS_VERSION\", but should be \"${REQUIRED_EMACS_VERSION}.x\""
exit 1
fi
if ! qwhich make; then
notify "Warning: Could not find \"make\" in your path, skipped compilation"
fi
if [[ $OS == Windows ]]; then
if ! qwhich ninja; then
notify "Warning: Could not find \"ninja\" in your path, skipped compilation"
fi
fi
set -e
echo "OS : $OS"
echo "BUILD : $BUILD"
echo "BUILD_GIT_MANPAGES : $BUILD_GIT_MANPAGES"
echo "DESTDIR : $DESTDIR"
echo
git submodule init
git submodule sync
git submodule update --depth 1
echo
# tree-sitter setup
npm ci
qpushd build
rm -fr tree-sitter-prisma
cp -r "$TOPDIR"/node_modules/tree-sitter-prisma .
qpushd tree-sitter-prisma
git init >/dev/null
git add . >/dev/null
git commit -m "workaround" >/dev/null
qpopd
qpopd
emacs --script install-packages.el 2>&1 | grep -v '^Loading '
qpushd share/man
git submodule init
git submodule update --depth 1
qpopd
if test -n "$BUILD_GIT_MANPAGES"; then
qpushd extra/git
git submodule init
git submodule update --depth 1
# check this for most up-to-date path:
# https://packages.msys2.org/package/docbook-xsl?repo=msys&variant=x86_64
xmlcatalog --noout \
--add rewriteURI \
http://docbook.sourceforge.net/release/xsl/current \
/ucrt64/share/xml/docbook/xsl-stylesheets-1.79.2 \
/etc/xml/catalog
# check this for most up-to-date path:
# https://packages.msys2.org/package/docbook-xml?repo=msys&variant=x86_64
xmlcatalog --noout \
--add rewriteURI \
http://www.oasis-open.org/docbook/xml/4.5/xsl/current \
/ucrt64/share/xml/docbook/xml-dtd-4.5 \
/etc/xml/catalog
xmlcatalog --noout \
--add rewriteURI \
http://www.oasis-open.org/docbook/xml/4.5 \
/ucrt64/share/xml/docbook/xml-dtd-4.5 \
/etc/xml/catalog
# see also end of INSTALL doc at https://github.com/git-for-windows/git/blob/main/INSTALL#L229
make prefix=$DESTDIR install-man
notify "Built manpages, make sure to check them in"
qpopd
fi
dir_elisp_submodules="archive-rpm gptel ligature polymode"
for mod in $dir_elisp_submodules; do
update_submodule elisp/"$mod"
byte_compile "$mod" elisp/"$mod"
done
file_elisp_submodules="asdf-vm elysium poly-markdown prisma-ts-mode tmux-mode zig-mode"
for mod in $file_elisp_submodules; do
update_submodule elisp/"$mod"
byte_compile "$mod" elisp/"$mod"/"$mod".el
done
update_submodule extra/emacs
update_submodule extra/tree-sitter-module
qpushd extra/tree-sitter-module
./build.sh go
./build.sh gomod
# disabling until wider adoption is reached
# JOBS=4 ./batch.sh
qpopd
for idx in ${!NOTICES[@]}; do
echo -e >&2 "\n${NOTICES[$idx]}"
done
echo -e >&2 "\nBootstrap complete! Your Emacs is ready for use."