-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
98 lines (74 loc) · 2.37 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
PROJ_NAME ?= ASM
TARGET_EXEC ?= asm
OBJ_DIR = ./obj
FILE_LAST_MODE = $(OBJ_DIR)/last_version.txt
cat := $(if $(filter $(OS),Windows_NT),type,cat)
LAST_MODE = $(shell $(cat) $(FILE_LAST_MODE) 2>/dev/null)
ifneq ($(mode),debug)
mode = release
BUILD_DIR = $(OBJ_DIR)/release
PREFIX = RELEASE MODE
else
mode = debug
BUILD_DIR = $(OBJ_DIR)/debug
PREFIX = DEBUG MODE
endif
ifneq ($(mode),$(LAST_MODE))
REBUILD = clean_only_exe
endif
SRC_DIRS = ./src
SRCS := $(shell find $(SRC_DIRS) -type f -name *.c )
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
LIBFTDIR = libft
LIBFT = $(LIBFTDIR)/libft.a
INC_DIRS := $(LIBFTDIR)/inc inc
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CFLAGS ?= -Wall -Wextra -Werror $(INC_FLAGS) -MMD -MP
ifeq ($(mode),release)
CFLAGS += -O3
else
CFLAGS += -O0 -g
endif
.PHONY: all clean fclean re info debug release
all: info $(TARGET_EXEC)
clean_only_exe:
@if [ -f "$(TARGET_EXEC)" ]; then \
printf "\033[0;32m%-10s\033[0;34m%-9s\033[0;33m %s\033[0m\n" "[$(PROJ_NAME)]" "[$(PREFIX)]" "Clean bin $(PROJ_NAME), because changed MODE COMPILATION."; \
rm -rf $(TARGET_EXEC); \
fi
@make -s -C $(LIBFTDIR) $(MAKECMDGOALS)
# make executable file
$(TARGET_EXEC): $(OBJS) $(LIBFT) $(REBUILD)
@printf "\033[0;32m%-10s\033[0;34m%-9s\033[0;33m %s\033[0m %s\n" "[$(PROJ_NAME)]" "[$(PREFIX)]" "Linking: " "$@"
@$(CC) $(OBJS) $(LIBFT) -o $@ $(LDFLAGS)
@rm -f $(FILE_LAST_MODE)
@echo "$(mode)" >> $(FILE_LAST_MODE)
# c source
$(BUILD_DIR)/%.c.o: %.c
@printf "\033[0;32m%-10s\033[0;34m%-9s\033[0;33m %s\033[0m %s\n" "[$(PROJ_NAME)]" "[$(PREFIX)]" "Compiling:" "$<"
@$(MKDIR_P) $(dir $@)
@$(CC) $(CFLAGS) -c $< -o $@
# make my libft
$(LIBFT):
@make -s -C $(LIBFTDIR) $(MAKECMDGOALS)
info:
debug:
@make -s mode=debug
release:
@make -s mode=release
clean:
@printf "\033[0;32m%-10s\033[0;34m%-9s\033[0;33m %s\033[0m\n" "[$(PROJ_NAME)]" "[$(PREFIX)]" "Clean objects $(PROJ_NAME)"
@$(RM) -rf $(OBJ_DIR)
@make -s -C $(LIBFTDIR) clean
fclean:
@printf "\033[0;32m%-10s\033[0;34m%-9s\033[0;33m %s\033[0m\n" "[$(PROJ_NAME)]" "[$(PREFIX)]" "Clean objects $(PROJ_NAME)"
@$(RM) -rf $(OBJ_DIR)
@printf "\033[0;32m%-10s\033[0;34m%-9s\033[0;33m %s\033[0m\n" "[$(PROJ_NAME)]" "[$(PREFIX)]" "Clean bin $(PROJ_NAME)"
@rm -rf $(TARGET_EXEC)
@make -s -C $(LIBFTDIR) fclean
norme:
@norminette | grep Error -B 1
re: fclean all
-include $(DEPS)
MKDIR_P ?= mkdir -p