-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmakefile
79 lines (61 loc) · 1.72 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
MAKEFLAGS += -j12
CXX := em++
MODE ?= debug
SRCF := src/client/plugins/optimizer/src
TEMP := build/obj/$(MODE)
TARGET := lib/optimizer/$(MODE)
SRC := $(wildcard $(SRCF)/*.cpp) $(wildcard $(SRCF)/*/*.cpp) $(wildcard $(SRCF)/*/*/*.cpp)
OBJ := $(patsubst $(SRCF)/%.cpp,$(TEMP)/%.o,$(SRC))
DEP := $(patsubst $(SRCF)/%.cpp,$(TEMP)/%.d,$(SRC))
OUT := optimizer
CXXFLAG_dist = -O3 -fno-exceptions
CXXFLAG_debug = -g -Wno-limited-postlink-optimizations -sNO_DISABLE_EXCEPTION_CATCHING
LDFLAG_dist = -sENVIRONMENT=worker
LDFLAG_debug = -sENVIRONMENT=node
# https://emscripten.org/docs/tools_reference/emcc.html
# https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
CPPFLAGS := -I$(SRCF) -Ilib/nlopt -std=c++20
CXXFLAGS := $(CXXFLAG_$(MODE))
LDFLAGS :=\
-Llib/nlopt\
-lnlopt.slsqp.2.9.0\
$(LDFLAG_$(MODE))\
-sINITIAL_MEMORY=10MB\
-sALLOW_MEMORY_GROWTH\
-sASYNCIFY=1\
-sMIN_SAFARI_VERSION=120000\
-sASSERTIONS\
-sMAXIMUM_MEMORY=4GB\
-sEXPORT_ES6=1\
-sEXPORTED_RUNTIME_METHODS=ccall\
-sEXPORTED_FUNCTIONS=_malloc,_free
WASM := $(TARGET)/$(OUT).mjs
ifeq ($(OS),Windows_NT)
# Error is still possible in parallel running, so we add extra protection
MK = -@if not exist "$(@D)" mkdir "$(@D)" 2> NUL
RM = rmdir /s /q
else
MK = @mkdir -p "$(@D)"
endif
.PHONY: all
all: $(WASM)
$(WASM): $(OBJ) makefile
$(MK)
@echo Compiling [33m$(WASM)[0m
@$(LINK.cc) $(USRFLAGS) -o $@ $(OBJ)
@echo [33mWebAssembly compile complete![0m
$(TEMP)/%.o: $(SRCF)/%.cpp
$(MK)
@echo Compiling [32m$(patsubst $(SRCF)/%,%,$<)[0m
@$(COMPILE.cc) -MMD -c $< -o $@
# Ignoring old dependencies that were removed
%.h: ;
%.hpp: ;
%.d: ;
-include $(DEP)
.PHONY: clean
clean:
@$(RM) "$(TEMP)"
.PHONY: dist
dist:
@$(MAKE) MODE=dist --no-print-directory