-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile.header
273 lines (219 loc) · 8.03 KB
/
Makefile.header
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# -*- Makefile -*-
STUDIO = superbol_vscode_platform
TARGET_PLATFORMS ?= linux # win32 darwin
TARGET_NAME = superbol-vscode-platform
SRCDIR ?= src
STUDIO_SRCDIR = $(SRCDIR)/vscode/superbol-vscode-platform
GNUCOBOL_SRCDIR = import/gnucobol
CP ?= cp -f # ln -srf
DUNE_BUILD_DIR ?= _build
DUNE_BUILD_ARGS = ${DUNE_CROSS_ARGS}
DUNE_BUILD_SRCDIR = \
${DUNE_BUILD_DIR}/default$(strip \
$(if $(filter win32,$(TARGET_PLAT)),.windows) \
$(if $(filter darwin,$(TARGET_PLAT)),.osx) \
)/$(SRCDIR)
# TARGET_PLAT is defined in Makefile
TARGET_ARCH ?= x64
TARGET_SPEC = $(TARGET_PLAT)-$(TARGET_ARCH)
TARGET_PROFILE ?= release
TARGET_VSIX = $(TARGET_NAME)-$(VERSION)-$(TARGET_SPEC)-$(TARGET_PROFILE).vsix
DOT_EXE = $(if $(filter win32,$(TARGET_PLAT)),.exe)
SUPERBOL_LSP = superbol-free-$(TARGET_SPEC)$(DOT_EXE)
SUPERBOL_LSPs = $(wildcard superbol-free-*-*)
ifeq ($(TARGET_PLAT)_$(BUILD_STATIC_EXECS),linux_true)
SUPERBOL_LSP_BUILT = superbol-free
else
SUPERBOL_LSP_BUILT = ${DUNE_BUILD_SRCDIR}/lsp/superbol-free/main.exe
endif
# Setting `GENERATE_PACKAGE_DOT_JSON` to `no` skips generation of
# `package.json` (which should always be updated/committed anyways).
# This generation requires the compilation of `$(SUPERBOL_LSP_BUILT)`,
# that itself depends on a phony target, and therefore triggers way
# too many calls to `scripts/static-build.sh` when
# `$(BUILD_STATIC_EXECS)` holds).
ifeq ($(BUILD_STATIC_EXECS),true)
GENERATE_PACKAGE_DOT_JSON ?= no
else
GENERATE_PACKAGE_DOT_JSON ?= yes
endif
YARN = npx --yes yarn
VSCE_ARGS = --yarn -t $(TARGET_SPEC)
VSCE_PACKAGE_ARGS ?= --pre-release
VSCE_PUBLISH_ARGS ?= --pre-release
OVSX_PUBLISH_ARGS ?= --pre-release
# Emacs lsp-mode source directory (https://github.com/emacs-lsp/lsp-mode):
# (could be a submodule)
LSP_MODE_SRCDIR ?= ../lsp-mode
# --- leading rules ---
.PHONY: compile package
all: superbol-lsp-server
compile: superbol-lsp-server build-release
package: vsix-package
$(SUPERBOL_LSP_BUILT): build vsix-dist-setup
superbol-lsp-server $(SUPERBOL_LSP): $(SUPERBOL_LSP_BUILT)
# Only rebuild `package.json` when on Linux
# TODO: maybe just check build platform matches target platform
ifeq ($(TARGET_PLAT),linux)
$(CP) $(SUPERBOL_LSP_BUILT) $(SUPERBOL_LSP)
ifeq ($(shell uname)_$(GENERATE_PACKAGE_DOT_JSON),Linux_yes)
package.json: $(SUPERBOL_LSP_BUILT)
cp -f package.json package.json.prev
./$(SUPERBOL_LSP_BUILT) json vscode --gen package.json
diff -u package.json.prev package.json && rm -f package.json.prev
endif
endif #linux
.PHONY: check-package.json
check-package.json: #to be used after `build`
./$(SUPERBOL_LSP_BUILT) json vscode --gen - | diff -u package.json -
.PHONY: build-debug yarn-debug
build-debug:
${DUNE} build ${DUNE_ARGS} ${DUNE_BUILD_ARGS} \
$(STUDIO_SRCDIR)/$(STUDIO).bc.js
@mkdir -p _out
$(CP) ${DUNE_BUILD_DIR}/default/$(STUDIO_SRCDIR)/$(STUDIO).bc.js _out/
$(MAKE) yarn-debug
# Use 'make build-debug' before to copy the JS file in _out/
yarn-debug: package.json
yarn-debug: _out/superbol-vscode-platform-bundle.js \
_out/superbol-vscode-gdb.js
$(YARN) esbuild $(filter %.js, $+) \
--bundle \
--external:vscode \
--outdir=_dist \
--platform=node \
--target=es6 \
--sourcemap
# the last command generated _dist/$(STUDIO).bs.js
.PHONY: build-release yarn-release
build-release:
${DUNE} build ${DUNE_ARGS} ${DUNE_BUILD_ARGS} --profile=release \
$(STUDIO_SRCDIR)/$(STUDIO).bc.js
@mkdir -p _out
$(CP) ${DUNE_BUILD_DIR}/default/$(STUDIO_SRCDIR)/$(STUDIO).bc.js _out/
$(MAKE) yarn-release
# Use 'make build-release' before to copy the JS file in _out/
yarn-release: package.json
yarn-release: _out/superbol-vscode-platform-bundle.js \
_out/superbol-vscode-gdb.js
$(YARN) esbuild $(filter %.js, $+) \
--bundle \
--external:vscode \
--outdir=_dist \
--platform=node \
--target=es6 \
--minify-whitespace \
--minify-syntax \
--sourcemap \
--sources-content=false
# ---
_out/superbol-vscode-platform-bundle.js: \
src/vscode/superbol-vscode-platform/bundle.js
@mkdir -p $(dir $@);
cp -f $< $@
_out/superbol-vscode-gdb.js: \
src/vscode/superbol-vscode-platform/gdb.js
@mkdir -p $(dir $@);
cp -f $< $@
# ---
# packaging
.PHONY: vsix-dist-setup vsix-package vsix-debug vsix-release \
all-vsix-release-packages \
all-vsix-debug-packages \
all-vsix-packages
gnucobol-config: $(GNUCOBOL_SRCDIR)/config
@mkdir -p $@
rm -r -f $@/*.*
find $(GNUCOBOL_SRCDIR)/config -type f \
-a -regex '.*.\(conf\|conf-inc\|words\|ttbl\)' -print0 | \
xargs -0 cp -f -t $@
vsix-dist-setup:
@mkdir -p _dist
vsix-package: gnucobol-config
# needs 'make build-debug' or 'make build-release' before
rm -f _dist/superbol-free-*-*
$(CP) $(SUPERBOL_LSP_BUILT) _dist/$(SUPERBOL_LSP)
$(YARN) vsce package $(VSCE_ARGS) $(VSCE_PACKAGE_ARGS) \
--no-git-tag-version \
--no-update-package-json \
--out $(TARGET_VSIX) $(VERSION)
vsix-release: superbol-lsp-server build-release
$(MAKE) vsix-package TARGET_PROFILE=release
vsix-debug: superbol-lsp-server build-debug
$(MAKE) vsix-package TARGET_PROFILE=debug
all-vsix-release-packages: build-release
for plat in $(TARGET_PLATFORMS); do \
$(MAKE) vsix-release TARGET_PLAT=$${plat}; \
done
all-vsix-debug-packages: build-debug
for plat in $(TARGET_PLATFORMS); do \
$(MAKE) vsix-debug TARGET_PLAT=$${plat}; \
done
all-vsix-packages: all-vsix-debug-packages all-vsix-release-packages
vsix-clean: clean
rm -rf _out gnucobol-config _dist *.vsix
# publishing (requires vsce/ovsx login)
.PHONY: ovsx-deploy vsce-deploy deploy-all
vsce-deploy:
$(YARN) vsce publish $(VSCE_ARGS) $(VSCE_PUBLISH_ARGS) \
--packagePath $(TARGET_VSIX)
ovsx-deploy:
# Note: should fail in case of duplicate version
$(YARN) ovsx publish $(VSCE_ARGS) $(OVSX_PUBLISH_ARGS) \
--packagePath $(TARGET_VSIX)
deploy-all: # Make sure to run target `all-vsix-release-packages` beforehand
# $(MAKE) all-vsix-release-packages;
for plat in $(TARGET_PLATFORMS); do \
$(MAKE) ovsx-deploy vsce-deploy TARGET_PROFILE=release; \
done
# vsix-specific cleanup
.PHONY: clean-execs
clean-execs:
rm -f superbol-free $(SUPERBOL_LSPs)
distclean: clean-execs vsix-clean
clean: clean-execs
.PHONY: node-setup
node-setup:
$(YARN) install
build-deps: node-setup
# ---
.PHONY: opam-cross
# Generates opam files for cross-compilation. We don't generate
# specific files for js-only packages. As a result we also forcibly
# remove a dependency to `superbol-vscode-platform` (which is js-only)
# from the platform-specific version of `superbol-studio-oss`. This is
# ok as those files are only there to grab external dependencies
# before cross-compiling.
opam-cross:
drom dep --cross osx
rm -f opam/osx/*-js-*.opam
rm -f opam/osx/vscode-debug*.opam
rm -f opam/osx/*-vscode-*.opam
sed -i '/"superbol-vscode-platform-osx"/ d' \
opam/osx/superbol-studio-oss-osx.opam
drom dep --cross windows
rm -f opam/windows/*-js-*.opam
rm -f opam/windows/vscode-debug*.opam
rm -f opam/windows/*-vscode-*.opam
sed -i '/"superbol-vscode-platform-windows"/ d' \
opam/windows/superbol-studio-oss-windows.opam
# emacs-lsp:
emacs/lsp-superbol-customs.el: $(LSP_MODE_SRCDIR) package.json
emacs --batch > "$@" \
--load "$(LSP_MODE_SRCDIR)/scripts/lsp-generate-settings.el" \
--eval "(dolist (l (lsp-generate-settings \"package.json\")) (print l))" \
&& echo "Generated $@" 1>&2 \
|| rm -f "$@"
# 8.0.1
# --eval "(princ (lsp-generate-settings \"package.json\" 'lsp-superbol))" \
# --eval '(princ "\n")' \
.PHONY: test-promote
test-promote: test-syntax-promote
opam exec -- dune runtest --auto-promote
.PHONY: test-syntax
test-syntax: superbol-lsp-server
\! opam exec -- autofonce 2>/dev/null || opam exec -- autofonce run -t syntax
.PHONY: test-syntax-promote
test-syntax-promote:
-$(MAKE) test-syntax # To avoid promoting past tests
\! opam exec -- autofonce 2>/dev/null || opam exec -- autofonce promote -t syntax --apply