This repository has been archived by the owner on Jul 30, 2022. It is now read-only.
forked from Speech-Rule-Engine/speech-rule-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
384 lines (307 loc) · 10.4 KB
/
Makefile
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#
# Makefile for Speech Rule Engine
# Copyright 2014-2016, Volker Sorge <[email protected]>
#
MODULE_NAME = node_modules
ifneq ($(wildcard ./$(MODULE_NAME)/.*),)
PREFIX = $(abspath .)
else
PREFIX =$(HOME)
endif
# Nodejs location.
NODEJS = node
NODE_MODULES = $(PREFIX)/$(MODULE_NAME)
IEMAPS_PKG = $(abspath ../sre-mathmaps-ie)
# Ideally, no changes necessary beyond this point!
SRC_DIR = $(abspath ./src)
BIN_DIR = $(abspath ./bin)
LIB_DIR = $(abspath ./lib)
SRC = $(SRC_DIR)/**/*.js
TARGET = $(LIB_DIR)/sre.js
DEPS = $(SRC_DIR)/deps.js
BROWSER = $(LIB_DIR)/sre_browser.js
MATHJAX = $(LIB_DIR)/mathjax-sre.js
SEMANTIC = $(LIB_DIR)/semantic.js
SEMANTIC_NODE = $(LIB_DIR)/semantic-node.js
ENRICH = $(LIB_DIR)/enrich.js
LICENSE = $(SRC_DIR)/license-header.txt
INTERACTIVE = $(LIB_DIR)/sre4node.js
JSON_SRC = $(SRC_DIR)/mathmaps
JSON_DST = $(LIB_DIR)/mathmaps
MAPS = si functions symbols units rules
IEMAPS_FILE = $(IEMAPS_PKG)/mathmaps_ie.js
LOCALES = $(notdir $(wildcard $(JSON_SRC)/*)) ## $(foreach dir, $(MAPS), $(JSON_SRC)/$(dir))
LOC_SRC = $(JSON_SRC)/* ## $(foreach dir, $(MAPS), $(JSON_SRC)/$(dir))
LOC_DST = $(addprefix $(JSON_DST)/, $(addsuffix .js,$(LOCALES)))
TEST_DIR = $(abspath ./sre-tests)
TEST_TARGET = $(LIB_DIR)/sre_test.js
TEST_RUNNER = $(TEST_DIR)/dist/sretest.js
TEST = $(BIN_DIR)/test_sre
JSDOC = $(NODE_MODULES)/.bin/jsdoc
JSDOC_FLAGS = -c $(PREFIX)/.jsdoc.json
DOCS = $(PREFIX)/docs
DOCS_SRC = $(DOCS)/src
DOCS_TESTS = $(DOCS)/tests
JSON_MINIFY = npx json-minify
##################################################################
# Error flags.
# Compiling as rigidly as possible.
# (Currently we use automatically all)
##################################################################
CLOSURE_ERRORS = accessControls\
checkDebuggerStatement\
checkRegExp\
checkTypes\
checkVars\
closureDepMethodUsageChecks\
conformanceViolations\
constantProperty\
const\
deprecatedAnnotations\
deprecated\
duplicateMessage\
duplicate\
es5Strict\
externsValidation\
extraRequire\
globalThis\
invalidCasts\
misplacedSuppress\
misplacedTypeAnnotation\
missingGetCssName\
missingProperties\
missingProvide\
missingRequire\
missingReturn\
nonStandardJsDocs\
strictModuleDepCheck\
strictPrimitiveOperators\
suspiciousCode\
tweakValidation\
typeInvalidation\
undefinedNames\
undefinedVars\
unknownDefines\
unusedLocalVariables\
unusedPrivateMembers\
untranspilableFeatures\
uselessCode\
violatedModuleDep\
visibility\
# reportUnknownTypes\
# strictCheckTypes\
# strictMissingProperties
MAKE_ERROR_FLAG = --jscomp_error=$(error)
ERROR_FLAGS = $(foreach error, $(CLOSURE_ERRORS), $(MAKE_ERROR_FLAG))
##################################################################
# Extern files.
# (Currently not used as they seem to be included automatically now.)
##################################################################
EXTERN_FILES = $(shell find $(SRC_DIR) -type f -name 'externs.js')
MAKE_EXTERN_FLAG = --externs=$(extern)
EXTERN_FLAGS = $(foreach extern, $(EXTERN_FILES), $(MAKE_EXTERN_FLAG))
COMPILER_FLAGS = $(EXTERN_FLAGS) $(ERROR_FLAGS)
## Node JS modules
# Closure compiler in nodejs.
# Linter in nodejs.
CLOSURE_LIB_NAME = google-closure-library
CLOSURE_LIB = $(NODE_MODULES)/$(CLOSURE_LIB_NAME)
CLOSURE_ROOT = $(CLOSURE_LIB)/closure/bin/build
GOOG_BASE = $(CLOSURE_LIB)/closure/goog/base.js
GOOG_BASE_CLEAN = $(CLOSURE_LIB)/sre_cleaned
COMPILER_JAR = $(NODE_MODULES)/google-closure-compiler/cli.js
CLOSURE_COMPILER = $(COMPILER_JAR) --dependency_mode=PRUNE $(GOOG_BASE) $(ERROR_FLAGS) $(EXTERN_FLAGS) '!**externs.js' --output_wrapper_file $(LICENSE)
DEPSWRITER = python $(CLOSURE_ROOT)/depswriter.py
space = $(null) #
comma = ,
LINT_EXCLUDE_FILES = deps.js,$(IEMAPS_FILE)
LINT_EXCLUDE_DIRS = $(JSON_SRC),$(NODE_MODULES),$(TEST_DIR)
LINT_ROOT = $(NODE_MODULES)/closure-linter-wrapper/tools/
GJSLINT = python $(LINT_ROOT)/gjslint.py --unix_mode --strict --jsdoc -x '$(LINT_EXCLUDE_FILES)' -e '$(LINT_EXCLUDE_DIRS)'
FIXJSSTYLE = python $(LINT_ROOT)/fixjsstyle.py --strict --jsdoc -x '$(LINT_EXCLUDE_FILES)' -e '$(LINT_EXCLUDE_DIRS)' -r
#######################################################################3
all: directories deps compile start_files maps
## This is a hack to get around a closure library problem.
$(GOOG_BASE_CLEAN):
@sed -i.bak s/"^.*@deprecated Use ES6.*"// $(GOOG_BASE)
@touch $(GOOG_BASE_CLEAN)
directories: $(BIN_DIR)
$(BIN_DIR):
mkdir -p $(BIN_DIR)
lint:
$(GJSLINT) -r $(SRC_DIR)
$(GJSLINT) --disable 0110 -r $(TEST_DIR)
fixjsstyle:
$(FIXJSSTYLE) $(SRC_DIR)
$(FIXJSSTYLE) $(TEST_DIR)
compile: $(TARGET)
$(TARGET): $(GOOG_BASE_CLEAN) $(SRC)
@echo Compiling Speech Rule Engine
@$(CLOSURE_COMPILER) --entry_point=goog:sre.Cli --entry_point=goog:sre.Api --js_output_file=$(TARGET) $^
deps: $(DEPS)
$(DEPS):
@echo Building Javascript dependencies $(DEPS)
@$(DEPSWRITER) --root_with_prefix="$(SRC_DIR) $(SRC_DIR)" > $(DEPS)
start_files: directories $(INTERACTIVE)
interactive: directories $(INTERACTIVE) deps maps
$(INTERACTIVE):
@echo "Making interactive script."
@echo "// This file is automatically generated. Do not edit!" > $@
@echo "" > $@
@echo "require('google-closure-library');" >> $@
@echo "// Rewrite google closure script for our purposes." >> $@
@echo "global.CLOSURE_IMPORT_SCRIPT = function(src, opt_sourceText) {" >> $@
@echo " if (opt_sourceText === undefined) {" >> $@
@echo " require((src[0] === '/' ? '' : './../') + src);" >> $@
@echo " } else {" >> $@
@echo " eval(opt_sourceText);" >> $@
@echo " }" >> $@
@echo " return true;" >> $@
@echo "};" >> $@
@echo "process.env.SRE_JSON_PATH = '$(JSON_DST)';" >> $@
@echo "require('$(DEPS)');" >> $@
@echo "goog.require('sre.System');" >> $@
@echo "sre.System.setAsync()" >> $@
clean: clean_test clean_semantic clean_browser clean_enrich clean_mathjax clean_json
rm -f $(TARGET)
rm -f $(DEPS)
rm -f $(INTERACTIVE)
##################################################################
# Test environment.
##################################################################
# Extern files.
##################################################################
test: directories deps test_compile test_script maps run_test
test_compile: $(TEST_TARGET)
$(TEST_TARGET): $(GOOG_BASE_CLEAN) $(SRC)
@echo Compiling test version of Speech Rule Engine
@$(CLOSURE_COMPILER) --entry_point=goog:sre.Global --js_output_file=$(TEST_TARGET) $^
test_script: $(TEST)
$(TEST):
@echo "Making test script."
@echo "#!/bin/bash" > $@
@echo "## This script is automatically generated. Do not edit!" >> $@
@echo "" >> $@
@echo "export SRE_JSON_PATH=$(JSON_DST)" >> $@
@echo "" >> $@
@echo $(NODEJS) $(TEST_RUNNER) "\$$@" >> $@
@chmod 755 $@
run_test: $(TEST_RUNNER)
@$(TEST)
$(TEST_RUNNER): $(TEST_DIR)/node_modules
@cd $(TEST_DIR); npm run prepare
@cd ..
## Using webpack instead.
## @cd $(TEST_DIR); npx webpack
$(TEST_DIR)/node_modules:
@cd $(TEST_DIR); npm install
@cd ..
clean_test:
rm -f $(TEST_TARGET)
rm -f $(TEST_RUNNER)
rm -f $(TEST)
rm -f tests
###
### This is for local tests, assuming that sre-tests repo is in parallel to the
### speech-rule-engine directory. This allows easier changes in sre-tests
### without having to bother with commits from a git submodule.
###
### Call with: make test_local TEST_DIR=tests
###
test_local: tests test
tests:
@ln -s ../sre-tests tests
@echo $(TEST_DIR)
##################################################################
# Publish the API via npm.
##################################################################
publish: clean compile browser maps
$(JSON_DST):
@echo "Creating JSON destination."
@mkdir -p $(JSON_DST)
maps: $(JSON_DST) clean_loc $(LOC_DST)
clean_loc:
@if ! [ -z $(LOC) ]; then \
echo "Deleting $(LOC).js"; \
rm -f $(JSON_DST)/$(LOC).js; \
fi
$(LOC_DST):
@echo "Creating mappings for locale `basename $@ .js`."
@echo '{' > $@
@for dir in $(MAPS); do\
if [ -d $(JSON_SRC)/`basename $@ .js`/$$dir ]; then \
for i in $(JSON_SRC)/`basename $@ .js`/$$dir/*.js; do\
echo '"'`basename $@ .js`/$$dir/`basename $$i`'": ' >> $@; \
$(JSON_MINIFY) $$i >> $@; \
echo ',' >> $@; \
done; \
fi; \
done
@sed '$$d' $@ > [email protected]
@echo '}' >> [email protected]
@echo '' >> [email protected]
@mv [email protected] $@
iemaps: $(JSON_DST) $(IEMAPS_FILE)
$(IEMAPS_FILE):
@echo "Creating mappings for IE."
@echo 'sre.BrowserUtil.mapsForIE = {' > $(IEMAPS_FILE)
@for j in $(LOCALES); do\
for dir in $(MAPS); do\
echo $(JSON_SRC)/$$j/$$dir;\
if [ -d $(JSON_SRC)/$$j/$$dir ]; then\
for i in $(JSON_SRC)/$$j/$$dir/*.js; do\
echo '"'`basename $$j`/$$dir/`basename $$i`'": ' >> $(IEMAPS_FILE); \
$(JSON_MINIFY) $$i >> $(IEMAPS_FILE); \
echo ',' >> $(IEMAPS_FILE); \
done; \
fi; \
done; \
done
@sed '$$d' $(IEMAPS_FILE) > $(IEMAPS_FILE).tmp
@echo '}' >> $(IEMAPS_FILE).tmp
@echo '' >> $(IEMAPS_FILE).tmp
@mv $(IEMAPS_FILE).tmp $(IEMAPS_FILE)
api: $(GOOG_BASE_CLEAN) $(SRC)
@echo Compiling Speech Rule Engine API
@$(CLOSURE_COMPILER) --entry_point=goog:sre.Api --js_output_file=$(TARGET) $^
##################################################################
# Other useful targets.
##################################################################
browser: $(BROWSER) maps
$(BROWSER): $(GOOG_BASE_CLEAN) $(SRC)
@echo Compiling browser ready Speech Rule Engine
@$(CLOSURE_COMPILER) --entry_point=goog:sre.Browser --js_output_file=$(BROWSER) $^
clean_browser:
rm -f $(BROWSER)
mathjax: $(MATHJAX) maps
$(MATHJAX): $(GOOG_BASE_CLEAN) $(SRC)
@echo Compiling MathJax ready Speech Rule Engine
@$(CLOSURE_COMPILER) --entry_point=goog:sre.Mathjax --js_output_file=$(MATHJAX) $^
clean_mathjax:
rm -f $(MATHJAX)
semantic: $(GOOG_BASE_CLEAN) $(SRC)
@echo Compiling browser ready Semantic Tree API
@$(CLOSURE_COMPILER) --entry_point=goog:sre.Semantic --js_output_file=$(SEMANTIC) $^
clean_semantic:
rm -f $(SEMANTIC)
semantic_node: $(GOOG_BASE_CLEAN) $(SRC)
@echo Compiling Semantic Tree API for Node
@$(CLOSURE_COMPILER) --entry_point=goog:sre.SemanticApi --js_output_file=$(SEMANTIC_NODE) $^
clean_semantic_node:
rm -f $(SEMANTIC_NODE)
enrich: $(GOOG_BASE_CLEAN) $(SRC)
@echo Compiling browser ready MathML Enrichment API
@$(CLOSURE_COMPILER) --entry_point=goog:sre.Enrich --js_output_file=$(ENRICH) $^
clean_enrich:
rm -f $(ENRICH)
emacs: publish
@cp $(TARGET) ../emacs-math-speak/
docs: $(JSDOC)
@$(JSDOC) $(JSDOC_FLAGS) $(SRC) -r -d $(DOCS_SRC)
@$(JSDOC) $(JSDOC_FLAGS) $(TEST_DIR) -r -d $(DOCS_TESTS)
clean_docs:
rm -rf $(DOCS)
clean_iemaps:
rm -f $(IEMAPS_FILE)
clean_json:
rm -rf $(JSON_DST)