-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProgMakefile
114 lines (88 loc) · 2.31 KB
/
ProgMakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Makefle template for 42 projects
# Tools
NAME = program
CC = clang
CFLAGS = -Wall -Wextra -Werror -I $(INC_PATH) $(DBGFLAGS)
COBJFLAGS = $(CFLAGS) -c
DBGFLAGS =
RMFLAGS = -r
# Paths
TGT_PATH = .
BIN_PATH = $(TGT_PATH)/
OBJ_PATH = $(TGT_PATH)/obj
DBG_PATH = debug
SRC_PATH = src
INC_PATH = $(SRC_PATH)/include
LFT_PATH = $(SRC_PATH)/libft
MSRC_PATH = $(SRC_PATH)/main
BSRC_PATH = $(SRC_PATH)/bonus
# Source and object files
HDRS =
MSRC =
MAIN = $(MSRC_PATH)/main.c
OBJ = $(MSRC:%.c=$(OBJ_PATH)/%.o)
BSRC =
BMAIN = $(BSRC_PATH)/main.c
BOBJ = $(BSRC:%.c=$(OBJ_PATH)/%.o)
# Config
# Unwanted files to be deleted
UNW = .DS_Store ./*/.DS_Store
# No. of seconds the screen output will be visible for
SECONDS_VISIBLE = 4
# BONUS = 0 if you're going to do bonus: BONUS := 1
# Colors
DEF_COLOR = \033[0;39m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
all: $(NAME)
$(NAME): mkdir $(OBJ) $(MAIN)
@echo "\n$(GREEN)$(NAME) objects compiled successfully.$(DEF_COLOR)\n"
@make -C $(LFT_PATH)
@cp $(LFT_PATH)/libft.a $(BIN_PATH)/libft
@echo "$(YELLOW)Linking $(NAME) objects.$(DEF_COLOR)\n"
@$(CC) $(CFLAGS) $(OBJ) $(MAIN:%.c=$(OBJ_PATH)/%.o) -L$(BIN_PATH) -lft -o $(NAME)
@echo "$(GREEN)$(NAME) compiled successfully.$(DEF_COLOR)\n"
debug: DBGFLAGS := -g
debug: $(NAME)
# bonus: BONUS := 1
# and add -D$(BONUS) to your COBJFLAGS.
# Do this if you'll use the same files for bonus and mandatory.
bonus: $(NAME)
# Or compile here if you'll use separate bonus and mandatory files.
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c
@mkdir -p $(@D)
@$(CC) $(COBJFLAGS) $^ -o $@
mkdir:
@mkdir -p $(BIN_PATH)
@mkdir -p $(OBJ_PATH)
# @mkdir -p $(OBJ_PATH)/other/path
preclean:
@echo "\n$(YELLOW)Cleaning project up...$(DEF_COLOR)"
postclean:
@echo "\n$(GREEN)Done!$(DEF_COLOR)\n"
clean: preclean clean-body postclean
clean-body:
@$(RM) $(RMFLAGS) $(OBJ_PATH)
fclean: preclean fclean-body postclean
fclean-body: clean-body
@$(RM) $(RMFLAGS) $(NAME)
xclean: preclean xclean-body postclean
xclean-body: fclean-body
@$(RM) $(RMFLAGS) $(UNW)
re: fclean all
bre: fclean bonus
try: re xclean
norminette
btry: bre xclean
norminette
ctry: try
sleep $(SECONDS_VISIBLE); clear
cbtry: btry
sleep $(SECONDS_VISIBLE); clear
.PHONY: all clean fclean xclean re bonus bre