From e6e8b2c9353fc928f46b95aedaef1f025178be30 Mon Sep 17 00:00:00 2001 From: Emmanuel Benoit Date: Mon, 2 Oct 2017 10:00:39 +0200 Subject: [PATCH] Build in separate directory --- .gitignore | 1 + Makefile | 59 +++++++++++++++++++++++++++++------------------------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 07056f0..ffb88be 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ imgui.ini .*.d .vim.local/data/* .vim.local/signature +output/ diff --git a/Makefile b/Makefile index 02ffc37..ea87301 100644 --- a/Makefile +++ b/Makefile @@ -1,38 +1,45 @@ +OUTDIR = output + CXXFLAGS += $(shell sdl2-config --cflags) -std=c++14 -Wall -g CFLAGS += $(shell sdl2-config --cflags) -CPPFLAGS += -I. -Iimgui -Iglm \ +CPPFLAGS += -I. -I$(OUTDIR) -Iimgui -Iglm \ -DREAL_BUILD -DGLM_ENABLE_EXPERIMENTAL LIBS += $(shell sdl2-config --libs) -lGL -lGLEW -ldl FILEDUMPS = -IMGUI = imgui.o imgui_demo.o imgui_draw.o +IMGUI = imgui.cpp imgui_draw.cpp DEMO = \ - main.o \ - imgui_impl_sdl.o \ + main.cc \ + imgui_impl_sdl.cc \ \ - utilities.o \ - texture.o \ - rendertarget.o \ - programs.o \ + utilities.cc \ + texture.cc \ + rendertarget.cc \ + programs.cc \ \ - raymarcher.o \ + raymarcher.cc \ \ - bloom.o \ - dof.o \ - combine.o \ + bloom.cc \ + dof.cc \ + combine.cc \ \ - profiling.o - -DEMO_DEPS = $(DEMO:%.o=.%.d) + profiling.cc -demo: $(DEMO) $(IMGUI) +IMGUI_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(IMGUI)))) +DEMO_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(DEMO)))) +OBJS = $(IMGUI_OBJS) $(DEMO_OBJS) +PCH=externals.hh.gch + +DEMO_DEPS = $(DEMO_OBJS:$(OUTDIR)/%.o=$(OUTDIR)/%.d) + +demo: $(OBJS) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o demo \ - $(DEMO) $(IMGUI) $(LIBS) + $(OBJS) $(LIBS) clean: - rm -f $(IMGUI) $(DEMO) $(FILEDUMPS) demo externals.hh.gch + rm -f $(OBJS) $(FILEDUMPS) demo $(PCH) fullclean: clean rm -f $(DEMO_DEPS) @@ -44,20 +51,18 @@ $(FILEDUMPS): fd-%.h: % xxd -i $< $@ -imgui.o: imgui/imgui.cpp - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< +outdir: + @if ! [ -d "$(OUTDIR)" ]; then mkdir "$(OUTDIR)"; fi +.PHONY: outdir -imgui_demo.o: imgui/imgui_demo.cpp - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< - -imgui_draw.o: imgui/imgui_draw.cpp +$(IMGUI_OBJS): $(OUTDIR)/%.o: imgui/%.cpp | outdir $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< -include $(DEMO_DEPS) -$(DEMO): %.o: %.cc externals.hh.gch | $(FILEDUMPS) +$(DEMO_OBJS): $(OUTDIR)/%.o: %.cc $(PCH) | outdir $(FILEDUMPS) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -M -MF $(@:%.o=.%.d) -MT $@ $< + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -M -MF $(@:%.o=%.d) -MT $@ $< -externals.hh.gch: externals.hh +$(PCH): externals.hh $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<