tuxanci2-engine
Game engine for tuxanci2
Log | Files | Refs | README | LICENSE
commit 9477413cf3ce2271c6d5f75f0360d35cbf32290c
parent 2ace7a1ef3d686a80a7af5e96d4ff00e51b954f3
Author: Connor Thomson <connor@gnufault.org>
Date: Sat, 31 Oct 2026 16:40:59 -0700
Add contents to engine.mk
Diffstat:
| M | engine.mk | | | 97 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 97 insertions(+), 0 deletions(-)
diff --git a/engine.mk b/engine.mk
@@ -0,0 +1,97 @@
+ENGINE ?= engine
+BUILD_DIR ?= build
+
+XXD ?= xxd
+CC ?= gcc
+AR ?= ar
+
+BITS ?= 32
+
+SRC ?= $(SRCS)
+CLEAN_SRC := $(patsubst ./%,%,$(SRC))
+RUNTIME_SRCS := $(sort $(foreach s,$(CLEAN_SRC),$(if $(wildcard $(s)/.),$(shell find $(patsubst %/,%,$(s)) -type f \( -name '*.c' -o -name '*.S' -o -name '*.s' \)),$(s))))
+RUNTIME_SRCS := $(patsubst ./%,%,$(RUNTIME_SRCS))
+
+RUNTIME_OBJS := $(patsubst %, $(BUILD_DIR)/runtime/%, $(RUNTIME_SRCS))
+RUNTIME_OBJS := $(RUNTIME_OBJS:.c=.o)
+RUNTIME_OBJS := $(RUNTIME_OBJS:.S=.o)
+RUNTIME_OBJS := $(RUNTIME_OBJS:.s=.o)
+
+ENGINE_DIR := $(ENGINE)
+ENGINE_SRCS := $(shell find $(ENGINE_DIR)/src -type f -name '*.c' | sort)
+ENGINE_OBJS := $(patsubst $(ENGINE_DIR)/src/%.c, $(BUILD_DIR)/engine/src/%.o, $(ENGINE_SRCS))
+
+CONFIG_HEADER := $(BUILD_DIR)/engine/include/ta_config.h
+FILES_HEADER := $(BUILD_DIR)/engine/include/ta_files.h
+
+ASSETS := $(shell find $(ENGINE_DIR)/font $(ENGINE_DIR)/images $(ENGINE_DIR)/files -type f -not -name 'LICENSE' 2>/dev/null | sort)
+asset_sym = $(shell printf '%s' 'ta_file_$(notdir $(basename $(1)))' | sed 's/[^a-zA-Z0-9_]/_/g')
+
+ASSET_GEN_SRCS := $(foreach a,$(ASSETS),$(BUILD_DIR)/engine/assets/$(notdir $(basename $(a))).c)
+ASSET_OBJS := $(ASSET_GEN_SRCS:.c=.o)
+
+ALL_ENGINE_OBJS := $(ENGINE_OBJS) $(ASSET_OBJS)
+ENGINE_LIB := $(BUILD_DIR)/engine/libtuxanci2-engine.a
+
+OUT ?= $(BUILD_DIR)/tuxanci2
+
+all: $(OUT)
+
+.PHONY: all clean FORCE
+
+define ASSET_RULE
+$(BUILD_DIR)/engine/assets/$(notdir $(basename $(1))).c: $(1)
+ mkdir -p $$(@D)
+ $$(XXD) -i -n $(call asset_sym,$(1)) $$< $$@
+endef
+$(foreach a,$(ASSETS),$(eval $(call ASSET_RULE,$(a))))
+
+$(CONFIG_HEADER): $(ENGINE_DIR)/include/ta_config.h.in
+ mkdir -p $(@D)
+ sed 's/\$$BITS/$(BITS)/g' $< > $@
+
+$(FILES_HEADER): FORCE
+ mkdir -p $(@D)
+ { \
+ printf '#ifndef TA_FILES_H\n#define TA_FILES_H\n\n'; \
+ $(foreach a,$(ASSETS),printf 'extern unsigned char %s[];\nextern unsigned int %s_len;\n' '$(call asset_sym,$(a))' '$(call asset_sym,$(a))';) \
+ printf '\n#endif // TA_FILES_H\n'; \
+ } > $@.tmp
+ if cmp -s $@.tmp $@; then rm -f $@.tmp; else mv $@.tmp $@; fi
+
+FORCE:
+
+$(BUILD_DIR)/engine/src/%.o: $(ENGINE_DIR)/src/%.c $(CONFIG_HEADER) $(FILES_HEADER)
+ mkdir -p $(@D)
+ $(CC) $(CFLAGS) -I$(ENGINE_DIR)/include -I$(BUILD_DIR)/engine/include -MMD -MP -c $< -o $@
+
+$(BUILD_DIR)/engine/assets/%.o: $(BUILD_DIR)/engine/assets/%.c $(CONFIG_HEADER)
+ mkdir -p $(@D)
+ $(CC) $(CFLAGS) -I$(ENGINE_DIR)/include -I$(BUILD_DIR)/engine/include -MMD -MP -c $< -o $@
+
+$(BUILD_DIR)/runtime/%.o: %.c $(CONFIG_HEADER)
+ mkdir -p $(@D)
+ $(CC) $(CFLAGS) -I$(ENGINE_DIR)/include -I$(BUILD_DIR)/engine/include -MMD -MP -c $< -o $@
+
+$(BUILD_DIR)/runtime/%.o: %.S $(CONFIG_HEADER)
+ mkdir -p $(@D)
+ $(CC) $(CFLAGS) $(ASFLAGS) -I$(ENGINE_DIR)/include -I$(BUILD_DIR)/engine/include -MMD -MP -c $< -o $@
+
+$(BUILD_DIR)/runtime/%.o: %.s $(CONFIG_HEADER)
+ mkdir -p $(@D)
+ $(CC) $(CFLAGS) $(ASFLAGS) -I$(ENGINE_DIR)/include -I$(BUILD_DIR)/engine/include -MMD -MP -c $< -o $@
+
+$(ENGINE_LIB): $(ALL_ENGINE_OBJS)
+ mkdir -p $(@D)
+ rm -f $@
+ $(AR) rcs $@ $^
+
+$(OUT): $(RUNTIME_OBJS) $(ENGINE_LIB)
+ mkdir -p $(@D)
+ $(CC) $(CFLAGS) $(RUNTIME_OBJS) $(ENGINE_LIB) $(LDFLAGS) $(LDLIBS) -o $@
+
+clean:
+ rm -rf $(BUILD_DIR)/engine $(BUILD_DIR)/runtime $(OUT)
+
+DEPS := $(ALL_ENGINE_OBJS:.o=.d) $(RUNTIME_OBJS:.o=.d)
+-include $(DEPS)