From 7228b2e1a2d0a8399facce3493d71a3569d250d5 Mon Sep 17 00:00:00 2001 From: mattkae Date: Fri, 23 Dec 2022 12:47:10 -0500 Subject: Improved the makefile considerably --- themes/Makefile | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'themes/Makefile') diff --git a/themes/Makefile b/themes/Makefile index 8bdc04e..bfe42a3 100644 --- a/themes/Makefile +++ b/themes/Makefile @@ -1,17 +1,44 @@ -CXX = emcc -EXE = dist/output.js -SRCS = $(wildcard *.cpp) -OBJS = $(patsubst %.cpp,%.o,$(SRCS)) +TARGET_EXEC ?= output.js + +BUILD_DIR ?= ./dist +SRC_DIRS ?= ./src + +CC := emcc +CXX := emcc +SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s) +OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) +DEPS := $(OBJS:.o=.d) + +INC_DIRS := $(shell find $(SRC_DIRS) -type d) +INC_FLAGS := $(addprefix -I,$(INC_DIRS)) LDFLAGS = -s ALLOW_MEMORY_GROWTH=1 -s USE_WEBGL2=1 -s FULL_ES3=1 -s WASM=1 -s NO_EXIT_RUNTIME=1 -s FETCH -all: build $(EXE) +CPPFLAGS ?= $(INC_FLAGS) -MMD -MP + +$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS) + $(CC) $(OBJS) -o $@ $(LDFLAGS) + +# assembly +$(BUILD_DIR)/%.s.o: %.s + $(MKDIR_P) $(dir $@) + $(AS) $(ASFLAGS) -c $< -o $@ -$(EXE): $(OBJS) - echo $(OBJS) - $(CXX) -o $(EXE) $(OBJS) $(LDFLAGS) +# c source +$(BUILD_DIR)/%.c.o: %.c + $(MKDIR_P) $(dir $@) + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ -build: - @mkdir -p dist +# c++ source +$(BUILD_DIR)/%.cpp.o: %.cpp + $(MKDIR_P) $(dir $@) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ + + +.PHONY: clean clean: - rm -rf dist && rm *.o \ No newline at end of file + $(RM) -r $(BUILD_DIR) + +-include $(DEPS) + +MKDIR_P ?= mkdir -p -- cgit v1.2.1