1# **************************************************************************** #
4# Makefile :+: :+: :+: #
6# By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ #
8# Created: 2025/05/29 22:58:19 by kamitsui #+# #+# #
9# Updated: 2025/06/03 01:42:13 by kamitsui ### ########.fr #
11# **************************************************************************** #
13#******************************************************************************#
14# @file ex03/Makefile #
15# @brief Build system for C++ Module 04 Exercise 03: "Interface & Recap". #
17# This Makefile orchestrates the compilation, linking, and management #
18# of all source files for Exercise 03. It's designed to automate the #
19# build process, manage object and dependency files, and provide #
20# convenient targets for cleaning, rebuilding, and running tests. #
22# @note This Makefile incorporates advanced features like automatic #
23# dependency generation (`-MMD -MP`) and integration with an external #
24# C++ module tester repository. #
26# @section features Features #
27# - **Automated Compilation:** Compiles all `.cpp` files into object files. #
28# - **Automatic Dependency Generation:** Generates `.d` files to ensure correct recompilation. #
29# - **Standard Targets:** Provides `all`, `clean`, `fclean`, `re`. #
30# - **Test Integration:** Includes a `test` target to interact with an external module tester. #
31# - **Output Management:** Creates `objs` and `.deps` directories. #
32# - **User Prompts:** Uses `ASK_AND_EXECUTE_ON_YES` for interactive commands. #
33# @section usage Usage #
34# - `make`: Builds the main executable (`a.out`). #
35# - `make clean`: Removes object and dependency files. #
36# - `make fclean`: Removes object, dependency, and the executable. #
37# - `make re`: Cleans and then rebuilds the project. #
38# - `make test`: Clones (if not present) and runs the associated test from the `cpp_module_tester` repository. #
39#******************************************************************************#
50 Cure.cpp Ice.cpp MateriaSource.cpp \
51 DroppedMateriaManager.cpp Logger.cpp
55# Object files and dependency files
56OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
57DEPS = $(addprefix $(DEP_DIR)/, $(SRCS:.cpp=.d))
66CXXFLAGS = -Wall -Wextra -Werror -std=c++98
67CF_DEP = -MMD -MP -MF $(@:$(OBJ_DIR)/%.o=$(DEP_DIR)/%.d)
69# Rules for building object files
71 $(CXX) $(CXXFLAGS) $(CF_DEP) -c $< -o $@
74all: directories $(NAME)
85 $(CXX) $(CXXFLAGS) $(OBJS) -o $(NAME)
86 $(call ASCII_ART,$(NAME))
89TEST_ROOT = ../../cpp_module_tester
90TEST_DIR = $(TEST_ROOT)/cpp04
91URL_TEST_CPP = "https://github.com/kamitsui/cpp_module_tester.git"
92TEST_TARGET = $(TEST_DIR)/ex03_app
98#ifeq ($(shell test -d $(TEST_DIR) && echo exist),)
99# @echo "Please clone the test repository"
100# $(call ASK_AND_EXECUTE_ON_YES, git clone $(URL_TEST_CPP) $(TEST_ROOT))
102# $(call ASK_AND_EXECUTE_ON_YES, make -C $(TEST_DIR) $(EX_NUM))
105# More Test : Enable Logger
112CXXFLAGS += -D DEBUG_MODE
115# Rule for removing object & dependency files
117 rm -rf $(OBJ_DIR) $(DEP_DIR) $(TEST_DIR)/objs $(TEST_DIR)/.deps
120# Rule for removing Target & others
122 rm -f $(NAME) $(TEST_TARGET)
125# Rule for Clean & Build Target
129# Enable dependency file
132# ASCII Art : Display Tips the way to use.
134 @echo " _____________________________________________"
136 @echo "< $$ ./a.out >"
139 @echo "< $$ make debug >"
140 @echo "< $$ ./a.out >"
142 @echo "< Test Case : >"
143 @echo "< $$ make test >"
144 @echo "----------------------------------------------"
146 @echo " \ (oo)\_______"
147 @echo " (__)\ )\\/\\"
153define ASK_AND_EXECUTE_ON_YES
154 @echo "Execute? $(1) (y/n)"
167# Makefile Option : Disable '--print-directory'
168MAKEFLAGS += --no-print-directory