-
Notifications
You must be signed in to change notification settings - Fork 6
/
makefile-emcc
77 lines (57 loc) · 2.19 KB
/
makefile-emcc
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
DEBUG ?= 0
# File names
ifeq ($(DEBUG),1)
EXEC = ./bin/emscripten/Debug/Graphoffline.Emscripten.js
else
EXEC = ./bin/emscripten/Release/Graphoffline.Emscripten.js
endif
LIB_DIR = ./lib
ALGORITHM_DIR = algorithm
PUGIXML_DIR = pugixml
REPORT_DIR = report
COMMON_DIR = common
GRAPH_DIR = graph
OBJ_DIR = bin/emscripten/obj
# Declaration of variables
CXX = emcc
CPPFLAGS += -std=c++17 -Wall -I. -I $(ALGORITHM_DIR) -I $(PUGIXML_DIR) -I $(REPORT_DIR) -I $(COMMON_DIR) -I $(GRAPH_DIR) -I $(LIB_DIR) -DEMSCRIPT
LINKFLAGS += -s EXPORTED_FUNCTIONS='_ProcessAlgorithm' -s EXPORTED_RUNTIME_METHODS=ccall,cwrap
ifeq ($(DEBUG),1)
CPPFLAGS += -g --emit-symbol-map -sWASM=2 -sALLOW_MEMORY_GROWTH=1
else
CPPFLAGS += -O3
endif
SOURCES = $(wildcard *.cpp) $(shell find $(ALGORITHM_DIR) $(PUGIXML_DIR) $(REPORT_DIR) $(COMMON_DIR) $(GRAPH_DIR) -name '*.cpp')
HEADERS = $(wildcard *.h) $(shell find $(ALGORITHM_DIR) $(PUGIXML_DIR) $(REPORT_DIR) $(COMMON_DIR) $(GRAPH_DIR) -name '*.h')
# Create obejcts files in $(OBJ_DIR)
OBJECTS = $(patsubst %.cpp,$(OBJ_DIR)/%.o, $(SOURCES))
# Main target
$(EXEC): $(OBJ_DIR)/$(GRAPH_DIR) $(OBJ_DIR)/$(COMMON_DIR) $(OBJ_DIR)/$(REPORT_DIR) $(OBJ_DIR)/$(ALGORITHM_DIR) $(OBJ_DIR)/$(PUGIXML_DIR) $(OBJECTS)
$(CXX) $(CPPFLAGS) $(OBJECTS) $(LINKFLAGS) -o $(EXEC)
# To obtain object files
$(OBJ_DIR)/$(ALGORITHM_DIR)/%.o: $(ALGORITHM_DIR)/%.cpp $(HEADERS)
$(CXX) -c $(CPPFLAGS) $< -o $@
$(OBJ_DIR)/$(PUGIXML_DIR)/%.o: $(PUGIXML_DIR)/%.cpp $(HEADERS)
$(CXX) -c $(CPPFLAGS) $< -o $@
$(OBJ_DIR)/$(REPORT_DIR)/%.o: $(REPORT_DIR)/%.cpp $(HEADERS)
$(CXX) -c $(CPPFLAGS) $< -o $@
$(OBJ_DIR)/$(COMMON_DIR)/%.o: $(COMMON_DIR)/%.cpp $(HEADERS)
$(CXX) -c $(CPPFLAGS) $< -o $@
$(OBJ_DIR)/$(GRAPH_DIR)/%.o: $(GRAPH_DIR)/%.cpp $(HEADERS)
$(CXX) -c $(CPPFLAGS) $< -o $@
$(OBJ_DIR)/%.o: %.cpp $(HEADERS)
$(CXX) -c $(CPPFLAGS) $< -o $@
# make dirs
$(OBJ_DIR)/$(ALGORITHM_DIR):
mkdir -p $(OBJ_DIR)/$(ALGORITHM_DIR)
$(OBJ_DIR)/$(PUGIXML_DIR):
mkdir -p $(OBJ_DIR)/$(PUGIXML_DIR)
$(OBJ_DIR)/$(REPORT_DIR):
mkdir -p $(OBJ_DIR)/$(REPORT_DIR)
$(OBJ_DIR)/$(COMMON_DIR):
mkdir -p $(OBJ_DIR)/$(COMMON_DIR)
$(OBJ_DIR)/$(GRAPH_DIR):
mkdir -p $(OBJ_DIR)/$(GRAPH_DIR)
# To remove generated files
clean:
rm -f $(EXEC) $(OBJECTS)