forked from Speech-Rule-Engine/speech-rule-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
149 lines (114 loc) · 3.64 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
#
# Makefile for Speech Rule Engine
# Copyright 2014-2021, Volker Sorge <[email protected]>
#
# This has been reduced to take care maps of only.
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 ./ts)
BIN_DIR = $(abspath ./bin)
LIB_DIR = $(abspath ./lib)
SRC = $(SRC_DIR)/**/*.ts
TARGET = $(LIB_DIR)/sre.js
MATHJAX = $(LIB_DIR)/mathjax-sre.js
JSON_SRC = $(abspath ./mathmaps)
JSON_DST = $(LIB_DIR)/mathmaps
MAPS = messages si functions symbols units rules
IEMAPS_FILE = $(IEMAPS_PKG)/mathmaps_ie.json
LOCALES = $(notdir $(wildcard $(JSON_SRC)/*)) ## $(foreach dir, $(MAPS), $(JSON_SRC)/$(dir))
LOC_DST = $(addprefix $(JSON_DST)/, $(addsuffix .json,$(LOCALES)))
JSON_MINIFY = npx json-minify
### Intermediate minified locale files for faster building
MINI_DIR = $(abspath ./minimaps)
JSON_FILES = $(wildcard $(foreach fd, $(LOCALES), $(foreach gd, $(MAPS), $(JSON_SRC)/$(fd)/$(gd)/*.json)))
MINI_SRC = $(foreach file, $(JSON_FILES), $(subst $(JSON_SRC)/, , $(file)))
# MINI_DST = $(foreach file, $(MINI_SRC), $(patsubst %.json, %.min, $(addprefix $(MINI_DIR)/, $(subst $(JSON_SRC)/, , $(file)))))
MINI_DST = $(patsubst %.json, %.min, $(JSON_FILES))
#######################################################################3
all: directories maps
directories: $(BIN_DIR) $(LIB_DIR)
$(BIN_DIR):
mkdir -p $(BIN_DIR)
$(LIB_DIR):
mkdir -p $(LIB_DIR)
clean: clean_json clean_mathjax
rm -f $(TARGET)
##################################################################
# Building the maps and publish the API via npm.
##################################################################
publish: 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).json"; \
rm -f $(JSON_DST)/$(LOC).json; \
fi
clean_mini:
rm -f $(MINI_DST)
%.min: %.json
@echo "Minifying " $@
@echo $<
@mkdir -p $(@D)
$(JSON_MINIFY) $(patsubst %.min, %.json, $@) > $@
$(LOC_DST): $(MINI_DST)
@echo "Creating mappings for locale `basename $@ .json`."
@echo '{' > $@
@for dir in $(MAPS); do\
if [ -d $(JSON_SRC)/`basename $@ .json`/$$dir ]; then \
for i in $(JSON_SRC)/`basename $@ .json`/$$dir/*.min; do\
echo '"'`basename $@ .json`/$$dir/`basename $$i`'": ' >> $@; \
cat $$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): $(MINI_DST)
@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/*.min; do\
echo '"'`basename $$j`/$$dir/`basename $$i`'": ' >> $(IEMAPS_FILE); \
cat $$i >> $@; \
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)
# Emacs-speak convenience
emacs: publish
@cp $(TARGET) ../emacs-math-speak/
##################################################################
# Other cleanup targets.
##################################################################
clean_mathjax:
rm -f $(MATHJAX)
clean_iemaps:
rm -f $(IEMAPS_FILE)
clean_json:
rm -rf $(JSON_DST)
clean_min:
rm $(MINI_DST)