summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile27
1 files changed, 22 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 98e6346..49823c8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,5 @@
CC ?= gcc
+CC ?= g++
SRCDIR ?= src
INCDIR ?= inc
@@ -6,11 +7,13 @@ OBJDIR ?= obj
TSTDIR ?= test
EXMDIR ?= examples
-LIBS = -lm
-INCS = -Ithirdparty/cglm/include -Iinc/
+PKGS = sdl2 opengl
+LIBS = -lm $(shell pkg-config --libs $(PKGS))
+INCS = -Ithirdparty/cglm/include -Ithirdparty/ -Iinc/
CFLAGS ?= -D_FORTIFY_SOURCE=2 -Wall -Werror -Wno-error=unused-variable -g -Og
-CFLAGS += -std=gnu23 -fms-extensions -flto
+CFLAGS += -std=gnu23 -fms-extensions -flto $(shell pkg-config --cflags $(PKGS)) -DCIMGUI_USE_OPENGL3 -DCIMGUI_USE_SDL2
+CXXFLAGS += -flto $(shell pkg-config --cflags $(PKGS)) -DCIMGUI_USE_OPENGL3 -DCIMGUI_USE_SDL2 -DIMGUI_IMPL_API='extern "C"'
APP_MAIN_SOURCES = $(SRCDIR)/main.c
APP_MAIN_OBJS = $(APP_MAIN_SOURCES:%.c=$(OBJDIR)/%.o)
@@ -30,6 +33,8 @@ EXM_OBJS = $(EXM_SOURCES:%.c=$(OBJDIR)/%.o)
EXM_DEPS = $(EXM_OBJS:%.o=%.d)
EXM_APPS = $(EXM_SOURCES:%.c=$(OBJDIR)/%)
+IMGUI_OBJS = $(OBJDIR)/thirdparty/cimgui/imgui/backends/imgui_impl_sdl2.o $(OBJDIR)/thirdparty/cimgui/imgui/backends/imgui_impl_opengl3.o
+
-include $(APP_DEPS) $(APP_MAIN_DEPS) $(TST_DEPS) $(EXM_DEPS)
# We don't really need to run the tests for bear to record them
@@ -37,8 +42,14 @@ compile_commands.json: clean Makefile $(APP_SOURCES)
@rm -f "$@"
bear -- make main
-main: $(APP_MAIN_OBJS) $(APP_OBJS)
- $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(APP_MAIN_OBJS) $(APP_OBJS) $(LIBS)
+.PHONY: thirdparty/cimgui/cimgui.so
+thirdparty/cimgui/cimgui.so:
+ make -C thirdparty/cimgui
+
+LIBS += -Lthirdparty/cimgui -Wl,-rpath,'$$ORIGIN/thirdparty/cimgui' -lcimgui -lstdc++
+
+main: $(APP_MAIN_OBJS) $(APP_OBJS) thirdparty/cimgui/cimgui.so $(IMGUI_OBJS)
+ $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(APP_MAIN_OBJS) $(APP_OBJS) $(IMGUI_OBJS) $(LIBS)
$(OBJDIR)/%.o: %.c
@mkdir -p $(dir $@)
@@ -55,6 +66,7 @@ $(OBJDIR)/examples/%: $(OBJDIR)/examples/%.o $(APP_OBJS)
clean:
@rm -rf $(OBJDIR)
@rm -f main
+ @make -C thirdparty/cimgui clean
test: $(TST_APPS)
@echo "Running tests"
@@ -64,3 +76,8 @@ examples: $(EXM_APPS)
.DEFAULT_GOAL := all
all: main test examples
+
+# Imgui specific compile rules
+$(OBJDIR)/%.o: %.cpp
+ @mkdir -p $(dir $@)
+ $(CXX) $(CXXFLAGS) $(INCS) -Ithirdparty/cimgui/imgui/ -MMD -o $@ -c $<