From 3b4a1de9f33df711d19f6ec07abb201b12109406 Mon Sep 17 00:00:00 2001 From: xtrm Date: Tue, 23 Apr 2024 20:21:53 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feature(Makefile):=20pretty=20makef?= =?UTF-8?q?ile,=20added=20`-rdynamic`=20LDFLAG,=20moved=20debug=20warning,?= =?UTF-8?q?=20added=20`debug`=20Makefile=20rule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 120 ++++++++++++++++++------------ src/renderer/core/render_core.cpp | 10 +-- 2 files changed, 75 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index c621183..bbc8780 100644 --- a/Makefile +++ b/Makefile @@ -6,96 +6,124 @@ # By: maldavid +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2022/10/04 16:43:41 by maldavid #+# #+# # -# Updated: 2024/01/10 14:20:30 by maldavid ### ########.fr # +# Updated: 2024/04/23 20:20:33 by kiroussa ### ########.fr # # # # **************************************************************************** # -NAME = libmlx.so +NAME = libmlx.so +MAKE = make --no-print-directory -SRCS = $(wildcard $(addsuffix /*.cpp, ./src/core)) -SRCS += $(wildcard $(addsuffix /*.cpp, ./src/platform)) -SRCS += $(wildcard $(addsuffix /*.cpp, ./src/renderer)) -SRCS += $(wildcard $(addsuffix /*.cpp, ./src/renderer/**)) +SRCS = $(wildcard $(addsuffix /*.cpp, src/core)) +SRCS += $(wildcard $(addsuffix /*.cpp, src/platform)) +SRCS += $(wildcard $(addsuffix /*.cpp, src/renderer)) +SRCS += $(wildcard $(addsuffix /*.cpp, src/renderer/**)) -OBJ_DIR = objs/makefile -OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o)) +OBJ_DIR = objs +OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o)) -OS = $(shell uname -s) -DEBUG ?= false -TOOLCHAIN ?= clang -IMAGES_OPTIMIZED ?= true -FORCE_INTEGRATED_GPU ?= false -GRAPHICS_MEMORY_DUMP ?= false -PROFILER ?= false +OS = $(shell uname -s) +DEBUG ?= false +TOOLCHAIN ?= clang +IMAGES_OPTIMIZED ?= true +FORCE_INTEGRATED_GPU ?= false +GRAPHICS_MEMORY_DUMP ?= false +PROFILER ?= false +_ENABLEDFLAGS = -MODE = "release" - -CXX = clang++ - -CXXFLAGS = -std=c++17 -O3 -fPIC -Wall -Wextra -Werror -DSDL_MAIN_HANDLED -INCLUDES = -I./includes -I./src -I./third_party - -LDLIBS = +CXX = clang++ +CXXFLAGS = -std=c++17 -O3 -fPIC -Wall -Wextra -Werror -DSDL_MAIN_HANDLED +INCLUDES = -I./includes -I./src -I./third_party ifeq ($(TOOLCHAIN), gcc) - CXX = g++ - CXXFLAGS += -Wno-error=cpp +CXX = g++ +CXXFLAGS += -Wno-error=cpp else - CXXFLAGS += -Wno-error=#warning +CXXFLAGS += -Wno-error=#warning endif ifeq ($(OS), Darwin) - LDLIBS += -L /opt/homebrew/lib -lSDL2 - CXXFLAGS += -I /opt/homebrew/include - NAME = libmlx.dylib +LDFLAGS += -L /opt/homebrew/lib -lSDL2 +CXXFLAGS += -I /opt/homebrew/include +NAME = libmlx.dylib endif ifeq ($(DEBUG), true) - CXXFLAGS += -g -D DEBUG - MODE = "debug" +CXXFLAGS += -g3 -D DEBUG +LDFLAGS += -rdynamic endif ifeq ($(FORCE_INTEGRATED_GPU), true) - CXXFLAGS += -D FORCE_INTEGRATED_GPU +_ENABLEDFLAGS += FORCE_INTEGRATED_GPU endif ifeq ($(IMAGES_OPTIMIZED), true) - CXXFLAGS += -D IMAGE_OPTIMIZED +_ENABLEDFLAGS += IMAGE_OPTIMIZED endif ifeq ($(GRAPHICS_MEMORY_DUMP), true) - CXXFLAGS += -D GRAPHICS_MEMORY_DUMP +_ENABLEDFLAGS += GRAPHICS_MEMORY_DUMP endif ifeq ($(PROFILER), true) - CXXFLAGS += -D PROFILER +_ENABLEDFLAGS += PROFILER endif +CXXFLAGS += $(addprefix -D, $(_ENABLEDFLAGS)) + RM = rm -rf +_RESET = $(shell tput sgr0) +_BOLD = $(shell tput bold) +_ITALIC = $(shell tput sitm) +_UNDER = $(shell tput smul) +_GREEN = $(shell tput setaf 2) +_YELLOW = $(shell tput setaf 3) +_RED = $(shell tput setaf 1) +_GRAY = $(shell tput setaf 8) +_PURPLE = $(shell tput setaf 5) + +ifeq ($(DEBUG), true) +MODE = $(_RESET)$(_PURPLE)$(_BOLD)Debug$(_RESET) +else +MODE = $(_RESET)$(_GREEN)$(_BOLD)Release$(_RESET) +endif + $(OBJ_DIR)/%.o: %.cpp - @printf "\033[1;32m[compiling... "$(MODE)" "$(CXX)"]\033[1;00m "$<"\n" + @mkdir -p $(dir $@) + @printf "$(MODE) $(_GRAY)|$(_RESET) Compiling $(_BOLD)$<$(_RESET) $(_GRAY)$(_ITALIC)($@)$(_RESET)\n" @$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@ all: $(NAME) -$(NAME): $(OBJ_DIR) $(OBJS) - @printf "\033[1;32m[linking ... "$(MODE)"]\033[1;00m "$@"\n" - @$(CXX) -shared -o $(NAME) $(OBJS) $(LDLIBS) - @printf "\033[1;32m[build finished]\033[1;00m\n" +$(NAME): $(OBJS) + @printf "$(MODE) $(_GRAY)|$(_RESET) Linking $(_BOLD)$(NAME)$(_RESET) $(_GRAY)$(_ITALIC)(from ./$(OBJ_DIR)/)$(_RESET)\n" + @$(CXX) -shared -o $(NAME) $(OBJS) $(LDFLAGS) + @printf "$(_BOLD)$(NAME)$(_RESET) compiled $(_GREEN)$(_BOLD)successfully$(_RESET)\n" -$(OBJ_DIR): - @mkdir -p $(sort $(addprefix $(OBJ_DIR)/, $(dir $(SRCS)))) - @printf "\033[1;32m[created objs directory]\033[1;00m\n" +_printbuildinfos: + @printf "$(_RED)$(_BOLD)Warning: $(_RESET)MLX is being compiled in $(MODE) mode.\n" + @printf "This activates $(_BOLD)Vulkan's validation layers$(_RESET) and $(_BOLD)MLX debug messages$(_RESET), which may impact rendering performances.\n\n" + + @printf "Building $(_BOLD)$(NAME)$(_RESET) in $(_BOLD)$(MODE)$(_RESET) mode\n" + @printf "\tOperating System: $(_BOLD)$(OS)$(_RESET)\n" + @printf "\tCompiler: $(_BOLD)$(CXX)$(_RESET)\n" + @printf "\tEnabled flags: $(_BOLD)$(_ENABLEDFLAGS)$(_RESET)\n" + @printf "\tCXXFLAGS: $(_BOLD)$(CXXFLAGS)$(_RESET)\n" + @printf "\tINCLUDES: $(_BOLD)$(INCLUDES)$(_RESET)\n" + @printf "\tLDFLAGS: $(_BOLD)$(LDFLAGS)$(_RESET)\n" + +debug: + @$(MAKE) _printbuildinfos DEBUG=true + @$(MAKE) all DEBUG=true -j clean: @$(RM) $(OBJ_DIR) - @printf "\033[1;32m[object files removed]\033[1;00m\n" + @printf "Cleaned $(_BOLD)$(OBJ_DIR)$(_RESET)\n" fclean: clean @$(RM) $(NAME) - @printf "\033[1;32m["$(NAME)" removed]\033[1;00m\n" + @printf "Cleaned $(_BOLD)$(NAME)$(_RESET)\n" re: fclean all -.PHONY: all clean fclean re +.PHONY: all clean debug fclean re diff --git a/src/renderer/core/render_core.cpp b/src/renderer/core/render_core.cpp index 1de3720..c96e6d6 100644 --- a/src/renderer/core/render_core.cpp +++ b/src/renderer/core/render_core.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/12/17 23:33:34 by maldavid #+# #+# */ -/* Updated: 2024/01/20 08:20:07 by maldavid ### ########.fr */ +/* Updated: 2024/04/23 20:09:14 by kiroussa ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,14 +16,6 @@ #include #include -#ifdef DEBUG - #ifdef MLX_COMPILER_MSVC - #pragma NOTE("MLX is being compiled in debug mode, this activates Vulkan's validation layers and debug messages which may impact rendering performances") - #else - #warning "MLX is being compiled in debug mode, this activates Vulkan's validation layers and debug messages which may impact rendering performances" - #endif -#endif - namespace mlx { namespace RCore