aboutsummaryrefslogtreecommitdiff
path: root/makefile
blob: babe492fb28b8d6b987bec9a580a697c68863706 (plain)
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
EMCC = emcc
EMCPP = em++

CFLAGS += -Wall -Wextra -Wno-unused-function -g
CFLAGS += -Isrc

EMSCRIPT_FLAGS := $(CFLAGS) -lembind
EMSCRIPT_FLAGS += -static --bind
EMSCRIPT_FLAGS += -fwasm-exceptions

CXXFLAGS = $(CFLAGS) -std=c++20 -fwasm-exceptions

TEST_FLAGS = $(CXXFLAGS) -Itest/include -DTEST


SRC_VIEW = src/view
SRC_CONTROLLERS = src/controllers
SRC_MODELS = src/models

OBJS := src/models/wg2nd.o

C_OBJS := src/models/crypto/halfsiphash.o
C_OBJS += src/models/crypto/curve25519.o
C_OBJS += src/models/crypto/encoding.o
C_OBJS += src/models/crypto/pubkey.o

TEST_DIR=test
TEST_BUILD_DIR=$(TEST_DIR)/build
TESTS=timer_test
TEST_TARGETS := $(patsubst %, $(TEST_BUILD_DIR)/%, $(TESTS))

DIST_DIR = dist
DIST_BUILD_DIR = $(DIST_DIR)/build

# DIST_OBJS := $(patsubst %, $(DIST_BUILD_DIR)/%, $(OBJS))
# DIST_C_OBJS := $(patsubst %, $(DIST_BUILD_DIR)/%, $(C_OBJS))

CONTROLLERS := $(wildcard $(SRC_CONTROLLERS)/*.cpp)
CONTROLLER_HARNESSES := $(patsubst $(SRC_CONTROLLERS)/%.cpp, $(DIST_BUILD_DIR)/%.js, $(CONTROLLERS))

VIEW_DIRECTORIES=$(patsubst $(SRC_VIEW)/%, $(DIST_DIR)/%, $(shell find $(SRC_VIEW) -type d))
VIEW_FILES=$(patsubst $(SRC_VIEW)/%, $(DIST_DIR)/%, $(shell find $(SRC_VIEW) -type f))

.PHONY: all clean run test

all: $(DIST_DIR) $(VIEW_DIRECTORIES) $(VIEW_FILES) $(CONTROLLER_HARNESSES)

test: $(TEST_TARGETS)

$(OBJS): %.o: %.cpp
	$(EMCPP) $(CXXFLAGS) -c -o $@ $<

$(C_OBJS): %.o: %.c
	$(EMCC) $(CFLAGS) -c -o $@ $<

$(DIST_BUILD_DIR)/%.js: src/controllers/browser.cpp $(OBJS) $(C_OBJS) $(DIST_BUILD_DIR)
	$(EMCPP) -o $@ $(EMSCRIPT_FLAGS) $(filter %.cpp %.o %.a, $^)

$(VIEW_DIRECTORIES):
	mkdir -p $@

$(DIST_DIR)/%: $(SRC_VIEW)/%
	cp $^ $@

$(DIST_DIR):
	mkdir -p $(DIST_DIR)

$(DIST_BUILD_DIR): $(DIST_DIR)
	mkdir -p $(DIST_BUILD_DIR)

$(TEST_BUILD_DIR):
	mkdir -p $(TEST_BUILD_DIR)

$(TEST_BUILD_DIR)/%: $(TEST_BUILD_DIR) $(TEST_DIR)/%.cpp $(SRC_MODELS)/*.cpp
	$(CPP) $(TEST_FLAGS) -o $@ $(filter %.cpp, $^)

run: # requires flask
	python serve.py

watch: # requires nodemon
	nodemon -w "./src" --exec "make" -e "js,html,css,cpp,hpp"

clean:
	rm -rf $(DIST_DIR) $(OBJS) $(C_OBJS) $(TEST_BUILD_DIR)