From b479742884c258a905432986e84d30fc6ffdee11 Mon Sep 17 00:00:00 2001 From: Emile Clark-Boman Date: Sat, 27 Sep 2025 13:27:15 +1000 Subject: [PATCH] transfer RENA project deps+make to enby --- Makefile | 51 +++++++++++++++++++++++++++++++++++ config.mk | 13 +++++++++ deps/Makefile | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ mk | 2 ++ 4 files changed, 141 insertions(+) create mode 100644 Makefile create mode 100644 config.mk create mode 100644 deps/Makefile create mode 100755 mk diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6526605 --- /dev/null +++ b/Makefile @@ -0,0 +1,51 @@ +.DEFAULT_GOAL := all + +include config.mk + +# === BUILD ENVIRONMENT === +BIN := bin +BUILD := build + +LIB := lib + +# === MACRO DEFINITIONS === +define objpath +$(addprefix $(BUILD)/, + $(addsuffix .o, + $(basename $(1)))) +endef +define mkobj +$(foreach DEP, $?, + mkdir -p $(dir $(call objpath, $(DEP))) + $(CC) $(CFLAGS) $1 -o $(call objpath, $(DEP)) -c $(DEP)) + +$(LD) -r $(LDFLAGS) -o $@ $(call objpath, $?) +endef + +# === BUILD TARGETS === +all: + +.PHONY: tests +tests: $(BIN) $(BIN)/test-imgui-sdl3glfw3 $(BIN)/test-custom + +$(BIN)/test-imgui-sdl3glfw3: + $(CXX) -o $@ sandbox/$(notdir $@).cpp -Ideps -Ideps/imgui -Ldeps -limgui -lSDL3 -lGL -lm +$(BIN)/test-custom: + $(CXX) -o $@ sandbox/$(notdir $@).cpp -Ideps -Ideps/imgui -Ldeps -limgui -lSDL3 -lGL -lm +$(BUILD) $(BIN): + mkdir -p $@ + +# === DEVELOPMENT TARGETS === +# .PHONY: debug run test +# debug: +# $(MAKE) all \ +# CFLAGS="$(CFLAGS) $(CFLAGS_DBG)" \ +# CLDFLAGS="$(CLDFLAGS) $(CLDFLAGS_DBG)" +# run: debug +# - command $(BIN)/pw-test +# test: clean run + +# === UTILITY TARGETS === +.PHONY: clean +clean: + - rm -rf $(BUILD) $(BIN) vgcore.* &>/dev/null logs/ diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..86f4764 --- /dev/null +++ b/config.mk @@ -0,0 +1,13 @@ +# === C Compiler Configuration === +CC := gcc +CFLAGS := -Wall -Wextra -std=gnu23 -O +CDEBUG := -g + +# === C++ Compiler Configuration === +CXX := gcc -xc++ -lstdc++ -shared-libgcc +CXXFLAGS := -Wall -Wextra -O +CXXDEBUG := -g + +# === Linker Configuration === +LD := ld +LDFLAGS := diff --git a/deps/Makefile b/deps/Makefile new file mode 100644 index 0000000..691105c --- /dev/null +++ b/deps/Makefile @@ -0,0 +1,75 @@ +.DEFAULT_GOAL := all + +CXX := gcc -xc++ -lstdc++ -shared-libgcc + +BUILD := build +DEPS := imgui +SYNC := $(addsuffix -sync, $(DEPS)) + +# imgui_impl_allegro5.o imgui_impl_android.o imgui_impl_dx9.o +# imgui_impl_dx10.o imgui_impl_dx11.o imgui_impl_dx12.o +# imgui_impl_glfw.o imgui_impl_glut.o imgui_impl_opengl2.o +# imgui_impl_opengl3.o imgui_impl_sdl2.o imgui_impl_sdl3.o +# imgui_impl_sdlgpu3.o imgui_impl_sdlrenderer2.o imgui_impl_sdlrenderer3.o +# imgui_impl_vulkan.o imgui_impl_wgpu.o imgui_impl_win32.o + +# === DEAR IMGUI = VALID BACKENDS === +# allegro5 glfw sdlgpu3 +# android glut sdlrenderer2 +# dx9 opengl2 sdlrenderer3 +# dx10 opengl3 vulkan +# dx11 sdl2 wgpu +# dx12 sdl3 win32 +IMGUI_ENABLE_BACKENDS := sdl3 opengl3 + +# Dear ImGui +IMGUI_UPSTREAM := https://github.com/ocornut/imgui.git +IMGUI_BRANCH := docking +IMGUI_TAG := v1.92.3-docking + +IMGUI_BACKENDS := $(foreach backend, $(IMGUI_ENABLE_BACKENDS), imgui_impl_$(backend).o) + +IMGUI_OBJS := imgui.o imgui_demo.o \ + imgui_draw.o imgui_tables.o imgui_widgets.o \ + imgui_freetype.o imgui_stdlib.o \ + $(addprefix backends/, $(IMGUI_BACKENDS)) + +STATICLIBS := $(foreach dep, $(DEPS), lib$(dep).a) + +# === BUILD TARGETS === +all: $(BUILD) $(STATICLIBS) +$(BUILD): + mkdir -p $(addprefix $(BUILD)/, $(DEPS)) + +libimgui.a: imgui $(addprefix $(BUILD)/imgui/, $(IMGUI_OBJS)) + ar rcs $@ $(filter %.o, $^) + +$(BUILD)/imgui/imgui_stdlib.o: imgui/misc/cpp/imgui_stdlib.cpp + $(CXX) -c $^ -o $@ -Iimgui +$(BUILD)/imgui/imgui_freetype.o: imgui/misc/freetype/imgui_freetype.cpp + $(CXX) -c $^ -o $@ -Iimgui +$(BUILD)/imgui/backends/%.o: imgui/backends/%.cpp + mkdir -p $(dir $@) + $(CXX) -c $^ -o $@ -Iimgui +$(BUILD)/imgui/%.o: imgui/%.cpp + $(CXX) -c $^ -o $@ + +# === SYNC TARGETS === +.PHONY: sync $(SYNC) +sync: $(SYNC) + +imgui: + mkdir -p $@ + - git -C $@ init + - git -C $@ remote add upstream $(IMGUI_UPSTREAM) + $(MAKE) $@-sync +imgui-sync: imgui + git -C $< fetch upstream --tags + git -C $< -c advice.detachedHead=false checkout $(IMGUI_TAG) + +# === UTILITY TARGETS === +.PHONY: clean purge +clean: + rm -rf $(BUILD) $(STATICLIBS) +purge: clean + rm -rf $(DEPS) diff --git a/mk b/mk new file mode 100755 index 0000000..8b114a6 --- /dev/null +++ b/mk @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +$([ -x "$(command -v bear)" ] && echo 'bear -- ') make $@