aboutsummaryrefslogtreecommitdiff
path: root/makefile
diff options
context:
space:
mode:
Diffstat (limited to 'makefile')
-rw-r--r--makefile68
1 files changed, 68 insertions, 0 deletions
diff --git a/makefile b/makefile
new file mode 100644
index 0000000..1dd3151
--- /dev/null
+++ b/makefile
@@ -0,0 +1,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)