-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
53 lines (42 loc) · 1.47 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
# ******************************** Directories *********************************
INCLUDES_DIR := include
SRCS_DIR := src
OBJS_DIR := obj
LIBS_DIR :=
# *********************************** Files ************************************
NAME := philo
MAIN := main.c
SRCS := $(shell ls $(SRCS_DIR))
OBJS := $(SRCS:.c=.o)
HEADERS := $(shell ls $(INCLUDES_DIR))
# ****************************** Compiler Options ******************************
CC := cc
CFLAGS := -Wall -Wextra -Werror -pthread
INCLUDES := -I $(INCLUDES_DIR)
LIBS :=
# ******************************* Other commands *******************************
RM := rm -rf
MKDIR := mkdir -p
# *********************************** Colors ***********************************
NC := '\033[0m'
GREEN := '\033[32m'
RED := '\033[0;31m'
# ********************************** Targets ***********************************
all: $(NAME)
$(NAME): $(addprefix $(OBJS_DIR)/, $(OBJS)) $(MAIN) \
$(addprefix $(INCLUDES_DIR)/, $(HEADERS))
@echo "Compiling" $(GREEN) "main"
@$(CC) $(CFLAGS) $(INCLUDES) $(LIBS) $(addprefix $(OBJS_DIR)/, $(OBJS)) \
$(MAIN) -o $(NAME)
$(OBJS_DIR)/%.o: $(SRCS_DIR)/%.c $(addprefix $(INCLUDES_DIR)/, $(HEADERS))
@$(MKDIR) $(OBJS_DIR)
@echo "Compiling" $(GREEN) $(basename $(shell basename $<)) $(NC)
@$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
clean:
@echo "Removing" $(RED) "object files" $(NC)
@$(RM) $(OBJS_DIR)
fclean: clean
@echo "Removing" $(RED) $(NAME) $(NC)
@$(RM) $(NAME)
re: fclean all
.PHONY: all clean fclean re