feature(Makefile): pretty makefile, added -rdynamic LDFLAG, moved debug warning, added debug Makefile rule

This commit is contained in:
xtrm
2024-04-23 20:21:53 +02:00
parent 5af4c82c1b
commit 3b4a1de9f3
2 changed files with 75 additions and 55 deletions

120
Makefile
View File

@@ -6,96 +6,124 @@
# By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# 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