CPP05 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
Makefile
[詳解]
1# **************************************************************************** #
2# #
3# ::: :::::::: #
4# Makefile :+: :+: :+: #
5# +:+ +:+ +:+ #
6# By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ #
7# +#+#+#+#+#+ +#+ #
8# Created: 2025/05/29 22:58:19 by kamitsui #+# #+# #
9# Updated: 2025/07/17 23:33:39 by kamitsui ### ########.fr #
10# #
11# **************************************************************************** #
12
13# Directories
14OBJ_DIR = objs
15DEP_DIR = .deps
16
17# Source files
18SRCS = \
19 main.cpp \
20 Bureaucrat.cpp AForm.cpp \
21 ShrubberyCreationForm.cpp RobotomyRequestForm.cpp PresidentialPardonForm.cpp
22
23#vpath %.cpp ./
24
25# Object files and dependency files
26OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
27DEPS = $(addprefix $(DEP_DIR)/, $(SRCS:.cpp=.d))
28
29# Build target
30NAME = a.out
31
32vpath %.cpp ./
33
34# Compiler
35CXX = c++
36CXXFLAGS = -Wall -Wextra -Werror -std=c++98
37CF_DEP = -MMD -MP -MF $(@:$(OBJ_DIR)/%.o=$(DEP_DIR)/%.d)
38
39# Rules for building object files
40$(OBJ_DIR)/%.o: %.cpp
41 $(CXX) $(CXXFLAGS) $(CF_DEP) -c $< -o $@
42
43# Default target
44all: directories $(NAME)
45 $(call ASCII_ART,$(NAME))
46.PHONY: all
47
48# Make Directories
49directories:
50 @mkdir -p $(OBJ_DIR)
51 @mkdir -p $(DEP_DIR)
52.PHONY: directories
53
54# Build Target
55$(NAME): $(OBJS)
56 $(CXX) $(CXXFLAGS) $(OBJS) -o $(NAME)
57
58# REPOSITORY for Test
59TEST_ROOT = ../../cpp_module_tester
60TEST_DIR = $(TEST_ROOT)/cpp05
61URL_TEST_CPP = "https://github.com/kamitsui/cpp_module_tester.git"
62TEST_TARGET = $(TEST_DIR)/ex02_app
63EX_NUM = ex02
64
65# Test
66test:
67ifeq ($(shell test -d $(TEST_DIR) && echo exist),)
68 @echo "Please clone the test repository"
69 $(call ASK_AND_EXECUTE_ON_YES, git clone $(URL_TEST_CPP) $(TEST_ROOT))
70endif
71 $(call ASK_AND_EXECUTE_ON_YES, make -C $(TEST_DIR) $(EX_NUM))
72.PHONY: test
73
74# More Test : Enable Logger
75debug: fclean
76 make WITH_DEBUG=1
77.PHONY: debug
78
79# DEBUG_MODE
80ifdef WITH_DEBUG
81CXXFLAGS += -D DEBUG_MODE
82endif
83
84# Rule for removing object & dependency files
85clean:
86 rm -rf $(OBJ_DIR) $(DEP_DIR) $(TEST_DIR)/objs $(TEST_DIR)/.deps
87.PHONY: clean
88
89# Rule for removing Target & others
90fclean: clean
91 rm -f $(NAME) $(TEST_TARGET)
92.PHONY: fclean
93
94# Rule for Clean & Build Target
95re: fclean all
96.PHONY: re
97
98# Enable dependency file
99-include $(DEPS)
100
101# ASCII Art : Display Tips the way to use.
102define ASCII_ART
103 @echo " _____________________________________________"
104 @echo "< Usage : >"
105 @echo "< $$ ./a.out >"
106 @echo "< >"
107 @echo "< Debug : >"
108 @echo "< $$ make debug >"
109 @echo "< $$ ./a.out >"
110 @echo "< >"
111 @echo "< Test Case : >"
112 @echo "< $$ make test >"
113 @echo "----------------------------------------------"
114 @echo " \ ^__^"
115 @echo " \ (oo)\_______"
116 @echo " (__)\ )\\/\\"
117 @echo " ||----w |"
118 @echo " || ||\n"
119endef
120
121# Ask and Exit on No
122define ASK_AND_EXECUTE_ON_YES
123 @echo "Execute? $(1) (y/n)"
124 @read -r answer; \
125 case "$$answer" in \
126 [yY]) \
127 echo $(1); \
128 $(1); \
129 ;; \
130 *) \
131 echo "Skip ..."; \
132 ;; \
133 esac
134endef
135
136# Makefile Option : Disable '--print-directory'
137MAKEFLAGS += --no-print-directory