aboutsummaryrefslogtreecommitdiff
path: root/makefile
blob: 1dd3151d600f248dd804f83ee3f0440d2a0f3187 (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
EMCPP = /usr/lib/emscripten/emcc
CPP = /opt/emscripten-llvm/bin/clang++
CXXFLAGS = -std=c++20
CXXFLAGS += -Wall -Wextra -Wno-unused-function
CXXFLAGS += -Isrc
EMSCRIPT_FLAGS = $(CXXFLAGS) -lembind --bind
TEST_FLAGS = $(CXXFLAGS) -Itest/include -DTEST

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

OBJS := models/timer.o
OBJS += models/counter.o
OBJS += utils/utils.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))

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)

$(DIST_BUILD_DIR)/%.js: $(SRC_CONTROLLERS)/%.cpp $(DIST_OBJS) $(DIST_BUILD_DIR)
	$(EMCPP) $(EMSCRIPT_FLAGS) -o $@ $(filter %.cpp %.o, $^)

$(DIST_BUILD_DIR)/%.o: src/%.cpp
	mkdir -p $(basename $@)
	$(EMCPP) $(CXXFLAGS) -c -o $@ $<

$(VIEW_DIRECTORIES):
	mkdir -p $@

$(VIEW_FILES):
	cp $(patsubst $(DIST_DIR)/%,$(SRC_VIEW)/%,$@) $@

$(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:
	python serve.py

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