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 01:45:28 by kamitsui ### ########.fr #
11# **************************************************************************** #
13#******************************************************************************#
14# @file ex01/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 \
35 WrongAnimal.cpp WrongCat.cpp \
38# Object files and dependency files
39OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
40DEPS = $(addprefix $(DEP_DIR)/, $(SRCS:.cpp=.d))
47CXXFLAGS = -Wall -Wextra -Werror -std=c++98
48CF_DEP = -MMD -MP -MF $(@:$(OBJ_DIR)/%.o=$(DEP_DIR)/%.d)
50# Rules for building object files
52 $(CXX) $(CXXFLAGS) $(CF_DEP) -c $< -o $@
55all: directories $(NAME)
66 $(CXX) $(CXXFLAGS) $(OBJS) -o $(NAME)
67 $(call ASCII_ART,$(NAME))
70TEST_ROOT = ../../cpp_module_tester
71TEST_DIR = $(TEST_ROOT)/cpp04
72URL_TEST_CPP = "https://github.com/kamitsui/cpp_module_tester.git"
73TEST_TARGET = $(TEST_DIR)/ex01_app
78ifeq ($(shell test -d $(TEST_DIR) && echo exist),)
79 @echo "Please clone the test repository"
80 $(call ASK_AND_EXECUTE_ON_YES, git clone $(URL_TEST_CPP) $(TEST_ROOT))
82 $(call ASK_AND_EXECUTE_ON_YES, make -C $(TEST_DIR) $(EX_NUM))
85# Rule for removing object & dependency files
87 rm -rf $(OBJ_DIR) $(DEP_DIR) $(TEST_DIR)/objs $(TEST_DIR)/.deps
90# Rule for removing Target & others
92 rm -f $(NAME) $(TEST_TARGET)
95# Rule for Clean & Build Target
99# Enable dependency file
102# ASCII Art : Display Tips the way to use.
104 @echo " _____________________________________________"
106 @echo "< $$ ./a.out >"
108 @echo "< Test Case : >"
109 @echo "< $$ make test >"
110 @echo "----------------------------------------------"
112 @echo " \ (oo)\_______"
113 @echo " (__)\ )\\/\\"
119define ASK_AND_EXECUTE_ON_YES
120 @echo "Execute? $(1) (y/n)"
133# Makefile Option : Disable '--print-directory'
134MAKEFLAGS += --no-print-directory