-
Notifications
You must be signed in to change notification settings - Fork 40
/
Makefile
127 lines (97 loc) · 3.24 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
#
# Makefile for Speech Rule Engine
# Copyright 2014-2022, Volker Sorge <[email protected]>
#
# This has been reduced to take care maps of only.
IEMAPS_PKG = $(abspath ../sre-mathmaps-ie)
# Ideally, no changes necessary beyond this point!
SRC_DIR = $(abspath ./ts)
LIB_DIR = $(abspath ./lib)
SRC = $(SRC_DIR)/**/*.ts
TARGET = $(LIB_DIR)/sre.js
JSON_SRC = $(abspath ./mathmaps)
JSON_DST = $(LIB_DIR)/mathmaps
MAPS = messages si characters 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 = pnpm 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 = $(patsubst %.json, %.min, $(JSON_FILES))
#######################################################################3
# Main Targets
all: directories maps
clean: clean_json clean_iemaps
rm -f $(TARGET)
#######################################################################3
directories: $(LIB_DIR)
$(LIB_DIR):
mkdir -p $(LIB_DIR)
##################################################################
# Building the maps and publish the API via npm.
##################################################################
$(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
%.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_iemaps:
rm -f $(IEMAPS_FILE)
clean_json:
rm -rf $(JSON_DST)
clean_min:
rm $(MINI_DST)