forked from jerem-ma/goose-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
145 lines (116 loc) · 3.09 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
140
141
142
143
144
145
EXTRA_PATH_METADATA = {'mlx-capivara/libs/.minilibx-linux': {'path': '.minilibx-linux'}}
NAME = capivara
SRCS = main.c mlx_utils.c mlx_new_window_fullscreen.c \
farbfeld_to_img.c mlx_new_window_without_border.c \
files.c init.c
_OBJS = ${SRCS:.c=.o}
OBJS = $(addprefix build/, $(_OBJS))
CC = cc
CFLAGS = -Wall -Werror -Wextra -g3
INCLUDE = -I includes/ -I libs/.minilibx-linux
LIBS = libs/.minilibx-linux/libmlx.a
#====================Scripts=======================#
define count_files
TOTAL_FILES=`bash -c 'make -n | grep -- "-c.*-o" | wc -l'`; \
TOTAL_FILES=$$((TOTAL_FILES-1)); \
if [ $$TOTAL_FILES -ne 0 ]; then \
echo -n $$TOTAL_FILES > .MAKEFILE_total_files; \
echo -n "0" > .MAKEFILE_compiled_files; \
tput civis; \
fi;
endef
define file_compiled
COMPILED=`bash -c 'cat .MAKEFILE_compiled_files'`; \
COMPILED=$$((COMPILED+1)); \
echo -n $$COMPILED > .MAKEFILE_compiled_files; \
sleep 0.1;
endef
define draw_bar
TOTAL_FILES=`bash -c 'cat .MAKEFILE_total_files'`; \
COMPILED=`bash -c 'cat .MAKEFILE_compiled_files'`; \
TOTAL_LENGTH=52; \
if [ $$COMPILED -eq 0 ]; then \
COMPLETED_LENGTH=0; \
else \
INCREMENT=$$((TOTAL_LENGTH/TOTAL_FILES)); \
COMPLETED_LENGTH=$$((INCREMENT*COMPILED)); \
fi; \
PRINT=0; \
printf "\r"; \
while [ $$PRINT -ne $$COMPLETED_LENGTH ]; do \
printf "\e[0;32m█\e[0m"; \
PRINT=$$((PRINT+1)); \
done; \
if [ $$COMPILED -eq $$TOTAL_FILES ]; then \
while [ $$PRINT -ne $$TOTAL_LENGTH ]; do \
printf "\e[0;32m█\e[0m"; \
PRINT=$$((PRINT+1)); \
done; \
fi; \
while [ $$PRINT -ne $$TOTAL_LENGTH ]; do \
printf "\e[0m▒\e[0m"; \
PRINT=$$((PRINT+1)); \
done; \
if [ $$COMPILED -eq $$TOTAL_FILES ]; then \
printf "\n"; \
tput cvvis; \
fi;
endef
define clean
rm -f .MAKEFILE_total_files; \
rm -f .MAKEFILE_compiled_files; \
tput cvvis;
endef
BLUE = \033[1;34m
CYAN = \033[0;36m
GREEN = \033[0;32m
ORANGE = \033[0;33m
NO_COLOR = \033[m
#==================================================#
all :
@$(call count_files)
@make -s $(NAME) || $(MAKE) reset
build/%.o : srcs/%.c
@if [ ! -d $(dir $@) ]; then\
mkdir -p $(dir $@);\
fi
@$(call draw_bar)
@echo "Compiling $@ ... "
@$(call draw_bar)
@$(CC) ${CFLAGS} ${INCLUDE} -c $< -o $@
@$(call file_compiled)
@$(call draw_bar)
$(NAME) : $(OBJS) | libs
@@echo "Linking $@ ..."
@$(CC) $(CFLAGS) $(OBJS) $(LIBS) -lXext -lX11 -o $(NAME)
@$(call clean)
@echo "$@ created ! "
libs :
@for lib in $(LIBS); do\
echo make -C $$(dirname $$lib);\
make -C $$(dirname $$lib);\
done
clean :
rm -rf build/
cleanlibs :
@for lib in $(LIBS); do\
echo make -C $$(dirname $$lib) clean;\
make -C $$(dirname $$lib) clean;\
done
cleanall : clean cleanlibs
fclean : clean
rm -f ${NAME}
fcleanlibs :
@for lib in $(LIBS); do\
echo make -C $$(dirname $$lib) fclean;\
make -C $$(dirname $$lib) fclean;\
done
fcleanall : fclean fcleanlibs
re : fclean
@$(call count_files)
@make -s $(NAME) || $(MAKE) reset
relibs :
reall : relibs re
reset:
@$(call clean)
.PHONY : all libs clean cleanlibs cleanall fclean fcleanlibs fcleanall re relibs reall reset