-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile.in
92 lines (74 loc) · 2.87 KB
/
Makefile.in
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
THIRDPARTY_DIR = third_party
NPM_DIR = npm
LIB_DIR = .libs
FST_DIR = $(THIRDPARTY_DIR)/openfst
FST_INC_DIR = $(FST_DIR)/src/include
FST_LIB_DIR = $(FST_DIR)/src/lib/.libs
FSTSCRIPT_NPM_DIR = $(FST_DIR)/src/script/.libs
RE2_DIR = $(THIRDPARTY_DIR)/re2
RE2_LIB_DIR = $(RE2_DIR)/obj
RE2_INC_DIR = $(RE2_DIR)
ifeq ($(NPMBUILD),1)
EMFLAGS = -s EXPORTED_FUNCTIONS="['__regex2dfa']" -s ALLOW_MEMORY_GROWTH=1
else
EMFLAGS =
endif
OPTIMIZATION_FLAGS = -O3
CXXFLAGS_ = $(CXXFLAGS) $(OPTIMIZATION_FLAGS) -std=c++0x -DNO_THREADS -DUSE_CXX0X -Wall -fPIC -I. -Isrc -I$(THIRDPARTY_DIR) -I$(RE2_INC_DIR) -I$(FST_INC_DIR) $(EMFLAGS)
LDFLAGS_ = $(LDFLAGS) $(OPTIMIZATION_FLAGS) -L$(RE2_LIB_DIR) -L$(FST_LIB_DIR) -L$(FSTSCRIPT_NPM_DIR) -pthread -lre2 -lfst -lfstscript -ldl $(EMFLAGS)
OBJ_REGEX2DFA = src/regex2dfa.o src/main.o
OBJ_LIBREGEX2DFA = src/regex2dfa.o
OBJ_LIBREGEX2DFAJS = src/regex2dfa.o
TARGET_REGEX2DFA = bin/regex2dfa
TARGET_LIBREGEX2DFA = $(LIB_DIR)/libregex2dfa.a
TARGET_LIBREGEX2DFAJS = $(NPM_DIR)/regex2dfa.js
LIBREGEX2DFAJS_FOOTER = src/regex2dfa_footer.js
TARGET_LIBRE2 = $(RE2_LIB_DIR)/libre2.a
TARGET_FSTLIB = $(FST_DIR)/src/lib/.libs/libfst.a
TARGET_FSTSCRIPTLIB = $(FST_DIR)/src/script/.libs/libfstscript.a
TARGET_TEST = bin/test
all: $(TARGET_REGEX2DFA) $(TARGET_LIBREGEX2DFA)
$(TARGET_REGEX2DFA): $(OBJ_REGEX2DFA)
$(CXX) $(CXXFLAGS_) $(OBJ_REGEX2DFA) -o $@ $(LDFLAGS_)
$(TARGET_LIBREGEX2DFAJS): $(NPM_DIR) $(OBJ_LIBREGEX2DFAJS)
$(CXX) $(CXXFLAGS_) $(OBJ_LIBREGEX2DFAJS) -o $@ $(LDFLAGS_)
cat $(LIBREGEX2DFAJS_FOOTER) >> $(TARGET_LIBREGEX2DFAJS)
sed -i "s/module\[\"exports\"\]=Module/Module['exports']=Module/g" $(TARGET_LIBREGEX2DFAJS)
$(LIB_DIR):
mkdir -p $(LIB_DIR)
$(TARGET_LIBREGEX2DFA): $(LIB_DIR) $(OBJ_LIBREGEX2DFA)
# hack to upack all static libs and build up libregex2dfa
# TODO: investigate libtool
mkdir $(LIB_DIR)/re2
cp $(TARGET_LIBRE2) $(LIB_DIR)/re2
cd $(LIB_DIR)/re2 && ar x libre2.a
mkdir $(LIB_DIR)/fst
cp $(TARGET_FSTLIB) $(LIB_DIR)/fst
cp $(TARGET_FSTSCRIPTLIB) $(LIB_DIR)/fst
cd $(LIB_DIR)/fst && ar x libfst.a
cd $(LIB_DIR)/fst && ar x libfstscript.a
$(AR) rsc $(TARGET_LIBREGEX2DFA) $(OBJ_LIBREGEX2DFA) $(LIB_DIR)/re2/*.o $(LIB_DIR)/fst/*.o
rm -rf $(LIB_DIR)/re2
rm -rf $(LIB_DIR)/fst
$(NPM_DIR):
mkdir -p $(NPM_DIR)
$(OBJ_REGEX2DFA): $(TARGET_LIBRE2) $(TARGET_FSTLIB)
$(TARGET_FSTLIB):
cd $(FST_DIR) && $(MAKE)
$(TARGET_LIBRE2): $(RE2_DIR)/util/logging.h.fixed
cd $(RE2_DIR) && $(MAKE) obj/libre2.a
$(RE2_DIR)/util/logging.h.fixed:
sed 's/LogMessage/RE2LogMessage/g' $(RE2_DIR)/util/logging.h > $(RE2_DIR)/util/logging.h.tmp
mv $(RE2_DIR)/util/logging.h.tmp $(RE2_DIR)/util/logging.h
touch $(RE2_DIR)/util/logging.h.fixed
%.o: %.cc
$(CXX) $(CXXFLAGS_) -c -o $@ $<
test:
$(TARGET_TEST)
clean:
cd $(FST_DIR) && $(MAKE) clean
cd $(RE2_DIR) && $(MAKE) clean
rm -f $(TARGET_REGEX2DFA)
rm -f $(TARGET_LIBREGEX2DFA)
rm -f $(TARGET_LIBREGEX2DFAJS)
rm -vf */*.o