-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
139 lines (114 loc) · 2.59 KB
/
Makefile
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# include
include mk/config.mk # base config
include mk/utils.mk # utils function / var
include mk/lib.mk # load lib if needed
include mk/srcs.mk # srcs.mk
include mk/pb.mk # ui thing, progress bar etc
$(call PB_INIT)
# rule
## config
.SILENT:
.PHONY: setup
.DEFAULT: all
all: setup $(TARGET)
bonus: setup $(TARGET)
### TARGETS
$(TARGET): $(LIBFT) $(MINI_LIBX) $(OBJ_C)
> $(call P_INF,Creating $(R)$(TARGET)$(RST))
> printf "\n\n"
> $(call PB_PRINT_ELAPSED)
> $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJ_C) $(LDFLAGS)
> $(call PB_TARGET_DONE)
## objs
# https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html#Automatic-Variables
# $(<) : dependencies
# $(@) : full target
# $(@D) : dir target
$(OBJ_C): $(OBJ_DIR)/%.o:$(SRC_DIR)/%.c
> $(call PB_PRINT,$(@))
> gcc $(CFLAGS) -o $@ -c $<
### LIBS
$(LIBFT):
ifeq ($(USE_LIBFT),1)
> make -C lib/ft_libft all
endif
$(MINI_LIBX):
ifeq ($(USE_MINI_LIBX),1)
> make -C lib/minilibx-linux all
endif
setup: corrector $(BIN_DIR) print_logo print_debug
$(BIN_DIR):
> $(call MKDIR,$(BIN_DIR))
print_debug:
ifeq ($(shell [ $(DEBUG) -ge 1 ] && printf 1 || printf 0),1)
> $(call P_INF,RUNTIME INFOS)
> $(call P_WAR,DEBUG: $(DEBUG))
> $(call P_WAR,CFLAGS:)
> printf "\n"
> printf "\t\t%s\n" $(CFLAGS)
> $(call P_WAR,LDFLAGS:)
> printf "\n"
> printf "\t\t%s\n" $(LDFLAGS)
> $(call P_WAR,.SHELLFLAGS:)
> printf "\n"
> printf "\t\t%s\n" $(.SHELLFLAGS)
> $(call P_WAR,OBJ_C:)
> printf "\n"
> printf "\t\t%s\n" $(OBJ_C)
> $(call P_WAR,SRC_C:)
> printf "\n"
> printf "\t\t%s\n" $(SRC_C)
endif
print_logo:
ifeq ($(LOGO_PRINTED),)
> printf "%b\n" "$(ASCII_COLOR)$$ASCII_BANNER$(RST)"
> $(eval export LOGO_PRINTED=1)
endif
### CORRECTOR
corrector: export_vars
> ./rsc/corrector/run
export_vars:
export MK_DIR
export SRC_DIR
### RUN
run: re
> ./$(TARGET) $(ARGS)
### CLEAN
clean:
> $(call P_FAI,Removing obj)
> rm -rf $(OBJ_DIR)
clean_all: clean
ifeq ($(USE_LIBFT),1)
> make -C lib/ft_libft clean
endif
ifeq ($(USE_MINI_LIBX),1)
> make -C lib/minilibx-linux clean
endif
fclean: clean
ifeq ($(BONUS),1)
> $(call P_FAI,Removing $(TARGET))
> rm -rf $(TARGET)
else
> $(call P_FAI,Removing $(TARGET_BONUS))
> rm -rf $(TARGET_BONUS)
endif
fclean_all: fclean
ifeq ($(USE_LIBFT),1)
> make -C lib/ft_libft fclean
endif
ifeq ($(USE_MINI_LIBX),1)
> make -C lib/minilibx-linux clean
endif
### RE
re: setup fclean $(TARGET)
re_all: re_lib re
re_lib:
ifeq ($(USE_LIBFT),1)
> make -C ./lib/ft_libft re
endif
ifeq ($(USE_MINI_LIBX),1)
> make -C ./lib/minilibx-linux re
endif
### install binary (need sudo)
install: re
> sudo cp $(TARGET) /usr/bin/