1# **************************************************************************** #
4# Makefile :+: :+: :+: #
6# By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ #
8# Created: 2025/05/20 16:30:43 by kamitsui #+# #+# #
9# Updated: 2025/06/03 12:36:58 by kamitsui ### ########.fr #
11# **************************************************************************** #
13#******************************************************************************#
14# @file ex00/Makefile #
15# @brief Makefile for C++ Module 04 Exercise 00. #
17# This Makefile automates the compilation and linking process for the #
18# Animal, Dog, Cat, WrongAnimal, and WrongCat classes, along with the main #
19# test program. It provides standard targets for building, cleaning, and #
20# recompiling the project. #
23# all: Builds the main executable. #
24# clean: Removes all object files (.o). #
25# fclean: Removes all object files and the executable. #
26# re: Cleans the project and then rebuilds it. #
27#******************************************************************************#
34SRCS = main.cpp Animal.cpp Cat.cpp Dog.cpp WrongAnimal.cpp WrongCat.cpp \
35 Tests.cpp TestRaii.cpp
37# Object files and dependency files
38OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
39DEPS = $(addprefix $(DEP_DIR)/, $(SRCS:.cpp=.d))
46CXXFLAGS = -Wall -Wextra -Werror -std=c++98
47CF_DEP = -MMD -MP -MF $(@:$(OBJ_DIR)/%.o=$(DEP_DIR)/%.d)
49# Rules for building object files
51 $(CXX) $(CXXFLAGS) $(CF_DEP) -c $< -o $@
54all: directories $(NAME)
65 $(CXX) $(CXXFLAGS) $(OBJS) -o $(NAME)
66 $(call ASCII_ART,$(NAME))
69TEST_ROOT = ../../cpp_module_tester
70TEST_DIR = $(TEST_ROOT)/cpp04
71URL_TEST_CPP = "https://github.com/kamitsui/cpp_module_tester.git"
72TEST_TARGET = $(TEST_DIR)/ex00_app
77ifeq ($(shell test -d $(TEST_DIR) && echo exist),)
78 @echo "Please clone the test repository"
79 $(call ASK_AND_EXECUTE_ON_YES, git clone $(URL_TEST_CPP) $(TEST_ROOT))
81 $(call ASK_AND_EXECUTE_ON_YES, make -C $(TEST_DIR) $(EX_NUM))
84# Rule for removing object & dependency files
86 rm -rf $(OBJ_DIR) $(DEP_DIR) $(TEST_DIR)/objs $(TEST_DIR)/.deps
89# Rule for removing Target & others
91 rm -f $(NAME) $(TEST_TARGET)
94# Rule for Clean & Build Target
98# Enable dependency file
101# ASCII Art : Display Tips the way to use.
103 @echo " _____________________________________________"
105 @echo "< $$ ./a.out >"
107 @echo "< Test Case : >"
108 @echo "< $$ make test >"
109 @echo "----------------------------------------------"
111 @echo " \ (oo)\_______"
112 @echo " (__)\ )\\/\\"
118define ASK_AND_EXECUTE_ON_YES
119 @echo "Execute? $(1) (y/n)"
132# Makefile Option : Disable '--print-directory'
133MAKEFLAGS += --no-print-directory