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:08 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
21
22#vpath %.cpp ./
23
24# Object files and dependency files
25OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
26DEPS = $(addprefix $(DEP_DIR)/, $(SRCS:.cpp=.d))
27
28# Build target
29NAME = a.out
30
31vpath %.cpp ./
32
33# Compiler
34CXX = c++
35CXXFLAGS = -Wall -Wextra -Werror -std=c++98
36CF_DEP = -MMD -MP -MF $(@:$(OBJ_DIR)/%.o=$(DEP_DIR)/%.d)
37
38# Rules for building object files
39$(OBJ_DIR)/%.o: %.cpp
40 $(CXX) $(CXXFLAGS) $(CF_DEP) -c $< -o $@
41
42# Default target
43all: directories $(NAME)
44 $(call ASCII_ART,$(NAME))
45.PHONY: all
46
47# Make Directories
48directories:
49 @mkdir -p $(OBJ_DIR)
50 @mkdir -p $(DEP_DIR)
51.PHONY: directories
52
53# Build Target
54$(NAME): $(OBJS)
55 $(CXX) $(CXXFLAGS) $(OBJS) -o $(NAME)
56
57# REPOSITORY for Test
58TEST_ROOT = ../../cpp_module_tester
59TEST_DIR = $(TEST_ROOT)/cpp05
60URL_TEST_CPP = "https://github.com/kamitsui/cpp_module_tester.git"
61TEST_TARGET = $(TEST_DIR)/ex00_app
62EX_NUM = ex00
63
64# Test
65test:
66ifeq ($(shell test -d $(TEST_DIR) && echo exist),)
67 @echo "Please clone the test repository"
68 $(call ASK_AND_EXECUTE_ON_YES, git clone $(URL_TEST_CPP) $(TEST_ROOT))
69endif
70 $(call ASK_AND_EXECUTE_ON_YES, make -C $(TEST_DIR) $(EX_NUM))
71# @echo "No support!"
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